From 151cf6be5076270d2bb96ba4ca1a3da6f38e9d7b Mon Sep 17 00:00:00 2001
From: "SAMBA\\bernat"
Date: Wed, 3 Jan 2018 12:00:59 +0100
Subject: [PATCH] Refactor on DBlocal files
---
services/db/Dockerfile | 13 +-
services/db/localDB01StructureAccount.sql | 1576 +
...cture.sql => localDB02StructureVn2008.sql} | 36470 +++-------------
services/db/localDB03StructureVn.sql | 11017 +++++
services/db/localDB04StructureOthersDB.sql | 14304 ++++++
services/db/localDB05StructureUtil.sql | 616 +
services/db/localDB06Views2008.sql | 1613 +
services/db/localDB07ViewsVn.sql | 2024 +
services/db/localDB08OthersViews.sql | 1236 +
...alDB02Inserts.sql => localDB09Inserts.sql} | 45 +-
10 files changed, 37808 insertions(+), 31106 deletions(-)
create mode 100644 services/db/localDB01StructureAccount.sql
rename services/db/{localDB01Structure.sql => localDB02StructureVn2008.sql} (54%)
create mode 100644 services/db/localDB03StructureVn.sql
create mode 100644 services/db/localDB04StructureOthersDB.sql
create mode 100644 services/db/localDB05StructureUtil.sql
create mode 100644 services/db/localDB06Views2008.sql
create mode 100644 services/db/localDB07ViewsVn.sql
create mode 100644 services/db/localDB08OthersViews.sql
rename services/db/{localDB02Inserts.sql => localDB09Inserts.sql} (85%)
diff --git a/services/db/Dockerfile b/services/db/Dockerfile
index 3826138f6..ba6c150b1 100644
--- a/services/db/Dockerfile
+++ b/services/db/Dockerfile
@@ -2,11 +2,18 @@ FROM mysql:5.6.37
ENV MYSQL_ALLOW_EMPTY_PASSWORD yes
-COPY localDB01Structure.sql /docker-entrypoint-initdb.d
-COPY localDB02Inserts.sql /docker-entrypoint-initdb.d
+COPY localDB01StructureAccount.sql /docker-entrypoint-initdb.d
+COPY localDB02StructureVn2008.sql /docker-entrypoint-initdb.d
+COPY localDB03StructureVn.sql /docker-entrypoint-initdb.d
+COPY localDB04StructureOthersDB.sql /docker-entrypoint-initdb.d
+COPY localDB05StructureUtil.sql /docker-entrypoint-initdb.d
+COPY localDB06Views2008.sql /docker-entrypoint-initdb.d
+COPY localDB07ViewsVn.sql /docker-entrypoint-initdb.d
+COPY localDB08OthersViews.sql /docker-entrypoint-initdb.d
+COPY localDB09Inserts.sql /docker-entrypoint-initdb.d
RUN chmod -R 755 /docker-entrypoint-initdb.d
CMD ["mysqld"]
-EXPOSE 3306
\ No newline at end of file
+EXPOSE 3306
diff --git a/services/db/localDB01StructureAccount.sql b/services/db/localDB01StructureAccount.sql
new file mode 100644
index 000000000..3c35f873c
--- /dev/null
+++ b/services/db/localDB01StructureAccount.sql
@@ -0,0 +1,1576 @@
+CREATE DATABASE IF NOT EXISTS `account` /*!40100 DEFAULT CHARACTER SET utf8 */;
+USE `account`;
+-- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64)
+--
+-- Host: db.verdnatura.es Database: account
+-- ------------------------------------------------------
+-- 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 `account`
+--
+
+DROP TABLE IF EXISTS `account`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `account` (
+ `id` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`id`),
+ CONSTRAINT `account_ibfk_3` FOREIGN KEY (`id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Users allowed to have an account';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `accountConfig`
+--
+
+DROP TABLE IF EXISTS `accountConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `accountConfig` (
+ `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
+ `homedir` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The base folder for users home directories',
+ `shell` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The default shell',
+ `min` smallint(6) NOT NULL,
+ `max` smallint(6) NOT NULL,
+ `warn` smallint(6) NOT NULL,
+ `inact` smallint(6) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters for accounts';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `accountDovecot`
+--
+
+DROP TABLE IF EXISTS `accountDovecot`;
+/*!50001 DROP VIEW IF EXISTS `accountDovecot`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `accountDovecot` AS SELECT
+ 1 AS `name`,
+ 1 AS `password`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `accountLog`
+--
+
+DROP TABLE IF EXISTS `accountLog`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `accountLog` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `msg` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `pid` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `user` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `host` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `rhost` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `time` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `accountPam`
+--
+
+DROP TABLE IF EXISTS `accountPam`;
+/*!50001 DROP VIEW IF EXISTS `accountPam`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `accountPam` AS SELECT
+ 1 AS `name`,
+ 1 AS `password`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `ldapConfig`
+--
+
+DROP TABLE IF EXISTS `ldapConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `ldapConfig` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `host` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The hostname of LDAP server',
+ `rdn` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The LDAP user',
+ `password` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Base64 encoded password',
+ `baseDn` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The base DN to do the query',
+ `filter` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Filter to apply to the query',
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='LDAP server configuration parameters';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `mailAlias`
+--
+
+DROP TABLE IF EXISTS `mailAlias`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `mailAlias` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `alias` varchar(50) CHARACTER SET utf8 NOT NULL,
+ `isPublic` tinyint(4) NOT NULL DEFAULT '1',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `alias` (`alias`)
+) ENGINE=InnoDB AUTO_INCREMENT=62 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Mail aliases';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `mailAliasAccount`
+--
+
+DROP TABLE IF EXISTS `mailAliasAccount`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `mailAliasAccount` (
+ `mailAlias` int(10) unsigned NOT NULL,
+ `account` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`mailAlias`,`account`),
+ KEY `account` (`account`),
+ CONSTRAINT `account` FOREIGN KEY (`account`) REFERENCES `account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `mailAlias` FOREIGN KEY (`mailAlias`) REFERENCES `mailAlias` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Mail alias that is assigned to each account';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `mailConfig`
+--
+
+DROP TABLE IF EXISTS `mailConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `mailConfig` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `domain` varchar(255) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `mailForward`
+--
+
+DROP TABLE IF EXISTS `mailForward`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `mailForward` (
+ `account` int(10) unsigned NOT NULL,
+ `forwardTo` varchar(250) CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`account`),
+ CONSTRAINT `mailForward_ibfk_1` FOREIGN KEY (`account`) REFERENCES `account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Mail forwarding';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `role`
+--
+
+DROP TABLE IF EXISTS `role`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `role` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `name` varchar(14) COLLATE utf8_unicode_ci NOT NULL,
+ `description` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `hasLogin` tinyint(3) unsigned NOT NULL DEFAULT '0',
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `name` (`name`)
+) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Roles';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `roleInherit`
+--
+
+DROP TABLE IF EXISTS `roleInherit`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `roleInherit` (
+ `role` int(10) unsigned NOT NULL,
+ `inheritsFrom` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`role`,`inheritsFrom`),
+ KEY `owner_id` (`inheritsFrom`),
+ CONSTRAINT `roleInherit_ibfk_1` FOREIGN KEY (`role`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `roleInherit_ibfk_2` FOREIGN KEY (`inheritsFrom`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Role inheritance';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `roleRole`
+--
+
+DROP TABLE IF EXISTS `roleRole`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `roleRole` (
+ `role` int(10) unsigned NOT NULL,
+ `inheritsFrom` int(10) unsigned NOT NULL,
+ UNIQUE KEY `role` (`role`,`inheritsFrom`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Calculated role inheritance';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `sambaConfig`
+--
+
+DROP TABLE IF EXISTS `sambaConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `sambaConfig` (
+ `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
+ `host` varchar(255) CHARACTER SET utf8 DEFAULT NULL COMMENT 'The hosname of Samba server',
+ `sshUser` varchar(30) CHARACTER SET utf8 DEFAULT NULL COMMENT 'The SSH user to connect to servers',
+ `sshPass` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The SSH password base64 encoded',
+ `uidBase` int(10) unsigned NOT NULL DEFAULT '10000' COMMENT 'The base for Unix uids',
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters for accounts';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `user`
+--
+
+DROP TABLE IF EXISTS `user`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `user` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `name` varchar(30) CHARACTER SET utf8 NOT NULL,
+ `nickname` varchar(127) COLLATE utf8_unicode_ci NOT NULL,
+ `password` char(64) COLLATE utf8_unicode_ci NOT NULL,
+ `role` int(10) unsigned NOT NULL DEFAULT '2',
+ `active` tinyint(1) NOT NULL DEFAULT '1',
+ `email` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
+ `lang` char(2) CHARACTER SET utf8 DEFAULT NULL,
+ `sync` tinyint(4) NOT NULL DEFAULT '0',
+ `recoverPass` tinyint(3) unsigned NOT NULL DEFAULT '1',
+ `lastPassChange` datetime DEFAULT NULL,
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `name` (`name`),
+ KEY `role` (`role`),
+ KEY `email` (`email`),
+ KEY `nickname` (`nickname`),
+ KEY `lang` (`lang`),
+ CONSTRAINT `user_ibfk_2` FOREIGN KEY (`role`) REFERENCES `role` (`id`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=50171 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global users';
+/*!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 `account`.`userBeforeInsert`
+ BEFORE INSERT ON `user`
+ FOR EACH ROW
+BEGIN
+ CALL userCheckName (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 `account`.`userBeforeUpdate`
+ BEFORE UPDATE ON `user`
+ FOR EACH ROW
+BEGIN
+ IF NOT (NEW.`name` <=> OLD.`name`) THEN
+ CALL userCheckName (NEW.`name`);
+ END IF;
+
+ IF NOT (NEW.`password` <=> OLD.`password`) THEN
+ SET NEW.lastPassChange = NOW();
+ END IF;
+
+ IF NEW.`sync` <=> OLD.`sync` THEN
+ SET NEW.`sync` = FALSE;
+ 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 `userAfterUpdate`
+ AFTER UPDATE ON `user`
+ FOR EACH ROW
+BEGIN
+ IF NOT (NEW.`role` <=> OLD.`role`)
+ THEN
+ INSERT INTO vn2008.mail SET
+ `to` = 'jgallego@verdnatura.es',
+ `reply_to` = 'jgallego@verdnatura.es',
+ `subject` = 'Rol modificado',
+ `text` = CONCAT(account.userGetName(), ' ha modificado el rol del usuario ',
+ NEW.`name`, ' de ', OLD.role, ' a ', NEW.role);
+ 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 `userConfig`
+--
+
+DROP TABLE IF EXISTS `userConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `userConfig` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `loginKey` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `userPassword`
+--
+
+DROP TABLE IF EXISTS `userPassword`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `userPassword` (
+ `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
+ `length` tinyint(3) unsigned NOT NULL,
+ `nAlpha` tinyint(3) unsigned NOT NULL,
+ `nUpper` tinyint(3) unsigned NOT NULL,
+ `nDigits` tinyint(3) unsigned NOT NULL,
+ `nPunct` tinyint(3) unsigned NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Restrictions on user passwords';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `userRole`
+--
+
+DROP TABLE IF EXISTS `userRole`;
+/*!50001 DROP VIEW IF EXISTS `userRole`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `userRole` AS SELECT
+ 1 AS `id`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `userView`
+--
+
+DROP TABLE IF EXISTS `userView`;
+/*!50001 DROP VIEW IF EXISTS `userView`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `userView` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `active`,
+ 1 AS `email`,
+ 1 AS `nickname`,
+ 1 AS `lang`,
+ 1 AS `role`,
+ 1 AS `recoverPass`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Dumping events for database 'account'
+--
+
+--
+-- Dumping routines for database 'account'
+--
+/*!50003 DROP FUNCTION IF EXISTS `toUnixDays` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `toUnixDays`(vDate DATE) RETURNS int(11)
+ DETERMINISTIC
+BEGIN
+/**
+ * Devuelve el timestamp unix en días de una fecha.
+ *
+ * @param vData La fecha
+ * @return Unix timestamp en días
+ */
+
+ RETURN UNIX_TIMESTAMP(vDate) DIV 86400;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `userCheckLogin` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `userCheckLogin`() RETURNS tinyint(1)
+ READS SQL DATA
+ DETERMINISTIC
+BEGIN
+/**
+ * Checks that variables @userId and @userName haven't been altered.
+ *
+ * @return %TRUE if they are unaltered or unset, otherwise %FALSE
+ */
+ DECLARE vSignature VARCHAR(128);
+ DECLARE vKey VARCHAR(255);
+
+ IF @userId IS NOT NULL
+ AND @userName IS NOT NULL
+ AND @userSignature IS NOT NULL
+ THEN
+ SELECT loginKey INTO vKey FROM userConfig;
+ SET vSignature = util.hmacSha2(256, CONCAT_WS('/', @userId, @userName), vKey);
+ RETURN vSignature = @userSignature;
+ END IF;
+
+ RETURN 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 FUNCTION IF EXISTS `userGetId` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `USERGETID`() RETURNS int(11)
+ READS SQL DATA
+ DETERMINISTIC
+BEGIN
+/**
+ * Returns the current user id.
+ *
+ * @return The user id
+ */
+ DECLARE vUser INT DEFAULT NULL;
+
+ IF userCheckLogin()
+ THEN
+ SET vUser = @userId;
+ ELSE
+ SELECT id INTO vUser FROM user
+ WHERE name = LEFT(USER(), INSTR(USER(), '@') - 1);
+ END IF;
+
+ RETURN vUser;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `userGetMysqlRole` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `userGetMysqlRole`(vUserName VARCHAR(255)) RETURNS varchar(255) CHARSET utf8
+BEGIN
+/**
+ * A partir de un nombre de usuario devuelve el rol
+ * de MySQL asociado y con el que deberia autenticarse
+ * cuando se utilice sistemas de autenticación externos.
+ *
+ * @param vUserName El nombre de usuario
+ * @return El rol de MySQL asociado
+ */
+ DECLARE vRole VARCHAR(255);
+
+ SELECT CONCAT(IF(r.hasLogin, 'z-', ''), r.name) INTO vRole
+ FROM role r
+ JOIN user u ON u.role = r.id
+ WHERE u.name = vUserName;
+
+ RETURN vRole;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `userGetName` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `userGetName`() RETURNS varchar(30) CHARSET utf8
+ NO SQL
+ DETERMINISTIC
+BEGIN
+/**
+ * Returns the current user name.
+ *
+ * @return The user name
+ */
+ DECLARE vUser VARCHAR(30) DEFAULT NULL;
+
+ IF userCheckLogin()
+ THEN
+ SET vUser = @userName;
+ ELSE
+ SET vUser = LEFT(USER(), INSTR(USER(), '@') - 1);
+ END IF;
+
+ RETURN vUser;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `userGetNameFromId` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `userGetNameFromId`(vId INT) RETURNS varchar(30) CHARSET utf8
+BEGIN
+/**
+ * Obtener nombre de usuari a partir de su id
+ *
+ * @param vId Id del usuario
+ * @return Nombre de usuario
+ */
+ DECLARE vName VARCHAR(30);
+
+ SELECT `name` INTO vName
+ FROM user
+ WHERE id = vId;
+
+ RETURN vName;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `userHasRole` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `userHasRole`(vRoleName VARCHAR(255)) RETURNS tinyint(1)
+ DETERMINISTIC
+BEGIN
+/**
+ * Comprueba si el usuario actual tiene asociado un rol.
+ *
+ * @param vRoleName Nombre del rol a comprobar
+ * @return %TRUE si tiene el rol, %FALSE en caso contrario
+ */
+ DECLARE vRoleId INT;
+
+ SELECT id INTO vRoleId
+ FROM role
+ WHERE `name` = vRoleName COLLATE 'utf8_unicode_ci';
+
+ RETURN userHasRoleId (vRoleId);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `userHasRoleId` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `userHasRoleId`(vRoleId INT) RETURNS tinyint(1)
+ DETERMINISTIC
+BEGIN
+/**
+ * Comprueba si el usuario actual tiene asociado un rol.
+ *
+ * @param vRoleId Identificador del rol a comprobar
+ * @return %TRUE si tiene el rol, %FALSE en caso contrario
+ */
+ DECLARE vHasRole BOOL DEFAULT FALSE;
+
+ SELECT COUNT(*) > 0 INTO vHasRole
+ FROM userRole
+ WHERE id = vRoleId;
+
+ RETURN vHasRole;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `privSync` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `privSync`()
+proc: BEGIN
+/**
+ * Sincroniza los permisos de los usuarios 'rol' de MySQL
+ * en base a la jerarquía de roles. Los usuarios rol resultantes
+ * de la mezcla de permisos serán nombrados singuiendo el patrón
+ * z-[nombre_rol].
+ *
+ * Para que el procedimiento funcione debe de existir un usuario
+ * any@% que se usara como plantilla base.
+ *
+ * ¡Atención! Este procedimiento solo debe ser llamado cuando se
+ * modifiquen los privilegios de MySQL. Si se modifica la jerarquía
+ * de roles, se debe llamar al procedimiento roleSync() que llama a
+ * este internamente.
+ */
+ DECLARE vTplUser VARCHAR(255) DEFAULT 'any';
+ DECLARE vHost VARCHAR(255) DEFAULT '%';
+ DECLARE vPrefix VARCHAR(2) DEFAULT 'z-';
+
+ DECLARE vTplExists BOOL;
+ DECLARE vTplHost VARCHAR(255);
+ DECLARE vPrefixedLike VARCHAR(255);
+
+ -- Comprueba que el usuario plantilla existe
+
+ SELECT COUNT(*) > 0, `Host`
+ INTO vTplExists, vTplHost
+ FROM mysql.user
+ WHERE `User` = vTplUser
+ LIMIT 1;
+
+ IF NOT vTplExists THEN
+ SIGNAL SQLSTATE '45000'
+ SET MESSAGE_TEXT = 'TEMPLATE_USER_NOT_EXISTS';
+ END IF;
+
+ -- Borra todos los privilegios calculados
+
+ SET vPrefixedLike = CONCAT(vPrefix, '%');
+
+ DELETE FROM mysql.user
+ WHERE `User` LIKE vPrefixedLike;
+
+ DELETE FROM mysql.db
+ WHERE `User` LIKE vPrefixedLike;
+
+ DELETE FROM mysql.tables_priv
+ WHERE `User` LIKE vPrefixedLike;
+
+ DELETE FROM mysql.columns_priv
+ WHERE `User` LIKE vPrefixedLike;
+
+ DELETE FROM mysql.procs_priv
+ WHERE `User` LIKE vPrefixedLike;
+
+ DELETE FROM mysql.proxies_priv
+ WHERE `Proxied_user` LIKE vPrefixedLike;
+
+ -- Tablas temporales
+
+ DROP TEMPORARY TABLE IF EXISTS tRole;
+ CREATE TEMPORARY TABLE tRole
+ ENGINE = MEMORY
+ SELECT
+ `name` role,
+ CONCAT(vPrefix, `name`) prefixedRole
+ FROM role
+ WHERE hasLogin;
+
+ DROP TEMPORARY TABLE IF EXISTS tRoleInherit;
+ CREATE TEMPORARY TABLE tRoleInherit
+ (INDEX (inheritsFrom))
+ ENGINE = MEMORY
+ SELECT
+ CONCAT(vPrefix, r.`name`) prefixedRole,
+ ri.`name` inheritsFrom
+ FROM role r
+ JOIN roleRole rr ON rr.role = r.id
+ JOIN role ri ON ri.id = rr.inheritsFrom;
+
+ -- Vueve a crear el usuario
+
+ INSERT INTO mysql.user (
+ `User`,
+ `Host`,
+ `Password`,
+ `ssl_type`,
+ `ssl_cipher`,
+ `x509_issuer`,
+ `x509_subject`,
+ `max_questions`,
+ `max_updates`,
+ `max_connections`,
+ `max_user_connections`
+ )
+ SELECT
+ r.prefixedRole,
+ vTplHost,
+ IF('' != u.`Password`,
+ u.`Password`, t.`Password`),
+ IF('' != u.`ssl_type`,
+ u.`ssl_type`, t.`ssl_type`),
+ IF('' != u.`ssl_cipher`,
+ u.`ssl_cipher`, t.`ssl_cipher`),
+ IF('' != u.`x509_issuer`,
+ u.`x509_issuer`, t.`x509_issuer`),
+ IF('' != u.`x509_subject`,
+ u.`x509_subject`, t.`x509_subject`),
+ IF(0 != u.`max_questions`,
+ u.`max_questions`, t.`max_questions`),
+ IF(0 != u.`max_updates`,
+ u.`max_updates`, t.`max_updates`),
+ IF(0 != u.`max_connections`,
+ u.`max_connections`, t.`max_connections`),
+ IF(0 != u.`max_user_connections`,
+ u.`max_user_connections`, t.`max_user_connections`)
+ FROM tRole r
+ JOIN mysql.user t
+ ON t.`User` = vTplUser
+ AND t.`Host` = vTplHost
+ LEFT JOIN mysql.user u
+ ON u.`User` = r.role
+ AND u.`Host` = vHost;
+
+ INSERT INTO mysql.proxies_priv (
+ `User`,
+ `Host`,
+ `Proxied_user`,
+ `Proxied_host`,
+ `Grantor`
+ )
+ SELECT
+ '',
+ vHost,
+ prefixedRole,
+ vHost,
+ CONCAT(prefixedRole, '@', vTplHost)
+ FROM tRole;
+
+ -- Copia los privilegios globales del usuario
+
+ DROP TEMPORARY TABLE IF EXISTS tUserPriv;
+ CREATE TEMPORARY TABLE tUserPriv
+ (INDEX (prefixedRole))
+ ENGINE = MEMORY
+ SELECT
+ r.prefixedRole,
+ MAX(u.`Select_priv`) `Select_priv`,
+ MAX(u.`Insert_priv`) `Insert_priv`,
+ MAX(u.`Update_priv`) `Update_priv`,
+ MAX(u.`Delete_priv`) `Delete_priv`,
+ MAX(u.`Create_priv`) `Create_priv`,
+ MAX(u.`Drop_priv`) `Drop_priv`,
+ MAX(u.`Reload_priv`) `Reload_priv`,
+ MAX(u.`Shutdown_priv`) `Shutdown_priv`,
+ MAX(u.`Process_priv`) `Process_priv`,
+ MAX(u.`File_priv`) `File_priv`,
+ MAX(u.`Grant_priv`) `Grant_priv`,
+ MAX(u.`References_priv`) `References_priv`,
+ MAX(u.`Index_priv`) `Index_priv`,
+ MAX(u.`Alter_priv`) `Alter_priv`,
+ MAX(u.`Show_db_priv`) `Show_db_priv`,
+ MAX(u.`Super_priv`) `Super_priv`,
+ MAX(u.`Create_tmp_table_priv`) `Create_tmp_table_priv`,
+ MAX(u.`Lock_tables_priv`) `Lock_tables_priv`,
+ MAX(u.`Execute_priv`) `Execute_priv`,
+ MAX(u.`Repl_slave_priv`) `Repl_slave_priv`,
+ MAX(u.`Repl_client_priv`) `Repl_client_priv`,
+ MAX(u.`Create_view_priv`) `Create_view_priv`,
+ MAX(u.`Show_view_priv`) `Show_view_priv`,
+ MAX(u.`Create_routine_priv`) `Create_routine_priv`,
+ MAX(u.`Alter_routine_priv`) `Alter_routine_priv`,
+ MAX(u.`Create_user_priv`) `Create_user_priv`,
+ MAX(u.`Event_priv`) `Event_priv`,
+ MAX(u.`Trigger_priv`) `Trigger_priv`,
+ MAX(u.`Create_tablespace_priv`) `Create_tablespace_priv`
+ FROM tRoleInherit r
+ JOIN mysql.user u
+ ON u.`User` = r.inheritsFrom
+ AND u.`Host`= vHost
+ GROUP BY r.prefixedRole;
+
+ UPDATE mysql.user u
+ JOIN tUserPriv t
+ ON u.`User` = t.prefixedRole
+ AND u.`Host` = vHost
+ SET
+ u.`Select_priv`
+ = t.`Select_priv`,
+ u.`Insert_priv`
+ = t.`Insert_priv`,
+ u.`Update_priv`
+ = t.`Update_priv`,
+ u.`Delete_priv`
+ = t.`Delete_priv`,
+ u.`Create_priv`
+ = t.`Create_priv`,
+ u.`Drop_priv`
+ = t.`Drop_priv`,
+ u.`Reload_priv`
+ = t.`Reload_priv`,
+ u.`Shutdown_priv`
+ = t.`Shutdown_priv`,
+ u.`Process_priv`
+ = t.`Process_priv`,
+ u.`File_priv`
+ = t.`File_priv`,
+ u.`Grant_priv`
+ = t.`Grant_priv`,
+ u.`References_priv`
+ = t.`References_priv`,
+ u.`Index_priv`
+ = t.`Index_priv`,
+ u.`Alter_priv`
+ = t.`Alter_priv`,
+ u.`Show_db_priv`
+ = t.`Show_db_priv`,
+ u.`Super_priv`
+ = t.`Super_priv`,
+ u.`Create_tmp_table_priv`
+ = t.`Create_tmp_table_priv`,
+ u.`Lock_tables_priv`
+ = t.`Lock_tables_priv`,
+ u.`Execute_priv`
+ = t.`Execute_priv`,
+ u.`Repl_slave_priv`
+ = t.`Repl_slave_priv`,
+ u.`Repl_client_priv`
+ = t.`Repl_client_priv`,
+ u.`Create_view_priv`
+ = t.`Create_view_priv`,
+ u.`Show_view_priv`
+ = t.`Show_view_priv`,
+ u.`Create_routine_priv`
+ = t.`Create_routine_priv`,
+ u.`Alter_routine_priv`
+ = t.`Alter_routine_priv`,
+ u.`Create_user_priv`
+ = t.`Create_user_priv`,
+ u.`Event_priv`
+ = t.`Event_priv`,
+ u.`Trigger_priv`
+ = t.`Trigger_priv`,
+ u.`Create_tablespace_priv`
+ = t.`Create_tablespace_priv`;
+
+ DROP TEMPORARY TABLE tUserPriv;
+
+ -- Copia los privilegios a nivel de esquema
+
+ INSERT INTO mysql.db (
+ `User`,
+ `Host`,
+ `Db`,
+ `Select_priv`,
+ `Insert_priv`,
+ `Update_priv`,
+ `Delete_priv`,
+ `Create_priv`,
+ `Drop_priv`,
+ `Grant_priv`,
+ `References_priv`,
+ `Index_priv`,
+ `Alter_priv`,
+ `Create_tmp_table_priv`,
+ `Lock_tables_priv`,
+ `Create_view_priv`,
+ `Show_view_priv`,
+ `Create_routine_priv`,
+ `Alter_routine_priv`,
+ `Execute_priv`,
+ `Event_priv`,
+ `Trigger_priv`
+ )
+ SELECT
+ r.prefixedRole,
+ vTplHost,
+ t.`Db`,
+ MAX(t.`Select_priv`),
+ MAX(t.`Insert_priv`),
+ MAX(t.`Update_priv`),
+ MAX(t.`Delete_priv`),
+ MAX(t.`Create_priv`),
+ MAX(t.`Drop_priv`),
+ MAX(t.`Grant_priv`),
+ MAX(t.`References_priv`),
+ MAX(t.`Index_priv`),
+ MAX(t.`Alter_priv`),
+ MAX(t.`Create_tmp_table_priv`),
+ MAX(t.`Lock_tables_priv`),
+ MAX(t.`Create_view_priv`),
+ MAX(t.`Show_view_priv`),
+ MAX(t.`Create_routine_priv`),
+ MAX(t.`Alter_routine_priv`),
+ MAX(t.`Execute_priv`),
+ MAX(t.`Event_priv`),
+ MAX(t.`Trigger_priv`)
+ FROM tRoleInherit r
+ JOIN mysql.db t
+ ON t.`User` = r.inheritsFrom
+ AND t.`Host`= vHost
+ GROUP BY r.prefixedRole, t.`Db`;
+
+ -- Copia los privilegios a nivel de tabla
+
+ INSERT INTO mysql.tables_priv (
+ `User`,
+ `Host`,
+ `Db`,
+ `Table_name`,
+ `Grantor`,
+ `Timestamp`,
+ `Table_priv`,
+ `Column_priv`
+ )
+ SELECT
+ r.prefixedRole,
+ vTplHost,
+ t.`Db`,
+ t.`Table_name`,
+ t.`Grantor`,
+ MAX(t.`Timestamp`),
+ GROUP_CONCAT(CONCAT(t.`Table_priv`, ',')),
+ GROUP_CONCAT(CONCAT(t.`Column_priv`, ','))
+ FROM tRoleInherit r
+ JOIN mysql.tables_priv t
+ ON t.`User` = r.inheritsFrom
+ AND t.`Host`= vHost
+ GROUP BY r.prefixedRole, t.`Db`, t.`Table_name`;
+
+ -- Copia los privilegios a nivel de columna
+
+ INSERT INTO mysql.columns_priv (
+ `User`,
+ `Host`,
+ `Db`,
+ `Table_name`,
+ `Column_name`,
+ `Timestamp`,
+ `Column_priv`
+ )
+ SELECT
+ r.prefixedRole,
+ vTplHost,
+ t.`Db`,
+ t.`Table_name`,
+ t.`Column_name`,
+ MAX(t.`Timestamp`),
+ GROUP_CONCAT(CONCAT(t.`Column_priv`, ','))
+ FROM tRoleInherit r
+ JOIN mysql.columns_priv t
+ ON t.`User` = r.inheritsFrom
+ AND t.`Host`= vHost
+ GROUP BY r.prefixedRole, t.`Db`, t.`Table_name`, t.`Column_name`;
+
+ -- Copia los privilegios de los procedimientos
+
+ INSERT IGNORE INTO mysql.procs_priv (
+ `User`,
+ `Host`,
+ `Db`,
+ `Routine_name`,
+ `Routine_type`,
+ `Grantor`,
+ `Timestamp`,
+ `Proc_priv`
+ )
+ SELECT
+ r.prefixedRole,
+ vTplHost,
+ t.`Db`,
+ t.`Routine_name`,
+ t.`Routine_type`,
+ t.`Grantor`,
+ t.`Timestamp`,
+ t.`Proc_priv`
+ FROM tRoleInherit r
+ JOIN mysql.procs_priv t
+ ON t.`User` = r.inheritsFrom
+ AND t.`Host`= vHost;
+
+ -- Libera memoria
+
+ DROP TEMPORARY TABLE
+ tRole,
+ tRoleInherit;
+
+ FLUSH PRIVILEGES;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `roleGetDescendents` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `roleGetDescendents`(vRole INT)
+BEGIN
+/**
+ * Obtiene los identificadores de todos los subroles
+ * implementados por un rol (Incluido el mismo).
+ *
+ * @param vRole Identificador del rol
+ * @table tmp.role Subroles implementados por el rol
+ */
+ DECLARE vIsRoot BOOL;
+
+ DROP TEMPORARY TABLE IF EXISTS
+ tmp.role, parents, childs;
+
+ CREATE TEMPORARY TABLE tmp.role
+ (UNIQUE (id))
+ ENGINE = MEMORY
+ SELECT vRole AS id;
+
+ CREATE TEMPORARY TABLE parents
+ ENGINE = MEMORY
+ SELECT vRole AS id;
+
+ CREATE TEMPORARY TABLE childs
+ LIKE parents;
+
+ REPEAT
+ DELETE FROM childs;
+ INSERT INTO childs
+ SELECT DISTINCT r.inheritsFrom id
+ FROM parents p
+ JOIN roleInherit r ON r.role = p.id
+ LEFT JOIN tmp.role t ON t.id = r.inheritsFrom
+ WHERE t.id IS NULL;
+
+ DELETE FROM parents;
+ INSERT INTO parents
+ SELECT * FROM childs;
+
+ INSERT INTO tmp.role
+ SELECT * FROM childs;
+
+ UNTIL ROW_COUNT() <= 0
+ END REPEAT;
+
+ -- If it is root all the roles are added
+
+ SELECT COUNT(*) > 0 INTO vIsRoot
+ FROM tmp.role
+ WHERE id = 0;
+
+ IF vIsRoot THEN
+ INSERT IGNORE INTO tmp.role (id)
+ SELECT id FROM role;
+ END IF;
+
+ -- Cleaning
+
+ DROP TEMPORARY TABLE
+ parents, childs;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `roleSync` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `roleSync`()
+BEGIN
+/**
+ * Sincroniza la tabla @roleRole con la jerarquía de roles
+ * actual. Este procedimiento debe ser llamado cada vez que
+ * se modifique la tabla @roleInherit para que los cambios
+ * realizados sobre esta sean efectivos.
+ */
+ DECLARE vRoleId INT;
+ DECLARE vDone BOOL;
+
+ DECLARE cur CURSOR FOR
+ SELECT id FROM role;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
+
+ TRUNCATE TABLE roleRole;
+
+ OPEN cur;
+
+ l: LOOP
+ SET vDone = FALSE;
+ FETCH cur INTO vRoleId;
+
+ IF vDone THEN
+ LEAVE l;
+ END IF;
+
+ CALL roleGetDescendents (vRoleId);
+
+ INSERT INTO roleRole (role, inheritsFrom)
+ SELECT vRoleId, id FROM tmp.role;
+
+ DROP TEMPORARY TABLE tmp.role;
+ END LOOP;
+
+ CLOSE cur;
+
+ CALL privSync();
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `userChangePassword` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `userChangePassword`(vOldPassword VARCHAR(255), vPassword VARCHAR(255))
+BEGIN
+/**
+ * Changes the current user password, if user is in recovery
+ * mode ignores the current password.
+ *
+ * @param vOldPassword The current password
+ * @param vPassword The new password
+ */
+ DECLARE vPasswordOk BOOL;
+
+ SELECT `password` = MD5(vOldPassword) OR recoverPass
+ INTO vPasswordOk
+ FROM user WHERE id = account.userGetId();
+
+ IF NOT vPasswordOk THEN
+ SIGNAL SQLSTATE '45000'
+ SET MESSAGE_TEXT = 'Invalid password';
+ END IF;
+
+ CALL userSetPassword (userGetName(), vPassword);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `userCheckName` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `userCheckName`(vUserName VARCHAR(255))
+BEGIN
+/**
+ * Comprueba que el nombre de usuario reune los requisitos
+ * de sintaxis necesarios, en caso contrario lanza una
+ * excepción.
+ * El nombre de usuario solo debe contener letras minúsculas
+ * o, a partir del segundo carácter, números o subguiones.
+ **/
+ IF vUserName NOT REGEXP '^[a-z0-9_]*$' THEN
+ SIGNAL SQLSTATE '45000'
+ SET MESSAGE_TEXT = 'INVALID_USER_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 DROP PROCEDURE IF EXISTS `userCheckPassword` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `userCheckPassword`(vPassword VARCHAR(255))
+BEGIN
+/**
+ * Comprueba si la contraseña cumple los requisitos de seguridad
+ * establecidos. Lanza una excepción si no se cumplen.
+ *
+ * @param vPassword Contraseña a comprobar
+ */
+ DECLARE vChr CHAR(1);
+ DECLARE vPasswordOk TINYINT;
+ DECLARE vI TINYINT DEFAULT 1;
+ DECLARE vNAlpha TINYINT DEFAULT 0;
+ DECLARE vNUpper TINYINT DEFAULT 0;
+ DECLARE vNDigits TINYINT DEFAULT 0;
+ DECLARE vNPunct TINYINT DEFAULT 0;
+
+ WHILE vI <= CHAR_LENGTH(vPassword)
+ DO
+ SET vChr = SUBSTRING(vPassword, vI, 1);
+
+ IF vChr REGEXP '[[:alpha:]]'
+ THEN
+ SET vNAlpha = vNAlpha+1;
+
+ IF vChr REGEXP '[A-Z]'
+ THEN
+ SET vNUpper = vNUpper+1;
+ END IF;
+ ELSEIF vChr REGEXP '[[:digit:]]'
+ THEN
+ SET vNDigits = vNDigits+1;
+ ELSEIF vChr REGEXP '[[:punct:]]'
+ THEN
+ SET vNPunct = vNPunct+1;
+ END IF;
+
+ SET vI = vI+1;
+ END WHILE;
+
+ SELECT
+ CHAR_LENGTH(vPassword) >= length
+ AND vNAlpha >= nAlpha
+ AND vNUpper >= nUpper
+ AND vNDigits >= nDigits
+ AND vNPunct >= nPunct
+ INTO vPasswordOk
+ FROM userPassword LIMIT 1;
+
+ IF NOT vPasswordOk THEN
+ SIGNAL SQLSTATE '45000'
+ SET MESSAGE_TEXT = 'Password does not meet requirements';
+ 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 `userLogin` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `userLogin`(vUserName VARCHAR(255), vPassword VARCHAR(255))
+ READS SQL DATA
+BEGIN
+/**
+ * Logs in using the user credentials.
+ *
+ * @param vUserName The user name
+ * @param vPassword The user password
+ */
+ DECLARE vAuthIsOk BOOLEAN DEFAULT FALSE;
+
+ SELECT COUNT(*) = 1 INTO vAuthIsOk FROM user
+ WHERE name = vUserName
+ AND password = MD5(vPassword)
+ AND active;
+
+ IF vAuthIsOk
+ THEN
+ CALL userLoginWithName (vUserName);
+ ELSE
+ CALL util.throw ('INVALID_CREDENTIALS');
+ 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 `userLoginWithName` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `userLoginWithName`(vUserName VARCHAR(255))
+ READS SQL DATA
+BEGIN
+/**
+ * Logs in using only the user name. This procedure is
+ * intended to be executed by users with a high level
+ * of privileges so that normal users should not have
+ * execute permissions on it
+ *
+ * @param vUserName The user name
+ */
+ DECLARE vUserId INT DEFAULT NULL;
+ DECLARE vKey VARCHAR(255);
+
+ SELECT id INTO vUserId FROM user
+ WHERE name = vUserName;
+
+ SELECT loginKey INTO vKey FROM userConfig;
+
+ SET @userId = vUserId;
+ SET @userName = vUserName;
+ SET @userSignature = util.hmacSha2(256, CONCAT_WS('/', vUserId, vUserName), vKey);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `userLogout` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `userLogout`()
+BEGIN
+/**
+ * Logouts the user.
+ */
+ SET @userId = NULL;
+ SET @userName = NULL;
+ SET @userSignature = 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 `userSetPassword` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `userSetPassword`(vUserName VARCHAR(255), vPassword VARCHAR(255))
+BEGIN
+/**
+ * Cambia la contraseña del usuario pasado como parámetro.
+ * Solo los administradores deberian de tener privilegios de
+ * ejecución sobre el procedimiento ya que no solicita la
+ * contraseña actual del usuario.
+ *
+ * @param vUserName Nombre de usuario
+ * @param vPassword Nueva contraseña
+ */
+ CALL userCheckPassword (vPassword);
+
+ UPDATE user SET
+ password = MD5(vPassword),
+ recoverPass = FALSE
+ WHERE `name` = 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 */ ;
+
+--
+-- Final view structure for view `accountDovecot`
+--
+
+/*!50001 DROP VIEW IF EXISTS `accountDovecot`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `accountDovecot` AS select `u`.`name` AS `name`,`u`.`password` AS `password` from (`user` `u` join `account` `a` on((`a`.`id` = `u`.`id`))) where `u`.`active` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `accountPam`
+--
+
+/*!50001 DROP VIEW IF EXISTS `accountPam`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `accountPam` AS select `u`.`name` AS `name`,`u`.`password` AS `password` from (`user` `u` join `account` `a` on((`u`.`id` = `a`.`id`))) where (`u`.`active` <> 0) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `userRole`
+--
+
+/*!50001 DROP VIEW IF EXISTS `userRole`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `userRole` AS select `r`.`inheritsFrom` AS `id` from (`roleRole` `r` join `user` `u` on((`u`.`role` = `r`.`role`))) where (`u`.`id` = `USERGETID`()) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `userView`
+--
+
+/*!50001 DROP VIEW IF EXISTS `userView`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `userView` AS select `u`.`id` AS `id`,`u`.`name` AS `name`,`u`.`active` AS `active`,`u`.`email` AS `email`,`u`.`nickname` AS `nickname`,`u`.`lang` AS `lang`,`u`.`role` AS `role`,`u`.`recoverPass` AS `recoverPass` from `user` `u` where (`u`.`name` = `account`.`userGetName`()) */
+/*!50002 WITH CASCADED CHECK OPTION */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
+
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
+
+-- Dump completed on 2017-12-27 7:50:17
diff --git a/services/db/localDB01Structure.sql b/services/db/localDB02StructureVn2008.sql
similarity index 54%
rename from services/db/localDB01Structure.sql
rename to services/db/localDB02StructureVn2008.sql
index 284b417dd..1fc6d417a 100644
--- a/services/db/localDB01Structure.sql
+++ b/services/db/localDB02StructureVn2008.sql
@@ -1,8 +1,10 @@
+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: 127.0.0.1 Database: vncontrol
+-- Host: db.verdnatura.es Database: vn2008
-- ------------------------------------------------------
--- Server version 5.6.37
+-- 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 */;
@@ -15,1603 +17,6 @@
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
---
--- Current Database: `vncontrol`
---
-
-CREATE DATABASE /*!32312 IF NOT EXISTS*/ `vncontrol` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
-
-USE `vncontrol`;
-
---
--- Table structure for table `accion`
---
-
-DROP TABLE IF EXISTS `accion`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `accion` (
- `accion_id` int(11) NOT NULL AUTO_INCREMENT,
- `accion` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`accion_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `clientes_match`
---
-
-DROP TABLE IF EXISTS `clientes_match`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `clientes_match` (
- `Id_cliente` int(11) NOT NULL,
- `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!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` (
- `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
- `created` 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 `fallo`
---
-
-DROP TABLE IF EXISTS `fallo`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `fallo` (
- `queja_id` int(10) unsigned NOT NULL,
- `accion_id` int(11) NOT NULL,
- PRIMARY KEY (`queja_id`,`accion_id`),
- KEY `accion` (`accion_id`,`queja_id`),
- KEY `fallo` (`queja_id`),
- CONSTRAINT `accion` FOREIGN KEY (`accion_id`) REFERENCES `accion` (`accion_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 `inter`
---
-
-DROP TABLE IF EXISTS `inter`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `inter` (
- `inter_id` int(11) NOT NULL AUTO_INCREMENT,
- `state_id` tinyint(3) unsigned NOT NULL,
- `fallo_id` int(10) unsigned NOT NULL DEFAULT '21',
- `nota` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
- `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
- `Id_Ticket` int(11) DEFAULT NULL,
- `Id_Trabajador` int(11) DEFAULT NULL,
- `Id_Supervisor` int(11) DEFAULT NULL,
- PRIMARY KEY (`inter_id`),
- KEY `currante` (`Id_Trabajador`),
- KEY `responsable` (`Id_Supervisor`),
- KEY `ticket` (`Id_Ticket`),
- KEY `inter_state` (`state_id`),
- CONSTRAINT `currante` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE,
- CONSTRAINT `inter_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `inter_state` FOREIGN KEY (`state_id`) REFERENCES `vn2008`.`state` (`id`) ON UPDATE CASCADE,
- CONSTRAINT `responsable` FOREIGN KEY (`Id_Supervisor`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE
-) ENGINE=InnoDB AUTO_INCREMENT=11 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 `interBeforeInsert`
-BEFORE INSERT ON `inter` FOR EACH ROW
-BEGIN
-
- DECLARE contados INT;
- DECLARE vSupervisor INT;
-
- SELECT Id_Trabajador INTO vSupervisor FROM vn2008.Trabajadores WHERE user_id = account.userGetId();
-
- SET NEW.Id_Supervisor = IFNULL(vSupervisor,5);
-
- IF NEW.state_id = 5
- THEN
- SELECT count(Id_Ticket) INTO contados
- FROM vncontrol.inter
- WHERE state_id = 5
- AND Id_Ticket = NEW.Id_Ticket
- AND IFNULL(Id_Supervisor,-1) <> vSupervisor
- AND TIMESTAMPADD(SECOND, 60, odbc_date) >= NOW();
-
- IF contados <> 0 THEN
- CALL util.throw ('FALLO_AL_INSERTAR');
- 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 `vncontrol`.`interAfterInsert`
-AFTER INSERT ON `inter` FOR EACH ROW
-BEGIN
- REPLACE vn2008.Tickets_state(Id_Ticket, inter_id,state_name)
- SELECT NEW.Id_Ticket, NEW.inter_id, s.`name` FROM vn2008.state s WHERE s.id = NEW.state_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 `vncontrol`.`interAfterUpdate`
-AFTER UPDATE ON `inter` FOR EACH ROW
-BEGIN
- DECLARE intIdTicket INT;
- DECLARE intInterId INT;
- DECLARE strName VARCHAR(15);
-
- IF (NEW.state_id <> OLD.state_id) THEN
- REPLACE INTO vn2008.Tickets_state(Id_Ticket, inter_id,state_name)
- SELECT NEW.Id_Ticket, NEW.inter_id, s.`name`
- FROM vn2008.state s WHERE s.id = NEW.state_id;
- END IF;
- IF (NEW.Id_Ticket <> OLD.Id_Ticket) THEN
-
- SELECT i.Id_Ticket, i.inter_id, s.`name`
- INTO intIdTicket, intInterId, strName
- FROM vncontrol.inter i
- JOIN vn2008.state s ON i.state_id = s.id
- WHERE Id_Ticket = NEW.Id_Ticket
- ORDER BY odbc_date DESC
- LIMIT 1;
- IF intIdTicket > 0 THEN
- REPLACE INTO vn2008.Tickets_state(Id_Ticket, inter_id,state_name)
- VALUES(intIdTicket, intInterId, strName);
- 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 `vncontrol`.`interAfterDelete`
-AFTER DELETE ON `inter` FOR EACH ROW
-BEGIN
- DECLARE intIdTicket INT;
- DECLARE intInterId INT;
- DECLARE strName VARCHAR(15);
-
- DECLARE CONTINUE HANDLER FOR SQLSTATE '23000'
- BEGIN
- DELETE FROM vn2008.Tickets_state
- WHERE Id_Ticket = OLD.Id_Ticket;
- END;
-
- IF OLD.odbc_date > TIMESTAMPADD(WEEK, -1, CURDATE()) THEN
-
- SELECT i.Id_Ticket, i.inter_id, s.`name`
- INTO intIdTicket, intInterId, strName
- FROM vncontrol.inter i
- JOIN vn2008.state s ON i.state_id = s.id
- WHERE Id_Ticket = OLD.Id_Ticket
- ORDER BY odbc_date DESC
- LIMIT 1;
-
- IF intIdTicket > 0 THEN
- REPLACE INTO vn2008.Tickets_state(Id_Ticket, inter_id,state_name)
- VALUES (intIdTicket, intInterId, strName);
- 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 */ ;
-
---
--- Dumping events for database 'vncontrol'
---
-
---
--- Dumping routines for database 'vncontrol'
---
-/*!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`()
-BEGIN
-
- DECLARE v_date2 DATETIME DEFAULT TIMESTAMPADD(MONTH, -2,CURDATE());
-
- INSERT INTO vncontrol.daily_task_log(state) VALUES('clean START');
-
- DELETE FROM vncontrol.inter WHERE odbc_date <= v_date2;
-
- INSERT INTO vncontrol.daily_task_log(state) 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 `Resumen` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `Resumen`()
-BEGIN
-
-select accion, CodigoTrabajador, semana, Pedidos, Lineas
-from accion
-join
-(
- SELECT * FROM
- (
- select count(*) as Pedidos, semana, Id_Trabajador, accion_id
- from
- (select distinct *
- from
- (
- select vn2008.semana(odbc_date) as semana
- ,Id_Trabajador
- ,accion_id
- ,Id_Ticket
- from vncontrol.inter
- ) sub
- ) sub2
- group by semana, Id_Trabajador, accion_id
- ) subpedidos
-
- inner join
- (
-
- select semana, Id_Trabajador, accion_id, count(*) as Lineas
- from vn2008.Movimientos
- inner join
- (
- select distinct vn2008.semana(odbc_date) as semana, Id_Ticket, Id_Trabajador, accion_id from vncontrol.inter
- ) vnc using(Id_Ticket)
- group by semana, Id_Trabajador, accion_id
-
- ) sublineas using(semana, Id_Trabajador, accion_id)
-
-) sub3 using(accion_id)
-
-join vn2008.Trabajadores using(Id_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 */ ;
-
---
--- Current Database: `edi`
---
-
-CREATE DATABASE /*!32312 IF NOT EXISTS*/ `edi` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
-
-USE `edi`;
-
---
--- Table structure for table `batch`
---
-
-DROP TABLE IF EXISTS `batch`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `batch` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `message_id` int(10) unsigned NOT NULL,
- `type_id` smallint(5) unsigned NOT NULL,
- `buy_edi_id` int(10) DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `type_id` (`type_id`,`buy_edi_id`),
- KEY `message_id` (`message_id`),
- KEY `buy_edi_id` (`buy_edi_id`),
- CONSTRAINT `batch_ibfk_1` FOREIGN KEY (`message_id`) REFERENCES `message` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `batch_ibfk_2` FOREIGN KEY (`buy_edi_id`) REFERENCES `vn2008`.`buy_edi` (`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 `batch_type`
---
-
-DROP TABLE IF EXISTS `batch_type`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `batch_type` (
- `id` mediumint(8) unsigned NOT NULL,
- `description` varchar(50) COLLATE utf8_unicode_ci NOT 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 `bucket`
---
-
-DROP TABLE IF EXISTS `bucket`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `bucket` (
- `bucket_id` int(11) unsigned NOT NULL,
- `bucket_type_id` mediumint(8) unsigned NOT NULL,
- `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
- `x_size` mediumint(8) unsigned NOT NULL,
- `y_size` mediumint(8) unsigned NOT NULL,
- `z_size` mediumint(8) unsigned NOT NULL,
- `entry_date` date DEFAULT NULL,
- `expiry_date` date DEFAULT NULL,
- `change_date_time` datetime DEFAULT NULL,
- PRIMARY KEY (`bucket_id`),
- KEY `group_id` (`y_size`),
- KEY `plant_id` (`x_size`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/VBN020101/CK090916.txt';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `bucket_type`
---
-
-DROP TABLE IF EXISTS `bucket_type`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `bucket_type` (
- `bucket_type_id` mediumint(8) unsigned NOT NULL,
- `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
- `entry_date` date DEFAULT NULL,
- `expiry_date` date DEFAULT NULL,
- `change_date_time` datetime DEFAULT NULL,
- PRIMARY KEY (`bucket_type_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/VBN020101/FB090916.txt';
-/*!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` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
- `log_mail` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Mail where the log information is sent',
- `presale_id` mediumint(8) unsigned DEFAULT NULL,
- `default_kop` int(10) unsigned DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `presale_id` (`presale_id`),
- CONSTRAINT `config_ibfk_1` FOREIGN KEY (`presale_id`) REFERENCES `batch_type` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Configuration parameters';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `feature`
---
-
-DROP TABLE IF EXISTS `feature`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `feature` (
- `item_id` int(11) unsigned NOT NULL,
- `feature_type_id` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
- `feature_value` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
- `entry_date` date NOT NULL,
- `expiry_date` date NOT NULL,
- `change_date_time` datetime NOT NULL,
- PRIMARY KEY (`item_id`,`feature_type_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FF130916.txt';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `file_config`
---
-
-DROP TABLE IF EXISTS `file_config`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `file_config` (
- `file_name` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
- `to_table` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
- `file` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
- `updated` date DEFAULT NULL,
- PRIMARY KEY (`file_name`),
- UNIQUE KEY `to_table` (`to_table`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `ftp_config`
---
-
-DROP TABLE IF EXISTS `ftp_config`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `ftp_config` (
- `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
- `host` varchar(255) CHARACTER SET utf8 NOT NULL,
- `user` varchar(50) CHARACTER SET utf8 NOT NULL,
- `password` varchar(50) CHARACTER SET utf8 NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Configuration parameters';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `genus`
---
-
-DROP TABLE IF EXISTS `genus`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `genus` (
- `genus_id` mediumint(8) unsigned NOT NULL,
- `latin_genus_name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
- `entry_date` date DEFAULT NULL,
- `expiry_date` date DEFAULT NULL,
- `change_date_time` datetime DEFAULT NULL,
- PRIMARY KEY (`genus_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FG130916.txt';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `goodCharacteristic`
---
-
-DROP TABLE IF EXISTS `goodCharacteristic`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `goodCharacteristic` (
- `supplyResponse` varchar(26) COLLATE utf8_unicode_ci NOT NULL,
- `type` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'edi.type',
- `value` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'edi.value',
- PRIMARY KEY (`supplyResponse`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `imap_config`
---
-
-DROP TABLE IF EXISTS `imap_config`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `imap_config` (
- `id` tinyint(3) unsigned NOT NULL,
- `host` varchar(150) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'localhost',
- `user` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `pass` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `clean_period` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'How long the old mails are preserved',
- `success_folder` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL,
- `error_folder` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='IMAP configuration parameters';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `item`
---
-
-DROP TABLE IF EXISTS `item`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `item` (
- `id` int(11) unsigned NOT NULL,
- `product_name` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
- `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
- `plant_id` mediumint(8) unsigned DEFAULT NULL,
- `group_id` int(11) DEFAULT NULL,
- `entry_date` date DEFAULT NULL,
- `expiry_date` date DEFAULT NULL,
- `change_date_time` datetime DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `group_id` (`group_id`),
- KEY `plant_id` (`plant_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FP130916.txt';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `item_feature`
---
-
-DROP TABLE IF EXISTS `item_feature`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `item_feature` (
- `item_id` int(11) NOT NULL,
- `presentation_order` tinyint(11) unsigned NOT NULL,
- `feature` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
- `regulation_type` tinyint(3) unsigned NOT NULL,
- `entry_date` date NOT NULL,
- `expiry_date` date DEFAULT NULL,
- `change_date_time` datetime NOT NULL,
- PRIMARY KEY (`item_id`,`presentation_order`,`entry_date`,`change_date_time`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FY130916.txt';
-/*!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 `item_feature_bi` BEFORE INSERT ON `item_feature` FOR EACH ROW
-BEGIN
- IF NEW.expiry_date = '0000-00-00' THEN
- SET NEW.expiry_date = 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 `item_group`
---
-
-DROP TABLE IF EXISTS `item_group`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `item_group` (
- `group_code` int(11) unsigned NOT NULL,
- `dutch_group_description` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
- `entry_date` date NOT NULL,
- `expiry_date` date NOT NULL,
- `change_date_time` datetime NOT NULL,
- PRIMARY KEY (`group_code`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FO130916.txt';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `item_track`
---
-
-DROP TABLE IF EXISTS `item_track`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `item_track` (
- `item_id` int(10) unsigned NOT NULL,
- `s1` tinyint(3) NOT NULL DEFAULT '0',
- `s2` tinyint(3) NOT NULL DEFAULT '0',
- `s3` tinyint(3) NOT NULL DEFAULT '0',
- `s4` tinyint(3) NOT NULL DEFAULT '0',
- `pac` tinyint(3) NOT NULL DEFAULT '0',
- `cat` tinyint(3) NOT NULL DEFAULT '0',
- `ori` tinyint(3) NOT NULL DEFAULT '0',
- `pro` tinyint(3) NOT NULL DEFAULT '0',
- `package` tinyint(3) NOT NULL DEFAULT '0',
- `s5` tinyint(3) NOT NULL DEFAULT '0',
- `s6` tinyint(3) NOT NULL DEFAULT '0',
- `kop` tinyint(3) NOT NULL DEFAULT '0',
- `sub` tinyint(3) NOT NULL DEFAULT '0',
- PRIMARY KEY (`item_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!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` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `mail` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
- `kop` int(10) unsigned DEFAULT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `mail` (`mail`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='List of allowed mailers';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `message`
---
-
-DROP TABLE IF EXISTS `message`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `message` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `sender_id` int(10) unsigned DEFAULT NULL,
- `mail_id` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
- `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (`id`),
- UNIQUE KEY `mail_id` (`mail_id`),
- KEY `sender_id` (`sender_id`),
- CONSTRAINT `message_ibfk_2` FOREIGN KEY (`sender_id`) REFERENCES `mail` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `param`
---
-
-DROP TABLE IF EXISTS `param`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `param` (
- `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
- `code` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
- `name` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
- `subname` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL,
- `position` tinyint(3) unsigned NOT NULL DEFAULT '1',
- `type` enum('INTEGER','DOUBLE','STRING','DATE','TIME') COLLATE utf8_unicode_ci NOT NULL,
- `required` tinyint(3) unsigned NOT NULL DEFAULT '1',
- PRIMARY KEY (`id`),
- UNIQUE KEY `name` (`name`,`subname`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Parameters to capture of every exchange';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `plant`
---
-
-DROP TABLE IF EXISTS `plant`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `plant` (
- `plant_id` mediumint(8) unsigned NOT NULL,
- `genus_id` mediumint(8) unsigned NOT NULL,
- `specie_id` mediumint(8) unsigned DEFAULT NULL,
- `entry_date` date DEFAULT NULL,
- `expiry_date` date DEFAULT NULL,
- `change_date_time` datetime DEFAULT NULL,
- PRIMARY KEY (`plant_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FT130916.txt';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `specie`
---
-
-DROP TABLE IF EXISTS `specie`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `specie` (
- `specie_id` mediumint(8) unsigned NOT NULL,
- `genus_id` mediumint(8) unsigned NOT NULL,
- `latin_species_name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
- `entry_date` date DEFAULT NULL,
- `expiry_date` date DEFAULT NULL,
- `change_date_time` datetime DEFAULT NULL,
- PRIMARY KEY (`specie_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FS130916.txt';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `supplier`
---
-
-DROP TABLE IF EXISTS `supplier`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `supplier` (
- `supplier_id` int(10) unsigned NOT NULL COMMENT 'FHRegistrationNr',
- `glnAddressCode` varchar(13) CHARACTER SET utf8 DEFAULT NULL,
- `company_name` varchar(70) COLLATE utf8_unicode_ci NOT NULL,
- `entry_date` date NOT NULL,
- `expiry_date` date NOT NULL,
- `change_date_time` datetime NOT NULL,
- PRIMARY KEY (`supplier_id`),
- KEY `glnaddressCodeidx` (`glnAddressCode`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/FEC010104/CC090916.txt';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `supplyResponse`
---
-
-DROP TABLE IF EXISTS `supplyResponse`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `supplyResponse` (
- `id` varchar(26) COLLATE utf8_unicode_ci NOT NULL,
- `marketPlace` varchar(13) COLLATE utf8_unicode_ci NOT NULL,
- `imageReference` varchar(2048) COLLATE utf8_unicode_ci DEFAULT NULL,
- `supplierParty` varchar(13) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'company GLN code',
- `productVnhCode` varchar(7) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Industry Assigned Id',
- `productDescription` varchar(70) COLLATE utf8_unicode_ci DEFAULT NULL,
- `quantity` int(8) DEFAULT NULL,
- `incrementalOrderableQuantity` int(8) DEFAULT NULL,
- `chargeAmount` decimal(10,2) DEFAULT NULL,
- `unitCode` tinyint(2) unsigned DEFAULT NULL,
- `packageQuantity` int(8) DEFAULT NULL,
- `earliestDespatch` datetime DEFAULT NULL,
- `latestDelivery` datetime 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 `type`
---
-
-DROP TABLE IF EXISTS `type`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `type` (
- `type_id` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
- `type_group_id` tinyint(3) unsigned NOT NULL,
- `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
- `entry_date` date NOT NULL,
- `expiry_date` date NOT NULL,
- `change_date_time` datetime NOT NULL,
- PRIMARY KEY (`type_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FE130916.txt';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `value`
---
-
-DROP TABLE IF EXISTS `value`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `value` (
- `type_id` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
- `type_value` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
- `type_description` varchar(70) COLLATE utf8_unicode_ci NOT NULL,
- `entry_date` date NOT NULL,
- `expiry_date` date NOT NULL,
- `change_date_time` datetime NOT NULL,
- PRIMARY KEY (`type_id`,`type_value`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FV130916.txt';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Dumping events for database 'edi'
---
-
---
--- Dumping routines for database 'edi'
---
-/*!50003 DROP PROCEDURE IF EXISTS `batchNew` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `batchNew`(
- vMessage INT
- ,vItem VARCHAR(255)
- ,vType MEDIUMINT
- ,vDeliveryNumber BIGINT
- ,vDate DATE
- ,vHour TIME
- ,vRef INT
- ,vAgj INT
- ,vCat VARCHAR(2)
- ,vPac INT
- ,vSub MEDIUMINT
- ,vKop INT
- ,vPtd VARCHAR(6)
- ,vPro MEDIUMINT
- ,vOrigin VARCHAR(3)
- ,vPtj MEDIUMINT
- ,vQuantiy INT
- ,vPrice DOUBLE
- ,vClock SMALLINT
- ,vS1 VARCHAR(3)
- ,vS2 VARCHAR(3)
- ,vS3 VARCHAR(3)
- ,vS4 VARCHAR(4)
- ,vS5 VARCHAR(3)
- ,vS6 VARCHAR(3)
- ,vK1 SMALLINT
- ,vK2 SMALLINT
- ,vP1 TINYINT
- ,vP2 TINYINT
- ,vAuction SMALLINT
- ,vPackage INT
-)
-BEGIN
-
- DECLARE vEdi INT;
- DECLARE vRewriteKop INT DEFAULT NULL;
- DECLARE vBarcode CHAR(15) DEFAULT NULL;
- DECLARE vIsDuplicated BOOLEAN DEFAULT FALSE;
- DECLARE vUpdateExistent BOOLEAN DEFAULT FALSE;
-
- DECLARE CONTINUE HANDLER FOR 1062
- SET vIsDuplicated = TRUE;
-
-
-
- IF vAgj != 0 AND vAgj IS NOT NULL
- THEN
- SET vBarcode = CONCAT(
- LPAD(vAuction, 2, 0),
- LPAD(IFNULL(vClock, 99), 2, 0),
- LPAD(DAYOFYEAR(vDate), 3, 0),
- IF(vClock IS NULL OR vClock = 99,
- LPAD(vAgj, 7, 0),
- CONCAT(LPAD(vAgj, 5, 0), '01')
- ),
- '0'
- );
- END IF;
-
-
-
- IF vKop IS NULL
- THEN
- SELECT default_kop INTO vKop FROM config;
- END IF;
-
- SELECT e.kop INTO vRewriteKop
- FROM mail e
- JOIN message m ON m.sender_id = e.id
- WHERE m.id = vMessage;
-
- SET vKop = IFNULL(vRewriteKop, vKop);
-
-
-
- INSERT INTO vn2008.buy_edi SET
- barcode = IFNULL(vBarcode, barcode)
- ,delivery_number = vDeliveryNumber
- ,entry_year = YEAR(vDate)
- ,fec = vDate
- ,hor = vHour
- ,ref = vRef
- ,item = vItem
- ,agj = vAgj
- ,cat = vCat
- ,pac = vPac
- ,sub = vSub
- ,kop = vKop
- ,ptd = vPtd
- ,pro = vPro
- ,ori = vOrigin
- ,ptj = vPtj
- ,qty = vQuantiy
- ,pri = vPrice
- ,klo = vClock
- ,s1 = vS1
- ,s2 = vS2
- ,s3 = vS3
- ,s4 = vS4
- ,s5 = vS5
- ,s6 = vS6
- ,k01 = vK1
- ,k02 = vK2
- ,k03 = vP1
- ,k04 = vP2
- ,auction = vAuction
- ,package = vPackage;
-
-
-
-
-
- IF NOT vIsDuplicated
- THEN
- SET vEdi = LAST_INSERT_ID();
- CALL ediLoad (vEdi);
-
- ELSEIF vDeliveryNumber != 0
- AND vDeliveryNumber IS NOT NULL
- THEN
- SELECT id INTO vEdi
- FROM vn2008.buy_edi
- WHERE delivery_number = vDeliveryNumber;
-
- SELECT COUNT(*) = 0 INTO vUpdateExistent
- FROM vn2008.buy_edi e
- JOIN batch b ON b.buy_edi_id = e.id
- JOIN config c
- WHERE e.delivery_number = vDeliveryNumber
- AND b.type_id != c.presale_id;
- END IF;
-
- IF vUpdateExistent
- THEN
- UPDATE vn2008.buy_edi SET
- barcode = IFNULL(vBarcode, barcode)
- ,fec = vDate
- ,hor = vHour
- ,ref = vRef
- ,item = vItem
- ,agj = vAgj
- ,cat = vCat
- ,pac = vPac
- ,sub = vSub
- ,kop = vKop
- ,ptd = vPtd
- ,pro = vPro
- ,ori = vOrigin
- ,ptj = vPtj
- ,qty = vQuantiy
- ,pri = vPrice
- ,klo = vClock
- ,s1 = vS1
- ,s2 = vS2
- ,s3 = vS3
- ,s4 = vS4
- ,s5 = vS5
- ,s6 = vS6
- ,k01 = vK1
- ,k02 = vK2
- ,k03 = vP1
- ,k04 = vP2
- ,auction = vAuction
- ,package = vPackage
- WHERE id = vEdi;
- END IF;
-
-
-
- INSERT INTO batch SET
- message_id = vMessage
- ,type_id = vType
- ,buy_edi_id = vEdi;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `ediLoad` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ediLoad`(vEdi INT)
-BEGIN
- DECLARE vRef INT;
- DECLARE vBuy INT;
- DECLARE vItem INT;
- DECLARE vQty INT;
- DECLARE vPackage INT;
- DECLARE vIsLot BOOLEAN;
-
-
-
- SELECT ref, qty, package INTO vRef, vQty, vPackage
- FROM vn2008.buy_edi e
- LEFT JOIN item i ON e.ref = i.id
- WHERE e.id = vEdi;
-
-
-
- IF vPackage = 800
- THEN
- SET vPackage = 800 + vQty;
-
- INSERT IGNORE INTO vn2008.Cubos SET
- Id_Cubo = vPackage,
- x = 7200 / vQty,
- y = 1;
- ELSE
- INSERT IGNORE INTO vn2008.Cubos (Id_Cubo, X, Y, Z)
- SELECT bucket_id, ROUND(x_size/10), ROUND(y_size/10), ROUND(z_size/10)
- FROM bucket WHERE bucket_id = vPackage;
-
- IF ROW_COUNT() > 0
- THEN
- INSERT INTO vn2008.mail SET
- `subject` = 'Cubo añadido',
- `text` = CONCAT('Se ha añadido el cubo: ', vPackage),
- `to` = 'ekt@verdnatura.es';
- END IF;
- END IF;
-
-
-
- INSERT IGNORE INTO item_track SET
- item_id = vRef;
-
- SELECT c.Id_Compra, c.Id_Article INTO vBuy, vItem
- FROM vn2008.buy_edi e
- JOIN item_track t ON t.item_id = e.ref
- LEFT JOIN vn2008.buy_edi l ON l.ref = e.ref
- LEFT JOIN vn2008.Compres c ON c.buy_edi_id = l.id
- JOIN vn2008.config cfg
- WHERE e.id = vEdi
- AND l.id != vEdi
- AND c.Id_Article != cfg.generic_item
- AND IF(t.s1, l.s1 = e.s1, TRUE)
- AND IF(t.s2, l.s2 = e.s2, TRUE)
- AND IF(t.s3, l.s3 = e.s3, TRUE)
- AND IF(t.s4, l.s4 = e.s4, TRUE)
- AND IF(t.s5, l.s5 = e.s5, TRUE)
- AND IF(t.s6, l.s6 = e.s6, TRUE)
- AND IF(t.kop, l.kop = e.kop, TRUE)
- AND IF(t.pac, l.pac = e.pac, TRUE)
- AND IF(t.cat, l.cat = e.cat, TRUE)
- AND IF(t.ori, l.ori = e.ori, TRUE)
- AND IF(t.pro, l.pro = e.pro, TRUE)
- AND IF(t.sub, l.sub = e.sub, TRUE)
- AND IF(t.package, l.package = e.package, TRUE)
- AND c.Id_Article < 170000
- ORDER BY l.now DESC, c.Id_Compra ASC LIMIT 1;
-
-
-
- IF vItem
- THEN
- SELECT COUNT(*) > 0 INTO vIsLot
- FROM vn2008.Articles a
- LEFT JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id
- WHERE a.Id_Article = vItem
- AND t.`transaction`;
-
-
-
- IF vIsLot
- THEN
- INSERT INTO vn2008.Articles (
- Article
- ,Medida
- ,Categoria
- ,Id_Origen
- ,iva_group_id
- ,Foto
- ,Color
- ,Codintrastat
- ,tipo_id
- ,Tallos
- )
- SELECT
- i.`name`
- ,IFNULL(e.s1, e.pac)
- ,e.cat
- ,IFNULL(o.id, 17)
- ,IFNULL(a.iva_group_id, 1)
- ,a.Foto
- ,a.Color
- ,a.Codintrastat
- ,IFNULL(a.tipo_id, 10)
- ,IF(a.tipo_id = 15, 0, 1)
- FROM vn2008.buy_edi e
- LEFT JOIN item i ON i.id = e.ref
- LEFT JOIN vn2008.Origen o ON o.Abreviatura = e.ori
- LEFT JOIN vn2008.Articles a ON a.Id_Article = vItem
- WHERE e.id = vEdi;
-
- SET vItem = LAST_INSERT_ID();
- END IF;
- END IF;
-
-
-
- INSERT INTO vn2008.Compres
- (
- Id_Entrada
- ,buy_edi_id
- ,Costefijo
- ,Id_Article
- ,grouping
- ,caja
- ,Packing
- ,Cantidad
- ,Productor
- ,Etiquetas
- ,Id_Cubo
- )
- SELECT
- cfg.edi_entry
- ,vEdi
- ,(@t := IF(a.Tallos, a.Tallos, 1)) * e.pri
- ,IFNULL(vItem, cfg.generic_item)
- ,IFNULL(c.grouping, e.pac)
- ,IFNULL(c.caja, TRUE)
- ,@pac := e.pac / @t
- ,@pac * e.qty
- ,s.company_name
- ,e.qty
- ,IFNULL(c.Id_Cubo, e.package)
- FROM vn2008.buy_edi e
- LEFT JOIN vn2008.Compres c ON c.Id_Compra = vBuy
- LEFT JOIN vn2008.Articles a ON a.Id_Article = c.Id_Article
- LEFT JOIN supplier s ON e.pro = s.supplier_id
- JOIN vn2008.config cfg
- WHERE e.id = vEdi
- 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 `messageNew` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `messageNew`(
- vMailId VARCHAR(100)
- ,vSender VARCHAR(150)
- ,OUT vMessageId INT
-)
-BEGIN
-
- DECLARE vSenderId INT;
-
- SELECT id INTO vSenderId FROM mail
- WHERE mail = vSender;
-
- INSERT IGNORE INTO message SET
- sender_id = vSenderId
- ,mail_id = vMailId;
-
- SET vMessageId = 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 `__batch_new` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `__batch_new`(
- v_message INT
- ,v_type MEDIUMINT
- ,v_delivery_number BIGINT
- ,v_fec DATE
- ,v_hor TIME
- ,v_ref INT
- ,v_agj INT
- ,v_cat VARCHAR(2)
- ,v_pac INT
- ,v_sub MEDIUMINT
- ,v_kop INT
- ,v_ptd VARCHAR(6)
- ,v_pro MEDIUMINT
- ,v_ori VARCHAR(3)
- ,v_ptj MEDIUMINT
- ,v_qty INT
- ,v_pri DOUBLE
- ,v_klo SMALLINT
- ,v_s1 VARCHAR(3)
- ,v_s2 VARCHAR(3)
- ,v_s3 VARCHAR(3)
- ,v_s4 VARCHAR(4)
- ,v_s5 VARCHAR(3)
- ,v_s6 VARCHAR(3)
- ,v_k1 SMALLINT
- ,v_k2 SMALLINT
- ,v_p1 TINYINT
- ,v_p2 TINYINT
- ,v_auction SMALLINT
- ,v_package INT
-)
-BEGIN
-
-
- DECLARE v_edi INT;
- DECLARE v_barcode CHAR(15) DEFAULT NULL;
- DECLARE v_is_duplicated BOOLEAN DEFAULT FALSE;
- DECLARE v_update_existent BOOLEAN DEFAULT FALSE;
-
- DECLARE CONTINUE HANDLER FOR 1062
- SET v_is_duplicated = TRUE;
-
-
-
- IF v_agj != 0 AND v_agj IS NOT NULL
- THEN
- SET v_barcode = CONCAT(
- LPAD(v_auction, 2, 0),
- LPAD(IFNULL(v_klo, 99), 2, 0),
- LPAD(DAYOFYEAR(v_fec), 3, 0),
- IF(v_klo IS NULL OR v_klo = 99,
- LPAD(v_agj, 7, 0),
- CONCAT(LPAD(v_agj, 5, 0), '01')
- ),
- '0'
- );
- END IF;
-
- IF v_kop IS NULL
- THEN
- SELECT default_kop INTO v_kop FROM config;
- END IF;
-
-
-
- INSERT INTO vn2008.buy_edi SET
- barcode = IFNULL(v_barcode, barcode)
- ,delivery_number = v_delivery_number
- ,entry_year = YEAR(v_fec)
- ,fec = v_fec
- ,hor = v_hor
- ,ref = v_ref
- ,agj = v_agj
- ,cat = v_cat
- ,pac = v_pac
- ,sub = v_sub
- ,kop = v_kop
- ,ptd = v_ptd
- ,pro = v_pro
- ,ori = v_ori
- ,ptj = v_ptj
- ,qty = v_qty
- ,pri = v_pri
- ,klo = v_klo
- ,s1 = v_s1
- ,s2 = v_s2
- ,s3 = v_s3
- ,s4 = v_s4
- ,s5 = v_s5
- ,s6 = v_s6
- ,k01 = v_k1
- ,k02 = v_k2
- ,k03 = v_p1
- ,k04 = v_p2
- ,auction = v_auction
- ,package = v_package;
-
-
-
-
-
- IF NOT v_is_duplicated
- THEN
- SET v_edi = LAST_INSERT_ID();
- CALL edi_load (v_edi);
-
- ELSEIF v_delivery_number != 0
- AND v_delivery_number IS NOT NULL
- THEN
- SELECT id INTO v_edi
- FROM vn2008.buy_edi
- WHERE delivery_number = v_delivery_number;
-
- SELECT COUNT(*) = 0 INTO v_update_existent
- FROM vn2008.buy_edi e
- JOIN batch b ON b.buy_edi_id = e.id
- JOIN config c
- WHERE e.delivery_number = v_delivery_number
- AND b.type_id != c.presale_id;
- END IF;
-
- IF v_update_existent
- THEN
- UPDATE vn2008.buy_edi SET
- barcode = IFNULL(v_barcode, barcode)
- ,fec = v_fec
- ,hor = v_hor
- ,ref = v_ref
- ,agj = v_agj
- ,cat = v_cat
- ,pac = v_pac
- ,sub = v_sub
- ,kop = v_kop
- ,ptd = v_ptd
- ,pro = v_pro
- ,ori = v_ori
- ,ptj = v_ptj
- ,qty = v_qty
- ,pri = v_pri
- ,klo = v_klo
- ,s1 = v_s1
- ,s2 = v_s2
- ,s3 = v_s3
- ,s4 = v_s4
- ,s5 = v_s5
- ,s6 = v_s6
- ,k01 = v_k1
- ,k02 = v_k2
- ,k03 = v_p1
- ,k04 = v_p2
- ,auction = v_auction
- ,package = v_package
- WHERE id = v_edi;
- END IF;
-
-
-
- INSERT INTO batch SET
- message_id = v_message
- ,type_id = v_type
- ,buy_edi_id = v_edi;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `__edi_load` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `__edi_load`(v_edi INT)
-BEGIN
- DECLARE v_ref INT;
- DECLARE v_buy INT;
- DECLARE v_item INT;
- DECLARE v_qty INT;
- DECLARE v_package INT;
- DECLARE v_is_lot BOOLEAN;
-
-
-
- SELECT ref, qty, package INTO v_ref, v_qty, v_package
- FROM vn2008.buy_edi e
- LEFT JOIN item i ON e.ref = i.id
- WHERE e.id = v_edi;
-
-
-
- IF v_package = 800
- THEN
- SET v_package = 800 + v_qty;
-
- INSERT IGNORE INTO vn2008.Cubos SET
- Id_Cubo = v_package,
- x = 7200 / v_qty,
- y = 1;
- ELSE
- INSERT IGNORE INTO vn2008.Cubos (Id_Cubo, X, Y, Z)
- SELECT bucket_id, ROUND(x_size/10), ROUND(y_size/10), ROUND(z_size/10)
- FROM bucket WHERE bucket_id = v_package;
-
- IF ROW_COUNT() > 0
- THEN
- INSERT INTO vn2008.mail SET
- `subject` = 'Cubo añadido',
- `text` = CONCAT('Se ha añadido el cubo: ', v_package),
- `to` = 'ekt@verdnatura.es';
- END IF;
- END IF;
-
-
-
- INSERT IGNORE INTO item_track SET
- item_id = v_ref;
-
- SELECT c.Id_Compra, c.Id_Article INTO v_buy, v_item
- FROM vn2008.buy_edi e
- JOIN item_track t ON t.item_id = e.ref
- LEFT JOIN vn2008.buy_edi l ON l.ref = e.ref
- LEFT JOIN vn2008.Compres c ON c.buy_edi_id = l.id
- JOIN vn2008.config cfg
- WHERE e.id = v_edi
- AND l.id != v_edi
- AND c.Id_Article != cfg.generic_item
- AND IF(t.s1, l.s1 = e.s1, TRUE)
- AND IF(t.s2, l.s2 = e.s2, TRUE)
- AND IF(t.s3, l.s3 = e.s3, TRUE)
- AND IF(t.s4, l.s4 = e.s4, TRUE)
- AND IF(t.s5, l.s5 = e.s5, TRUE)
- AND IF(t.s6, l.s6 = e.s6, TRUE)
- AND IF(t.kop, l.kop = e.kop, TRUE)
- AND IF(t.pac, l.pac = e.pac, TRUE)
- AND IF(t.cat, l.cat = e.cat, TRUE)
- AND IF(t.ori, l.ori = e.ori, TRUE)
- AND IF(t.pro, l.pro = e.pro, TRUE)
- AND IF(t.sub, l.sub = e.sub, TRUE)
- AND IF(t.package, l.package = e.package, TRUE)
- AND c.Id_Article < 170000
- ORDER BY l.now DESC, c.Id_Compra ASC LIMIT 1;
-
-
-
- IF v_item
- THEN
- SELECT COUNT(*) > 0 INTO v_is_lot
- FROM vn2008.Articles a
- LEFT JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id
- WHERE a.Id_Article = v_item
- AND t.`transaction`;
-
-
-
- IF v_is_lot
- THEN
- INSERT INTO vn2008.Articles (
- Article
- ,Medida
- ,Categoria
- ,Id_Origen
- ,iva_group_id
- ,Foto
- ,Color
- ,Codintrastat
- ,tipo_id
- ,Tallos
- )
- SELECT
- i.`name`
- ,IFNULL(e.s1, e.pac)
- ,e.cat
- ,IFNULL(o.id, 17)
- ,IFNULL(a.iva_group_id, 1)
- ,a.Foto
- ,a.Color
- ,a.Codintrastat
- ,IFNULL(a.tipo_id, 10)
- ,IF(a.tipo_id = 15, 0, 1)
- FROM vn2008.buy_edi e
- LEFT JOIN item i ON i.id = e.ref
- LEFT JOIN vn2008.Origen o ON o.Abreviatura = e.ori
- LEFT JOIN vn2008.Articles a ON a.Id_Article = v_item
- WHERE e.id = v_edi;
-
- SET v_item = LAST_INSERT_ID();
- END IF;
- END IF;
-
-
-
- INSERT INTO vn2008.Compres
- (
- Id_Entrada
- ,buy_edi_id
- ,Costefijo
- ,Id_Article
- ,grouping
- ,caja
- ,Packing
- ,Cantidad
- ,Productor
- ,Etiquetas
- ,Id_Cubo
- )
- SELECT
- cfg.edi_entry
- ,v_edi
- ,(@t := IF(a.Tallos, a.Tallos, 1)) * e.pri
- ,IFNULL(v_item, cfg.generic_item)
- ,IFNULL(c.grouping, e.pac)
- ,IFNULL(c.caja, TRUE)
- ,@pac := e.pac / @t
- ,@pac * e.qty
- ,s.company_name
- ,e.qty
- ,IFNULL(c.Id_Cubo, e.package)
- FROM vn2008.buy_edi e
- LEFT JOIN vn2008.Compres c ON c.Id_Compra = v_buy
- LEFT JOIN vn2008.Articles a ON a.Id_Article = c.Id_Article
- LEFT JOIN supplier s ON e.pro = s.supplier_id
- JOIN vn2008.config cfg
- WHERE e.id = v_edi
- 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 `__message_new` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `__message_new`(
- v_mail_id VARCHAR(100)
- ,v_sender VARCHAR(150)
- ,OUT v_message_id INT
-)
-BEGIN
-
-
- DECLARE v_sender_id INT;
-
- SELECT id INTO v_sender_id FROM mail
- WHERE mail = v_sender;
-
- INSERT IGNORE INTO message SET
- sender_id = v_sender_id
- ,mail_id = v_mail_id;
-
- SET v_message_id = 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 */ ;
-
---
--- Current Database: `vn2008`
---
-
-CREATE DATABASE /*!32312 IF NOT EXISTS*/ `vn2008` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
-
-USE `vn2008`;
-
--
-- Table structure for table `Agencias`
--
@@ -1638,7 +43,7 @@ CREATE TABLE `Agencias` (
PRIMARY KEY (`Id_Agencia`),
KEY `Agencias` (`Agencia`),
KEY `Vista` (`Vista`)
-) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=1103 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -1657,7 +62,7 @@ CREATE TABLE `Agencias_dits` (
`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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=13306 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -1739,7 +144,7 @@ CREATE TABLE `Articles` (
`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 ',
+ `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`),
@@ -1757,7 +162,7 @@ CREATE TABLE `Articles` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -1941,7 +346,7 @@ CREATE TABLE `Articles_dits` (
KEY `fgkey1_idx` (`idaccion_dits`),
KEY `fgkey2_idx` (`Id_Ticket`),
KEY `fgkey3_idx` (`Id_Trabajador`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=19575 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -1960,7 +365,7 @@ CREATE TABLE `Articles_nicho` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -1974,7 +379,7 @@ 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
@@ -2036,7 +441,7 @@ 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
@@ -2186,7 +591,7 @@ CREATE TABLE `Bancos_poliza` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lineas de credito asociadas a cuentas corrientes';
+) 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 */;
--
@@ -2243,7 +648,7 @@ CREATE TABLE `Cajas` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -2368,7 +773,7 @@ CREATE TABLE `Clientes` (
`invoiceByAddress` tinyint(1) DEFAULT '0',
`cplusTerIdNifFk` int(11) NOT NULL DEFAULT '1',
`isCreatedAsServed` tinyint(1) DEFAULT '0',
- `hasInvoiceSimplified` 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`),
@@ -2382,7 +787,6 @@ CREATE TABLE `Clientes` (
KEY `Telefono` (`telefono`),
KEY `movil` (`movil`),
KEY `tipos_de_cliente_idx` (`clientes_tipo_id`),
- KEY `cpostcode_fk_idx` (`postcode_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,
@@ -2390,11 +794,10 @@ CREATE TABLE `Clientes` (
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 `Clientes_postcode` FOREIGN KEY (`postcode_id`) REFERENCES `postcodeKK` (`postcode_id`) ON DELETE SET NULL 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=13 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -2409,6 +812,17 @@ DELIMITER ;;
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);
@@ -2468,8 +882,17 @@ DELIMITER ;;
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);
@@ -2483,7 +906,7 @@ BEGIN
CALL pbx.phoneIsValid (NEW.fax);
END IF;
-
+ -- Actualiza el crédito
SELECT Id_Trabajador INTO vEmployee
FROM Trabajadores WHERE user_id = account.userGetId();
@@ -2500,7 +923,7 @@ BEGIN
Id_Trabajador = vEmployee;
END IF;
-
+ -- Avisar al comercial si ha llegado la documentación sepa/core
IF NEW.sepavnl AND !OLD.sepavnl THEN
SET vText = 'Sepa de VNL';
@@ -2553,7 +976,7 @@ CREATE TABLE `Clientes_cedidos` (
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 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';
+) 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 */;
--
@@ -2574,7 +997,7 @@ CREATE TABLE `Clientes_dits` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=70647 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -2593,7 +1016,7 @@ CREATE TABLE `Clientes_empresa` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Empresa por defecto para crear los tickets';
+) 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 */;
--
@@ -2674,7 +1097,7 @@ CREATE TABLE `Colas` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=1272 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -2756,7 +1179,7 @@ CREATE TABLE `Compres` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC;
+) 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 */ ;
@@ -2823,7 +1246,7 @@ DELIMITER ;;
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));
@@ -3008,7 +1431,7 @@ CREATE TABLE `Compres_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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=14728 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -3047,14 +1470,12 @@ CREATE TABLE `Consignatarios` (
KEY `province_id` (`province_id`),
KEY `telefono` (`telefono`),
KEY `movil` (`movil`),
- KEY `Consignatarios_postcode_idx` (`postcode_id`),
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 `Consignatarios_postcode` FOREIGN KEY (`postcode_id`) REFERENCES `postcodeKK` (`postcode_id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `address_customer_id` FOREIGN KEY (`Id_cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE
-) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -3173,7 +1594,7 @@ BEGIN
END IF;
END IF;
-
+ -- Recargos de equivalencia distintos implican facturacion por consignatario
IF NEW.isEqualizated != OLD.isEqualizated THEN
IF
@@ -3238,7 +1659,7 @@ CREATE TABLE `Contactos` (
PRIMARY KEY (`Id_Contacto`),
KEY `Telefono` (`Telefono`),
KEY `Movil` (`Movil`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -3367,7 +1788,7 @@ CREATE TABLE `Cubos_Retorno` (
`Vacio` double NOT NULL DEFAULT '0',
`Lleno` double NOT NULL DEFAULT '0',
PRIMARY KEY (`idCubos_Retorno`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -3392,7 +1813,7 @@ CREATE TABLE `Enlaces Facturas` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=23889 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -3433,7 +1854,7 @@ CREATE TABLE `Entradas` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='InnoDB free: 88064 kB; (`Id_Proveedor`) REFER `vn2008/Provee';
+) 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 */ ;
@@ -3498,6 +1919,15 @@ BEGIN
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 */ ;
@@ -3517,6 +1947,7 @@ DELIMITER ;;
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 */ ;
@@ -3553,7 +1984,7 @@ DROP TABLE IF EXISTS `Entradas_Auto`;
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 UPDATE CASCADE
+ 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 */;
@@ -3579,7 +2010,7 @@ CREATE TABLE `Entradas_dits` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=2456079 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -3597,7 +2028,7 @@ CREATE TABLE `Entradas_kop` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona las entradas con los origenes de compra';
+) 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 */;
--
@@ -3685,7 +2116,7 @@ CREATE TABLE `Equipos` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=127 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -3704,7 +2135,7 @@ CREATE TABLE `Espionajes` (
`Id_Equipo` int(11) DEFAULT NULL,
PRIMARY KEY (`idEspionaje`),
KEY `index` (`Id_Trabajador`,`Fecha`)
-) ENGINE=MyISAM AUTO_INCREMENT=75646 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=MyISAM AUTO_INCREMENT=75648 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -3718,7 +2149,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -3766,7 +2197,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -3840,7 +2271,7 @@ CREATE TABLE `Facturas` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -3853,14 +2284,14 @@ CREATE TABLE `Facturas` (
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;
@@ -3879,7 +2310,7 @@ BEGIN
WHERE Serie LIKE NEW.Serie
AND ((Year(NEW.Fecha) = Year(Fecha)
AND length(Id_Factura) > 6
- AND empresa_id = NEW.empresa_id) );
+ AND empresa_id = NEW.empresa_id) /*OR (NEW.Serie LIKE 'B' AND length(Id_Factura) > 7)*/);
ELSE
@@ -3887,7 +2318,7 @@ BEGIN
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;
@@ -3898,7 +2329,33 @@ 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 */ ;
@@ -3989,7 +2446,7 @@ CREATE TABLE `Forms` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`titulo` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -4032,7 +2489,7 @@ CREATE TABLE `Greuges` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=FIXED;
+) 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 */ ;
@@ -4072,7 +2529,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -4089,7 +2546,7 @@ CREATE TABLE `Grupos` (
`observation_type_id` tinyint(3) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `name` (`name`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -4230,7 +2687,7 @@ CREATE TABLE `Movimientos` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -4356,7 +2813,6 @@ CREATE TABLE `Movimientos_componentes` (
`Valor` double NOT NULL,
`greuge` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`Id_Movimiento`,`Id_Componente`),
- KEY `fk_comp_mov_idx` (`Id_Movimiento`),
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
@@ -4380,7 +2836,7 @@ CREATE TABLE `Movimientos_mark` (
`Id_Movimiento_mark` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`Id_Movimiento_mark`),
KEY `Id_Movimiento` (`Id_Movimiento`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=8792994 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -4450,7 +2906,7 @@ CREATE TABLE `Ordenes` (
KEY `Id_Comprador` (`CodCOMPRADOR`),
KEY `Id_Movimiento` (`Id_Movimiento`),
KEY `Id_Vendedor` (`CodVENDEDOR`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=25397 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -4473,7 +2929,7 @@ CREATE TABLE `Origen` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -4496,7 +2952,7 @@ CREATE TABLE `Pagares` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=2834 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -4518,7 +2974,7 @@ CREATE TABLE `Paises` (
`geoFk` int(11) DEFAULT NULL,
PRIMARY KEY (`Id`),
KEY `Id_Paisreal` (`Id_Paisreal`)
-) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=68 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -4559,7 +3015,7 @@ CREATE TABLE `PreciosEspeciales` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=690 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -4617,14 +3073,12 @@ CREATE TABLE `Proveedores` (
KEY `pay_met_id` (`pay_met_id`),
KEY `province_id` (`province_id`),
KEY `pay_dem_id` (`pay_dem_id`),
- KEY `postcode_fk_idx` (`postcode_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 `postcode_fk` FOREIGN KEY (`postcode_id`) REFERENCES `postcodeKK` (`postcode_id`) ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT `province_id` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=2393 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -4643,14 +3097,28 @@ CREATE TABLE `Proveedores_account` (
`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) NOT NULL,
+ `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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */;
--
@@ -4683,7 +3151,7 @@ CREATE TABLE `Proveedores_escritos` (
`escrito` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
`informe` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -4727,7 +3195,7 @@ CREATE TABLE `Recibos` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -4818,7 +3286,7 @@ CREATE TABLE `Relaciones` (
KEY `Id_Contacto` (`Id_Contacto`),
KEY `Id_Proveedor` (`Id_Proveedor`),
KEY `Id_Cliente` (`Id_Cliente`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=2573 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -4838,7 +3306,7 @@ CREATE TABLE `Remesas` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=985 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -4893,7 +3361,7 @@ CREATE TABLE `Rutas` (
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=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -4908,14 +3376,14 @@ DELIMITER ;;
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;
@@ -4955,7 +3423,7 @@ CREATE TABLE `Rutas_Master` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=48 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -4980,7 +3448,32 @@ CREATE TABLE `Rutas_dits` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */;
--
@@ -5021,7 +3514,7 @@ CREATE TABLE `Saldos_Prevision` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Aqui ponemos los gastos e ingresos pendientes de introducir ';
+) 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 */;
--
@@ -5056,7 +3549,7 @@ CREATE TABLE `Split_lines` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=309585 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -5074,7 +3567,7 @@ CREATE TABLE `Splits` (
`Notas` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`Id_Split`),
KEY `Id_Entrada` (`Id_Entrada`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=36069 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -5102,7 +3595,7 @@ CREATE TABLE `Stockcontrol` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=23181 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -5153,13 +3646,13 @@ CREATE TABLE `Tickets` (
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_10` FOREIGN KEY (`Factura`) REFERENCES `Facturas` (`Id_Factura`) ON DELETE SET NULL 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
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+ 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 */ ;
@@ -5173,7 +3666,25 @@ 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 */ ;
@@ -5192,7 +3703,24 @@ 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 */ ;
@@ -5223,7 +3751,7 @@ BEGIN
SET vEmployee = 20;
END IF;
-
+ -- Comprobación de VIES
IF NEW.empresa_id <> OLD.empresa_id THEN
SELECT CEE INTO vIsCee
@@ -5231,7 +3759,7 @@ BEGIN
INNER JOIN Paises p ON p.Id = pr.pais_id
WHERE Id_Proveedor = NEW.empresa_id;
- SELECT VIES INTO vHasVies
+ SELECT isVies INTO vHasVies
FROM vn.`client`
WHERE id = OLD.Id_Cliente;
@@ -5269,6 +3797,14 @@ 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 ;
@@ -5299,7 +3835,7 @@ CREATE TABLE `Tickets_dits` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=56280004 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -5348,7 +3884,7 @@ CREATE TABLE `Tickets_turno` (
`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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=1713122 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -5397,7 +3933,7 @@ CREATE TABLE `Tipos` (
`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 la densidad en kg/m3 para el calculo de los portes aereos',
+ `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',
@@ -5411,7 +3947,7 @@ CREATE TABLE `Tipos` (
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 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.';
+) 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 */ ;
@@ -5423,7 +3959,7 @@ CREATE TABLE `Tipos` (
/*!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);
@@ -5454,7 +3990,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -5465,12 +4001,12 @@ 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,
- `Id_Trabajador` int(11) NOT NULL AUTO_INCREMENT,
`extension` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`sub` int(11) unsigned DEFAULT NULL,
`user` varchar(20) CHARACTER SET utf8 DEFAULT NULL,
@@ -5498,7 +4034,7 @@ CREATE TABLE `Trabajadores` (
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=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -5507,21 +4043,16 @@ CREATE TABLE `Trabajadores` (
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = '' */ ;
+/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`Trabajadores_BEFORE_INSERT` BEFORE INSERT ON `Trabajadores` FOR EACH ROW
-
-begin
-
-IF NEW.password = '' THEN
-
- SET NEW.password = 'FALLO';
-
- END IF;
-
-
-
-end */;;
+/*!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 */ ;
@@ -5534,21 +4065,16 @@ DELIMITER ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = '' */ ;
+/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`Trabajadores_BEFORE_UPDATE` BEFORE UPDATE ON `Trabajadores` FOR EACH ROW
-
-begin
-
-IF NEW.password = '' THEN
-
- SET NEW.password = 'FALLO';
-
- END IF;
-
-
-
-end */;;
+/*!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 */ ;
@@ -5635,7 +4161,7 @@ CREATE TABLE `Vehiculos` (
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=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=361 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -5661,7 +4187,7 @@ CREATE TABLE `Vehiculos_consumo` (
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 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';
+) 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 */;
--
@@ -5694,7 +4220,7 @@ CREATE TABLE `Vistas` (
`code` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`vista_id`),
UNIQUE KEY `code` (`code`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -5773,7 +4299,7 @@ CREATE TABLE `XDiario` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=3121688 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -5848,7 +4374,7 @@ CREATE TABLE `XDiario_KK` (
`FECHA_RT` date DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `empresa_id` (`empresa_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -5885,7 +4411,7 @@ CREATE TABLE `accion_dits` (
`accion` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`idaccion_dits`),
UNIQUE KEY `accion_UNIQUE` (`accion`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=166 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -5910,7 +4436,7 @@ CREATE TABLE `account_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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -5973,7 +4499,7 @@ CREATE TABLE `account_detail` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=70 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -5987,7 +4513,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6005,7 +4531,7 @@ CREATE TABLE `accumulatorsReadingDate` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=269 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6048,7 +4574,7 @@ CREATE TABLE `agency` (
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=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -6094,7 +4620,7 @@ CREATE TABLE `agency_hour` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -6189,7 +4715,7 @@ CREATE TABLE `agency_weekday_bonus` (
`zona` tinyint(4) DEFAULT NULL,
`bonus` decimal(10,2) NOT NULL DEFAULT '0.00',
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=92 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6203,7 +4729,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6259,7 +4785,7 @@ CREATE TABLE `albaran` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=1920 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6291,7 +4817,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6322,6 +4848,7 @@ CREATE TABLE `awb` (
`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`),
@@ -6329,7 +4856,7 @@ CREATE TABLE `awb` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -6440,7 +4967,7 @@ CREATE TABLE `awb_component_template` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=400 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6454,7 +4981,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT=' ';
+) ENGINE=InnoDB AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT=' ';
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6473,7 +5000,7 @@ CREATE TABLE `awb_gestdoc` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=1988 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6528,7 +5055,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT=' ';
+) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT=' ';
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6572,7 +5099,7 @@ CREATE TABLE `balance_nest_tree` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`Id_Gasto` text COLLATE utf8_unicode_ci,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=381 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6591,7 +5118,7 @@ CREATE TABLE `barcodes` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=33147 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6605,7 +5132,7 @@ 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 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';
+) 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 */;
--
@@ -6625,7 +5152,7 @@ CREATE TABLE `botanic_export` (
PRIMARY KEY (`botanic_export_id`),
KEY `Id_Paises` (`Id_Paises`),
CONSTRAINT `botanic_export_ibfk_1` FOREIGN KEY (`Id_Paises`) REFERENCES `Paises` (`Id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Especifica los generos y especies prohibidos en paises';
+) 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 */ ;
@@ -6659,7 +5186,7 @@ CREATE TABLE `businessReasonEnd` (
`id` tinyint(3) NOT NULL AUTO_INCREMENT,
`reason` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6731,7 +5258,7 @@ CREATE TABLE `buy_edi` (
KEY `pro` (`pro`),
KEY `kop` (`kop`),
KEY `barcode` (`barcode`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=620925 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6790,7 +5317,7 @@ CREATE TABLE `call_information` (
`Id_Cliente` int(11) NOT NULL,
`fecha` date NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=164 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6804,7 +5331,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -6883,7 +5410,7 @@ 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=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Canal por el que nos ha conocido un cliente y se ha dado de';
+) 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 */;
--
@@ -6920,7 +5447,7 @@ CREATE TABLE `city` (
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=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -6985,7 +5512,7 @@ CREATE TABLE `cl_act` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Acciones en respuesta a las reclamaciones';
+) 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 */;
--
@@ -7019,7 +5546,7 @@ CREATE TABLE `cl_cau` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Causas de las reclamaciones';
+) 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 */;
--
@@ -7033,7 +5560,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Consecuencias de los motivos';
+) 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 */;
--
@@ -7047,7 +5574,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Departamentos para las quejas';
+) 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 */;
--
@@ -7073,7 +5600,7 @@ CREATE TABLE `cl_det` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de las reclamaciones';
+) 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 */;
--
@@ -7087,7 +5614,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Método por el cual el cliente nos devuelve la mercancía';
+) 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 */;
--
@@ -7101,7 +5628,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Estados posibles de las reclamaciones';
+) 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 */;
--
@@ -7130,7 +5657,7 @@ CREATE TABLE `cl_main` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Reclamaciones, tabla principal';
+) ENGINE=InnoDB AUTO_INCREMENT=44214 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Reclamaciones, tabla principal';
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -7144,7 +5671,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Motivos de las fallos';
+) 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 */;
--
@@ -7158,7 +5685,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Peticiones de los cliente en relacion a las quejas';
+) 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 */;
--
@@ -7172,7 +5699,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queja por linea de las reclamaciones';
+) 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 */;
--
@@ -7187,7 +5714,7 @@ CREATE TABLE `cl_res` (
`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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Responsables de las causas';
+) 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 */;
--
@@ -7201,7 +5728,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Solucion ofrecida a la reclamación';
+) 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 */;
--
@@ -7243,7 +5770,7 @@ CREATE TABLE `client_observation` (
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=12 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket';
+) 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 */;
--
@@ -7311,7 +5838,7 @@ CREATE TABLE `clientes_tipo` (
`tipo` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`clientes_tipo_id`),
UNIQUE KEY `code_UNIQUE` (`code`)
-) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Establece categorias para poder agrupar las ventas';
+) 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 */;
--
@@ -7407,7 +5934,7 @@ CREATE TABLE `consignatarios_observation` (
`text` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`consignatarios_observation_id`),
UNIQUE KEY `Id_Consigna` (`Id_Consigna`,`observation_type_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de los consignatarios';
+) 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 */;
--
@@ -7421,7 +5948,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -7435,7 +5962,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Define el orden en que se imprimen los F5';
+) 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 */;
--
@@ -7451,7 +5978,7 @@ CREATE TABLE `cooler_path_detail` (
`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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=94 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -7468,7 +5995,7 @@ CREATE TABLE `cp` (
`zone_id` smallint(6) DEFAULT NULL,
`town` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`cp_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relacio de codis postals i el municipi al qual se asigna';
+) 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 */;
--
@@ -7486,8 +6013,10 @@ CREATE TABLE `credit` (
`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=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=57446 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -7508,7 +6037,7 @@ CREATE TABLE `credit_card` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=956 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -7526,7 +6055,7 @@ CREATE TABLE `cyc` (
PRIMARY KEY (`cyc_id`),
KEY `Cliente` (`Id_Cliente`),
CONSTRAINT `Cliente` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalla los clientes que estan clasificados en Credito y Cau';
+) 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 */;
--
@@ -7595,7 +6124,7 @@ CREATE TABLE `department` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -7612,7 +6141,7 @@ CREATE TABLE `device` (
PRIMARY KEY (`device_id`),
UNIQUE KEY `device_id_UNIQUE` (`device_id`),
UNIQUE KEY `sn_UNIQUE` (`sn`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=158 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -7643,6 +6172,23 @@ CREATE TABLE `dhl` (
) 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`
--
@@ -7654,7 +6200,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -7823,7 +6369,7 @@ CREATE TABLE `edi_testigos` (
`field` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
`testigo` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -7922,7 +6468,7 @@ 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=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -7934,15 +6480,14 @@ DROP TABLE IF EXISTS `entity`;
/*!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,
+ `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 `entity_id_UNIQUE` (`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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Entidades bancarias ';
+) ENGINE=InnoDB AUTO_INCREMENT=10227 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Entidades bancarias ';
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -7954,11 +6499,11 @@ DROP TABLE IF EXISTS `escritos`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `escritos` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `abrev` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
+ `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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -7976,10 +6521,12 @@ CREATE TABLE `escritos_det` (
`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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=14112 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -8006,8 +6553,9 @@ CREATE TABLE `expeditions` (
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
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+ 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 */ ;
@@ -8020,7 +6568,7 @@ CREATE TABLE `expeditions` (
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;
@@ -8053,7 +6601,7 @@ 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
@@ -8110,7 +6658,7 @@ BEGIN
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 ,trabajador,OLD.ticket_id,CONCAT(OLD.odbc_date,',Bultos:',OLD.counter,',Embalaje:',OLD.EsBulto),user()
+ 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 ;
@@ -8147,7 +6695,7 @@ CREATE TABLE `expeditions_deleted` (
KEY `index2` (`EsBulto`),
KEY `index3` (`odbc_date`),
KEY `index4` (`ticket_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=2168610 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -8177,7 +6725,7 @@ CREATE TABLE `filtros` (
`sql` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`Estanteria` tinyint(1) DEFAULT '0',
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=137 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -8228,7 +6776,7 @@ CREATE TABLE `form_query` (
`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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -8272,7 +6820,7 @@ CREATE TABLE `gestdoc` (
UNIQUE KEY `emp_id` (`emp_id`,`orden`,`warehouse_id`),
KEY `trabajador_id` (`trabajador_id`),
KEY `warehouse_id` (`warehouse_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -8297,7 +6845,7 @@ BEGIN
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;
@@ -8351,7 +6899,7 @@ CREATE TABLE `gesttip` (
`tipo` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
`path` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -8471,7 +7019,7 @@ CREATE TABLE `intrastat_data` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=60070 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -8515,28 +7063,24 @@ CREATE TABLE `invoice_observation` (
`empresa_id` smallint(5) unsigned NOT NULL DEFAULT '0',
`text` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`invoice_observation_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
--- Table structure for table `itemTag`
+-- Temporary view structure for view `itemTag`
--
DROP TABLE IF EXISTS `itemTag`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `itemTag` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `itemFk` int(11) NOT NULL,
- `tagFk` int(11) NOT NULL,
- `value` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
- `priority` int(2) NOT NULL DEFAULT '0',
- PRIMARY KEY (`id`),
- KEY `tag_fk_idx` (`tagFk`),
- KEY `priorityItem` (`itemFk`,`priority`),
- CONSTRAINT `itemFK` FOREIGN KEY (`itemFk`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
+/*!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`
@@ -8577,7 +7121,7 @@ CREATE TABLE `item_catalog` (
`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 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 */;
@@ -8614,6 +7158,22 @@ SET character_set_client = utf8;
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`
--
@@ -8646,8 +7206,8 @@ CREATE TABLE `iva_codigo` (
`fecha` date NOT NULL,
`codigo` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`iva_tipo_id` tinyint(2) NOT NULL,
- `iva` float(3,1) NOT NULL DEFAULT '0.0',
- `recargo` float(2,1) NOT NULL DEFAULT '0.0',
+ `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',
@@ -8656,7 +7216,7 @@ CREATE TABLE `iva_codigo` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=116 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -8671,7 +7231,7 @@ CREATE TABLE `iva_group` (
`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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -8710,7 +7270,7 @@ CREATE TABLE `iva_tipo` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -8822,7 +7382,7 @@ CREATE TABLE `mail` (
`recipientFk` int(11) DEFAULT NULL,
`plainTextBody` text COLLATE utf8_unicode_ci,
PRIMARY KEY (`id`)
-) ENGINE=MyISAM AUTO_INCREMENT=1136979 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=MyISAM AUTO_INCREMENT=1209471 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -8840,7 +7400,7 @@ CREATE TABLE `mail_templates` (
`body` text COLLATE utf8_unicode_ci NOT NULL,
`attachment` text COLLATE utf8_unicode_ci,
PRIMARY KEY (`id`,`countryCode`,`name`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -8865,7 +7425,7 @@ CREATE TABLE `mandato` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -8903,7 +7463,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -8931,7 +7491,7 @@ CREATE TABLE `movement_label` (
/*!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 */;;
@@ -8942,14 +7502,14 @@ DELIMITER ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
--
--- Temporary view structure for view `new_view`
+-- Temporary view structure for view `new_viewkk`
--
-DROP TABLE IF EXISTS `new_view`;
-/*!50001 DROP VIEW IF EXISTS `new_view`*/;
+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_view` AS SELECT
+/*!50001 CREATE VIEW `new_viewkk` AS SELECT
1 AS `id`,
1 AS `worker`,
1 AS `document`*/;
@@ -8979,7 +7539,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -9088,7 +7648,7 @@ CREATE TABLE `pago` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -9100,7 +7660,7 @@ CREATE TABLE `pago` (
/*!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;
@@ -9108,10 +7668,10 @@ BEGIN
-
+ -- 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
+ 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;
@@ -9164,12 +7724,12 @@ CREATE TABLE `pago_sdc` (
`strike` decimal(10,2) DEFAULT NULL,
PRIMARY KEY (`pago_sdc_id`),
KEY `empresa_sdc_idx` (`empresa_id`),
- KEY `entity_sdc_idx` (`entity_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 `entity_sdc` FOREIGN KEY (`entity_id`) REFERENCES `entity` (`entity_id`) ON UPDATE CASCADE,
- CONSTRAINT `financial_type_fk` FOREIGN KEY (`financialProductTypefk`) REFERENCES `financialProductType` (`id`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Seguros de cambio';
+ 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 */;
--
@@ -9183,7 +7743,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -9215,7 +7775,7 @@ CREATE TABLE `pay_met` (
`graceDays` int(11) unsigned NOT NULL DEFAULT '0',
`ibanRequired` tinyint(3) DEFAULT '0',
PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -9238,7 +7798,7 @@ CREATE TABLE `payroll_basess` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -9432,7 +7992,7 @@ 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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -9453,7 +8013,7 @@ CREATE TABLE `payrroll_apEmpresarial` (
`costeEmpresaFogasa` decimal(8,2) NOT NULL,
`costeEmpresaExtra` decimal(8,2) NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=1654 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -9522,49 +8082,6 @@ CREATE TABLE `plantpassport_authority` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='entidades certificadoras';
/*!40101 SET character_set_client = @saved_cs_client */;
---
--- Table structure for table `postcodeKK`
---
-
-DROP TABLE IF EXISTS `postcodeKK`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `postcodeKK` (
- `postcode_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
- `code` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
- `city_id` int(11) NOT NULL,
- `nst_geo_id` int(11) DEFAULT NULL,
- `nst_name` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
- PRIMARY KEY (`postcode_id`),
- UNIQUE KEY `code_city` (`code`,`city_id`),
- KEY `postal_code_idx` (`code`),
- KEY `city_id_pk_idx` (`city_id`),
- KEY `nst_geo_pc_id_idx` (`nst_geo_id`),
- CONSTRAINT `city_id_pk` FOREIGN KEY (`city_id`) REFERENCES `city` (`city_id`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `nst_geo_pc_id` FOREIGN KEY (`nst_geo_id`) REFERENCES `nst`.`geo` (`id`) ON DELETE SET NULL 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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`postcode_BEFORE_INSERT` BEFORE INSERT ON `postcodeKK` FOR EACH ROW
-BEGIN
-
- SET new.nst_name = new.code;
-
-END */;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `preparation_exception`
--
@@ -9626,7 +8143,7 @@ CREATE TABLE `price_fixed` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -9687,7 +8204,7 @@ CREATE TABLE `producer` (
`name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`visible` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`producer_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=3517 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -9762,7 +8279,7 @@ CREATE TABLE `province` (
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=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -9849,6 +8366,7 @@ CREATE TABLE `recibida` (
`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`),
@@ -9868,7 +8386,7 @@ CREATE TABLE `recibida` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -9887,6 +8405,7 @@ BEGIN
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;
@@ -9914,8 +8433,9 @@ BEGIN
AND empresa_id = NEW.empresa_id;
SET NEW.num_recibida = v_num_recibida;
- END IF;
+ END IF;
+
END */;;
DELIMITER ;
@@ -9933,7 +8453,7 @@ DELIMITER ;
/*!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);
@@ -9952,13 +8472,384 @@ BEGIN
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`
@@ -9994,7 +8885,7 @@ CREATE TABLE `recibida_entrada` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -10082,7 +8973,7 @@ CREATE TABLE `recibida_iva` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=82588 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -10105,7 +8996,7 @@ CREATE TABLE `recibida_vencimiento` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -10148,7 +9039,7 @@ CREATE TABLE `recovery` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla apuntaremos los acuerdos de recobro semanal a ';
+) 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 */;
--
@@ -10166,7 +9057,7 @@ CREATE TABLE `recovery_asset` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla se registra el detalle de los recobros definid';
+) 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 */;
--
@@ -10178,8 +9069,9 @@ DROP TABLE IF EXISTS `reference_min`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `reference_min` (
`date` date NOT NULL,
- `rate` double NOT NULL,
- `moneda_id` tinyint(3) unsigned NOT NULL DEFAULT '2'
+ `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 */;
@@ -10215,7 +9107,7 @@ CREATE TABLE `reinos` (
`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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -10244,7 +9136,7 @@ CREATE TABLE `reparacion` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -10261,21 +9153,6 @@ CREATE TABLE `rolekk` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
---
--- Temporary view structure for view `root`
---
-
-DROP TABLE IF EXISTS `root`;
-/*!50001 DROP VIEW IF EXISTS `root`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `root` 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 `rounding`
--
@@ -10339,7 +9216,7 @@ CREATE TABLE `salarioDits` (
`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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=96 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -10356,7 +9233,7 @@ CREATE TABLE `scan` (
`name` varchar(45) CHARACTER SET utf8 DEFAULT NULL,
`odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Se borra automaticamente 8 dias en el pasado desde vn2008.clean';
+) 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 */;
--
@@ -10374,7 +9251,7 @@ CREATE TABLE `scan_line` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=553359 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -10396,7 +9273,7 @@ CREATE TABLE `sharingcart` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -10474,7 +9351,7 @@ CREATE TABLE `sharingclient` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -10520,61 +9397,24 @@ DELIMITER ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
--
--- Table structure for table `sms`
+-- Temporary view structure for view `sms`
--
DROP TABLE IF EXISTS `sms`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `sms` (
- `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
- `Id_trabajador` int(11) NOT NULL,
- `text` varchar(160) COLLATE utf8_unicode_ci NOT NULL,
- `to` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
- `DATE_ODBC` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `sent` tinyint(4) NOT NULL DEFAULT '0',
- `Id_Cliente` int(11) DEFAULT NULL,
- `response` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
- `from` varchar(9) COLLATE utf8_unicode_ci NOT NULL DEFAULT '693474205',
- PRIMARY KEY (`id`)
-) 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 `sms_bi` BEFORE INSERT ON `sms`
- FOR EACH ROW
- BEGIN
- DECLARE intLast INT;
- DECLARE strTrab VARCHAR(3);
-
- SET NEW.`to` = LTRIM(NEW.`to`);
- IF NEW.`to` LIKE '6________' or NEW.`to` LIKE '7________'THEN
- SET NEW.`to` = CONCAT('0034',REPLACE(NEW.`to`,' ',''));
- ELSE
- IF NEW.`to` NOT LIKE '00346________' or NEW.`to` NOT LIKE '00347________'THEN
- INSERT INTO Mensajes(Mensaje,Fecha,Remitente,Destinatario)
- VALUES(CONCAT("El mensaje que ha enviado no contenía un número de teléfono MÓVIL válido:",NEW.`to`),NOW(),20,NEW.Id_trabajador);
- SELECT LAST_INSERT_ID() INTO intlast;
- SELECT CodigoTrabajador INTO strTrab FROM Trabajadores WHERE id_Trabajador = NEW.Id_Trabajador;
- INSERT INTO Incidencias(Incidencia,Id_Trabajador,Destino,Fecha,Fecha_Mod)
- VALUES (CONCAT('@@ ' , intLast), 20,strTrab, NOW(),NOW());
- SET NEW.id = 0;
-SET intLast = 'fallo provocado';
- 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 */ ;
+/*!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`
@@ -10606,23 +9446,25 @@ CREATE TABLE `state` (
`code` varchar(45) CHARACTER SET utf8 NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `code_UNIQUE` (`code`)
-) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
--- Table structure for table `tag`
+-- Temporary view structure for view `tag`
--
DROP TABLE IF EXISTS `tag`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `tag` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(25) CHARACTER SET utf8 NOT NULL,
- `free` tinyint(1) NOT NULL DEFAULT '1',
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Categorias para etiquetar los productos';
-/*!40101 SET character_set_client = @saved_cs_client */;
+/*!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`
@@ -10673,7 +9515,7 @@ CREATE TABLE `tarifas` (
PRIMARY KEY (`tarifa_id`),
KEY `tarifa_warehouse` (`warehouse_id`),
CONSTRAINT `tarifa_warehouse` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=133 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -10886,68 +9728,9 @@ CREATE TABLE `ticket_observation` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket';
+) 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 `ticket_stateKK`
---
-
-DROP TABLE IF EXISTS `ticket_stateKK`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `ticket_stateKK` (
- `ticket_id` int(11) NOT NULL,
- `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `user_id` int(11) NOT NULL,
- `state_id` tinyint(1) unsigned NOT NULL DEFAULT '1',
- UNIQUE KEY `ticket_id` (`ticket_id`),
- KEY `user_id` (`user_id`),
- KEY `state_id` (`state_id`),
- CONSTRAINT `ticket_stateKK_ibfk_1` FOREIGN KEY (`ticket_id`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `ticket_stateKK_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE CASCADE,
- CONSTRAINT `ticket_stateKK_ibfk_3` FOREIGN KEY (`state_id`) REFERENCES `state` (`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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`ticket_stateAfterInsert`
- AFTER INSERT ON `ticket_stateKK` FOR EACH ROW
-BEGIN
- CALL stock.queueAdd ('ticket', NEW.ticket_id, 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 `vn2008`.`ticket_stateAfterDelete`
- AFTER UPDATE ON `ticket_stateKK` FOR EACH ROW
-BEGIN
- CALL stock.queueAdd ('ticket', NEW.ticket_id, 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 `tickets_gestdoc`
--
@@ -11053,6 +9836,7 @@ CREATE TABLE `travel` (
`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`),
@@ -11060,10 +9844,12 @@ CREATE TABLE `travel` (
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
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC;
+ 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 */ ;
@@ -11077,7 +9863,7 @@ 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())
@@ -11105,13 +9891,13 @@ DELIMITER ;;
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())
@@ -11119,14 +9905,14 @@ BEGIN
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 ,IFNULL(trabajador,20),NEW.id,OLD.delivered,CONCAT(NEW.delivered,' desde ' ,user()));
+ VALUES (89/*Cambia delivered*/,IFNULL(trabajador,20),NEW.id,OLD.delivered,CONCAT(NEW.delivered,' desde ' ,user()));
END IF;
END */;;
DELIMITER ;
@@ -11147,6 +9933,13 @@ DELIMITER ;;
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 */ ;
@@ -11193,7 +9986,7 @@ CREATE TABLE `travel_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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=143118 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -11220,7 +10013,7 @@ CREATE TABLE `travel_pattern` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=317 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -11286,7 +10079,7 @@ CREATE TABLE `trolley` (
`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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=132 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -11317,7 +10110,7 @@ CREATE TABLE `unary` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=852 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -11332,7 +10125,7 @@ CREATE TABLE `unaryScanFilter` (
`name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`filter` text COLLATE utf8_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -11369,7 +10162,7 @@ CREATE TABLE `unary_scan_line` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=8462 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -12284,7 +11077,7 @@ CREATE TABLE `versiones` (
`version` int(11) NOT NULL,
`critical` tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (`programa`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -12377,7 +11170,7 @@ CREATE TABLE `warehouse` (
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=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) 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 */ ;
@@ -12435,7 +11228,7 @@ 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=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -12582,7 +11375,7 @@ CREATE TABLE `wks` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`comments` text COLLATE utf8_unicode_ci,
PRIMARY KEY (`id`) USING BTREE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=626 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -12628,7 +11421,7 @@ CREATE TABLE `workerTeam` (
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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+) ENGINE=InnoDB AUTO_INCREMENT=116 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -12673,6 +11466,21 @@ CREATE TABLE `zeleris` (
) 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`
--
@@ -12691,6 +11499,63 @@ CREATE TABLE `zones` (
--
-- 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'
@@ -12719,15 +11584,15 @@ 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)
@@ -12739,7 +11604,7 @@ 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
@@ -12757,13 +11622,13 @@ IF (SELECT COUNT(*) FROM Trabajadores WHERE Nombre=strNombre AND Apellidos=strAp
ELSE
SET RETORNO="CodigoTrabajador Existente";
END IF;
-
-END;
-
-
+ -- 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
+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;
@@ -12781,7 +11646,7 @@ END IF;
REPLACE INTO account.mailAliasAccount(mailAlias, account) VALUES (48,intId_Cliente);
-END;
+END; -- samba
RETURN RETORNO;
END ;;
@@ -12814,15 +11679,15 @@ 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)
@@ -12834,7 +11699,7 @@ 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
@@ -12852,13 +11717,13 @@ IF (SELECT COUNT(*) FROM Trabajadores WHERE Nombre=strNombre AND Apellidos=strAp
ELSE
SET RETORNO="CodigoTrabajador Existente";
END IF;
-
-END;
-
-
+ -- 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
+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;
@@ -12876,7 +11741,7 @@ END IF;
REPLACE INTO account.mailAliasAccount(mailAlias, account) VALUES (48,intId_Cliente);
-END;
+END; -- samba
RETURN RETORNO;
END ;;
@@ -12897,11 +11762,17 @@ DELIMITER ;
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 */ ;
@@ -12978,7 +11849,14 @@ 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;
@@ -13009,12 +11887,20 @@ 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
@@ -13026,7 +11912,7 @@ BEGIN
ORDER BY s.id
LIMIT 1;
-
+ -- Si no hay ninguno en sharingclient busca en sharingcart
IF v_substitute IS NOT NULL
THEN
@@ -13087,7 +11973,14 @@ 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;
@@ -13115,7 +12008,14 @@ 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;
@@ -13143,7 +12043,7 @@ 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);
@@ -13217,18 +12117,18 @@ BEGIN
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
@@ -13241,8 +12141,8 @@ BEGIN
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;
@@ -13309,7 +12209,12 @@ DELIMITER ;
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;
@@ -13387,7 +12292,7 @@ DELIMITER ;
/*!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 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 */ ;
@@ -13397,16 +12302,25 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = '' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` FUNCTION `CM3`(v_buy_id INT) RETURNS int(11)
+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 */ ;
@@ -13454,16 +12368,25 @@ DELIMITER ;
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 */ ;
@@ -13528,7 +12451,8 @@ BEGIN
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);
@@ -13612,6 +12536,7 @@ DELIMITER ;;
CREATE DEFINER=`root`@`%` FUNCTION `date_inv`() RETURNS datetime
DETERMINISTIC
BEGIN
+
RETURN (SELECT FechaInventario FROM tblContadores LIMIT 1);
END ;;
DELIMITER ;
@@ -13632,8 +12557,10 @@ 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 */ ;
@@ -13678,6 +12605,7 @@ 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;
@@ -13687,6 +12615,11 @@ RETURN intPeriod;
+
+
+
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -13710,7 +12643,15 @@ CREATE DEFINER=`root`@`%` FUNCTION `getBouquetId`(
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);
@@ -13718,6 +12659,37 @@ BEGIN
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 */ ;
@@ -13881,7 +12853,7 @@ 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 ;;
@@ -14023,6 +12995,7 @@ BEGIN
RETURN dblRESULT;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -14048,6 +13021,7 @@ SET vDued = vn.getDueDate(vDated, vDayToPay);
RETURN vDued;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -14142,7 +13116,51 @@ BEGIN
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 ;;
@@ -14165,12 +13183,20 @@ 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 */ ;
@@ -14189,7 +13215,11 @@ DELIMITER ;
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;
@@ -14216,7 +13246,31 @@ 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);
@@ -14240,7 +13294,11 @@ 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;
@@ -14266,12 +13324,17 @@ DELIMITER ;
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;
- DECLARE dblFreight DECIMAL(10,2);
+
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
@@ -14291,7 +13354,13 @@ BEGIN
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 ;;
@@ -14311,31 +13380,56 @@ DELIMITER ;
/*!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 */ ;
@@ -14446,25 +13540,37 @@ DELIMITER ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET 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 idx USING HASH (ticket_id))
- ENGINE = MEMORY
- SELECT ticket_id;
+ (INDEX (ticket_id))
+ ENGINE = MEMORY
+ SELECT ticket_id;
- CALL ticket_total ();
+ CALL ticket_total;
SELECT total INTO v_total FROM ticket_total;
- DROP TEMPORARY TABLE ticket_total;
- DROP TEMPORARY TABLE ticket_tmp;
+ DROP TEMPORARY TABLE
+ ticket_total,
+ ticket_tmp;
RETURN v_total;
END ;;
@@ -14520,7 +13626,11 @@ 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;
@@ -14553,7 +13663,23 @@ 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 ;
@@ -14588,7 +13714,7 @@ BEGIN
DECLARE v_subaccount VARCHAR(12);
DECLARE v_asiento INT DEFAULT NULL;
-
+ -- Inserta el registro en cajas
INSERT INTO Cajas
SET
@@ -14602,7 +13728,7 @@ BEGIN
,Numero = v_number
,empresa_id = v_company;
-
+ -- Inserta los asientos contables
SELECT Cuenta INTO v_account
FROM Bancos WHERE Id_Banco = v_bank;
@@ -14620,11 +13746,11 @@ BEGIN
,v_amount
,0
,0
- ,NULL
- ,NULL
- ,NULL
- ,NULL
- ,FALSE
+ ,NULL -- Serie
+ ,NULL -- Factura
+ ,NULL -- IVA
+ ,NULL -- Recargo
+ ,FALSE -- Auxiliar
,v_company
);
DO asiento
@@ -14637,11 +13763,11 @@ BEGIN
,0
,v_amount
,0
- ,NULL
- ,NULL
- ,NULL
- ,NULL
- ,FALSE
+ ,NULL -- Serie
+ ,NULL -- Factura
+ ,NULL -- IVA
+ ,NULL -- Recargo
+ ,FALSE -- Auxiliar
,v_company
);
@@ -14685,7 +13811,7 @@ 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
+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;
@@ -14913,7 +14039,7 @@ DELIMITER ;
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;
@@ -15003,7 +14129,9 @@ 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
@@ -15052,7 +14180,7 @@ BEGIN
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
+ WHEN 'AWB' THEN 1 -- No action
WHEN 'FB' THEN hb/2
WHEN 'GW' THEN peso
WHEN 'TW' THEN GREATEST(peso,volume_weight)
@@ -15242,7 +14370,7 @@ BEGIN
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
+ 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 ;;
@@ -15277,11 +14405,11 @@ BEGIN
,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
@@ -15291,12 +14419,12 @@ BEGIN
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
+ 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)
@@ -15306,12 +14434,12 @@ BEGIN
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
+ 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
@@ -15321,20 +14449,29 @@ BEGIN
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
+ 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
+ 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 ;
+ GROUP BY ag.agency_id/*, Prioridad*/;
DROP TEMPORARY TABLE IF EXISTS agenVOL;
END ;;
@@ -15428,12 +14565,19 @@ 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 */ ;
@@ -15452,7 +14596,9 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `articleTagUpdatePriority_kk`(IN vItem INT)
BEGIN
-
+/*
+* DEPRECATED
+*/
CALL vn.itemTagUpdatePriority(vItem);
@@ -15480,7 +14626,7 @@ BEGIN
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 ;
@@ -15500,7 +14646,11 @@ DELIMITER ;
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;
@@ -15546,11 +14696,11 @@ proc: BEGIN
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;
@@ -15605,7 +14755,7 @@ proc: BEGIN
UPDATE tblContadores SET FechaInventario = vDate;
- DELETE e
+ DELETE e, t
FROM travel t
JOIN Entradas e ON e.travel_id = t.id
WHERE Id_Proveedor = 4
@@ -15629,7 +14779,7 @@ DELIMITER ;
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;
@@ -15637,7 +14787,7 @@ BEGIN
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
@@ -15717,7 +14867,7 @@ BEGIN
JOIN tmp t ON ai.article_id = t.Id_Article
SET ai.buy_id = t.Id_Compra;
-
+ -- Los valores de hoy
TRUNCATE TABLE tmp;
@@ -15756,35 +14906,65 @@ 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 */ ;
@@ -15803,21 +14983,35 @@ DELIMITER ;
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 */ ;
@@ -15863,17 +15057,26 @@ 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 */ ;
@@ -15904,7 +15107,7 @@ proc: BEGIN
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');
@@ -15914,7 +15117,7 @@ proc: BEGIN
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
@@ -15931,7 +15134,7 @@ proc: BEGIN
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());
@@ -15952,7 +15155,7 @@ proc: BEGIN
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;
@@ -15982,7 +15185,7 @@ proc: BEGIN
INSERT INTO item_range_copy5
SELECT * FROM item_range_copy1;
-
+ -- Calcula el ATP
DROP TEMPORARY TABLE IF EXISTS availableTraslate;
CREATE TEMPORARY TABLE availableTraslate
@@ -16076,7 +15279,7 @@ proc: BEGIN
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');
@@ -16086,7 +15289,7 @@ proc: BEGIN
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
@@ -16115,7 +15318,7 @@ proc: BEGIN
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());
@@ -16146,7 +15349,7 @@ proc: BEGIN
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;
@@ -16176,7 +15379,7 @@ proc: BEGIN
INSERT INTO item_range_copy5
SELECT * FROM item_range_copy1;
-
+ -- Calcula el ATP
SELECT item_id, stock,'tmp_item'
FROM vn2008.tmp_item;
@@ -16271,7 +15474,7 @@ proc: BEGIN
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');
@@ -16281,7 +15484,7 @@ proc: BEGIN
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
@@ -16298,13 +15501,13 @@ proc: BEGIN
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 ;
+ 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;
@@ -16332,7 +15535,7 @@ proc: BEGIN
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;
@@ -16364,7 +15567,7 @@ proc: BEGIN
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 ;
@@ -16501,7 +15704,7 @@ 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;
@@ -16536,21 +15739,27 @@ IF NOT vInterGroupSalesIncluded THEN
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(tr.dateBooking,tr.Fecha),IFNULL(r.dateBooking,r.Fecha))) as `year`
- , month(IFNULL(IFNULL(tr.dateBooking,tr.Fecha),IFNULL(r.dateBooking,r.Fecha))) as `month`
+ /*
+ , 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;
@@ -16581,7 +15790,7 @@ DELETE FROM tmp.balance_desglose
-
+-- Ahora el balance
SET v_sql = sql_printf (
'
ALTER TABLE tmp.balance
@@ -16596,10 +15805,10 @@ SET v_sql = sql_printf (
YEAR(CURDATE())
);
-CALL sql_query (v_sql);
-
+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
@@ -16609,7 +15818,7 @@ JOIN (SELECT Id_Gasto, 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
@@ -16631,11 +15840,11 @@ WHILE intYEARS > 0 DO
YEAR(CURDATE()) - intYEARS
);
- CALL sql_query (v_sql);
+ CALL util.exec (v_sql);
END WHILE;
-
+-- Añadimos las ventas
SET v_sql = sql_printf (
@@ -16670,9 +15879,9 @@ END WHILE;
);
- CALL sql_query (v_sql);
-
+ CALL util.exec (v_sql);
+-- Ventas intra grupo
IF NOT vInterGroupSalesIncluded THEN
SELECT lft, rgt
@@ -16687,7 +15896,7 @@ IF NOT vInterGroupSalesIncluded THEN
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;
@@ -16745,30 +15954,35 @@ DELIMITER ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = '' */ ;
+/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `bionic_available_`(
- v_date DATE,
- v_consigna INT,
- v_agencia INT)
+ vDate DATE,
+ vAddress INT,
+ vAgency INT)
BEGIN
-
-
- DECLARE v_available_calc INT;
- DECLARE v_shipment DATE;
- DECLARE v_agency_id INT;
- DECLARE v_wh INT;
- DECLARE done BOOL;
- DECLARE cur CURSOR FOR
+/**
+ * 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 done = TRUE;
+ 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 v_agency_id FROM Agencias WHERE Id_Agencia = v_agencia;
+ SELECT agency_id INTO vAgencyId
+ FROM Agencias WHERE Id_Agencia = vAgency;
- CALL travel_tree (v_date,v_consigna, v_agency_id);
+ CALL travel_tree (vDate, vAddress, vAgencyId);
DROP TEMPORARY TABLE IF EXISTS t_bionic_available;
CREATE TEMPORARY TABLE t_bionic_available(
@@ -16777,22 +15991,22 @@ BEGIN
)
ENGINE = MEMORY;
- OPEN cur;
+ OPEN cTravelTree;
l: LOOP
- SET done = FALSE;
- FETCH cur INTO v_wh, v_shipment;
+ SET vDone = FALSE;
+ FETCH cTravelTree INTO vWh, vShipment;
- IF done THEN
+ IF vDone THEN
LEAVE l;
END IF;
- CALL `cache`.available_refresh (v_available_calc, FALSE, v_wh, v_shipment);
+ CALL `cache`.available_refresh (vAvailableCalc, FALSE, vWh, vShipment);
- INSERT IGNORE INTO t_bionic_available (calc_id)
- VALUES (v_available_calc);
+ INSERT IGNORE INTO t_bionic_available
+ SET calc_id = vAvailableCalc;
END LOOP;
- CLOSE cur;
+ CLOSE cTravelTree;
DROP TEMPORARY TABLE travel_tree;
END ;;
DELIMITER ;
@@ -16830,7 +16044,7 @@ ENGINE = INNODB;
-
+-- Arreglos
SET minMED = IFNULL(minMED,0);
SET minMED = IF(minMED = 0,0.01, minMED);
@@ -16841,7 +16055,7 @@ 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);
@@ -16876,10 +16090,10 @@ ELSE
SET v_sql = sql_printf (
'
- REPLACE articlelist
+ REPLACE vn2008.articlelist
SELECT a.Id_Article
- FROM Articles a
- LEFT JOIN Tipos t ON t.tipo_id = a.tipo_id
+ FROM vn2008.Articles a
+ LEFT JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id
WHERE %s
AND Medida BETWEEN %v AND %v;
'
@@ -16891,15 +16105,15 @@ ELSE
SET v_sql = sql_printf (
'
- REPLACE articlelist
+ REPLACE vn2008.articlelist
SELECT a.Id_Article
- FROM Articles a
- LEFT JOIN Tipos t ON t.tipo_id = a.tipo_id
+ FROM vn2008.Articles a
+ LEFT JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id
JOIN (
SELECT DISTINCT Id_Article
- FROM Movimientos m
- JOIN Tickets t using(Id_Ticket)
- JOIN Clientes c using(Id_Cliente)
+ 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
@@ -16914,10 +16128,10 @@ ELSE
,maxMED);
end if;
- CALL sql_query (v_sql);
+ CALL util.exec (v_sql);
END IF;
-
+-- SELECT Id_Article, Article, Medida FROM Articles join articlelist using(Id_Article);
END ;;
DELIMITER ;
@@ -16935,11 +16149,15 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = '' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `bionic_available_items_`(v_date DATE,
+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;
@@ -16993,11 +16211,16 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `bionic_available_types_`(
- v_date DATE,
+ 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);
@@ -17010,7 +16233,7 @@ BEGIN
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
+ 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;
@@ -17031,58 +16254,58 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `bionic_available_types_filter`(IN v_date DATE,
- IN v_consigna INT,
- IN v_agencia INT,
- IN v_filter TEXT)
+CREATE DEFINER=`root`@`%` PROCEDURE `bionic_available_types_filter`(
+ v_date DATE,
+ v_consigna INT,
+ v_agencia INT,
+ v_filter TEXT)
BEGIN
-
-
-
-
-
- DECLARE v_sql TEXT;
- DECLARE v_list TEXT;
- SET v_list = '';
+/**
+ * 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
+ */
- SET v_filter = IFNULL(v_filter,' TRUE');
-
- CALL bionic_available_(v_date, v_consigna, v_agencia);
-
- DROP TEMPORARY TABLE IF EXISTS t_bionic_available_types;
-
- CALL check_table_existence('articlelist');
-
- IF @table_exists THEN
-
- SET v_list = 'JOIN 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 Articles a ON c.item_id = a.Id_Article
- JOIN Tipos t ON t.tipo_id = a.tipo_id
- JOIN reinos r ON r.id = t.reino_id
- JOIN 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);
-
+ 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 ;
@@ -17101,53 +16324,55 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc`(
- v_date DATE,
- v_consigna INT,
- v_agencia INT)
+ vDate DATE, -- Fecha de recepcion de mercancia
+ vAddress INT,
+ vAgency INT)
proc: BEGIN
- DECLARE v_available_calc INT;
- DECLARE v_shipment DATE;
- DECLARE v_agency_id INT;
- DECLARE v_customer INT;
- DECLARE v_wh SMALLINT;
- DECLARE done BOOL;
- DECLARE cur CURSOR FOR
- SELECT warehouse_id, Fecha_envio FROM vn2008.travel_tree;
+ 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 done = TRUE;
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
- DROP TEMPORARY TABLE IF EXISTS tmp.bionic_item;
- DROP TEMPORARY TABLE IF EXISTS tmp.bionic_component;
- DROP TEMPORARY TABLE IF EXISTS tmp.bionic_lot;
- DROP TEMPORARY TABLE IF EXISTS tmp.bionic_price;
+ 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 v_agency_id FROM vn2008.Agencias WHERE Id_Agencia = v_agencia;
- SELECT Id_Cliente INTO v_customer FROM vn2008.Consignatarios WHERE Id_Consigna = v_consigna;
+ SELECT agency_id INTO vAgencyId FROM Agencias WHERE Id_Agencia = vAgency;
+ SELECT Id_Cliente INTO vCustomer FROM Consignatarios WHERE Id_Consigna = vAddress;
- CALL vn2008.travel_tree(v_date,v_consigna, v_agency_id);
+ 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 cur;
+ OPEN cTravelTree;
+
l: LOOP
-
- SET done = FALSE;
- FETCH cur INTO v_wh, v_shipment;
- IF done THEN
+ SET vDone = FALSE;
+ FETCH cTravelTree INTO vWh, vShipment;
+
+ IF vDone THEN
LEAVE l;
END IF;
- CALL `cache`.available_refresh (v_available_calc, FALSE, v_wh, v_shipment);
- CALL item_last_buy_ (v_wh, v_shipment);
+ 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
- v_wh,
+ vWh,
i.item_id,
IFNULL(i.available, 0),
ilb.buy_id
@@ -17155,7 +16380,7 @@ proc: BEGIN
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 = v_available_calc
+ WHERE i.calc_id = vAvailableCalc
AND a.Id_Article != 100
AND i.available > 0;
@@ -17163,14 +16388,15 @@ proc: BEGIN
END LOOP;
- CLOSE cur;
+ CLOSE cTravelTree;
- CALL bionic_calc_component(v_consigna,v_agencia);
+ 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
+ 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
@@ -17180,8 +16406,7 @@ proc: BEGIN
FROM tmp.bionic_price
GROUP BY item_id
) bl ON bl.item_id = b.item_id
- GROUP BY b.item_id;
-
+ GROUP BY b.item_id;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -17201,7 +16426,9 @@ 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;
@@ -17222,7 +16449,7 @@ BEGIN
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);
+ 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
@@ -17234,7 +16461,7 @@ BEGIN
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
@@ -17242,7 +16469,7 @@ BEGIN
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
@@ -17258,7 +16485,7 @@ BEGIN
WHERE Id_Ticket = v_ticket;
END IF;
-
+ -- Log
call Ditacio(v_ticket
,'Bioniza Ticket'
,'T'
@@ -17266,7 +16493,7 @@ BEGIN
, 'proc bionic_calc_clon'
, NULL);
-
+ -- Limpieza
DROP TEMPORARY TABLE t_item_last_buy;
END ;;
DELIMITER ;
@@ -17287,7 +16514,9 @@ 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;
@@ -17307,7 +16536,7 @@ BEGIN
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);
+ 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
@@ -17319,7 +16548,7 @@ BEGIN
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
@@ -17327,7 +16556,7 @@ BEGIN
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
@@ -17336,7 +16565,7 @@ BEGIN
CALL bionic_movement_update(6);
-
+ -- Log
call Ditacio(v_ticket
,'Bioniza Ticket'
,'T'
@@ -17344,7 +16573,7 @@ BEGIN
, 'proc bionic_calc_clon'
, NULL);
-
+ -- Limpieza
DROP TEMPORARY TABLE t_item_last_buy;
END ;;
DELIMITER ;
@@ -17363,7 +16592,7 @@ DELIMITER ;
/*!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
@@ -17372,7 +16601,7 @@ 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 vValorEmbolsado DOUBLE DEFAULT 0.04;
SELECT Id_Cliente INTO v_customer FROM Consignatarios WHERE Id_Consigna = v_consigna;
SET @rate2 := 0;
@@ -17406,15 +16635,15 @@ proc: BEGIN
) 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
@@ -17425,7 +16654,7 @@ proc: BEGIN
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;
@@ -17434,7 +16663,7 @@ proc: BEGIN
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)
@@ -17442,7 +16671,7 @@ proc: BEGIN
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
@@ -17453,11 +16682,18 @@ proc: BEGIN
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
@@ -17466,7 +16702,7 @@ proc: BEGIN
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
@@ -17474,9 +16710,9 @@ proc: BEGIN
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
@@ -17485,8 +16721,8 @@ proc: BEGIN
* ROUND(
r.cm3
* IF(a.Vista = 1, (GREATEST(art.density,DENSIDAD_MINIMA_PESO_VOLUMETRICO) / DENSIDAD_MINIMA_PESO_VOLUMETRICO ) , 1)
- * az.price
- * az.inflacion
+ * IFNULL(az.price
+ * az.inflacion ,50)
/ VOLUMEN_CAJA_VERDNATURA, 4
) cost
FROM t_bionic_temp b
@@ -17498,7 +16734,7 @@ proc: BEGIN
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
@@ -17522,11 +16758,11 @@ proc: BEGIN
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
@@ -17536,8 +16772,8 @@ proc: BEGIN
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
@@ -17546,13 +16782,13 @@ proc: BEGIN
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
@@ -17562,7 +16798,7 @@ proc: BEGIN
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))
@@ -17572,8 +16808,8 @@ proc: BEGIN
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
@@ -17584,7 +16820,7 @@ proc: BEGIN
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
@@ -17593,7 +16829,7 @@ proc: BEGIN
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
@@ -17602,7 +16838,7 @@ proc: BEGIN
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
@@ -17620,7 +16856,7 @@ proc: BEGIN
ENGINE = MEMORY
SELECT * FROM travel_tree;
-
+ -- Limpieza
DROP TEMPORARY TABLE travel_tree;
DROP TEMPORARY TABLE t_bionic_temp;
@@ -17645,7 +16881,7 @@ DELIMITER ;
/*!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
@@ -17654,7 +16890,7 @@ 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 vValorEmbolsado DOUBLE DEFAULT 0.04;
SELECT Id_Cliente INTO v_customer FROM Consignatarios WHERE Id_Consigna = v_consigna;
SET @rate2 := 0;
@@ -17688,15 +16924,15 @@ proc: BEGIN
) 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
@@ -17707,7 +16943,7 @@ proc: BEGIN
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;
@@ -17716,7 +16952,7 @@ proc: BEGIN
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)
@@ -17724,7 +16960,7 @@ proc: BEGIN
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
@@ -17735,11 +16971,18 @@ proc: BEGIN
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
@@ -17748,7 +16991,7 @@ proc: BEGIN
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
@@ -17756,9 +16999,9 @@ proc: BEGIN
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
@@ -17780,7 +17023,7 @@ proc: BEGIN
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
@@ -17804,11 +17047,11 @@ proc: BEGIN
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
@@ -17818,8 +17061,8 @@ proc: BEGIN
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
@@ -17828,13 +17071,13 @@ proc: BEGIN
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
@@ -17847,7 +17090,7 @@ proc: BEGIN
-
+ -- Lotes
DROP TEMPORARY TABLE IF EXISTS t_component_sum;
CREATE TEMPORARY TABLE t_component_sum
(INDEX (item_id, warehouse_id))
@@ -17857,8 +17100,8 @@ proc: BEGIN
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
@@ -17869,7 +17112,7 @@ proc: BEGIN
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
@@ -17878,7 +17121,7 @@ proc: BEGIN
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
@@ -17887,7 +17130,7 @@ proc: BEGIN
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
@@ -17905,7 +17148,7 @@ proc: BEGIN
ENGINE = MEMORY
SELECT * FROM travel_tree;
-
+ -- Limpieza
DROP TEMPORARY TABLE travel_tree;
DROP TEMPORARY TABLE t_bionic_temp;
@@ -17932,7 +17175,11 @@ DELIMITER ;
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;
@@ -17951,7 +17198,12 @@ proc: BEGIN
@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)
@@ -17985,7 +17237,9 @@ 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;
@@ -18027,7 +17281,7 @@ proc: BEGIN
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);
+ 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;
@@ -18045,9 +17299,9 @@ proc: BEGIN
(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));
+ 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'
@@ -18055,7 +17309,7 @@ proc: BEGIN
, 'proc bionic_calc_movement '
, v_id_mov);
-
+ -- Limpieza
DROP TEMPORARY TABLE t_item_last_buy;
END ;;
@@ -18077,7 +17331,9 @@ 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;
@@ -18097,7 +17353,7 @@ BEGIN
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);
+ 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
@@ -18115,7 +17371,7 @@ BEGIN
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'
@@ -18123,7 +17379,7 @@ BEGIN
, 'proc bionic_calc_movement_ok '
, NULL);
-
+ -- Limpieza
DROP TEMPORARY TABLE t_item_last_buy;
END ;;
DELIMITER ;
@@ -18161,18 +17417,18 @@ proc: BEGIN
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
@@ -18185,8 +17441,8 @@ proc: BEGIN
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;
@@ -18210,7 +17466,9 @@ 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;
@@ -18227,7 +17485,10 @@ proc: BEGIN
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);
@@ -18239,7 +17500,7 @@ proc: BEGIN
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);
+ 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
@@ -18258,7 +17519,7 @@ proc: BEGIN
FROM Movimientos m
where m.Id_Ticket = v_ticket;
- CALL bionic_movement_update(IF(v_ticket_free,1,6));
+ CALL bionic_movement_update(IF(v_ticket_free,1,6)); -- si el ticket esta facturado, respeta los precios
IF v_landing IS NULL THEN
@@ -18269,8 +17530,8 @@ proc: BEGIN
WHERE Id_Ticket = v_ticket;
END IF;
-
-
+ -- Limpieza
+ -- DROP TEMPORARY TABLE t_item_last_buy;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -18342,7 +17603,7 @@ DELIMITER ;
/*!50003 SET sql_mode = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `bionic_from_order`(
- v_date DATE,
+ v_date DATE, -- fecha de recepcion de mercancia
v_consigna INT,
v_agencia INT,
v_order INT)
@@ -18373,7 +17634,7 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `bionic_from_ticket`(
- v_date DATE,
+ v_date DATE, -- fecha de recepcion de mercancia
v_consigna INT,
v_agencia INT,
v_ticket INT)
@@ -18408,7 +17669,7 @@ BEGIN
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;
@@ -18434,7 +17695,7 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `bionic_from_type`(
- v_date DATE,
+ v_date DATE, -- fecha de recepcion de mercancia
v_consigna INT,
v_agencia INT,
v_type INT)
@@ -18473,14 +17734,16 @@ CREATE DEFINER=`root`@`%` PROCEDURE `bionic_make_update`(
,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;
@@ -18494,7 +17757,7 @@ BEGIN
WHERE
t.Id_Ticket = i_ticket;
-
+ -- La opcion 8 es No realizar modificaciones en los precios
IF i_option <> 8
THEN
@@ -18528,50 +17791,56 @@ DELIMITER ;
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
+ WHEN 1 THEN -- caso normal
SET bolRENUEVA_COMPONENTES = TRUE;
SET bolRESPETA_PRECIOS = FALSE;
WHEN 2 THEN
- SET intComponent = 17;
+ SET intComponent = 17; -- greuge al client
SET bolRENUEVA_COMPONENTES = TRUE;
SET bolRESPETA_PRECIOS = TRUE;
WHEN 3 THEN
- SET intComponent = 37;
+ SET intComponent = 37; -- convertir en maná
SET bolRENUEVA_COMPONENTES = TRUE;
SET bolRESPETA_PRECIOS = TRUE;
WHEN 4 THEN
- SET intComponent = 34;
+ SET intComponent = 34; -- greuge contra la cartera del producto
SET bolRENUEVA_COMPONENTES = TRUE;
SET bolRESPETA_PRECIOS = TRUE;
WHEN 5 THEN
- SET intComponent = 35;
+ SET intComponent = 35; -- greuge contra la cartera del comprador
SET bolRENUEVA_COMPONENTES = TRUE;
SET bolRESPETA_PRECIOS = TRUE;
WHEN 6 THEN
- SET intComponent = 36;
+ 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
@@ -18579,7 +17848,7 @@ BEGIN
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
@@ -18591,12 +17860,12 @@ BEGIN
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
@@ -18605,7 +17874,7 @@ BEGIN
SET bolRENUEVA_COMPONENTES = FALSE;
SET bolRESPETA_PRECIOS = FALSE;
- WHEN 9 THEN
+ 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;
@@ -18614,14 +17883,14 @@ BEGIN
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
@@ -18646,7 +17915,7 @@ BEGIN
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
@@ -18655,9 +17924,9 @@ BEGIN
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';
+ 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
@@ -18669,7 +17938,7 @@ BEGIN
END IF;
-
+ -- Fija el Costfixat
UPDATE Movimientos m
JOIN (SELECT SUM(mc.Valor) sum_valor,mc.Id_Movimiento
@@ -18681,8 +17950,8 @@ BEGIN
SET m.CostFixat = sum_valor, PrecioFijado = 1;
-
-
+ -- PAK 2017-02-06
+ -- Familia PORTES, un unico componente de porte
DELETE mc.*
FROM Movimientos_componentes mc
@@ -18693,16 +17962,32 @@ BEGIN
WHERE Tipo = 'Portes';
INSERT INTO Movimientos_componentes(Id_Movimiento, Id_Componente, Valor)
- SELECT m.Id_Movimiento, 15, preu
+ 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 ;
@@ -18802,7 +18087,7 @@ 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
@@ -18817,7 +18102,7 @@ select t.Id_Ticket, IFNULL(sum(Valor),0) - (Preu * (100 - m.Descuento)/100) as
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
@@ -18836,7 +18121,7 @@ UNION ALL
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
@@ -19012,9 +18297,148 @@ DELIMITER ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET 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;
@@ -19106,7 +18530,7 @@ BEGIN
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`;
@@ -19129,15 +18553,20 @@ DELIMITER ;
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');
@@ -19225,13 +18654,13 @@ BEGIN
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
@@ -19279,14 +18708,14 @@ BEGIN
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
@@ -19313,7 +18742,7 @@ BEGIN
SELECT * FROM tmp.aux;
-
+ -- Limpia y confirma cambios
DROP TEMPORARY TABLE
tmp.split,
@@ -19363,17 +18792,17 @@ BEGIN
JOIN tblTARIFAS TC
SET C.Portefijo = @PF:=
IF (va.importe,
- ROUND((va.importe * TP.density * CM3_2(C.Id_Cubo, C.Id_Article) / 1000) / (va.Vol_Total * 167 * C.Packing ),3),
+ 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)),
+ 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
+ IF v_wh = 42 -- Canarias
THEN
UPDATE Compres
SET Tarifa2 = Tarifa3
@@ -19426,13 +18855,13 @@ LIMIT 1;
JOIN Agencias AG ON TR.agency_id = AG.Id_Agencia
JOIN tblTARIFAS TC
- SET C.Portefijo = @PF:= round((va.importe * TP.density * CM3_2(C.Id_Cubo, C.Id_Article) / 1000) / (va.Vol_Total * 167 * C.Packing ),3),
+ 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)),
+ 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),
@@ -19444,7 +18873,7 @@ LIMIT 1;
CASE wh_id
- WHEN 41 THEN
+ WHEN 41 THEN -- Canarias
UPDATE Compres
SET Tarifa2 = Tarifa3
@@ -19489,8 +18918,8 @@ 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
@@ -19539,7 +18968,7 @@ BEGIN
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 * ( TP.density / 167 ) * cm3_2(C.Id_Cubo, C.Id_Article)) / 1000000) ,0)) INTO m3i
+ 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)
@@ -19565,19 +18994,16 @@ BEGIN
SET C.Portefijo = @PF:=
IF (va.importe,
- round((va.importe * TP.density * CM3_2(C.Id_Cubo, C.Id_Article) / 1000) / (va.Vol_Total * 167 * C.Packing ),3),
+ 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)),
+ 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),
@@ -19588,7 +19014,7 @@ BEGIN
CASE wh_id
- WHEN 41 THEN
+ WHEN 41 THEN -- Canarias
UPDATE Compres
SET Tarifa2 = Tarifa3
@@ -19779,7 +19205,7 @@ BEGIN
WHERE C.Id_Compra = idCOMPRA;
- IF wh_id = 41 THEN
+ IF wh_id = 41 THEN -- Canarias
UPDATE Compres
SET Tarifa2 = Tarifa3
@@ -19860,14 +19286,14 @@ 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
@@ -19889,7 +19315,7 @@ BEGIN
) sub2
LIMIT 1;
-
+ -- pak 22/09/2015
UPDATE bi.rotacion r
JOIN Compres c ON c.Id_Article = r.Id_Article
@@ -19914,7 +19340,10 @@ DELIMITER ;
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;
@@ -19922,7 +19351,7 @@ proc: BEGIN
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
@@ -19936,7 +19365,7 @@ proc: BEGIN
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));
@@ -19945,7 +19374,7 @@ proc: BEGIN
LEAVE proc;
END IF;
-
+ -- Calcula la cantidad a trasladar
SELECT Id_Article INTO v_item
FROM Compres WHERE Id_Compra = v_buy;
@@ -19980,7 +19409,7 @@ proc: BEGIN
LEAVE proc;
END IF;
-
+ -- Crea la nueva línea de compra con el translado
INSERT INTO Compres (
Id_Article, Etiquetas, Cantidad, Id_Entrada,
@@ -20015,6 +19444,30 @@ DELIMITER ;
/*!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 */ ;
@@ -20092,6 +19545,81 @@ 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
@@ -20210,22 +19738,43 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `camiones`(vWarehouse INT, vDate DATE)
BEGIN
+
SELECT Temperatura
- ,ROUND(SUM(Etiquetas * cm3_2(Id_Cubo, Id_Article))) AS cm3
- ,ROUND(SUM(IF(scanned,Etiquetas,0) * cm3_2(Id_Cubo, Id_Article))) AS cm3s
- ,ROUND(SUM(Vida * cm3_2(Id_Cubo, Id_Article))) AS cm3e
+
+ ,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, c.Id_Cubo, c.Id_Article, b.scanned, c.Vida
+
+ 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 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
+
+ AND tr.landing = vDate
+
) sub
+
GROUP BY Temperatura;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -20330,15 +19879,15 @@ DELIMITER ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET 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 @sql_query = CONCAT('SELECT NULL FROM ',@table_name);
- PREPARE stmt1 FROM @sql_query;
+ SET @sqlString = CONCAT('SELECT NULL FROM ',@table_name);
+ PREPARE stmt1 FROM @sqlString;
IF (@err = 1) THEN
SET @table_exists = 0;
ELSE
@@ -20363,39 +19912,40 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `clean`(IN v_full TINYINT(1))
BEGIN
- DECLARE v_date DATETIME;
+ DECLARE v_date DATETIME;
DECLARE v_date_fut DATE;
DECLARE v_date18 DATETIME;
- DECLARE v_date8 DATE;
- DECLARE v_date6 DATE;
- DECLARE strtable varchar(15) DEFAULT NULL;
+ 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_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_date OR FECHA IS NULL;
+ 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)
+
+ 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 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;
@@ -20413,90 +19963,89 @@ BEGIN
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)
+ 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;
-
-
+ 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 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
+ 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);
+ 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'))
+ 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;
+ 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;
- 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);
-
-
-
-
-
- UPDATE vn2008.Tickets
+ 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;
-
-
- 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');
+ 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 */ ;
@@ -20517,10 +20066,7 @@ CREATE DEFINER=`root`@`%` PROCEDURE `clean_launcher`()
BEGIN
call vn2008.clean(TRUE);
- call vn.clean();
- call vncontrol.clean();
- call bi.clean();
- call cache.clean();
+
END ;;
DELIMITER ;
@@ -20565,7 +20111,7 @@ BEGIN
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)
@@ -20577,30 +20123,36 @@ BEGIN
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
+ SELECT Id_Cliente, 3, CASE pay_met_id WHEN 4 -- giro
THEN 2
- WHEN 1
+ WHEN 1 -- contado
THEN -1
- WHEN 5
+ WHEN 5 -- tarjeta
THEN 1
- WHEN 7
+ WHEN 7 -- tarjeta
THEN 1
- WHEN 6
+ 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)
@@ -20613,7 +20165,7 @@ BEGIN
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
@@ -20625,12 +20177,12 @@ BEGIN
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
+ 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
@@ -20641,7 +20193,7 @@ BEGIN
GROUP BY Id_Cliente
HAVING Inicio >= TIMESTAMPADD(DAY,-30,CURDATE())) sub ;
-
+ -- Ahora actualizamos la tabla Clientes
UPDATE Clientes
JOIN
@@ -20654,8 +20206,8 @@ BEGIN
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
@@ -20867,7 +20419,7 @@ BEGIN
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
+ WHERE g.Greuges_type_id = 3 -- Maná
AND g.Fecha > '2016-01-01'
AND c.Id_Cliente = vClient;
@@ -20923,7 +20475,7 @@ BEGIN
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
@@ -20990,8 +20542,8 @@ BEGIN
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
@@ -21012,7 +20564,7 @@ BEGIN
END IF;
-
+ -- CAJERA
INSERT INTO Cajas(Id_Trabajador
, Id_Banco
@@ -21038,7 +20590,7 @@ BEGIN
-
+ -- RECIBO
INSERT INTO Recibos(Entregado
,Fechacobro
,Id_Trabajador
@@ -21099,16 +20651,16 @@ 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
+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
+ join jerarquia j on j.worker_id = c.Id_Trabajador -- este filtro es para que solo toque los de los comerciales
join
(
@@ -21137,16 +20689,16 @@ IF day(CURDATE()) = 5 then
) tic_vivos on tic_vivos.Id_Cliente = c.Id_Cliente
- where c.Created < CURDATE() - INTERVAL 2 MONTH
- and j.boss_id = 87
- and f.Id_Cliente is null
- and sindeuda.Saldo < 10
- and tic_vivos.Id_Cliente is null
+ 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 ;
+ set Id_Trabajador = 87 ;-- Alfredo Giner;
end if;
@@ -21295,19 +20847,19 @@ SELECT cc.Id_Article
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
@@ -21459,19 +21011,19 @@ SELECT cc.Id_Article
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
@@ -21572,9 +21124,9 @@ BEGIN
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 wperiod INT;-- DECLARE ws, ys INT; -- PAK 11/01/2016
DECLARE i INT DEFAULT 0;
- DECLARE lastCOMP BIGINT;
+ DECLARE lastCOMP BIGINT; -- Almacena el ultimo valor del Periodo
DECLARE strFILTRO VARCHAR(255) DEFAULT 'TRUE';
IF i_filtro THEN
@@ -21590,17 +21142,17 @@ BEGIN
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
+ LEFT JOIN reinos r ON r.id = t.reino_id
WHERE (i_tipo = 0 OR a.tipo_id = i_tipo)
AND r.display <> 0;
@@ -21635,8 +21187,8 @@ BEGIN
REPEAT
SET i = i + 1;
- SET wperiod = vnperiod(TIMESTAMPADD(DAY, 7*(i - 1), date_cyear_ini));
- INSERT INTO wtable(cy, ly) VALUES(wperiod, wperiod - 100);
+ 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;
@@ -21653,7 +21205,7 @@ BEGIN
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
@@ -21683,7 +21235,7 @@ BEGIN
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
@@ -21727,50 +21279,48 @@ BEGIN
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');
-
- CALL sql_query (sql_printf
+ -- select * from article_inventory;
+ CALL util.exec (sql_printf
(
- 'CREATE TEMPORARY TABLE remcom
+ '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
- 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
- ,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
- ,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 article_inventory i
- JOIN Articles A ON A.Id_Article = i.article_id
- LEFT JOIN Articles_nicho an ON A.Id_Article = an.Id_Article AND an.warehouse_id = %s
- LEFT JOIN producer p ON p.producer_id = A.producer_id
- LEFT JOIN Tipos tp ON A.tipo_id = tp.tipo_id
+ ,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 Trabajadores TR ON TR.Id_Trabajador = tp.Id_Trabajador
- LEFT JOIN Tintas t ON t.Id_Tinta = A.color
- LEFT JOIN Compres C ON i.buy_id = C.Id_Compra
- LEFT JOIN Entradas E USING(Id_Entrada)
- LEFT JOIN Origen o ON o.id = A.id_origen
- LEFT JOIN last_year ly ON ly.Id_Article = A.Id_Article
- LEFT JOIN 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 '
+ 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
));
@@ -21791,18 +21341,18 @@ BEGIN
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 `comparative2` */;
+/*!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 */ ;
@@ -21812,7 +21362,7 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `comparative2`(
+CREATE DEFINER=`root`@`%` PROCEDURE `comparativekk`(
v_date DATETIME
,days TINYINT
,i_wh TINYINT
@@ -21831,9 +21381,9 @@ BEGIN
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 wperiod INT;-- DECLARE ws, ys INT; -- PAK 11/01/2016
DECLARE i INT DEFAULT 0;
- DECLARE lastCOMP BIGINT;
+ DECLARE lastCOMP BIGINT; -- Almacena el ultimo valor del Periodo
DECLARE strFILTRO VARCHAR(255) DEFAULT 'TRUE';
IF i_filtro THEN
@@ -21849,10 +21399,10 @@ BEGIN
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 ();
@@ -21894,8 +21444,8 @@ BEGIN
REPEAT
SET i = i + 1;
- SET wperiod = vnperiod(TIMESTAMPADD(DAY, 7*(i - 1), date_cyear_ini));
- INSERT INTO wtable(cy, ly) VALUES(wperiod, wperiod - 100);
+ 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;
@@ -21912,7 +21462,7 @@ BEGIN
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
@@ -21942,7 +21492,7 @@ BEGIN
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
@@ -21986,16 +21536,16 @@ BEGIN
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');
-
- CALL sql_query (sql_printf
+ -- select * from article_inventory;
+ CALL util.exec (sql_printf
(
- 'CREATE TEMPORARY TABLE remcom
+ 'CREATE TEMPORARY TABLE vn2008.remcom
SELECT
an.nicho, p.name Productor, C.Packing, C.Costefijo
@@ -22014,19 +21564,19 @@ BEGIN
,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 article_inventory i
- JOIN Articles A ON A.Id_Article = i.article_id
- LEFT JOIN Articles_nicho an ON A.Id_Article = an.Id_Article AND an.warehouse_id = %s
- LEFT JOIN producer p ON p.producer_id = A.producer_id
- LEFT JOIN Tipos tp ON A.tipo_id = tp.tipo_id
- LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id
- LEFT JOIN Trabajadores TR ON TR.Id_Trabajador = tp.Id_Trabajador
- LEFT JOIN Tintas t ON t.Id_Tinta = A.color
- LEFT JOIN Compres C ON i.buy_id = C.Id_Compra
- LEFT JOIN Entradas E USING(Id_Entrada)
- LEFT JOIN Origen o ON o.id = A.id_origen
- LEFT JOIN last_year ly ON ly.Id_Article = A.Id_Article
- LEFT JOIN cur_year cy ON cy.Id_Article = A.Id_Article
+ 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)
@@ -22051,7 +21601,7 @@ BEGIN
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;
@@ -22062,7 +21612,7 @@ DELIMITER ;
/*!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_test` */;
+/*!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 */ ;
@@ -22072,7 +21622,7 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `comparative_test`(
+CREATE DEFINER=`root`@`%` PROCEDURE `comparativekk2`(
v_date DATETIME
,days TINYINT
,i_wh TINYINT
@@ -22091,9 +21641,9 @@ BEGIN
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 wperiod INT;-- DECLARE ws, ys INT; -- PAK 11/01/2016
DECLARE i INT DEFAULT 0;
- DECLARE lastCOMP BIGINT;
+ DECLARE lastCOMP BIGINT; -- Almacena el ultimo valor del Periodo
DECLARE strFILTRO VARCHAR(255) DEFAULT 'TRUE';
IF i_filtro THEN
@@ -22109,10 +21659,10 @@ BEGIN
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 ();
@@ -22154,8 +21704,8 @@ BEGIN
REPEAT
SET i = i + 1;
- SET wperiod = vnperiod(TIMESTAMPADD(DAY, 7*(i - 1), date_cyear_ini));
- INSERT INTO wtable(cy, ly) VALUES(wperiod, wperiod - 100);
+ 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;
@@ -22172,7 +21722,7 @@ BEGIN
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
@@ -22202,7 +21752,7 @@ BEGIN
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
@@ -22246,16 +21796,16 @@ BEGIN
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');
-
- CALL sql_query (sql_printf
+ -- select * from article_inventory;
+ CALL util.exec (sql_printf
(
- 'CREATE TEMPORARY TABLE remcom
+ 'CREATE TEMPORARY TABLE vn2008.remcom
SELECT
an.nicho, p.name Productor, C.Packing, C.Costefijo
@@ -22274,19 +21824,19 @@ BEGIN
,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 article_inventory i
- JOIN Articles A ON A.Id_Article = i.article_id
- LEFT JOIN Articles_nicho an ON A.Id_Article = an.Id_Article AND an.warehouse_id = %s
- LEFT JOIN producer p ON p.producer_id = A.producer_id
- LEFT JOIN Tipos tp ON A.tipo_id = tp.tipo_id
- LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id
- LEFT JOIN Trabajadores TR ON TR.Id_Trabajador = tp.Id_Trabajador
- LEFT JOIN Tintas t ON t.Id_Tinta = A.color
- LEFT JOIN Compres C ON i.buy_id = C.Id_Compra
- LEFT JOIN Entradas E USING(Id_Entrada)
- LEFT JOIN Origen o ON o.id = A.id_origen
- LEFT JOIN last_year ly ON ly.Id_Article = A.Id_Article
- LEFT JOIN 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
+ 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 '
@@ -22310,7 +21860,247 @@ BEGIN
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;
@@ -22499,7 +22289,7 @@ BEGIN
DECLARE vMidnight DATETIME DEFAULT TIMESTAMP(CURDATE(),'23:59:59');
DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,vMidnight);
- DECLARE SAFE_ALERT_LEVEL INT DEFAULT 3;
+ DECLARE maxAlertLevel INT DEFAULT 2;
DROP TEMPORARY TABLE IF EXISTS tmp.production_buffer;
@@ -22553,15 +22343,16 @@ BEGIN
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,
@@ -22626,7 +22417,7 @@ BEGIN
DECLARE vDate DATE;
DECLARE vCodintrastat INT(11);
-
+ -- COMPROBAMOS SI EXISTE UN ARTÍCULO IGUAL.
SELECT
Id_Article
INTO vItem FROM
@@ -22639,14 +22430,14 @@ BEGIN
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,
@@ -22695,66 +22486,106 @@ BEGIN
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)
- SELECT vClient, Concat('TR ', vName, ' ', vCognames), vAddress, vDNI, vPhone, vProvince, vTown, vPostalCode, CONCAT(vCognames, ' ', vName), vName, 1, 3, vPostalCode, 4, 5, 300;
+ 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 (id, lastchange, `expire`) values (vClient, CURRENT_DATE(), CURRENT_DATE());
+ 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 (id, lastchange ,`expire`) values (vUser, CURRENT_DATE(), CURRENT_DATE());
+ 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);
@@ -22763,16 +22594,16 @@ BEGIN
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 ;
@@ -23221,7 +23052,7 @@ BEGIN
,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)
@@ -23232,12 +23063,12 @@ BEGIN
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
+ 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)
@@ -23248,12 +23079,12 @@ BEGIN
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
+ 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
@@ -23268,14 +23099,14 @@ BEGIN
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
+ 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
@@ -23301,7 +23132,11 @@ 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;
@@ -23399,7 +23234,7 @@ proc_label:BEGIN
ORDER BY CHAR_LENGTH(accion) DESC
LIMIT 1;
- IF @intidaccion IS null THEN
+ IF @intidaccion IS null THEN -- idaccion genèric per a evitar errors en cas de no existir
SET @intidaccion = 103;
END IF;
@@ -23492,14 +23327,14 @@ SET txt = CONCAT(txt,
'
Muchas gracias por su confianza
',
'
');
-
+-- Envío del email
IF emptyList = 0 THEN
SELECT CONCAT(`e-mail`,',pako@verdnatura.es') INTO MyMailTo
FROM Clientes
WHERE Id_Cliente = v_Client_Id AND `e-mail`>'';
- IF v_Client_Id = 7818 THEN
+ IF v_Client_Id = 7818 THEN -- LOEWE
SET MyMailTo = 'isabel@elisabethblumen.com,emunozca@loewe.es,pako@verdnatura.es';
@@ -23705,6 +23540,39 @@ join warehouse w on w.id = mov.warehouse_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 DROP PROCEDURE IF EXISTS `entradaCambioUpdate` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `entradaCambioUpdate`(IN vIdEntrada INT)
+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 = e.Id_Moneda AND tr.shipment >= rm.`date`
+ WHERE e.Id_Entrada = vIdEntrada
+ ORDER BY rm.date DESC
+ LIMIT 1;
+
+ UPDATE Entradas
+ SET comision = vComision
+ WHERE Id_Entrada = vIdEntrada;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -23807,6 +23675,29 @@ SET c.Cantidad = c.Cantidad - sub.Cantidad
WHERE Id_Entrada = Id_Minuendo;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `entryComisionUpdate` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `entryComisionUpdate`(IN vIdEntrada INT)
+BEGIN
+
+ UPDATE Entradas
+ SET comision = getComision(vIdEntrada)
+ WHERE Id_Entrada = vIdEntrada;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -23831,27 +23722,27 @@ BEGIN
DECLARE vEntry INT;
DECLARE vBucket VARCHAR(10);
-
+ -- seleccionamos travel
SELECT id, Id_Entrada INTO vTravel, vEntry
FROM travel t LEFT JOIN Entradas e ON t.id = e.travel_id
WHERE t.landing = vInOutDate AND t.shipment = vInOutDate AND t.warehouse_id_out = vShipmentWarehouse
AND t.warehouse_id = vLandingWarehouse AND agency_id = 15
LIMIT 1;
-
+ -- creamos el travel si es necesario
IF NOT IFNULL(vTravel,0) THEN
INSERT INTO travel (shipment, landing, warehouse_id, warehouse_id_out, agency_id)
VALUES (vInOutDate, vInOutDate, vLandingWarehouse, vShipmentWarehouse, 15);
SELECT LAST_INSERT_ID() INTO vTravel;
END IF;
-
+ -- creamos la Entrada si es necesario
IF NOT IFNULL(vEntry,0) THEN
INSERT INTO Entradas (Id_Proveedor, travel_id)
- VALUES (13, vTravel);
+ VALUES (13, vTravel); -- proveedor 'MOVIMIENTO ALMACEN'
SELECT LAST_INSERT_ID() INTO vEntry;
END IF;
-
+ -- creamos el cubo si es necesario
SELECT Id_Cubo INTO vBucket FROM Cubos WHERE Volumen = vVolume LIMIT 1;
IF NOT IFNULL(vBucket,'') > '' THEN
@@ -23902,14 +23793,14 @@ BEGIN
SELECT warehouse_id, Fecha, Fecha INTO vShipmentWarehouse, vShipmentDate, vLandingDate FROM Tickets WHERE Id_Ticket = vTicket;
-
+ -- seleccionamos travel
SELECT id, Id_Entrada INTO vTravel, vEntry
FROM travel t LEFT JOIN Entradas e ON t.id = e.travel_id
WHERE t.landing = vLandingDate AND t.shipment = vShipmentDate AND t.warehouse_id_out = vShipmentWarehouse AND t.warehouse_id = vLandingWarehouse
AND agency_id = 15
LIMIT 1;
-
+ -- creamos el travel si es necesario
IF vTravel IS NULL THEN
select vLandingDate;
INSERT INTO travel (shipment, landing, warehouse_id, warehouse_id_out, agency_id)
@@ -23917,10 +23808,10 @@ BEGIN
SELECT LAST_INSERT_ID() INTO vTravel;
END IF;
-
+ -- creamos la Entrada si es necesario
IF vEntry IS NULL THEN
INSERT INTO Entradas (Id_Proveedor, travel_id)
- VALUES (13, vTravel);
+ VALUES (13, vTravel); -- proveedor 'MOVIMIENTO ALMACEN'
SELECT LAST_INSERT_ID() INTO vEntry;
END IF;
@@ -23953,6 +23844,29 @@ DELIMITER ;
/*!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 `entryUpdateComision` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `entryUpdateComision`(IN vIdEntrada INT)
+BEGIN
+
+ UPDATE Entradas
+ SET comision = getComision(vIdEntrada, Id_Moneda)
+ WHERE Id_Entrada = vIdEntrada;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `entryWithItem` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
@@ -23974,28 +23888,28 @@ BEGIN
DECLARE vEntry INT;
DECLARE vBucket VARCHAR(10);
-
+ -- seleccionamos travel
SELECT id, Id_Entrada INTO vTravel, vEntry
FROM travel t LEFT JOIN Entradas e ON t.id = e.travel_id
WHERE t.landing = vInOutDate AND t.shipment = vInOutDate AND t.warehouse_id_out = vShipmentWarehouse
AND t.warehouse_id = vLandingWarehouse AND agency_id = 15
LIMIT 1;
-
+ -- creamos el travel si es necesario
IF NOT vTravel THEN
INSERT INTO travel (shipment, landing, warehouse_id, warehouse_id_out, agency_id)
VALUES (vShipmentDate, vLandingDate, vLandingWarehouse, vLandingWarehouse, 15);
SELECT LAST_INSERT_ID() INTO vTravel;
END IF;
-
+ -- creamos la Entrada si es necesario
IF NOT vEntry THEN
INSERT INTO Entradas (Id_Proveedor, travel_id)
- VALUES (13, vTravel);
+ VALUES (13, vTravel); -- proveedor 'MOVIMIENTO ALMACEN'
SELECT LAST_INSERT_ID() INTO vEntry;
END IF;
-
+ -- creamos el cubo si es necesario
SELECT Id_Cubo INTO vBucket FROM Cubos WHERE Volumen = vVolume LIMIT 1;
IF vBucket IS NULL THEN
INSERT INTO Cubos (Id_Cubo, Volumen)
@@ -24040,9 +23954,9 @@ DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `envios_masivos`(IN idTICKET INT, IN IdCONSIGNA_DESDE INT, IN IdCONSIGNA_HASTA INT)
BEGIN
+-- Se trata de clonar el ticket semilla para todos los consignatarios del rango, con los movimientos que contenga
-
-
+-- Insertamos los tickets
INSERT INTO Tickets(Id_Consigna, Id_Cliente, warehouse_id, Fecha, Alias, Tipo, Id_Trabajador, empresa_id, Id_Agencia)
SELECT c.Id_Consigna, t.Id_Cliente, t.warehouse_id, t.Fecha, c.Consignatario, t.Tipo, t.Id_Trabajador, t.empresa_id, t.Id_Agencia
@@ -24052,7 +23966,7 @@ WHERE Id_Ticket = idTICKET
AND c.Id_Consigna BETWEEN IdCONSIGNA_DESDE AND IdCONSIGNA_HASTA;
-
+-- Insertamos los movimientos
INSERT INTO Movimientos(Id_Article, Concepte, Cantidad, Preu, PrecioFijado, Id_Ticket)
SELECT Id_Article, Concepte, Cantidad, Preu, TRUE , t.Id_Ticket
@@ -24436,7 +24350,7 @@ CREATE DEFINER=`root`@`%` PROCEDURE `f10_no_vincular`(lngEntrada INTEGER)
BEGIN
DECLARE datFecha DATE DEFAULT CURDATE();
-
+-- Modifica el NoVincular si hay dos entradas con el mismo Packing y el mismo Id_Articulo
DROP TEMPORARY TABLE IF EXISTS f10_no_vincular_;
CREATE TEMPORARY TABLE IF NOT EXISTS f10_no_vincular_
SELECT c.Id_Entrada,c.Id_Compra,c.Id_Article, c.Novincular, c.Packing, be.pri
@@ -24448,7 +24362,7 @@ BEGIN
OR (c.Id_Entrada = 9200 AND be.ok <> FALSE)
OR c.Id_Entrada = lngEntrada) AND Id_Article <> 90;
-
+ -- Modifica el NoVincular si hay dos entradas con el mismo Packing y el mismo Id_Articulo
DROP TEMPORARY TABLE IF EXISTS f10_mismo_Packing;
CREATE TEMPORARY TABLE IF NOT EXISTS f10_mismo_Packing
SELECT * FROM (
@@ -24467,7 +24381,7 @@ BEGIN
OR (c.Id_Entrada = 9200 AND be.ok <> FALSE)
OR c.Id_Entrada = lngEntrada);
-
+-- Modifica el Id_Articulo si hay dos entradas con packing y el mismo Id_Articulo
DROP TEMPORARY TABLE IF EXISTS f10_mismo_Articulo;
CREATE TEMPORARY TABLE IF NOT EXISTS f10_mismo_Articulo
SELECT Id_Article FROM (
@@ -24509,8 +24423,41 @@ SELECT C.calidad,
LEFT(Article, 4) as Subtipo,
barcode,
'ASEGURADO' AS asegurado,
- Reino,
- R.orden,
+/*CASE A.tipo_id
+WHEN 75 THEN IF(M.Id_Article IN (120,2388,20100,16,10,130,104851,1,56,238,104850,104849,2),'RAMAJE',R.Reino)
+WHEN 68 THEN IF(M.Id_Article IN (11539,10,14),'RAMAJE',R.Reino)
+WHEN 69 THEN IF(M.Id_Article IN (41),'RAMAJE',R.Reino)
+WHEN 72 THEN IF(M.Id_Article IN (238),'RAMAJE',R.Reino)
+WHEN 2 THEN 'CYMBIDIUMS & ANTHURIUMS'
+WHEN 122 THEN 'CYMBIDIUMS & ANTHURIUMS'
+WHEN 12 THEN 'CYMBIDIUMS & ANTHURIUMS'
+WHEN 13 THEN 'CYMBIDIUMS & ANTHURIUMS'
+WHEN 14 THEN 'CYMBIDIUMS & ANTHURIUMS'
+WHEN 15 THEN 'CYMBIDIUMS & ANTHURIUMS'
+WHEN 71 THEN IF(LEFT(Article,2) = 'HC','Flor',R.Reino)
+WHEN 19 THEN IF(LEFT(Article,3) IN ('HEL','GIN'),'CYMBIDIUMS & ANTHURIUMS',R.Reino)
+WHEN 70 THEN IF(Article like '%red beauty%' or Article like '%clarinervium%','CYMBIDIUMS & ANTHURIUMS',R.Reino)
+WHEN 86 THEN 'Flor'
+ELSE R.Reino
+END as*/ Reino,
+ /*
+CASE A.tipo_id
+WHEN 75 THEN IF(M.Id_Article IN (120,2388,20100,16,10,130,104851,1,56,238,104850,104849,2),-1,R.orden)
+WHEN 68 THEN IF(M.Id_Article IN (11539,10,14),-1,R.orden)
+WHEN 69 THEN IF(M.Id_Article IN (41),-1,R.orden)
+WHEN 72 THEN IF(M.Id_Article IN (238),-1,R.orden)
+WHEN 2 THEN 0
+WHEN 122 THEN 0
+WHEN 12 THEN 0
+WHEN 13 THEN 0
+WHEN 14 THEN 0
+WHEN 15 THEN 0
+WHEN 71 THEN IF(LEFT(Article,2) = 'HC',1,R.orden)
+WHEN 19 THEN IF(LEFT(Article,3) IN ('HEL','GIN'),0,R.orden)
+WHEN 70 THEN IF(Article like '%red beauty%' or Article like '%clarinervium%',0,R.orden)
+WHEN 86 THEN 1
+ELSE R.orden
+END as*/ R.orden,
CS.Consignatario,
T.Id_Cliente,
T.Id_Trabajador,
@@ -24531,7 +24478,7 @@ SELECT C.calidad,
T.Observaciones,
Ag.Agencia Tipo,
TR.CodigoTrabajador,
-
+ /*0 Seguro,*/
M.OK,
M.Reservado,
A.Tallos,
@@ -24548,14 +24495,14 @@ SELECT C.calidad,
M.Id_Movimiento movement_id,
lpad(ifnull(cooler_path_detail_id, an.Nicho),5,'0') as path,
M.Descuento,M.Preu, mm.valor as Preparado, mm.original_quantity
- , p.`name` producer, T.warehouse_id, CS.POBLACION
+ , p.`name` producer, T.warehouse_id, CS.POBLACION -- JGF 2016-02-16
FROM
Tickets T
LEFT JOIN Movimientos M USING(Id_Ticket)
LEFT JOIN Articles A on A.Id_Article = M.Id_Article
LEFT JOIN Articles_nicho an ON A.Id_Article = an.Id_Article AND an.warehouse_id = T.warehouse_id
- LEFT JOIN producer p on p.producer_id = A.producer_id
+ LEFT JOIN producer p on p.producer_id = A.producer_id -- JGF 2016-02-16
LEFT JOIN cooler_path_detail c on left(an.Nicho,3) = pasillo
LEFT JOIN Origen O ON A.id_origen = O.id
LEFT JOIN Clientes C USING(Id_Cliente)
@@ -24891,21 +24838,21 @@ DECLARE datFEC DATE;
DECLARE intEMP INT;
DECLARE intCLI_OLD INT;
-
+/*Este procedure no funcionara correctament perque el strFactura ha de fer referencia al factura_id*/
SELECT Importe, Fecha, empresa_id, Id_Cliente
INTO dblIMPORTE, datFEC, intEMP, intCLI_OLD
FROM Facturas WHERE Id_Factura = strFactura;
-
+-- Cambia la empresa de la factura
UPDATE Facturas SET empresa_id = 965, Id_Cliente = intCLI WHERE Id_Factura = strFactura;
-
+-- Cambia la empresa de los tickets
UPDATE Tickets SET empresa_id = 965, Id_Cliente = intCLI WHERE Factura = strFactura;
-
+-- Descuenta la cantidad del cliente antiguo
INSERT INTO Recibos(Id_Factura
,Entregado
@@ -24923,7 +24870,7 @@ VALUES (strFactura
,intCLI_OLD
,intEMP);
-
+-- Carga el cobro en la cuenta del nuevo cliente
INSERT INTO Recibos(Id_Factura
,Entregado
@@ -25038,7 +24985,7 @@ BEGIN
DECLARE intCLI,intCLI2 INT DEFAULT 0;
DECLARE datFEC,datFEC2,auxdatFEC DATE DEFAULT '2001-01-01';
DECLARE lngTIC, lngTIC2 BIGINT DEFAULT 0;
-DECLARE intDiferencia INT DEFAULT 0;
+DECLARE intDiferencia INT DEFAULT 0; # Variable donde se colocará la diferencia de días entre dos fechas.
DECLARE done,EsPerdido bit DEFAULT 0;
DECLARE intEstado TINYINT(2) DEFAULT 0;
DECLARE intNuevo INT DEFAULT 1;
@@ -25046,8 +24993,14 @@ DECLARE intPerdido INT DEFAULT 2;
DECLARE intRecuperado INT DEFAULT 3;
-
-
+# Añado una fecha de fin para que no tenga en cuenta los tickets del futuro. (and Fecha<=current_date())
+/*
+DECLARE cursor1 CURSOR FOR SELECT Id_Ticket,ti.Id_Cliente,date_format(Fecha,'%Y-%m-%d') AS FormatoFecha
+FROM vn2008.Tickets ti
+WHERE DATE_FORMAT(Fecha,'%Y-%m-%d')>CAST(CONCAT(YEAR(CURDATE())-2,'-','01-01')AS DATE)
+AND DATE_FORMAT(Fecha,'%Y-%m-%d')<=LAST_DAY(CAST(CONCAT(intAno, '-' , intMes,'-',01) AS DATE))
+ORDER BY ti.Id_Cliente,Fecha;
+*/
DECLARE cursor1 CURSOR FOR SELECT Id_Ticket,fac.Id_Cliente,date_format(Fecha,'%Y-%m-%d') AS FormatoFecha
FROM Facturas fac
JOIN (SELECT Id_Ticket,Id_Cliente,Factura from Tickets ti where Factura is not null order by Fecha DESC,Id_Ticket DESC) sub1
@@ -25067,7 +25020,7 @@ CREATE TEMPORARY TABLE GC (Id_Ticket BIGINT,Fecha DATE,Id_Cliente int,Estado SMA
OPEN cursor1;
FETCH cursor1 INTO lngtIC,intCLI,datFEC;
-
+ # el primero registro es un cliente nuevo.
INSERT INTO GC(Id_Ticket, Fecha, Id_Cliente, Estado) VALUES(lngtIC,datFEC, intCLI,intNuevo);
SET auxdatFEC=datFEC;
@@ -25077,27 +25030,27 @@ OPEN cursor1;
WHEN DONE THEN SET intDiferencia=DATEDIFF(CURRENT_DATE,datFEC2);
WHEN intCLI=intCLI2 THEN
SET intDiferencia=DATEDIFF(datFEC2,datFEC);
- IF ((intEstado=2)) THEN
- INSERT INTO GC(Id_Ticket, Fecha, Id_Cliente, Estado) VALUES (lngtIC2,datFEC2, intCLI,intRecuperado);
+ IF ((intEstado=2)) THEN -- es recuperado despues de haberse perdido
+ INSERT INTO GC(Id_Ticket, Fecha, Id_Cliente, Estado) VALUES (lngtIC2,datFEC2, intCLI,intRecuperado); # RECUPERADO
SET intEstado=1;
SET auxdatFEC=datFEC2;
ELSE
IF (intDiferencia >= intDiasPerdidos) THEN
-
+ -- IF (DATE_FORMAT(datFEC2,'%Y-%m')<>DATE_FORMAT(DATE_ADD(datFEC,INTERVAL intDiasPerdidos DAY),'%Y-%m')) AND (intEstado<2) THEN
INSERT INTO GC(Id_Ticket, Fecha, Id_Cliente, Estado) VALUES (0,DATE_ADD(auxdatFEC,INTERVAL intDiasPerdidos DAY), intCLI,intPerdido);
- INSERT INTO GC(Id_Ticket, Fecha, Id_Cliente, Estado) VALUES (lngtIC2,datFEC2, intCLI,intRecuperado);
+ INSERT INTO GC(Id_Ticket, Fecha, Id_Cliente, Estado) VALUES (lngtIC2,datFEC2, intCLI,intRecuperado); # RECUPERADO
SET intEstado=1,auxdatFEC=datFEC2;
-
-
-
-
+ -- ELSE
+ -- INSERT INTO GC(Id_Ticket, Fecha, Id_Cliente, Estado) VALUES (lngtIC2,datFEC2, intCLI,intPerdido); # PERDIDO
+ -- SET intEstado=2; # Lo marcamos como perdido
+ -- END IF;
END IF;
END IF;
WHEN intCLI<>intCLI2 THEN
SET intEstado=0;
SET intDiferencia=DATEDIFF(CURRENT_DATE,datFEC);
- INSERT INTO GC(Id_Ticket, Fecha, Id_Cliente, Estado) VALUES(lngtIC2,datFEC2, intCLI2,intNuevo);
+ INSERT INTO GC(Id_Ticket, Fecha, Id_Cliente, Estado) VALUES(lngtIC2,datFEC2, intCLI2,intNuevo); # NUEVO
SET auxdatFEC=datFEC2;
END CASE;
SET datFEC=datFEC2;
@@ -25109,7 +25062,7 @@ OPEN cursor1;
CLOSE cursor1;
-
+ # inserto los registros de clientes sin ticket (Estado 4)
INSERT GC
SELECT 0,'2000-01-01',Id_Cliente,4
FROM vn2008.Clientes
@@ -25216,6 +25169,114 @@ CREATE DEFINER=`root`@`%` PROCEDURE `historico`(IN idART INT, IN wh INT, IN v_vi
BEGIN
DECLARE datFEC DATETIME;
+SELECT Fechainventario INTO datFEC FROM tblContadores;
+SET @a = 0;
+SELECT DATE(Fecha) AS Fecha,
+ Entrada,
+ Salida,
+ OK,
+ Alias,
+ Referencia,
+ id,
+ @a := @a + IFNULL(Entrada,0) - IFNULL(Salida,0) as acumulado,
+ F5,
+ v_virtual,
+ Calidad,CodigoTrabajador
+FROM
+
+ ( SELECT TR.landing as Fecha,
+ C.Cantidad as Entrada,
+ NULL as Salida,
+ (TR.received != FALSE) as OK,
+ P.Proveedor as Alias,
+ E.Referencia as Referencia,
+ E.Id_Entrada as id,
+ TR.delivered as F5,
+ 0 as Calidad, tra.CodigoTrabajador
+ FROM Compres C
+ JOIN Entradas E USING (Id_Entrada)
+ JOIN travel TR ON TR.id = E.travel_id
+ JOIN Proveedores P USING (Id_Proveedor)
+ LEFT JOIN Articles a ON a.Id_Article = C.Id_Article
+ LEFT JOIN Tipos ti ON ti.Id_Tipo = a.tipo_id
+ LEFT JOIN Trabajadores tra ON tra.Id_Trabajador = ti.Id_Trabajador
+ WHERE TR.landing >= datFEC
+ AND wh IN (TR.warehouse_id , 0)
+ AND C.Id_Article = idART
+ AND E.Inventario = 0
+
+ UNION ALL
+
+ SELECT TR.shipment as Fecha,
+ NULL as Entrada,
+ C.Cantidad as Salida,
+ TR.delivered as OK,
+ P.Proveedor as Alias,
+ E.Referencia as Referencia,
+ E.Id_Entrada as id,
+ TR.delivered as F5,
+ 0 as Calidad, tra.CodigoTrabajador
+
+ FROM Compres C
+ JOIN Entradas E USING (Id_Entrada)
+ JOIN travel TR ON TR.id = E.travel_id
+ JOIN warehouse ON warehouse.id = TR.warehouse_id_out
+ JOIN Proveedores P USING (Id_Proveedor)
+ LEFT JOIN Articles a ON a.Id_Article = C.Id_Article
+ LEFT JOIN Tipos ti ON ti.Id_Tipo = a.tipo_id
+ LEFT JOIN Trabajadores tra ON tra.Id_Trabajador = ti.Id_Trabajador
+ WHERE TR.shipment >= datFEC
+ AND wh IN (TR.warehouse_id_out,0)
+ AND Id_Proveedor <> 4
+ AND C.Id_Article = idART
+ AND E.Inventario = 0
+ AND fuente = 0
+
+ UNION ALL
+
+ SELECT T.Fecha as Fecha,
+ NULL as Entrada,
+ M.Cantidad as Salida,
+ (IFNULL(ts.alertLevel,0) > 1 OR ok ) as OK,
+ T.Alias as Alias,
+ T.Localizacion as Referencia,
+ T.Id_Ticket as id,
+ FALSE EtiquetasEmitidas,
+ C.Calidad, tr.CodigoTrabajador
+
+ FROM Movimientos M
+ JOIN Tickets T USING (Id_Ticket)
+ LEFT JOIN vn.ticketState ts ON ts.ticket = T.Id_Ticket
+ JOIN Clientes C ON C.Id_Cliente = T.Id_Cliente
+ LEFT JOIN Trabajadores tr ON tr.Id_Trabajador = C.Id_Trabajador
+ WHERE T.Fecha >= datFEC
+ AND M.Id_Article = idART
+ AND wh IN (T.warehouse_id , 0)
+
+ ) AS Historico
+ORDER BY Fecha, OK DESC, Entrada 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 `historicokk` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `historicokk`(IN idART INT, IN wh INT, IN v_virtual INT)
+BEGIN
+DECLARE datFEC DATETIME;
+
SELECT Fechainventario INTO datFEC FROM tblContadores;
SET @a = 0;
SELECT DATE(Fecha) AS Fecha,
@@ -25379,10 +25440,10 @@ BEGIN
DECLARE datini,datfin,datiniaux,datfinaux DATE;
DECLARE dblrate0,dblrate0aux,dblrate1,dblrate1aux,dblrate2,dblrate2aux,dblrate3,dblrate3aux DOUBLE DEFAULT 0;
DECLARE boolBeforeStart TINYINT DEFAULT 1;
-
+ -- selecciona el primer bloque apartir de la mínima fecha que esta dentro del rango y la fecha de finalizar es posterior
SET datiniaux = NULL;
SET datfinaux = NULL;
-
+ -- guarda en dblrate0aux el valor del valor del periode, a lo millor falla si no trau cap linea
SELECT IFNULL(rate_0,0), IFNULL(rate_1,0), IFNULL(rate_2,0), IFNULL(rate_3,0)
INTO dblrate0aux,dblrate1aux,dblrate2aux,dblrate3aux FROM price_fixed
WHERE date_start = id_datestart AND warehouse_id IN (0,id_wh) AND item_id = id_art;
@@ -25402,22 +25463,22 @@ BEGIN
ORDER BY date_start LIMIT 1;
IF datini IS NOT NULL THEN
-
+ -- Inserta un registre(dia -1)
IF boolBeforeStart THEN
INSERT INTO historicoprecio(date_start,rate_0,rate_1,rate_2,rate_3)
VALUES(TIMESTAMPADD(DAY,-1,datini),dblrate0aux,dblrate1aux,dblrate2aux,dblrate3aux);
SET boolBeforeStart = TRUE;
END IF;
-
+ -- reiniciem els valors de les variables
SET datiniaux = NULL;
SET datfinaux = NULL;
-
+ -- seleccionem el dia fins al qual dura el periode eliminant els dies que queden solapats
SELECT MIN(date_start) INTO datfinaux FROM price_fixed WHERE date_start > datini AND date_start < datfin AND date_end >= datfin
AND warehouse_id IN (0,id_wh) AND item_id = id_art;
-
+ -- cridada recursiva per al periode(retallat si cal) inclós
CALL historicoprecio2 (id_art,id_wh,datini,IFNULL(datfinaux,datfin));
-
+ -- anyadeix el valor que ha d'agafar el dia seguent d'acabar el periode actual.
IF datfinaux IS NULL THEN
INSERT INTO historicoprecio(date_start,rate_0,rate_1,rate_2,rate_3)
VALUES(TIMESTAMPADD(DAY,1,datfin),dblrate0aux,dblrate1aux,dblrate2aux,dblrate3aux),
@@ -25432,7 +25493,7 @@ BEGIN
END IF;
UNTIL datini IS NULL END REPEAT;
-
+ -- inserta linea caso base
INSERT INTO historicoprecio(date_start,rate_0,rate_1,rate_2,rate_3) VALUES(id_datestart,dblrate0aux,dblrate1aux,dblrate2aux,dblrate3aux)
ON DUPLICATE KEY UPDATE rate_0 = dblrate0,rate_1 = dblrate1,rate_2 = dblrate2,rate_3 = dblrate3;
END ;;
@@ -25472,7 +25533,7 @@ SET today = curdate();
E.Referencia as Referencia,
E.Id_Entrada as id,
TR.delivered as F5, 0 as Calidad
- FROM Compres C
+ FROM Compres C -- mirar perque no entra en received
INNER JOIN Entradas E USING (Id_Entrada)
INNER JOIN travel TR ON TR.id = E.travel_id
INNER JOIN Proveedores P USING (Id_Proveedor)
@@ -25525,7 +25586,7 @@ SET today = curdate();
FROM historico_pasado
WHERE Fecha < datfecha;
-
+ -- WHERE historico_pasado.Fecha < fecha_inv ;
SELECT p1.*, NULL as v_virtual FROM(
@@ -25895,7 +25956,7 @@ from (
inner join Clientes cli on ti.Id_Cliente=cli.Id_Cliente
inner join vn2008.Trabajadores on cli.Id_Trabajador=Trabajadores.Id_Trabajador
where (date between date_add(dat_from,interval -1 year) and date_add(dat_to,interval -1 year))
-
+ -- and cli.invoice
group by CodigoTrabajador,ti.Id_Cliente
union all
@@ -25912,7 +25973,7 @@ select CodigoTrabajador,cli.Id_Cliente,Cliente,0 ImporteAnt,
inner join vn2008.Permisos perm on cli.Id_Trabajador=perm.Id_Trabajador
inner join vn2008.Grupos grup on perm.Id_Grupo=grup.Id
where ti.Fecha between dat_from and DAYEND(dat_to)
-
+ -- and cli.invoice
AND r.display <> 0
and (grup.Id in (6) or cli.Id_Trabajador in (20))
group by CodigoTrabajador,c.Id_Cliente,year(Fecha)
@@ -25988,9 +26049,13 @@ BEGIN
JOIN edi.supplier es ON es.supplier_id = be.pro
WHERE c.Id_Compra = idCompra;
-
+ -- SELECT LAST_INSERT_ID() INTO last_insert;
-
+ /*
+ IF last_insert > 0 THEN
+ UPDATE Articles a JOIN Compres c
+ ON a.Id_Article = c.Id_Article SET a.producer_id = last_insert WHERE c.Id_Compra = idCompra;
+ END IF;*/
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -26029,21 +26094,21 @@ BEGIN
-
+-- PREVIO: Crear una tabla para filtrar los articulos que interesan
DROP TEMPORARY TABLE IF EXISTS article_selection;
SET strFILTRO = REPLACE(strFILTRO, 'Id_Article','A.Id_Article');
- CALL sql_query (sql_printf(
- 'CREATE TEMPORARY TABLE article_selection
+ CALL util.exec (sql_printf(
+ 'CREATE TEMPORARY TABLE vn2008.article_selection
ENGINE = MEMORY
- SELECT Id_Article
- FROM Articles A
- LEFT JOIN Tipos USING(tipo_id)
- LEFT JOIN Trabajadores TR ON TR.Id_Trabajador = Tipos.Id_Trabajador
- LEFT JOIN Tintas ON A.color = Tintas.Id_Tinta
- LEFT JOIN Origen ON Origen.id = A.id_origen
+ SELECT A.Id_Article
+ FROM vn2008.Articles A
+ LEFT JOIN vn2008.Tipos t USING(tipo_id)
+ LEFT JOIN vn2008.Trabajadores TR ON TR.Id_Trabajador = t.Id_Trabajador
+ LEFT JOIN vn2008.Tintas tn ON A.color = tn.Id_Tinta
+ LEFT JOIN vn2008.Origen o ON o.id = A.id_origen
WHERE %s AND %s AND reino_id != %v'
,IF(i_tipo, CONCAT('tipo_id = ', i_tipo), 'TRUE')
,strFILTRO
@@ -26054,9 +26119,9 @@ BEGIN
ALTER TABLE article_selection ADD PRIMARY KEY(Id_Article);
-
+-- PRIMER PASO: Cálculo del inventario inicial, valorado
-
+-- Averiguamos la fecha del inventario inmediatemente anterior a la fecha de inicio
SELECT landing INTO d_INV
FROM travel TR
@@ -26081,7 +26146,7 @@ ALTER TABLE article_selection ADD PRIMARY KEY(Id_Article);
END IF;
-
+-- Ubicamos la fecha de inventario segun su posición relativa a la de inicio y a la de fin
IF d_INV <= d_START THEN
@@ -26103,7 +26168,7 @@ END IF;
DROP TEMPORARY TABLE IF EXISTS inv;
-
+-- Preparamos la tabla temporal que va a almacenar el valor y cantidad de productos
CREATE TEMPORARY TABLE inv
(w_id SMALLINT,
@@ -26115,7 +26180,7 @@ CREATE TEMPORARY TABLE inv
ALTER TABLE inv ADD PRIMARY KEY USING HASH (w_id, Id_Article, Sector);
-
+/************************** SECTOR INICIAL: 0 *****************************/
CASE intCASE
@@ -26135,7 +26200,7 @@ CASE intCASE
END CASE;
-
+-- Inicializamos el inventario
INSERT INTO inv(w_id, Id_Article, Unidades,Valor)
@@ -26155,7 +26220,7 @@ END CASE;
AND TR.warehouse_id != TR.warehouse_id_out
GROUP BY TR.warehouse_id, C.Id_Article;
-
+-- Se insertan las compras que llegan entre la fecha del inventario y la fecha inicial
INSERT INTO inv(w_id, Id_Article, Unidades, Valor)
SELECT TR.warehouse_id, C.Id_Article, C.Cantidad * IF(bolREVERSE,-1,1), ifnull(C.Costefijo,0) + IFNULL(C.Embalajefijo,0) + IFNULL(C.Portefijo,0) + IFNULL(C.Comisionfija,0)
@@ -26177,7 +26242,7 @@ END CASE;
ON DUPLICATE KEY UPDATE inv.Unidades = inv.Unidades + (C.Cantidad * IF(bolREVERSE,-1,1))
, Valor = IF(Costefijo > 0,ifnull(C.Costefijo,0) + IFNULL(C.Embalajefijo,0) + IFNULL(C.Portefijo,0) + IFNULL(C.Comisionfija,0),Valor);
-
+-- Se sacan las que salen
INSERT INTO inv(w_id, Id_Article, Unidades)
SELECT TR.warehouse_id_out, C.Id_Article, C.Cantidad * IF(bolREVERSE,1,-1)
@@ -26197,7 +26262,7 @@ END CASE;
AND TR.warehouse_id != TR.warehouse_id_out
ON DUPLICATE KEY UPDATE inv.Unidades = inv.Unidades + (C.Cantidad * IF(bolREVERSE,1,-1));
-
+-- Ahora las ventas
INSERT INTO inv(w_id, Id_Article, Unidades)
SELECT w.id, M.Id_Article, M.Cantidad * IF(bolREVERSE,1,-1)
@@ -26217,7 +26282,7 @@ END CASE;
UPDATE inv SET Valor = inv.Unidades * Valor;
-
+/************************** SECTOR ENTRADAS: 1 *****************************/
SET i_SECTOR = 1;
@@ -26227,7 +26292,7 @@ SET i_SECTOR = 1;
-
+-- Ahora vamos a incrementar en unidades y valor el producto recibido en el rango de fechas del procedimiento
INSERT INTO inv(Sector, w_id, Id_Article, Unidades, Valor)
SELECT i_SECTOR, TR.warehouse_id, C.Id_Article, sum(C.Cantidad )
@@ -26251,11 +26316,11 @@ SET i_SECTOR = 1;
-
+/************************** SECTOR SALIDAS: 2 *****************************/
SET i_SECTOR = 2;
-
+-- Ahora vamos a restar en unidades y valor el producto que sale de los almacenes en el rango de fechas del procedimiento
INSERT INTO inv(Sector, w_id, Id_Article, Unidades, Valor)
SELECT i_SECTOR, TR.warehouse_id_out, C.Id_Article, sum( -1 * C.Cantidad )
@@ -26278,7 +26343,7 @@ SET i_SECTOR = 2;
-
+/******************** SECTOR VENTAS: 3 **************************************/
SET i_SECTOR = 3;
@@ -26313,7 +26378,13 @@ IF d_START >= '2015-10-01' THEN
AND i_wh IN (0,T.warehouse_id)
AND w.comisionantes
AND reino_id != ID_REINO_OTROS
-
+ /*
+ AND (
+ T.Id_Cliente != ID_CLIENTE_COMPLEMENTOS
+ OR
+ TP.Id_Trabajador != ID_TRABAJADOR_MARIBEL
+ )
+ */
GROUP BY T.warehouse_id, Id_Article;
@@ -26361,13 +26432,19 @@ ELSE
AND i_wh IN (0,T.warehouse_id)
AND w.comisionantes
AND reino_id != ID_REINO_OTROS
-
+ /*
+ AND (
+ T.Id_Cliente != ID_CLIENTE_COMPLEMENTOS
+ OR
+ TP.Id_Trabajador != ID_TRABAJADOR_MARIBEL
+ )
+ */
GROUP BY T.warehouse_id, Id_Article;
END IF;
-
+ -- Ventas del año anterior
DROP TEMPORARY TABLE IF EXISTS Ventas_Lastyear;
@@ -26405,7 +26482,13 @@ END IF;
AND i_wh IN (0,T.warehouse_id)
AND w.comisionantes
AND reino_id != ID_REINO_OTROS
-
+ /*
+ AND (
+ T.Id_Cliente != ID_CLIENTE_COMPLEMENTOS
+ OR
+ TP.Id_Trabajador != ID_TRABAJADOR_MARIBEL
+ )
+ */
GROUP BY CodigoTrabajador, Id_Tipo;
@@ -26413,7 +26496,7 @@ END IF;
-
+/******************** SECTOR FINAL: 4 **************************************/
SET i_SECTOR = 4;
@@ -26436,9 +26519,9 @@ CASE intCASE
END CASE;
+-- Ahora repetimos el proceso de inventario, para contabilizar el stock remanente.
-
-
+-- Inicializamos el inventario
INSERT INTO inv(Sector, w_id, Id_Article, Unidades, Valor)
@@ -26463,7 +26546,7 @@ END CASE;
-
+-- Se insertan las compras que llegan entre la fecha del inventario y la fecha inicial
INSERT INTO inv(Sector, w_id, Id_Article, Unidades, Valor)
SELECT i_SECTOR, TR.warehouse_id, C.Id_Article, C.Cantidad * IF(bolREVERSE,-1,1), nz(Costefijo) + nz(Portefijo) + nz(Embalajefijo) + nz(Comisionfija)
@@ -26485,7 +26568,7 @@ END CASE;
ON DUPLICATE KEY UPDATE inv.Unidades = inv.Unidades + (C.Cantidad * IF(bolREVERSE,-1,1))
, Valor = IF( nz(Costefijo) > 0,nz(Costefijo) + nz(Portefijo) + nz(Embalajefijo) + nz(Comisionfija),Valor);
-
+-- Se sacan las que salen
INSERT INTO inv(Sector, w_id, Id_Article, Unidades)
SELECT i_SECTOR, TR.warehouse_id_out, C.Id_Article, C.Cantidad * IF(bolREVERSE,1,-1)
@@ -26506,7 +26589,7 @@ END CASE;
ON DUPLICATE KEY UPDATE inv.Unidades = inv.Unidades + (C.Cantidad * IF(bolREVERSE,1,-1));
-
+-- Ahora las ventas
INSERT INTO inv(Sector, w_id, Id_Article, Unidades)
SELECT i_SECTOR, w.id, M.Id_Article, M.Cantidad * IF(bolREVERSE,1,-1)
@@ -26522,13 +26605,13 @@ END CASE;
AND reino_id != ID_REINO_OTROS
ON DUPLICATE KEY UPDATE inv.Unidades = inv.Unidades + (M.Cantidad * IF(bolREVERSE,1,-1));
-
+-- Valoramos el inventario final
UPDATE inv SET Valor = inv.Unidades * Valor WHERE Sector =4;
-
+-- Resultado
DROP TEMPORARY TABLE IF EXISTS Margen_Desglose;
@@ -26592,7 +26675,7 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `inventario_multiple`(IN wh TINYINT(2), IN date_ticket DATETIME)
BEGIN
-
+-- DEPRECATED USAR cache.available_refresh
DECLARE date_order DATETIME;
DECLARE date_end DATETIME DEFAULT CURDATE();
DECLARE date_aux DATE;
@@ -26611,8 +26694,17 @@ BEGIN
ADD `inventory` FLOAT(7,2) NOT NULL,
ADD `visible` FLOAT(7,2) NOT NULL;
-
-
+ -- JGF 2015-02-19 Falla, el valor @camp es cero y falla Campanya
+ /*
+ SELECT
+ IF(@camp := DATEDIFF(campaign, date_ticket) BETWEEN 0 AND campaign_life,
+ TIMESTAMPADD(DAY, -campaign_life, campaign),
+ FechaInventario),
+ IF(@camp BETWEEN 0 AND campaign_life,
+ TIMESTAMP(campaign, '23:59:59'),
+ TIMESTAMP(TIMESTAMPADD(DAY, 15, date_ticket),'23:59:59'))
+ INTO date_start, date_end
+ FROM tblContadores;*/
SELECT
FechaInventario,TIMESTAMP(TIMESTAMPADD(DAY, 15, date_ticket),'23:59:59')
@@ -26623,7 +26715,7 @@ BEGIN
SET date_order = TIMESTAMP(DATE(date_ticket), '00:00:00');
SET date_tomorrow = TIMESTAMPADD(DAY, 1, date_order);
-
+-- Inventario hasta dia antes del ticket
CALL item_stock(wh,date_ticket,NULL);
INSERT INTO article_inventory (article_id,inventory,visible,available)
@@ -26632,7 +26724,7 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS tmp_item;
-
+-- Inventario ventas durante el dia del ticket
INSERT INTO article_inventory(article_id,visible)
SELECT Id_Article, SUM(amount) AS Subtotal
@@ -26704,7 +26796,7 @@ BEGIN
visible = inventory + VALUES(visible);
-
+ -- Disponible en el futuro
CALL item_travel (wh, date_order);
SET date_aux = DATE(date_order);
@@ -26807,7 +26899,7 @@ proc: BEGIN
DECLARE date_top DATETIME;
DECLARE date_tomorrow DATETIME;
- SET date_ticket = DATE(date_ticket);
+ SET date_ticket = DATE(date_ticket); -- PAK
ALTER TABLE `article_inventory`
ADD `avalaible` INT NOT NULL,
@@ -26829,7 +26921,7 @@ proc: BEGIN
SET date_tomorrow = TIMESTAMPADD(DAY, 1,date_ticket);
SET date_top = TIMESTAMPADD(DAY, 1,date_end);
-
+ -- Calculo del inventario dia D a las 24:00 zulu
UPDATE article_inventory AI INNER JOIN
@@ -26852,7 +26944,7 @@ proc: BEGIN
SELECT Id_Article, Cantidad
FROM Compres C INNER JOIN Entradas E USING (Id_Entrada)
LEFT JOIN travel TR ON E.travel_id = TR.id
- JOIN warehouse W ON W.id = TR.warehouse_id
+ JOIN warehouse W ON W.id = TR.warehouse_id -- PAK
WHERE TR.landing BETWEEN date_start AND date_ticket
AND IF(wh = 0, W.is_comparative, wh =TR.warehouse_id)
AND E.Inventario = 0
@@ -26886,7 +26978,7 @@ proc: BEGIN
AI.sd = T2.Subtotal;
-
+ -- Calculo del visible
UPDATE article_inventory AI INNER JOIN
(
@@ -26895,8 +26987,8 @@ proc: BEGIN
SELECT Id_Article, Cantidad AS amount
FROM Movimientos M
JOIN Tickets T USING (Id_Ticket)
- JOIN warehouse W ON W.id = T.warehouse_id
- WHERE Fecha >= date_ticket AND Fecha < date_tomorrow
+ JOIN warehouse W ON W.id = T.warehouse_id -- PAK
+ WHERE Fecha >= date_ticket AND Fecha < date_tomorrow -- PAK
AND (M.OK = 0 AND T.Etiquetasemitidas = 0 AND T.Factura IS NULL)
AND IF(wh = 0, W.is_comparative, wh =T.warehouse_id)
@@ -26906,7 +26998,7 @@ proc: BEGIN
FROM Compres C
JOIN Entradas E USING (Id_Entrada)
JOIN travel TR ON E.travel_id = TR.id
- JOIN warehouse W ON W.id = TR.warehouse_id
+ JOIN warehouse W ON W.id = TR.warehouse_id -- PAK
WHERE TR.landing = date_ticket
AND TR.received = 0
AND E.Inventario = 0
@@ -26935,7 +27027,7 @@ proc: BEGIN
SET AI.visible = AI.visible + T2.Subtotal;
-
+ -- Calculo del disponible
CALL item_travel (wh, date_ticket);
@@ -26959,7 +27051,7 @@ proc: BEGIN
FROM Compres C
JOIN Entradas E USING (Id_Entrada)
JOIN travel TR ON E.travel_id = TR.id
- JOIN warehouse W ON W.id = TR.warehouse_id
+ JOIN warehouse W ON W.id = TR.warehouse_id -- PAK
WHERE TR.landing BETWEEN date_tomorrow AND date_end
AND IF(wh = 0, W.is_comparative, wh =TR.warehouse_id)
AND E.Inventario = 0
@@ -27025,7 +27117,7 @@ BEGIN
ALTER TABLE article_inventory
ADD visible FLOAT(7,2) NOT NULL;
-
+ -- Campaña
SELECT
IF(@camp := DATEDIFF(campaign, date_ticket) BETWEEN 0 AND campaign_life ,
@@ -27094,7 +27186,7 @@ proc: BEGIN
DECLARE i_avalaible INTEGER;
DECLARE wh INTEGER;
- SET date_ticket = DATE(date_ticket);
+ SET date_ticket = DATE(date_ticket); -- PAK
ALTER TABLE `article_inventory`
ADD `avalaible` INT NOT NULL,
@@ -27116,7 +27208,7 @@ proc: BEGIN
SET date_tomorrow = TIMESTAMPADD(DAY, 1,date_ticket);
SET date_top = TIMESTAMPADD(DAY, 1,date_end);
-
+ -- Calculo del inventario dia D a las 24:00 zulu
UPDATE article_inventory AI INNER JOIN
@@ -27131,7 +27223,7 @@ proc: BEGIN
FROM Movimientos M
JOIN Tickets T USING (Id_Ticket)
- JOIN warehouse_joined wj ON T.warehouse_id = wj.warehouse_id
+ JOIN warehouse_joined wj ON T.warehouse_id = wj.warehouse_id -- JGF 15/12/14
WHERE DATE(Fecha) BETWEEN date_start AND date_ticket
AND wh_joined IN (wj.warehouse_alias_id, 0)
UNION ALL
@@ -27141,7 +27233,7 @@ proc: BEGIN
FROM Compres C INNER JOIN Entradas E USING (Id_Entrada)
LEFT JOIN travel TR ON E.travel_id = TR.id
- JOIN warehouse_joined wj ON TR.warehouse_id = wj.warehouse_id
+ JOIN warehouse_joined wj ON TR.warehouse_id = wj.warehouse_id -- JGF 15/12/14
WHERE TR.landing BETWEEN date_start AND date_ticket
AND wh_joined IN (wj.warehouse_alias_id, 0)
@@ -27155,7 +27247,7 @@ proc: BEGIN
JOIN Entradas E USING (Id_Entrada)
JOIN travel TR ON E.travel_id = TR.id
- JOIN warehouse_joined wj ON TR.warehouse_id_out = wj.warehouse_id
+ JOIN warehouse_joined wj ON TR.warehouse_id_out = wj.warehouse_id -- JGF 15/12/14
WHERE TR.shipment BETWEEN date_start AND date_ticket
AND wh_joined IN (wj.warehouse_alias_id,0)
AND E.Inventario = 0
@@ -27178,7 +27270,7 @@ proc: BEGIN
SELECT avalaible INTO i_avalaible FROM article_inventory WHERE article_id = 21012;
-
+ -- Calculo del visible
UPDATE article_inventory AI INNER JOIN
(
@@ -27188,8 +27280,8 @@ proc: BEGIN
FROM Movimientos M
JOIN Tickets T USING (Id_Ticket)
- JOIN warehouse_joined wj ON T.warehouse_id = wj.warehouse_id
- WHERE Fecha >= date_ticket AND Fecha < date_tomorrow
+ JOIN warehouse_joined wj ON T.warehouse_id = wj.warehouse_id -- JGF 15/12/14
+ WHERE Fecha >= date_ticket AND Fecha < date_tomorrow -- PAK
AND (M.OK = 0 AND T.Etiquetasemitidas = 0 AND T.Factura IS NULL)
AND wh_joined IN (wj.warehouse_alias_id, 0)
UNION ALL
@@ -27199,7 +27291,7 @@ proc: BEGIN
JOIN Entradas E USING (Id_Entrada)
JOIN travel TR ON E.travel_id = TR.id
- JOIN warehouse_joined wj ON TR.warehouse_id = wj.warehouse_id
+ JOIN warehouse_joined wj ON TR.warehouse_id = wj.warehouse_id -- JGF 15/12/14
WHERE TR.landing = date_ticket
AND TR.received = 0
@@ -27212,7 +27304,7 @@ proc: BEGIN
SELECT Id_Article, Cantidad
FROM Compres C INNER JOIN Entradas E USING (Id_Entrada)
LEFT JOIN travel TR ON E.travel_id = TR.id
- JOIN warehouse_joined wj ON TR.warehouse_id_out = wj.warehouse_id
+ JOIN warehouse_joined wj ON TR.warehouse_id_out = wj.warehouse_id -- JGF 15/12/14
WHERE TR.shipment = date_ticket
AND TR.delivered = 0
AND E.Inventario = 0
@@ -27228,7 +27320,7 @@ proc: BEGIN
SET AI.visible = AI.visible + T2.Subtotal;
-
+ -- Calculo del disponible
SELECT IF(COUNT(warehouse_id),0,warehouse_id) INTO wh FROM warehouse_joined WHERE warehouse_alias_id = wh_joined;
CALL item_travel (wh, date_ticket);
@@ -27245,7 +27337,7 @@ proc: BEGIN
JOIN Tickets T USING (Id_Ticket)
- JOIN warehouse_joined wj ON T.warehouse_id = wj.warehouse_id
+ JOIN warehouse_joined wj ON T.warehouse_id = wj.warehouse_id -- JGF 15/12/14
WHERE Fecha BETWEEN date_tomorrow AND date_end
AND wh_joined IN (wj.warehouse_alias_id, 0)
@@ -27256,7 +27348,7 @@ proc: BEGIN
JOIN Entradas E USING (Id_Entrada)
JOIN travel TR ON E.travel_id = TR.id
- JOIN warehouse_joined wj ON TR.warehouse_id = wj.warehouse_id
+ JOIN warehouse_joined wj ON TR.warehouse_id = wj.warehouse_id -- JGF 15/12/14
WHERE TR.landing BETWEEN date_tomorrow AND date_end
AND wh_joined IN (wj.warehouse_alias_id, 0)
@@ -27268,7 +27360,7 @@ proc: BEGIN
JOIN Entradas E USING (Id_Entrada)
JOIN travel TR ON E.travel_id = TR.id
- JOIN warehouse_joined wj ON TR.warehouse_id_out = wj.warehouse_id
+ JOIN warehouse_joined wj ON TR.warehouse_id_out = wj.warehouse_id -- JGF 15/12/14
WHERE TR.shipment BETWEEN date_tomorrow AND date_end
AND wh_joined IN (wj.warehouse_alias_id,0)
AND E.Inventario = 0
@@ -27340,13 +27432,13 @@ BEGIN
SET date_end = TIMESTAMP(TIMESTAMPADD(DAY, -1, date_ticket),'23:59:59');
-
+ -- Utilizo el valor clave 4848 para days_max para aprovechar el procedimiento para el frmCamiones de eti
IF days_max = 4848 THEN
set date_ticket = date_end;
END IF;
-
+ -- Calculo del inventario dia D a las 24:00
UPDATE article_inventory AI INNER JOIN
(
@@ -27407,9 +27499,6 @@ DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `inventario_valorado`(IN d_FEC DATE, IN bol_DESGLOSE BOOLEAN)
BEGIN
-
-
-
DECLARE d_INV DATE;
DECLARE bolREVERSE BOOLEAN DEFAULT 0;
DECLARE d_INV2 DATE;
@@ -27422,8 +27511,6 @@ BEGIN
ORDER BY landing DESC
LIMIT 1;
-
-
SET bolREVERSE = IF (d_INV is null, 1, 0);
@@ -27550,14 +27637,16 @@ BEGIN
IF bol_DESGLOSE THEN
- SELECT w_id, Id_Article, Article, Medida, Cantidad,Id_Tipo,reino_id, coste, cast(total as decimal(10,2)) total
+ SELECT inv.w_id, a.Id_Article, a.Article, a.Medida, inv.Cantidad, tp.Id_Tipo,
+ tp.reino_id, inv.coste, cast(inv.total as decimal(10,2)) total, an.nicho
FROM inv
- JOIN warehouse w on w.id = w_id
- JOIN Articles USING(Id_Article)
- JOIN Tipos TP USING(tipo_id)
+ JOIN warehouse w on w.id = w_id
+ JOIN Articles a ON a.Id_Article = inv.Id_Article
+ JOIN Tipos tp ON tp.tipo_id = a.tipo_id
+ JOIN Articles_nicho an ON an.Id_Article = a.Id_Article
where w.valuatedInventory
- and total > 0
- order by total desc;
+ and inv.total > 0
+ order by inv.total desc;
ELSE
@@ -27695,7 +27784,7 @@ END IF;
AND A.tipo_id NOT IN (21,7)
ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (C.Cantidad * IF(bolREVERSE,-1,1));
-
+-- SELECT * FROM inv WHERE Id_Article = 10067;
INSERT INTO inv(w_id, Id_Article, cantidad)
SELECT TR.warehouse_id_out, C.Id_Article, C.Cantidad * IF(bolREVERSE,1,-1)
@@ -27714,7 +27803,7 @@ END IF;
-
+-- SELECT * FROM inv WHERE Id_Article = 10067;
INSERT INTO inv(w_id, Id_Article, cantidad)
SELECT w.id, M.Id_Article, M.Cantidad * IF(bolREVERSE,1,-1)
@@ -27730,7 +27819,7 @@ END IF;
AND A.tipo_id NOT IN (21,7)
ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + M.Cantidad * IF(bolREVERSE,1,-1);
-
+-- SELECT * FROM inv WHERE Id_Article = 10067;
INSERT INTO inv(w_id, Id_Article, cantidad)
SELECT w.id, M.Id_Article, M.Cantidad * IF(bolREVERSE,0,-1)
@@ -27748,7 +27837,7 @@ END IF;
AND A.tipo_id NOT IN (21,7)
ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + M.Cantidad * IF(bolREVERSE,0,-1);
-
+-- SELECT * FROM inv WHERE Id_Article = 10067;
UPDATE inv
JOIN ( SELECT * FROM
@@ -27786,7 +27875,7 @@ WHERE inv.cantidad > 0;
DELETE FROM inv WHERE Cantidad IS NULL or Cantidad <= 0 or total = 0;
-
+-- Incrementamos las cantidades para alcanzar el valor fijado al inicio
SELECT SUM(total) INTO inv_value FROM inv;
UPDATE inv SET cantidad = ROUND(cantidad * inv_value_new / inv_value ,0);
@@ -27802,7 +27891,7 @@ SELECT inv.*, Article, Medida, Id_Tipo,reino_id
FROM inv
JOIN Articles USING(Id_Article)
JOIN Tipos TP USING(tipo_id)
-where w_id IN (1,44, 5)
+where w_id IN (1,44, 5) -- JGF 2015-06-08 afegeix 41 a peticio de MAV
and total > 0
order by total desc;
@@ -27828,22 +27917,35 @@ 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 = utf8 */ ;
-/*!50003 SET character_set_results = utf8 */ ;
-/*!50003 SET collation_connection = utf8_general_ci */ ;
+/*!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' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `inventory_refresh`()
BEGIN
- INSERT INTO daily_task_log
- SET consulta = 'inventory_refresh-begin';
-
- CALL article_inventory_warehouses (TIMESTAMPADD(DAY, -10, CURDATE()));
+/**
+
+ * Recalcula los inventarios de todos los almacenes.
+
+ */
INSERT INTO daily_task_log
+
+ SET consulta = 'inventory_refresh-begin';
+
+
+
+ CALL article_inventory_warehouses (TIMESTAMPADD(DAY, -10, CURDATE()));
+
+
+
+ INSERT INTO daily_task_log
+
SET consulta = 'inventory_refresh-end';
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -27932,13 +28034,13 @@ BEGIN
AND Factura IS NULL ;
END IF;
-
+-- Elimina tickets sense moviments
UPDATE Tickets INNER JOIN (SELECT COUNT(Movimientos.Id_Movimiento) AS num, ticket_invoice.ticket_id AS ticket_id
FROM ticket_invoice LEFT JOIN Movimientos ON ticket_invoice.ticket_id = Movimientos.Id_Ticket
GROUP BY ticket_invoice.ticket_id HAVING num = 0) counter
ON Tickets.Id_Ticket = counter.ticket_id SET Tickets.Fecha = '1999-01-01 00:00:00';
-
+ -- Eliminem els tickets que no han de ser facturats
DELETE ticket_invoice.* FROM ticket_invoice INNER JOIN Tickets ON ticket_invoice.ticket_id = Tickets.Id_Ticket
INNER JOIN Clientes ON Tickets.Id_Cliente = Clientes.Id_cliente WHERE YEAR(Tickets.Fecha) < 2001 AND invoice;
@@ -28001,7 +28103,7 @@ BEGIN
SELECT Vencimiento INTO day_vec FROM Clientes WHERE Id_cliente = customer_id;
SET date_vec = TIMESTAMPADD(DAY, day_vec, date_vec);
-
+ -- el trigger añade el siguiente Id_Factura correspondiente a la serie
INSERT INTO Facturas
(
Id_Factura,
@@ -28055,7 +28157,7 @@ BEGIN
SELECT * FROM tmp.updateInter;
INSERT INTO Tickets_dits (idaccion_dits,Id_Trabajador,Id_Ticket,value_old,value_new)
- SELECT 111 ,Id_Trabajador,ti.ticket_id,NULL,serie FROM ticket_invoice ti;
+ SELECT 111/*Factura serie*/,Id_Trabajador,ti.ticket_id,NULL,serie FROM ticket_invoice ti;
END IF;
DROP TEMPORARY TABLE `iva_base`;
@@ -28079,7 +28181,9 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `itemTagArrangedUpdate`(IN vItem BIGINT)
BEGIN
-
+/**
+ * DEPRECATED
+ **/
CALL vn.itemTagArrangedUpdate(vItem);
END ;;
@@ -28121,7 +28225,9 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `itemTagUpdatePriority`(IN vItem INT)
BEGIN
-
+/*
+* DEPRECATED
+*/
CALL vn.itemTagUpdatePriority(vItem);
@@ -28143,7 +28249,7 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `item_buffer_tarifa_traveltreekk`(v_date DATE, v_consigna INT, v_agencia INT, i_order INT, v_wh SMALLINT)
BEGIN
-
+ -- v_date fecha de recepcion de mercancia
DECLARE done TINYINT DEFAULT 0;
DECLARE v_shipment DATE;
@@ -28155,11 +28261,11 @@ BEGIN
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
-
+ -- establecemos los almacenes y las fechas que van a entrar al dispo_multi
SELECT agency_id INTO v_agency_id FROM Agencias WHERE Id_Agencia = v_agencia;
-
+ -- Si pasamos un almacen significa que estamos recalculando el dispo y el precio para un ticket existente
IF v_wh = 0
THEN
@@ -28178,7 +28284,7 @@ BEGIN
SELECT v_wh, v_date, v_date;
END IF;
-
+ -- Ejecutamos item_buffer_tarifa para cada registro del cursos, y almacenaremos los valores acumulados, para el buffer y para los componentes
OPEN cur1;
FETCH cur1 INTO v_wh, v_shipment;
@@ -28215,7 +28321,7 @@ BEGIN
DO
CALL item_buffer_tarifa(v_wh, v_shipment, v_consigna, FALSE, v_agencia);
-
+ -- eliminaremos PCA de Silla FV y viceversa
INSERT INTO buffer_multi(warehouse_id, Id_Article, visible, available, future, buy_inc, buy_last, buy_id, `fixed`, rate_0, rate_1, rate_2, rate_3, Packing, Grouping, Productor, caja, Origen, mark, `comment`, foto, Id_Tipo, Article)
SELECT v_wh, id, visible, available, future, buy_inc, buy_last, buy_id, `fixed`, rate_0, rate_1, rate_2, rate_3, Packing, Grouping, Productor, bb.caja, Origen, mark, `comment`, A.Foto, A.tipo_id, A.Article
@@ -28279,7 +28385,7 @@ DELIMITER ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `item_buffer_tarifa_traveltree_dupkk`(
- v_date DATE,
+ v_date DATE, -- fecha de recepcion de mercancia
v_consigna INT,
v_agencia INT,
i_order INT,
@@ -28295,11 +28401,11 @@ BEGIN
CALL cache.order_clean (i_order);
-
+ -- Establecemos los almacenes y las fechas que van a entrar al dispo_multi
SELECT agency_id INTO v_agency_id FROM Agencias WHERE Id_Agencia = v_agencia;
-
+ -- Si pasamos un almacen significa que estamos recalculando el dispo y el precio para un ticket existente
DROP TEMPORARY TABLE IF EXISTS travel_tree;
@@ -28313,7 +28419,7 @@ BEGIN
SELECT v_wh warehouse_id, v_date Fecha_envio;
END IF;
-
+ -- Ejecutamos item_buffer_tarifa para cada registro del cursos, y almacenaremos los valores acumulados, para el buffer y para los componentes
OPEN cur;
FETCH cur INTO v_wh, v_shipment;
@@ -28322,7 +28428,7 @@ BEGIN
DO
CALL item_buffer_tarifa_dup (v_wh, v_shipment, v_consigna, FALSE, v_agencia);
-
+ -- Eliminaremos PCA de Silla FV y viceversa
INSERT INTO cache.order_stock (
order_id, warehouse_id, Id_Article, visible, available, future, buy_inc, buy_last, buy_id, `fixed`, rate_0, rate_1, rate_2, rate_3, Packing, Grouping, Productor, caja, Origen, mark, `comment`, foto, Id_Tipo, Article
@@ -28439,7 +28545,7 @@ BEGIN
ADD discount INT;
-
+ -- Lo primero, el precio normal, la ultima entrada para ese almacen
UPDATE item i
JOIN Compres b ON i.buy_id = b.Id_Compra
@@ -28454,7 +28560,7 @@ BEGIN
END,
i.discount = IF(c.Descuento BETWEEN 4 AND 100, c.Descuento, 0);
-
+ -- Precios fijados
UPDATE item i
INNER JOIN Clientes c ON c.Id_cliente = v_customer
@@ -28470,7 +28576,7 @@ BEGIN
WHERE fp.warehouse_id IN (0,v_wh)
AND date_ BETWEEN fp.date_start AND fp.date_end;
-
+ -- Precios especiales
UPDATE item i
JOIN Clientes c ON c.Id_cliente = v_customer
@@ -28478,14 +28584,14 @@ BEGIN
SET i.price = p.PrecioEspecial,
i.discount = 0;
-
+ -- Precio mínimo
UPDATE item i
JOIN Articles a ON a.Id_Article = i.id
JOIN Clientes c ON c.Id_cliente = v_customer
SET i.price = IF(a.`Min` AND i.price < a.PVP, a.PVP,i.price);
-
+-- pak 14/9/14 provisional
END ;;
DELIMITER ;
@@ -28588,8 +28694,8 @@ BEGIN
LEFT JOIN PreciosEspeciales p
ON p.Id_Cliente = v_customer AND b.item_id = p.Id_Article
WHERE b.available > 0 AND b.cache_id = v_cache;
-
-
+ -- ON be.compra_id = co.compra_id
+ -- Cliente Te gustan las flores
IF NOT v_customer = 3064
THEN
@@ -28604,219 +28710,6 @@ DELIMITER ;
/*!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 `item_disp_virt` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `item_disp_virt`(v_wh SMALLINT, v_date DATETIME, id_single INT, v_cache INT)
-BEGIN
- DROP TEMPORARY TABLE IF EXISTS wh_father;
- DROP TEMPORARY TABLE IF EXISTS wh_son;
- DROP TEMPORARY TABLE IF EXISTS article_inventory;
-
- CREATE TEMPORARY TABLE wh_father
- (
- wh SMALLINT,
- INDEX i (wh)
- )
- ENGINE = MEMORY;
-
- CREATE TEMPORARY TABLE wh_son
- (
- wh INT,
- INDEX i (wh)
- )
- ENGINE = MEMORY;
-
- INSERT INTO wh_father(wh) VALUES(v_wh);
- INSERT INTO wh_son(wh) VALUES(v_wh);
-
-
- IF @wh_son THEN
- INSERT INTO wh_son(wh) VALUES(@wh_son);
- END IF;
-
- CALL item_travel_fixed(v_wh,v_date);
- SET @@max_sp_recursion_depth = 10;
-
- CALL item_disp_virt1 (v_wh, v_date, 0, id_single, v_cache);
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `item_disp_virt1` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `item_disp_virt1`(v_wh SMALLINT, v_date DATETIME, direccion TINYINT, id_single INT, v_cache INT)
-BEGIN
- DECLARE wh_cursor,done TINYINT DEFAULT 0;
- DECLARE v_shipment_aux DATETIME DEFAULT NULL;
- DECLARE v_date_cur DATETIME DEFAULT CURDATE();
- DECLARE v_inv DATETIME;
- DECLARE v_camp DATETIME;
- DECLARE b_fprice TINYINT;
-
-
- DECLARE cur1 CURSOR FOR
- SELECT son FROM warehouse_tree_bidi
- WHERE father = v_wh AND son NOT IN (SELECT DISTINCT wh FROM wh_son);
-
-
- DECLARE cur2 CURSOR FOR
- SELECT father FROM warehouse_tree_bidi
- WHERE son = v_wh AND father NOT IN (SELECT DISTINCT wh FROM wh_father);
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
-
-
-SELECT FechaInventario, TIMESTAMPADD(DAY, -campaign_life, campaign)
- INTO v_inv, v_camp FROM tblContadores LIMIT 1;
-
- CALL hedera.sql_query (sql_printf('DROP TEMPORARY TABLE IF EXISTS %t;',v_wh));
- CALL hedera.sql_query (sql_printf('create temporary table %t
- (
- article_id INT PRIMARY KEY,
- amount DOUBLE(8,2)
- )ENGINE = MEMORY;'
- ,v_wh));
-
- IF v_camp >= v_date_cur AND v_camp <= v_date THEN
- SET v_date_cur = v_camp;
- ELSE
- OPEN cur1;
- FETCH cur1 INTO wh_cursor;
-
-
- WHILE !done DO
-
- SELECT MIN(landing) INTO v_shipment_aux
- FROM travel t
- WHERE t.warehouse_id_out = v_wh
- AND t.warehouse_id = wh_cursor
- AND t.shipment >= v_date
- AND NOT t.delivered
- AND t.landing >= t.shipment;
-
-
- INSERT INTO wh_son(wh) VALUES (v_wh);
-
- CALL item_disp_virt1 (wh_cursor, v_shipment_aux, -1, id_single, v_cache);
-
-
- CALL hedera.sql_query (sql_printf (
- 'INSERT INTO %t (article_id,amount)
- SELECT item_id ,available FROM vn2008.tmp_item WHERE available < 0
- ON DUPLICATE KEY UPDATE
- amount = amount + VALUES(amount);'
- ,v_wh
- ));
-
- FETCH cur1 INTO wh_cursor;
- END WHILE;
- CLOSE cur1;
-
- SET v_shipment_aux = NULL;
-
-
-
-
- IF direccion >= 0 THEN
-
- SET done = 0;
- OPEN cur2;
- FETCH cur2 INTO wh_cursor;
-
- WHILE !done DO
-
- SELECT MAX(shipment) INTO v_shipment_aux FROM travel t
- WHERE t.warehouse_id_out = wh_cursor
- AND t.warehouse_id = v_wh
- AND t.delivered = 0
- AND t.shipment >= CURDATE()
- AND t.landing <= v_date;
-
- INSERT INTO wh_son(wh) VALUES (v_wh);
- INSERT INTO wh_father(wh) VALUES (v_wh);
- IF v_shipment_aux IS NOT NULL THEN
-
- CALL item_disp_virt1(wh_cursor,v_shipment_aux,1, id_single, v_cache);
-
- CALL hedera.sql_query (sql_printf('INSERT INTO %t (article_id,amount)
- SELECT item_id ,available FROM vn2008.tmp_item WHERE available > 0
- ON DUPLICATE KEY UPDATE
- amount = amount + VALUES(amount);',v_wh));
- ELSE
-
-
- SELECT MIN(shipment) INTO v_shipment_aux FROM travel t
- WHERE t.warehouse_id_out = wh_cursor
- AND t.warehouse_id = v_wh
- AND t.delivered = 0
- AND t.shipment >= CURDATE()
- AND t.landing >= v_date;
- CALL item_disp_virt1(wh_cursor,v_shipment_aux,2, id_single, v_cache);
- END IF;
- FETCH cur2 INTO wh_cursor;
-
- END WHILE;
-
- END IF;
- END IF;
-
-
- CALL item_stock (v_wh, v_date,NULL);
-
- CALL item_stock_avail (v_wh, v_date,NULL,direccion);
-
-
- CALL hedera.sql_query (sql_printf('INSERT INTO vn2008.tmp_item ( item_id, available)
- SELECT article_id, amount FROM %t
- ON DUPLICATE KEY UPDATE
- available = available + VALUES(available);',v_wh));
-
- IF !direccion THEN
- IF v_date = curdate() THEN
- CALL item_stock_visible (v_wh,NULL);
- END IF;
- DELETE FROM cache_a WHERE cache_id = v_cache;
-
- CALL hedera.sql_query (sql_printf (
- 'INSERT INTO vn2008.cache_a (cache_id, item_id, visible, available, virtual, future)
- SELECT %v, item_id, visible, available, IFNULL(amount,0) virtual, future
- FROM vn2008.tmp_item
- LEFT JOIN %t ON item_id = article_id
- ON DUPLICATE KEY UPDATE
- visible = VALUES(visible),
- available = VALUES(available),
- virtual = VALUES(virtual),
- future = VALUES(future);'
- ,v_cache
- ,v_wh
-
- ));
- END IF;
-
- CALL hedera.sql_query (sql_printf ('DROP TEMPORARY TABLE IF EXISTS %t;', 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 `item_express` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
@@ -28883,7 +28776,7 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `item_last_buy_`(v_wh SMALLINT, v_date DATE)
BEGIN
-
+ -- Ultima compra hasta hoy
CALL cache.last_buy_refresh (FALSE);
@@ -28897,10 +28790,10 @@ BEGIN
WHERE v_wh = warehouse_id OR v_wh IS NULL;
-
+ -- Ultima compra hasta @v_date
-
+ -- CALL item_last_buy_from_interval (v_wh, CURDATE(), TIMESTAMPADD(DAY, 1, v_date)); JGF 2016-06-08 fallo: cogia un dia mas de lo solicitado
CALL item_last_buy_from_interval (v_wh, CURDATE(), v_date);
REPLACE INTO t_item_last_buy
@@ -28928,16 +28821,25 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `item_last_buy_from_interval`(v_wh SMALLINT, v_date_ini DATE, v_date_end DATE)
BEGIN
-
-
-
-
+/**
+ * Obtiene la ultima compra a partir de un intervalo
+ * de fechas dado.
+ *
+ * @param v_wh Id de almacen %NULL para todos los almacenes
+ * @param v_date_ini Fecha inicial
+ * @param v_date_end Fecha final
+ * @table tmp.item_last_buy_from_interval
+ **/
IF v_date_end IS NULL
THEN
SET v_date_end = v_date_ini;
END IF;
+ IF v_date_end < v_date_ini THEN
+ SET v_date_ini = TIMESTAMPADD(MONTH,-1,v_date_end);
+ END IF;
+
DROP TEMPORARY TABLE IF EXISTS tmp.item_last_buy_from_interval;
CREATE TEMPORARY TABLE tmp.item_last_buy_from_interval
ENGINE = MEMORY
@@ -28968,12 +28870,19 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `item_new`()
BEGIN
+
CREATE TEMPORARY TABLE item
+
(
+
item_id INT UNSIGNED NOT NULL,
+
UNIQUE KEY USING HASH (item_id)
+
)
+
ENGINE = MEMORY;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -28992,7 +28901,9 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `item_stock`(v_wh SMALLINT, v_date DATETIME, v_item INT)
BEGIN
-
+/**
+ * Calcula el stock del v_wh desde FechaInventario hasta v_date
+ **/
DECLARE n TINYINT;
DECLARE v_diff TIME;
@@ -29050,7 +28961,7 @@ DELIMITER ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = '' */ ;
+/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `item_stock_avail`(IN v_wh TINYINT, IN v_date DATETIME, IN id_single INT,IN direccion TINYINT)
BEGIN
@@ -29059,21 +28970,21 @@ BEGIN
DECLARE query TEXT;
DECLARE _son,_self TEXT;
DECLARE _auxshipment, _auxlanding,fut DATE;
-
+ -- Selecciona tots els travels cap als fill ens els próxims 15 dies
DECLARE cur1 CURSOR FOR
SELECT shipment,landing FROM travel WHERE warehouse_id_out = v_wh AND shipment BETWEEN TIMESTAMPADD(day,1,v_date)
AND TIMESTAMPADD(day,15,v_date) AND warehouse_id = (SELECT son FROM warehouse_tree_bidi WHERE father = v_wh
LIMIT 1)
ORDER BY shipment;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
-
+ -- selecciona els primers travels que arrivaran després de la v_date de cada warehouse
CALL item_travel (v_wh, v_date);
SET expr = sql_printf ('dat BETWEEN DATE(%v) AND DATE(%v)'
,TIMESTAMP(v_date, '00:00:00')
,TIMESTAMP(TIMESTAMPADD(DAY, 15, v_date), '23:59:59')
-
+ /*,v_wh*/
);
@@ -29091,8 +29002,8 @@ BEGIN
SET expr2 = '';
SET _self = CONCAT(v_wh, 'virtual');
-
- CALL hedera.sql_query (sql_printf('CREATE TEMPORARY TABLE IF NOT EXISTS vn2008.%t
+ -- crea una taula amb el nom del warehousevirtual
+ CALL sql_query (sql_printf('CREATE TEMPORARY TABLE IF NOT EXISTS vn2008.%t
(
item_id INT(11),
dat DATE,
@@ -29100,7 +29011,7 @@ BEGIN
PRIMARY KEY(item_id,dat)
)
ENGINE = MEMORY;',_self));
-
+ -- si esta mirant els pares li añadeix el virtual que pot arrivar a conseguir
IF direccion >= 0 THEN
SET expr2 = sql_printf (' UNION ALL
SELECT item_id, dat, amount
@@ -29112,8 +29023,8 @@ BEGIN
ALTER TABLE tmp_item ADD future DATE;
-
-
+ /*jgf afegeix AND Reservado != 0 */
+ -- calcula el mínim disponible fins a la próxima arrivada de mercancia
SET query = sql_printf (
'INSERT INTO tmp_item (item_id,available, future)
SELECT item_id, SUM(amount) AS available,landing as future FROM (
@@ -29142,15 +29053,15 @@ SET query = sql_printf (
available = IFNULL(available,0) + VALUES(available)'
, DATE(v_date) + 0, expr1, expr1, expr1, expr2
);
-
-
+ -- JGF 22/10/14 - WHERE IFNULL(dt <= w.landing OR Id_Article > 170000, TRUE)
+ -- JGF 2015-03-31 ANTES WHERE IFNULL(dt <= w.landing OR Id_Article > 170000, TRUE)
CALL sql_query (query);
-
+ -- si el v_wh es pare
IF (direccion > 0) THEN
-
+ -- crea una taula TEMPORAL per al fill
SELECT CONCAT(son,'virtual') A INTO _son FROM warehouse_tree_bidi WHERE father = v_wh LIMIT 1;
- CALL hedera.sql_query (sql_printf('CREATE TEMPORARY TABLE IF NOT EXISTS vn2008.%t
+ CALL sql_query (sql_printf('CREATE TEMPORARY TABLE IF NOT EXISTS vn2008.%t
(
item_id INT(11),
dat DATE,
@@ -29160,7 +29071,7 @@ SET query = sql_printf (
ENGINE = MEMORY;',_son));
IF (direccion >= 2) THEN
CALL sql_query (query);
- SET query = sql_printf (
+ SET query = sql_printf ( -- REPLACE en lugar de INSERT INTO PAK 20/11/14
'REPLACE vn2008.%t (item_id,dat,amount)
SELECT item_id,landing,available FROM tmp_item,travel
WHERE shipment = DATE(%v) AND warehouse_id_out = %v AND available > 0
@@ -29190,7 +29101,7 @@ SET query = sql_printf (
,expr4
,v_wh
);
-
+ -- afegir entrades menys eixides desde l'ultim dia..
SET query = sql_printf (
'INSERT INTO vn2008.%t (item_id,dat,amount)
SELECT item_id, %v, SUM(amount) AS available FROM (
@@ -29219,7 +29130,7 @@ SET query = sql_printf (
ON DUPLICATE KEY UPDATE
amount = IFNULL(amount,0) + VALUES(amount)
',_son,DATE(_auxlanding)+0,DATE(_auxshipment)+0,expr5, expr5, expr5,_self,expr4);
-
+ -- JGF 07/07/14 - WHERE IFNULL(dt < w.landing , TRUE)
CALL sql_query (query);
FETCH cur1 INTO _auxshipment,_auxlanding;
END WHILE;
@@ -29241,7 +29152,7 @@ DELIMITER ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = '' */ ;
+/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `item_stock_avail_new`(IN v_wh TINYINT, IN v_date DATETIME, IN id_single INT,IN direccion TINYINT)
BEGIN
@@ -29251,7 +29162,7 @@ BEGIN
DECLARE _son,_self TEXT;
DECLARE _auxshipment, _auxlanding,fut DATE;
-
+ -- Selecciona tots els viajes cap als fill ens els próxims 15 dies
DECLARE cur1 CURSOR FOR
SELECT shipment,landing FROM travel
@@ -29263,7 +29174,7 @@ BEGIN
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
-
+ -- Selecciona els primers viajes que arrivaran després de la v_date de cada almacen
CALL item_travel (v_wh, v_date);
@@ -29287,9 +29198,9 @@ BEGIN
SET expr2 = '';
SET _self = CONCAT(v_wh, 'virtual');
-
+ -- Crea una taula amb el nom del almacen virtual
- CALL hedera.sql_query (sql_printf('CREATE TEMPORARY TABLE IF NOT EXISTS vn2008.%t
+ CALL sql_query (sql_printf('CREATE TEMPORARY TABLE IF NOT EXISTS vn2008.%t
(
item_id INT(11),
dat DATE,
@@ -29298,7 +29209,7 @@ BEGIN
)
ENGINE = MEMORY',_self));
-
+ -- Si esta mirant els pares li añadeix el virtual que pot arrivar a conseguir
IF direccion >= 0
THEN
@@ -29312,7 +29223,7 @@ BEGIN
ALTER TABLE tmp_item ADD future DATE;
-
+ -- Calcula el mínim disponible fins a la próxima arrivada de mercancia
SET query = sql_printf (
'INSERT INTO tmp_item (item_id, available, future)
@@ -29348,14 +29259,14 @@ BEGIN
);
CALL sql_query (query);
-
+ -- Si es el almacen padre
IF (direccion > 0)
THEN
-
+ -- Crea una tabla temporar pare el hijo
SELECT CONCAT(son,'virtual') A INTO _son FROM warehouse_tree_bidi WHERE father = v_wh LIMIT 1;
- CALL hedera.sql_query (sql_printf(
+ CALL sql_query (sql_printf(
'CREATE TEMPORARY TABLE IF NOT EXISTS vn2008.%t
(
item_id INT(11),
@@ -29407,7 +29318,7 @@ BEGIN
,v_wh
);
-
+ -- Afegir entrades menys eixides desde l'ultim dia
CALL sql_query (sql_printf (
'INSERT INTO vn2008.%t (item_id,dat,amount)
@@ -29482,7 +29393,9 @@ BEGIN
AND (alertLevel > 1
OR
ok != FALSE
-
+ /* AND (((ok != FALSE OR ready != FALSE OR invoice IS NOT NULL)
+ AND dat < v_tomorrow)
+ */
OR Reservado != FALSE )
UNION ALL
SELECT item_id, amount FROM item_entry_in
@@ -29527,58 +29440,67 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS travel_top;
DROP TEMPORARY TABLE IF EXISTS item_travel;
-
+ -- Crea una taula buida travel_top
CREATE TEMPORARY TABLE travel_top
- (PRIMARY KEY (wh_in,wh_out,landing,shipment))
+ (PRIMARY KEY (wh_in,wh_out,landing,shipment)) -- 28/1/15 JGF & PAK cuelgue dia 26
ENGINE = MEMORY
SELECT 0 id, v_wh wh_in, v_wh wh_out, FALSE ok, v_date landing, v_date shipment;
REPEAT
SET v_travel = NULL;
-
+ -- Va seleccionant registres un a un
SELECT id, wh_out, shipment, landing
INTO v_travel, v_wh_out, v_shipment, v_date_start
FROM travel_top WHERE ok = FALSE LIMIT 1;
-
+ -- Marca el registre per a saber que esta revistat
UPDATE travel_top SET ok = TRUE WHERE id = v_travel;
-
+ -- Concatena travels
INSERT IGNORE INTO travel_top
SELECT id, v_wh, warehouse_id_out, FALSE, IF(v_travel, v_date_start, landing), shipment
FROM travel
WHERE warehouse_id = v_wh_out
-
-
+ -- Canvia Javi 08/04/13 error que pasaba a les 06:00 del mati
+ -- AND IF(v_travel, landing <= v_shipment, landing > v_shipment)
AND IF(v_travel, landing <= v_shipment, landing >= v_shipment)
AND shipment >= CURDATE()
AND delivered = FALSE;
UNTIL v_travel IS NULL
- END REPEAT;
+ END REPEAT;/*
+ select max_count;
+ SELECT * FROM travel_top;*/
DELETE FROM travel_top WHERE id = 0;
+/*
+ SELECT TIMESTAMPADD(DAY, -campaign_life, campaign), campaign
+ INTO v_date_start, v_campaign FROM tblContadores;*/
-
-
+ -- Agafa el travel que arriva primer per a cada warehouse
CREATE TEMPORARY TABLE item_travel
(KEY (wh))
ENGINE = MEMORY
SELECT * FROM (
- SELECT wh_out wh, landing
+ SELECT wh_out wh,/* IF(
+ v_date BETWEEN v_date_start AND v_campaign
+ AND landing BETWEEN v_date_start AND v_campaign
+ ,TIMESTAMPADD(DAY, 1, v_campaign)
+ ,landing
+ ) */landing
FROM travel_top
WHERE wh_out <> v_wh
ORDER BY landing
) t
GROUP BY wh;
-
+-- SELECT * FROM item_travel;
DROP TEMPORARY TABLE travel_top;
END ;;
DELIMITER ;
@@ -29622,7 +29544,7 @@ BEGIN
LIMIT 1;
INSERT INTO travel_top
- SELECT t.id, warehouse_id_out, shipment
+ SELECT t.id, warehouse_id_out, shipment/*, FALSE*/
FROM travel t
WHERE warehouse_id = v_wh_out
AND landing <= v_shipment
@@ -29679,7 +29601,7 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS travel_top;
DROP TEMPORARY TABLE IF EXISTS item_travel;
-
+ -- Crea una taula buida travel_top
CREATE TEMPORARY TABLE travel_top
(PRIMARY KEY (id))
@@ -29689,17 +29611,17 @@ BEGIN
REPEAT
SET v_travel = NULL;
-
+ -- Va seleccionant registres un a un
SELECT id, wh_out, shipment, landing
INTO v_travel, v_wh_out, v_shipment, v_date_start
FROM travel_top WHERE ok = FALSE LIMIT 1;
-
+ -- Marca el registre per a saber que esta revistat
UPDATE travel_top SET ok = TRUE WHERE id = v_travel;
-
+ -- Concatena travels cap al pasat
INSERT IGNORE INTO travel_top
SELECT id, v_wh, warehouse_id_out, FALSE, IF(v_travel, v_date_start, landing), shipment
@@ -29717,7 +29639,7 @@ BEGIN
SELECT TIMESTAMPADD(DAY, -campaign_life, campaign), campaign
INTO v_date_start, v_campaign FROM tblContadores;
-
+ -- Agafa el travel que arriva primer per a cada warehouse
CREATE TEMPORARY TABLE item_travel
(KEY (wh))
@@ -29766,14 +29688,14 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS travel_top;
DROP TEMPORARY TABLE IF EXISTS item_travel;
-
+ -- Crea una taula buida travel_top
drop temporary table if exists travels_list;
create temporary table travels_list
(id integer, shipment date, landing date, warehouse_id int, warehouse_id_out int);
CREATE TEMPORARY TABLE travel_top
-
+ -- (PRIMARY KEY (wh_in,wh_out,landing,shipment) )
ENGINE = MEMORY
SELECT 0 RODA, 0 ORDRE, 0 son_id, 0 id, v_wh wh_in, v_wh wh_out, FALSE ok, v_date landing, v_date shipment;
@@ -29783,18 +29705,18 @@ BEGIN
SET v_travel = -1;
-
+ -- Va seleccionant registres un a un
SELECT id, wh_out, shipment, landing
INTO v_travel, v_wh_out, v_shipment, v_date_start
FROM travel_top WHERE ok = FALSE
LIMIT 1;
-
+ -- Marca el registre per a saber que esta revistat
UPDATE travel_top SET ok = TRUE WHERE id = v_travel;
-
+ -- Concatena travels
SET @ordre := 0;
INSERT INTO travel_top
@@ -29823,18 +29745,27 @@ UNTIL v_travel = -1 END REPEAT;
-
+ /*
+ select max_count;
+ SELECT * FROM travel_top;*/
-
+ /*DELETE FROM travel_top WHERE id = 0;*/
+/*
+ SELECT TIMESTAMPADD(DAY, -campaign_life, campaign), campaign
+ INTO v_date_start, v_campaign FROM tblContadores;*/
-
-
+ -- Agafa el travel que arriva primer per a cada warehouse
CREATE TEMPORARY TABLE item_travel
(KEY (wh))
ENGINE = MEMORY
SELECT * FROM (
- SELECT wh_out wh, landing
+ SELECT wh_out wh,/* IF(
+ v_date BETWEEN v_date_start AND v_campaign
+ AND landing BETWEEN v_date_start AND v_campaign
+ ,TIMESTAMPADD(DAY, 1, v_campaign)
+ ,landing
+ ) */landing
FROM travel_top
WHERE wh_out <> v_wh
ORDER BY landing
@@ -29934,6 +29865,109 @@ and Fecha > '2015-01-01'
where sub4.Id_Cliente 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 `manaEraser` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `manaEraser`(vTicket INT)
+BEGIN
+
+ DECLARE vComponentOld INT;
+ DECLARE vComponentNew INT;
+
+ SELECT Id_Componente
+ INTO vComponentOld
+ FROM tarifa_componentes
+ WHERE Componente = 'maná';
+
+ SELECT Id_Componente
+ INTO vComponentNew
+ FROM tarifa_componentes
+ WHERE Componente = 'rebaja manual';
+
+ UPDATE Movimientos_componentes mc
+ JOIN Movimientos m using(Id_Movimiento)
+ SET mc.Id_Componente = vComponentNew
+ WHERE mc.Id_Componente = vComponentOld
+ AND m.Id_Ticket = vTicket;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `manaRequery` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `manaRequery`(worker INTEGER)
+BEGIN
+
+DECLARE MyFechaDesde DATE;
+
+SELECT max(dated) INTO MyFechaDesde
+FROM bs.manaCustomer;
+
+
+REPLACE bs.mana_spellers (Id_Trabajador, used)
+
+ SELECT worker, sum(mana) FROM
+
+ (
+ SELECT Cantidad * Valor as mana
+ FROM vn2008.Tickets t
+ JOIN Consignatarios cs using(Id_Consigna)
+ JOIN Clientes c on c.Id_Cliente = cs.Id_Cliente
+ JOIN Movimientos m using(Id_Ticket)
+ JOIN Movimientos_componentes mc using(Id_Movimiento)
+ WHERE c.Id_Trabajador = worker AND Id_Componente IN (39, 37) -- maná auto y maná
+ AND Fecha > MyFechaDesde
+
+ UNION ALL
+
+ SELECT - Entregado
+ FROM Recibos r
+ JOIN Clientes c using(Id_Cliente)
+ WHERE c.Id_Trabajador = worker AND Id_Banco = 66
+ AND Fechacobro > MyFechaDesde
+
+ UNION ALL
+
+ SELECT g.Importe
+ FROM Greuges g
+ JOIN Clientes c using(Id_Cliente)
+ WHERE c.Id_Trabajador = worker AND Greuges_type_id = 3 -- Maná
+ AND Fecha > MyFechaDesde
+
+ UNION ALL
+
+ SELECT mana
+ FROM bs.manaCustomer mc
+ JOIN vn2008.Clientes c ON c.Id_Cliente = mc.Id_Cliente
+ WHERE c.Id_Trabajador = worker AND dated = MyFechaDesde
+ ) sub;
+
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -29955,7 +29989,7 @@ BEGIN
DECLARE idT INT;
-IF ASCII(str) between 48 and 57 THEN
+IF ASCII(str) between 48 and 57 THEN -- el chr(48) es el 0 y el chr(57) es el 9. De ese modo se comprueba si es un numero o un carácter de texto
SET idT = cast(str as signed);
@@ -29997,7 +30031,7 @@ SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
SELECT c.Id_Cliente, Cliente, r.FechaCobro, r.odbc_date, NULL, 'cobro', NULL, NULL, - Entregado
FROM Recibos r
JOIN Clientes c using(Id_Cliente)
- WHERE Id_Banco = 66
+ WHERE Id_Banco = 66 -- Caja de maná
AND c.Id_Trabajador = idT
UNION ALL
@@ -30009,7 +30043,7 @@ SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
SELECT c.Id_Cliente, Cliente, g.Fecha, g.odbc_date, NULL, Comentario, NULL, NULL, g.Importe
FROM Greuges g
JOIN Clientes c using(Id_Cliente)
- WHERE Greuges_type_id = 3
+ WHERE Greuges_type_id = 3 -- Maná
AND c.Id_Trabajador = idT
) t1
ORDER BY FechaAccion DESC;
@@ -30056,7 +30090,7 @@ LEFT JOIN
JOIN Clientes c on c.Id_Cliente = cs.Id_Cliente
JOIN Movimientos m using(Id_Ticket)
JOIN Movimientos_componentes mc using(Id_Movimiento)
- WHERE Id_Componente IN (39, 37)
+ WHERE Id_Componente IN (39, 37) -- maná auto y maná
AND Fecha > MyFechaDesde
UNION ALL
@@ -30072,7 +30106,7 @@ LEFT JOIN
SELECT c.Id_Trabajador, g.Importe
FROM Greuges g
JOIN Clientes c using(Id_Cliente)
- WHERE Greuges_type_id = 3
+ WHERE Greuges_type_id = 3 -- Maná
AND Fecha > MyFechaDesde
UNION ALL
@@ -30110,7 +30144,15 @@ DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `massiveTicket`(
IN dateFrom DATE, IN dateTo DATE, IN customerId INT, OUT newTicketId INT)
BEGIN
-
+/**
+ * Genera un nuevo ticket con los movimientos correspondientes a los parámetros
+ *
+ * @param dateFrom Fecha mínima para los tickets
+ * @param dateTo Fecha máxima para los tickets
+ * @param customerId Cliente
+ *
+ * @return newTicketId Nuevo numero de ticket
+ **/
DECLARE inventoryWarehouse INT DEFAULT 13;
DECLARE defaultCompany INT DEFAULT 442;
@@ -30165,9 +30207,9 @@ DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `mensaje`(IN idREM INT, IN idDES INT, IN strMSG LONGTEXT)
BEGIN
+/*DECLARE lngLASTID BIGINT;*/
-
-
+-- Caso sencillo
INSERT INTO Mensajes(Mensaje, Fecha, Remitente, Destinatario)
VALUES(strMSG, NOW(), idREM, idDES);
@@ -30214,7 +30256,25 @@ SELECT DISTINCT Fecha FROM Tickets WHERE Fecha >= datFEC
WHERE Id_Grupo = 6
GROUP BY Id_Trabajador, Fecha, Hora;
-
+/*
+SELECT Id_Trabajador, SUM(dur_in) dur_in, SUM(dur_out) dur_out, llamadas.Fecha,YEAR(llamadas.Fecha) `year`,
+MONTH(llamadas.Fecha) `month`,WEEK(llamadas.Fecha,7) `week`, Hora, SUM(Recibidas) as Entrantes, SUM(Emitidas) as Salientes
+FROM
+(
+SELECT Id_Trabajador, billsec dur_in, NULL dur_out, 1 as Recibidas, NULL as Emitidas, date(calldate) as Fecha, hour(calldate) as Hora
+FROM Trabajadores T
+INNER JOIN cdr C ON C.dstchannel LIKE CONCAT('%', T.extension, '%')
+WHERE calldate >= CURDATE()
+UNION ALL
+SELECT Id_Trabajador,NULL dur_in, billsec dur_out, NULL as Recibidas, 1 as Emitidas, date(calldate), hour(calldate)
+FROM Trabajadores T
+INNER JOIN cdr C ON C.src = T.extension
+WHERE calldate >= CURDATE()
+) llamadas
+INNER JOIN Permisos USING(Id_Trabajador)
+WHERE Id_Grupo = 6
+GROUP BY Id_Trabajador, Fecha, Hora;
+*/
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -30278,7 +30338,7 @@ BEGIN
JOIN Movimientos m using(Id_Ticket)
WHERE Id_Movimiento = idMOV;
-
+ -- Busca un ticket existente que coincida con los parametros del nuevo pedido
SET v_start = TIMESTAMP(newFEC);
SET v_end = TIMESTAMP(newFEC, '23:59:59');
@@ -30289,7 +30349,7 @@ BEGIN
AND intWarehouse = t.warehouse_id
AND intIdAgencia = t.Id_Agencia
AND IFNULL(datLanding,-1) = IFNULL(t.Landing,-1)
- AND t.Fecha BETWEEN v_start AND v_end
+ AND t.Fecha BETWEEN v_start AND v_end -- uso BETWEEN para aprovechar el indice
AND t.Factura IS NULL
AND t.Localizacion = 'RECHAZO'
AND t.PedidoImpreso = 0
@@ -30350,6 +30410,7 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `msg`(IN memTXT VARCHAR(255), IN idREM INTEGER, idDES INTEGER)
BEGIN
+
DECLARE last_ID INTEGER;
DECLARE codDES CHAR(3);
@@ -30382,65 +30443,52 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `nest_brother_add`(IN strTABLE VARCHAR(45)
- ,IN strBROTHER_NEW VARCHAR(45)
- ,IN idBROTHER_OLD INT
- )
+CREATE DEFINER=`root`@`%` PROCEDURE `nest_brother_add`(
+ vTable VARCHAR(45)
+ ,vNewBrother VARCHAR(45)
+ ,vOldBrotherId INT
+)
BEGIN
+ DECLARE vMyRight INT;
+ DECLARE vSchema VARCHAR(255) DEFAULT SCHEMA();
+ DROP TEMPORARY TABLE IF EXISTS aux;
+ CREATE TEMPORARY TABLE aux
+ SELECT 0 as rgt;
-DECLARE v_sql TEXT;
-DECLARE myRight INT;
+ CALL util.exec (sql_printf (
+ 'UPDATE vn2008.aux SET rgt = (SELECT rgt FROM %t.%t WHERE id = %v)'
+ ,vSchema
+ ,vTable
+ ,vOldBrotherId
+ ));
-DROP TEMPORARY TABLE IF EXISTS aux;
-CREATE TEMPORARY TABLE aux
-SELECT 0 as rgt;
+ SELECT rgt INTO vMyRight FROM aux;
+ DROP TEMPORARY TABLE aux;
-
-
- SET v_sql = sql_printf (
- '
- UPDATE aux SET rgt = (SELECT rgt FROM %t WHERE id = %v);
- ',
- strTABLE,
- idBROTHER_OLD);
-
-CALL sql_query (v_sql);
-
-SELECT rgt INTO myRight FROM aux;
-
-DROP TEMPORARY TABLE IF EXISTS aux;
-
-
-
-
-SET v_sql = sql_printf (
- '
- UPDATE %t SET rgt = rgt + 2 WHERE rgt > %v ORDER BY rgt DESC;
- ',
- strTABLE, myRight);
-
-CALL sql_query (v_sql);
-
-SET v_sql = sql_printf (
- '
- UPDATE %t SET lft = lft + 2 WHERE lft > %v ORDER BY lft DESC;
- ',strTABLE, myRight);
-CALL sql_query (v_sql);
-
-SET v_sql = sql_printf (
- '
- INSERT INTO %t(name, lft, rgt) VALUES(%v, %v + 1, %v + 2);
- ',strTABLE
- ,strBROTHER_NEW
- ,myRight
- ,myRight);
-
-CALL sql_query (v_sql);
-
+ CALL util.exec (sql_printf (
+ 'UPDATE %t.%t SET rgt = rgt + 2 WHERE rgt > %v ORDER BY rgt DESC'
+ ,vSchema
+ ,vTable
+ ,vMyRight
+ ));
+ CALL util.exec (sql_printf (
+ 'UPDATE %t.%t SET lft = lft + 2 WHERE lft > %v ORDER BY lft DESC'
+ ,vSchema
+ ,vTable
+ ,vMyRight
+ ));
+ CALL util.exec (sql_printf (
+ 'INSERT INTO %t.%t (name, lft, rgt) VALUES(%v, %v + 1, %v + 2)'
+ ,vSchema
+ ,vTable
+ ,vNewBrother
+ ,vMyRight
+ ,vMyRight
+ ));
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -30457,64 +30505,52 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `nest_child_add`(IN strTABLE VARCHAR(45)
- ,IN strCHILD VARCHAR(45)
- ,IN idFATHER INT
- )
+CREATE DEFINER=`root`@`%` PROCEDURE `nest_child_add`(
+ vTable VARCHAR(45)
+ ,vChild VARCHAR(45)
+ ,vFatherId INT
+)
BEGIN
+ DECLARE vMyLeft INT;
+ DECLARE vSchema VARCHAR(255) DEFAULT SCHEMA();
+ DROP TEMPORARY TABLE IF EXISTS aux;
+ CREATE TEMPORARY TABLE aux
+ SELECT 0 as lft;
-DECLARE v_sql TEXT;
-DECLARE myLeft INT;
+ CALL util.exec (sql_printf (
+ 'UPDATE vn2008.aux SET lft = (SELECT lft FROM %t.%t WHERE id = %v)'
+ ,vSchema
+ ,vTable
+ ,vFatherId
+ ));
-DROP TEMPORARY TABLE IF EXISTS aux;
-CREATE TEMPORARY TABLE aux
-SELECT 0 as lft;
+ SELECT lft INTO vMyLeft FROM aux;
-
-
- SET v_sql = sql_printf (
- '
- UPDATE aux SET lft = (SELECT lft FROM %t WHERE id = %v);
- ',
- strTABLE,
- idFATHER);
-
-CALL sql_query (v_sql);
+ DROP TEMPORARY TABLE aux;
-SELECT lft INTO myLeft FROM aux;
-
-DROP TEMPORARY TABLE IF EXISTS aux;
-
-
-
-
-SET v_sql = sql_printf (
- '
- UPDATE %t SET rgt = rgt + 2 WHERE rgt > %v ORDER BY rgt DESC;
- ',
- strTABLE, myLeft);
-
-CALL sql_query (v_sql);
-
-SET v_sql = sql_printf (
- '
- UPDATE %t SET lft = lft + 2 WHERE lft > %v ORDER BY lft DESC;
- ',strTABLE, myLeft);
-CALL sql_query (v_sql);
-
-SET v_sql = sql_printf (
- '
- INSERT INTO %t(name, lft, rgt) VALUES(%v, %v + 1, %v + 2);
- ',strTABLE
- ,strCHILD
- ,myLeft
- ,myLeft);
-
-CALL sql_query (v_sql);
-
+ CALL util.exec (sql_printf (
+ 'UPDATE %t.%t SET rgt = rgt + 2 WHERE rgt > %v ORDER BY rgt DESC'
+ ,vSchema
+ ,vTable
+ ,vMyLeft
+ ));
+ CALL util.exec (sql_printf (
+ 'UPDATE %t.%t SET lft = lft + 2 WHERE lft > %v ORDER BY lft DESC'
+ ,vSchema
+ ,vTable
+ ,vMyLeft
+ ));
+ CALL util.exec (sql_printf (
+ 'INSERT INTO %t.%t(name, lft, rgt) VALUES(%v, %v + 1, %v + 2)'
+ ,vSchema
+ ,vTable
+ ,vChild
+ ,vMyLeft
+ ,vMyLeft
+ ));
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -30531,66 +30567,54 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `nest_delete`(IN strTABLE VARCHAR(45) ,IN idNODE INT)
+CREATE DEFINER=`root`@`%` PROCEDURE `nest_delete`(
+ vTable VARCHAR(45)
+ ,vNodeId INT
+)
BEGIN
+ DECLARE vMyRight INT;
+ DECLARE vMyLeft INT;
+ DECLARE vMyWidth INT;
+ DECLARE vSchema VARCHAR(255) DEFAULT SCHEMA();
+ DROP TEMPORARY TABLE IF EXISTS aux;
+ CREATE TEMPORARY TABLE aux
+ SELECT 0 AS rgt, 0 AS lft, 0 AS wdt;
-DECLARE v_sql TEXT;
-DECLARE myRight INT;
-DECLARE myLeft INT;
-DECLARE myWidth INT;
+ CALL util.exec (sql_printf (
+ 'UPDATE vn2008.aux a JOIN %t.%t t SET a.rgt = t.rgt, a.lft = t.lft, a.wdt = t.rgt - t.lft + 1 WHERE t.id = %v'
+ ,vSchema
+ ,vTable
+ ,vNodeId
+ ));
-DROP TEMPORARY TABLE IF EXISTS aux;
-CREATE TEMPORARY TABLE aux
-SELECT 0 as rgt, 0 as lft, 0 as wdt;
-
-
- SET v_sql = sql_printf (
- '
- UPDATE aux a JOIN %t t SET a.rgt = t.rgt, a.lft = t.lft, a.wdt = t.rgt - t.lft + 1
- WHERE t.id = %v;
- ',
- strTABLE,
- idNODE);
-
-CALL sql_query (v_sql);
-
-SELECT rgt, lft, wdt INTO myRight, myLeft, myWidth FROM aux;
-
-DROP TEMPORARY TABLE IF EXISTS aux;
-
-SET v_sql = sql_printf (
- '
- DELETE FROM %t WHERE lft BETWEEN %v AND %v
- ',strTABLE
- ,myLeft
- ,myRight);
-
-CALL sql_query (v_sql);
-
-
-
-SET v_sql = sql_printf (
- '
- UPDATE %t SET rgt = rgt - %v WHERE rgt > %v ORDER BY rgt;
- ',strTABLE
- ,myWidth
- ,myRight);
-
-CALL sql_query (v_sql);
-
-SET v_sql = sql_printf (
- '
- UPDATE %t SET lft = lft - %v WHERE lft > %v ORDER BY lft;
- ',strTABLE
- ,myWidth
- ,myRight);
-
-CALL sql_query (v_sql);
+ SELECT rgt, lft, wdt INTO vMyRight, vMyLeft, vMyWidth FROM aux;
+ DROP TEMPORARY TABLE aux;
+ CALL util.exec (sql_printf (
+ 'DELETE FROM %t.%t WHERE lft BETWEEN %v AND %v'
+ ,vSchema
+ ,vTable
+ ,vMyLeft
+ ,vMyRight
+ ));
+ CALL util.exec (sql_printf (
+ 'UPDATE %t.%t SET rgt = rgt - %v WHERE rgt > %v ORDER BY rgt'
+ ,vSchema
+ ,vTable
+ ,vMyWidth
+ ,vMyRight
+ ));
+ CALL util.exec (sql_printf (
+ 'UPDATE %t.%t SET lft = lft - %v WHERE lft > %v ORDER BY lft'
+ ,vSchema
+ ,vTable
+ ,vMyWidth
+ ,vMyRight
+ ));
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -30607,84 +30631,82 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `nest_leaves`(IN strTABLE VARCHAR(20), IN strTABLE_LINES VARCHAR(40), IN strNEST_ID VARCHAR(40), IN intGAP INTEGER, IN bolSHOW BOOLEAN)
+CREATE DEFINER=`root`@`%` PROCEDURE `nest_leaves`(
+ vTable VARCHAR(20)
+ ,vLinesTable VARCHAR(40)
+ ,vNestId VARCHAR(40)
+ ,vGap INT
+ ,vShouldShow BOOL
+)
BEGIN
+ DECLARE vSchema VARCHAR(255) DEFAULT SCHEMA();
-DECLARE v_sql TEXT;
+ DROP TEMPORARY TABLE IF EXISTS tmp.nest;
-
-DROP TEMPORARY TABLE IF EXISTS tmp.nest;
-
-
-CALL nest_tree(strTABLE, intGAP, FALSE);
-
-
-ALTER TABLE tmp.nest
-ADD leaves INT,
-ADD time DATETIME;
-
-
-SET v_sql = sql_printf (
- '
- update tmp.nest n
- join vn2008.%t s using(id)
- set n.time = s.odbc_date ;
- ', strTABLE
- );
-
-
-CALL sql_query (v_sql);
-
-
-
-SET v_sql = sql_printf (
- '
- update tmp.nest n
- join
- (
- select %t as id, count(*) as leaves
- from vn2008.%t
- group by %t
- ) s using(id)
- set n.leaves = s.leaves
- ;
- ', strNEST_ID
- , strTABLE_LINES
- , strNEST_ID
- );
-
-
-CALL sql_query (v_sql);
-
-
-drop temporary table if exists tmp.nest2;
-
-create temporary table tmp.nest2
-select * from tmp.nest;
-
-drop temporary table if exists tmp.nest3;
-
-create temporary table tmp.nest3
-select * from tmp.nest;
-
-update tmp.nest
-join
-(
-select n.id, sum(n2.leaves) leaves
-from tmp.nest3 n
-join tmp.nest2 n2 on n2.lft between n.lft and n.rgt
-group by n.id
-) sub on sub.id = nest.id
-set nest.leaves = ifnull(sub.leaves,0);
-
-
-drop temporary table tmp.nest2;
-
-IF bolSHOW THEN
- SELECT * FROM tmp.nest;
-END IF;
+ -- Se llama al procedimiento que genera el arbol
+ CALL nest_tree(vTable, vGap, FALSE);
+ -- Se añade un campo para el conteo de hojas
+
+ ALTER TABLE tmp.nest
+ ADD leaves INT,
+ ADD time DATETIME;
+
+ -- Añadimos la hora
+
+ CALL util.exec (sql_printf (
+ 'UPDATE tmp.nest n
+ JOIN %t.%t s using(id)
+ SET n.time = s.odbc_date'
+ ,vSchema
+ ,vTable
+ ));
+
+ -- Actualizamos el campo leaves para los nodos que tienen asociados
+
+ CALL util.exec (sql_printf (
+ 'update tmp.nest n
+ join
+ (
+ select %t as id, count(*) as leaves
+ from %t.%t
+ group by %t
+ ) s using(id)
+ set n.leaves = s.leaves'
+ ,vNestId
+ ,vSchema
+ ,vLinesTable
+ ,vNestId
+ ));
+
+ -- Actualizamos todos los nodos con la suma de las hojas de los hijos
+
+ drop temporary table if exists tmp.nest2;
+
+ create temporary table tmp.nest2
+ select * from tmp.nest;
+
+ drop temporary table if exists tmp.nest3;
+
+ create temporary table tmp.nest3
+ select * from tmp.nest;
+
+ update tmp.nest
+ join
+ (
+ select n.id, sum(n2.leaves) leaves
+ from tmp.nest3 n
+ join tmp.nest2 n2 on n2.lft between n.lft and n.rgt
+ group by n.id
+ ) sub on sub.id = nest.id
+ set nest.leaves = ifnull(sub.leaves,0);
+
+ drop temporary table tmp.nest2;
+
+ IF vShouldShow THEN
+ SELECT * FROM tmp.nest;
+ END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -30701,131 +30723,113 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `nest_move`(IN strTABLE VARCHAR(45) ,IN idNODE INT, IN idFATHER INT)
+CREATE DEFINER=`root`@`%` PROCEDURE `nest_move`(
+ strTABLE VARCHAR(45)
+ ,idNODE INT
+ ,idFATHER INT
+)
BEGIN
+ DECLARE myRight INT;
+ DECLARE myLeft INT;
+ DECLARE myWidth INT;
+ DECLARE fatherRight INT;
+ DECLARE fatherLeft INT;
+ DECLARE gap INT;
+ DECLARE vSchema VARCHAR(255) DEFAULT SCHEMA();
+ DROP TEMPORARY TABLE IF EXISTS aux;
+ CREATE TEMPORARY TABLE aux
+ SELECT 0 as rgt, 0 as lft, 0 as wdt, 0 as frg, 0 as flf;
-DECLARE v_sql TEXT;
-DECLARE myRight INT;
-DECLARE myLeft INT;
-DECLARE myWidth INT;
-DECLARE fatherRight INT;
-DECLARE fatherLeft INT;
-DECLARE gap INT;
+ -- Averiguamos el ancho de la rama
-DROP TEMPORARY TABLE IF EXISTS aux;
-CREATE TEMPORARY TABLE aux
-SELECT 0 as rgt, 0 as lft, 0 as wdt, 0 as frg, 0 as flf;
+ CALL util.exec (sql_printf (
+ 'UPDATE vn2008.aux a JOIN %t.%t t SET a.wdt = t.rgt - t.lft +1
+ WHERE t.id = %v'
+ ,vSchema
+ ,strTABLE
+ ,idNODE
+ ));
+ -- Averiguamos la posicion del nuevo padre
-
-
- SET v_sql = sql_printf (
- '
- UPDATE aux a JOIN %t t SET a.wdt = t.rgt - t.lft +1
- WHERE t.id = %v;
- ',
- strTABLE,
- idNODE);
-
-CALL sql_query (v_sql);
+ CALL util.exec (sql_printf (
+ 'UPDATE vn2008.aux a JOIN %t.%t t SET a.frg = t.rgt, a.flf = t.lft WHERE t.id = %v'
+ ,vSchema
+ ,strTABLE
+ ,idFATHER
+ ));
+ SELECT wdt, frg, flf INTO myWidth, fatherRight, fatherLeft FROM aux;
- SET v_sql = sql_printf (
- '
- UPDATE aux a JOIN %t t SET a.frg = t.rgt, a.flf = t.lft
- WHERE t.id = %v;
- ',
- strTABLE,
- idFATHER);
-
-CALL sql_query (v_sql);
+ -- 1º Incrementamos los valores de todos los nodos a la derecha del punto de inserción (fatherRight) , para hacer sitio
-SELECT wdt, frg, flf INTO myWidth, fatherRight, fatherLeft FROM aux;
+ CALL util.exec (sql_printf (
+ 'UPDATE %t.%t SET rgt = rgt + %v WHERE rgt >= %v ORDER BY rgt DESC'
+ ,vSchema
+ ,strTABLE
+ ,myWidth
+ ,fatherRight
+ ));
+ CALL util.exec (sql_printf (
+ 'UPDATE %t.%t SET lft = lft + %v WHERE lft >= %v ORDER BY lft DESC'
+ ,vSchema
+ ,strTABLE
+ ,myWidth
+ ,fatherRight
+ ));
+ -- Es preciso recalcular los valores del nodo en el caso de que estuviera a la derecha del nuevo padre
+ CALL util.exec (sql_printf (
+ 'UPDATE vn2008.aux a JOIN %t.%t t SET a.rgt = t.rgt, a.lft = t.lft WHERE t.id = %v'
+ ,vSchema
+ ,strTABLE
+ ,idNODE
+ ));
+ SELECT lft, rgt, frg - lft INTO myLeft, myRight, gap FROM aux;
-SET v_sql = sql_printf (
- '
- UPDATE %t SET rgt = rgt + %v WHERE rgt >= %v ORDER BY rgt DESC;
- ',strTABLE
- ,myWidth
- ,fatherRight);
-
-CALL sql_query (v_sql);
+ -- 2º Incrementamos el valor de todos los nodos a trasladar hasta alcanzar su nueva posicion
-SET v_sql = sql_printf (
- '
- UPDATE %t SET lft = lft + %v WHERE lft >= %v ORDER BY lft DESC;
- ',strTABLE
- ,myWidth
- ,fatherRight);
-
-CALL sql_query (v_sql);
+ CALL util.exec (sql_printf (
+ 'UPDATE %t.%t SET lft = lft + %v WHERE lft BETWEEN %v AND %v ORDER BY lft DESC'
+ ,vSchema
+ ,strTABLE
+ ,gap
+ ,myLeft
+ ,myRight
+ ));
+ CALL util.exec (sql_printf (
+ 'UPDATE %t.%t SET rgt = rgt + %v WHERE rgt BETWEEN %v AND %v ORDER BY rgt DESC'
+ ,vSchema
+ ,strTABLE
+ ,gap
+ ,myLeft
+ ,myRight
+ ));
+ -- 3º Restaremos a todos los nodos resultantes, a la derecha de la posicion arrancada el ancho de la rama escindida
-SET v_sql = sql_printf (
- '
- UPDATE aux a JOIN %t t SET a.rgt = t.rgt, a.lft = t.lft
- WHERE t.id = %v;
- ',
- strTABLE,
- idNODE);
-
-CALL sql_query (v_sql);
+ CALL util.exec (sql_printf (
+ 'UPDATE %t.%t SET lft = lft - %v WHERE lft > %v ORDER BY lft'
+ ,vSchema
+ ,strTABLE
+ ,myWidth
+ ,myLeft
+ ));
-SELECT lft, rgt, frg - lft INTO myLeft, myRight, gap FROM aux;
-
-
-
-
-
-SET v_sql = sql_printf (
- '
- UPDATE %t SET lft = lft + %v WHERE lft BETWEEN %v AND %v ORDER BY lft DESC;
- ',strTABLE
- ,gap
- ,myLeft
- ,myRight);
-
-CALL sql_query (v_sql);
-
-SET v_sql = sql_printf (
- '
- UPDATE %t SET rgt = rgt + %v WHERE rgt BETWEEN %v AND %v ORDER BY rgt DESC;
- ',strTABLE
- ,gap
- ,myLeft
- ,myRight);
-
-CALL sql_query (v_sql);
-
-
-SET v_sql = sql_printf (
- '
- UPDATE %t SET lft = lft - %v WHERE lft > %v ORDER BY lft;
- ',strTABLE
- ,myWidth
- ,myLeft);
-
-CALL sql_query (v_sql);
-
-
-SET v_sql = sql_printf (
- '
- UPDATE %t SET rgt = rgt - %v WHERE rgt > %v ORDER BY rgt;
- ',strTABLE
- ,myWidth
- ,myRight);
-
-CALL sql_query (v_sql);
-
-
-DROP TEMPORARY TABLE IF EXISTS aux;
+ CALL util.exec (sql_printf (
+ 'UPDATE %t.%t SET rgt = rgt - %v WHERE rgt > %v ORDER BY rgt'
+ ,vSchema
+ ,strTABLE
+ ,myWidth
+ ,myRight
+ ));
+ DROP TEMPORARY TABLE aux;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -30842,176 +30846,142 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `nest_query`(IN strTABLE VARCHAR(45))
+CREATE DEFINER=`root`@`%` PROCEDURE `nest_query`(strTABLE VARCHAR(45))
BEGIN
+ DECLARE v_max_depth INT;
+ DECLARE v_current_depth INT;
+ DECLARE vSchema VARCHAR(255) DEFAULT SCHEMA();
+ DROP TEMPORARY TABLE IF EXISTS tmp.nest_depth;
+ DROP TEMPORARY TABLE IF EXISTS tmp.nest_depth_aux;
-DECLARE v_sql TEXT;
-DECLARE v_max_depth INT;
-DECLARE v_current_depth INT;
+ -- Calculamos el nivel de profundidad para cada item
-DROP TEMPORARY TABLE IF EXISTS tmp.nest_depth;
-DROP TEMPORARY TABLE IF EXISTS tmp.nest_depth_aux;
-
-
-
-SET v_sql = sql_printf (
- '
- CREATE TEMPORARY TABLE tmp.nest_depth
-
- SELECT node.id node_id, COUNT(parent.id) - 1 as depth
- FROM %t AS node,
- %t AS parent
+ CALL util.exec (sql_printf (
+ 'CREATE TEMPORARY TABLE tmp.nest_depth
+ SELECT node.id node_id, COUNT(parent.id) - 1 as depth
+ FROM %t.%t AS node,
+ %t.%t AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
GROUP BY node.id
- ORDER BY node.lft
- ;
- ',
- strTABLE,
- strTABLE
- );
-
-
-CALL sql_query (v_sql);
-
-SELECT max(depth) FROM tmp.nest_depth INTO v_max_depth;
-SET v_current_depth = 2;
+ ORDER BY node.lft'
+ ,vSchema
+ ,strTABLE
+ ,vSchema
+ ,strTABLE
+ ));
-CREATE TEMPORARY TABLE tmp.nest_depth_aux
-SELECT * FROM tmp.nest_depth;
+ SELECT max(depth) FROM tmp.nest_depth INTO v_max_depth;
+ SET v_current_depth = 2;
+ CREATE TEMPORARY TABLE tmp.nest_depth_aux
+ SELECT * FROM tmp.nest_depth;
+ -- Vamos a hacer consultas anidadas para obtener una consulta de dos entradas
+ DROP TEMPORARY TABLE IF EXISTS tmp.nest;
+ DROP TEMPORARY TABLE IF EXISTS tmp.nest_aux;
-DROP TEMPORARY TABLE IF EXISTS tmp.nest;
-DROP TEMPORARY TABLE IF EXISTS tmp.nest_aux;
-
-
-
-SET v_sql = sql_printf (
- '
- CREATE TEMPORARY TABLE tmp.nest
- SELECT child.id nest_id
- ,child.lft
- ,child.rgt
- ,parent.id as ID0
- ,parent.name as PARENT0
- ,child.id as ID1
- ,child.name as PARENT1
- FROM %t AS parent
- JOIN tmp.nest_depth nd ON nd.node_id = parent.id AND nd.depth = 0,
- %t AS child
- JOIN tmp.nest_depth_aux ndc ON ndc.node_id = child.id AND ndc.depth = 1
+ -- Primera tabla, con el nivel 0
+ CALL util.exec (sql_printf (
+ 'CREATE TEMPORARY TABLE tmp.nest
+ SELECT child.id nest_id
+ ,child.lft
+ ,child.rgt
+ ,parent.id as ID0
+ ,parent.name as PARENT0
+ ,child.id as ID1
+ ,child.name as PARENT1
+ FROM %t.%t AS parent
+ JOIN tmp.nest_depth nd ON nd.node_id = parent.id AND nd.depth = 0,
+ %t.%t AS child
+ JOIN tmp.nest_depth_aux ndc ON ndc.node_id = child.id AND ndc.depth = 1
WHERE child.lft BETWEEN parent.lft + 1 AND parent.rgt
- ORDER BY parent.lft;
- ',
- strTABLE,
- strTABLE
- );
-
-CALL sql_query (v_sql);
+ ORDER BY parent.lft'
+ ,vSchema
+ ,strTABLE
+ ,vSchema
+ ,strTABLE
+ ));
-CREATE TEMPORARY TABLE tmp.nest_aux
-SELECT * FROM tmp.nest;
-
-
-
-
-WHILE v_current_depth <= v_max_depth DO
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.nest;
-
- SET v_sql = sql_printf (
- '
- CREATE TEMPORARY TABLE tmp.nest
- SELECT parent.*
- ,child.id as %v
- ,child.name as %v
- ,child.id as ID
- FROM tmp.nest_aux AS parent
- LEFT JOIN %t AS child ON child.lft BETWEEN parent.lft + 1 AND parent.rgt
- LEFT JOIN tmp.nest_depth_aux ndc ON ndc.node_id = child.id
- WHERE IFNULL(ndc.depth,%v) = %v
- ORDER BY parent.lft;
- '
- ,CONCAT('ID',v_current_depth)
- ,CONCAT('PARENT',v_current_depth)
- ,strTABLE
- ,v_current_depth
- ,v_current_depth
- );
-
- CALL sql_query (v_sql);
-
-
-SET v_sql = sql_printf (
- '
- UPDATE tmp.nest
- JOIN %t AS child ON child.id = nest.ID
- SET nest.lft = child.lft, nest.rgt = child.rgt, nest_id = nest.ID'
- ,strTABLE
- );
-
-CALL sql_query (v_sql);
-
-
-
- ALTER TABLE tmp.nest DROP COLUMN ID;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.nest_aux;
- CREATE TEMPORARY TABLE tmp.nest_aux
+ CREATE TEMPORARY TABLE tmp.nest_aux
SELECT * FROM tmp.nest;
+ WHILE v_current_depth <= v_max_depth
+ DO
+ DROP TEMPORARY TABLE IF EXISTS tmp.nest;
+ CALL util.exec (sql_printf (
+ 'CREATE TEMPORARY TABLE tmp.nest
+ SELECT parent.*
+ ,child.id as %v
+ ,child.name as %v
+ ,child.id as ID
+ FROM tmp.nest_aux AS parent
+ LEFT JOIN %t.%t AS child ON child.lft BETWEEN parent.lft + 1 AND parent.rgt
+ LEFT JOIN tmp.nest_depth_aux ndc ON ndc.node_id = child.id
+ WHERE IFNULL(ndc.depth,%v) = %v
+ ORDER BY parent.lft'
+ ,CONCAT('ID',v_current_depth)
+ ,CONCAT('PARENT',v_current_depth)
+ ,vSchema
+ ,strTABLE
+ ,v_current_depth
+ ,v_current_depth
+ ));
+
+ -- Actualizamos lft y rgt
+
+ CALL util.exec (sql_printf (
+ 'UPDATE tmp.nest
+ JOIN %t.%t AS child ON child.id = nest.ID
+ SET nest.lft = child.lft, nest.rgt = child.rgt, nest_id = nest.ID'
+ ,vSchema
+ ,strTABLE
+ ));
+
+ ALTER TABLE tmp.nest DROP COLUMN ID;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.nest_aux;
+ CREATE TEMPORARY TABLE tmp.nest_aux
+ SELECT * FROM tmp.nest;
+
+ SET v_current_depth = v_current_depth + 1;
+ END WHILE;
+
+ -- Eliminamos los campos duplicados
+ SET v_current_depth = 0;
+
+ WHILE v_current_depth <= v_max_depth
+ DO
+ SET @id = 0;
+
+ CALL util.exec (sql_printf (
+ 'UPDATE tmp.nest_aux
+ SET %t = IF(@id = %t, NULL, %t),
+ ID0 = IF(@id := %t, ID0, ID0),
+ %t = IF(length(%t), %t,NULL)'
+ ,CONCAT('PARENT',v_current_depth)
+ ,CONCAT('ID',v_current_depth)
+ ,CONCAT('PARENT',v_current_depth)
+ ,CONCAT('ID',v_current_depth)
+ ,CONCAT('ID',v_current_depth)
+ ,CONCAT('PARENT',v_current_depth)
+ ,CONCAT('ID',v_current_depth)
+ ));
SET v_current_depth = v_current_depth + 1;
+ END WHILE;
-END WHILE;
+ SELECT * FROM tmp.nest_aux;
+ -- Limpieza
-
-
-SET v_current_depth = 0;
-
-WHILE v_current_depth <= v_max_depth DO
-
- SET @id = 0;
-
- SET v_sql = sql_printf (
- '
- UPDATE tmp.nest_aux
- SET %t = IF(@id = %t, NULL, %t),
- ID0 = IF(@id := %t, ID0, ID0),
- %t = IF(length(%t), %t,NULL)
- '
- ,CONCAT('PARENT',v_current_depth)
- ,CONCAT('ID',v_current_depth)
- ,CONCAT('PARENT',v_current_depth)
- ,CONCAT('ID',v_current_depth)
- ,CONCAT('ID',v_current_depth)
- ,CONCAT('PARENT',v_current_depth)
- ,CONCAT('ID',v_current_depth)
- );
-
- CALL sql_query (v_sql);
-
- SET v_current_depth = v_current_depth + 1;
-
-END WHILE;
-
-
-
-
-SELECT * FROM tmp.nest_aux;
-
-
-
-DROP TEMPORARY TABLE IF EXISTS tmp.nest_aux;
-DROP TEMPORARY TABLE IF EXISTS tmp.nest;
-DROP TEMPORARY TABLE IF EXISTS tmp.nest_depth_aux;
-DROP TEMPORARY TABLE IF EXISTS tmp.nest_depth;
-
+ DROP TEMPORARY TABLE IF EXISTS
+ tmp.nest_aux,
+ tmp.nest,
+ tmp.nest_depth_aux,
+ tmp.nest_depth;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -31028,46 +30998,36 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `nest_sons_list`(IN intID INT, IN strTABLE VARCHAR(45), IN bolSHOW BOOLEAN)
+CREATE DEFINER=`root`@`%` PROCEDURE `nest_sons_list`(
+ vId INT
+ ,vTable VARCHAR(45)
+ ,vShouldShow BOOLEAN
+)
BEGIN
+/**
+ * Devuelve un recordset con los ID de todos los nodos que
+ * cuelgan del nodo que se pasa como parámetro
+ */
+ DECLARE vSchema VARCHAR(255) DEFAULT SCHEMA();
-
-
-
-
-DECLARE v_sql TEXT;
-
-DROP TEMPORARY TABLE IF EXISTS tmp.nest_sons;
-
-
-SET v_sql = sql_printf (
- '
- CREATE TEMPORARY TABLE tmp.nest_sons
-
- SELECT DISTINCT node.id node_id
- FROM %t AS node
- JOIN %t AS parent ON node.lft between parent.lft and parent.rgt
+ DROP TEMPORARY TABLE IF EXISTS tmp.nest_sons;
+ CALL util.exec (sql_printf (
+ 'CREATE TEMPORARY TABLE tmp.nest_sons
+ SELECT DISTINCT node.id node_id
+ FROM %t.%t AS node
+ JOIN %t.%t AS parent ON node.lft between parent.lft and parent.rgt
WHERE parent.id = %v
- ORDER BY node.lft
- ;
- ',
- strTABLE,
- strTABLE,
- intID
- );
-
-
-CALL sql_query (v_sql);
+ ORDER BY node.lft'
+ ,vSchema
+ ,vTable
+ ,vSchema
+ ,vTable
+ ,vId
+ ));
-IF bolSHOW THEN
-
- SELECT * FROM tmp.nest_sons;
-
-END IF;
-
-
-
-
+ IF vShouldShow THEN
+ SELECT * FROM tmp.nest_sons;
+ END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -31084,42 +31044,38 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `nest_tree`(IN strTABLE VARCHAR(20), IN intGAP INTEGER, IN bolSHOW BOOLEAN)
+CREATE DEFINER=`root`@`%` PROCEDURE `nest_tree`(
+ vTable VARCHAR(20)
+ ,vGap INT
+ ,vShouldShow BOOL
+)
BEGIN
+ DECLARE vSchema VARCHAR(255) DEFAULT SCHEMA();
-DECLARE v_sql TEXT;
-
-
-DROP TEMPORARY TABLE IF EXISTS tmp.nest;
-
-SET v_sql = sql_printf (
- '
- CREATE TEMPORARY TABLE tmp.nest
- SELECT node.id
- , CONCAT( REPEAT(REPEAT(" ",%v), COUNT(parent.id) - 1), node.name) AS name
- , node.lft
- , node.rgt
- , COUNT(parent.id) - 1 as depth
- , cast((node.rgt - node.lft - 1) / 2 as DECIMAL) as sons
- FROM %t AS node,
- %t AS parent
+ DROP TEMPORARY TABLE IF EXISTS tmp.nest;
+ CALL util.exec (sql_printf (
+ 'CREATE TEMPORARY TABLE tmp.nest
+ SELECT node.id
+ ,CONCAT( REPEAT(REPEAT(" ",%v), COUNT(parent.id) - 1), node.name) AS name
+ ,node.lft
+ ,node.rgt
+ ,COUNT(parent.id) - 1 as depth
+ ,cast((node.rgt - node.lft - 1) / 2 as DECIMAL) as sons
+ FROM %t.%t AS node,
+ %t.%t AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
GROUP BY node.id
- ORDER BY node.lft;
- ',
- intGAP,
- strTABLE,
- strTABLE
- );
-
-
-CALL sql_query (v_sql);
-
-IF bolSHOW THEN
- SELECT * FROM tmp.nest;
-END IF;
-
+ ORDER BY node.lft'
+ ,vGap
+ ,vSchema
+ ,vTable
+ ,vSchema
+ ,vTable
+ ));
+ IF vShouldShow THEN
+ SELECT * FROM tmp.nest;
+ END IF;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -31147,23 +31103,23 @@ BEGIN
SELECT warehouse_id, Fecha, landing INTO vLandingWarehouse, vShipmentDate, vLandingDate FROM Tickets WHERE Id_Ticket = vTicket;
-
+ -- seleccionamos travel
SELECT id, Id_Entrada INTO vTravel, vEntry
FROM travel t LEFT JOIN Entradas e ON t.id = e.travel_id
WHERE t.landing = vLandingDate AND t.shipment = vShipmentDate AND t.warehouse_id_out = vLandingWarehouse AND t.warehouse_id = vWarehouse
- AND t.delivered = FALSE ;
+ AND t.delivered = FALSE ; -- agency ??
-
+ -- creamos el travel si es necesario
IF NOT vTravel THEN
INSERT INTO travel (shipment, landing, warehouse_id, warehouse_id_out, agency_id)
VALUES (vShipmentDate, vLandingDate, vLandingWarehouse, vShipmentWarehouse, a);
SELECT LAST_INSERT_ID() INTO vTravel;
END IF;
-
+ -- creamos la Entrada si es necesario
IF NOT vEntry THEN
INSERT INTO Entradas (Id_Proveedor, travel_id)
- VALUES (13, vTravel);
+ VALUES (13, vTravel); -- proveedor 'MOVIMIENTO ALMACEN'
SELECT LAST_INSERT_ID() INTO vEntry;
END IF;
@@ -31184,51 +31140,96 @@ DELIMITER ;
/*!50003 SET sql_mode = '' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `niching`(IN i_ini INT, IN i_end INT
+
, IN i_bal INT, IN i_col INT )
BEGIN
+
+
DECLARE i INT(5);
+
DECLARE j INT(5);
+
+
DROP TEMPORARY TABLE IF EXISTS labels;
+
+
CREATE TEMPORARY TABLE `labels`
+
(`label` VARCHAR(15) NULL)
+
ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+
+
WHILE i_ini <= i_end DO
+
+
SET i = i_bal;
+
+
WHILE i > 0 DO
+
+
+
+
SET j = i_col;
+
IF j = 0 THEN
+
INSERT INTO labels(label)
+
VALUES (CONCAT(i_ini,IF(i=0,' ',char(64 + i))));
+
ELSE
+
+
WHILE j > 0 DO
+
+
INSERT INTO labels(label)
+
VALUES (CONCAT(i_ini,char(64 + i), j));
+
+
SET j = j - 1;
+
+
END WHILE;
+
END IF;
+
SET i = i - 1;
+
+
END WHILE;
+
+
SET i_ini = i_ini + 1;
+
+
END WHILE;
+
+
SELECT CONCAT('*',label,'*') as label, label as id FROM labels;
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -31273,14 +31274,18 @@ END;
CALL bi.last_buy_id_add;
INSERT INTO vn2008.daily_task_log(consulta) VALUES('last buy id END');
-
+ /* JGF 2016-09-06 Quitado a peticion de AGS
+ SELECT SLEEP(1) INTO AUX;
+ CALL vn2008.comercial_caducado;
+ INSERT INTO vn2008.daily_task_log(consulta) VALUES('Comercial Caducado END');
+ */
SELECT SLEEP(1) INTO AUX;
CALL bi.defaulting(curdate());
INSERT INTO vn2008.daily_task_log(consulta) VALUES('defaulting END');
INSERT INTO vn2008.Colas(Id_Informe,Id_Trabajador) VALUES (11,57);
-
+ -- Desactivacion de usuarios con contrato terminado
INSERT INTO vn2008.Colas(Id_Informe) VALUES (16);
SELECT SLEEP(1) INTO AUX;
@@ -31312,7 +31317,7 @@ END;
INSERT INTO vn2008.daily_task_log(consulta) VALUES('comparativa add END');
SELECT SLEEP(1) INTO AUX;
- call vn2008.recobro_credito();
+ call vn2008.recobro_credito(); -- PAK 12/01/2016
INSERT INTO vn2008.daily_task_log(consulta) VALUES('recobro_credito END');
SELECT SLEEP(1) INTO AUX;
@@ -31327,9 +31332,16 @@ END;
CALL vn.itemTagUpdatePriority(0);
INSERT INTO vn2008.daily_task_log(consulta) VALUES('articleTagUpdatePriority END');
+ /*
+ CALL vn.invoiceOutAgainDateRange(util.yesterday(),util.yesterday());
+ INSERT INTO vn2008.daily_task_log(consulta) VALUES('invoiceOutAgainDateRange END');
+ */
-
-
+ /* jgf posar quan estiga arreglat
+ SELECT SLEEP(1) INTO AUX;
+ CALL bi.primer_pedido_add;
+ INSERT INTO vn2008.daily_task_log(consulta) VALUES('primer_pedido_add END');
+*/
SELECT SLEEP(1) INTO AUX;
INSERT INTO vn2008.daily_task_log(consulta) VALUES('finalitza el event vn2008.nightly_tasks');
@@ -31394,7 +31406,7 @@ CREATE DEFINER=`root`@`%` PROCEDURE `pay`(IN datFEC DATE
BEGIN
-
+-- Registro en la tabla Cajas
INSERT INTO Cajas ( Concepto
, Serie
, Numero
@@ -31420,7 +31432,7 @@ FROM Proveedores
WHERE Id_Proveedor = idPROV;
-
+-- Registro en la tabla pago
INSERT INTO pago(fecha
, id_proveedor
, importe
@@ -31467,6 +31479,7 @@ BEGIN
DECLARE max_range INT;
+
DROP TEMPORARY TABLE IF EXISTS previa;
CREATE TEMPORARY TABLE previa
@@ -31482,6 +31495,7 @@ GROUP BY Id_Cliente) sub
ORDER BY Total
) sub2;
+
SELECT COUNT(*) INTO max_range FROM previa;
UPDATE Clientes SET percentil = 0;
@@ -31489,6 +31503,7 @@ UPDATE Clientes SET percentil = 0;
UPDATE Clientes INNER JOIN previa USING(Id_Cliente)
SET Clientes.percentil = ROUND(Posicion *100 / max_range,0);
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -31508,7 +31523,7 @@ DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `portekk`(IN intId_Ticket INT,IN intbultos INT, IN intId_Article INT)
BEGIN
-
+ -- Deprecated!! Usar la funcion porte en lugar de este procedure
DECLARE intId_Agencia INT;
DECLARE int_agency_id SMALLINT;
DECLARE int_province_id SMALLINT;
@@ -31533,13 +31548,16 @@ BEGIN
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;
-
-
+-- Fusionar con lo de arriba
+/*SELECT IFNULL(MAX(counter),0) +1 INTO intcounter 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 t2.Id_Ticket = NEW.ticket_id AND t1.Etiquetasemitidas = FALSE AND t1.empresa_id = t2.empresa_id;*/
IF (intPorte >= 0 or dbldescuento BETWEEN 0 AND 1 ) THEN
IF intPorte or base_ticket(intId_Ticket) < 50 THEN
- SELECT IFNULL(intPorte,10)/intbultos price;
+ SELECT IFNULL(intPorte,10)/intbultos price;/*en el cas dels tarifa 1 els cobren 10€ de ports*/
ELSE
SELECT 0 price;
END IF;
@@ -31550,14 +31568,14 @@ BEGIN
SELECT IF(price * intbultos < 10 AND porte_minimo, 10 / intbultos, price) price FROM Agencias_zonas az
WHERE zona = 1 AND Id_Agencia = intId_Agencia AND az.warehouse_id = intWarehouse_id;
ELSE
- IF intId_Agencia = 47 THEN
+ IF intId_Agencia = 47 THEN -- Si es viaxpress
SELECT price price FROM Agencias_zonas az INNER JOIN viaxpress USING(zona)
WHERE Id_Agencia = 47 AND codigo_postal = strCodPostal AND az.warehouse_id = intWarehouse_id;
ELSE
- CALL sql_query (sql_printf ('
- SELECT price FROM Agencias_zonas az
+ CALL util.exec (sql_printf ('
+ SELECT price FROM vn2008.Agencias_zonas az
WHERE Id_Agencia = %v AND %v = Id_Article AND az.warehouse_id = %v
- AND zona = (SELECT zona FROM Agencias_province
+ AND zona = (SELECT zona FROM vn2008.Agencias_province
WHERE warehouse_id = %v AND agency_id = %v and province_id = %v)'
,intId_Agencia,intId_Article,intWarehouse_id,intWarehouse_id,int_agency_id,int_province_id));
END IF;
@@ -31565,7 +31583,7 @@ BEGIN
ELSE
SELECT 0 price;
END IF;
- ELSE
+ ELSE -- Si es una agency con la columna por_volumen <> 0 calcula el porte por Volumen
CALL ticket_volumen(intId_Ticket);
SELECT MAX(Porte_total)/intbultos price FROM ticket_volumen;
@@ -31593,11 +31611,11 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `PortesDesdeTicketkk`( intTicket INTEGER)
BEGIN
-
+ -- DEPRECATED! con el bionic esto ya no se usa
DECLARE done BIT DEFAULT 0;
DECLARE v_date_ini,v_date_end DATE;
-
-
+ -- JGF 21/08/14 A partir de un intTicket se calcula lo que se ha cobrado en concepto de portes
+ -- restando la tarifa dos en esa fecha al valor del ticket
DROP TEMPORARY TABLE IF EXISTS portes;
IF (SELECT Descuento FROM Clientes c JOIN Tickets t ON t.Id_Cliente = c.Id_Cliente WHERE t.Id_Ticket = intTicket) BETWEEN 0 AND 1 THEN
SELECT TIMESTAMPADD(MONTH,-12,Fecha),Fecha INTO v_date_ini,v_date_end FROM Tickets WHERE Id_Ticket = intTicket LIMIT 1;
@@ -31635,9 +31653,9 @@ BEGIN
Preu * (1 - (Descuento / 100)) * Cantidad diferencia,0 Tarifa2, Cantidad FROM Movimientos
WHERE Id_Ticket= intTicket AND Id_Article = 71;
END IF;
-
+ -- SELECT * FROM vn2008.portes;
-
+ -- SELECT NULL, NULL, NULL, sum(diferencia) as Porte, NULL FROM portes p;
END ;;
DELIMITER ;
@@ -31849,11 +31867,18 @@ DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `proc_end`()
BEGIN
+
+
UPDATE stat SET `end` = NOW()
+
WHERE id = (SELECT id FROM lastid);
+
+
DROP TEMPORARY TABLE IF EXISTS lastid;
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -31873,13 +31898,56 @@ DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `proc_start`(IN v_proc_id INT)
BEGIN
+
+
INSERT INTO stat(proc_id) VALUES(v_proc_id);
+
+
+
DROP TEMPORARY TABLE IF EXISTS lastid;
+
CREATE TEMPORARY TABLE lastid
+
SELECT last_insert_id() 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 `productionState` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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=`z-developer`@`%` PROCEDURE `productionState`(vWarehouse INT , vDate DATE)
+BEGIN
+
+
+SELECT IF(a.Vista= 2, z.alias, a.Agencia) Agencia, t.Id_Ruta, count(*) Pedidos
+FROM Tickets t
+JOIN Consignatarios CS on CS.Id_Consigna = t.Id_Consigna
+JOIN Agencias a ON a.Id_Agencia = t.Id_Agencia
+ LEFT JOIN Agencias_province ap on ap.province_id = CS.province_id AND ap.warehouse_id = t.warehouse_id AND ap.agency_id = a.agency_id
+ LEFT JOIN Tickets_state tls on tls.Id_Ticket = t.Id_Ticket
+ LEFT JOIN zoneNickname z ON z.warehouse_id = ap.warehouse_id and z.agency_id = ap.agency_id AND z.zona = ap.zona
+ LEFT JOIN vncontrol.inter vni ON vni.inter_id = tls.inter_id
+ LEFT JOIN state s ON s.id = vni.state_id
+WHERE Fecha BETWEEN vDate AND util.dayend(vDate)
+AND s.alert_level = 1
+AND t.warehouse_id = vWarehouse
+GROUP BY Agencia, Id_Ruta;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -31898,7 +31966,9 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `production_buffer_problems`()
BEGIN
-
+/**
+ * Necesita la tabla tmp.ticket_list
+ */
DECLARE vToday DATETIME;
DECLARE vTomorrowMidnight DATETIME ;
DECLARE vWarehouse INT;
@@ -31939,7 +32009,7 @@ BEGIN
CALL cache.visible_refresh (vVisibleCache, FALSE, vWarehouse);
CALL cache.available_refresh (vAvailableCache, FALSE, vWarehouse, vDate);
-
+ -- El disponible es menor que 0
INSERT INTO tmp.buffer_problems(Id_Ticket, problem)
SELECT tt.Id_Ticket, Article
@@ -31959,7 +32029,7 @@ BEGIN
AND NOT generic
AND vWarehouse = t.warehouse_id;
-
+ -- El disponible es mayor que cero y la cantidad supera el visible, estando aun sin preparar
INSERT INTO tmp.buffer_problems(Id_Ticket, problem)
SELECT tt.Id_Ticket, CONCAT('RETRASO (', A.Id_Article, ') ', Article)
FROM tmp.ticket_list tt
@@ -31987,7 +32057,7 @@ BEGIN
CLOSE vCursor;
-
+ -- Código 100
INSERT INTO tmp.buffer_problems(Id_Ticket, problem)
SELECT DISTINCT tt.Id_Ticket, 'COD 100'
@@ -31995,7 +32065,7 @@ BEGIN
JOIN Movimientos m on m.Id_Ticket = tt.Id_Ticket
WHERE Id_Article = 100;
-
+ -- Congelado
INSERT INTO tmp.buffer_problems(Id_Ticket, problem)
SELECT DISTINCT tt.Id_Ticket, 'CONGELADO'
@@ -32004,7 +32074,7 @@ BEGIN
JOIN Clientes c on c.Id_Cliente = t.Id_Cliente
WHERE c.Congelado;
-
+ -- Riesgo
CALL risk_vs_client_list(CURDATE());
@@ -32016,8 +32086,18 @@ BEGIN
JOIN tmp.risk r on r.Id_Cliente = t.Id_Cliente
JOIN Clientes c on c.Id_Cliente = t.Id_Cliente
WHERE r.risk > c.Credito + 10
- AND Vista != 3;
-
+ AND Vista != 3; -- para que las recogidas se preparen
+ /*
+ -- Saldo vencido
+ INSERT INTO tmp.buffer_problems(Id_Ticket, problem)
+ SELECT DISTINCT tt.Id_Ticket, 'SALDO VENCIDO'
+ FROM tmp.ticket_list tt
+ JOIN Tickets t on t.Id_Ticket = tt.Id_Ticket
+ JOIN Agencias a on t.Id_Agencia = a.Id_Agencia
+ JOIN bi.defaulters d ON d.client = t.Id_Cliente
+ WHERE d.amount > 200 AND d.date = CURDATE()
+ AND Vista != 3; -- para que las recogidas se preparen
+ */
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -32036,7 +32116,10 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `production_buffer_problemsOptimizado`()
BEGIN
-
+/*
+ * Necesita la tabla tmp.ticket_list
+ *
+ */
DECLARE vWarehouse INT;
DECLARE vDate DATE;
DECLARE vAvailableCache INT;
@@ -32060,14 +32143,14 @@ BEGIN
ENGINE = MEMORY;
-
+ -- CONGELADO
INSERT INTO tmp.buffer_problems(Id_Ticket, problem)
SELECT DISTINCT tt.Id_Ticket, 'CONGELADO'
FROM tmp.ticket_list tt
JOIN Clientes c on c.Id_Cliente = tt.Id_Cliente
WHERE c.Congelado;
-
+ -- eliminamos tickets con problemas para no volverlos a mirar
DROP TEMPORARY TABLE IF EXISTS tmp.ticketListFiltered;
CREATE TEMPORARY TABLE tmp.ticketListFiltered
@@ -32078,7 +32161,7 @@ BEGIN
JOIN Clientes c on c.Id_Cliente = tt.Id_Cliente
WHERE c.Congelado = 0;
-
+ -- RIESGO
CALL risk_vs_client_list(CURDATE());
@@ -32090,20 +32173,20 @@ BEGIN
JOIN tmp.risk r on r.Id_Cliente = t.Id_Cliente
JOIN Clientes c on c.Id_Cliente = t.Id_Cliente
WHERE r.risk > c.Credito + 10
- AND Vista != 3;
-
+ AND Vista != 3; -- para que las recogidas se preparen
+ -- eliminamos tickets con problemas para no volverlos a mirar
DELETE tlf FROM tmp.ticketListFiltered tlf
JOIN tmp.buffer_problems bf ON tlf.Id_Ticket = bf.Id_Ticket;
-
+ -- CODIGO 100
INSERT INTO tmp.buffer_problems(Id_Ticket, problem)
SELECT DISTINCT tt.Id_Ticket, 'COD 100'
FROM tmp.ticket_list tt
JOIN Movimientos m on m.Id_Ticket = tt.Id_Ticket
WHERE Id_Article = 100;
-
+ -- eliminamos tickets con problemas para no volverlos a mirar
DELETE tlf FROM tmp.ticketListFiltered tlf
JOIN tmp.buffer_problems bf ON tlf.Id_Ticket = bf.Id_Ticket;
@@ -32116,10 +32199,10 @@ BEGIN
CALL cache.visible_refresh(vVisibleCache,FALSE,vWarehouse);
CALL cache.available_refresh(vAvailableCache,FALSE,vWarehouse,vDate);
-
+ -- El disponible es menor que 0
INSERT INTO tmp.buffer_problems(Id_Ticket, problem)
SELECT tt.Id_Ticket, Article
-
+ -- CONCAT(IF( M.Cantidad < IFNULL(v.visible,0) , 'NO HAY ','FALTARÁ ' ), Article)
FROM tmp.ticket_list tt
JOIN Tickets t on t.Id_Ticket = tt.Id_Ticket
LEFT JOIN vn2008.Movimientos M ON M.Id_Ticket = t.Id_Ticket
@@ -32135,11 +32218,11 @@ BEGIN
AND NOT generic
AND vWarehouse = t.warehouse_id;
-
+ -- eliminamos tickets con problemas para no volverlos a mirar
DELETE tlf FROM tmp.ticketListFiltered tlf
JOIN tmp.buffer_problems bf ON tlf.Id_Ticket = bf.Id_Ticket;
-
+ -- Amarillo: El disponible es mayor que cero y la cantidad supera el visible, estando aun sin preparar
INSERT INTO tmp.buffer_problems(Id_Ticket, problem)
SELECT tt.Id_Ticket, CONCAT('RETRASO ', Article)
FROM tmp.ticket_list tt
@@ -32185,7 +32268,7 @@ DECLARE currentDayOfWeek INT;
SET currentDayOfWeek = weekday(curdate());
-
+-- Sin provincia ni dia de envio
UPDATE tmp.production_buffer pb
LEFT JOIN
(
@@ -32204,7 +32287,7 @@ SET pb.Hora = IF(pb.Hora is null or pb.Hora = 0 or pb.Hora = 24,IFNULL(t.max_ho
,pb.Departure =IFNULL(t.max_hour,0);
-
+-- Agencias sin provincia, machacan lo anterior si coinciden
UPDATE tmp.production_buffer pb
JOIN
(
@@ -32228,7 +32311,7 @@ SET pb.Hora = IF(pb.Hora is null or pb.Hora = 0 or pb.Hora = 24,t.max_hour, pb.
;
-
+-- Agencias con provincia, se ejecuta para machacar lo anterior, si procede.
UPDATE tmp.production_buffer pb
JOIN
(
@@ -32253,8 +32336,13 @@ SET pb.Hora = IF(pb.Hora is null or pb.Hora = 0 or pb.Hora = 24,t.max_hour, pb.H
,pb.Departure = t.max_hour
;
-
-
+-- Pedidos del dia anterior son prioritarios
+/*
+UPDATE tmp.production_buffer pb
+JOIN Tickets t ON t.Id_Ticket = pb.ticket
+SET pb.Hora = 1
+WHERE t.Fecha < CURDATE();
+*/
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -32276,8 +32364,9 @@ BEGIN
DECLARE vMidnight DATETIME DEFAULT TIMESTAMP(CURDATE(),'23:59:59');
DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,vMidnight);
DECLARE SAFE_ALERT_LEVEL INT DEFAULT 3;
+ DECLARE vLoadingDelay DECIMAL(5) DEFAULT 2;
- CALL prepare_ticket_list(TIMESTAMPADD(DAY,-1,CURDATE()), vEndingDate);
+ CALL prepare_ticket_list(TIMESTAMPADD(DAY,0,CURDATE()-1), vEndingDate);
CALL prepare_client_list;
CALL production_buffer_problems;
@@ -32291,14 +32380,15 @@ BEGIN
, t.Alias
, t.Bultos
, HOUR(t.Fecha) as Hora
- , HOUR(t.Fecha) as Departure
+ , HOUR(t.Fecha) + vLoadingDelay as Departure
+ , MINUTE(t.Fecha) as minuto
, t.Id_Ruta
, IF(a.Vista = 2,ap.zona,0) as zona
, CS.Consignatario
, CS.CODPOSTAL
, CS.POBLACION
, p.name PROVINCIA
- , IF(a.Vista= 2, CONCAT('ZONA ',ap.zona), a.Agencia) Agencia
+ , IF(a.Vista= 2, CONCAT(LEFT(z.alias,16),' ',IFNULL(RIGHT(t.Id_Ruta,3),'')), a.Agencia) Agencia
, a.agency_id
, 0 AS `lines`
, CAST( 0 AS DECIMAL(5,2)) AS m3
@@ -32315,16 +32405,17 @@ BEGIN
FROM tmp.ticket_list tt
JOIN Tickets t on tt.Id_Ticket = t.Id_Ticket
JOIN Consignatarios CS on CS.Id_Consigna = t.Id_Consigna
- JOIN province p on p.province_id = CS.province_id
+ LEFT JOIN province p on p.province_id = CS.province_id
JOIN Agencias a ON a.Id_Agencia = t.Id_Agencia
LEFT JOIN Agencias_province ap on ap.province_id = CS.province_id AND ap.warehouse_id = t.warehouse_id AND ap.agency_id = a.agency_id
LEFT JOIN vn.ticketState tls on tls.ticket = tt.Id_Ticket
LEFT JOIN Trabajadores w on w.Id_Trabajador = tls.worker
+ LEFT JOIN zoneNickname z ON z.warehouse_id = ap.warehouse_id and z.agency_id = ap.agency_id AND z.zona = ap.zona
WHERE t.warehouse_id = vWarehouseId
AND a.Vista IN (1,2,3);
-
+ -- Líneas y volumen por ticket
UPDATE tmp.production_buffer pb
JOIN (
@@ -32341,7 +32432,7 @@ BEGIN
DELETE FROM tmp.production_buffer
WHERE `lines`= 0;
-
+ -- Cajas
ALTER TABLE tmp.production_buffer
ADD Cajas DOUBLE DEFAULT NULL;
@@ -32361,7 +32452,7 @@ BEGIN
) sub ON sub.Id_Ticket = pb.Id_Ticket
SET pb.Cajas = sub.Cajas;
-
+ -- Artificial, Seco y Preservado: Reino 4
ALTER TABLE tmp.production_buffer
ADD lineasArtificial INT DEFAULT NULL;
@@ -32381,7 +32472,7 @@ BEGIN
SET pb.lineasArtificial = sub.Lineas;
-
+ -- Problemas por ticket
UPDATE tmp.production_buffer pb
JOIN (
@@ -32392,11 +32483,11 @@ BEGIN
SET pb.problems = p.problems,
pb.problem = p.problem;
-
+ -- Hora limite de preparación
CALL production_buffer_set_priority;
-
+ -- Entradas
INSERT INTO tmp.production_buffer(
Fecha
@@ -32426,11 +32517,11 @@ BEGIN
AND c.shipment >= CURDATE()
GROUP BY Id_Entrada;
-
+ -- Refresca la caché para el cierre dinámico de agencias
CALL cache.departure_timing;
-
+ -- Tickets de recogida
REPLACE tmp.production_buffer(
Fecha
@@ -32463,8 +32554,263 @@ BEGIN
WHERE t.Fecha between TIMESTAMPADD(WEEK,-1,CURDATE()) AND dayend(TIMESTAMPADD(DAY,-1,CURDATE()))
AND wp.warehouse_id = vWarehouseId;
+ -- DROP TEMPORARY TABLE tmp.ticket_list;
+ -- DROP TEMPORARY TABLE IF EXISTS tmp.risk;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `production_control_source_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 `production_control_source_Beta`(vWarehouseId INT, vScopeDays TINYINT)
+BEGIN
+ DECLARE vMidnight DATETIME DEFAULT TIMESTAMP(CURDATE(),'23:59:59');
+ DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,vMidnight);
+ DECLARE SAFE_ALERT_LEVEL INT DEFAULT 3;
+ DECLARE vLoadingDelay DECIMAL(5) DEFAULT 2;
+
+ CALL prepare_ticket_list(TIMESTAMPADD(DAY,0,CURDATE()-1), vEndingDate);
+ CALL prepare_client_list;
+ CALL production_buffer_problems;
+
+ IF vWarehouseId = 0 THEN
+
+ DELETE tt.*
+ FROM tmp.ticket_list tt
+ JOIN Tickets t on tt.Id_Ticket = t.Id_Ticket
+ WHERE t.warehouse_id NOT IN (1,44);
+
+ ELSE
+
+ DELETE tt.*
+ FROM tmp.ticket_list tt
+ JOIN Tickets t on tt.Id_Ticket = t.Id_Ticket
+ WHERE t.warehouse_id != vWarehouseId;
+
+ END IF;
+
+ /*
+ DROP TEMPORARY TABLE IF EXISTS tmp.selectedWarehouses;
+
+ IF vWarehouseId = 0 THEN
+
+ CREATE TEMPORARY TABLE tmp.selectedWarehouses
+ (PRIMARY KEY(id))
+ ENGINE = MEMORY
+ SELECT id
+ FROM warehouse
+ WHERE id = vWarehouseId;
+
+ ELSE
+
+ CREATE TEMPORARY TABLE tmp.selectedWarehouses
+ (PRIMARY KEY(id))
+ ENGINE = MEMORY
+ SELECT id
+ FROM warehouse
+ WHERE id IN (1,44); -- Silla FV y Silla PCA
+
+ END IF;
+ */
+
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.production_buffer;
+ CREATE TEMPORARY TABLE tmp.production_buffer
+ (PRIMARY KEY(Id_Ticket))
+ ENGINE = MEMORY
+ SELECT t.Id_Ticket
+ , t.Id_Cliente
+ , t.warehouse_id
+ , t.Alias
+ , t.Bultos
+ , HOUR(t.Fecha) as Hora
+ , HOUR(t.Fecha) + vLoadingDelay as Departure
+ , MINUTE(t.Fecha) as minuto
+ , t.Id_Ruta
+ , IF(a.Vista = 2,ap.zona,0) as zona
+ , CS.Consignatario
+ , CS.CODPOSTAL
+ , CS.POBLACION
+ , p.name PROVINCIA
+ , IF(a.Vista= 2, CONCAT(LEFT(z.alias,16),' ',IFNULL(RIGHT(t.Id_Ruta,3),'')), a.Agencia) Agencia
+ , a.agency_id
+ , 0 AS `lines`
+ , CAST( 0 AS DECIMAL(5,2)) AS m3
+ , 0 AS problems
+ , " " as problem
+ , IFNULL(tls.state,2) AS state
+ , w.Codigotrabajador
+ , DATE(t.Fecha) AS Fecha
+ , Averiguar_ComercialCliente_IdTicket(t.Id_Ticket) AS Comercial
+ , p.province_id
+ , tls.productionOrder as state_order
+ , ifnull(tls.alertLevel,0) alert_level
+ , t.boxed as palletized
+ FROM tmp.ticket_list tt
+ JOIN Tickets t on tt.Id_Ticket = t.Id_Ticket
+ JOIN Consignatarios CS on CS.Id_Consigna = t.Id_Consigna
+ LEFT JOIN province p on p.province_id = CS.province_id
+ JOIN Agencias a ON a.Id_Agencia = t.Id_Agencia
+ LEFT JOIN Agencias_province ap on ap.province_id = CS.province_id AND ap.warehouse_id = t.warehouse_id AND ap.agency_id = a.agency_id
+ LEFT JOIN vn.ticketState tls on tls.ticket = tt.Id_Ticket
+ LEFT JOIN Trabajadores w on w.Id_Trabajador = tls.worker
+ LEFT JOIN zoneNickname z ON z.warehouse_id = ap.warehouse_id and z.agency_id = ap.agency_id AND z.zona = ap.zona
+ AND a.Vista IN (1,2,3);
+
+
+ -- Líneas y volumen por ticket
+
+ UPDATE tmp.production_buffer pb
+ JOIN (
+ SELECT m.Id_Ticket, COUNT(Id_Movimiento) as `lines`, cast( sum( m.Cantidad * r.cm3 / 1000000 ) as decimal(10,2)) as m3
+ FROM tmp.ticket_list tt
+ JOIN Tickets t ON t.Id_Ticket = tt.Id_Ticket
+ JOIN Movimientos m on tt.Id_Ticket = m.Id_Ticket
+ JOIN bi.rotacion r on m.Id_Article = r.Id_Article AND r.warehouse_id = t.warehouse_id
+ GROUP BY m.Id_Ticket
+ ) m on m.Id_Ticket = pb.Id_Ticket
+ SET pb.`lines` = m.`lines`,
+ pb.m3 = m.m3;
+
+ DELETE FROM tmp.production_buffer
+ WHERE `lines`= 0;
+
+ -- Cajas
+
+ ALTER TABLE tmp.production_buffer
+ ADD Cajas DOUBLE DEFAULT NULL;
+
+ UPDATE tmp.production_buffer pb
+ JOIN (
+ SELECT t.Id_Ticket, sum(floor(m.Cantidad / c.Packing) * bultoCubico) as Cajas
+ FROM tmp.ticket_list tt
+ JOIN Tickets t on tt.Id_Ticket = t.Id_Ticket
+ JOIN Movimientos m on m.Id_Ticket = t.Id_Ticket
+ JOIN cache.last_buy lb on lb.warehouse_id = t.warehouse_id AND lb.item_id = m.Id_Article
+ JOIN Compres c on c.Id_Compra = lb.buy_id
+ JOIN Cubos cb on cb.Id_Cubo = c.Id_Cubo
+ WHERE m.Cantidad > c.Packing
+ GROUP BY t.Id_Ticket
+ HAVING Cajas >= 1
+ ) sub ON sub.Id_Ticket = pb.Id_Ticket
+ SET pb.Cajas = sub.Cajas;
-
+ -- Artificial, Seco y Preservado: Reino 4
+
+ ALTER TABLE tmp.production_buffer
+ ADD lineasArtificial INT DEFAULT NULL;
+
+ UPDATE tmp.production_buffer pb
+ JOIN (
+ SELECT tt.Id_Ticket, COUNT(m.Id_Movimiento) as Lineas
+ FROM tmp.ticket_list tt
+ JOIN Movimientos m ON m.Id_Ticket = tt.Id_Ticket
+ JOIN Articles a ON a.Id_Article = m.Id_Article
+ JOIN Tipos tp ON tp.tipo_id = a.tipo_id
+ JOIN reinos r ON r.id = tp.reino_id
+ WHERE reino = 'Artificial'
+ GROUP BY tt.Id_Ticket
+ HAVING Lineas >= 1
+ ) sub ON sub.Id_Ticket = pb.Id_Ticket
+ SET pb.lineasArtificial = sub.Lineas;
+
+
+ -- Problemas por ticket
+
+ UPDATE tmp.production_buffer pb
+ JOIN (
+ SELECT Id_Ticket, COUNT(Id_Ticket) as problems, GROUP_CONCAT(problem) problem
+ FROM tmp.buffer_problems
+ GROUP BY Id_Ticket
+ ) p on p.Id_Ticket = pb.Id_Ticket
+ SET pb.problems = p.problems,
+ pb.problem = p.problem;
+
+ -- Hora limite de preparación
+
+ CALL production_buffer_set_priority;
+
+ -- Entradas
+
+ INSERT INTO tmp.production_buffer(
+ Fecha
+ , Id_Ticket
+ , Agencia
+ , Id_Cliente
+ , Consignatario
+ , state
+ , CodigoTrabajador
+ , m3
+ , `lines`
+ )
+ SELECT DISTINCT c.shipment AS Fecha
+ , c.Id_Entrada AS Id_Ticket
+ , warehouse.name
+ , c.Id_Proveedor
+ , c.ref AS Consignatario
+ , IF(BIT_OR(controlado.Id_Compra),6,IF(BIT_OR(preparado.Id_Compra),5,3)) AS state
+ , c.Id_Trabajador AS CodigoTrabajador
+ , round(sum(cm3) / 1000000,2) AS m3
+ , count(c.Id_Compra) as `lines`
+ FROM v_compres c
+ INNER JOIN warehouse ON c.warehouse_id = warehouse.id
+ LEFT JOIN Compres_ok preparado ON c.Id_Compra = preparado.Id_Compra AND preparado.valor = 1
+ LEFT JOIN Compres_ok controlado ON c.Id_Compra = controlado.Id_Compra AND controlado.valor = 2
+ WHERE (warehouse_id_out = CASE vWarehouseId WHEN 0 THEN 1 ELSE vWarehouseId END
+ OR
+ warehouse_id_out = CASE vWarehouseId WHEN 0 THEN 44 ELSE vWarehouseId END)
+ AND IFNULL(c.Confirmada,FALSE) = FALSE
+ AND c.shipment >= CURDATE()
+ GROUP BY Id_Entrada;
+
+ -- Refresca la caché para el cierre dinámico de agencias
+
+ CALL cache.departure_timing;
+
+ -- Tickets de recogida
+
+ REPLACE tmp.production_buffer(
+ Fecha
+ , Id_Ticket
+ , Agencia
+ , Id_Cliente
+ , Consignatario
+ , state
+ , CodigoTrabajador
+ , alert_level
+ , warehouse_id
+ )
+ SELECT
+ DATE(t.Fecha) AS Fecha
+ , t.Id_Ticket
+ , a.Agencia
+ , t.Id_Cliente
+ , CS.Consignatario
+ , s.id as state
+ , w.Codigotrabajador
+ , ifnull(tls.alertLevel,0) alert_level
+ , t.warehouse_id
+ FROM vn2008.Tickets t
+ JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.Id_Ticket
+ JOIN vn2008.Consignatarios CS on CS.Id_Consigna = t.Id_Consigna
+ JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia
+ LEFT JOIN vn2008.warehouse_pickup wp ON wp.agency_id = a.Id_Agencia
+ LEFT JOIN vn.ticketState tls on tls.ticket = t.Id_Ticket
+ LEFT JOIN vn.state s ON s.id = tls.state
+ LEFT JOIN vn2008.Trabajadores w on w.Id_Trabajador = tls.worker
+ WHERE t.Fecha between TIMESTAMPADD(WEEK,-1,CURDATE()) AND dayend(TIMESTAMPADD(DAY,-1,CURDATE()))
+ ;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -32705,7 +33051,7 @@ GROUP BY id_proveedor, empresa_id
GROUP BY Id_Proveedor, empresa_id
) sub_tot USING(Id_Proveedor, empresa_id)
-
+-- Saldo inmediato
LEFT JOIN
(
@@ -32790,7 +33136,7 @@ BEGIN
, PRIMARY KEY(proveedor_id, empresa_id, moneda_id))
ENGINE = MEMORY;
-
+ -- Calcula el saldo inicial y final de cada proveedor
INSERT INTO saldos_iniciales
SELECT id_proveedor, empresa_id, sum(importe * isBeforeStarting) as saldo_inicial,sum(importe) saldo_final, moneda_id
FROM (
@@ -32876,7 +33222,7 @@ BEGIN
AND r.proveedor_id <> 567
ORDER BY id_proveedor, empresa_id, id_moneda, fecha, isPago DESC,id;
-
+ -- Ahora, calculamos el importe pendiente para cada recibo en orden descendente
SET @saldo:= 0.0;
SET @prov := 0.0;
SET @emp := 0.0;
@@ -32886,7 +33232,7 @@ BEGIN
UPDATE vencimientos_pendientes vp LEFT JOIN saldos_iniciales si ON
vp.empresa_id = si.empresa_id AND vp.proveedor_id = si.proveedor_id AND vp.moneda_id = si.moneda_id
- SET vp.saldo = @saldo:= (IF(@emp <> vp.empresa_id OR @prov <> vp.proveedor_id OR @moneda <> vp.moneda_id, IFNULL(si.saldo_inicial,0),@saldo) + vp.importe)
+ SET vp.saldo = @saldo:= (IF(@emp <> vp.empresa_id OR @prov <> vp.proveedor_id OR @moneda <> vp.moneda_id, IFNULL(si.saldo_inicial,0),@saldo) + vp.importe) -- si hay cambio de empresa o proveedor o moneda, el saldo se reinicia
, vp.pendiente = @pendiente:= IF(@emp <> vp.empresa_id OR @prov <> vp.proveedor_id OR @moneda <> vp.moneda_id OR @day <> vp.fecha, vp.importe * (NOT isPago) , @pendiente + vp.importe)
, vp.empresa_id = @emp:= vp.empresa_id
, vp.proveedor_id = @prov:= vp.proveedor_id
@@ -33063,16 +33409,16 @@ SELECT id_proveedor, empresa_id, sum(importe) as saldo, id_moneda as moneda_id
DROP TEMPORARY TABLE vencimientos_pendientes_aux;
+ -- Ahora, al fin, calculamos el importe pendiente para cada recibo en orden descendente
-
-
+ -- Cogemos los valores del primer registro como semilla
SELECT proveedor_id, empresa_id, saldo, moneda_id, 0
INTO @prov, @emp, @saldo, @moneda, @pend
FROM vencimientos_pendientes WHERE id2 = 1;
UPDATE vencimientos_pendientes
- SET saldo = @saldo:= IF(@emp <> empresa_id OR @prov <>proveedor_id OR @moneda <> moneda_id,saldo,@saldo)
+ SET saldo = @saldo:= IF(@emp <> empresa_id OR @prov <>proveedor_id OR @moneda <> moneda_id,saldo,@saldo) -- si hay cambio de empresa o proveedor o moneda, el saldo se reinicia
, pendiente = @pend:= IF(saldo >= importe AND saldo > 0, importe, saldo)
, saldo = @saldo:= @saldo - @pend
, empresa_id = @emp:= empresa_id
@@ -33187,7 +33533,7 @@ BEGIN
JOIN Proveedores P2 ON P2.Id_Proveedor = sub2.empresa_id
- WHERE pm.deudaviva
+ WHERE pm.deudaviva -- Cliente de perdidas no vale la pena revisarlo
HAVING ABS(Diferencia) > 0.05
@@ -33218,7 +33564,7 @@ DECLARE datSTART DATE;
SET datSTART = FIRSTDAYOFYEAR(datFEC);
SET datFEC = TIMESTAMP(datFEC,'23:59:59');
-
+-- Creamos una tabla para almacenar las facturas del cliente, junto con el numero de veces que se repite.
DROP TEMPORARY TABLE IF EXISTS qFACTURAS;
CREATE TEMPORARY TABLE qFACTURAS
@@ -33234,7 +33580,7 @@ CREATE TEMPORARY TABLE qFACTURAS
ENGINE = InnoDB
;
-
+-- Insertamos las facturas y los recibos de gestion.
INSERT INTO qFACTURAS
SELECT Fecha, COUNT(*) as TPVcount, round(Importe,2) as Factura, 0 as Recibo, COUNT(*)as CPcount,round(Importe,2) as Debe, 0 as Haber, 1 as Control
@@ -33247,7 +33593,7 @@ INSERT INTO qFACTURAS
WHERE Id_Cliente = idC AND empresa_id = idE AND Fechacobro BETWEEN datSTART AND datFEC
GROUP BY Fechacobro, round(Entregado,2);
-
+-- Insertamos los asientos de contabilidad, marcando con control = -1 las repetidas.
INSERT INTO qFACTURAS
SELECT *
FROM (
@@ -33263,14 +33609,14 @@ INSERT INTO qFACTURAS
+-- Eliminamos las repetidas
+-- DELETE FROM qFACTURAS WHERE Control = -1;
-
-
-
+-- Arreglamos las buenas
UPDATE qFACTURAS SET TPVcount = 0, Factura = 0, Recibo = 0 WHERE Control = 2;
UPDATE qFACTURAS SET CPcount = 0, Debe = 0, Haber = 0 WHERE Control IN (1,3);
-
+-- Mostramos el resultado
SELECT *, @saldo := @saldo + TPVcount * (Factura + Recibo) - CPCount * ( Debe + Haber ) as Saldo
FROM qFACTURAS
JOIN (SELECT @saldo := 0) truqui ;
@@ -33322,7 +33668,7 @@ BEGIN
SELECT empresa_id, proveedor_id, -1 * sum(cantidad) as Gestion
FROM recibida_vencimiento rv
INNER JOIN recibida r ON r.id = rv.recibida_id
- WHERE IFNULL(r.dateBooking,r.fecha) BETWEEN datSTART AND datFEC
+ WHERE IFNULL(r.bookEntried,r.fecha) BETWEEN datSTART AND datFEC
AND r.contabilizada
GROUP BY r.id
@@ -33332,7 +33678,7 @@ BEGIN
FROM pago
WHERE Fecha BETWEEN datSTART AND datFEC
AND conciliado
- AND pay_met_id <> 18
+ AND pay_met_id <> 18 -- Saldos iniciales
) G
UNION ALL
@@ -33389,7 +33735,7 @@ SET datFEC = TIMESTAMP(datFEC,'23:59:59');
SET datSTART = FIRSTDAYOFYEAR(datFEC);
-
+-- Creamos una tabla para almacenar las facturas del proveedor, junto con el numero de veces que se repite.
DROP TEMPORARY TABLE IF EXISTS qFACTURAS;
CREATE TEMPORARY TABLE qFACTURAS
@@ -33405,7 +33751,7 @@ CREATE TEMPORARY TABLE qFACTURAS
ENGINE = InnoDB
;
-
+-- Insertamos las facturas y los pagos de gestion.
INSERT INTO qFACTURAS
SELECT Fecha, COUNT(*) as TPVcount, round(Importe,2) as Factura
@@ -33426,7 +33772,7 @@ INSERT INTO qFACTURAS
AND conciliado
GROUP BY Fecha, round(importe,2);
-
+-- Insertamos los asientos de contabilidad, marcando con control = -1 las repetidas
INSERT INTO qFACTURAS
SELECT *
FROM (
@@ -33442,14 +33788,14 @@ INSERT INTO qFACTURAS
-
+-- Eliminamos las repetidas
DELETE FROM qFACTURAS WHERE Control = -1;
-
+-- Arreglamos las buenas
UPDATE qFACTURAS SET TPVcount = 0, Factura = 0, Recibo = 0 WHERE Control = 2;
UPDATE qFACTURAS SET CPcount = 0, Debe = 0, Haber = 0 WHERE Control IN (1,3);
-
+-- Mostramos el resultado
SELECT *, @saldo := @saldo + TPVcount * (Factura + Recibo) - CPcount * (Debe + Haber) as Saldo
FROM qFACTURAS
JOIN (SELECT @saldo := 0) truqui ;
@@ -33512,7 +33858,7 @@ BEGIN
FROM pago
WHERE Fecha BETWEEN datSTART AND datFEC
AND conciliado
- AND pay_met_id <> 18
+ AND pay_met_id <> 18 -- Saldos iniciales
) G
UNION ALL
@@ -33576,13 +33922,13 @@ BEGIN
SET dateStart = TIMESTAMPADD(MONTH, -2, CURDATE());
SELECT TIMESTAMPADD(DAY, -1, today) INTO yesterday;
-
+ -- lo quitamos despues de campañaA
SELECT TIMESTAMP(TIMESTAMPADD(DAY, scopeDays, yesterday),'23:59:59') INTO maxDate;
-
-
+ -- SELECT TIMESTAMP(TIMESTAMPADD(DAY, 14, yesterday),'23:59:59') INTO maxDate;
+ -- Creamos una tabla con los Comerciales de los que se mostraran los tickets
CALL subordinate(worker,TRUE);
-
+ -- Se genera una tabla con los tickets representados
DROP TEMPORARY TABLE IF EXISTS ticketRange;
CREATE TEMPORARY TABLE ticketRange
@@ -33629,7 +33975,14 @@ BEGIN
INNER JOIN Tickets T USING(Id_Cliente)
LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket
INNER JOIN workerTeamCollegues w ON w.collegueId = C.Id_Trabajador
-
+ /*
+ (SELECT Id_Trabajador
+ FROM Trabajadores t
+ JOIN account.user u ON u.id = t.user_id
+ JOIN workerTeam w on w.user = u.id
+ JOIN (SELECT team FROM workerTeam wt JOIN Trabajadores tr on tr.user_id = wt.user WHERE Id_Trabajador = worker) sub on sub.team = w.team
+ ) sub2 ON sub2.Id_Trabajador = C.Id_Trabajador
+ */
WHERE Fecha >= yesterday
AND Fecha <= maxDate AND T.Factura Is NULL
AND IFNULL(tls.alertLevel,0) < 3
@@ -33637,7 +33990,7 @@ BEGIN
IF (SELECT COUNT(*) FROM ticketRange) THEN
-
+ -- Generamos varias auxiliares (ya podian los de mysql haber solucionado esto)
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
CREATE TEMPORARY TABLE tmp.client_list
@@ -33651,7 +34004,7 @@ BEGIN
ENGINE = MEMORY
SELECT Id_Cliente FROM tmp.client_list;
-
+ -- usar ticket_total crear ticket_tmp(ticket_id)
DROP TEMPORARY TABLE IF EXISTS ticket_tmp;
CREATE TEMPORARY TABLE `ticket_tmp`
ENGINE = MEMORY
@@ -33662,7 +34015,7 @@ BEGIN
CALL ticket_total();
-
+ -- Generamos otra tabla temporal con los Tickets_iva
DROP TEMPORARY TABLE IF EXISTS tt3;
CREATE TEMPORARY TABLE tt3
@@ -33671,7 +34024,7 @@ BEGIN
JOIN ticketRange tr ON tr.Id_Ticket = tt.ticket_id;
-
+ -- Generamos la lista de tickets y sus datos
DROP TEMPORARY TABLE IF EXISTS Radartest;
@@ -33680,15 +34033,15 @@ BEGIN
SELECT IF(C.Id_Trabajador = worker, 1, 0) as Propio,
Credito,
Riesgo,
-
+ -- Greuge,
T.Id_Ticket,
T.warehouse_id as wh,
T.Fecha,
T.Alias,
-
+ -- T.Vista,
REPEAT(' ',50) as problem,
T.Agencia Tipo,
-
+ -- C.Id_Trabajador,
T.workerId AS Id_Trabajador,
T.Solucion,
T.Localizacion,
@@ -33712,7 +34065,7 @@ BEGIN
0 AS inacabable
-
+ -- (-1 < ifnull(order_id,-1)) as isbionic
FROM Tickets T
LEFT JOIN vn.ticketState ts on ts.ticket = T.Id_Ticket
@@ -33720,11 +34073,11 @@ BEGIN
INNER JOIN tt3 ON tt3.ticket_id = T.Id_Ticket
-
+ -- LEFT JOIN (SELECT DISTINCT 1 as order_id, Id_Ticket FROM order_Tickets) o on o.Id_Ticket = T.Id_Ticket
INNER JOIN Agencias A ON A.Id_Agencia = T.Id_Agencia
-
+ -- WHERE T.Etiquetasemitidas = FALSE
GROUP BY T.Id_Ticket
) AS T ON T.Id_Cliente = C.Id_Cliente
@@ -33754,7 +34107,7 @@ BEGIN
) AS Peligros ON Peligros.Id_Cliente = C.Id_Cliente
;
-
+ -- Actualizamos el Riesgo con los tickets futuros
set @cliente:= 0;
SET @riesgo := 0;
@@ -33824,14 +34177,13 @@ BEGIN
SET dateStart = TIMESTAMPADD(MONTH, -2, CURDATE());
SELECT TIMESTAMPADD(DAY, -1, today) INTO yesterday;
-
+ -- lo quitamos despues de campañaA
SELECT TIMESTAMP(TIMESTAMPADD(DAY, scopeDays, yesterday),'23:59:59') INTO maxDate;
-
-
+ -- SELECT TIMESTAMP(TIMESTAMPADD(DAY, 14, yesterday),'23:59:59') INTO maxDate;
+ -- Creamos una tabla con los Comerciales de los que se mostraran los tickets
CALL subordinate(worker,TRUE);
-
-
+ -- Se genera una tabla con los tickets representados
DROP TEMPORARY TABLE IF EXISTS ticketRange;
CREATE TEMPORARY TABLE ticketRange
@@ -33869,11 +34221,31 @@ BEGIN
AND datEND >= yesterday
AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART)
AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND)
- AND IFNULL(tls.alertLevel,0) < 3;
-
+ AND IFNULL(tls.alertLevel,0) < 3
+
+ UNION DISTINCT
+
+ SELECT Id_Ticket, C.Id_Cliente, C.Id_Trabajador
+ FROM Clientes C
+ INNER JOIN Tickets T USING(Id_Cliente)
+ LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket
+ INNER JOIN workerTeamCollegues w ON w.collegueId = C.Id_Trabajador
+ /*
+ (SELECT Id_Trabajador
+ FROM Trabajadores t
+ JOIN account.user u ON u.id = t.user_id
+ JOIN workerTeam w on w.user = u.id
+ JOIN (SELECT team FROM workerTeam wt JOIN Trabajadores tr on tr.user_id = wt.user WHERE Id_Trabajador = worker) sub on sub.team = w.team
+ ) sub2 ON sub2.Id_Trabajador = C.Id_Trabajador
+ */
+ WHERE Fecha >= yesterday
+ AND Fecha <= maxDate AND T.Factura Is NULL
+ AND IFNULL(tls.alertLevel,0) < 3
+ AND w.workerId = worker;
+
IF (SELECT COUNT(*) FROM ticketRange) THEN
-
+ -- Generamos varias auxiliares (ya podian los de mysql haber solucionado esto)
DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
CREATE TEMPORARY TABLE tmp.client_list
@@ -33887,7 +34259,7 @@ BEGIN
ENGINE = MEMORY
SELECT Id_Cliente FROM tmp.client_list;
-
+ -- usar ticket_total crear ticket_tmp(ticket_id)
DROP TEMPORARY TABLE IF EXISTS ticket_tmp;
CREATE TEMPORARY TABLE `ticket_tmp`
ENGINE = MEMORY
@@ -33896,10 +34268,9 @@ BEGIN
WHERE Fecha BETWEEN dateStart AND maxDate
AND Factura Is NULL;
- CALL ticket_total();
-
-
+ CALL ticket_total();
+ -- Generamos otra tabla temporal con los Tickets_iva
DROP TEMPORARY TABLE IF EXISTS tt3;
CREATE TEMPORARY TABLE tt3
@@ -33908,92 +34279,45 @@ BEGIN
JOIN ticketRange tr ON tr.Id_Ticket = tt.ticket_id;
-
+ -- Generamos la lista de tickets y sus datos
DROP TEMPORARY TABLE IF EXISTS Radartest;
CREATE TEMPORARY TABLE Radartest
-
- SELECT IF(C.Id_Trabajador = worker, 1, 0) as Propio,
+ (INDEX (Id_Ticket))
+ ENGINE = MEMORY
+ SELECT IF(c.Id_Trabajador = worker, 1, 0) as Propio,
Credito,
- Riesgo,
-
- T.Id_Ticket,
- T.warehouse_id as wh,
- T.Fecha,
- T.Alias,
-
+ 0 Riesgo,
+ -- Greuge,
+ t.Id_Ticket,
+ t.warehouse_id as wh,
+ t.Fecha,
+ t.Alias,
+ -- T.Vista,
REPEAT(' ',50) as problem,
- T.Agencia Tipo,
-
- T.workerId AS Id_Trabajador,
- T.Solucion,
- T.Localizacion,
- IFNULL(state,'LIBRE') as Estado,
- alertLevel,
- Date(T.Fecha) as Fecha_Simple,
- T.Importe,
- C.Descuento,
- C.calidad,
- C.Id_Cliente,
+ a.Agencia Tipo,
+ tt3.Id_Trabajador,
+ t.Solucion,
+ t.Localizacion,
+ IFNULL(s.`name`,'LIBRE') as Estado,
+ ts.alertLevel,
+ Date(t.Fecha) as Fecha_Simple,
+ tt3.total as Importe,
+ c.Descuento,
+ c.calidad,
+ c.Id_Cliente,
p.`name` provincia
- FROM Clientes C
- INNER JOIN
-
- (
-
- SELECT T.* , A.Vista, A.Agencia, s.`name` as state, alertLevel, tt3.Id_Trabajador AS workerId,
-
- tt3.total as Importe,
-
- 0 AS inacabable
-
-
-
- FROM Tickets T
- LEFT JOIN vn.ticketState ts on ts.ticket = T.Id_Ticket
- LEFT JOIN vn2008.state s on s.id = ts.state
-
- INNER JOIN tt3 ON tt3.ticket_id = T.Id_Ticket
-
-
-
- INNER JOIN Agencias A ON A.Id_Agencia = T.Id_Agencia
-
-
- GROUP BY T.Id_Ticket
-
- ) AS T ON T.Id_Cliente = C.Id_Cliente
-
- LEFT JOIN Consignatarios co ON co.Id_Consigna = T.Id_Consigna
- LEFT JOIN province p ON p.province_id = co.province_id
-
- LEFT JOIN
-
- (
-
- SELECT TOTAL.Id_Cliente, ROUND(SUM(amount),2) as Riesgo FROM
-
- (SELECT cl.Id_Cliente, amount FROM bi.customer_risk cr
- INNER JOIN tmp.client_list cl ON cr.customer_id = cl.Id_Cliente
-
- UNION ALL
-
- SELECT t.Id_Cliente, tt.total FROM ticket_total tt
- INNER JOIN Tickets t ON t.Id_Ticket = tt.ticket_id
- INNER JOIN cr5 C ON C.Id_Cliente = t.Id_Cliente
- WHERE t.Fecha BETWEEN dateStart AND maxDate
- AND t.Factura is null
-
- ) as TOTAL GROUP BY TOTAL.Id_Cliente
-
-
- ) AS Peligros ON Peligros.Id_Cliente = C.Id_Cliente
-
-
- ;
-
-
+ FROM tt3
+ JOIN Tickets t ON t.Id_Ticket = tt3.ticket_id
+ JOIN Clientes c ON c.Id_Cliente = t.Id_Cliente
+ LEFT JOIN vn.ticketState ts on ts.ticket = tt3.ticket_id
+ LEFT JOIN vn2008.state s on s.id = ts.state
+ JOIN Agencias a ON a.Id_Agencia = t.Id_Agencia
+ LEFT JOIN Consignatarios co ON co.Id_Consigna = t.Id_Consigna
+ LEFT JOIN province p ON p.province_id = co.province_id;
+
+ -- Actualizamos el Riesgo con los tickets futuros
set @cliente:= 0;
SET @riesgo := 0;
@@ -34010,7 +34334,7 @@ BEGIN
CALL prepare_client_list();
CALL production_buffer_problems;
-
+
UPDATE Radartest r
JOIN (
SELECT Id_Ticket, GROUP_CONCAT(problem) problem
@@ -34103,7 +34427,12 @@ DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `radar_negativos`(IN v_force BOOLEAN, IN intRANGE INT)
BEGIN
-
+/**
+ * Calcula una tabla con el máximo negativo visible para cada producto y almacen
+ *
+ * @param v_force Fuerza el recalculo del stock
+ * @param intRANGE Numero de dias a considerar
+**/
CALL `cache`.stock_refresh(v_force);
SET @aid = NULL;
@@ -34132,6 +34461,56 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS article_minacum;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `rateView` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `rateView`()
+BEGIN
+
+ SELECT
+ t.year as año,
+ t.month as mes,
+ pagos.dolares,
+ pagos.cambioPractico,
+ CAST(sum(divisa) / sum(bi) as DECIMAL(5,4)) as cambioTeorico,
+ pagos.cambioOficial
+ FROM recibida r
+ JOIN time t ON t.date = r.fecha
+ JOIN recibida_iva ri ON r.id = ri.recibida_id
+ JOIN
+ (
+ SELECT
+ t.year as Año,
+ t.month as Mes,
+ cast(sum(divisa) as DECIMAL(10,2)) as dolares,
+ cast(sum(divisa) / sum(importe) as DECIMAL(5,4)) as cambioPractico,
+ cast(rr.rate * 0.998 as DECIMAL(5,4)) as cambioOficial
+ FROM pago p
+ JOIN time t ON t.date = p.fecha
+ JOIN reference_rate rr ON rr.date = p.fecha AND moneda_id = 2
+ WHERE divisa
+ AND fecha >= '2015-01-11'
+ GROUP BY t.year, t.month
+ ) pagos ON t.year = pagos.Año AND t.month = pagos.Mes
+ WHERE moneda_id = 2
+ AND fecha >= '2015-01-01'
+ AND divisa
+ AND bi
+ GROUP BY t.year, t.month;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -34246,6 +34625,77 @@ DELIMITER ;
/*!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 `recibidaIvaDivisaUpdate` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `recibidaIvaDivisaUpdate`(IN vRecibidaId INT)
+BEGIN
+
+/* Actualiza el valor de la divisa en función del cambio oficial para el dia de expedicion
+*/
+ UPDATE recibida_iva
+ SET bi = NULL
+ WHERE recibida_id = vRecibidaId
+ AND divisa IS NOT NULL;
+
+ UPDATE recibida_iva ri
+ JOIN recibida r ON r.id = ri.recibida_id
+ JOIN reference_rate rr ON rr.date = r.fecha AND r.moneda_id = rr.moneda_id
+ SET ri.bi = ri.divisa / rr.rate
+ WHERE r.id = vRecibidaId;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `recibidaIvaInsert` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `recibidaIvaInsert`(IN vId INT)
+BEGIN
+
+ INSERT INTO recibida_iva(recibida_id, iva_id, bi,gastos_id,divisa)
+ SELECT r.id,
+ CASE
+ WHEN p.cuenta LIKE '___4______' THEN 71
+ WHEN p.cuenta LIKE '___1______' THEN 36
+ WHEN p.cuenta LIKE '___3______' THEN 63
+ END,
+ SUM(Costefijo * Cantidad) / IFNULL(rr.rate,1),
+ 6003000000,
+ IF(r.moneda_id = 1,NULL,SUM(Costefijo * Cantidad ))
+ FROM recibida r
+ JOIN recibida_entrada re ON r.id = re.recibida_id
+ JOIN Entradas e ON e.Id_Entrada = re.Id_Entrada
+ JOIN Proveedores p ON p.Id_Proveedor = e.Id_Proveedor
+ JOIN Compres c ON c.Id_Entrada = e.Id_Entrada
+ JOIN reference_rate rr ON rr.moneda_id = r.moneda_id AND rr.date = r.fecha
+ LEFT JOIN recibida_iva ri ON re.recibida_id=ri.recibida_id
+ WHERE re.awb_recibida =vId AND ri.bi IS NULL
+ GROUP BY e.Id_Entrada, re.awb_recibida;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `recibida_select` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
@@ -34288,11 +34738,11 @@ BEGIN
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)
@@ -34319,7 +34769,7 @@ SELECT a,NEW_fecha,subcta,contra,concepto,eurodebe,eurohaber,baseeuro,NEW_serie,
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 (
@@ -34340,14 +34790,14 @@ SELECT a,NEW_fecha,subcta,contra,concepto,eurodebe,eurohaber,baseeuro,NEW_serie,
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(pa2.CEE < 2 AND ri2.gastos_id IS NULL,'','*') AUXILIAR
-
+ IF(pa2.CEE < 2 AND ri2.gastos_id IS NULL,'','*') AUXILIAR -- JGF 30-01-2014 IF(NOT ((p.pais_id <> p2.pais_id) AND pa.CEE < 2),'*','') -- ANTES '' AUXILIAR JGF < 30-01-2014
+-- AND ri.gastos_id LIKE '4751______'
FROM recibida r
INNER JOIN recibida_iva ri ON ri.recibida_id = r.id
@@ -34370,7 +34820,7 @@ SELECT a,NEW_fecha,subcta,contra,concepto,eurodebe,eurohaber,baseeuro,NEW_serie,
WHERE r.id = NEW_id AND g.conbase AND link GROUP BY iva
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,
@@ -34390,7 +34840,7 @@ SELECT a,NEW_fecha,subcta,contra,concepto,eurodebe,eurohaber,baseeuro,NEW_serie,
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 ,4),10,gastos_id),gastos_id),cta_proveed ,
if(gastos_id LIKE '4751______',NULL,ABS(ROUND(SUM(bi),2))) ,
@@ -34412,7 +34862,7 @@ SELECT a,NEW_fecha,subcta,contra,concepto,eurodebe,eurohaber,baseeuro,NEW_serie,
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',dblRefRate,1)* (re.percentage / 100),2),NULL ,IF( @a:=@a+1 ,NULL,NULL) ,0, 0 l340,0 LRECT349,' ' TIPOOPE,'' AUXILIAR,r.serie
@@ -34435,13 +34885,13 @@ SELECT a,NEW_fecha,subcta,contra,concepto,eurodebe,eurohaber,baseeuro,NEW_serie,
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',dblRefRate,1)* (re.percentage / 100),2) eurohaber,
NULL baseeuro,0 iva, 0 l340,0 LRECT349,' ' TIPOOPE,'' AUXILIAR,r.serie
-
+ -- antes sols iva
FROM recibida_entrada re
INNER JOIN recibida_iva ri ON re.recibida_id = ri.recibida_id
@@ -34458,7 +34908,7 @@ UNION ALL
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,
@@ -34486,7 +34936,7 @@ UNION ALL
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,
@@ -34516,7 +34966,7 @@ UNION ALL
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),
(IF(@cont<@a,
@@ -34569,7 +35019,7 @@ UNION ALL
) sub2 USING(Codintrastat)
-
+ -- JOIN recibida_intrastat ri ON ar.awb_recibida = ri.recibida_id and ri.Codintrastat = sub1.Codintrastat
JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada
@@ -34588,12 +35038,12 @@ UNION ALL
JOIN Proveedores p2 ON p2.Id_Proveedor = r.empresa_id
WHERE re.awb_recibida = NEW_id AND re.percentage AND IF(cta_proveed like '___0______',ri.gastos_id = 5660000002,TRUE)
-
+ -- canvie el cta_proveed like '___1______' per cero cuidao en les van de put
GROUP BY p.Id_Proveedor
-
+ -- antes GROUP BY a.Codintrastat,Id_Entrada
) t3)t4;
@@ -34645,11 +35095,11 @@ BEGIN
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)
@@ -34687,7 +35137,7 @@ SELECT CONCAT('COMPRA FRA ',p.Proveedor) concepto,ic.codigo subcta,p.Cuenta,ic.i
left JOIN awb aw ON ar.awb_id = aw.id
- WHERE ar.recibida_id = NEW_id AND re.percentage
+ WHERE ar.recibida_id = NEW_id AND re.percentage/*JGF 27/08/14*/
GROUP BY a.Codintrastat
@@ -34703,7 +35153,7 @@ SELECT CONCAT('COMPRA FRA ',p.Proveedor) concepto,ic.codigo subcta,p.Cuenta,ic.i
) sub2 USING(Codintrastat)
-
+ -- JOIN recibida_intrastat ri ON ar.awb_recibida = ri.recibida_id and ri.Codintrastat = sub1.Codintrastat
left JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada
@@ -34721,8 +35171,8 @@ SELECT CONCAT('COMPRA FRA ',p.Proveedor) concepto,ic.codigo subcta,p.Cuenta,ic.i
left JOIN Proveedores p2 ON p2.Id_Proveedor = r.empresa_id
- WHERE re.awb_recibida = NEW_id AND re.percentage AND IF(cta_proveed like '___0______',ri.gastos_id = 5660000002,TRUE)
-
+ WHERE re.awb_recibida = NEW_id AND re.percentage/*JGF 27/08/14*/ AND IF(cta_proveed like '___0______',ri.gastos_id = 5660000002,TRUE)
+ -- canvie el cta_proveed like '___1______' per cero cuidao en les van de put
GROUP BY p.Id_Proveedor;
@@ -34742,7 +35192,7 @@ DELIMITER ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = '' */ ;
+/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `recobro_credito`()
BEGIN
@@ -34778,7 +35228,12 @@ JOIN
clientes_credit using(Id_Cliente)
SET Clientes.Credito = newCredit;
-
+/*
+Lo hace el trigger JGF 2017/10/18
+INSERT INTO credit(Id_Cliente, amount, Id_Trabajador)
+SELECT Id_Cliente, newCredit, 20
+FROM clientes_credit;
+*/
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -34847,7 +35302,7 @@ BEGIN
INSERT INTO ticket_invoice (ticket_id) SELECT Id_Ticket FROM Tickets t
WHERE Factura = Id_Factura;
-
+ -- Eliminem els tickets que no han de ser facturats
IF (SELECT COUNT(*) FROM ticket_invoice) > 0
THEN
@@ -35032,7 +35487,13 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `risk`(v_date DATE, v_customer INT)
BEGIN
-
+/**
+ * Calcula el riesgo para uno o todos los clientes activos.
+ *
+ * @param v_date Fecha maxima de los registros
+ * @param v_customer Cliente a mostrar su riesgo, %NULL para todos
+ * @return table tmp.risk
+ */
DECLARE v_date_start DATETIME DEFAULT TIMESTAMPADD(MONTH, -33, CURDATE());
DECLARE v_date_end DATETIME;
@@ -35048,8 +35509,6 @@ BEGIN
AND t.Fecha BETWEEN v_date_start AND v_date_end;
CALL ticket_total();
-
-
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
CREATE TEMPORARY TABLE tmp.risk
@@ -35073,12 +35532,12 @@ BEGIN
JOIN Tickets t ON tt.ticket_id = t.Id_Ticket
GROUP BY t.Id_Cliente
UNION ALL
- SELECT t.customer_id, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
- FROM hedera.tpv_transaction t
- WHERE (v_customer IS NULL OR t.customer_id = v_customer)
- AND t.receipt_id IS NULL
+ SELECT t.clientFk customer_id, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
+ FROM hedera.tpvTransaction t
+ WHERE (v_customer IS NULL OR t.clientFk = v_customer)
+ AND t.receiptFk IS NULL
AND t.status = 'ok'
- GROUP BY t.customer_id
+ GROUP BY t.clientFk
) t ON c.Id_Cliente = t.customer_id
WHERE c.activo != FALSE
GROUP BY c.Id_Cliente;
@@ -35104,45 +35563,45 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `risk_vs_client_list`(maxRiskDate DATE)
BEGIN
-
-
-
- DECLARE startingDate DATETIME DEFAULT TIMESTAMPADD(DAY, - DAYOFMONTH(CURDATE()) - 5, CURDATE());
+/**
+ * Calcula el riesgo para los clientes activos de la tabla temporal tmp.client_list
+ *
+ * @param maxRiskDate Fecha maxima de los registros
+ * @return table tmp.risk
+ */
+ DECLARE startingDate DATETIME DEFAULT TIMESTAMPADD(DAY, - DAYOFMONTH(CURDATE()) - 30, CURDATE());
DECLARE endingDate DATETIME;
- DECLARE MAX_RISK_ALLOWED INT DEFAULT 200;
-
- SET maxRiskDate = IFNULL(maxRiskDate, CURDATE());
- SET endingDate = TIMESTAMP(maxRiskDate, '23:59:59');
-
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.client_list_2;
- CREATE TEMPORARY TABLE tmp.client_list_2
- (PRIMARY KEY (Id_Cliente))
- ENGINE = MEMORY
- SELECT *
- FROM tmp.client_list;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.client_list_3;
- CREATE TEMPORARY TABLE tmp.client_list_3
- (PRIMARY KEY (Id_Cliente))
- ENGINE = MEMORY
- SELECT *
- FROM tmp.client_list;
+ DECLARE MAX_RISK_ALLOWED INT DEFAULT 200;
+
+ SET maxRiskDate = IFNULL(maxRiskDate, CURDATE());
+ SET endingDate = TIMESTAMP(maxRiskDate, '23:59:59');
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.client_list_2;
+ CREATE TEMPORARY TABLE tmp.client_list_2
+ (PRIMARY KEY (Id_Cliente))
+ ENGINE = MEMORY
+ SELECT *
+ FROM tmp.client_list;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.client_list_3;
+ CREATE TEMPORARY TABLE tmp.client_list_3
+ (PRIMARY KEY (Id_Cliente))
+ ENGINE = MEMORY
+ SELECT *
+ FROM tmp.client_list;
-
DROP TEMPORARY TABLE IF EXISTS tmp.tickets_sin_facturar;
CREATE TEMPORARY TABLE tmp.tickets_sin_facturar
- (PRIMARY KEY (Id_Cliente))
+ (PRIMARY KEY (Id_Cliente))
ENGINE = MEMORY
- SELECT t.Id_Cliente, floor(IF(VIES, 1, 1.1) * sum(Cantidad * Preu * (100 - Descuento) / 100)) as total
- FROM Movimientos m
- JOIN Tickets t on m.Id_Ticket = t.Id_Ticket
- JOIN tmp.client_list c on c.Id_Cliente = t.Id_Cliente
- JOIN vn.client cl ON cl.id = t.Id_Cliente
- WHERE Factura IS NULL
- AND Fecha BETWEEN startingDate AND endingDate
- GROUP BY t.Id_Cliente;
+ SELECT t.Id_Cliente, floor(IF(cl.isVies, 1, 1.1) * sum(Cantidad * Preu * (100 - Descuento) / 100)) as total
+ FROM Movimientos m
+ JOIN Tickets t on m.Id_Ticket = t.Id_Ticket
+ JOIN tmp.client_list c on c.Id_Cliente = t.Id_Cliente
+ JOIN vn.client cl ON cl.id = t.Id_Cliente
+ WHERE Factura IS NULL
+ AND Fecha BETWEEN startingDate AND endingDate
+ GROUP BY t.Id_Cliente;
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
CREATE TEMPORARY TABLE tmp.risk
@@ -35150,137 +35609,38 @@ BEGIN
ENGINE = MEMORY
SELECT Id_Cliente, SUM(amount) risk, sum(saldo) saldo
FROM Clientes c
- JOIN (
- SELECT customer_id, SUM(amount) amount,SUM(amount) saldo
- FROM bi.customer_risk
- JOIN tmp.client_list on Id_Cliente = customer_id
- GROUP BY customer_id
- UNION ALL
- SELECT Id_Cliente, SUM(Entregado),SUM(Entregado)
- FROM Recibos
- JOIN tmp.client_list_2 using(Id_Cliente)
- WHERE Fechacobro > endingDate
- GROUP BY Id_Cliente
- UNION ALL
- SELECT Id_Cliente, total,0
- FROM tmp.tickets_sin_facturar
- UNION ALL
- SELECT t.customer_id, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2)), CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
- FROM hedera.tpv_transaction t
- JOIN tmp.client_list_3 on Id_Cliente = customer_id
- WHERE t.receipt_id IS NULL
+ JOIN (
+ SELECT customer_id, SUM(amount) amount,SUM(amount) saldo
+ FROM bi.customer_risk
+ JOIN tmp.client_list on Id_Cliente = customer_id
+ GROUP BY customer_id
+ UNION ALL
+ SELECT Id_Cliente, SUM(Entregado),SUM(Entregado)
+ FROM Recibos
+ JOIN tmp.client_list_2 using(Id_Cliente)
+ WHERE Fechacobro > endingDate
+ GROUP BY Id_Cliente
+ UNION ALL
+ SELECT Id_Cliente, total,0
+ FROM tmp.tickets_sin_facturar
+ UNION ALL
+ SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2)), CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
+ FROM hedera.tpvTransaction t
+ JOIN tmp.client_list_3 on Id_Cliente = t.clientFk
+ WHERE t.receiptFk IS NULL
AND t.status = 'ok'
- GROUP BY t.customer_id
- ) t ON c.Id_Cliente = t.customer_id
+ GROUP BY t.clientFk
+ ) t ON c.Id_Cliente = t.customer_id
WHERE c.activo != FALSE
GROUP BY c.Id_Cliente;
-
+
DELETE r.*
- FROM tmp.risk r
- JOIN vn2008.Clientes c on c.Id_Cliente = r.Id_Cliente
- JOIN vn2008.pay_met pm on pm.id = c.pay_met_id
- WHERE IFNULL(r.saldo,0) < 10
- AND r.risk <= MAX_RISK_ALLOWED
- AND pm.`name` = 'TARJETA';
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `risk_vs_client_listbeta` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `risk_vs_client_listbeta`(maxRiskDate DATE)
-BEGIN
-
-
-
- DECLARE startingDate DATETIME DEFAULT TIMESTAMPADD(DAY, - DAYOFMONTH(CURDATE()) - 5, CURDATE());
- DECLARE endingDate DATETIME;
- DECLARE MAX_RISK_ALLOWED INT DEFAULT 200;
-
- SET maxRiskDate = IFNULL(maxRiskDate, CURDATE());
- SET endingDate = TIMESTAMP(maxRiskDate, '23:59:59');
-
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.client_list_2;
- CREATE TEMPORARY TABLE tmp.client_list_2
- (PRIMARY KEY (Id_Cliente))
- ENGINE = MEMORY
- SELECT *
- FROM tmp.client_list;
- select 1;
- DROP TEMPORARY TABLE IF EXISTS tmp.client_list_3;
- CREATE TEMPORARY TABLE tmp.client_list_3
- (PRIMARY KEY (Id_Cliente))
- ENGINE = MEMORY
- SELECT *
- FROM tmp.client_list;
-
- select 2;
- DROP TEMPORARY TABLE IF EXISTS tmp.tickets_sin_facturar;
- CREATE TEMPORARY TABLE tmp.tickets_sin_facturar
- (PRIMARY KEY (Id_Cliente))
- ENGINE = MEMORY
- SELECT t.Id_Cliente, Cantidad as total
- FROM Movimientos m
- JOIN Tickets t on m.Id_Ticket = t.Id_Ticket
- JOIN tmp.client_list c on c.Id_Cliente = t.Id_Cliente
- WHERE Factura IS NULL
- AND Fecha BETWEEN startingDate AND endingDate
- GROUP BY t.Id_Cliente;
-select 3;
- DROP TEMPORARY TABLE IF EXISTS tmp.risk;
- CREATE TEMPORARY TABLE tmp.risk
- (PRIMARY KEY (Id_Cliente))
- ENGINE = MEMORY
- SELECT Id_Cliente, SUM(amount) risk, sum(saldo) saldo
- FROM Clientes c
- JOIN (
- SELECT customer_id, SUM(amount) amount,SUM(amount) saldo
- FROM bi.customer_risk
- JOIN tmp.client_list on Id_Cliente = customer_id
- GROUP BY customer_id
- UNION ALL
- SELECT Id_Cliente, SUM(Entregado),SUM(Entregado)
- FROM Recibos
- JOIN tmp.client_list_2 using(Id_Cliente)
- WHERE Fechacobro > endingDate
- GROUP BY Id_Cliente
- UNION ALL
- SELECT Id_Cliente, total,0
- FROM tmp.tickets_sin_facturar
- UNION ALL
- SELECT t.customer_id, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2)), CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
- FROM hedera.tpv_transaction t
- JOIN tmp.client_list_3 on Id_Cliente = customer_id
- WHERE t.receipt_id IS NULL
- AND t.status = 'ok'
- GROUP BY t.customer_id
- ) t ON c.Id_Cliente = t.customer_id
- WHERE c.activo != FALSE
- GROUP BY c.Id_Cliente;
-select 4;
- DELETE r.*
- FROM tmp.risk r
- JOIN vn2008.Clientes c on c.Id_Cliente = r.Id_Cliente
- JOIN vn2008.pay_met pm on pm.id = c.pay_met_id
- WHERE IFNULL(r.saldo,0) < 10
- AND r.risk <= MAX_RISK_ALLOWED
- AND pm.`name` = 'TARJETA';
-select 5;
-
-
+ FROM tmp.risk r
+ JOIN vn2008.Clientes c on c.Id_Cliente = r.Id_Cliente
+ JOIN vn2008.pay_met pm on pm.id = c.pay_met_id
+ WHERE IFNULL(r.saldo,0) < 10
+ AND r.risk <= MAX_RISK_ALLOWED
+ AND pm.`name` = 'TARJETA';
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -35329,7 +35689,7 @@ Select cast(sum(Cantidad * vn2008.cm3_unidad(buy_id)) / 1000000 as decimal(5,1))
where t.Fecha between TIMESTAMPADD(DAY,-1,datSTART) and TIMESTAMPADD(DAY,-1,datEND)
AND wp.agency_id IS NULL
group by Agencia, Almacen, Fecha
-
+ -- JGF 2016-05-05
UNION ALL
Select cast(sum(Cantidad * vn2008.cm3_unidad(Id_Compra)) / 1000000 as decimal(5,1)) as m3 ,a.Agencia, w.name as Almacen,
timestampadd(day,1,t.shipment) Fecha
@@ -35341,6 +35701,103 @@ UNION ALL
where t.shipment between TIMESTAMPADD(DAY,-1,datSTART) and TIMESTAMPADD(DAY,-1,datEND)
group by a.Agencia, Almacen, 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 `Rutas_monitor_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 `Rutas_monitor_update`(vDate DATE)
+BEGIN
+
+DECLARE vDateEND DATETIME;
+
+SET vDateEND = util.dayend(vDate);
+SET vDate = TIMESTAMPADD(DAY,-1,vDate);
+
+INSERT IGNORE INTO Rutas_monitor(Id_Ruta)
+ SELECT DISTINCT Id_Ruta
+ FROM Tickets
+ WHERE Fecha BETWEEN vDate AND vDateEND
+ AND Id_Ruta;
+
+UPDATE Rutas_monitor rm
+JOIN Rutas r ON r.Id_Ruta = rm.Id_Ruta
+JOIN Agencias a ON a.Id_Agencia = r.Id_Agencia
+SET rm.`name` = a.Agencia, rm.fecha = r.Fecha,
+ rm.pedidosLibres = 0,
+ rm.pedidosProduccion = 0,
+ rm.pedidosEncajados = 0;
+
+UPDATE Rutas_monitor rm
+JOIN (
+ SELECT Id_Ruta, max(landing) as landing
+ FROM Tickets t
+ WHERE t.Fecha BETWEEN vDate AND vDateEND
+ GROUP BY Id_Ruta
+ ) t ON t.Id_Ruta = rm.Id_Ruta
+SET rm.Fecha = t.landing;
+
+UPDATE Rutas_monitor rm
+JOIN
+( SELECT Id_Ruta, count(*) AS pedidosLibres
+ FROM Tickets t
+ JOIN Tickets_state ts ON t.Id_Ticket = ts.Id_Ticket
+ JOIN vncontrol.inter i ON i.inter_id = ts.inter_id
+ JOIN state s ON i.state_id = s.id AND s.alert_level = 0
+ WHERE t.Fecha BETWEEN vDate AND vDateEND
+ AND Id_Ruta
+ GROUP BY Id_Ruta
+) t ON t.Id_Ruta = rm.Id_Ruta
+SET rm.pedidosLibres = t.pedidosLibres;
+
+UPDATE Rutas_monitor rm
+JOIN
+( SELECT Id_Ruta, count(*) AS pedidosProduccion
+ FROM Tickets t
+ JOIN Tickets_state ts ON t.Id_Ticket = ts.Id_Ticket
+ JOIN vncontrol.inter i ON i.inter_id = ts.inter_id
+ JOIN state s ON i.state_id = s.id AND s.alert_level = 1
+ WHERE t.Fecha BETWEEN vDate AND vDateEND
+ AND Id_Ruta
+ GROUP BY Id_Ruta
+) t ON t.Id_Ruta = rm.Id_Ruta
+SET rm.pedidosProduccion = t.pedidosProduccion;
+
+UPDATE Rutas_monitor rm
+JOIN
+( SELECT Id_Ruta, count(*) AS pedidosEncajados
+ FROM Tickets t
+ JOIN Tickets_state ts ON t.Id_Ticket = ts.Id_Ticket
+ JOIN vncontrol.inter i ON i.inter_id = ts.inter_id
+ JOIN state s ON i.state_id = s.id AND s.alert_level >= 2
+ WHERE t.Fecha BETWEEN vDate AND vDateEND
+ AND Id_Ruta
+ GROUP BY Id_Ruta
+) t ON t.Id_Ruta = rm.Id_Ruta
+SET rm.pedidosEncajados = t.pedidosEncajados;
+
+UPDATE Rutas_monitor rm
+JOIN
+( SELECT Id_Ruta, count(*) AS bultos
+ FROM Tickets t
+ JOIN expeditions e ON e.ticket_id = t.Id_Ticket
+ WHERE t.Fecha BETWEEN vDate AND vDateEND
+ AND Id_Ruta
+ GROUP BY Id_Ruta
+) t ON t.Id_Ruta = rm.Id_Ruta
+SET rm.bultos = t.bultos;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -35393,7 +35850,7 @@ create table bi.saldos_bancos
union all
Select Id_Banco, NULL, importe, greatest(fecha,TIMESTAMPADD(DAY,1,CURDATE())),empresa_id
from pago
- where conciliado = FALSE
+ where conciliado = FALSE /*fecha between CURDATE() and datEND*/
union all
Select Id_Banco, Entregado, NULL, greatest(Fechacobro,TIMESTAMPADD(DAY,1,CURDATE())),empresa_id
from Recibos
@@ -35469,11 +35926,11 @@ create table bi.saldos_bancos_pordia
union all
Select Id_Banco, NULL, importe, greatest(fecha,TIMESTAMPADD(DAY,1,CURDATE())),empresa_id
from pago
- where conciliado = FALSE
+ where conciliado = FALSE /*fecha between CURDATE() and datEND*/
union all
Select Id_Banco, Entregado, NULL, greatest(Fechacobro,TIMESTAMPADD(DAY,1,CURDATE())),empresa_id
from Recibos
- where conciliado = FALSE
+ where conciliado = FALSE -- Fechacobro between CURDATE() and datEND
union all
Select IFNULL(Id_Banco,9999), Importe, NULL, Fecha,empresa_id
from Saldos_Prevision
@@ -35512,7 +35969,7 @@ CREATE DEFINER=`root`@`%` PROCEDURE `scan_rutas_view`()
BEGIN
-
+/* muestra las rutas agrupadas de los ultimos tres dias, así como una lista de los tickets sin enrutar, agrpados por agencia y fecha*/
select Fecha, Id_Ruta, Matricula, sub.m3, CodigoTrabajador, Agencia, Bultos, w.name as Almacen
from
@@ -35663,7 +36120,7 @@ WHILE NOT done DO
SELECT LAST_INSERT_ID() INTO vNewTicket;
-
+ -- SELECT vMyTicket, vNewTicket; SET done = 1;
UPDATE Movimientos m
JOIN Articles a using(Id_Article)
JOIN Tipos tp using(tipo_id)
@@ -35753,7 +36210,7 @@ WHILE NOT done DO
SELECT LAST_INSERT_ID() INTO vNewTicket;
-
+ -- SELECT vMyTicket, vNewTicket; SET done = 1;
UPDATE Movimientos m
JOIN Compres c ON Id_Entrada IN (100461, 100929) AND c.Id_Article = m.Id_Article
SET Id_Ticket = vNewTicket
@@ -35847,7 +36304,7 @@ WHILE NOT done DO
SELECT LAST_INSERT_ID() INTO vNewTicket;
-
+ -- SELECT vMyTicket, vNewTicket; SET done = 1;
UPDATE Movimientos m
JOIN Articles a using(Id_Article)
JOIN Tipos tp using(tipo_id)
@@ -35967,7 +36424,7 @@ WHILE NOT done DO
SELECT LAST_INSERT_ID() INTO vNewTicket;
-
+ -- SELECT vMyTicket, vNewTicket; SET done = 1;
UPDATE Movimientos m
JOIN
(
@@ -36007,11 +36464,11 @@ 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 = latin1 */ ;
-/*!50003 SET character_set_results = latin1 */ ;
-/*!50003 SET collation_connection = latin1_swedish_ci */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!50003 SET character_set_results = utf8 */ ;
+/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = '' */ ;
+/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `sql_query`(IN v_sql TEXT)
BEGIN
@@ -36046,7 +36503,7 @@ BEGIN
FROM Trabajadores
WHERE Id_Trabajador = idWORKER;
- IF vCompanyId = 1381 THEN
+ IF vCompanyId = 1381 THEN -- ORNAMENTALES
DROP TABLE IF EXISTS subordinate;
CREATE TABLE subordinate
@@ -36058,7 +36515,26 @@ BEGIN
ELSE
+ /* PAK 23/05/2016
+ Guardia de domingos
+
+ Los domingos viene Fran a hacer de comercial y necesita ver todos los radares
+
+
+
+ IF dayofweek(curdate()) = 1 and idWORKER = 43 then -- Domingo y Fran Natek
+
+ DROP TABLE IF EXISTS subordinate;
+
+ CREATE TABLE subordinate
+ (INDEX (Id_Trabajador)) ENGINE = MEMORY
+ SELECT Id_Trabajador,TRUE visited,0 boss
+ FROM Trabajadores;
+
+
+ else
+ */
IF CasoBase THEN
SET @@max_sp_recursion_depth = 5 ;
@@ -36081,16 +36557,21 @@ BEGIN
END REPEAT;
END IF;
-
+ /*
+ end if;
+ */
END IF;
IF idWorker = 2 THEN
INSERT INTO subordinate(Id_Trabajador,visited,boss) VALUES (2,TRUE,2);
-
+ -- INSERT INTO subordinate(Id_Trabajador,visited,boss) VALUES (43,TRUE,2);
END IF;
-
+ /*
+ IF CasoBase THEN
+ SELECT * FROM subordinate;
+ END IF;*/
END ;;
DELIMITER ;
@@ -36118,7 +36599,7 @@ BEGIN
FROM Trabajadores
WHERE Id_Trabajador = idWORKER;
- IF vCompanyId = 1381 THEN
+ IF vCompanyId = 1381 THEN -- ORNAMENTALES
DROP TABLE IF EXISTS subordinate;
CREATE TABLE subordinate
@@ -36130,7 +36611,26 @@ BEGIN
ELSE
+ /* PAK 23/05/2016
+ Guardia de domingos
+
+ Los domingos viene Fran a hacer de comercial y necesita ver todos los radares
+
+
+
+ IF dayofweek(curdate()) = 1 and idWORKER = 43 then -- Domingo y Fran Natek
+
+ DROP TABLE IF EXISTS subordinate;
+
+ CREATE TABLE subordinate
+ (INDEX (Id_Trabajador)) ENGINE = MEMORY
+ SELECT Id_Trabajador,TRUE visited,0 boss
+ FROM Trabajadores;
+
+
+ else
+ */
IF CasoBase THEN
SET @@max_sp_recursion_depth = 5 ;
@@ -36153,7 +36653,9 @@ BEGIN
END REPEAT;
END IF;
-
+ /*
+ end if;
+ */
END IF;
@@ -36161,7 +36663,10 @@ BEGIN
INSERT INTO subordinate(Id_Trabajador) VALUES (2);
END IF;
-
+ /*
+ IF CasoBase THEN
+ SELECT * FROM subordinate;
+ END IF;*/
END ;;
DELIMITER ;
@@ -36229,7 +36734,7 @@ BEGIN
UPDATE Clientes
SET Credito = 0
- WHERE pay_met_id = 5
+ WHERE pay_met_id = 5 -- TARJETA
;
UPDATE credit
@@ -36258,7 +36763,7 @@ BEGIN
DECLARE datINI DATE;
DECLARE datFIN DATE;
-
+ -- Seleccionamos la fecha minima/maxima del periodo que vamos a consultar
SELECT MIN(`date`) INTO datINI FROM vn2008.`time` t WHERE t.period = period;
SELECT TIMESTAMP(MAX(`date`),'23:59:59') INTO datFIN FROM vn2008.`time` t WHERE t.period = period;
@@ -36306,7 +36811,7 @@ BEGIN
SELECT tipo_id INTO intTIPO FROM Articles WHERE Id_Article = idART;
-
+ -- Seleccionamos la fecha minima/maxima del periodo que vamos a consultar
SELECT MIN(`date`) INTO datINI FROM vn2008.`time` t WHERE t.period = period;
SELECT TIMESTAMP(MAX(`date`),'23:59:59') INTO datFIN FROM vn2008.`time` t WHERE t.period = period;
@@ -36361,8 +36866,14 @@ BEGIN
+-- Año 2014
+/*
+IF datSTART = '2013-12-31' THEN
+ SET datSTART = '2013-12-30' ;
+END IF;
+*/
SET datEND = TIMESTAMPADD(DAY,7,datSTART);
@@ -36577,7 +37088,7 @@ BEGIN
JOIN travel TR ON TR.id = E.travel_id
JOIN (SELECT Consignatario, Id_Consigna FROM Consignatarios WHERE Id_Cliente = IdCliente AND Predeterminada LIMIT 1) Consigna
WHERE Id_Entrada = IdEntrada;
-
+ -- JOIN Agencias AG ON AG.Id_Agencia = TR.agency_id
SELECT LAST_INSERT_ID() INTO idTICKET;
@@ -36615,7 +37126,7 @@ BEGIN
DECLARE done BIT DEFAULT 0;
DECLARE IdEntrada INT(10);
-
+-- Declaro el cursor para las entradas
DECLARE cursor_entradas CURSOR FOR
SELECT Id_Entrada
FROM Entradas E
@@ -36655,74 +37166,36 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `ticket_iva`(billing_date DATE)
+CREATE DEFINER=`root`@`%` PROCEDURE `ticket_iva`(vBillingDate DATE)
+ READS SQL DATA
BEGIN
+/**
+ * Calcula la base imponible, el IVA y el recargo de equivalencia para
+ * un conjunto de tickets.
+ *
+ * @deprecated Use procedure vn.ticketGetTax() instead
+ *
+ * @table ticket_tmp(ticket_id) Tabla con el listado de tickets
+ * @param billing_date Fecha de facturación
+ * @treturn ticket_iva
+ */
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
+ CREATE TEMPORARY TABLE tmp.ticket
+ (INDEX (ticketFk))
+ ENGINE = MEMORY
+ SELECT ticket_id ticketFk FROM ticket_tmp;
-
- DECLARE clean CONDITION FOR SQLSTATE 'HY000';
- DECLARE CONTINUE HANDLER FOR clean
- BEGIN
- DROP TEMPORARY TABLE IF EXISTS iva_group;
- DROP TEMPORARY TABLE IF EXISTS iva_tax;
- END;
-
- SIGNAL clean;
- DROP TEMPORARY TABLE IF EXISTS ticket_iva;
-
- SET billing_date = IFNULL(billing_date, CURDATE());
-
-
-
- CREATE TEMPORARY TABLE iva_group
- (INDEX idx USING HASH (Id_Pais, iva_group_id))
- ENGINE = MEMORY
- SELECT * FROM (
- SELECT Id_Pais, iva_group_id, c.tipo
- FROM iva_group_codigo g
- JOIN iva_codigo c ON g.iva_codigo_id = c.id
- JOIN iva_tipo t ON t.id = c.iva_tipo_id
- WHERE date <= billing_date
- ORDER BY date DESC
- ) t
- GROUP BY Id_Pais, iva_group_id;
-
-
-
- CREATE TEMPORARY TABLE iva_tax
- (INDEX idx USING HASH (Id_Pais, tipo))
- ENGINE = MEMORY
- SELECT * FROM (
- SELECT Id_Pais, tipo, iva * 0.01 AS iva, recargo * 0.01 AS re
- FROM iva_codigo
- JOIN iva_tipo t ON t.id = iva_tipo_id
- WHERE Fecha <= billing_date
- ORDER BY fecha DESC, recargo DESC
- ) t
- GROUP BY Id_Pais, tipo;
-
-
+ CALL vn.ticketGetTax (vBillingDate);
CREATE TEMPORARY TABLE ticket_iva
- (INDEX idx USING HASH (ticket_id))
- ENGINE = MEMORY
- SELECT ticket_id, b.tipo, bi, IF(has_iva, red(bi * iva), 0) iva, IF(has_re, red(bi * i.re), 0) re
- FROM (
- SELECT ticket_id, g.Id_Pais, g.tipo
- ,SUM(red(m.Cantidad * m.Preu * (100 - m.Descuento) / 100)) AS bi
- ,NOT(VIES AND p.pais_id <> c.Id_Pais) AS has_iva
- ,RE != FALSE AS has_re
- FROM ticket_tmp i
- JOIN Tickets t ON t.Id_ticket = i.ticket_id
- JOIN Clientes c ON c.Id_Cliente = t.Id_Cliente
- JOIN Proveedores p ON p.Id_Proveedor = t.empresa_id
- JOIN Movimientos m ON m.Id_Ticket = i.ticket_id
- JOIN Articles a USING(Id_Article)
- JOIN iva_group g ON g.Id_Pais = p.pais_id AND g.iva_group_id = a.iva_group_id
- GROUP BY ticket_id, tipo
- ) b
- JOIN iva_tax i ON i.Id_Pais = b.Id_Pais AND i.tipo = b.tipo;
-
- SIGNAL clean;
+ (INDEX (ticket_id))
+ ENGINE = MEMORY
+ SELECT ticketFk ticket_id, type tipo, taxBase bi, tax iva, equalizationTax re
+ FROM tmp.ticketTax;
+
+ DROP TEMPORARY TABLE
+ tmp.ticketTax,
+ tmp.ticket;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -36739,7 +37212,7 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `ticket_locator`(IN date_ DATETIME,IN wh_ INT, IN days TINYINT)
+CREATE DEFINER=`root`@`%` PROCEDURE `ticket_locator`(date_ DATETIME, IN wh_ INT, IN days TINYINT)
BEGIN
DECLARE DATEFEC DATE DEFAULT CURDATE();
DECLARE v_date_start DATETIME DEFAULT TIMESTAMPADD(MONTH, -2, CURDATE());
@@ -36748,7 +37221,7 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS `Locator`;
-
+-- usar ticket_total crear ticket_tmp(ticket_id)
DROP TEMPORARY TABLE IF EXISTS ticket_tmp;
CREATE TEMPORARY TABLE `ticket_tmp`
ENGINE = MEMORY
@@ -36771,12 +37244,13 @@ BEGIN
LEFT JOIN Agencias a ON a.Id_Agencia = t1.Id_Agencia
LEFT JOIN agency ag ON ag.agency_id = a.agency_id
LEFT JOIN agency_warehouse aw ON aw.agency_id = a.agency_id AND aw.warehouse_id = wh_
-
+ -- para pte recogida
LEFT JOIN warehouse w_out on w_out.id = t1.warehouse_id
LEFT JOIN warehouse w ON w.id = wh_
LEFT JOIN warehouse_pickup wp on wp.agency_id = t1.Id_Agencia and wp.warehouse_id = wh_
- WHERE IFNULL(aw.Vista,a.Vista) > 0
+ WHERE /*t1.Fecha BETWEEN TIMESTAMPADD(DAY,-5,DATE(date_)) AND TIMESTAMPADD(DAY,days,DATE(date_))
+ AND */IFNULL(aw.Vista,a.Vista) > 0
AND ((t1.Anotadoencaja = FALSE
AND t1.Etiquetasemitidas = FALSE
AND e.ticket_id IS NULL
@@ -36806,11 +37280,11 @@ BEGIN
WHERE t.Fecha <= v_date_end
GROUP BY t.Id_Cliente
UNION ALL
- SELECT t.customer_id, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
- FROM hedera.tpv_transaction t
- WHERE t.receipt_id IS NULL
+ SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
+ FROM hedera.tpvTransaction t
+ WHERE t.receiptFk IS NULL
AND t.status = 'ok'
- GROUP BY t.customer_id
+ GROUP BY t.clientFk
) t ON c.Id_Cliente = t.customer_id
WHERE c.activo != FALSE
GROUP BY c.Id_Cliente;
@@ -36876,14 +37350,14 @@ BEGIN
SET Observaciones = CONCAT('F5 PERDIDO ',IFNULL(Observaciones,''));
-
+ -- CODIGO 100
UPDATE `Locator`
JOIN Movimientos using(Id_Ticket)
SET Observaciones = 'CODIGO 100'
WHERE Id_Article = 100;
-
+ -- ENTRADAS
INSERT INTO `Locator`(Fecha_Simple, Id_Ticket, Agencia, Id_Cliente, Alias, PedidoImpreso, CodigoTrabajador, Fecha, Estado, Consignatario, Vista, PROVINCIA,Riesgo)
SELECT DISTINCT v_compres.shipment AS Fecha_Simple, v_compres.Id_Entrada AS Id_Ticket, warehouse.name, v_compres.Id_Proveedor,
v_compres.ref AS Alias, v_compres.Pedida AS PedidoImpreso, v_compres.Id_Trabajador AS CodigoTrabajador, v_compres.shipment AS Fecha, 0 AS problem, v_compres.ref AS Consignatario, 1, 'TRASLADO',0
@@ -36927,7 +37401,7 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS `Locator`;
-
+-- usar ticket_total crear ticket_tmp(ticket_id)
DROP TEMPORARY TABLE IF EXISTS ticket_tmp;
CREATE TEMPORARY TABLE `ticket_tmp`
ENGINE = MEMORY
@@ -36936,7 +37410,34 @@ BEGIN
AND t.Fecha BETWEEN v_date_start AND v_date_future;
CALL ticket_total();
-
+ /*
+ DROP TEMPORARY TABLE IF EXISTS ticket_total2;
+ CREATE TEMPORARY TABLE `ticket_total2`
+ ENGINE = MEMORY
+ SELECT t.* FROM ticket_total t
+ LEFT JOIN Tickets t1 ON t1.Id_Ticket = t.ticket_id
+ LEFT JOIN Tickets_state ts ON ts.Id_Ticket = t1.Id_Ticket
+ LEFT JOIN vncontrol.inter i ON ts.inter_id = i.inter_id
+ LEFT JOIN state s ON s.id = i.state_id
+ LEFT JOIN expeditions e ON e.ticket_id = t.ticket_id
+ LEFT JOIN Agencias a ON a.Id_Agencia = t1.Id_Agencia
+ LEFT JOIN agency ag ON ag.agency_id = a.agency_id
+ LEFT JOIN agency_warehouse aw ON aw.agency_id = a.agency_id AND aw.warehouse_id = wh_
+ -- para pte recogida
+ LEFT JOIN warehouse w_out on w_out.id = t1.warehouse_id
+ LEFT JOIN warehouse w ON w.id = wh_
+ LEFT JOIN warehouse_pickup wp on wp.agency_id = t1.Id_Agencia and wp.warehouse_id = wh_
+
+ WHERE t1.Fecha BETWEEN TIMESTAMPADD(DAY,-5,DATE(date_)) AND TIMESTAMPADD(DAY,days,DATE(date_))
+ AND IFNULL(aw.Vista,a.Vista) > 0
+ AND ((t1.Anotadoencaja = FALSE
+ AND t1.Etiquetasemitidas = FALSE
+ AND e.ticket_id IS NULL
+ AND t1.warehouse_id = wh_
+ AND IFNULL(s.order,0) < 2)
+ OR (ts.state_name = 'Pte Recogida'
+ AND wp.warehouse_id IS NOT NULL));
+ */
SELECT t.* FROM ticket_total t
LEFT JOIN Tickets t1 ON t1.Id_Ticket = t.ticket_id
LEFT JOIN Tickets_state ts ON ts.Id_Ticket = t1.Id_Ticket
@@ -36946,7 +37447,7 @@ BEGIN
LEFT JOIN Agencias a ON a.Id_Agencia = t1.Id_Agencia
LEFT JOIN agency ag ON ag.agency_id = a.agency_id
LEFT JOIN agency_warehouse aw ON aw.agency_id = a.agency_id AND aw.warehouse_id = wh_
-
+ -- para pte recogida
LEFT JOIN warehouse w_out on w_out.id = t1.warehouse_id
LEFT JOIN warehouse w ON w.id = wh_
LEFT JOIN warehouse_pickup wp on wp.agency_id = t1.Id_Agencia and wp.warehouse_id = wh_
@@ -36956,8 +37457,113 @@ BEGIN
AND ((t1.Anotadoencaja = FALSE
AND t1.Etiquetasemitidas = FALSE
AND e.ticket_id IS NULL));
-
-
+ /* AND t1.warehouse_id = wh_
+ AND IFNULL(s.order,0) < 2)
+ OR (ts.state_name = 'Pte Recogida'
+ AND wp.warehouse_id IS NOT NULL))*/
+ /*
+ DROP TEMPORARY TABLE IF EXISTS tmp.risk;
+ CREATE TEMPORARY TABLE tmp.risk
+ SELECT Id_Cliente, SUM(amount) risk
+ FROM Clientes c
+ JOIN (
+ SELECT customer_id, SUM(amount) amount
+ FROM bi.customer_risk
+ GROUP BY customer_id
+ UNION ALL
+ SELECT Id_Cliente, SUM(Entregado)
+ FROM Recibos
+ WHERE Fechacobro > v_date_end
+ GROUP BY Id_Cliente
+ UNION ALL
+ SELECT t.Id_Cliente, SUM(total)
+ FROM ticket_total tt
+ JOIN Tickets t ON tt.ticket_id = t.Id_Ticket
+ WHERE t.Fecha <= v_date_end
+ GROUP BY t.Id_Cliente
+ UNION ALL
+ SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
+ FROM hedera.tpvTransaction t
+ WHERE t.receiptFk IS NULL
+ AND t.status = 'ok'
+ GROUP BY t.clientFk
+ ) t ON c.Id_Cliente = t.customer_id
+ WHERE c.activo != FALSE
+ GROUP BY c.Id_Cliente;
+
+ CREATE TEMPORARY TABLE `Locator`
+ ENGINE = MEMORY
+ SELECT Congelado, Credito, risk Riesgo, Greuge, T.*,IFNULL(state_name,'libre') AS Estado,
+ Codigotrabajador, DATE(T.Fecha) AS Fecha_Simple, Averiguar_ComercialCliente_IdTicket(T.Id_Ticket) AS Comercial,C.calidad,UCASE(LEFT(w_out.`name`,5)) w_out
+ FROM Clientes C
+ INNER JOIN
+ (
+ SELECT
+ t.Id_Ticket, t.Id_Cliente, t.warehouse_id, t.Fecha, t.Alias,
+ NULL Notas, t.Factura, t.factura_id, t.Anotadoencaja, t.Id_Consigna, t.Id_Trabajador,
+ t.Observaciones, t.Firmado, t.Etiquetasemitidas, t.PedidoImpreso, t.Bultos, t.Localizacion,
+ t.Hora, t.odbc_date, t.blocked, t.Solucion, t.Id_Ruta, t.Prioridad, t.priority,
+ t.empresa_id, t.Id_Agencia,
+ CS.Consignatario, IFNULL(aw.Vista,a.Vista) Vista,a.Agencia, DATEFEC AS Hora_MAX ,
+ SUM(IF(Movimientos.OK = 0, 1, 0)) AS `lines`,
+ tt.total AS Importe,
+ IF(reino_id IN (5, 1), 0,tt.total) AS Plantas,
+ 0 AS inacabable,
+ CS.CODPOSTAL, CS.POBLACION, p.name PROVINCIA, a.Vista VistaTicket,p.zone
+
+ FROM Tickets t
+ JOIN ticket_total2 tt ON tt.ticket_id = t.Id_Ticket
+ INNER JOIN Consignatarios CS USING(Id_Consigna)
+ LEFT JOIN province p USING(province_id)
+ LEFT JOIN Movimientos USING(Id_Ticket)
+ LEFT JOIN Articles on Movimientos.Id_Article = Articles.Id_Article
+ LEFT JOIN Tipos using(tipo_id)
+ LEFT JOIN Agencias a ON a.Id_Agencia = t.Id_Agencia
+ LEFT JOIN agency ag ON ag.agency_id = a.agency_id
+ LEFT JOIN agency_warehouse aw ON aw.agency_id = a.agency_id AND aw.warehouse_id = wh_
+
+ GROUP BY t.Id_Ticket
+ ) T USING(Id_Cliente)
+ LEFT JOIN Tickets_state ts ON ts.Id_Ticket = T.Id_Ticket
+ LEFT JOIN Trabajadores Tb ON Tb.Id_Trabajador = T.Id_Trabajador
+ LEFT JOIN tmp.risk as Peligros USING(Id_Cliente)
+ JOIN warehouse w_out on w_out.id = T.warehouse_id
+ LEFT JOIN
+ (
+ SELECT Id_Cliente, SUM(Importe) AS Greuge FROM Greuges
+ GROUP BY Id_Cliente
+ ) AS Agravios USING(Id_Cliente);
+
+
+ ALTER TABLE `Locator` ADD PRIMARY KEY(Id_Ticket);
+
+ UPDATE `Locator` JOIN
+ (
+ SELECT d.Id_Ticket from Tickets_dits d
+ JOIN Tickets t using(Id_Ticket)
+ LEFT JOIN Agencias a using(Id_Agencia)
+ LEFT JOIN expeditions e on e.ticket_id = d.Id_Ticket
+ WHERE Fecha BETWEEN CURDATE() AND TIMESTAMP(curdate(),'23:59:59')
+ AND idaccion_dits = 18 AND ticket_id is null
+ AND t.warehouse_id = 1
+ AND NOT Etiquetasemitidas
+ AND d.ODBC_DATE < TIMESTAMPADD(HOUR,-2, now())
+ AND Vista in (1,2)) sub using(Id_Ticket)
+ SET Observaciones = CONCAT('F5 PERDIDO ',IFNULL(Observaciones,''));
+
+
+ -- ENTRADAS
+ INSERT INTO `Locator`(Fecha_Simple, Id_Ticket, Agencia, Id_Cliente, Alias, PedidoImpreso, CodigoTrabajador, Fecha, Estado, Consignatario, Vista, PROVINCIA,Riesgo)
+ SELECT DISTINCT v_compres.shipment AS Fecha_Simple, v_compres.Id_Entrada AS Id_Ticket, warehouse.name, v_compres.Id_Proveedor,
+ v_compres.ref AS Alias, v_compres.Pedida AS PedidoImpreso, v_compres.Id_Trabajador AS CodigoTrabajador, v_compres.shipment AS Fecha, 0 AS problem, v_compres.ref AS Consignatario, 1, 'TRASLADO',0
+ FROM v_compres
+ INNER JOIN warehouse ON v_compres.warehouse_id = warehouse.id
+ WHERE warehouse_id_out = wh_ AND v_compres.Confirmada = False
+ AND v_compres.shipment >= date_;
+
+
+
+*/
DROP TEMPORARY TABLE IF EXISTS ticket_tmp;
DROP TEMPORARY TABLE IF EXISTS ticket_total;
DROP TEMPORARY TABLE IF EXISTS ticket_total2;
@@ -36989,7 +37595,18 @@ BEGIN
SELECT timeSTART, 'ARRANCA';
DROP TEMPORARY TABLE IF EXISTS `Locator`;
-
+/*
+-- usar ticket_total crear ticket_tmp(ticket_id)
+ DROP TEMPORARY TABLE IF EXISTS ticket_tmp;
+ CREATE TEMPORARY TABLE `ticket_tmp`
+ (INDEX idx USING HASH (ticket_id))
+ ENGINE = MEMORY
+ SELECT Id_Ticket ticket_id FROM Tickets t
+ WHERE t.Factura IS NULL
+ AND t.Fecha BETWEEN v_date_start AND v_date_future;
+
+ CALL ticket_total();
+ */
DROP TEMPORARY TABLE IF EXISTS ticket_total;
CREATE TEMPORARY TABLE ticket_total
@@ -37044,11 +37661,11 @@ BEGIN
WHERE t.Fecha <= v_date_end
GROUP BY t.Id_Cliente
UNION ALL
- SELECT t.customer_id, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
- FROM hedera.tpv_transaction t
- WHERE t.receipt_id IS NULL
+ SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
+ FROM hedera.tpvTransaction t
+ WHERE t.receiptFk IS NULL
AND t.status = 'ok'
- GROUP BY t.customer_id
+ GROUP BY t.clientFk
) t ON c.Id_Cliente = t.customer_id
WHERE c.activo != FALSE
GROUP BY c.Id_Cliente;
@@ -37117,7 +37734,7 @@ SET Observaciones = CONCAT('F5 PERDIDO ',IFNULL(Observaciones,''));
SELECT TIMEDIFF(NOW(), timeSTART), 'UPDATE';
-
+-- ENTRADAS
INSERT INTO `Locator`(Fecha_Simple, Id_Ticket, Agencia, Id_Cliente, Alias, PedidoImpreso, CodigoTrabajador, Fecha, Estado, Consignatario, Vista, PROVINCIA,Riesgo)
SELECT DISTINCT v_compres.shipment AS Fecha_Simple, v_compres.Id_Entrada AS Id_Ticket, warehouse.name, v_compres.Id_Proveedor,
v_compres.ref AS Alias, v_compres.Pedida AS PedidoImpreso, v_compres.Id_Trabajador AS CodigoTrabajador, v_compres.shipment AS Fecha, 0 AS problem, v_compres.ref AS Consignatario, 1, 'TRASLADO',0
@@ -37127,7 +37744,7 @@ WHERE warehouse_id_out = wh_ AND v_compres.Confirmada = False
AND v_compres.shipment >= date_;
SELECT TIMEDIFF(NOW(), timeSTART), 'ENTRADAS';
-
+-- TICKET PTE RECOGIDA
INSERT INTO `Locator`(Fecha_Simple
, Id_Ticket
, Agencia
@@ -37151,7 +37768,7 @@ SELECT date(t.Fecha)
, t.Id_Cliente
, t.Alias
, t.PedidoImpreso
- , UCASE(LEFT(w_out.name,5)) as CodigoTrabajador
+ , UCASE(LEFT(w_out.name,5)) as CodigoTrabajador -- es el almacen de origen
, t.Fecha
, 0 as Estado
, t.Alias
@@ -37176,7 +37793,7 @@ JOIN
order by odbc_date desc, state_id desc
) sub
group by Id_Ticket
- having state_id = 15
+ having state_id = 15 -- Pendiente de entrega
) sub2 using(Id_Ticket);
SELECT TIMEDIFF(NOW(), timeSTART), 'PTE RECOGIDA';
@@ -37213,7 +37830,7 @@ CREATE DEFINER=`root`@`%` PROCEDURE `ticket_new`(
, IN datLANDING DATE
, OUT newTICKET INT)
BEGIN
-
+-- DEPRECATED usar ticketCreate
DECLARE boolaux TINYINT;
SET boolaux = If(IdC = 200 Or IdC = 400 Or intTIPO = 23, True, False);
@@ -37279,7 +37896,7 @@ CREATE DEFINER=`root`@`%` PROCEDURE `ticket_new_complet`(
, IN idRUTA INT
, OUT newTICKET INT)
BEGIN
-
+-- DEPRECATED usar ticketCreate
DECLARE boolaux TINYINT;
@@ -37341,7 +37958,7 @@ FROM vn2008.Movimientos m
JOIN vn2008.Movimientos_componentes mc using(Id_Movimiento)
INNER JOIN bi.tarifa_componentes tc ON mc.Id_Componente = tc.Id_Componente
WHERE m.Id_Ticket = idTICKET
-AND tc.tarifa_componentes_series_id = 6;
+AND tc.tarifa_componentes_series_id = 6; -- agencia
@@ -37398,17 +38015,22 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `ticket_total`()
BEGIN
-
-
- DROP TEMPORARY TABLE IF EXISTS ticket_total;
-
+/**
+ * Calcula el total con IVA de un conjunto de tickets.
+ *
+ * @deprecated Use procedure vn.ticketGetTotal() instead
+ *
+ * @table ticket_tmp(ticket_id) Tabla con el listado de tickets
+ * @return table ticket_total
+ */
CALL ticket_iva (NULL);
+ DROP TEMPORARY TABLE IF EXISTS ticket_total;
CREATE TEMPORARY TABLE ticket_total
- (INDEX idx USING HASH (ticket_id))
- ENGINE = MEMORY
- SELECT ticket_id, red(SUM(bi + iva + re)) AS total
- FROM ticket_iva GROUP BY ticket_id;
+ (INDEX (ticket_id))
+ ENGINE = MEMORY
+ SELECT ticket_id, red(SUM(bi + iva + re)) AS total
+ FROM ticket_iva GROUP BY ticket_id;
DROP TEMPORARY TABLE ticket_iva;
END ;;
@@ -37435,23 +38057,18 @@ BEGIN
DROP TEMPORARY TABLE IF EXISTS ticket_volumen;
SELECT warehouse_id, Fecha INTO intWh,datFecha FROM Tickets WHERE Id_Ticket = idT;
- CALL item_last_buy_(intWh,datFecha);
-
CREATE TEMPORARY TABLE IF NOT EXISTS ticket_volumen ENGINE MEMORY
SELECT Id_Article,Cantidad, Concepte, VolUd as m3_uni, Volumen as m3, @m3:= @m3 + ifnull(Volumen,0) as m3_total
FROM
(
- SELECT round(cm3(Id_Compra)/1000000/Packing,3) as VolUd ,M.Cantidad,round(M.Cantidad * cm3(Id_Compra)/1000000/Packing,3) as Volumen,
+ SELECT round(r.cm3 / 1000000,3) as VolUd ,M.Cantidad, round(r.cm3 * M.Cantidad / 1000000,3) as Volumen,
M.Id_Article, Concepte, @m3:= 0, @vol:=0, Id_Agencia
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 bi.rotacion r ON r.Id_Article = M.Id_Article AND r.warehouse_id = T.warehouse_id
WHERE M.Id_Ticket = idT
- ) sub
- JOIN Agencias a using(Id_Agencia);
+ ) sub;
- DROP TEMPORARY TABLE t_item_last_buy;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -37599,7 +38216,7 @@ BEGIN
-
+#Vamos a calcular el porcentaje a incrementar las cantidades de las lineas de movimiento para inflar / desinflar la base final
DECLARE dblBASE_INICIAL DOUBLE DEFAULT 0;
DECLARE dblBASE_FINAL DOUBLE DEFAULT 0;
@@ -37614,11 +38231,11 @@ WHERE Id_Ticket = intIDTICKET;
SET dblBASE_FINAL = dblBASE_INICIAL;
-
+#Eliminamos lineas a 0
DELETE FROM Movimientos WHERE Cantidad = 0 AND Id_Ticket = intIDTICKET;
-
+# Vamos a ir probando incrementos paulatinos hasta que encontremos el que supera lo pedido, teniendo en cuenta el sentido del incremento
IF dblINCREMENTO < 0 THEN
@@ -37696,7 +38313,7 @@ BEGIN
CALL buy_tarifas_table(i_entrada);
-
+ -- Traslado en almacen origen
DROP TEMPORARY TABLE IF EXISTS buy_edi_temp;
@@ -37825,7 +38442,7 @@ BEGIN
CREATE INDEX tindex USING HASH ON Traslados (article_id);
-
+-- Inventario en el warehouse destino
IF dateShipment >= CURDATE() THEN
CALL cache.visible_refresh(v_calc_visible, TRUE, warehouseLanding);
@@ -37837,7 +38454,7 @@ BEGIN
SET vis2 = v.visible, dis2 = a.available;
END IF;
-
+-- ---------------------------------------------
SELECT t.*,
@@ -37902,7 +38519,7 @@ BEGIN
CALL buy_tarifas_table(i_entrada);
-
+ -- Traslado en almacen origen
DROP TEMPORARY TABLE IF EXISTS buy_edi_temp;
@@ -37920,7 +38537,7 @@ BEGIN
IF dateShipment >= CURDATE() THEN
-
+ -- CALL `cache`.available_refresh(v_calc_available, TRUE, warehouseShipment, dateShipment);
CALL availableTraslate(warehouseShipment, dateShipment,NULL);
CALL `cache`.visible_refresh(v_calc_visible,TRUE,warehouseShipment);
DROP TEMPORARY TABLE IF EXISTS tmp_item;
@@ -38026,7 +38643,7 @@ BEGIN
CREATE INDEX tindex USING HASH ON Traslados (article_id);
-
+-- Inventario en el warehouse destino
IF dateShipment >= CURDATE() THEN
CALL cache.visible_refresh(v_calc_visible, TRUE, warehouseLanding);
@@ -38041,7 +38658,7 @@ BEGIN
SET vis2 = v.visible, dis2 = a.available;
END IF;
-
+-- ---------------------------------------------
SELECT t.*,
@@ -38105,7 +38722,7 @@ BEGIN
CALL buy_tarifas_table(i_entrada);
-
+ -- Traslado en almacen origen
DROP TEMPORARY TABLE IF EXISTS buy_edi_temp;
@@ -38124,7 +38741,7 @@ BEGIN
IF dateShipment >= CURDATE() THEN
CALL `cache`.available_refresh(v_calc_available, TRUE, warehouseShipment, dateShipment);
-
+ -- CALL `cache`.availableTraslate(warehouseShipment, dateShipment,NULL);
CALL `cache`.visible_refresh(v_calc_visible,TRUE,warehouseShipment);
DROP TEMPORARY TABLE IF EXISTS tmp_item;
CREATE TEMPORARY TABLE tmp_item (UNIQUE INDEX i USING HASH (item_id)) ENGINE = MEMORY
@@ -38229,7 +38846,7 @@ BEGIN
CREATE INDEX tindex USING HASH ON Traslados (article_id);
-
+-- Inventario en el warehouse destino
IF dateShipment >= CURDATE() THEN
CALL cache.visible_refresh(v_calc_visible, TRUE, warehouseLanding);
@@ -38241,7 +38858,7 @@ BEGIN
SET vis2 = v.visible, dis2 = a.available;
END IF;
-
+-- ---------------------------------------------
SELECT t.*,
@@ -38331,7 +38948,7 @@ SET intEntrada = IF(intEntrada = 0, i_entrada_PCA + i_entrada_FV, intEntrada);
select c_land.Id_Cubo,c_land.Packing,c_land.grouping,c_land.Costefijo,c_land.Comisionfija,c_land.Portefijo,c_land.caja,SUM(c_land.Etiquetas) Etiquetas,c_land.EmbalajeFijo,
c_land.novincular,c_land.buy_edi_id,c_land.Id_Article,SUM(c_land.Cantidad) Cantidad
from
-
+ -- Entradas que llegan a vnh
Compres c_land
JOIN
Entradas e_land ON c_land.Id_Entrada = e_land.Id_Entrada AND c_land.Id_Article = intArticle
@@ -38340,21 +38957,21 @@ SET intEntrada = IF(intEntrada = 0, i_entrada_PCA + i_entrada_FV, intEntrada);
JOIN
Cubos cu ON cu.Id_Cubo = c_land.Id_Cubo
WHERE
-
+ -- Entradas que llegan a vnh
(t_land.warehouse_id = 7 AND t_land.landing = CURDATE())
) land
- LEFT JOIN
+ LEFT JOIN -- Entradas que salen de vnh
(SELECT SUM(c_ship.Etiquetas) Etiquetas,c_ship.Packing,SUM(c_ship.Cantidad) Cantidad
FROM Compres c_ship
LEFT JOIN Entradas e_ship ON c_ship.Id_Entrada = e_ship.Id_Entrada AND c_ship.Id_Article = intArticle
LEFT JOIN travel t_ship ON t_ship.id = e_ship.travel_id
WHERE t_ship.warehouse_id_out = 7 AND t_ship.shipment = CURDATE()
-
+ -- Entrada destino
) ship ON TRUE
JOIN Entradas e2 ON e2.Id_Entrada = intEntrada
JOIN travel t ON t.id = e2.travel_id
JOIN Agencias a ON t.agency_id = a.Id_Agencia
-
+ -- Ventas ese dia en VNH
LEFT JOIN
(SELECT sum(Cantidad) as Ventas
FROM Movimientos m
@@ -38384,14 +39001,74 @@ DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `traslado_label_2`(IN i_compra INTEGER,IN i_entrada_FV INTEGER, IN i_entrada_PCA INTEGER, i_cantidad INTEGER)
BEGIN
-
+-- PAK 2015-09-15
DECLARE idARTICLE INT;
SELECT Id_Article INTO idARTICLE FROM Compres WHERE Id_Compra = i_compra;
call traslado_label_3(idARTICLE,i_entrada_FV,i_entrada_PCA);
+/*
+DECLARE i_entrada_shipment INTEGER;
+DECLARE i_entrada_landing INTEGER;
+DECLARE i_FV INTEGER;
+SELECT c.Id_Entrada, FV INTO i_entrada_shipment, i_FV
+FROM Compres c
+JOIN Articles a ON a.Id_Article = c.Id_Article
+JOIN Tipos tp ON tp.tipo_id = a.tipo_id
+WHERE Id_Compra = i_compra;
+
+SET i_entrada_landing = IF(i_FV, i_entrada_FV,i_entrada_PCA);
+
+SET i_entrada_landing = IF(i_entrada_landing = 0, i_entrada_PCA + i_entrada_FV, i_entrada_landing);
+
+IF i_entrada_landing > 0 THEN
+
+ CALL buy_tarifas_table(i_entrada_landing);
+
+ INSERT INTO Compres (Id_Article, Etiquetas, Cantidad, Id_Entrada, Id_Cubo, Packing,grouping,caja,
+ Costefijo, Portefijo, Embalajefijo, Comisionfija, Productor, S3, S4, S2, novincular,k01,k02,k03,k04,buy_edi_id)
+ SELECT
+ Id_Article,
+ i_cantidad / Packing,
+ i_cantidad,
+ i_entrada_landing,
+ Id_Cubo,
+ Packing,
+ c.grouping,
+ c.caja,
+ @cost := ROUND(IFNULL(Costefijo, 0) + IFNULL(Comisionfija, 0) + IFNULL(Portefijo, 0),
+ 3) Costefij,
+ @porte := ROUND((@cm3:= cm3_2(Id_Cubo, Id_Article)) * a.m3 / 1000000 / Packing,
+ 3) Porte,
+ EmbalajeFijo AS Embalaje,
+ @comision := ROUND(Costefijo * e2.comision / 100, 3) Comision,
+ Productor,
+ S3,
+ S4,
+ S2,
+ novincular,c.k01,c.k02,c.k03,c.k04,c.buy_edi_id
+ FROM
+ Compres c
+ JOIN
+ Entradas e USING (Id_Entrada)
+ JOIN
+ Cubos cu USING (Id_Cubo)
+ JOIN
+ Entradas e2 ON e2.Id_Entrada = i_entrada_landing
+ JOIN
+ travel t ON t.id = e2.travel_id
+ JOIN
+ Agencias a ON t.agency_id = a.Id_Agencia
+ WHERE
+ Id_Compra = i_compra and i_cantidad;
+
+
+CALL buy_tarifas(LAST_INSERT_ID());
+
+END IF;
+*/
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -38410,7 +39087,7 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `traslado_label_3`(IN intArticle INTEGER,IN i_entrada_FV INTEGER, IN i_entrada_PCA INTEGER)
BEGIN
-
+-- DEPRECATED usar traslado_label
DECLARE intEntrada INTEGER;
DECLARE i_FV INTEGER;
@@ -38450,7 +39127,7 @@ SET intEntrada = IF(intEntrada = 0, i_entrada_PCA + i_entrada_FV, intEntrada);
select c_land.Id_Cubo,c_land.Packing,c_land.grouping,c_land.Costefijo,c_land.Comisionfija,c_land.Portefijo,c_land.caja,SUM(c_land.Etiquetas) Etiquetas,c_land.EmbalajeFijo,
c_land.novincular,c_land.buy_edi_id,c_land.Id_Article,SUM(c_land.Cantidad) Cantidad
from
-
+ -- Entradas que llegan a vnh
Compres c_land
JOIN
Entradas e_land ON c_land.Id_Entrada = e_land.Id_Entrada AND c_land.Id_Article = intArticle
@@ -38459,21 +39136,21 @@ SET intEntrada = IF(intEntrada = 0, i_entrada_PCA + i_entrada_FV, intEntrada);
JOIN
Cubos cu ON cu.Id_Cubo = c_land.Id_Cubo
WHERE
-
+ -- Entradas que llegan a vnh
(t_land.warehouse_id = 7 AND t_land.landing = CURDATE())
) land
- LEFT JOIN
+ LEFT JOIN -- Entradas que salen de vnh
(SELECT SUM(c_ship.Etiquetas) Etiquetas,c_ship.Packing,SUM(c_ship.Cantidad) Cantidad
FROM Compres c_ship
LEFT JOIN Entradas e_ship ON c_ship.Id_Entrada = e_ship.Id_Entrada AND c_ship.Id_Article = intArticle
LEFT JOIN travel t_ship ON t_ship.id = e_ship.travel_id
WHERE t_ship.warehouse_id_out = 7 AND t_ship.shipment = CURDATE()
-
+ -- Entrada destino
) ship ON TRUE
JOIN Entradas e2 ON e2.Id_Entrada = intEntrada
JOIN travel t ON t.id = e2.travel_id
JOIN Agencias a ON t.agency_id = a.Id_Agencia
-
+ -- Ventas ese dia en VNH
LEFT JOIN
(SELECT sum(Cantidad) as Ventas
FROM Movimientos m
@@ -38599,18 +39276,20 @@ SELECT
wo.name as OrigenCajas,
tr.landing,
w.name as Destino,
- NULL as Etiquetas,
+ sum(c.Etiquetas) as Etiquetas,
NULL as Notas_Eva,
kg,
- cast(sum(tp.density * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as loadedKg,
+ cast(sum(a.density * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as loadedKg,
NULL as loadPriority,
- NULL as awb
+ NULL as Notas,
+ pc.Proveedor as Carguera
FROM travel tr
- JOIN Entradas e ON e.travel_id = tr.id
- JOIN Compres c ON c.Id_Entrada = e.Id_Entrada
- JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo
- JOIN Articles a ON a.Id_Article = c.Id_Article
- JOIN Tipos tp ON tp.tipo_id = a.tipo_id
+ LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk
+ LEFT JOIN Entradas e ON e.travel_id = tr.id
+ LEFT JOIN Compres c ON c.Id_Entrada = e.Id_Entrada
+ LEFT JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo
+ LEFT JOIN Articles a ON a.Id_Article = c.Id_Article
+ LEFT JOIN Tipos tp ON tp.tipo_id = a.tipo_id
JOIN warehouse w ON w.id = tr.warehouse_id
JOIN warehouse wo ON wo.id = tr.warehouse_id_out
JOIN Agencias ag ON ag.Id_Agencia = tr.agency_id
@@ -38632,20 +39311,23 @@ SELECT
sum(Etiquetas) as Etiquetas,
e.Notas_Eva,
NULL as kg,
- cast(sum(tp.density * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as loadedkg,
+ cast(sum(a.density * c.Etiquetas * IF(cb.Volumen, cb.Volumen, cb.X * cb.Y * cb.Z) / 1000000 ) as DECIMAL(10,0)) as loadedkg,
loadPriority,
- CAST(awb.codigo AS DECIMAL(11,0)) as awb
+ -- CAST(awb.codigo AS DECIMAL(11,0)) as awb,
+ e.Notas,
+ pc.Proveedor as carguera
FROM Entradas e
- LEFT JOIN recibida_entrada re ON re.Id_Entrada = e.Id_Entrada
+ /* LEFT JOIN recibida_entrada re ON re.Id_Entrada = e.Id_Entrada
LEFT JOIN awb_recibida ar ON ar.recibida_id = re.awb_recibida
LEFT JOIN awb ON awb.id = ar.awb_id
- JOIN Compres c ON c.Id_Entrada = e.Id_Entrada
+ */ JOIN Compres c ON c.Id_Entrada = e.Id_Entrada
JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo
JOIN Articles a ON a.Id_Article = c.Id_Article
JOIN Tipos tp ON tp.tipo_id = a.tipo_id
JOIN Proveedores p ON p.Id_Proveedor = e.Id_Proveedor
JOIN travel tr ON tr.id = e.travel_id
+ LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk
JOIN warehouse w ON w.id = tr.warehouse_id
JOIN warehouse wo ON wo.id = tr.warehouse_id_out
WHERE tr.landing >= vDateFrom
@@ -38671,7 +39353,15 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `travel_tree`(vDate DATE, vAddress INT, vAgency INT)
BEGIN
-
+/**
+ * Devuelve la lista de almacenes disponibles y la fecha de
+ * envío desde cada uno.
+ *
+ * @param vDate Fecha de recepción de mercancía
+ * @param vAddress Id consignatario, %NULL para recogida
+ * @param vAgency Id de subagencia
+ * @table travel_tree Lista de almacenes disponibles
+ */
DECLARE vDone BOOL;
DECLARE vWh SMALLINT;
@@ -38691,7 +39381,7 @@ BEGIN
)
ENGINE = MEMORY;
-
+ -- Establecemos los almacenes y las fechas que van a entrar
OPEN vCur;
@@ -38746,7 +39436,14 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `travel_tree_list`(vAddress INT, vDate DATE)
BEGIN
-
+/**
+ * Devuelve el listado de agencias disponibles para la fecha
+ * y dirección pasadas.
+ *
+ * @param vAddress Id de dirección de envío, %NULL si es recogida
+ * @param vDate Fecha de recogida
+ * @table agency_list Listado de agencias disponibles
+ */
DECLARE vAgency INT;
DECLARE vDone BOOL DEFAULT FALSE;
@@ -38811,7 +39508,14 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `travel_tree_shipment`(v_date DATE, v_consigna INT, v_agency INT, v_warehouse INT)
BEGIN
-
+/**
+ * Devuelve una tabla temporal con el dia de recepcion para v_date.
+ *
+ * @param v_date Fecha de preparacion de mercancia
+ * @param v_consigna Id de consignatario, %NULL para recogida
+ * @param v_agency Id agencia
+ * @table travel_tree_shipment Datos de recepción
+ */
DROP TEMPORARY TABLE IF EXISTS travel_tree_shipment;
CREATE TEMPORARY TABLE travel_tree_shipment
ENGINE = MEMORY
@@ -38922,9 +39626,9 @@ WHILE NOT done DO
SELECT LAST_INSERT_ID() INTO myNuevaEntrada;
INSERT INTO Compres(Id_Entrada, Id_Article, Cantidad, Costefijo, Portefijo, Embalajefijo, Novincular, Comisionfija, Etiquetas, Packing
- ,grouping, caja, Nicho, Id_Cubo, Tarifa1,Tarifa2,Tarifa3, PVP, Productor)
+ ,grouping, caja, /*container_id, */Nicho, Id_Cubo, Tarifa1,Tarifa2,Tarifa3, PVP, Productor)
SELECT myNuevaEntrada, Id_Article, Cantidad, Costefijo, Portefijo, Embalajefijo, Novincular, Comisionfija, Etiquetas, Packing
- ,grouping, caja, Nicho, Id_Cubo, Tarifa1,Tarifa2,Tarifa3, PVP, Productor
+ ,grouping, caja,/* container_id, */Nicho, Id_Cubo, Tarifa1,Tarifa2,Tarifa3, PVP, Productor
FROM Compres
WHERE Id_Entrada = myEntrada;
@@ -38991,7 +39695,7 @@ DELIMITER ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = '' */ ;
+/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `ubicator`(IN i_wh TINYINT, IN d_fecha DATE,IN filtro VARCHAR(255))
BEGIN
@@ -39019,8 +39723,13 @@ SELECT Id_Article article_id,SUM(Cantidad) amount FROM (
UNION ALL
-
-
+ -- JGF Error cuando se pedia para una fecha futura 30/06/14
+ /*SELECT Id_Article,-Cantidad
+ FROM Compres c
+ JOIN Entradas e USING(Id_Entrada)
+ JOIN travel t ON t.id = e.travel_id
+ WHERE shipment BETWEEN date_inv AND timestampadd(DAY,-1,d_fecha)
+ AND warehouse_id_out = i_wh AND NOT Redada*/
SELECT Id_Article,-Cantidad
FROM Compres c
JOIN Entradas e USING(Id_Entrada)
@@ -39029,9 +39738,13 @@ SELECT Id_Article article_id,SUM(Cantidad) amount FROM (
AND warehouse_id_out = i_wh AND NOT Redada AND delivered
UNION ALL
-
+ -- JGF Error cuando se pedia para una fecha futura 30/06/14
-
+ /*SELECT Id_Article, -Cantidad
+ FROM Movimientos m
+ JOIN Tickets t USING(Id_Ticket)
+ WHERE Fecha BETWEEN date_inv AND timestampadd(DAY,-1,d_fecha)
+ AND warehouse_id = i_wh */
SELECT Id_Article, -Cantidad
FROM Movimientos m
JOIN Tickets t USING(Id_Ticket)
@@ -39041,10 +39754,11 @@ SELECT Id_Article article_id,SUM(Cantidad) amount FROM (
) t GROUP BY article_id;
+/*
+SELECT * from stock_actual;*/
-
-
-CALL hedera.sql_query (sql_printf('
+-- TEMPORARY
+CALL util.exec (sql_printf('
CREATE TEMPORARY TABLE IF NOT EXISTS vn2008.tmp_ubicator_stock AS
SELECT A.Id_Article,A.Article, T.Id_Cubo,IF(Z > 0,Z,0) as z,x,y,
CEIL(S.Suma/T.packing) as etiquetas,A.Medida,A.Nicho
@@ -39103,15 +39817,15 @@ DECLARE intContador INT DEFAULT 1;
WHERE W=int_X and D=int_Y and Id_Estanterias=intId_Estanterias and Id_Baldas=intId_Baldas and NumEstanterias=contId_Estanterias
ORDER BY H DESC LIMIT 1;
- WHILE (int_Z*intContador0) DO
SET posZ=posZ+int_Z;
-
-
-
+ -- INSERT INTO Ubicator_Cajas
+ -- (Id_Estanterias,NumEtiquetas,W ,D,H ,Id_Cubo ,Id_Article,POSX,POSY,POSZ,Id_Article_aux ,Id_Baldas,modelo,Article,Medida)
+ -- VALUES (intId_Estanterias ,1,posX,posY,posZ,strId_Cubo ,intId_Article,0,0,0,0,intId_Baldas,strmodelo,'',int_Z);
INSERT INTO Ubicator_Cajas (Id_Estanterias,Id_Baldas,modelo,W ,D,H ,Id_Cubo,X,Y,Z,Medida,Id_Article,Article,numEstanterias)
VALUES (intId_Estanterias,intId_Baldas,strmodelo,posX,posY,posZ,strId_Cubo,x_cubo,y_cubo,int_Z,null,intId_Article,'',contId_Estanterias);
SET intnumcubosocup=intnumcubosocup+1;
@@ -39134,8 +39848,8 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `ubicator_ordenacion`(date DATE,boolORDALFA TINYINT(1), intWAREHOUSE INT,strFILTRO NVARCHAR(255), boolESAPILABLE TINYINT(1),boolESABIERTO TINYINT(1),intCmNichoExtra SMALLINT,inEstanteria SMALLINT,strOrdenacion varchar(255))
BEGIN
-
-
+-- Inicializo variables
+-- boolESABIERTO --> permite apilar las cajas de diferentes articulos (cerrada) para aprovechar el espacio.
DECLARE intPOSX,intPOSY,intPOSZ,intSUMAH,intCMNICHO_EXTRA INT DEFAULT 0;
DECLARE intId_Estanterias,intW,intD,intId_Baldas,intH,intEtiquetas,
intX,intY,intZ,ReturnX,ReturnY,ReturnZ,Cantidad,intId_Baldas_aux INT DEFAULT 0;
@@ -39148,31 +39862,34 @@ DECLARE strArticle VARCHAR(50);
DECLARE boolCabeCaja,boolPasarZ,boolPasarX,boolNoNextRecord,fin BOOLEAN DEFAULT FALSE;
DECLARE intMedida,intX_ant,intY_ant,IntZ_ant INT(10) DEFAULT 0;
+-- ejemplo: call ubicator_ordenacion(CURDATE(),false,1,'tipo_id = 2',TRUE,FALSE,2,1)
-
-
+-- Declaro el cursor para leer las estanterias y las baldas ordenadas por las baldas. (La primera es la de arriba).
DECLARE cursor_estanterias CURSOR FOR SELECT Id_Estanterias,w,d,modelo,Id_Baldas,h FROM Estanterias
INNER JOIN Baldas USING (Id_Estanterias) WHERE Id_Estanterias=inEstanteria ORDER BY Id_Estanterias,Id_Baldas;
-
+-- Declaro el cursor para leer el recorset de los cubos a colocar en las estanterias obteniendo las variables X,Y,Z del cubo.
DECLARE cursor_ubicator CURSOR FOR SELECT Id_Cubo,Etiquetas,Id_Article,X,Y,Z,Article,Medida FROM ubicator_stock;
-
+ -- Creo la tabla temporal donde devuelvo la ordenación de las cajas.
-DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
+DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; -- handler para el cursor de las estanterias y baldas
DROP TEMPORARY TABLE IF EXISTS Ubicator_Cajas;
-
+/*
+ CREATE TEMPORARY TABLE IF NOT EXISTS Ubicator_Cajas (Id_Estanterias INT,Id_Baldas SMALLINT,modelo varchar(255),
+ W SMALLINT,D SMALLINT,H SMALLINT,Id_Cubo VARCHAR(10),X SMALLINT,Y SMALLINT,Z SMALLINT,Medida SMALLINT,Id_Article INT(11),Article varchar(50),NumEstanterias SMALLINT);
+*/
CREATE TEMPORARY TABLE IF NOT EXISTS Ubicator_Cajas(Id_Estanterias INT,Id_Baldas SMALLINT,modelo varchar(255),
W SMALLINT,D SMALLINT,H SMALLINT,Id_Cubo VARCHAR(10),X SMALLINT,Y SMALLINT,Z SMALLINT,Medida SMALLINT,
Id_Article INT(11),Article varchar(50),NumEstanterias SMALLINT,NumEtiquetas INT,POSX INT (11),POSY INT(11),
POSZ INT(11),Id_Article_aux int(11));
-
+-- Creo la tabla temporal donde voy a insertar las cajas que no caben en las estanterias.
DROP TEMPORARY TABLE IF EXISTS Ubicator_CajasNoCaben;
CREATE TEMPORARY TABLE IF NOT EXISTS Ubicator_CajasNoCaben (Id_Cubo VARCHAR(10),Id_Estanteria SMALLINT);
-CALL ubicator (intWAREHOUSE,date,strFILTRO);
+CALL ubicator (intWAREHOUSE,date,strFILTRO); -- Ejecuto el procedimiento de stock para recorrer los articulos con las cajas.
DROP TEMPORARY TABLE IF EXISTS ubicator_stock;
@@ -39183,22 +39900,22 @@ PREPARE stmt1 FROM @SQL;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
+ -- IF (boolORDALFA) THEN
+ -- CREATE TEMPORARY TABLE IF NOT EXISTS ubicator_stock SELECT Id_Cubo,Etiquetas,Id_Article,X,Y,IF(Z=0,Medida,Z) Z,Article,Medida FROM tmp_ubicator_stock
+ -- ORDER BY Article,Medida;
+ -- ELSE
+ -- CREATE TEMPORARY TABLE IF NOT EXISTS ubicator_stock SELECT Id_Cubo,Etiquetas,Id_Article,X,Y,IF(Z=0,Medida,Z) Z,Article,Medida FROM tmp_ubicator_stock
+ -- ORDER BY Id_Article;
+ -- END IF;
-
-
-
-
-
-
-
-
+-- Open Recordsets
OPEN cursor_estanterias;
OPEN cursor_ubicator;
REPEAT
FETCH cursor_estanterias INTO intId_Estanterias,intW,intD,strmodelo,intId_Baldas,intH;
- IF (done) THEN
+ IF (done) THEN -- Si llega a la ultima balda, empieza de nuevo.
CLOSE cursor_estanterias;
SET done=FALSE;
OPEN cursor_estanterias;
@@ -39206,7 +39923,7 @@ REPEAT
FETCH cursor_estanterias INTO intId_Estanterias,intW,intD,strmodelo,intId_Baldas,intH;
END IF;
-
+ -- Obtengo la altura absoluta de la balda.
SELECT CASE WHEN (SUM(H)>=0) THEN SUM(H) ELSE 0 END As suma INTO intSUMAH
FROM Baldas WHERE Id_Estanterias=intId_Estanterias and Baldas.Id_Baldas>intId_Baldas;
@@ -39224,53 +39941,53 @@ REPEAT
SELECT Id_Cubo,Etiquetas,Id_Article,X,Y,Z,Article,Medida FROM ubicator_stock ORDER BY Id_Article;
SET Cantidad=0;
END IF;
-
-
+ -- SET Medida=intZ;
+ -- 1. Compruebo que cabe la caja en la estanteria
SELECT ubicator_cabecaja(intX,intY,intZ,intW,intD,intH) INTO boolCabeCaja;
- IF (NOT boolCabeCaja) THEN
+ IF (NOT boolCabeCaja) THEN -- Compruebo si la caja cabe en la estanteria sino la coloco en una tabla temporal.
INSERT INTO Ubicator_CajasNoCaben (Id_Cubo,Id_Estanteria) VALUES (strId_Cubo,intId_Estanterias);
SET Id_Article_aux=intId_Article,boolNoNextRecord=FALSE;
ITERATE ITERACION;
END IF;
SET boolPasarX=FALSE,boolPasarZ=FALSE;
-
+ -- Inicializo el contador
REPEAT
- SET Cantidad=Cantidad+1;
+ SET Cantidad=Cantidad+1; -- Incremento el contador en 1
IF (intId_Baldas_aux<>intId_Baldas) THEN
SET intId_Baldas_aux=intId_Baldas;
SET intPOSX=0,intPOSY=0,intPOSZ=0;
END IF;
- IF (boolESAPILABLE AND intPOSZ>0 AND intZ>0) THEN
- IF (boolESABIERTO) THEN
-
- IF (intId_Article=Id_Article_aux) THEN
+ IF (boolESAPILABLE AND intPOSZ>0 AND intZ>0) THEN -- Es Apilable
+ IF (boolESABIERTO) THEN -- abierto
+ -- SET intPOSX=intPOSX+intCmNichoExtra,intPOSZ=0,intPOSY=0,Id_Article_aux=intId_Article;
+ IF (intId_Article=Id_Article_aux) THEN -- mismo articulo
SET boolPasarX=FALSE,boolPasarZ=TRUE;
SET intPOSX=intPOSX-intX;
- ELSE
+ ELSE -- distinto articulo
SET boolPasarX=TRUE,boolPasarZ=TRUE;
SET intPOSY=intY,intPOSZ=intZ;
SET Id_Article_aux=intId_Article;
SET intPOSX=intPOSX+intCmNichoExtra;
END IF;
- ELSE
- IF ((intZ=intZ_ant) AND (intY=intY_ant) AND (intX=intX_ant)) THEN
+ ELSE -- cerrado
+ IF ((intZ=intZ_ant) AND (intY=intY_ant) AND (intX=intX_ant)) THEN -- tienen que ser del mismo tamaño
SET intPOSX=intPOSX-intX;
SET boolPasarX=FALSE,boolPasarZ=FALSE;
ELSE
- CALL ubicator_calcularhuecosvacios (alturabalda,ReturnX,ReturnY,intZ_aux,intId_Estanterias,intId_Baldas,contId_Estanterias);
+ CALL ubicator_calcularhuecosvacios (alturabalda,ReturnX,ReturnY,intZ_aux,intId_Estanterias,intId_Baldas,contId_Estanterias); -- Calculo las cajas vacias
SET intPOSY=intY,intPOSZ=intZ;
SET boolPasarX=TRUE,boolPasarZ=TRUE;
SET intPOSX=intPOSX+intCmNichoExtra;
- END IF;
+ END IF; -- article
END IF;
- ELSE
+ ELSE -- No apilable or posz<>0
IF (NOT boolESAPILABLE AND boolESABIERTO) THEN
SET boolPasarX=FALSE,boolPasarZ=FALSE;
-
- SET intPOSZ=0;
- IF (intId_Article<>Id_Article_aux and Id_Article_aux<>0) THEN
+ -- @@@ cambio abierto no apilable
+ SET intPOSZ=0; -- no se puede subir en altura
+ IF (intId_Article<>Id_Article_aux and Id_Article_aux<>0) THEN -- cambio @@@vicente, añado id_Article_aux<>0
SET intPOSY=0;
END IF;
ELSE
@@ -39278,30 +39995,30 @@ REPEAT
SET intPOSY=intY,intPOSZ=intZ;
END IF;
-
- IF (intPOSX>0) THEN
+ -- @@@@ cambio
+ IF (intPOSX>0) THEN -- SI ES EL PRIMER ELEMENTO (X=0) NO LE INCREMENTE LOS CM EXTRA DEL NICHO si la profundidad es menor no lo incrementa
SET intPOSX=intPOSX+intCmNichoExtra;
END IF;
- END IF;
+ END IF; -- apilable
Condicional:loop
IF (NOT boolPasarX) THEN
IF (NOT boolPasarZ) THEN
- IF (intD-intPOSY>intY) THEN
+ IF (intD-intPOSY>intY) THEN -- cabe de profundo
SET intPOSY=intPOSY+intY;
-
+ -- @@@@ULTIMO CAMBIO
IF (intPOSX>0) and (intId_Article=Id_Article_aux) THEN
IF (intPOSX-intX-intCmNichoExtra<0) THEN
SET intPOSX=0,boolNoNextRecord=TRUE,Cantidad=Cantidad-1;
LEAVE ITERACION;
END IF;
- SET intPOSX=intPOSX-intX-intCmNichoExtra;
+ SET intPOSX=intPOSX-intX-intCmNichoExtra; -- cambio @@@vicente quito descomentando
END IF;
-
+ -- @@@@ fin ultimo cambio
ELSE
SET intPOSY=intY;
END IF;
- END IF;
+ END IF; -- boolpasarz (depth)
IF (intH-intPOSZ>intZ) THEN
SET intPOSZ=intPOSZ+intZ;
@@ -39314,7 +40031,7 @@ REPEAT
SET intPOSY=intY;
SET intPOSX=intPOSX+intX+intCmNichoExtra;
END IF;
- END IF;
+ END IF; -- boolpasarx
IF (intW-intPOSX>intX) THEN
SET intPOSX=intPOSX+intX;
@@ -39325,13 +40042,16 @@ REPEAT
LEAVE Condicional;
END loop Condicional;
- SET ReturnX=intPOSX-intX;
- SET ReturnZ=intSUMAH+intPOSZ-intZ;
- SET ReturnY=intPOSY-intY;
+ SET ReturnX=intPOSX-intX; -- Anchura absoluta x del artículo
+ SET ReturnZ=intSUMAH+intPOSZ-intZ; -- Altura absoluta del cubo
+ SET ReturnY=intPOSY-intY; -- Profundidad absoluta del artículo
SET boolPasarZ=FALSE,boolPasarX=FALSE;
-
+ /*
+ INSERT INTO Ubicator_Cajas (Id_Estanterias,Id_Baldas,modelo,W ,D,H ,Id_Cubo,X,Y,Z,Medida,Id_Article,Article,NumEstanterias)
+ VALUES (intId_Estanterias,intId_Baldas,strmodelo,ReturnX ,ReturnY,ReturnZ ,strId_Cubo,intX,intY,intZ,intMedida,intId_Article,strArticle,contId_Estanterias);
+ */
INSERT INTO Ubicator_Cajas (Id_Estanterias,Id_Baldas,modelo,W ,D,H ,Id_Cubo,X,Y,Z,Medida,Id_Article,Article,NumEstanterias,
NumEtiquetas,POSX,POSY,POSZ,Id_Article_aux)
@@ -39339,7 +40059,7 @@ REPEAT
intEtiquetas,intPOSX,intPOSY,intPOSZ,Id_Article_aux);
SET Id_Article_aux=intId_Article,intZ_aux=intZ,boolNoNextRecord=FALSE;
-
+ -- Cambio
SET intZ_ant=intZ,intY_ant=intY,intX_ant=intX;
UNTIL Cantidad=intEtiquetas END REPEAT;
END WHILE ITERACION;
@@ -39351,9 +40071,9 @@ UNTIL fin END REPEAT;
CLOSE cursor_ubicator;
CLOSE cursor_estanterias;
-
-
-
+-- select * from Ubicator_Cajas;
+-- select * from ubicator_stock;
+-- select * from Ubicator_CajasNoCaben;
END ;;
@@ -39374,8 +40094,8 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `ubicator_ordenacion_distrib`(date DATE,boolORDALFA TINYINT(1), intWAREHOUSE INT,strFILTRO NVARCHAR(255), boolESAPILABLE TINYINT(1),boolESABIERTO TINYINT(1),intCmNichoExtra SMALLINT,inEstant_distrib SMALLINT)
BEGIN
-
-
+-- Inicializo variables
+-- boolESABIERTO --> permite apilar las cajas de diferentes articulos (cerrada) para aprovechar el espacio.
DECLARE intPOSX,intPOSY,intPOSZ,intSUMAH,intCMNICHO_EXTRA INT DEFAULT 0;
DECLARE intId_Estanterias,intW,intD,intId_Baldas,intH,intEtiquetas,
intX,intY,intZ,ReturnX,ReturnY,ReturnZ,Cantidad,intId_Baldas_aux INT DEFAULT 0;
@@ -39388,34 +40108,39 @@ DECLARE strArticle VARCHAR(50);
DECLARE boolCabeCaja,boolPasarZ,boolPasarX,boolNoNextRecord,fin BOOLEAN DEFAULT FALSE;
DECLARE intMedida,intX_ant,intY_ant,IntZ_ant ,intposinicial,intposfinal,auxintId_Estanterias,auxintposinicial,auxintposfinal,intnumdistrib,nestanterias INT(11) DEFAULT 0;
+-- ejemplo: call ubicator_ordenacion(CURDATE(),false,1,'tipo_id = 2',TRUE,FALSE,2,1)
-
-
+-- Declaro el cursor para leer las estanterias y las baldas ordenadas por las baldas. (La primera es la de arriba).
DECLARE cursor_estanterias CURSOR FOR SELECT Id_Estanterias,w,d,modelo,Id_Baldas,h,posinicial,posfinal FROM Estanterias
INNER JOIN Baldas USING (Id_Estanterias)
INNER JOIN Estanterias_distri using (Id_Estanterias)
WHERE IdEstanterias_distri=inEstant_distrib
-
+ -- AND Id_Estanterias>nestanterias
AND posinicial>auxintposinicial
ORDER BY posinicial;
-
+-- Declaro el cursor para leer el recorset de los cubos a colocar en las estanterias obteniendo las variables X,Y,Z del cubo.
DECLARE cursor_ubicator CURSOR FOR SELECT Id_Cubo,Etiquetas,Id_Article,X,Y,Z,Article,Medida FROM ubicator_stock;
-
+ -- Creo la tabla temporal donde devuelvo la ordenación de las cajas.
-DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
+DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; -- handler para el cursor de las estanterias y baldas
DROP TEMPORARY TABLE IF EXISTS Ubicator_Cajas;
CREATE TEMPORARY TABLE IF NOT EXISTS Ubicator_Cajas (Id_Estanterias INT,Id_Baldas SMALLINT,modelo varchar(255),
W SMALLINT,D SMALLINT,H SMALLINT,Id_Cubo VARCHAR(10),X SMALLINT,Y SMALLINT,Z SMALLINT,Medida SMALLINT,Id_Article INT(11),Article varchar(50),NumEstanterias SMALLINT);
+ /*
+ CREATE TEMPORARY TABLE IF NOT EXISTS Ubicator_Cajas(Id_Estanterias INT,Id_Baldas SMALLINT,modelo varchar(255),
+ W SMALLINT,D SMALLINT,H SMALLINT,Id_Cubo VARCHAR(10),X SMALLINT,Y SMALLINT,Z SMALLINT,Medida SMALLINT,
+ Id_Article INT(11),Article varchar(50),NumEstanterias SMALLINT,NumEtiquetas INT,POSX INT (11),POSY INT(11),
+ POSZ INT(11),Id_Article_aux int(11));
+ */
-
-
+-- Creo la tabla temporal donde voy a insertar las cajas que no caben en las estanterias.
DROP TEMPORARY TABLE IF EXISTS Ubicator_CajasNoCaben;
CREATE TEMPORARY TABLE IF NOT EXISTS Ubicator_CajasNoCaben (Id_Cubo VARCHAR(10),Id_Estanteria SMALLINT);
-CALL ubicator (intWAREHOUSE,date,strFILTRO);
+CALL ubicator (intWAREHOUSE,date,strFILTRO); -- Ejecuto el procedimiento de stock para recorrer los articulos con las cajas.
DROP TEMPORARY TABLE IF EXISTS ubicator_stock;
IF (boolORDALFA) THEN
@@ -39426,7 +40151,7 @@ ELSE
ORDER BY Id_Article;
END IF;
-
+-- Open Recordsets
OPEN cursor_estanterias;
OPEN cursor_ubicator;
SET contId_Estanterias=0;
@@ -39443,7 +40168,7 @@ REPEAT
SELECT DISTINCT posinicial-1 INTO auxintposinicial
FROM Estanterias_distri
WHERE Id_Estanterias=auxintId_Estanterias;
-
+ -- SET nestanterias=auxintId_Estanterias-1;
CLOSE cursor_estanterias;
OPEN cursor_estanterias;
@@ -39455,7 +40180,7 @@ REPEAT
END IF;
SET intnumdistrib=intnumdistrib+1;
- IF (done) THEN
+ IF (done) THEN -- Si llega a la ultima balda, empieza de nuevo.
IF (intnumdistrib=0) THEN SUM(H) ELSE 0 END As suma INTO intSUMAH
FROM Baldas WHERE Id_Estanterias=intId_Estanterias and Baldas.Id_Baldas>intId_Baldas;
@@ -39488,71 +40213,71 @@ REPEAT
SELECT Id_Cubo,Etiquetas,Id_Article,X,Y,Z,Article,Medida FROM ubicator_stock ORDER BY Id_Article;
SET Cantidad=0;
END IF;
-
-
+ -- SET Medida=intZ;
+ -- 1. Compruebo que cabe la caja en la estanteria
SELECT ubicator_cabecaja(intX,intY,intZ,intW,intD,intH) INTO boolCabeCaja;
- IF (NOT boolCabeCaja) THEN
+ IF (NOT boolCabeCaja) THEN -- Compruebo si la caja cabe en la estanteria sino la coloco en una tabla temporal.
INSERT INTO Ubicator_CajasNoCaben (Id_Cubo,Id_Estanteria) VALUES (strId_Cubo,intId_Estanterias);
SET Id_Article_aux=intId_Article,boolNoNextRecord=FALSE;
ITERATE ITERACION;
END IF;
SET boolPasarX=FALSE,boolPasarZ=FALSE;
-
+ -- Inicializo el contador
REPEAT
- SET Cantidad=Cantidad+1;
+ SET Cantidad=Cantidad+1; -- Incremento el contador en 1
IF (intId_Baldas_aux<>intId_Baldas) THEN
SET intId_Baldas_aux=intId_Baldas;
SET intPOSX=0,intPOSY=0,intPOSZ=0;
END IF;
- IF (boolESAPILABLE AND intPOSZ>0 AND intZ>0) THEN
- IF (boolESABIERTO) THEN
-
- IF (intId_Article=Id_Article_aux) THEN
+ IF (boolESAPILABLE AND intPOSZ>0 AND intZ>0) THEN -- Es Apilable
+ IF (boolESABIERTO) THEN -- abierto
+ -- SET intPOSX=intPOSX+intCmNichoExtra,intPOSZ=0,intPOSY=0,Id_Article_aux=intId_Article;
+ IF (intId_Article=Id_Article_aux) THEN -- mismo articulo
SET boolPasarX=FALSE,boolPasarZ=TRUE;
SET intPOSX=intPOSX-intX;
- ELSE
+ ELSE -- distinto articulo
SET boolPasarX=TRUE,boolPasarZ=TRUE;
SET intPOSY=intY,intPOSZ=intZ;
SET Id_Article_aux=intId_Article;
SET intPOSX=intPOSX+intCmNichoExtra;
END IF;
- ELSE
- IF ((intZ=intZ_ant) AND (intY=intY_ant) AND (intX=intX_ant)) THEN
+ ELSE -- cerrado
+ IF ((intZ=intZ_ant) AND (intY=intY_ant) AND (intX=intX_ant)) THEN -- tienen que ser del mismo tamaño
SET intPOSX=intPOSX-intX;
SET boolPasarX=FALSE,boolPasarZ=FALSE;
ELSE
- CALL ubicator_calcularhuecosvacios (alturabalda,ReturnX,ReturnY,intZ_aux,intId_Estanterias,intId_Baldas,contId_Estanterias);
+ CALL ubicator_calcularhuecosvacios (alturabalda,ReturnX,ReturnY,intZ_aux,intId_Estanterias,intId_Baldas,contId_Estanterias); -- Calculo las cajas vacias
SET intPOSY=intY,intPOSZ=intZ;
SET boolPasarX=TRUE,boolPasarZ=TRUE;
SET intPOSX=intPOSX+intCmNichoExtra;
- END IF;
+ END IF; -- article
END IF;
- ELSE
+ ELSE -- No apilable or posz<>0
IF (NOT boolESAPILABLE AND boolESABIERTO) THEN
SET boolPasarX=FALSE,boolPasarZ=FALSE;
-
- SET intPOSZ=0;
+ -- @@@ cambio abierto no apilable
+ SET intPOSZ=0; -- no se puede subir en altura
ELSE
SET boolPasarX=TRUE,boolPasarZ=TRUE;
SET intPOSY=intY,intPOSZ=intZ;
END IF;
- IF (intPOSX>0) THEN
+ IF (intPOSX>0) THEN -- SI ES EL PRIMER ELEMENTO (X=0) NO LE INCREMENTE LOS CM EXTRA DEL NICHO
SET intPOSX=intPOSX+intCmNichoExtra;
END IF;
- END IF;
+ END IF; -- apilable
Condicional:loop
IF (NOT boolPasarX) THEN
IF (NOT boolPasarZ) THEN
- IF (intD-intPOSY>intY) THEN
+ IF (intD-intPOSY>intY) THEN -- cabe de profundo
SET intPOSY=intPOSY+intY;
ELSE
SET intPOSY=intY;
END IF;
- END IF;
+ END IF; -- boolpasarz (depth)
IF (intH-intPOSZ>intZ) THEN
SET intPOSZ=intPOSZ+intZ;
@@ -39564,7 +40289,7 @@ REPEAT
SET intPOSZ=intZ;
SET intPOSY=intY, intPOSX=intPOSX+intX+intCmNichoExtra;
END IF;
- END IF;
+ END IF; -- boolpasarx
IF (intW-intPOSX>intX) THEN
SET intPOSX=intPOSX+intX;
@@ -39575,17 +40300,22 @@ REPEAT
LEAVE Condicional;
END loop Condicional;
- SET ReturnX=intPOSX-intX;
- SET ReturnZ=intSUMAH+intPOSZ-intZ;
- SET ReturnY=intPOSY-intY;
+ SET ReturnX=intPOSX-intX; -- Anchura absoluta x del artículo
+ SET ReturnZ=intSUMAH+intPOSZ-intZ; -- Altura absoluta del cubo
+ SET ReturnY=intPOSY-intY; -- Profundidad absoluta del artículo
SET boolPasarZ=FALSE,boolPasarX=FALSE;
INSERT INTO Ubicator_Cajas (Id_Estanterias,Id_Baldas,modelo,W ,D,H ,Id_Cubo,X,Y,Z,Medida,Id_Article,Article,NumEstanterias)
VALUES (intId_Estanterias,intId_Baldas,strmodelo,ReturnX ,ReturnY,ReturnZ ,strId_Cubo,intX,intY,intZ,intMedida,intId_Article,strArticle,contId_Estanterias);
-
+ /*
+ INSERT INTO Ubicator_Cajas (Id_Estanterias,Id_Baldas,modelo,W ,D,H ,Id_Cubo,X,Y,Z,Medida,Id_Article,Article,NumEstanterias,
+ NumEtiquetas,POSX,POSY,POSZ,Id_Article_aux)
+ VALUES (intId_Estanterias,intId_Baldas,strmodelo,ReturnX ,ReturnY,ReturnZ ,strId_Cubo,intX,intY,intZ,intMedida,intId_Article,strArticle,contId_Estanterias,
+ intEtiquetas,intPOSX,intPOSY,intPOSZ,Id_Article_aux);
+ */
SET Id_Article_aux=intId_Article,intZ_aux=intZ,boolNoNextRecord=FALSE;
-
+ -- Cambio
SET intZ_ant=intZ,intY_ant=intY,intX_ant=intX;
UNTIL Cantidad=intEtiquetas END REPEAT;
END WHILE ITERACION;
@@ -39598,9 +40328,9 @@ UNTIL fin END REPEAT;
CLOSE cursor_ubicator;
CLOSE cursor_estanterias;
-
-
-
+-- select * from Ubicator_Cajas;
+-- select * from ubicator_stock;
+-- select * from Ubicator_CajasNoCaben;
END ;;
@@ -39617,7 +40347,7 @@ DELIMITER ;
/*!50003 SET character_set_results = utf8 */ ;
/*!50003 SET collation_connection = utf8_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
-/*!50003 SET sql_mode = '' */ ;
+/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `ubicator_test`(IN i_wh TINYINT, IN d_fecha DATE,IN filtro VARCHAR(255))
BEGIN
@@ -39664,10 +40394,11 @@ SELECT Id_Article article_id,SUM(Cantidad) amount FROM (
) t GROUP BY article_id;
+/*
+SELECT * from stock_actual;*/
-
-
-CALL hedera.sql_query (sql_printf('
+-- TEMPORARY
+CALL util.exec (sql_printf('
CREATE TEMPORARY TABLE IF NOT EXISTS vn2008.tmp_ubicator_stock AS
SELECT A.Id_Article,A.Article, T.Id_Cubo,IF(Z > 0,Z,0) as z,x,y,
CEIL(S.Suma/T.grouping) as etiquetas,A.Medida,A.Nicho
@@ -39711,7 +40442,14 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `unary_delete`(v_node INT, v_delete bool)
BEGIN
-
+/**
+ * Borra un nodo. Se puede indicar si se quieren mantener los hijos.
+ * En este caso los hijos pasan al padre del nodo.
+ * Si no tiene padre, los hijos pasaran a ser padres.
+ *
+ * @v_node: Nodo que se quiere borrar.
+ * @v_delete: Se indica si se borran los nodos.
+ **/
DECLARE v_parent INT;
@@ -39748,7 +40486,12 @@ DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `unary_insert`(OUT v_unary INT, v_parent INT)
BEGIN
-
+ /**
+ * Inserta un nuevo nodo. Se puede indicar el padre.
+ *
+ * @v_parent: Nodo padre.
+ * @v_unary: Id del nuevo nodo.
+ **/
INSERT INTO unary(parent) VALUES(v_parent);
@@ -39772,7 +40515,11 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `unary_leaves`(v_top INT)
BEGIN
-
+/**
+ * A partir de un nodo devuelve todos sus descendientes.
+ *
+ * @table tmp.tree Tabla con los ids de los nodos descendientes;
+ **/
DECLARE v_count INT;
DECLARE v_parent INT;
DECLARE v_depth INT DEFAULT 0;
@@ -39839,7 +40586,14 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `unary_scan_ident`(v_top INT, v_space INT)
BEGIN
-
+/**
+ * A partir de un nodo devuelve el id y el nombre del nodod y sus hijos.
+ * El nombre viene identado segun el numero de espacios multiplicado por la profundiad del nodo.
+ *
+ * v_top: Id del nodo padre.
+ * v_space: Spacios a dejar al identar,
+ * @table tmp.tree_ident Tabla con los ids de los nodos descendientes y su nombre identado;
+ **/
DROP TEMPORARY TABLE IF EXISTS tmp.tree_ident;
CALL tree_leaves(v_top);
@@ -39871,7 +40625,13 @@ DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `unary_scan_insert`(v_name VARCHAR(45), v_parent INT, v_type VARCHAR(45))
BEGIN
-
+ /**
+ * Inserta un nuevo nodo de tipo unary_scan. Se puede indicar el padre.
+ *
+ * @v_name: Nombre del nodo.
+ * @v_parent: Nodo padre.
+ * @v_type: Tipo del nodo a crear.
+ **/
DECLARE v_unary INT;
@@ -39897,7 +40657,11 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `unary_tops`()
BEGIN
-
+/**
+ * Devuelve todos los nodos que no tienen padre.
+ *
+ * @table tmp.tree Tabla con los ids de los nodos que no tienen padre;
+ **/
DROP TEMPORARY TABLE IF EXISTS tmp.tree;
CREATE TEMPORARY TABLE tmp.tree
@@ -39925,7 +40689,15 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `unary_update`(v_node INT, v_new_parent INT, v_move bool)
BEGIN
-
+/**
+ * Cambia el padre de un nodo. Se puede indicar si se quieren mover los hijos.
+ * En este caso los hijos pasan al padre del nodo.
+ * Si no tiene padre, los hijos pasaran a ser padres.
+ *
+ * @v_node: Nodo que se quiere mover.
+ * @v_new_parent: Padre al que se quiere mover el nodo.
+ * @v_move: Se indica si se mueven los nodos.
+ **/
DECLARE v_parent INT;
@@ -40075,27 +40847,22 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `vips_in_a_week`(IN strCONDITION varchar(512))
+CREATE DEFINER=`root`@`%` PROCEDURE `vips_in_a_week`(vCondition VARCHAR(512))
BEGIN
-call sql_query( CONCAT('SELECT C.Id_Cliente, C.Cliente, RED(SUM((M.Cantidad * M.Preu) * 100 - M.Descuento) / 100) as Importe
- FROM Clientes C INNER JOIN Tickets T ON T.Id_Cliente = C.Id_Cliente
- INNER JOIN Movimientos M ON M.Id_Ticket = T.Id_Ticket
- INNER JOIN Articles A ON A.Id_Article = M.Id_Article
- JOIN Tipos TP ON A.tipo_id = TP.tipo_id
- INNER JOIN Trabajadores TR ON TR.Id_Trabajador = TP.Id_Trabajador
- WHERE ',
-
- strCONDITION,
-
-
- ' GROUP BY Id_Cliente
- HAVING Importe > 0
- ORDER BY Importe DESC
- ')
-
-
-);
+ CALL util.exec (CONCAT(
+ 'SELECT C.Id_Cliente, C.Cliente, RED(SUM((M.Cantidad * M.Preu) * 100 - M.Descuento) / 100) as Importe
+ FROM vn2008.Clientes C
+ JOIN vn2008.Tickets T ON T.Id_Cliente = C.Id_Cliente
+ JOIN vn2008.Movimientos M ON M.Id_Ticket = T.Id_Ticket
+ JOIN vn2008.Articles A ON A.Id_Article = M.Id_Article
+ JOIN vn2008.Tipos TP ON A.tipo_id = TP.tipo_id
+ JOIN vn2008.Trabajadores TR ON TR.Id_Trabajador = TP.Id_Trabajador
+ WHERE ', vCondition, '
+ GROUP BY Id_Cliente
+ HAVING Importe > 0
+ ORDER BY Importe DESC'
+ ));
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -40112,26 +40879,21 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `vips_in_a_week_by_client`(IN strCONDITION varchar(512))
+CREATE DEFINER=`root`@`%` PROCEDURE `vips_in_a_week_by_client`(vCondition VARCHAR(512))
BEGIN
-
-call sql_query( CONCAT('SELECT M.Id_Article, A.Article, A.Medida, A.Color, A.Categoria,
- SUM(M.Cantidad) Cantidad, M.Preu, M.Descuento,
- RED(SUM(M.Cantidad) * M.Preu * (100 - M.Descuento) / 100) as Importe
- FROM Clientes C INNER JOIN Tickets T ON T.Id_Cliente = C.Id_Cliente
- INNER JOIN Movimientos M ON M.Id_Ticket = T.Id_Ticket
- INNER JOIN Articles A ON A.Id_Article = M.Id_Article
- JOIN Tipos TP ON A.tipo_id = TP.tipo_id
- INNER JOIN Trabajadores TR ON TR.Id_Trabajador = TP.Id_Trabajador
- WHERE ',
-
- strCONDITION,
-
- ' GROUP BY M.Id_Article, A.Article, A.Medida, A.Color, A.Categoria, M.Preu, M.Descuento '
-
- )
- );
-
+ CALL util.exec (CONCAT(
+ 'SELECT M.Id_Article, A.Article, A.Medida, A.Color, A.Categoria,
+ SUM(M.Cantidad) Cantidad, M.Preu, M.Descuento,
+ RED(SUM(M.Cantidad) * M.Preu * (100 - M.Descuento) / 100) as Importe
+ FROM vn2008.Clientes C
+ JOIN vn2008.Tickets T ON T.Id_Cliente = C.Id_Cliente
+ JOIN vn2008.Movimientos M ON M.Id_Ticket = T.Id_Ticket
+ JOIN vn2008.Articles A ON A.Id_Article = M.Id_Article
+ JOIN vn2008.Tipos TP ON A.tipo_id = TP.tipo_id
+ JOIN vn2008.Trabajadores TR ON TR.Id_Trabajador = TP.Id_Trabajador
+ WHERE ', vCondition, '
+ GROUP BY M.Id_Article, A.Article, A.Medida, A.Color, A.Categoria, M.Preu, M.Descuento'
+ ));
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -40151,41 +40913,78 @@ DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `volumetricoReparto`( IN IdTicket INT(11), OUT atot DOUBLE )
BEGIN
+
+
DECLARE ticket INT(11);
+
+
DECLARE rutaid INT(11);
+
+
DECLARE art INT(11);
+
+
DECLARE ax, ay, az, atot double;
+
+
DECLARE CUR1 CURSOR FOR SELECT a.Id_Article FROM vn2008.Movimientos m, vn2008.Articles a
+
WHERE m.Id_Ticket = IdTicket AND m.Id_Article = a.Id_Article ;
+
+
DECLARE CONTINUE HANDLER FOR NOT FOUND SET @atot = 0;
+
+
set @atot = 0;
+
+
OPEN CUR1;
+
+
REPEAT
+
+
FETCH CUR1 INTO art ;
+
+
SELECT x, y, z into ax,ay,az
+
FROM vn2008.Cubos cu, vn2008.Compres co
+
WHERE cu.Id_Cubo = co.Id_Cubo AND Id_Compra =
+
(SELECT max(Id_Compra) FROM vn2008.Compres c
+
WHERE c.Id_Article = @art);
+
+
set @atot = @atot +((@ax * @ay * @az)* 1,10);
+
+
UNTIL done END REPEAT;
+
CLOSE CUR1;
+
+
+
select 'hola ',@atot;
+
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -40204,35 +41003,65 @@ DELIMITER ;
DELIMITER ;;
CREATE DEFINER=`root`@`%` PROCEDURE `weekly_sales_new`(v_wh SMALLINT, v_date_ini DATETIME, v_date_end DATETIME)
BEGIN
+
IF v_date_end IS NULL THEN
+
SET v_date_end = v_date_ini;
+
END IF;
+
+
SET v_date_end = TIMESTAMPADD(DAY, 1, v_date_end);
+
+
CREATE TEMPORARY TABLE weekly_ticket
+
(INDEX idx USING HASH (Id_Ticket))
+
ENGINE = MEMORY
+
SELECT Id_Ticket, to_weeks (DATE(Fecha)) week, warehouse_id
+
FROM Tickets t
+
JOIN warehouse w ON w.id = t.warehouse_id
+
WHERE Fecha >= v_date_ini AND Fecha < v_date_end
+
AND Id_Cliente NOT IN (400, 200)
+
AND NOT w.fuente
+
AND v_wh IN (t.warehouse_id, 0);
+
+
CREATE TEMPORARY TABLE weekly_sales
+
ENGINE = MEMORY
+
SELECT week, warehouse_id, a.Id_Article item_id, SUM(Cantidad) AS amount,
+
SUM(Cantidad * Preu * (100 - Descuento) / 100) AS price
+
FROM Movimientos m
+
JOIN weekly_ticket t USING (Id_Ticket)
+
JOIN Articles a USING (Id_Article)
+
INNER JOIN Tipos USING (tipo_id)
+
WHERE reino_id != 6
+
GROUP BY week, warehouse_id, item_id;
+
+
DROP TEMPORARY TABLE weekly_ticket;
+
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
@@ -40281,7 +41110,7 @@ DELIMITER ;
/*!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 DROP PROCEDURE IF EXISTS `__risk_vs_client_listbeta` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
@@ -40291,26621 +41120,98 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `__camiones`(vWarehouse INT, vDate DATE)
+CREATE DEFINER=`root`@`%` PROCEDURE `__risk_vs_client_listbeta`(maxRiskDate DATE)
BEGIN
- CALL inventario_multiple_reservas(vDate, 7, 4848);
- CALL article_multiple_buy(vDate, 7);
-
- SELECT Temperatura
- ,ROUND(SUM(Etiquetas * cm3_2(Id_Cubo, Id_Article))) AS cm3
- ,ROUND(SUM(IF(scanned,Etiquetas,0) * cm3_2(Id_Cubo, Id_Article))) AS cm3s
- ,ROUND(SUM(Vida * cm3_2(Id_Cubo, Id_Article))) AS cm3e
- FROM (
- SELECT t.Temperatura, c.Etiquetas, c.Id_Cubo, c.Id_Article, b.scanned, c.Vida
- 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
- WHERE tr.warehouse_id = vWarehouse
- AND tr.landing = vDate
- UNION ALL
- SELECT t.Temperatura, @e:= ai.visible/c.packing, c.Id_Cubo, ai.article_id, @e, @e
- FROM article_inventory ai
- JOIN Compres c ON c.Id_Compra = ai.buy_id
- JOIN Articles a ON a.Id_Article = ai.article_id
- JOIN Tipos t ON t.tipo_id = a.tipo_id
- WHERE avalaible > 0
- ) sub
- GROUP BY Temperatura;
-
- 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 `__sql_signal` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `__sql_signal`(v_code CHAR(35))
-BEGIN
- SIGNAL SQLSTATE '45000'
- SET MESSAGE_TEXT = v_code;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-
---
--- Current Database: `bi`
---
-
-CREATE DATABASE /*!32312 IF NOT EXISTS*/ `bi` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
-
-USE `bi`;
-
---
--- Table structure for table `Equalizator`
---
-
-DROP TABLE IF EXISTS `Equalizator`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `Equalizator` (
- `Vista` int(11) NOT NULL,
- `Pedido` int(11) DEFAULT NULL,
- `Impreso` int(11) DEFAULT NULL,
- `Encajado` int(11) DEFAULT NULL,
- PRIMARY KEY (`Vista`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `Greuge_Evolution`
---
-
-DROP TABLE IF EXISTS `Greuge_Evolution`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `Greuge_Evolution` (
- `Id_Cliente` int(11) NOT NULL,
- `Fecha` date NOT NULL,
- `Greuge` decimal(10,2) NOT NULL DEFAULT '0.00',
- `Ventas` decimal(10,2) NOT NULL DEFAULT '0.00',
- `Fosil` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'greuge fósil, correspondiente a los clientes muertos',
- `Recobro` decimal(10,2) NOT NULL DEFAULT '0.00',
- PRIMARY KEY (`Id_Cliente`,`Fecha`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacenamos la evolucion del greuge de los ultimos dias ';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `Greuge_comercial_recobro`
---
-
-DROP TABLE IF EXISTS `Greuge_comercial_recobro`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `Greuge_comercial_recobro` (
- `Id_Trabajador` int(11) NOT NULL,
- `recobro` decimal(10,2) NOT NULL DEFAULT '0.00',
- `peso_cartera` decimal(10,2) NOT NULL DEFAULT '0.00',
- PRIMARY KEY (`Id_Trabajador`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `Greuges_comercial_detail`
---
-
-DROP TABLE IF EXISTS `Greuges_comercial_detail`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `Greuges_comercial_detail` (
- `Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `Id_Trabajador` int(10) unsigned NOT NULL,
- `Comentario` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
- `Importe` decimal(10,2) NOT NULL,
- `Fecha` datetime DEFAULT NULL,
- PRIMARY KEY (`Id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=FIXED;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `Last_buy_id`
---
-
-DROP TABLE IF EXISTS `Last_buy_id`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `Last_buy_id` (
- `Id_Article` int(11) NOT NULL DEFAULT '90',
- `Id_Compra` int(11) NOT NULL DEFAULT '0',
- `warehouse_id` smallint(6) unsigned NOT NULL,
- PRIMARY KEY (`warehouse_id`,`Id_Article`),
- UNIQUE KEY `Id_Compra_UNIQUE` (`Id_Compra`),
- CONSTRAINT `Id_CompraFK` FOREIGN KEY (`Id_Compra`) REFERENCES `vn2008`.`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 `Last_buy_idBackUp`
---
-
-DROP TABLE IF EXISTS `Last_buy_idBackUp`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `Last_buy_idBackUp` (
- `Id_Article` int(11) NOT NULL DEFAULT '90',
- `Id_Compra` int(11) NOT NULL DEFAULT '0',
- `warehouse_id` smallint(6) unsigned NOT NULL,
- PRIMARY KEY (`Id_Article`,`warehouse_id`),
- UNIQUE KEY `Id_Compra_UNIQUE` (`Id_Compra`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `Radar`
---
-
-DROP TABLE IF EXISTS `Radar`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `Radar` (
- `Propio` int(1) NOT NULL DEFAULT '0',
- `Credito` double NOT NULL DEFAULT '0',
- `Riesgo` double(19,2) DEFAULT NULL,
- `Greuge` double DEFAULT NULL,
- `Id_Ticket` int(11) NOT NULL DEFAULT '0',
- `wh` smallint(6) unsigned NOT NULL DEFAULT '1',
- `Fecha` datetime NOT NULL,
- `Alias` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `Vista` int(11) DEFAULT '0',
- `Tipo` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'RECOGIDA',
- `Id_Trabajador` int(11) DEFAULT '20',
- `Solucion` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL,
- `Localizacion` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
- `Estado` varchar(15) CHARACTER SET utf8 DEFAULT NULL,
- `Fecha_Simple` date DEFAULT NULL,
- `Id_Comercial` int(11) DEFAULT '20',
- `Risk` double NOT NULL DEFAULT '0',
- `Rojo` bigint(21) DEFAULT '0',
- `Naranja` bigint(21) DEFAULT '0',
- `Amarillo` bigint(21) DEFAULT '0'
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `Ticket_Portes`
---
-
-DROP TABLE IF EXISTS `Ticket_Portes`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `Ticket_Portes` (
- `Id_Ticket` int(11) NOT NULL,
- `rate` tinyint(4) NOT NULL COMMENT 'Tarifa',
- `real_amount` double NOT NULL COMMENT 'Cantidad pactada con la agencia',
- `payed_amount` double NOT NULL COMMENT 'Cantidad reflejada en el Ticket',
- PRIMARY KEY (`Id_Ticket`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `VelocityKK`
---
-
-DROP TABLE IF EXISTS `VelocityKK`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `VelocityKK` (
- `tipo_id` int(11) NOT NULL,
- `Fecha` datetime NOT NULL,
- `Disponible` int(11) DEFAULT NULL,
- `Visible` int(11) DEFAULT NULL,
- `velocity_id` int(11) NOT NULL AUTO_INCREMENT,
- PRIMARY KEY (`velocity_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `XDiario_ALL`
---
-
-DROP TABLE IF EXISTS `XDiario_ALL`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `XDiario_ALL` (
- `empresa_id` int(5) NOT NULL,
- `SUBCTA` varchar(11) COLLATE utf8_unicode_ci NOT NULL,
- `Eurodebe` double DEFAULT NULL,
- `Eurohaber` double DEFAULT NULL,
- `Fecha` date DEFAULT NULL,
- `FECHA_EX` date DEFAULT NULL,
- KEY `Cuenta` (`SUBCTA`),
- KEY `empresa` (`empresa_id`),
- KEY `Fecha` (`Fecha`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `analisis_grafico_simple`
---
-
-DROP TABLE IF EXISTS `analisis_grafico_simple`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `analisis_grafico_simple` (
- `Año` smallint(5) unsigned NOT NULL,
- `Semana` tinyint(3) unsigned NOT NULL,
- `Importe` double DEFAULT NULL
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `analisis_grafico_ventas`
---
-
-DROP TABLE IF EXISTS `analisis_grafico_ventas`;
-/*!50001 DROP VIEW IF EXISTS `analisis_grafico_ventas`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `analisis_grafico_ventas` AS SELECT
- 1 AS `Año`,
- 1 AS `Semana`,
- 1 AS `Importe`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `analisis_ventas`
---
-
-DROP TABLE IF EXISTS `analisis_ventas`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `analisis_ventas` (
- `Familia` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
- `Reino` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
- `Comercial` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
- `Comprador` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
- `Provincia` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
- `almacen` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
- `Año` smallint(5) unsigned NOT NULL,
- `Mes` tinyint(3) unsigned NOT NULL,
- `Semana` tinyint(3) unsigned NOT NULL,
- `Vista` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `Importe` double NOT NULL,
- KEY `Año` (`Año`,`Semana`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `analisis_ventas_almacen_evolution`
---
-
-DROP TABLE IF EXISTS `analisis_ventas_almacen_evolution`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `analisis_ventas_almacen_evolution` (
- `Semana` int(11) NOT NULL,
- `Almacen` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
- `Ventas` int(11) NOT NULL,
- `Año` int(11) NOT NULL,
- `Periodo` int(11) NOT NULL,
- KEY `Almacen` (`Almacen`,`Periodo`),
- KEY `Periodo` (`Periodo`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `analisis_ventas_comprador_evolution`
---
-
-DROP TABLE IF EXISTS `analisis_ventas_comprador_evolution`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `analisis_ventas_comprador_evolution` (
- `semana` int(11) NOT NULL,
- `comprador` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
- `ventas` int(11) NOT NULL,
- `año` int(11) NOT NULL,
- `periodo` int(11) NOT NULL,
- UNIQUE KEY `comprador` (`comprador`,`periodo`),
- KEY `periodo` (`periodo`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `analisis_ventas_familia_evolution`
---
-
-DROP TABLE IF EXISTS `analisis_ventas_familia_evolution`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `analisis_ventas_familia_evolution` (
- `semana` int(11) NOT NULL,
- `familia` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `ventas` int(11) NOT NULL,
- `año` int(11) NOT NULL,
- `periodo` int(11) NOT NULL,
- KEY `familia` (`familia`,`periodo`),
- KEY `periodo` (`periodo`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `analisis_ventas_provincia_evolution`
---
-
-DROP TABLE IF EXISTS `analisis_ventas_provincia_evolution`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `analisis_ventas_provincia_evolution` (
- `semana` int(11) NOT NULL,
- `provincia` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
- `ventas` int(11) NOT NULL,
- `año` int(11) NOT NULL,
- `periodo` int(11) NOT NULL,
- UNIQUE KEY `provincia` (`provincia`,`periodo`),
- KEY `periodo` (`periodo`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `analisis_ventas_reino_evolution`
---
-
-DROP TABLE IF EXISTS `analisis_ventas_reino_evolution`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `analisis_ventas_reino_evolution` (
- `semana` int(11) NOT NULL,
- `reino` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
- `ventas` int(11) NOT NULL,
- `año` int(11) NOT NULL,
- `periodo` int(11) NOT NULL,
- UNIQUE KEY `reino` (`reino`,`periodo`),
- KEY `periodo` (`periodo`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `analisis_ventas_simple`
---
-
-DROP TABLE IF EXISTS `analisis_ventas_simple`;
-/*!50001 DROP VIEW IF EXISTS `analisis_ventas_simple`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `analisis_ventas_simple` AS SELECT
- 1 AS `Año`,
- 1 AS `Semana`,
- 1 AS `Importe`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `analisis_ventas_vendedor_evolution`
---
-
-DROP TABLE IF EXISTS `analisis_ventas_vendedor_evolution`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `analisis_ventas_vendedor_evolution` (
- `semana` int(11) NOT NULL,
- `vendedor` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
- `ventas` int(11) NOT NULL,
- `año` int(11) NOT NULL,
- `periodo` int(11) NOT NULL,
- UNIQUE KEY `vendedor` (`vendedor`,`periodo`),
- KEY `periodo` (`periodo`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `analisis_ventas_vista_evolution`
---
-
-DROP TABLE IF EXISTS `analisis_ventas_vista_evolution`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `analisis_ventas_vista_evolution` (
- `semana` int(11) NOT NULL,
- `vista` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
- `ventas` int(11) NOT NULL,
- `año` int(11) NOT NULL,
- `periodo` int(11) NOT NULL,
- UNIQUE KEY `vista` (`vista`,`periodo`),
- KEY `periodo` (`periodo`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `calidad_detalle`
---
-
-DROP TABLE IF EXISTS `calidad_detalle`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `calidad_detalle` (
- `Id_Cliente` int(11) NOT NULL,
- `calidad_parametros_id` int(2) NOT NULL,
- `valor` int(3) DEFAULT NULL,
- PRIMARY KEY (`Id_Cliente`,`calidad_parametros_id`),
- KEY `calidad_parametros_detalle_idx` (`calidad_parametros_id`),
- CONSTRAINT `calidad_parametros_detalle` FOREIGN KEY (`calidad_parametros_id`) REFERENCES `calidad_parametros` (`calidad_parametros_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 `calidad_parametros`
---
-
-DROP TABLE IF EXISTS `calidad_parametros`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `calidad_parametros` (
- `calidad_parametros_id` int(2) NOT NULL,
- `descripcion` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`calidad_parametros_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `claims_ratio`
---
-
-DROP TABLE IF EXISTS `claims_ratio`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `claims_ratio` (
- `Id_Cliente` int(11) NOT NULL DEFAULT '0',
- `Consumo` decimal(10,2) DEFAULT NULL,
- `Reclamaciones` decimal(10,2) DEFAULT NULL,
- `Ratio` decimal(5,2) DEFAULT NULL,
- `recobro` decimal(5,2) DEFAULT NULL,
- `inflacion` decimal(5,2) NOT NULL DEFAULT '1.00',
- PRIMARY KEY (`Id_Cliente`),
- CONSTRAINT `claims_ratio_ibfk_1` FOREIGN KEY (`Id_Cliente`) REFERENCES `vn2008`.`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 `comparativa_clientes`
---
-
-DROP TABLE IF EXISTS `comparativa_clientes`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `comparativa_clientes` (
- `Fecha` date NOT NULL DEFAULT '0000-00-00',
- `Id_Cliente` int(11) NOT NULL DEFAULT '0',
- `Propietario` int(11) DEFAULT NULL,
- `titular` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
- `suplente` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
- `trabajador` int(11) DEFAULT NULL,
- `actual` double DEFAULT NULL,
- `pasado` double DEFAULT NULL,
- `concepto` varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '',
- KEY `cc_data_indez` (`Fecha`),
- KEY `cc_Id_Cliente_index` (`Id_Cliente`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `customerDebtInventory`
---
-
-DROP TABLE IF EXISTS `customerDebtInventory`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `customerDebtInventory` (
- `Id_Cliente` int(11) NOT NULL,
- `Debt` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'CREATE TABLE bi.customerDebtInventory\n\nSELECT Id_Cliente, sum(Euros) as Debt\n\nFROM \n(\nSELECT Id_Cliente, Entregado as Euros\n\nFROM Recibos \n\nWHERE Fechacobro < ''2017-01-01\n''\nUNION ALL\n\nSELECT Id_Cliente, - Importe \nFROM Facturas\nWHERE Fecha < ''2017-01-01''\n) sub \nGROUP BY Id_Cliente',
- PRIMARY KEY (`Id_Cliente`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `customerRiskOverdue`
---
-
-DROP TABLE IF EXISTS `customerRiskOverdue`;
-/*!50001 DROP VIEW IF EXISTS `customerRiskOverdue`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `customerRiskOverdue` AS SELECT
- 1 AS `customer_id`,
- 1 AS `amount`,
- 1 AS `company_id`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `customer_risk`
---
-
-DROP TABLE IF EXISTS `customer_risk`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `customer_risk` (
- `customer_id` int(11) NOT NULL DEFAULT '0',
- `company_id` smallint(6) unsigned NOT NULL DEFAULT '0',
- `amount` decimal(10,2) DEFAULT NULL,
- PRIMARY KEY (`customer_id`,`company_id`),
- KEY `company_id` (`company_id`),
- CONSTRAINT `customer_risk_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `customer_risk_ibfk_2` FOREIGN KEY (`company_id`) REFERENCES `vn2008`.`empresa` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Saldo de apertura < 2015-01-01';
-/*!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` (
- `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
- `created` 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 `defaulters`
---
-
-DROP TABLE IF EXISTS `defaulters`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `defaulters` (
- `client` int(11) NOT NULL,
- `date` date NOT NULL,
- `amount` double NOT NULL DEFAULT '0',
- `defaulterSince` date DEFAULT NULL,
- `hasChanged` tinyint(1) DEFAULT NULL,
- PRIMARY KEY (`client`,`date`),
- KEY `client` (`client`),
- KEY `date` (`date`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `defaulting`
---
-
-DROP TABLE IF EXISTS `defaulting`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `defaulting` (
- `date` date NOT NULL,
- `amount` double NOT NULL,
- PRIMARY KEY (`date`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `f_tvc`
---
-
-DROP TABLE IF EXISTS `f_tvc`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `f_tvc` (
- `Id_Ticket` int(11) NOT NULL,
- PRIMARY KEY (`Id_Ticket`),
- CONSTRAINT `id_ticket_to_comisionantes` FOREIGN KEY (`Id_Ticket`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacenamos la lista de tickets para agilizar la consulta. Corresponde a los clientes REAL y en los almacenes COMISIONANTES';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `facturacion_media_anual`
---
-
-DROP TABLE IF EXISTS `facturacion_media_anual`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `facturacion_media_anual` (
- `Id_Cliente` int(11) NOT NULL,
- `Consumo` double(17,0) DEFAULT NULL,
- PRIMARY KEY (`Id_Cliente`),
- CONSTRAINT `fmaId_Cliente` FOREIGN KEY (`Id_Cliente`) REFERENCES `vn2008`.`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 */;
-
---
--- Temporary view structure for view `last_Id_Cubo`
---
-
-DROP TABLE IF EXISTS `last_Id_Cubo`;
-/*!50001 DROP VIEW IF EXISTS `last_Id_Cubo`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `last_Id_Cubo` AS SELECT
- 1 AS `Id_Compra`,
- 1 AS `Id_Article`,
- 1 AS `warehouse_id`,
- 1 AS `Id_Cubo`,
- 1 AS `Packing`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `lastaction`
---
-
-DROP TABLE IF EXISTS `lastaction`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `lastaction` (
- `Id_Cliente` int(11) unsigned NOT NULL,
- `Cliente` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `Ultima_accion` date DEFAULT NULL,
- `Comercial` varchar(3) CHARACTER SET utf8 DEFAULT NULL,
- 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 `live_counter`
---
-
-DROP TABLE IF EXISTS `live_counter`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `live_counter` (
- `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `amount` double NOT NULL,
- PRIMARY KEY (`odbc_date`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `mana_inventory_kk`
---
-
-DROP TABLE IF EXISTS `mana_inventory_kk`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `mana_inventory_kk` (
- `Id_Trabajador` int(11) NOT NULL,
- `mana` double NOT NULL DEFAULT '0',
- `dated` date NOT NULL,
- PRIMARY KEY (`Id_Trabajador`,`dated`),
- CONSTRAINT `fk_trabajador_mana_inventory` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) 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_log`
---
-
-DROP TABLE IF EXISTS `movimientos_log`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `movimientos_log` (
- `idmovimientos_log` int(11) NOT NULL AUTO_INCREMENT,
- `Id_Movimiento` int(11) NOT NULL,
- `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `Id_Trabajador` int(11) NOT NULL,
- `field_name` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,
- `new_value` double DEFAULT NULL,
- PRIMARY KEY (`idmovimientos_log`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `partitioning_information`
---
-
-DROP TABLE IF EXISTS `partitioning_information`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `partitioning_information` (
- `schema_name` varchar(10) CHARACTER SET utf8 NOT NULL,
- `table_name` varchar(20) CHARACTER SET utf8 NOT NULL,
- `date_field` varchar(20) CHARACTER SET utf8 DEFAULT NULL,
- `table_depending` varchar(15) CHARACTER SET utf8 DEFAULT NULL,
- `execution_order` tinyint(3) unsigned NOT NULL,
- PRIMARY KEY (`schema_name`,`table_name`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `primer_pedido`
---
-
-DROP TABLE IF EXISTS `primer_pedido`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `primer_pedido` (
- `Id_Cliente` int(11) NOT NULL,
- `Id_Ticket` int(11) NOT NULL,
- `month` tinyint(1) NOT NULL,
- `year` smallint(2) NOT NULL,
- `total` decimal(10,2) NOT NULL DEFAULT '0.00',
- 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 `rotacion`
---
-
-DROP TABLE IF EXISTS `rotacion`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `rotacion` (
- `Id_Article` int(11) NOT NULL,
- `warehouse_id` smallint(6) unsigned NOT NULL,
- `total` int(10) NOT NULL DEFAULT '0',
- `rotacion` decimal(10,4) NOT NULL DEFAULT '0.0000',
- `cm3` int(11) NOT NULL DEFAULT '0',
- `almacenaje` decimal(10,4) NOT NULL DEFAULT '0.0000',
- `manipulacion` decimal(10,4) NOT NULL DEFAULT '0.0000',
- `auxiliar` decimal(10,4) NOT NULL DEFAULT '0.0000',
- `mermas` decimal(10,4) NOT NULL DEFAULT '0.0000',
- PRIMARY KEY (`Id_Article`,`warehouse_id`),
- KEY `id_article_rotacion_idx` (`Id_Article`),
- KEY `warehouse_id_rotacion_idx` (`warehouse_id`),
- CONSTRAINT `id_article_rotaci` FOREIGN KEY (`Id_Article`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `warehouse_id_rotaci` FOREIGN KEY (`warehouse_id`) REFERENCES `vn2008`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los valores de rotacion en los ultimos 365 dias';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `saldos_bancos`
---
-
-DROP TABLE IF EXISTS `saldos_bancos`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `saldos_bancos` (
- `Semana` int(2) NOT NULL,
- `Mes` int(2) NOT NULL,
- `Año` int(4) NOT NULL,
- `Entrada` double DEFAULT NULL,
- `Salida` decimal(32,2) DEFAULT NULL,
- `Saldo` double DEFAULT NULL,
- `Id_Banco` int(11) NOT NULL DEFAULT '0',
- `empresa_id` int(5) unsigned NOT NULL DEFAULT '0',
- `Empresa` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT ''
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `saldos_bancos_pordia`
---
-
-DROP TABLE IF EXISTS `saldos_bancos_pordia`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `saldos_bancos_pordia` (
- `Fecha` date NOT NULL,
- `Entrada` double DEFAULT NULL,
- `Salida` decimal(32,2) DEFAULT NULL,
- `Saldo` double DEFAULT NULL,
- `Id_Banco` int(11) NOT NULL DEFAULT '0',
- `empresa_id` int(5) unsigned NOT NULL DEFAULT '0',
- `Empresa` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT '',
- `Año` int(4) NOT NULL,
- `Mes` int(2) NOT NULL,
- `Dia` int(2) NOT NULL
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `sales`
---
-
-DROP TABLE IF EXISTS `sales`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `sales` (
- `Id_Trabajador` int(10) unsigned NOT NULL,
- `year` int(10) unsigned NOT NULL,
- `month` int(10) unsigned NOT NULL,
- `weight` int(11) NOT NULL DEFAULT '0',
- `boss_aid` int(10) NOT NULL DEFAULT '0',
- `boss_id` int(10) NOT NULL DEFAULT '0',
- `comision` int(11) DEFAULT NULL,
- PRIMARY KEY (`Id_Trabajador`,`year`,`month`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `tarifa_componentes`
---
-
-DROP TABLE IF EXISTS `tarifa_componentes`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `tarifa_componentes` (
- `Id_Componente` int(11) NOT NULL AUTO_INCREMENT,
- `Componente` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
- `tarifa_componentes_series_id` int(11) NOT NULL,
- `tarifa_class` smallint(6) DEFAULT NULL,
- `tax` double DEFAULT NULL,
- `is_renewable` tinyint(2) NOT NULL DEFAULT '1',
- PRIMARY KEY (`Id_Componente`),
- KEY `series_componentes_idx` (`tarifa_componentes_series_id`),
- KEY `comp` (`tarifa_class`),
- CONSTRAINT `serie_componente` FOREIGN KEY (`tarifa_componentes_series_id`) REFERENCES `tarifa_componentes_series` (`tarifa_componentes_series_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 `tarifa_componentes_series`
---
-
-DROP TABLE IF EXISTS `tarifa_componentes_series`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `tarifa_componentes_series` (
- `tarifa_componentes_series_id` int(11) NOT NULL AUTO_INCREMENT,
- `Serie` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
- `base` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Marca aquellas series que se utilizan para calcular el precio base de las ventas, a efectos estadisticos',
- `margen` tinyint(4) NOT NULL DEFAULT '0',
- PRIMARY KEY (`tarifa_componentes_series_id`),
- UNIQUE KEY `Serie_UNIQUE` (`Serie`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Permite organizar de forma ordenada los distintos componentes';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `tarifa_premisas`
---
-
-DROP TABLE IF EXISTS `tarifa_premisas`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `tarifa_premisas` (
- `Id_Premisa` int(11) NOT NULL AUTO_INCREMENT,
- `premisa` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`Id_Premisa`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `tarifa_warehouse`
---
-
-DROP TABLE IF EXISTS `tarifa_warehouse`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `tarifa_warehouse` (
- `Id_Tarifa_Warehouse` int(11) NOT NULL AUTO_INCREMENT,
- `warehouse_id` int(11) NOT NULL,
- `Id_Premisa` int(11) NOT NULL,
- `Valor` double NOT NULL,
- PRIMARY KEY (`Id_Tarifa_Warehouse`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los valores de gasto por almacen';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `v_clientes_jerarquia`
---
-
-DROP TABLE IF EXISTS `v_clientes_jerarquia`;
-/*!50001 DROP VIEW IF EXISTS `v_clientes_jerarquia`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `v_clientes_jerarquia` AS SELECT
- 1 AS `Id_Cliente`,
- 1 AS `Cliente`,
- 1 AS `Comercial`,
- 1 AS `Jefe`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `v_ventas_contables`
---
-
-DROP TABLE IF EXISTS `v_ventas_contables`;
-/*!50001 DROP VIEW IF EXISTS `v_ventas_contables`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `v_ventas_contables` AS SELECT
- 1 AS `year`,
- 1 AS `month`,
- 1 AS `importe`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `variablesKK`
---
-
-DROP TABLE IF EXISTS `variablesKK`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `variablesKK` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `variable` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `value` double DEFAULT NULL,
- `date` datetime DEFAULT NULL,
- `text` 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 */;
-
---
--- Dumping events for database 'bi'
---
-
---
--- Dumping routines for database 'bi'
---
-/*!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
-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 PROCEDURE IF EXISTS `analisis_ventas_evolution_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `analisis_ventas_evolution_add`()
-BEGIN
- DECLARE vPreviousPeriod INT;
- DECLARE vCurrentPeriod INT;
- DECLARE vLastPeriod INT;
- DECLARE vMinPeriod INT DEFAULT 201400;
- DECLARE vMaxPeriod INT DEFAULT vn2008.vnperiod(CURDATE());
-
- DECLARE vYear INT;
- DECLARE vWeek INT;
-
-
-
- SET vCurrentPeriod = IFNULL(vLastPeriod, vMinPeriod);
-
- WHILE vCurrentPeriod < vMaxPeriod
- DO
- SELECT MAX(Periodo) INTO vPreviousPeriod
- FROM bi.analisis_ventas_almacen_evolution
- WHERE Periodo < vMaxPeriod;
-
- SELECT MIN(period) INTO vCurrentPeriod
- FROM vn2008.time
- WHERE period > vPreviousPeriod;
-
- SET vYear = FLOOR(vCurrentPeriod / 100);
- SET vWeek = vCurrentPeriod - (vYear * 100);
-
- DELETE FROM bi.analisis_ventas_almacen_evolution
- WHERE Periodo = vCurrentPeriod;
-
- REPLACE bi.analisis_ventas_almacen_evolution(Almacen, Ventas, Semana,Año, Periodo)
- SELECT Almacen, sum(Ventas) AS Ventas, vWeek, vYear, vCurrentPeriod
- FROM (
- SELECT almacen, sum(Importe) AS Ventas
- FROM bi.analisis_ventas
- WHERE vYear = Año
- AND vWeek = Semana
- GROUP BY almacen
- UNION ALL
- SELECT almacen, - sum(Importe) AS Ventas
- FROM bi.analisis_ventas
- WHERE vYear - 1 = Año
- AND vWeek = Semana
- GROUP BY almacen
- UNION ALL
- SELECT Almacen, Ventas
- FROM bi.analisis_ventas_almacen_evolution
- WHERE Periodo = vPreviousPeriod
- ) sub
- GROUP BY Almacen;
- END WHILE;
-
-
-
- SET vCurrentPeriod = vMinPeriod;
-
- WHILE vCurrentPeriod < vMaxPeriod
- DO
- SELECT MAX(periodo) INTO vPreviousPeriod
- FROM bi.analisis_ventas_reino_evolution
- WHERE periodo < vMaxPeriod;
-
- SELECT MIN(period) INTO vCurrentPeriod
- FROM vn2008.time
- WHERE period > vPreviousPeriod;
-
- SET vYear = FLOOR(vCurrentPeriod / 100);
- SET vWeek = vCurrentPeriod - (vYear * 100);
-
- DELETE FROM bi.analisis_ventas_reino_evolution
- WHERE Periodo = vCurrentPeriod;
-
- REPLACE bi.analisis_ventas_reino_evolution(reino, ventas, semana,año, periodo)
- SELECT reino, sum(ventas) AS ventas, vWeek, vYear, vCurrentPeriod
- FROM (
- SELECT Reino, sum(Importe) AS ventas
- FROM bi.analisis_ventas
- WHERE vYear = Año
- AND vWeek = Semana
- GROUP BY Reino
- UNION ALL
- SELECT Reino, - sum(Importe) AS ventas
- FROM bi.analisis_ventas
- WHERE vYear - 1 = Año
- AND vWeek = Semana
- GROUP BY Reino
- UNION ALL
- SELECT reino, ventas
- FROM bi.analisis_ventas_reino_evolution
- WHERE Periodo = vPreviousPeriod
- ) sub
- GROUP BY reino;
- END WHILE;
-
-
-
- SET vCurrentPeriod = vMinPeriod;
-
- WHILE vCurrentPeriod < vMaxPeriod
- DO
- SELECT MAX(periodo) INTO vPreviousPeriod
- FROM bi.analisis_ventas_familia_evolution
- WHERE periodo < vMaxPeriod;
-
- SELECT MIN(period) INTO vCurrentPeriod
- FROM vn2008.time
- WHERE period > vPreviousPeriod;
-
- SET vYear = FLOOR(vCurrentPeriod / 100);
- SET vWeek = vCurrentPeriod - (vYear * 100);
-
- DELETE FROM bi.analisis_ventas_familia_evolution
- WHERE Periodo = vCurrentPeriod;
-
- REPLACE bi.analisis_ventas_familia_evolution(familia, ventas, semana,año, periodo)
- SELECT Familia, sum(ventas) AS ventas, vWeek, vYear, vCurrentPeriod
- FROM (
- SELECT Familia, sum(Importe) AS ventas
- FROM bi.analisis_ventas
- WHERE vYear = Año
- AND vWeek = Semana
- GROUP BY familia
- UNION ALL
- SELECT Familia, - sum(Importe) AS ventas
- FROM bi.analisis_ventas
- WHERE vYear - 1 = Año
- AND vWeek = Semana
- GROUP BY familia
- UNION ALL
- SELECT familia, ventas
- FROM bi.analisis_ventas_familia_evolution
- WHERE Periodo = vPreviousPeriod
- ) sub
- GROUP BY Familia;
- END WHILE;
-
-
-
-
-
-
- SET vCurrentPeriod = vMinPeriod;
-
- WHILE vCurrentPeriod < vMaxPeriod
- DO
- SELECT MAX(periodo) INTO vPreviousPeriod
- FROM bi.analisis_ventas_provincia_evolution
- WHERE periodo < vMaxPeriod;
-
- SELECT MIN(period) INTO vCurrentPeriod
- FROM vn2008.time
- WHERE period > vPreviousPeriod;
-
- SET vYear = FLOOR(vCurrentPeriod / 100);
- SET vWeek = vCurrentPeriod - (vYear * 100);
-
- DELETE FROM bi.analisis_ventas_provincia_evolution
- WHERE Periodo = vCurrentPeriod;
-
- REPLACE bi.analisis_ventas_provincia_evolution(provincia, ventas, semana,año, periodo)
- SELECT Provincia, sum(ventas) AS ventas, vWeek, vYear, vCurrentPeriod
- FROM (
- SELECT Provincia, sum(Importe) AS ventas
- FROM bi.analisis_ventas
- WHERE vYear = Año
- AND vWeek = Semana
- GROUP BY Provincia
- UNION ALL
- SELECT Provincia, - sum(Importe) AS ventas
- FROM bi.analisis_ventas
- WHERE vYear - 1 = Año
- AND vWeek = Semana
- GROUP BY Provincia
- UNION ALL
- SELECT provincia, ventas
- FROM bi.analisis_ventas_provincia_evolution
- WHERE Periodo = vPreviousPeriod
- ) sub
- GROUP BY Provincia;
- END WHILE;
-
-
-
- SET vCurrentPeriod = vMinPeriod;
-
- WHILE vCurrentPeriod < vMaxPeriod
- DO
- SELECT MAX(periodo) INTO vPreviousPeriod
- FROM bi.analisis_ventas_vista_evolution
- WHERE periodo < vMaxPeriod;
-
- SELECT MIN(period) INTO vCurrentPeriod
- FROM vn2008.time
- WHERE period > vPreviousPeriod;
-
- SET vYear = FLOOR(vCurrentPeriod / 100);
- SET vWeek = vCurrentPeriod - (vYear * 100);
-
- DELETE FROM bi.analisis_ventas_vista_evolution
- WHERE Periodo = vCurrentPeriod;
-
- REPLACE bi.analisis_ventas_vista_evolution(vista, ventas, semana,año, periodo)
- SELECT vista, sum(ventas) AS ventas, vWeek, vYear, vCurrentPeriod
- FROM (
- SELECT Vista, sum(Importe) AS ventas
- FROM bi.analisis_ventas
- WHERE vYear = Año
- AND vWeek = Semana
- GROUP BY Vista
- UNION ALL
- SELECT Vista, - sum(Importe) AS ventas
- FROM bi.analisis_ventas
- WHERE vYear - 1 = Año
- AND vWeek = Semana
- GROUP BY Vista
- UNION ALL
- SELECT vista, ventas
- FROM bi.analisis_ventas_vista_evolution
- WHERE Periodo = vPreviousPeriod
- ) sub
- GROUP BY Vista;
- END WHILE;
-
-
-
- SET vCurrentPeriod = vMinPeriod;
-
- WHILE vCurrentPeriod < vMaxPeriod
- DO
- SELECT MAX(periodo) INTO vPreviousPeriod
- FROM bi.analisis_ventas_vendedor_evolution
- WHERE periodo < vMaxPeriod;
-
- SELECT MIN(period) INTO vCurrentPeriod
- FROM vn2008.time
- WHERE period > vPreviousPeriod;
-
- SET vYear = FLOOR(vCurrentPeriod / 100);
- SET vWeek = vCurrentPeriod - (vYear * 100);
-
- DELETE FROM bi.analisis_ventas_vendedor_evolution
- WHERE Periodo = vCurrentPeriod;
-
- REPLACE bi.analisis_ventas_vendedor_evolution(vendedor, ventas, semana,año, periodo)
- SELECT Comercial AS vendedor, sum(ventas) AS ventas, vWeek, vYear, vCurrentPeriod
- FROM (
- SELECT Comercial, sum(Importe) AS ventas
- from bi.analisis_ventas
- WHERE vYear = Año
- AND vWeek = Semana
- GROUP BY Comercial
- UNION ALL
- SELECT Comercial, - sum(Importe) AS ventas
- from bi.analisis_ventas
- WHERE vYear - 1 = Año
- AND vWeek = Semana
- GROUP BY Comercial
- UNION ALL
- SELECT vendedor, ventas
- FROM bi.analisis_ventas_vendedor_evolution
- WHERE Periodo = vPreviousPeriod
- ) sub
- GROUP BY vendedor;
- 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 `analisis_ventas_simple` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `analisis_ventas_simple`()
-BEGIN
-
-TRUNCATE bi.analisis_grafico_simple;
-
-INSERT INTO bi.analisis_grafico_simple SELECT * FROM bi.analisis_grafico_ventas;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `analisis_ventas_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 `analisis_ventas_update`()
-BEGIN
-
- DECLARE vLastMonth DATE;
-
- SET vLastMonth = util.firstDayOfMonth(TIMESTAMPADD(MONTH, -1, CURDATE()));
-
- DELETE FROM bi.analisis_ventas
- WHERE Año > YEAR(vLastMonth)
- OR (Año = YEAR(vLastMonth) AND Mes >= MONTH(vLastMonth));
-
- INSERT INTO bi.analisis_ventas
-
- SELECT
- `tp`.`Tipo` AS `Familia`,
- `r`.`reino` AS `Reino`,
- `tr`.`CodigoTrabajador` AS `Comercial`,
- `tr2`.`CodigoTrabajador` AS `Comprador`,
- `p`.`name` AS `Provincia`,
- `w`.`name` AS `almacen`,
- `time`.`year` AS `Año`,
- `time`.`month` AS `Mes`,
- `time`.`week` AS `Semana`,
- `v`.`vista` AS `Vista`,
- `bt`.`importe` AS `Importe`
- FROM
- (((((((((`bs`.`ventas` `bt`
- LEFT JOIN `vn2008`.`Tipos` `tp` ON ((`tp`.`tipo_id` = `bt`.`tipo_id`)))
- LEFT JOIN `vn2008`.`reinos` `r` ON ((`r`.`id` = `tp`.`reino_id`)))
- LEFT JOIN `vn2008`.`Clientes` c on c.Id_Cliente = bt.Id_Cliente
- LEFT JOIN `vn2008`.`Trabajadores` `tr` ON ((`tr`.`Id_Trabajador` = `c`.`Id_Trabajador`)))
- LEFT JOIN `vn2008`.`Trabajadores` `tr2` ON ((`tr2`.`Id_Trabajador` = `tp`.`Id_Trabajador`)))
- JOIN vn2008.time on time.date = bt.fecha
- JOIN vn2008.Movimientos m on m.Id_Movimiento = bt.Id_Movimiento
- LEFT JOIN `vn2008`.`Tickets` `t` ON ((`t`.`Id_Ticket` = `m`.`Id_Ticket`)))
- JOIN vn2008.Agencias a on a.Id_Agencia = t.Id_Agencia
- LEFT JOIN `vn2008`.`Vistas` `v` ON ((`v`.`vista_id` = `a`.`Vista`)))
- LEFT JOIN `vn2008`.`Consignatarios` `cs` ON ((`cs`.`Id_Consigna` = `t`.`Id_Consigna`)))
- LEFT JOIN `vn2008`.`province` `p` ON ((`p`.`province_id` = `cs`.`province_id`)))
- LEFT JOIN `vn2008`.`warehouse` `w` ON ((`w`.`id` = `t`.`warehouse_id`)))
- WHERE bt.fecha >= vLastMonth AND r.mercancia;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `call_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `call_add`()
-BEGIN
-
-DECLARE datSTART DATETIME DEFAULT '2012-03-01' ;
-
-INSERT INTO vn2008.daily_task_log(consulta) VALUES('bi.call_add');
-
-
-SELECT MAX(Fecha) INTO datSTART FROM `call`;
-
-
-
-DELETE FROM `call` WHERE Fecha = datSTART;
-
-INSERT INTO bi.`call`(CodTrabajadorCartera,CodTrabajadorTelefono,dur_in,dur_out,Fecha,`year`,`month`,`week`,`hour`,phone)
-SELECT vn2008.Averiguar_ComercialCliente(pb.Id_Cliente,Fecha) CodTrabajadorCartera,ll.CodigoTrabajador, dur_in,
- dur_out, ll.Fecha,YEAR(ll.Fecha) `year`, MONTH(ll.Fecha) `month`,WEEK(ll.Fecha,7) `week`, Hora,phone
-FROM
-(
-SELECT Id_Trabajador,CodigoTrabajador, IFNULL(billsec,0) dur_in, 0 dur_out, 1 as Recibidas, NULL as Emitidas, calldate as Fecha,
- hour(calldate) as Hora,src as phone
-FROM vn2008.Trabajadores T
-INNER JOIN vn2008.cdr C ON C.dstchannel LIKE CONCAT('%', T.extension, '%')
-WHERE calldate >= datSTART AND LENGTH(C.src) >=9 AND disposition = 'ANSWERED' AND duration
-UNION ALL
-SELECT Id_Trabajador,CodigoTrabajador,0 dur_in, IFNULL(billsec,0) dur_out, NULL as Recibidas, 1 as Emitidas, date(calldate), hour(calldate),dst
-FROM vn2008.Trabajadores T
-INNER JOIN vn2008.cdr C ON C.src = T.extension
-WHERE calldate >= datSTART AND LENGTH(C.dst) >=9 AND disposition = 'ANSWERED' AND duration
-) ll
-INNER JOIN vn2008.Permisos USING(Id_Trabajador)
-LEFT JOIN vn2008.v_phonebook pb ON pb.Telefono = ll.phone
-WHERE 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 `claim_ratio_routine` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `claim_ratio_routine`()
-BEGIN
-
-DECLARE vMonthToRefund INT DEFAULT 4;
-
-
-INSERT INTO vn2008.daily_task_log(consulta)
- VALUES('bi.claim_ratio_routine START');
-
-
-
-
-
-INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario, Importe, Id_Ticket)
- SELECT Fecha, Id_Cliente, Concat('COD11 : ',Concepte), - round(Cantidad *
- Preu * (100 - Descuento) / 100 ,2) AS Importe, t.Id_Ticket
- FROM vn2008.Tickets t
- JOIN vn2008.Movimientos m ON m.Id_Ticket = t.Id_Ticket
- WHERE Id_Article = 11
- AND Concepte NOT LIKE '$%'
- AND Fecha > '2014-01-01'
- HAVING nz(Importe) <> 0;
-
-DELETE mc.*
- FROM vn2008.Movimientos_componentes mc
- JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento
- JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket
- WHERE m.Id_Article = 11
- AND m.Concepte NOT LIKE '$%'
- AND t.Fecha > '2017-01-01';
-
-INSERT INTO vn2008.Movimientos_componentes(Id_Movimiento, Id_Componente, Valor)
- SELECT m.Id_Movimiento, 34, round(m.Preu * (100 - m.Descuento)/100,4)
- FROM vn2008.Movimientos m
- JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket
- WHERE m.Id_Article = 11
- AND m.Concepte NOT LIKE '$%'
- AND t.Fecha > '2017-01-01';
-
-UPDATE vn2008.Movimientos m
- JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket
- SET Concepte = CONCAT('$ ',Concepte)
- WHERE Id_Article = 11
- AND Concepte NOT LIKE '$%'
- AND Fecha > '2014-01-01';
-
-
-
-INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario,
- Importe, Greuges_type_id,Id_Ticket)
- SELECT cm.Fecha
- , cm.Id_Cliente
- , concat('Claim ',cm.id,' : ', m.Concepte)
- ,round( -1 * ((sensib -1)/4) * Cantidad *
- Preu * (100 - Descuento) / 100, 2) AS Reclamaciones
- , 4
- , m.Id_Ticket
- FROM vn2008.Movimientos m
- JOIN vn2008.cl_act ca USING(Id_Movimiento)
- JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id
- WHERE ca.cl_sol_id NOT IN (1,5)
- AND ca.greuge = 0
- AND cm.cl_est_id = 3;
-
-
-
-INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario,
- Importe , Greuges_type_id,Id_Ticket)
- SELECT cm.Fecha
- , cm.Id_Cliente
- , concat('Claim_mana ',cm.id,' : ', m.Concepte)
- ,round( ((sensib -1)/4) * Cantidad * Preu * (100 - Descuento) / 100, 2)
- AS Reclamaciones
- ,3
- ,m.Id_Ticket
- FROM vn2008.Movimientos m
- JOIN vn2008.cl_act ca USING(Id_Movimiento)
- JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id
- WHERE ca.cl_sol_id NOT IN (1,5)
- AND ca.greuge = 0
- AND cm.cl_est_id = 3
- AND cm.mana;
-
-
-UPDATE vn2008.cl_act ca
- JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id
- SET greuge = 1
- WHERE ca.cl_sol_id NOT IN (1,5)
- AND ca.greuge = 0
- AND cm.cl_est_id = 3;
-
-
-
-
-
-DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list;
-CREATE TEMPORARY TABLE tmp.ticket_list
-(PRIMARY KEY (Id_Ticket))
-SELECT DISTINCT t.Id_Ticket
- FROM vn2008.Movimientos_componentes mc
- JOIN vn2008.Movimientos m ON mc.Id_Movimiento = m.Id_Movimiento
- JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket
- JOIN vn2008.Tickets_state ts ON ts.Id_Ticket = t.Id_Ticket
- JOIN vncontrol.inter i ON i.inter_id = ts.inter_id
- JOIN vn2008.state s ON s.id = i.state_id
- WHERE mc.Id_Componente = 17
- AND mc.greuge = 0
- AND t.Fecha >= '2016-10-01'
- AND t.Fecha < CURDATE()
- AND t.warehouse_id <> 41
- AND s.alert_level >= 3;
-
-DELETE g.*
- FROM vn2008.Greuges g
- JOIN tmp.ticket_list t ON g.Id_Ticket = t.Id_Ticket
- WHERE Greuges_type_id = 2;
-
-INSERT INTO vn2008.Greuges (Id_Cliente,Comentario,Importe,Fecha,
- Greuges_type_id, Id_Ticket)
- SELECT Id_Cliente
- ,concat('recobro ', m.Id_Ticket), - round(SUM(mc.Valor*Cantidad),2)
- AS dif
- ,date(t.Fecha)
- , 2
- ,tt.Id_Ticket
- FROM vn2008.Movimientos m
- JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket
- JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.Id_Ticket
- JOIN vn2008.Movimientos_componentes mc
- ON mc.Id_Movimiento = m.Id_Movimiento AND mc.Id_Componente = 17
- GROUP BY t.Id_Ticket
- HAVING ABS(dif) > 1;
-
-UPDATE vn2008.Movimientos_componentes mc
- JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento
- JOIN tmp.ticket_list tt ON tt.Id_Ticket = m.Id_Ticket
- SET greuge = 1
- WHERE Id_Componente = 17;
-
-
-
-DELETE FROM bi.claims_ratio;
-
-REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro)
- SELECT fm.Id_Cliente, 12 * fm.Consumo, Reclamaciones,
- round(Reclamaciones / (12*fm.Consumo),4) AS Ratio, 0
- FROM bi.facturacion_media_anual fm
- LEFT JOIN(
- SELECT cm.Id_Cliente, round(sum(-1 * ((sensib -1)/4) *
- Cantidad * Preu * (100 - Descuento) / 100))
- AS Reclamaciones
- FROM vn2008.Movimientos m
- JOIN vn2008.cl_act ca
- ON ca.Id_Movimiento = m.Id_Movimiento
- JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id
- WHERE ca.cl_sol_id NOT IN (1,5)
- AND cm.cl_est_id = 3
- AND cm.Fecha >= TIMESTAMPADD(YEAR, -1, CURDATE())
- GROUP BY cm.Id_Cliente
- ) claims ON claims.Id_Cliente = fm.Id_Cliente;
-
-
-
-UPDATE bi.claims_ratio cr
- JOIN (
- SELECT Id_Cliente, nz(SUM(Importe)) AS Greuge
- FROM vn2008.Greuges
- WHERE Fecha <= CURDATE()
- GROUP BY Id_Cliente
- ) g ON g.Id_Cliente = cr.Id_Cliente
- SET recobro = GREATEST(0,round(nz(Greuge) /
- (nz(Consumo) * vMonthToRefund / 12 ) ,3));
-
-
-INSERT INTO vn2008.daily_task_log(consulta)
- VALUES('bi.claim_ratio_routine 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` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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`()
-BEGIN
-DECLARE vDateShort DATETIME;
-DECLARE vDateLong DATETIME;
-
-SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE());
-SET vDateLong = TIMESTAMPADD(MONTH, -18,CURDATE());
-
-INSERT INTO bi.daily_task_log(state) VALUES('clean START');
-
-DELETE FROM bi.comparativa_clientes WHERE Fecha < vDateLong;
-DELETE FROM bi.Greuge_Evolution WHERE Fecha < vDateShort AND weekday(Fecha) != 1;
-
-INSERT INTO bi.daily_task_log(state) 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(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 `comparativa_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `comparativa_add`()
-BEGIN
- DECLARE lastCOMP INT;
-
- SELECT MAX(Periodo) INTO lastCOMP FROM vn2008.Comparativa;
-
-
- IF lastCOMP < vn2008.vnperiod(CURDATE())- 3 AND vn2008.vnweek(CURDATE()) > 3 THEN
-
- REPLACE vn2008.Comparativa(Periodo, Id_Article, warehouse_id, Cantidad,price)
- SELECT vn2008.vnperiod(T.Fecha) AS Periodo
- , Id_Article
- , warehouse_id
- , SUM(Cantidad) AS Total
- , SUM(Cantidad * Preu * (100 - Descuento) / 100) precio
- FROM vn2008.Movimientos M
- JOIN vn2008.Tickets T USING (Id_Ticket)
- JOIN vn2008.Articles A USING (Id_Article)
- LEFT JOIN vn2008.Tipos ti ON ti.tipo_id = A.tipo_id
- LEFT JOIN vn2008.reinos r ON r.id = ti.reino_id
- WHERE T.Fecha BETWEEN TIMESTAMPADD(DAY,-60,CURDATE()) AND TIMESTAMPADD(DAY,-30,CURDATE())
- AND T.Id_Cliente NOT IN(400,200)
- AND display <> 0 AND warehouse_id NOT IN (0,13)
- GROUP BY Id_Article, Periodo, warehouse_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 DROP PROCEDURE IF EXISTS `comparativa_add_manual` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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_add_manual`(IN dat_START DATE, IN dat_END DATE)
-BEGIN
-
- DECLARE datINI DATETIME;
- DECLARE datFIN DATETIME;
-
-
- SELECT MIN(`date`) INTO datINI FROM vn2008.`time` WHERE period = vn2008.vnperiod(dat_START);
- SELECT TIMESTAMP(MAX(`date`),'23:59:59') INTO datFIN FROM vn2008.`time` WHERE period = vn2008.vnperiod(dat_END);
-
- DELETE FROM vn2008.Comparativa WHERE Periodo BETWEEN vn2008.vnperiod(dat_START) and vn2008.vnperiod(dat_END);
-
- REPLACE vn2008.Comparativa(Periodo, Id_Article, warehouse_id, Cantidad,price)
- SELECT tm.period AS Periodo
- , M.Id_Article
- , t.warehouse_id
- , SUM(Cantidad) AS Total
- , sum(v.importe) AS precio
- FROM vn2008.Movimientos M
- JOIN vn2008.Tickets t on t.Id_Ticket = M.Id_Ticket
- JOIN bs.ventas v on v.Id_Movimiento = M.Id_Movimiento
- JOIN vn2008.time tm on tm.date = v.fecha
- JOIN vn2008.Tipos tp on v.tipo_id = tp.tipo_id
- LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id
- WHERE v.fecha BETWEEN datINI and datFIN
- AND r.display <> 0 AND t.warehouse_id NOT IN (0,13)
- GROUP BY Id_Article, Periodo, t.warehouse_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 `customer_risk_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 `customer_risk_update`(v_customer INT, v_company INT, v_amount DECIMAL(10,2))
-BEGIN
- IF v_amount IS NOT NULL
- THEN
- INSERT INTO bi.customer_risk
- SET
- customer_id = v_customer,
- company_id = v_company,
- amount = v_amount
- ON DUPLICATE KEY UPDATE
- amount = amount + VALUES(amount);
- 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 `defaultersFromDate` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `defaultersFromDate`(IN vDate DATE)
-BEGIN
-
-SELECT t1.*, c.Cliente, w.workerCode, c.pay_met_id,c.Vencimiento
-FROM (
-
- select * from(
- select today.client, today.amount todayAmount, yesterday.amount yesterdayAmount, round(yesterday.amount - today.amount,2) as difference, defaulterSince
- from
- (select client, amount, defaulterSince
- from defaulters
- where date = vDate and hasChanged) today
- join
- (select client, amount
- from defaulters
- where date = TIMESTAMPADD(DAY,-1,vDate)) yesterday using(client)
-
- having today.amount > 0 and difference <> 0
- ) newDefaulters
-)t1 left join vn2008.Clientes c ON t1.client = c.Id_Cliente
- left join vn.worker w ON w.id = c.Id_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 DROP PROCEDURE IF EXISTS `defaulting` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `defaulting`(IN vDate DATE)
-BEGIN
- DECLARE vDone BOOLEAN;
- DECLARE vClient INT;
- DECLARE vAmount INT;
- DECLARE vDateInvoice DATE;
- DECLARE vAmountInvoice DECIMAL(10,2);
- DECLARE vDueDay INT;
- DECLARE vGraceDays INT;
- DECLARE defaulters CURSOR FOR
- SELECT client, amount, Vencimiento, graceDays FROM bi.defaulters d
- JOIN vn2008.Clientes c ON c.Id_Cliente = d.client
- JOIN vn2008.pay_met pm ON pm.id = c.pay_met_id
- WHERE hasChanged AND date = vDate;
-
- DECLARE invoices CURSOR FOR
- SELECT Fecha, importe FROM vn2008.Facturas f
- WHERE f.Fecha >= '2016-01-01' AND f.Id_Cliente = vClient ORDER BY f.Fecha DESC;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
-
-
- INSERT INTO vn2008.daily_task_log(consulta) VALUES('defaulting');
-
- DELETE FROM bi.defaulters WHERE date = vDate;
-
- INSERT INTO bi.defaulters(client, date, amount)
- SELECT customer_id, vDate, FLOOR(SUM(amount)) AS amount
- FROM bi.customerRiskOverdue
- GROUP BY customer_id;
-
-
- UPDATE bi.defaulters d
- JOIN (
- SELECT * FROM(
- SELECT client, amount , defaulterSince FROM bi.defaulters
- WHERE date <= TIMESTAMPADD(DAY,-1, vDate)
- ORDER BY date DESC) t GROUP BY client
- ) yesterday using(client)
- SET d.hasChanged = IF(d.amount <> yesterday.amount, 1, 0),
- d.defaulterSince = yesterday.defaulterSince
- WHERE d.date = vDate ;
-
- OPEN defaulters;
- defaulters: LOOP
- SET vDone = FALSE;
- SET vAmount = 0;
- FETCH defaulters INTO vClient,vAmount, vDueDay, vGraceDays;
- IF vDone THEN
- LEAVE defaulters;
- END IF;
- OPEN invoices;
- invoices:LOOP
-
- FETCH invoices INTO vDateInvoice, vAmountInvoice;
- IF vDone THEN
- LEAVE invoices;
- END IF;
-
- IF TIMESTAMPADD(DAY, vGraceDays, vn2008.paymentday(vDateInvoice, vDueDay)) <= vDate THEN
- SET vAmount = vAmount - vAmountInvoice;
- IF vAmount <= 0 THEN
- UPDATE defaulters SET defaulterSince = vn2008.paymentday(vDateInvoice, vDueDay)
- WHERE client = vClient and date = vDate;
-
- SET vAmount = 0;
- LEAVE invoices;
- END IF;
- END IF;
- END LOOP;
- CLOSE invoices;
- END LOOP;
- CLOSE defaulters;
- DELETE FROM bi.defaulting WHERE date = vDate;
-
- INSERT INTO bi.defaulting(date, amount)
- SELECT vDate, SUM(amount)
- FROM bi.defaulters
- WHERE date = vDate and amount > 0;
-
- CALL vn.clientFreeze();
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `defaultingkk` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `defaultingkk`(IN vDate DATE)
-BEGIN
- DECLARE done BIT DEFAULT 0;
- DECLARE vClient INT;
- DECLARE vAmount INT;
- DECLARE vDateInvoice DATE;
- DECLARE vAmountInvoice DECIMAL(10,2);
- DECLARE vDueDay INT;
- DECLARE vGraceDays INT;
- DECLARE defaulters CURSOR FOR
- SELECT client, amount, Vencimiento, graceDays FROM bi.defaulters d
- JOIN vn2008.Clientes c ON c.Id_Cliente = d.client
- JOIN vn2008.pay_met pm ON pm.id = c.pay_met_id
- WHERE hasChanged AND date = vDate;
-
- DECLARE invoices CURSOR FOR
- SELECT Fecha, importe FROM vn2008.Facturas f
- WHERE f.Fecha >= '2016-01-01' AND f.Id_Cliente = vClient ORDER BY f.Fecha DESC;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
-
-
- INSERT INTO vn2008.daily_task_log(consulta) VALUES('defaulting');
-
- DELETE FROM bi.defaulters WHERE date = vDate;
-
- INSERT INTO bi.defaulters(client, date, amount)
- SELECT customer_id, vDate, FLOOR(SUM(amount)) AS amount
- FROM bi.customerRiskOverdue
- GROUP BY customer_id;
-
-
- UPDATE bi.defaulters d
- JOIN (
- SELECT client, amount , defaulterSince FROM bi.defaulters
- WHERE date = TIMESTAMPADD(DAY,-1, vDate)
- GROUP BY client
- ) yesterday using(client)
- SET d.hasChanged = IF(d.amount <> yesterday.amount, 1, 0),
- d.defaulterSince = yesterday.defaulterSince
- WHERE d.date = vDate ;
-
- OPEN defaulters;
- defaulters: BEGIN
- REPEAT
- FETCH defaulters INTO vClient,vAmount, vDueDay, vGraceDays;
- OPEN invoices;
- invoices:BEGIN
- REPEAT
-
- FETCH invoices INTO vDateInvoice, vAmountInvoice;
- IF TIMESTAMPADD(DAY, vGraceDays, vn2008.paymentday(vDateInvoice, vDueDay)) <= vDate THEN
- SET vAmount = vAmount - vAmountInvoice;
- IF vAmount < 0 THEN
- UPDATE defaulters SET defaulterSince = vn2008.paymentday(vDateInvoice, vDueDay)
- WHERE client = vClient and date = vDate;
- SET vAmount = 0;
- LEAVE invoices;
- END IF;
- END IF;
- UNTIL done END REPEAT;
- END invoices;
- CLOSE invoices;
- UNTIL done OR vClient IS NULL END REPEAT;
- END defaulters;
- CLOSE defaulters;
- DELETE FROM bi.defaulting WHERE date = vDate;
-
- INSERT INTO bi.defaulting(date, amount)
- SELECT vDate, SUM(amount)
- FROM bi.defaulters
- WHERE date = vDate and amount > 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 `defaulting_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 `defaulting_launcher`()
-BEGIN
-
- CALL bi.defaulting(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 `equaliza` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `equaliza`(IN wh_id INT)
-BEGIN
-
-DECLARE datEQ DATETIME;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `facturacion_media_anual_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 `facturacion_media_anual_update`()
-BEGIN
-
-
-INSERT INTO vn2008.daily_task_log(consulta) VALUES('bi.facturacion_media_anual_update');
-
-TRUNCATE TABLE bi.facturacion_media_anual;
-
-REPLACE bi.facturacion_media_anual(Id_Cliente, Consumo)
-select Id_Cliente, avg(Consumo)
-from (
- Select Id_Cliente, YEAR(fecha) year, MONTH(fecha) month, sum(importe) as Consumo
- from bs.ventas
- where fecha >= TIMESTAMPADD(YEAR,-1,CURDATE())
- group by Id_Cliente, year, month
-) vol
-group by 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 `greuge_dif_porte_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `greuge_dif_porte_add`()
-BEGIN
-
-DECLARE datSTART DATETIME DEFAULT TIMESTAMPADD(DAY,-10,CURDATE());
-DECLARE datEND DATETIME DEFAULT TIMESTAMPADD(DAY,-1,CURDATE());
-
-DROP TEMPORARY TABLE IF EXISTS tmp.dp;
-
-CREATE TEMPORARY TABLE tmp.dp
- (PRIMARY KEY (Id_Ticket))
- SELECT
- t.Id_Ticket,
- SUM(az.price * IF(
- e.EsBulto = 71
- AND ISNULL(e.Id_Article)
- AND a.Vista = 2,
- 0.75,
- 1
- )
- ) AS teorico,
- 00000.00 as practico,
- 00000.00 as greuge
- FROM
- vn2008.Tickets t
- JOIN vn2008.Clientes cli ON cli.Id_cliente = t.Id_Cliente
- LEFT JOIN vn2008.expeditions e ON e.ticket_id = t.Id_Ticket
- JOIN vn2008.Consignatarios c ON c.Id_Consigna = t.Id_Consigna
- JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia
- JOIN vn2008.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 vn2008.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 between datSTART AND datEND
- AND cli.`real`
- AND t.empresa_id IN (442 , 567)
- GROUP BY t.Id_Ticket;
-
-DROP TEMPORARY TABLE IF EXISTS tmp.dp_aux;
-
-CREATE TEMPORARY TABLE tmp.dp_aux
- (PRIMARY KEY (Id_Ticket))
- SELECT t.Id_Ticket, sum(freight) as porte
- FROM tmp.dp
- JOIN vn2008.Tickets t ON t.Id_Ticket = dp.Id_Ticket
- JOIN vn2008.Rutas r on r.Id_Ruta = t.Id_Ruta
- JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia
- JOIN (
- SELECT
- M.Id_Ticket,
- M.Cantidad * (vn2008.CM3(b.Id_Compra) / 1000000 / C.Packing) * (az.price / 0.08) AS freight
- FROM
- vn2008.Movimientos M
- JOIN vn2008.Tickets t ON t.Id_Ticket = M.Id_Ticket
- JOIN vn2008.Consignatarios c ON c.Id_Consigna = t.Id_Consigna
- JOIN bi.Last_buy_id b ON M.Id_Article = b.Id_Article
- AND t.warehouse_id = b.warehouse_id
- JOIN vn2008.Compres C ON b.Id_Compra = C.Id_Compra
- JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia
- JOIN vn2008.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 vn2008.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 t.Fecha between datSTART AND datEND
- ) vmv ON vmv.Id_Ticket = t.Id_Ticket
- WHERE a.is_volumetric
- GROUP BY t.Id_Ticket;
-
- UPDATE tmp.dp
- JOIN tmp.dp_aux using(Id_Ticket)
- SET teorico = porte;
-
-DROP TEMPORARY TABLE IF EXISTS tmp.dp_aux;
-
-CREATE TEMPORARY TABLE tmp.dp_aux
- (PRIMARY KEY (Id_Ticket))
- SELECT dp.Id_Ticket, sum(Cantidad * Valor) as valor
- FROM tmp.dp
- JOIN vn2008.Movimientos m using(Id_Ticket)
- JOIN vn2008.Movimientos_componentes mc using(Id_Movimiento)
- WHERE Id_Componente = 15
- GROUP BY m.Id_Ticket;
-
-UPDATE tmp.dp
- JOIN tmp.dp_aux using(Id_Ticket)
- SET practico = valor;
-
-DROP TEMPORARY TABLE tmp.dp_aux;
-
-CREATE TEMPORARY TABLE tmp.dp_aux
- (PRIMARY KEY (Id_Ticket))
- SELECT dp.Id_Ticket, Importe
- FROM tmp.dp
- JOIN
- (
- SELECT Id_Ticket, sum(Importe) as Importe
- FROM vn2008.Greuges g
- WHERE Greuges_type_id = 1
- GROUP BY Id_Ticket
- ) sub using(Id_Ticket);
-
-UPDATE tmp.dp
- JOIN tmp.dp_aux using(Id_Ticket)
- SET greuge = Importe;
-
-
-INSERT INTO vn2008.Greuges (Id_Cliente,Comentario,Importe,Fecha, Greuges_type_id, Id_Ticket)
-SELECT t.Id_Cliente
- , concat('dif_porte ', dp.Id_Ticket)
- , round(teorico - practico - greuge,2) as Importe
- , date(t.Fecha)
- , 1
- ,t.Id_Ticket
- FROM tmp.dp
- JOIN vn2008.Tickets t on dp.Id_Ticket = t.Id_Ticket
- WHERE ABS(teorico - practico - greuge) > 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 `Greuge_Evolution_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `Greuge_Evolution_Add`()
-BEGIN
-
-
-
-
-
- DECLARE datFEC DATE;
- DECLARE datFEC_TOMORROW DATE;
- DECLARE datFEC_LASTYEAR DATE;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN
-
- GET DIAGNOSTICS CONDITION 2 @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
- SELECT CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'));
- INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('jgallego@verdnatura.es', 'Greuge_Evolution_Add' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')));
- INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('pako@verdnatura.es', 'Greuge_Evolution_Add' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')));
-
- END;
-
- SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
-
-
- INSERT INTO vn2008.daily_task_log(consulta) VALUES('Greuge Evolution Add START');
-
- SELECT TIMESTAMPADD(DAY,1,MAX(Fecha)),TIMESTAMPADD(DAY,2,MAX(Fecha)) INTO datFEC, datFEC_TOMORROW FROM bi.Greuge_Evolution;
-
- SET datFEC_LASTYEAR = TIMESTAMPADD(YEAR,-1,datFEC);
-
- DELETE FROM bi.Greuge_Evolution WHERE Fecha >= datFEC;
-
- DROP TEMPORARY TABLE IF EXISTS maxInvoice;
-
- CREATE TEMPORARY TABLE maxInvoice
- (PRIMARY KEY (Id_Cliente))
- ENGINE = MEMORY
- SELECT DISTINCT Id_Cliente, max(Fecha) as maxFecha
- FROM vn2008.Facturas
- GROUP BY Id_Cliente
- HAVING maxFecha < timestampadd(month,-2,datFEC);
-
- INSERT INTO vn2008.daily_task_log(consulta) VALUES('Greuge Evolution Add MIDDLE');
-
- WHILE datFEC < CURDATE() DO
-
- REPLACE bi.Greuge_Evolution(Id_Cliente, Fecha, Greuge, Ventas)
-
- SELECT Id_Cliente, datFEC as Fecha, Greuge, Ventas
-
- FROM
-
- (
- SELECT Id_Cliente, sum(Importe) as Greuge
- FROM vn2008.Greuges
- where Fecha <= datFEC
- group by Id_Cliente
-
- ) sub
-
- RIGHT JOIN
-
- (
-
- SELECT Id_Cliente, sum(Ventas) as Ventas
- FROM
- (
-
- SELECT Id_Cliente, IF (fecha != datFEC, -1,1) * (importe + recargo) as Ventas
- FROM bs.ventas
- WHERE fecha = datFEC or fecha = datFEC_LASTYEAR
-
- UNION ALL
-
- SELECT Id_Cliente, Ventas
- FROM bi.Greuge_Evolution
- WHERE Fecha = TIMESTAMPADD(DAY, -1, datFEC)
-
- ) sub
- group by Id_Cliente
-
- ) v using(Id_Cliente)
- ;
-
-
-
-
-
- UPDATE bi.Greuge_Evolution ge
- JOIN maxInvoice using(Id_Cliente)
- SET FOSIL = GREUGE
- WHERE ge.Fecha = datFEC;
-
-
-
-
- UPDATE bi.Greuge_Evolution ge
- JOIN (
- SELECT cs.Id_Cliente, sum(Valor * Cantidad) as Importe
- FROM vn2008.Tickets t
- JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna
- JOIN vn2008.Movimientos m on m.Id_Ticket = t.Id_Ticket
- JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento
- WHERE t.Fecha >= datFEC
- AND t.Fecha < datFEC_TOMORROW
- AND mc.Id_Componente = 17
- GROUP BY cs.Id_Cliente
- ) sub using(Id_Cliente)
- SET Recobro = Importe
- WHERE ge.Fecha = datFEC;
-
- INSERT INTO vn2008.daily_task_log(consulta) VALUES(CONCAT('Greuge Evolution ',datFEC));
-
- SET datFEC = datFEC_TOMORROW;
- SET datFEC_TOMORROW = TIMESTAMPADD(DAY,1,datFEC_TOMORROW);
- SET datFEC_LASTYEAR = TIMESTAMPADD(YEAR,-1,datFEC);
-
-
- END WHILE;
-
- DROP TEMPORARY TABLE IF EXISTS maxInvoice;
-
- INSERT INTO vn2008.daily_task_log(consulta) VALUES('Greuge Evolution Add 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 `last_buy_id_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `last_buy_id_add`()
-BEGIN
-
-
-
-
-
-TRUNCATE TABLE bi.Last_buy_id;
-
-
-
-
-INSERT INTO bi.Last_buy_id SELECT * FROM
- (SELECT
- Id_Article, Id_Compra, warehouse_id
- FROM
- vn2008.Compres c
- JOIN vn2008.Entradas e USING (Id_Entrada)
- JOIN vn2008.travel tr ON tr.id = e.travel_id
- WHERE
- Novincular = FALSE AND tarifa2 > 0 AND NOT Redada
- AND landing > curdate()
- ORDER BY landing DESC) t1
-GROUP BY Id_Article , warehouse_id;
-
-
-
-REPLACE bi.Last_buy_id SELECT * FROM
- (SELECT
- Id_Article, Id_Compra, warehouse_id
- FROM
- vn2008.Compres c
- JOIN vn2008.Entradas e USING (Id_Entrada)
- JOIN vn2008.travel tr ON tr.id = e.travel_id
- WHERE
- Novincular = FALSE AND tarifa2 > 0 AND NOT Redada
- AND landing BETWEEN vn2008.date_inv() AND curdate()
- ORDER BY landing DESC) t1
-GROUP BY Id_Article , warehouse_id;
-
- TRUNCATE TABLE bi.Last_buy_idBackUp;
- INSERT INTO bi.Last_buy_idBackUp
- SELECT * FROM Last_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 `margenes` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `margenes`()
-BEGIN
-
-TRUNCATE TABLE bi.margenes;
-
-INSERT INTO bi.margenes
-SELECT Id_Article, Cantidad as Unidades, Cantidad * round(nz(Costefijo) + nz(Embalajefijo) + nz(Comisionfija) + nz(Portefijo),3) as Coste , w.name as almacen, month(landing) as Mes, year(landing) as Year, 0 as Venta
-FROM vn2008.Compres C
-JOIN vn2008.Entradas E using(Id_Entrada)
-JOIN vn2008.travel tr on tr.id = travel_id
-JOIN vn2008.warehouse w on w.id = tr.warehouse_id
-LEFT JOIN vn2008.Articles A using(Id_Article)
-JOIN vn2008.Tipos TP using(tipo_id)
-WHERE landing between '2013-01-01' and ' 2013-12-31'
-AND E.Id_Proveedor <> 4
-AND not redada
-AND not inventario
-union all
-SELECT Id_Article, Cantidad as Unidades, 0 as Coste , w.name, month(Fecha) as Mes, year(Fecha) as Year, Cantidad * round(Preu * (100 - M.Descuento) / 100,2) as Venta
-FROM vn2008.Movimientos M
-JOIN vn2008.Articles A using(Id_Article)
-JOIN vn2008.Tipos TP using(tipo_id)
-JOIN vn2008.Tickets T using(Id_Ticket)
-JOIN vn2008.Clientes C using(Id_Cliente)
-JOIN vn2008.warehouse w on w.id = warehouse_id
-WHERE Fecha between '2013-01-01' and ' 2013-12-31'
-AND (Id_Cliente = 31 or invoice)
-AND Id_Cliente NOT IN (2066,2067,2068);
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `nightly_tasks` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `nightly_tasks`()
-BEGIN
-
-call bi.analisis_ventas_evolution_add;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `nigthlyAnalisisVentas` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `nigthlyAnalisisVentas`()
-BEGIN
-
- INSERT INTO vn2008.daily_task_log(consulta) VALUES('analisis ventas START');
-
- CALL bi.analisis_ventas_update;
- CALL bi.analisis_ventas_simple;
- CALL bi.analisis_ventas_evolution_add;
-
- INSERT INTO vn2008.daily_task_log(consulta) VALUES('analisis ventas 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 `partitioning` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `partitioning`(IN intyear INT)
-BEGIN
-
- DECLARE v_sql TEXT;
- DECLARE strSquemaName VARCHAR(10);
- DECLARE strTableName VARCHAR(20);
- DECLARE strFieldName VARCHAR(20);
- DECLARE strDateField VARCHAR(20);
- DECLARE strTableDependingOn VARCHAR(20);
- DECLARE strFieldDependingOn VARCHAR(20);
- DECLARE done BIT DEFAULT 0;
- DECLARE strCacheSchema VARCHAR(5);
- DECLARE dat_start,dat_end DATE;
- DECLARE cur1 CURSOR FOR
- SELECT `schema_name`,`table_name` FROM `cache`.partitioning_information ORDER BY execution_order;
- DECLARE cur2 CURSOR FOR
- SELECT `schema_name`,`table_name`,`date_field` FROM `cache`.partitioning_information WHERE date_field > '' ORDER BY execution_order;
- DECLARE cur3 CURSOR FOR
- SELECT `schema_name`,`table_name`,`table_depending` FROM `cache`.partitioning_information WHERE table_depending > '' ORDER BY execution_order;
- DECLARE cur4 CURSOR FOR
- SELECT `schema_name`,`table_name`,`table_depending` FROM `cache`.partitioning_information WHERE table_depending > '' ORDER BY execution_order DESC;
- DECLARE cur5 CURSOR FOR
- SELECT `schema_name`,`table_name`,`date_field` FROM `cache`.partitioning_information WHERE date_field > '' ORDER BY execution_order DESC;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
-
- SET FOREIGN_KEY_CHECKS=0;
- IF LENGTH(intyear) <> 4 THEN
- CALL el_año_debe_contener_4_caracteres_yyyy();
- END IF;
- SET dat_start = STR_TO_DATE(CONCAT('01,01,',intyear),'%d,%m,%Y');
- SET dat_end = STR_TO_DATE(CONCAT('31,12,',intyear),'%d,%m,%Y');
- SET strCacheSchema = CONCAT('vn_',right(intyear,2));
- SET v_sql = sql_printf ('CREATE SCHEMA IF NOT EXISTS %t',strCacheSchema);
- CALL vn2008.sql_query (v_sql);
-
-
- OPEN cur1;
- FETCH cur1 INTO strSquemaName,strTableName;
- WHILE NOT done DO
- SET v_sql = sql_printf ('CREATE TABLE IF NOT EXISTS %t.%t LIKE %t.%t',
- strCacheSchema,
- strTableName,
- strSquemaName,
- strTableName);
-
- CALL vn2008.sql_query (v_sql);
+/**
+ * Calcula el riesgo para los clientes activos de la tabla temporal tmp.client_list
+ *
+ * @param maxRiskDate Fecha maxima de los registros
+ * @return table tmp.risk
+ **/
- FETCH cur1 INTO strSquemaName,strTableName;
-
- END WHILE;
- CLOSE cur1;
-
-
- OPEN cur2;
- FETCH cur2 INTO strSquemaName,strTableName,strDateField;
- WHILE NOT done DO
- SET v_sql = sql_printf ('REPLACE INTO %t.%t SELECT * FROM %t.%t WHERE %t BETWEEN %v AND %v',
- strCacheSchema,
- strTableName,
- strSquemaName,
- strTableName,
- strDateField,
- dat_start,
- dat_end);
-
- SELECT v_sql;
- CALL vn2008.sql_query (v_sql);
-
- FETCH cur2 INTO strSquemaName,strTableName,strDateField;
-
- END WHILE;
- CLOSE cur2;
-
-
- OPEN cur3;
- SET done = 0;
- FETCH cur3 INTO strSquemaName,strTableName,strTableDependingOn;
- WHILE NOT done DO
-
-
-
- SELECT kcu.column_name INTO strFieldName
- FROM information_schema.key_column_usage kcu
- WHERE table_schema = CONVERT(strSquemaName USING utf8) COLLATE utf8_general_ci
- AND REFERENCED_TABLE_NAME = CONVERT(strTableDependingOn USING utf8) COLLATE utf8_general_ci
- AND table_name = CONVERT(strTableName USING utf8) COLLATE utf8_general_ci;
-
-
- SELECT kcu.column_name INTO strFieldDependingOn
- FROM information_schema.key_column_usage kcu
- WHERE table_schema = CONVERT(strSquemaName USING utf8) COLLATE utf8_general_ci
- AND constraint_name = 'PRIMARY'
- AND table_name = CONVERT(strTableDependingOn USING utf8) COLLATE utf8_general_ci;
-
- SET v_sql = sql_printf ('REPLACE INTO %t.%t SELECT a.* FROM %t.%t a JOIN %t.%t b ON a.%t = b.%t',
- strCacheSchema,
- strTableName,
- strSquemaName,
- strTableName,
- strCacheSchema,
- strTableDependingOn,
- strFieldName,
- strFieldDependingOn);
- select v_sql;
- CALL vn2008.sql_query (v_sql);
-
- FETCH cur3 INTO strSquemaName,strTableName,strTableDependingOn;
- END WHILE;
-
- CLOSE cur3;
-
-
-
- OPEN cur4;
- SET done = 0;
- FETCH cur4 INTO strSquemaName,strTableName,strTableDependingOn;
- WHILE NOT done DO
-
-
-
- SELECT kcu.column_name INTO strFieldName
- FROM information_schema.key_column_usage kcu
- WHERE table_schema = CONVERT(strSquemaName USING utf8) COLLATE utf8_general_ci
- AND REFERENCED_TABLE_NAME = CONVERT(strTableDependingOn USING utf8) COLLATE utf8_general_ci
- AND table_name = CONVERT(strTableName USING utf8) COLLATE utf8_general_ci;
-
-
- SELECT kcu.column_name INTO strFieldDependingOn
- FROM information_schema.key_column_usage kcu
- WHERE table_schema = CONVERT(strSquemaName USING utf8) COLLATE utf8_general_ci
- AND constraint_name = 'PRIMARY'
- AND table_name = CONVERT(strTableDependingOn USING utf8) COLLATE utf8_general_ci;
-
- SELECT v_sql;
- SET v_sql = sql_printf ('DELETE a.* FROM %t.%t a JOIN %t.%t b ON a.%t = b.%t',
- strSquemaName,
- strTableName,
- strCacheSchema,
- strTableDependingOn,
- strFieldName,
- strFieldDependingOn);
- CALL vn2008.sql_query (v_sql);
-
- FETCH cur4 INTO strSquemaName,strTableName,strTableDependingOn;
- END WHILE;
-
- CLOSE cur4;
-
-
- OPEN cur5;
- SET done = 0;
- FETCH cur5 INTO strSquemaName,strTableName,strDateField;
- WHILE NOT done DO
-
- SET v_sql = sql_printf ('DELETE FROM %t WHERE %t BETWEEN %v AND %v',
- strTableName,
- strDateField,
- dat_start,
- dat_end);
- CALL vn2008.sql_query (v_sql);
-
- FETCH cur5 INTO strSquemaName,strTableName,strDateField;
-
- END WHILE;
- CLOSE cur5;
- SET FOREIGN_KEY_CHECKS=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 `primer_pedido_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `primer_pedido_add`()
-BEGIN
- INSERT IGNORE INTO bi.primer_pedido(Id_Ticket, Id_Cliente, month, year, total)
- SELECT *
- FROM
- (SELECT
- `m`.`Id_Ticket` ,
- `v`.`Id_Cliente` ,
- `t`.`month`,
- `t`.`year`,
- v.importe + v.recargo as total
- FROM
- bs.ventas v
- JOIN
- vn2008.Movimientos m on m.Id_Movimiento = v.Id_Movimiento
- JOIN
- vn2008.time t on t.date = v.fecha
- WHERE
- fecha > CURDATE() + INTERVAL -(1) YEAR
- ORDER BY fecha) `s`
- GROUP BY `s`.`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 `regularidad` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `regularidad`()
-BEGIN
-
-select Id_Cliente, Meses, IF(Antiguedad = 13,12,Antiguedad) , Meses / IF(Antiguedad = 13,12,Antiguedad) as Regularidad from (
-SELECT Id_Cliente, count(*) as Meses, FLOOR(DATEDIFF('2012-07-31', IF(Created < '2011-08-01','2011-08-01', Created)) / 30) +1 as Antiguedad from
-(
-
-SELECT DISTINCT Id_Cliente, Periodo(Fecha) as periodo from Facturas
-where Fecha between '2011-08-01' AND '2012-07-31'
-
-) sub
-
-join Clientes using(Id_Cliente)
-where Created <= '2012-07-31'
-
-group by Id_Cliente
-having Antiguedad > 0
-
-) sub44
-order by Antiguedad ;
-
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `rotacion_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 `rotacion_update`()
-BEGIN
-
-
-INSERT INTO vn2008.daily_task_log(consulta) VALUES('bi.rotation_update');
-
-
-
-IF DAY(CURDATE()) = 5 THEN
-
- call rotacion_update_manual(1, 999999, TIMESTAMPADD(YEAR,-1,CURDATE()), 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 `rotacion_update_manual` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `rotacion_update_manual`(IN intART_DESDE INT, IN intART_HASTA INT, IN datSTART DATE, IN datEND DATE)
-BEGIN
-
-
-DECLARE intLAPSO INT DEFAULT DATEDIFF(datEND,datSTART );
-
-
-
-
- REPLACE bi.rotacion(Id_Article,warehouse_id,total,rotacion)
- SELECT Id_Article, warehouse_id, Total, round((sum(Saldo_Ponderado)/Total),2) as rotacion
- FROM
- (
- SELECT Id_Article, warehouse_id,
- @intervalo:= IF(warehouse_id = @wh AND Id_Article = @art , DATEDIFF(Fecha, @fec),1) as Dias,
- IF(warehouse_id = @wh AND Id_Article = @art , IF(@sd < 0,0,@sd) * @intervalo, IF(Unidades<0,0,Unidades)) as Saldo_Ponderado,
- IF(warehouse_id = @wh AND Id_Article = @art , @sd:= @sd + Unidades, @sd:= Unidades) as Saldo
-
- , @fec:= Fecha, @art:= Id_Article, @wh:= warehouse_id
- FROM
- (
- SELECT Id_Article, landing as Fecha, sum(Cantidad) as Unidades, warehouse_id, @fec:= datSTART, @art := 0, @d := 0, @sd:= 0, @wh := 0, @intervalo := 0
- FROM
- (
- SELECT Id_Article, landing, Cantidad, warehouse_id
- FROM vn2008.Compres C
- JOIN vn2008.Entradas E using(Id_Entrada)
- JOIN vn2008.Articles A using(Id_Article)
- JOIN vn2008.Tipos tp ON tp.tipo_id = A.tipo_id
- LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id
- JOIN vn2008.travel tr on tr.id = travel_id
- JOIN vn2008.warehouse w on w.id = tr.warehouse_id
- WHERE landing between datSTART and datEND
- AND Id_Article between intART_DESDE and intART_HASTA
- AND Id_Proveedor <> 4
- AND r.display <> 0
- AND NOT E.Inventario
- AND NOT fuente
- AND NOT redada
- UNION ALL
- SELECT Id_Article, shipment, -Cantidad, warehouse_id_out
- FROM vn2008.Compres C
- JOIN vn2008.Entradas E using(Id_Entrada)
- JOIN vn2008.Articles A using(Id_Article)
- JOIN vn2008.Tipos tp ON tp.tipo_id = A.tipo_id
- LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id
- JOIN vn2008.travel tr on tr.id = travel_id
- JOIN vn2008.warehouse w on w.id = tr.warehouse_id_out
- WHERE shipment between datSTART and datEND
- AND Id_Article between intART_DESDE and intART_HASTA
- AND Id_Proveedor <> 4
- AND r.display <> 0
- AND NOT fuente
- AND NOT E.Inventario
- AND NOT redada
- UNION ALL
- SELECT Id_Article, date(Fecha), -Cantidad, warehouse_id
- FROM vn2008.Movimientos M
- JOIN vn2008.Articles A using(Id_Article)
- JOIN vn2008.Tipos tp ON tp.tipo_id = A.tipo_id
- LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id
- JOIN vn2008.Tickets t using(Id_Ticket)
- JOIN vn2008.warehouse w on w.id = t.warehouse_id
- WHERE Fecha between datSTART and datEND
- AND r.display <> 0
- AND NOT fuente
- AND Id_Article between intART_DESDE and intART_HASTA
- AND Id_Cliente NOT IN (2066,2067,2068)
- ) sub
- GROUP BY Id_Article, warehouse_id, Fecha
- ) sub2
- ) sub4
- JOIN
- (
- SELECT Id_Article, sum(Cantidad) as Total, warehouse_id
- FROM vn2008.Compres C
- JOIN vn2008.Entradas E using(Id_Entrada)
- JOIN vn2008.Articles A using(Id_Article)
- JOIN vn2008.Tipos tp ON tp.tipo_id = A.tipo_id
- LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id
- JOIN vn2008.travel tr on tr.id = travel_id
- JOIN vn2008.warehouse w on w.id = tr.warehouse_id
- WHERE landing between datSTART and datEND
- AND Id_Article between intART_DESDE and intART_HASTA
- AND Id_Proveedor <> 4
- AND NOT E.Inventario
- AND r.display <> 0
- AND NOT redada
- AND NOT fuente
- GROUP BY Id_Article, warehouse_id
- ) sub3 using(Id_Article, warehouse_id)
-
- GROUP BY Id_Article, warehouse_id;
-
-
-
- CALL vn2008.item_last_buy_(NULL,datSTART);
-
-
- update bi.rotacion r
- JOIN vn2008.t_item_last_buy b ON r.Id_Article = b.item_id AND r.warehouse_id = b.warehouse_id
- join vn2008.Compres ON Id_Compra = b.buy_id
- set cm3 = vn2008.cm3_2(Id_Cubo, r.Id_Article) / Packing
- where r.Id_Article between intART_DESDE and intART_HASTA;
-
-
-UPDATE bi.rotacion
-JOIN (
- SELECT warehouse_id, sum(total*rotacion*cm3) as Operacion
- FROM bi.rotacion
- WHERE Id_Article between intART_DESDE and intART_HASTA
- GROUP BY warehouse_id
- ) sub using(warehouse_id)
-
-JOIN (
- SELECT warehouse_id, sum(Valor) as Coste_Auxiliar
- FROM bi.tarifa_warehouse
- WHERE Id_Premisa = 1
- GROUP BY warehouse_id
- ) sub2 using(warehouse_id)
-
-JOIN (
- SELECT warehouse_id, sum(Valor) as Coste_Operativo
- FROM bi.tarifa_warehouse
- WHERE Id_Premisa IN (2,3)
- GROUP BY warehouse_id
- ) sub3 using(warehouse_id)
-
-JOIN (
- SELECT warehouse_id, sum(Valor) as Coste_Manipulacion
- FROM bi.tarifa_warehouse
- WHERE Id_Premisa = 4
- GROUP BY warehouse_id
- ) sub4 using(warehouse_id)
-
-SET auxiliar = if(rotacion < 0,0,round(rotacion *cm3 * Coste_Auxiliar / Operacion,4))
- ,almacenaje = if(rotacion < 0,0,round(rotacion *cm3 * Coste_Operativo / Operacion,4))
- , manipulacion = if(rotacion < 0,0,round(rotacion *cm3 * Coste_Manipulacion / Operacion,4))
- WHERE Id_Article between intART_DESDE and intART_HASTA;
-
-
-
-
-INSERT INTO bi.rotacion(Id_Article, warehouse_id, rotacion, cm3, almacenaje, manipulacion, auxiliar, mermas)
-SELECT a.Id_Article, warehouse_id, rotacion_m, cm3_m, alm_m, man_m, aux_m, merm_m
-FROM vn2008.Articles a
-JOIN (SELECT tipo_id, warehouse_id, Id_Tipo, avg(rotacion) rotacion_m, avg(cm3) cm3_m, avg(almacenaje) alm_m, avg(manipulacion) man_m
- , avg(auxiliar) aux_m, avg(mermas) merm_m
- from bi.rotacion
- join vn2008.Articles a using(Id_Article)
- join vn2008.Tipos tp using(tipo_id)
- group by tipo_id, warehouse_id) sub using(tipo_id)
-
-WHERE a.Id_Article between intART_DESDE and intART_HASTA
-ON DUPLICATE KEY UPDATE rotacion = rotacion;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `rotacion_update_manual_PCA` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `rotacion_update_manual_PCA`(IN datSTART DATE, IN datEND DATE)
-BEGIN
-
-
-DECLARE intLAPSO INT DEFAULT DATEDIFF(datEND,datSTART );
-DECLARE intART_DESDE BIGINT DEFAULT 1;
-DECLARE intART_HASTA BIGINT DEFAULT 100;
-
-WHILE intART_HASTA < 999999 DO
-
- IF intART_HASTA MOD 1000 = 0 THEN
-
- SELECT intART_HASTA;
-
- END IF;
-
- REPLACE bi.rotacion(Id_Article,warehouse_id,total,rotacion)
- SELECT Id_Article, warehouse_id, Total, round((sum(Saldo_Ponderado)/Total),2) as rotacion
- FROM
- (
- SELECT Id_Article, warehouse_id,
- @intervalo:= IF(warehouse_id = @wh AND Id_Article = @art , DATEDIFF(Fecha, @fec),1) as Dias,
- IF(warehouse_id = @wh AND Id_Article = @art , IF(@sd < 0,0,@sd) * @intervalo, IF(Unidades<0,0,Unidades)) as Saldo_Ponderado,
- IF(warehouse_id = @wh AND Id_Article = @art , @sd:= @sd + Unidades, @sd:= Unidades) as Saldo
-
- , @fec:= Fecha, @art:= Id_Article, @wh:= warehouse_id
- FROM
- (
- SELECT Id_Article, landing as Fecha, sum(Cantidad) as Unidades, warehouse_id, @fec:= datSTART, @art := 0, @d := 0, @sd:= 0, @wh := 0, @intervalo := 0
- FROM
- (
- SELECT Id_Article, landing, Cantidad, warehouse_id
- FROM vn2008.Compres C
- JOIN vn2008.Entradas E using(Id_Entrada)
- JOIN vn2008.Articles A using(Id_Article)
- JOIN vn2008.Tipos using(tipo_id)
- JOIN vn2008.travel tr on tr.id = travel_id
- JOIN vn2008.warehouse w on w.id = tr.warehouse_id
- WHERE landing between datSTART and datEND
- AND warehouse_id = 44
- AND Id_Article between intART_DESDE and intART_HASTA
- AND Id_Proveedor <> 4
- AND reino_id IN (3,4)
- AND NOT E.Inventario
- AND NOT fuente
- AND NOT redada
- UNION ALL
- SELECT Id_Article, shipment, -Cantidad, warehouse_id_out
- FROM vn2008.Compres C
- JOIN vn2008.Entradas E using(Id_Entrada)
- JOIN vn2008.Articles A using(Id_Article)
- JOIN vn2008.Tipos using(tipo_id)
- JOIN vn2008.travel tr on tr.id = travel_id
- JOIN vn2008.warehouse w on w.id = tr.warehouse_id_out
- WHERE shipment between datSTART and datEND
- AND warehouse_id_out = 44
- AND Id_Article between intART_DESDE and intART_HASTA
- AND Id_Proveedor <> 4
- AND reino_id IN (3,4)
- AND NOT fuente
- AND NOT E.Inventario
- AND NOT redada
- UNION ALL
- SELECT Id_Article, date(Fecha), -Cantidad, warehouse_id
- FROM vn2008.Movimientos M
- JOIN vn2008.Articles A using(Id_Article)
- JOIN vn2008.Tipos using(tipo_id)
- JOIN vn2008.Tickets t using(Id_Ticket)
- JOIN vn2008.warehouse w on w.id = t.warehouse_id
- WHERE Fecha between datSTART and datEND
- AND t.warehouse_id = 44
- AND reino_id IN (3,4)
- AND NOT fuente
- AND Id_Article between intART_DESDE and intART_HASTA
- AND Id_Cliente NOT IN (2066,2067,2068)
- ) sub
- GROUP BY Id_Article, warehouse_id, Fecha
- ) sub2
- ) sub4
- JOIN
- (
- SELECT Id_Article, sum(Cantidad) as Total, warehouse_id
- FROM vn2008.Compres C
- JOIN vn2008.Entradas E using(Id_Entrada)
- JOIN vn2008.Articles A using(Id_Article)
- JOIN vn2008.Tipos using(tipo_id)
- JOIN vn2008.travel tr on tr.id = travel_id
- JOIN vn2008.warehouse w on w.id = tr.warehouse_id
- WHERE landing between datSTART and datEND
- AND warehouse_id = 44
- AND Id_Article between intART_DESDE and intART_HASTA
- AND Id_Proveedor <> 4
- AND NOT E.Inventario
- AND reino_id IN (3,4)
- AND NOT redada
- AND NOT fuente
- GROUP BY Id_Article, warehouse_id
- ) sub3 using(Id_Article, warehouse_id)
- GROUP BY Id_Article, warehouse_id;
-
-SET intART_DESDE = intART_DESDE + 100;
-SET intART_DESDE = intART_HASTA + 100;
-
-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 `rotacion_volumen_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 `rotacion_volumen_update`(IN vIdCompra BIGINT)
-BEGIN
-
-UPDATE bi.rotacion r
-JOIN vn2008.travel tr ON r.warehouse_id = tr.warehouse_id
-JOIN vn2008.Entradas e ON e.travel_id = tr.id
-JOIN vn2008.Compres c ON e.Id_Entrada = c.Id_Entrada AND c.Id_Article = r.Id_Article
-SET r.cm3 = vn2008.cm3_2(c.Id_Cubo, c.Id_Article) / c.Packing
-where c.Id_Compra = vIdCompra;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `rutas_m3_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `rutas_m3_add`()
-BEGIN
-
- DECLARE datSTART DATE DEFAULT TIMESTAMPADD(DAY,-90,CURDATE());
- DECLARE datEND DATE DEFAULT CURDATE();
- DECLARE datFEC DATE;
-
- IF hour(now()) between 5 and 24 then
-
- SET datSTART = CURDATE();
- SET datEND = TIMESTAMPADD(DAY,1,CURDATE());
-
- end if;
-
- SET datFEC = datSTART;
-
- CALL vn2008.item_last_buy_(NULL,CURDATE());
- WHILE datFEC <= datEND DO
-
- UPDATE vn2008.Rutas R
- JOIN (SELECT R.Id_Ruta, sum(Cantidad * vn2008.cm3_unidad(b.buy_id)) / 1000000 as m3
- from vn2008.Rutas R
- join vn2008.Tickets t using(Id_Ruta)
- join vn2008.Movimientos m using(Id_Ticket)
- join vn2008.t_item_last_buy b ON Id_Article = b.item_id AND b.warehouse_id = t.warehouse_id
- where R.Fecha = datFEC AND R.m3 IS NULL
- group by R.Id_Ruta
- ) t using(Id_Ruta)
- SET R.m3 = t.m3
- WHERE R.m3 IS NULL;
-
- SET datFEC = TIMESTAMPADD(DAY,1,datFEC);
-
- 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 `ticket_add2kk` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticket_add2kk`(intNUMDAYS INTEGER)
-BEGIN
-
-DECLARE datSTART,datEND DATETIME;
-
-
- SET @@session.max_sp_recursion_depth=250;
- SET datSTART = TIMESTAMPADD(DAY, -intNUMDAYS, CURDATE());
-
-
- SET datEND = vn2008.DAYEND(datSTART);
-
-
-
-
-
-update vn2008.Movimientos m
-join
-(
-select Id_Movimiento, round(IFNULL(sum(Valor) , IFNULL( Preu * (100 - m.Descuento) /100,0 ) ),2) as Cost
-from vn2008.Tickets t
-join vn2008.Movimientos m using(Id_Ticket)
-left join vn2008.Movimientos_componentes mc using(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
-where t.Fecha between datSTART AND datEND
-group by Id_Movimiento
-) sub using(Id_Movimiento)
-set CostFixat = Cost;
-
-
-
-
- REPLACE INTO bi.ticket(Id_Ticket,Id_Cliente,`date`, tipo_id, `year`,`week`,`month`,`day`,`view`,amount,Id_Trabajador,Id_propietario )
- SELECT t.Id_Ticket,c.Id_Cliente,t.Fecha `date`,tipo_id, year(Fecha) as `year`, vn2008.vnweek(Fecha) as `week`,
- month(Fecha) as `month`,vn2008.vnday(Fecha) as `day`, A.Vista `view`,
- IFNULL( round( sum(cantidad * Preu * (100 - m.Descuento)/100) ,2) ,0) as amount,
- c.Id_Trabajador, c.Id_Trabajador
- FROM vn2008.Tickets t
- JOIN vn2008.Consignatarios cs using(Id_Consigna)
- JOIN vn2008.warehouse W ON W.id = t.warehouse_id
- INNER JOIN vn2008.Clientes c on cs.Id_Cliente = c.Id_Cliente
- INNER JOIN vn2008.Movimientos m USING(Id_Ticket)
- INNER JOIN vn2008.Articles USING(Id_Article)
- INNER JOIN vn2008.Agencias A on A.Id_Agencia = t.Id_Agencia
- INNER JOIN vn2008.Tipos TP USING(tipo_id)
- WHERE Fecha BETWEEN datSTART AND datEND
- AND NOT W.fuente
- AND c.`Real`
- AND (reino_id <> 6 OR m.Id_Article IN (95,98))
- GROUP BY t.Id_Ticket,tipo_id ;
-
-
-
-
-
- IF (intNUMDAYS>0) THEN
- CALL `bi`.`ticket_add2` (intNUMDAYS-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 `ticket_addkk` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticket_addkk`(intNUMDAYS INTEGER)
-BEGIN
-
-DECLARE datSTART DATETIME;
-
- IF (intNUMDAYS > 0) THEN
- SET datSTART = TIMESTAMPADD(DAY, -intNUMDAYS, CURDATE());
- DELETE FROM bi.ticket where `date` >= datSTART ;
- CALL `bi`.`ticket_add2` (intNUMDAYS);
- DELETE FROM bi.ticket where `date` < '2001-01-01';
- END IF;
-
-UPDATE bi.ticket bt
-JOIN vn2008.Tickets USING(Id_Ticket)
-JOIN vn2008.Consignatarios C USING(Id_Consigna)
-SET bt.Id_Cliente = C.Id_Cliente
-, bt.Id_Trabajador = @idT := vn2008.Averiguar_ComercialCliente_Id(C.Id_Cliente,bt.date)
-, bt.Id_propietario = @idT
-WHERE Tickets.Id_Cliente = 31 AND bt.date >= datSTART;
-
-
-
-
-truncate table bi.f_tvc;
-
-insert into bi.f_tvc
-select Id_Ticket
-from vn2008.Tickets t
-join vn2008.Consignatarios cs using(Id_Consigna)
-join vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente
-join vn2008.warehouse w on w.id = t.warehouse_id
-where c.`Real` = TRUE
-and w.comisionantes = TRUE;
-
-
-
-
-
-IF DAY(CURDATE()) = 15 THEN
- update vn2008.Tickets
- set Fecha = date(Fecha)
- where Fecha between TIMESTAMPADD(DAY,-46,CURDATE()) and TIMESTAMPADD(DAY, -1 - DAY(CURDATE()), 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 `ticket_add_bydaykk` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticket_add_bydaykk`(datFEC DATE)
-BEGIN
-
- DECLARE datSTART DATETIME;
- DECLARE datEND DATETIME;
-
-
-
- SET @@session.max_sp_recursion_depth=2500;
-
- SET datSTART = DATE(datFEC);
- SET datEND = TIMESTAMPADD(DAY,30,datSTART);
-
- DELETE FROM bi.ticket WHERE `date` between datSTART and datEND;
-
- INSERT INTO bi.ticket(Id_Ticket,`date`, tipo_id, `year`,`week`,`month`,`view`,amount,Id_Trabajador, Id_Cliente, Id_Propietario )
- SELECT t.Id_Ticket,t.Fecha `date`,tipo_id, vn2008.vnyear(Fecha) as `year`, vn2008.vnweek(Fecha) as `week`,
- vn2008.vnmonth(Fecha) as `month`, A.Vista `view`, IFNULL(round(sum(cantidad * preu * (100 - m.Descuento)/100),2),0) as amount,
- c.Id_Trabajador, c.Id_Cliente, ifnull(c.Id_Trabajador,20)
- FROM vn2008.Tickets t
- JOIN vn2008.Consignatarios cs using(Id_Consigna)
- JOIN vn2008.warehouse W ON W.id = t.warehouse_id
- INNER JOIN vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente
- INNER JOIN vn2008.Movimientos m USING(Id_Ticket)
- INNER JOIN vn2008.Articles USING(Id_Article)
- INNER JOIN vn2008.Agencias A on A.Id_Agencia = t.Id_Agencia
- INNER JOIN vn2008.Tipos TP USING(tipo_id)
- LEFT JOIN vn2008.reinos r ON r.id = TP.reino_id
- WHERE Fecha >= datSTART
- AND Fecha < datEND
- AND NOT W.fuente
- AND (invoice or t.Id_Cliente in (5,31))
- AND r.display <> 0
- GROUP BY t.Id_Ticket,tipo_id
- ON DUPLICATE KEY UPDATE amount = amount,
- `view` = `view`,
- `date` = `date`,
- `week` = `week`,
- `year` = `year`,
- `month` = `month`,
- tipo_id = tipo_id,
- Id_Trabajador = Id_Trabajador,
- Id_Cliente = Id_Cliente,
- Id_Propietario = ifnull(Id_Trabajador,20);
-
- UPDATE bi.ticket
- JOIN vn2008.Tickets using(Id_Ticket)
- JOIN vn2008.Agencias using(Id_Agencia)
- JOIN vn2008.agency_warehouse aw using(agency_id,warehouse_id)
- SET `view` = aw.Vista
- WHERE Tickets.Fecha BETWEEN datSTART AND datEND;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `Ultima_Accion` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `Ultima_Accion`()
-BEGIN
-
-REPLACE INTO bi.lastaction(Id_Cliente, Cliente, Ultima_accion, Comercial)
-
-SELECT Id_Cliente, Cliente, Ultima_accion, Comercial
-FROM vn2008.Clientes
-JOIN
-(
-SELECT Id_Cliente, MAX(calldate) as Ultima_accion, vn2008.Averiguar_ComercialCliente(Id_Cliente, CURDATE()) as Comercial
-FROM
-(
-SELECT Id_Cliente, calldate
-FROM vn2008.cdr
-JOIN vn2008.Contactos CT on CT.Telefono = dst
-JOIN vn2008.Relaciones using(Id_Contacto)
-WHERE Id_Cliente IS NOT NULL
-AND duration > 30
-UNION ALL
-SELECT Id_Cliente, calldate
-FROM vn2008.cdr
-JOIN vn2008.Contactos CT on CT.Movil = dst
-JOIN vn2008.Relaciones using(Id_Contacto)
-WHERE Id_Cliente IS NOT NULL
-AND duration > 30
-UNION ALL
-SELECT Id_Cliente, calldate
-FROM vn2008.cdr
-JOIN vn2008.Clientes CT on CT.Telefono = dst
-WHERE duration > 30
-UNION ALL
-SELECT Id_Cliente, calldate
-FROM vn2008.cdr
-JOIN vn2008.Clientes CT on CT.Movil = dst
-WHERE duration > 30
-UNION ALL
-SELECT C.Id_Cliente, Fecha
-FROM vn2008.Tickets JOIN vn2008.Consignatarios C using(Id_Consigna)
-) sub
-GROUP BY Id_Cliente ) sub2 USING(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 `Velocity_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 `Velocity_Add`()
-BEGIN
-
-DECLARE bol_EXISTS BOOL;
-DECLARE datMAX DATETIME;
-DECLARE v_buffer VARCHAR(11);
-DECLARE v_sql VARCHAR(255);
-
-
-
-SELECT MAX(Fecha) INTO datMAX FROM bi.Velocity;
-
-IF Date(datMAX) = CURDATE() AND hour(datMAX) > hour(now()) THEN
-
-
- SET v_buffer = vn2008.buffer_name(CURDATE(),1);
-
- SELECT count(*) INTO bol_EXISTS FROM information_schema.`TABLES`
- WHERE TABLE_NAME = CONVERT(v_buffer using utf8) collate utf8_general_ci;
-
- IF bol_EXISTS THEN
-
- SET v_sql = sql_printf (
- 'INSERT INTO bi.Velocity(tipo_id, Fecha, Disponible, Visible)
- SELECT A.tipo_id, NOW(), sum(avalaible), sum(visible)
- FROM vn2008.%t b
- JOIN Articles A ON b.item_id = A.Id_Article GROUP BY tipo_id;
- ',
- v_buffer
- );
-
-
- CALL sql_query (v_sql);
-
- 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 */ ;
-
---
--- Current Database: `vn`
---
-
-CREATE DATABASE /*!32312 IF NOT EXISTS*/ `vn` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
-
-USE `vn`;
-
---
--- Temporary view structure for view `accounting`
---
-
-DROP TABLE IF EXISTS `accounting`;
-/*!50001 DROP VIEW IF EXISTS `accounting`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `accounting` AS SELECT
- 1 AS `id`,
- 1 AS `bank`,
- 1 AS `account`,
- 1 AS `accountingTypeFk`,
- 1 AS `entityFk`,
- 1 AS `isActive`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `accountingType`
---
-
-DROP TABLE IF EXISTS `accountingType`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `accountingType` (
- `id` smallint(6) NOT NULL DEFAULT '0',
- `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='descripcio dels valors de la columna "cash" de la taula vn2008.Bancios';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `activityTaxDismissed`
---
-
-DROP TABLE IF EXISTS `activityTaxDismissed`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `activityTaxDismissed` (
- `clientFk` int(11) NOT NULL,
- `isNotified` tinyint(1) DEFAULT '0',
- `isDismissed` tinyint(1) DEFAULT '0',
- `notified` int(11) DEFAULT '0',
- PRIMARY KEY (`clientFk`),
- CONSTRAINT `clientFk` FOREIGN KEY (`clientFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) 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 */;
-
---
--- Temporary view structure for view `address`
---
-
-DROP TABLE IF EXISTS `address`;
-/*!50001 DROP VIEW IF EXISTS `address`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `address` AS SELECT
- 1 AS `customer`,
- 1 AS `warehouse`,
- 1 AS `street`,
- 1 AS `city`,
- 1 AS `province`,
- 1 AS `postalCode`,
- 1 AS `phone`,
- 1 AS `celular`,
- 1 AS `nickname`,
- 1 AS `id`,
- 1 AS `defaultAddress`,
- 1 AS `agency`,
- 1 AS `active`,
- 1 AS `longitude`,
- 1 AS `latitude`,
- 1 AS `clientFk`,
- 1 AS `warehouseFk`,
- 1 AS `provinceFk`,
- 1 AS `mobile`,
- 1 AS `agencyFk`,
- 1 AS `isEqualizated`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `addressForPackaging`
---
-
-DROP TABLE IF EXISTS `addressForPackaging`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `addressForPackaging` (
- `addressFk` int(11) NOT NULL,
- `packagingValue` decimal(10,2) NOT NULL DEFAULT '0.04',
- PRIMARY KEY (`addressFk`),
- CONSTRAINT `addresForPackaging_fk1` FOREIGN KEY (`addressFk`) REFERENCES `vn2008`.`Consignatarios` (`id_consigna`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `addressObservation`
---
-
-DROP TABLE IF EXISTS `addressObservation`;
-/*!50001 DROP VIEW IF EXISTS `addressObservation`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `addressObservation` AS SELECT
- 1 AS `id`,
- 1 AS `addressFk`,
- 1 AS `observationTypeFk`,
- 1 AS `description`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `agency`
---
-
-DROP TABLE IF EXISTS `agency`;
-/*!50001 DROP VIEW IF EXISTS `agency`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `agency` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `warehouse`,
- 1 AS `warehouseFk`,
- 1 AS `isVolumetric`,
- 1 AS `bank`,
- 1 AS `bankFk`,
- 1 AS `warehouseNickname`,
- 1 AS `warehouseAliasFk`,
- 1 AS `own`,
- 1 AS `labelZone`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `agencyHour`
---
-
-DROP TABLE IF EXISTS `agencyHour`;
-/*!50001 DROP VIEW IF EXISTS `agencyHour`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `agencyHour` AS SELECT
- 1 AS `id`,
- 1 AS `agency`,
- 1 AS `weekDay`,
- 1 AS `warehouse`,
- 1 AS `province`,
- 1 AS `substractDay`,
- 1 AS `maxHour`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `agencyMode`
---
-
-DROP TABLE IF EXISTS `agencyMode`;
-/*!50001 DROP VIEW IF EXISTS `agencyMode`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `agencyMode` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `description`,
- 1 AS `view`,
- 1 AS `deliveryMethod`,
- 1 AS `m3`,
- 1 AS `cod71`,
- 1 AS `web`,
- 1 AS `agency`,
- 1 AS `agencyFk`,
- 1 AS `agencyService`,
- 1 AS `agencyServiceFk`,
- 1 AS `inflacion`,
- 1 AS `isVolumetric`,
- 1 AS `reportMail`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `agencyWarehouse`
---
-
-DROP TABLE IF EXISTS `agencyWarehouse`;
-/*!50001 DROP VIEW IF EXISTS `agencyWarehouse`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `agencyWarehouse` AS SELECT
- 1 AS `agencyFk`,
- 1 AS `warehouseFk`,
- 1 AS `agencyType`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `autonomousRegion`
---
-
-DROP TABLE IF EXISTS `autonomousRegion`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `autonomousRegion` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(50) CHARACTER SET utf8 NOT NULL,
- `geoFk` int(11) DEFAULT NULL,
- `countryFk` mediumint(8) unsigned DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `countryFk` (`countryFk`),
- CONSTRAINT `countryFk` FOREIGN KEY (`countryFk`) REFERENCES `vn2008`.`Paises` (`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 */;
-
---
--- Temporary view structure for view `awb`
---
-
-DROP TABLE IF EXISTS `awb`;
-/*!50001 DROP VIEW IF EXISTS `awb`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `awb` AS SELECT
- 1 AS `id`,
- 1 AS `code`,
- 1 AS `package`,
- 1 AS `weight`,
- 1 AS `created`,
- 1 AS `transitoryFk`,
- 1 AS `taxFk`,
- 1 AS `docFk`,
- 1 AS `amount`,
- 1 AS `freightFk`,
- 1 AS `m3`,
- 1 AS `stems`,
- 1 AS `flightFk`,
- 1 AS `volumeWeight`,
- 1 AS `hb`,
- 1 AS `rate`,
- 1 AS `booked`,
- 1 AS `issued`,
- 1 AS `operated`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `bank`
---
-
-DROP TABLE IF EXISTS `bank`;
-/*!50001 DROP VIEW IF EXISTS `bank`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `bank` AS SELECT
- 1 AS `id`,
- 1 AS `bank`,
- 1 AS `account`,
- 1 AS `cash`,
- 1 AS `entityFk`,
- 1 AS `isActive`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `bookingPlanner`
---
-
-DROP TABLE IF EXISTS `bookingPlanner`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `bookingPlanner` (
- `id` int(10) NOT NULL AUTO_INCREMENT,
- `effectived` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `pgcFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
- `taxAreaFk` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'SPAIN',
- `priority` int(2) unsigned DEFAULT NULL,
- `taxClassFk` tinyint(3) unsigned NOT NULL DEFAULT '1',
- `countryFk` mediumint(8) unsigned NOT NULL DEFAULT '1',
- PRIMARY KEY (`id`),
- KEY `taxArea_bookingPlanner_idx` (`taxAreaFk`),
- KEY `pgcFk_bookingPlanner_idx` (`pgcFk`),
- KEY `taxClassFk` (`taxClassFk`),
- KEY `countryFk` (`countryFk`),
- CONSTRAINT `bookingPlanner_ibfk_1` FOREIGN KEY (`pgcFk`) REFERENCES `pgc` (`code`) ON DELETE CASCADE,
- CONSTRAINT `bookingPlanner_ibfk_2` FOREIGN KEY (`taxClassFk`) REFERENCES `vn2008`.`iva_group` (`iva_group_id`) ON DELETE CASCADE,
- CONSTRAINT `bookingPlanner_ibfk_3` FOREIGN KEY (`countryFk`) REFERENCES `vn2008`.`Paises` (`Id`) ON DELETE CASCADE,
- CONSTRAINT `taxArea_bookingPlanner` FOREIGN KEY (`taxAreaFk`) REFERENCES `taxArea` (`code`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `botanicExport`
---
-
-DROP TABLE IF EXISTS `botanicExport`;
-/*!50001 DROP VIEW IF EXISTS `botanicExport`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `botanicExport` AS SELECT
- 1 AS `id`,
- 1 AS `ediGenusFk`,
- 1 AS `ediSpecieFk`,
- 1 AS `countryFk`,
- 1 AS `restriction`,
- 1 AS `description`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `buy`
---
-
-DROP TABLE IF EXISTS `buy`;
-/*!50001 DROP VIEW IF EXISTS `buy`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `buy` AS SELECT
- 1 AS `id`,
- 1 AS `entryFk`,
- 1 AS `itemFk`,
- 1 AS `amount`,
- 1 AS `buyingValue`,
- 1 AS `quantity`,
- 1 AS `packageFk`,
- 1 AS `stickers`,
- 1 AS `freightValue`,
- 1 AS `packageValue`,
- 1 AS `comissionValue`,
- 1 AS `packing`,
- 1 AS `grouping`,
- 1 AS `groupingMode`,
- 1 AS `location`,
- 1 AS `price1`,
- 1 AS `price2`,
- 1 AS `price3`,
- 1 AS `minPrice`,
- 1 AS `producer`,
- 1 AS `printedStickers`,
- 1 AS `isChecked`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `category`
---
-
-DROP TABLE IF EXISTS `category`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `category` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
- `nick` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
- 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 `city`
---
-
-DROP TABLE IF EXISTS `city`;
-/*!50001 DROP VIEW IF EXISTS `city`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `city` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `provinceFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `client`
---
-
-DROP TABLE IF EXISTS `client`;
-/*!50001 DROP VIEW IF EXISTS `client`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `client` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `fi`,
- 1 AS `socialName`,
- 1 AS `contact`,
- 1 AS `street`,
- 1 AS `city`,
- 1 AS `postcode`,
- 1 AS `phone`,
- 1 AS `mobile`,
- 1 AS `fax`,
- 1 AS `isRelevant`,
- 1 AS `email`,
- 1 AS `iban`,
- 1 AS `dueDay`,
- 1 AS `accountingAccount`,
- 1 AS `isEqualizated`,
- 1 AS `provinceFk`,
- 1 AS `hasToInvoice`,
- 1 AS `credit`,
- 1 AS `countryFk`,
- 1 AS `isActive`,
- 1 AS `gestdocFk`,
- 1 AS `quality`,
- 1 AS `payMethodFk`,
- 1 AS `created`,
- 1 AS `isToBeMailed`,
- 1 AS `contactChannelFk`,
- 1 AS `hasSepaVnl`,
- 1 AS `hasCoreVnl`,
- 1 AS `hasCoreVnh`,
- 1 AS `riskCalculated`,
- 1 AS `clientTypeFk`,
- 1 AS `mailAddress`,
- 1 AS `cplusTerIdNifFk`,
- 1 AS `hasToInvoiceByAddress`,
- 1 AS `isTaxDataChecked`,
- 1 AS `isFreezed`,
- 1 AS `creditInsurance`,
- 1 AS `isCreatedAsServed`,
- 1 AS `hasInvoiceSimplified`,
- 1 AS `salesPersonFk`,
- 1 AS `isVies`,
- 1 AS `eypbc`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `clientCreditLimit`
---
-
-DROP TABLE IF EXISTS `clientCreditLimit`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `clientCreditLimit` (
- `id` int(11) NOT NULL,
- `maxAmount` int(10) unsigned NOT NULL,
- `roleFk` int(10) unsigned NOT NULL,
- 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 `clientManaCache`
---
-
-DROP TABLE IF EXISTS `clientManaCache`;
-/*!50001 DROP VIEW IF EXISTS `clientManaCache`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `clientManaCache` AS SELECT
- 1 AS `clientFk`,
- 1 AS `mana`,
- 1 AS `dated`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `clientObservation`
---
-
-DROP TABLE IF EXISTS `clientObservation`;
-/*!50001 DROP VIEW IF EXISTS `clientObservation`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `clientObservation` AS SELECT
- 1 AS `id`,
- 1 AS `client`,
- 1 AS `worker`,
- 1 AS `text`,
- 1 AS `creationDate`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `clientType`
---
-
-DROP TABLE IF EXISTS `clientType`;
-/*!50001 DROP VIEW IF EXISTS `clientType`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `clientType` AS SELECT
- 1 AS `id`,
- 1 AS `code`,
- 1 AS `type`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `company`
---
-
-DROP TABLE IF EXISTS `company`;
-/*!50001 DROP VIEW IF EXISTS `company`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `company` AS SELECT
- 1 AS `id`,
- 1 AS `code`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `confectionType`
---
-
-DROP TABLE IF EXISTS `confectionType`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `confectionType` (
- `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
- `description` varchar(45) COLLATE utf8_unicode_ci NOT 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 `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(10) unsigned NOT NULL AUTO_INCREMENT,
- `mdbServer` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `fakeEmail` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
- `defaultersMaxAmount` int(10) DEFAULT '200' COMMENT 'maxima deuda permitida a partir de la cual se bloquea a un usuario',
- PRIMARY KEY (`id`)
-) 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 `country`
---
-
-DROP TABLE IF EXISTS `country`;
-/*!50001 DROP VIEW IF EXISTS `country`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `country` AS SELECT
- 1 AS `id`,
- 1 AS `country`,
- 1 AS `CEE`,
- 1 AS `isUeeMember`,
- 1 AS `Code`,
- 1 AS `currencyFk`,
- 1 AS `politicalCountryFk`,
- 1 AS `geoFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `cplusCorrectingType`
---
-
-DROP TABLE IF EXISTS `cplusCorrectingType`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `cplusCorrectingType` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `description` varchar(45) COLLATE utf8_unicode_ci NOT 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 `cplusInvoiceType472`
---
-
-DROP TABLE IF EXISTS `cplusInvoiceType472`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `cplusInvoiceType472` (
- `id` int(10) unsigned NOT NULL,
- `description` varchar(255) CHARACTER SET utf8 NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='(*18) TIPO FACTURA (Asientos)SOPORTADO – DEDUCIBLE (472)';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `cplusInvoiceType477`
---
-
-DROP TABLE IF EXISTS `cplusInvoiceType477`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `cplusInvoiceType477` (
- `id` int(10) unsigned NOT NULL,
- `description` varchar(255) CHARACTER SET utf8 NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='(*18) TIPO FACTURA (Asientos)REPERCUTIDO - DEVENGADO (477)';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `cplusRectificationType`
---
-
-DROP TABLE IF EXISTS `cplusRectificationType`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `cplusRectificationType` (
- `id` int(10) unsigned NOT NULL,
- `description` varchar(255) CHARACTER SET utf8 NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='(*20) TIPO RECTIFICATIVA (Asientos)';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `cplusSubjectOp`
---
-
-DROP TABLE IF EXISTS `cplusSubjectOp`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `cplusSubjectOp` (
- `id` int(10) unsigned NOT NULL,
- `description` varchar(255) CHARACTER SET utf8 NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='(*17) TIPO OPERACIÓN SUJETA/NO SUJETA (Asientos)';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `cplusTaxBreak`
---
-
-DROP TABLE IF EXISTS `cplusTaxBreak`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `cplusTaxBreak` (
- `id` int(10) unsigned NOT NULL,
- `description` varchar(255) CHARACTER SET utf8 NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='(*16) TIPO EXENCIÓN (Asientos)';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `cplusTerIdNif`
---
-
-DROP TABLE IF EXISTS `cplusTerIdNif`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `cplusTerIdNif` (
- `id` int(11) NOT NULL,
- `description` varchar(255) CHARACTER SET utf8 NOT 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 `cplusTrascendency472`
---
-
-DROP TABLE IF EXISTS `cplusTrascendency472`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `cplusTrascendency472` (
- `id` int(10) unsigned NOT NULL,
- `description` varchar(255) CHARACTER SET utf8 NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='(*15) CLAVE DE RÉGIMEN ESPECIAL O TRASCENDENCIA(Asientos)SOPORTADO – DEDUCIBLE (472)';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `cplusTrascendency477`
---
-
-DROP TABLE IF EXISTS `cplusTrascendency477`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `cplusTrascendency477` (
- `id` int(10) unsigned NOT NULL,
- `description` varchar(255) CHARACTER SET utf8 NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='(*15) CLAVE DE RÉGIMEN ESPECIAL O TRASCENDENCIA(Asientos) REPERCUTIDO - DEVENGADO (477)';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `creditClassification`
---
-
-DROP TABLE IF EXISTS `creditClassification`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `creditClassification` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `client` int(11) NOT NULL,
- `dateStart` date NOT NULL,
- `dateEnd` date DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `creditClassifClientFk_idx` (`client`),
- KEY `creditClassifdateEnd_idx` (`dateEnd`),
- CONSTRAINT `creditClassifClientFk` FOREIGN KEY (`client`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `vn`.`creditClassification_BEFORE_UPDATE` BEFORE UPDATE ON `creditClassification` FOR EACH ROW
-BEGIN
- IF NEW.client <> OLD.client THEN
- CALL util.throw('NOT_ALLOWED_CHANGE_CLIENT');
- END IF;
- IF NEW.dateEnd IS NOT NULL AND OLD.dateEnd IS NULL THEN
- UPDATE vn2008.Clientes c
- SET creditInsurance = 0 WHERE c.Id_cliente = NEW.client;
- 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 */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Table structure for table `creditInsurance`
---
-
-DROP TABLE IF EXISTS `creditInsurance`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `creditInsurance` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `creditClassification` int(11) DEFAULT NULL,
- `credit` int(11) DEFAULT NULL,
- `creationDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `grade` tinyint(1) DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `CreditInsurance_Fk1_idx` (`creditClassification`),
- CONSTRAINT `CreditInsurance_Fk1` FOREIGN KEY (`creditClassification`) REFERENCES `creditClassification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalla los clientes que tienen seguro de credito';
-/*!40101 SET character_set_client = @saved_cs_client */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `vn`.`creditInsurance_AFTER_INSERT` AFTER INSERT ON `creditInsurance` FOR EACH ROW
-BEGIN
- UPDATE vn2008.Clientes c
- JOIN vn.creditClassification cc ON cc.client = c.Id_Cliente
- SET creditInsurance = NEW.credit WHERE cc.id = NEW.creditClassification;
-
-END */;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Table structure for table `dailyTaskLog`
---
-
-DROP TABLE IF EXISTS `dailyTaskLog`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `dailyTaskLog` (
- `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
- `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `deliveryError`
---
-
-DROP TABLE IF EXISTS `deliveryError`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `deliveryError` (
- `ticket` int(11) NOT NULL,
- `description` varchar(255) CHARACTER SET latin1 NOT NULL,
- `worker` int(11) NOT NULL,
- `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- KEY `errorTickets_idx` (`ticket`),
- KEY `errorWorker_idx` (`worker`),
- CONSTRAINT `errorTickets` FOREIGN KEY (`ticket`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE NO ACTION ON UPDATE NO ACTION,
- CONSTRAINT `errorWorker` FOREIGN KEY (`worker`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) 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 */;
-
---
--- Temporary view structure for view `deliveryMethod`
---
-
-DROP TABLE IF EXISTS `deliveryMethod`;
-/*!50001 DROP VIEW IF EXISTS `deliveryMethod`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `deliveryMethod` AS SELECT
- 1 AS `id`,
- 1 AS `code`,
- 1 AS `description`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `ediGenus`
---
-
-DROP TABLE IF EXISTS `ediGenus`;
-/*!50001 DROP VIEW IF EXISTS `ediGenus`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ediGenus` AS SELECT
- 1 AS `id`,
- 1 AS `latinGenusName`,
- 1 AS `entried`,
- 1 AS `dued`,
- 1 AS `modified`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `ediSpecie`
---
-
-DROP TABLE IF EXISTS `ediSpecie`;
-/*!50001 DROP VIEW IF EXISTS `ediSpecie`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ediSpecie` AS SELECT
- 1 AS `id`,
- 1 AS `genusFk`,
- 1 AS `latinSpeciesName`,
- 1 AS `entried`,
- 1 AS `dued`,
- 1 AS `modified`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `entry`
---
-
-DROP TABLE IF EXISTS `entry`;
-/*!50001 DROP VIEW IF EXISTS `entry`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `entry` AS SELECT
- 1 AS `id`,
- 1 AS `supplierFk`,
- 1 AS `ref`,
- 1 AS `isInventory`,
- 1 AS `isConfirmed`,
- 1 AS `isOrdered`,
- 1 AS `isRaid`,
- 1 AS `commission`,
- 1 AS `created`,
- 1 AS `evaNotes`,
- 1 AS `travelFk`,
- 1 AS `currencyFk`,
- 1 AS `companyFk`,
- 1 AS `gestDocFk`,
- 1 AS `invoiceReceivedFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `especialPrice`
---
-
-DROP TABLE IF EXISTS `especialPrice`;
-/*!50001 DROP VIEW IF EXISTS `especialPrice`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `especialPrice` AS SELECT
- 1 AS `id`,
- 1 AS `clientFk`,
- 1 AS `itemFk`,
- 1 AS `value`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `excuse`
---
-
-DROP TABLE IF EXISTS `excuse`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `excuse` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `txt` varchar(255) CHARACTER SET latin1 NOT NULL,
- `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
- 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 `expedition`
---
-
-DROP TABLE IF EXISTS `expedition`;
-/*!50001 DROP VIEW IF EXISTS `expedition`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `expedition` AS SELECT
- 1 AS `id`,
- 1 AS `agency`,
- 1 AS `agencyFk`,
- 1 AS `ticket`,
- 1 AS `ticketFk`,
- 1 AS `isBox`,
- 1 AS `printingTime`,
- 1 AS `item`,
- 1 AS `itemFk`,
- 1 AS `counter`,
- 1 AS `checked`,
- 1 AS `workerFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `expence`
---
-
-DROP TABLE IF EXISTS `expence`;
-/*!50001 DROP VIEW IF EXISTS `expence`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `expence` AS SELECT
- 1 AS `id`,
- 1 AS `taxTypeFk`,
- 1 AS `name`,
- 1 AS `isWithheld`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `family`
---
-
-DROP TABLE IF EXISTS `family`;
-/*!50001 DROP VIEW IF EXISTS `family`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `family` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `life`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `grant`
---
-
-DROP TABLE IF EXISTS `grant`;
-/*!50001 DROP VIEW IF EXISTS `grant`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `grant` AS SELECT
- 1 AS `group`,
- 1 AS `worker`,
- 1 AS `company`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `grantGroup`
---
-
-DROP TABLE IF EXISTS `grantGroup`;
-/*!50001 DROP VIEW IF EXISTS `grantGroup`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `grantGroup` AS SELECT
- 1 AS `id`,
- 1 AS `description`,
- 1 AS `observationType`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `ink`
---
-
-DROP TABLE IF EXISTS `ink`;
-/*!50001 DROP VIEW IF EXISTS `ink`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ink` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `picture`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `intrastat`
---
-
-DROP TABLE IF EXISTS `intrastat`;
-/*!50001 DROP VIEW IF EXISTS `intrastat`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `intrastat` AS SELECT
- 1 AS `id`,
- 1 AS `description`,
- 1 AS `taxGroupFk`,
- 1 AS `taxCodeFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `invoiceCorrection`
---
-
-DROP TABLE IF EXISTS `invoiceCorrection`;
-/*!50001 DROP VIEW IF EXISTS `invoiceCorrection`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `invoiceCorrection` AS SELECT
- 1 AS `correctingFk`,
- 1 AS `correctedFk`,
- 1 AS `cplusRectificationTypeFk`,
- 1 AS `cplusInvoiceType477Fk`,
- 1 AS `invoiceCorrectionTypeFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `invoiceCorrectionDataSource`
---
-
-DROP TABLE IF EXISTS `invoiceCorrectionDataSource`;
-/*!50001 DROP VIEW IF EXISTS `invoiceCorrectionDataSource`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `invoiceCorrectionDataSource` AS SELECT
- 1 AS `itemFk`,
- 1 AS `quantity`,
- 1 AS `concept`,
- 1 AS `price`,
- 1 AS `discount`,
- 1 AS `refFk`,
- 1 AS `saleFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `invoiceCorrectionType`
---
-
-DROP TABLE IF EXISTS `invoiceCorrectionType`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `invoiceCorrectionType` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `description_UNIQUE` (`description`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `invoiceIn`
---
-
-DROP TABLE IF EXISTS `invoiceIn`;
-/*!50001 DROP VIEW IF EXISTS `invoiceIn`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `invoiceIn` AS SELECT
- 1 AS `id`,
- 1 AS `serialNumber`,
- 1 AS `serial`,
- 1 AS `supplierFk`,
- 1 AS `issued`,
- 1 AS `supplierRef`,
- 1 AS `isBooked`,
- 1 AS `currencyFk`,
- 1 AS `created`,
- 1 AS `companyFk`,
- 1 AS `docFk`,
- 1 AS `booked`,
- 1 AS `operated`,
- 1 AS `cplusInvoiceType472Fk`,
- 1 AS `cplusRectificationTypeFk`,
- 1 AS `cplusSubjectOpFk`,
- 1 AS `cplusTaxBreakFk`,
- 1 AS `cplusTrascendency472Fk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `invoiceInAwb`
---
-
-DROP TABLE IF EXISTS `invoiceInAwb`;
-/*!50001 DROP VIEW IF EXISTS `invoiceInAwb`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `invoiceInAwb` AS SELECT
- 1 AS `invoiceInFk`,
- 1 AS `awbFk`,
- 1 AS `dua`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `invoiceInEntry`
---
-
-DROP TABLE IF EXISTS `invoiceInEntry`;
-/*!50001 DROP VIEW IF EXISTS `invoiceInEntry`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `invoiceInEntry` AS SELECT
- 1 AS `id`,
- 1 AS `invoiceInFk`,
- 1 AS `entryFk`,
- 1 AS `percentage`,
- 1 AS `invoiceInAwbFk`,
- 1 AS `isBooked`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `invoiceInIntrastat`
---
-
-DROP TABLE IF EXISTS `invoiceInIntrastat`;
-/*!50001 DROP VIEW IF EXISTS `invoiceInIntrastat`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `invoiceInIntrastat` AS SELECT
- 1 AS `invoiceInFk`,
- 1 AS `intrastatFk`,
- 1 AS `amount`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `invoiceInSerial`
---
-
-DROP TABLE IF EXISTS `invoiceInSerial`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `invoiceInSerial` (
- `code` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
- `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `cplusTerIdNifFk` int(11) NOT NULL DEFAULT '1',
- PRIMARY KEY (`code`),
- KEY `InvoiceInSerial_Fk1_idx` (`cplusTerIdNifFk`),
- CONSTRAINT `InvoiceInSerial_Fk1` FOREIGN KEY (`cplusTerIdNifFk`) REFERENCES `cplusTerIdNif` (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `invoiceInTax`
---
-
-DROP TABLE IF EXISTS `invoiceInTax`;
-/*!50001 DROP VIEW IF EXISTS `invoiceInTax`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `invoiceInTax` AS SELECT
- 1 AS `id`,
- 1 AS `invoiceInFk`,
- 1 AS `taxCodeFk`,
- 1 AS `taxableBase`,
- 1 AS `expenceFk`,
- 1 AS `foreignValue`,
- 1 AS `created`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `invoiceOut`
---
-
-DROP TABLE IF EXISTS `invoiceOut`;
-/*!50001 DROP VIEW IF EXISTS `invoiceOut`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `invoiceOut` AS SELECT
- 1 AS `id`,
- 1 AS `ref`,
- 1 AS `serial`,
- 1 AS `issued`,
- 1 AS `amount`,
- 1 AS `clientFk`,
- 1 AS `created`,
- 1 AS `companyFk`,
- 1 AS `dued`,
- 1 AS `booked`,
- 1 AS `cplusInvoiceType477Fk`,
- 1 AS `cplusTaxBreakFk`,
- 1 AS `cplusSubjectOpFk`,
- 1 AS `cplusTrascendency477Fk`,
- 1 AS `pdf`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `invoiceOutExpence`
---
-
-DROP TABLE IF EXISTS `invoiceOutExpence`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `invoiceOutExpence` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `invoiceOutFk` int(10) unsigned NOT NULL,
- `amount` decimal(10,2) NOT NULL DEFAULT '0.00',
- `expenceFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
- `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (`id`),
- UNIQUE KEY `invoiceOutExpence_restriccion` (`expenceFk`,`invoiceOutFk`),
- KEY `invoiceOutExpence_FK_1_idx` (`invoiceOutFk`),
- KEY `invoiceOutExpence_FK_2_idx` (`expenceFk`),
- CONSTRAINT `invoiceOutExpence_FK_1` FOREIGN KEY (`invoiceOutFk`) REFERENCES `vn2008`.`Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `invoiceOutExpence_FK_2` FOREIGN KEY (`expenceFk`) REFERENCES `vn2008`.`Gastos` (`Id_Gasto`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Desglosa la base imponible de una factura en funcion del tipo de gasto/venta';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `invoiceOutSerial`
---
-
-DROP TABLE IF EXISTS `invoiceOutSerial`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `invoiceOutSerial` (
- `code` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
- `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `isTaxed` tinyint(1) NOT NULL DEFAULT '1',
- `taxAreaFk` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'NATIONAL',
- `isCEE` tinyint(1) NOT NULL DEFAULT '0',
- PRIMARY KEY (`code`),
- KEY `taxAreaFk_idx` (`taxAreaFk`),
- CONSTRAINT `invoiceOutSerial_ibfk_1` FOREIGN KEY (`taxAreaFk`) REFERENCES `taxArea` (`code`) ON DELETE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `invoiceOutTax`
---
-
-DROP TABLE IF EXISTS `invoiceOutTax`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `invoiceOutTax` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `invoiceOutFk` int(10) unsigned NOT NULL,
- `taxableBase` decimal(10,2) NOT NULL,
- `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `vat` decimal(10,2) NOT NULL DEFAULT '0.00',
- `pgcFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0000000000',
- PRIMARY KEY (`id`),
- UNIQUE KEY `invoiceOutTax_Resctriccion` (`invoiceOutFk`,`pgcFk`),
- KEY `invoiceOutFk_idx` (`invoiceOutFk`),
- KEY `pgcFk` (`pgcFk`),
- CONSTRAINT `invoiceOutFk` FOREIGN KEY (`invoiceOutFk`) REFERENCES `vn2008`.`Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `invoiceOutTax_ibfk_1` FOREIGN KEY (`pgcFk`) REFERENCES `pgc` (`code`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `item`
---
-
-DROP TABLE IF EXISTS `item`;
-/*!50001 DROP VIEW IF EXISTS `item`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `item` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `familyFk`,
- 1 AS `size`,
- 1 AS `inkFk`,
- 1 AS `category`,
- 1 AS `stems`,
- 1 AS `originFk`,
- 1 AS `description`,
- 1 AS `producerFk`,
- 1 AS `intrastatFk`,
- 1 AS `expenceFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `itemBotanical`
---
-
-DROP TABLE IF EXISTS `itemBotanical`;
-/*!50001 DROP VIEW IF EXISTS `itemBotanical`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `itemBotanical` AS SELECT
- 1 AS `itemFk`,
- 1 AS `botanical`,
- 1 AS `genusFk`,
- 1 AS `specieFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `itemBotanicalWithGenus`
---
-
-DROP TABLE IF EXISTS `itemBotanicalWithGenus`;
-/*!50001 DROP VIEW IF EXISTS `itemBotanicalWithGenus`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `itemBotanicalWithGenus` AS SELECT
- 1 AS `itemFk`,
- 1 AS `ediBotanic`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `itemConversor`
---
-
-DROP TABLE IF EXISTS `itemConversor`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `itemConversor` (
- `espItemFk` int(11) NOT NULL,
- `genItemFk` int(11) DEFAULT NULL,
- PRIMARY KEY (`espItemFk`),
- KEY `itemConversor_fk2_idx` (`genItemFk`),
- CONSTRAINT `itemConversor_fk1` FOREIGN KEY (`espItemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `itemConversor_fk2` FOREIGN KEY (`genItemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona los item específicos con los genéricos';
-/*!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;
-
---
--- Table structure for table `itemTagArranged`
---
-
-DROP TABLE IF EXISTS `itemTagArranged`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `itemTagArranged` (
- `itemFk` int(11) NOT NULL,
- `tag1` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
- `val1` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
- `tag2` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
- `val2` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
- `tag3` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
- `val3` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
- `tag4` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
- `val4` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
- `tag5` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
- `val5` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
- `tag6` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
- `val6` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
- `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
- PRIMARY KEY (`itemFk`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Cache de columnas de características de artículo';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `itemTagged`
---
-
-DROP TABLE IF EXISTS `itemTagged`;
-/*!50001 DROP VIEW IF EXISTS `itemTagged`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `itemTagged` AS SELECT
- 1 AS `itemFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `itemTaxCountry`
---
-
-DROP TABLE IF EXISTS `itemTaxCountry`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `itemTaxCountry` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `itemFk` int(11) DEFAULT NULL,
- `countryFk` mediumint(8) unsigned DEFAULT NULL,
- `taxClassFk` tinyint(3) unsigned NOT NULL DEFAULT '1',
- `effectived` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (`id`),
- KEY `taxClassFK_idx` (`taxClassFk`),
- KEY `countryFK_paises_idx` (`countryFk`),
- KEY `itemFK_Article_idx` (`itemFk`),
- CONSTRAINT `countryFK_paises` FOREIGN KEY (`countryFk`) REFERENCES `vn2008`.`Paises` (`Id`) ON UPDATE CASCADE,
- CONSTRAINT `itemFK_Article` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `taxClassFK_Iva_Group` FOREIGN KEY (`taxClassFk`) REFERENCES `vn2008`.`iva_group` (`iva_group_id`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Define la clase de iva por artículo y pais';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `itemVerdecora`
---
-
-DROP TABLE IF EXISTS `itemVerdecora`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `itemVerdecora` (
- `itemFk` int(11) NOT NULL,
- `codin` int(11) DEFAULT NULL,
- PRIMARY KEY (`itemFk`),
- CONSTRAINT `itemVerdecora_fk1` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona nuestros articulos con los de Verdecora';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `logClient`
---
-
-DROP TABLE IF EXISTS `logClient`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `logClient` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `originFk` int(11) NOT NULL,
- `userFk` int(10) unsigned NOT NULL,
- `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
- `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
- `description` text COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`),
- KEY `originFk` (`originFk`),
- KEY `userFk` (`userFk`),
- CONSTRAINT `logClient_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE NO ACTION ON UPDATE NO ACTION,
- CONSTRAINT `logClient_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`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 `logEntry`
---
-
-DROP TABLE IF EXISTS `logEntry`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `logEntry` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `originFk` int(11) NOT NULL,
- `userFk` int(10) unsigned NOT NULL,
- `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
- `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
- `description` text COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`),
- KEY `userFk` (`userFk`),
- KEY `logEntry_ibfk_1` (`originFk`),
- CONSTRAINT `logEntry_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `logEntry_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`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 `logTicket`
---
-
-DROP TABLE IF EXISTS `logTicket`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `logTicket` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `originFk` int(11) NOT NULL,
- `userFk` int(10) unsigned NOT NULL,
- `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
- `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
- `description` text COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`),
- KEY `logTicketoriginFk` (`originFk`),
- KEY `logTicketuserFk` (`userFk`),
- CONSTRAINT `logTicket_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `logTicket_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`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 `logType`
---
-
-DROP TABLE IF EXISTS `logType`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `logType` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `code` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
- `originTableName` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
- `logTableName` varchar(45) COLLATE utf8_unicode_ci NOT 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 `logWorker`
---
-
-DROP TABLE IF EXISTS `logWorker`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `logWorker` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `originFk` int(11) NOT NULL,
- `userFk` int(10) unsigned NOT NULL,
- `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
- `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
- `description` text COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`),
- KEY `workerFk_idx` (`originFk`),
- KEY `userFk_idx` (`userFk`),
- CONSTRAINT `userFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
- CONSTRAINT `workerFk` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) 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 */;
-
---
--- Temporary view structure for view `mail`
---
-
-DROP TABLE IF EXISTS `mail`;
-/*!50001 DROP VIEW IF EXISTS `mail`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `mail` AS SELECT
- 1 AS `id`,
- 1 AS `senderFk`,
- 1 AS `recipientFk`,
- 1 AS `sender`,
- 1 AS `replyTo`,
- 1 AS `subject`,
- 1 AS `body`,
- 1 AS `plainTextBody`,
- 1 AS `attachment`,
- 1 AS `creationDate`,
- 1 AS `sent`,
- 1 AS `status`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `mailTemplates`
---
-
-DROP TABLE IF EXISTS `mailTemplates`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `mailTemplates` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(50) CHARACTER SET utf8 NOT NULL,
- `attachmentPath` text CHARACTER SET utf8 NOT NULL,
- 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 `manaSpellers`
---
-
-DROP TABLE IF EXISTS `manaSpellers`;
-/*!50001 DROP VIEW IF EXISTS `manaSpellers`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `manaSpellers` AS SELECT
- 1 AS `worker`,
- 1 AS `size`,
- 1 AS `used`,
- 1 AS `pricesModifierRate`,
- 1 AS `pricesModifierActivated`,
- 1 AS `workerCode`,
- 1 AS `firstname`,
- 1 AS `name`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `message`
---
-
-DROP TABLE IF EXISTS `message`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `message` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `uuid` varchar(50) CHARACTER SET utf8 NOT NULL,
- `sender` varchar(50) CHARACTER SET utf8 NOT NULL,
- `recipient` varchar(50) CHARACTER SET utf8 NOT NULL,
- `message` longtext CHARACTER SET utf8,
- `sendDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (`id`),
- KEY `sender` (`sender`),
- KEY `recipient` (`recipient`),
- KEY `uuid` (`uuid`(8))
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `messageInbox`
---
-
-DROP TABLE IF EXISTS `messageInbox`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `messageInbox` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `uuid` varchar(50) CHARACTER SET utf8 NOT NULL,
- `sender` varchar(50) CHARACTER SET utf8 NOT NULL,
- `recipient` varchar(45) CHARACTER SET utf8 NOT NULL,
- `finalRecipient` varchar(50) CHARACTER SET utf8 NOT NULL,
- `message` longtext CHARACTER SET utf8,
- `sendDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
- `read` varchar(45) CHARACTER SET utf8 NOT NULL DEFAULT '0',
- PRIMARY KEY (`id`),
- KEY `uuid` (`uuid`(8)),
- KEY `finalRecipient` (`finalRecipient`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `movement`
---
-
-DROP TABLE IF EXISTS `movement`;
-/*!50001 DROP VIEW IF EXISTS `movement`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `movement` AS SELECT
- 1 AS `id`,
- 1 AS `item`,
- 1 AS `ticket`,
- 1 AS `concept`,
- 1 AS `amount`,
- 1 AS `quantity`,
- 1 AS `price`,
- 1 AS `discount`,
- 1 AS `cost`,
- 1 AS `reservado`,
- 1 AS `od`,
- 1 AS `priceFixed`,
- 1 AS `lastUpdate`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `noticeCategory`
---
-
-DROP TABLE IF EXISTS `noticeCategory`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `noticeCategory` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `keyName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `subject` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `description` text COLLATE utf8_unicode_ci,
- `isEnabled` tinyint(1) NOT NULL DEFAULT '1',
- `requiredRole` int(11) NOT NULL DEFAULT '1',
- PRIMARY KEY (`id`),
- UNIQUE KEY `keyName_UNIQUE` (`keyName`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `noticeSubscription`
---
-
-DROP TABLE IF EXISTS `noticeSubscription`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `noticeSubscription` (
- `noticeCategoryFk` int(11) NOT NULL DEFAULT '0',
- `userFk` int(10) unsigned NOT NULL DEFAULT '0',
- PRIMARY KEY (`noticeCategoryFk`,`userFk`),
- KEY `noticeSubscription_ibfk_2` (`userFk`),
- CONSTRAINT `noticeSubscription_ibfk_1` FOREIGN KEY (`noticeCategoryFk`) REFERENCES `noticeCategory` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `noticeSubscription_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `observationType`
---
-
-DROP TABLE IF EXISTS `observationType`;
-/*!50001 DROP VIEW IF EXISTS `observationType`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `observationType` AS SELECT
- 1 AS `id`,
- 1 AS `description`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `origin`
---
-
-DROP TABLE IF EXISTS `origin`;
-/*!50001 DROP VIEW IF EXISTS `origin`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `origin` AS SELECT
- 1 AS `id`,
- 1 AS `code`,
- 1 AS `name`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `outgoingInvoice`
---
-
-DROP TABLE IF EXISTS `outgoingInvoice`;
-/*!50001 DROP VIEW IF EXISTS `outgoingInvoice`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `outgoingInvoice` AS SELECT
- 1 AS `id`,
- 1 AS `serie`,
- 1 AS `dateInvoice`,
- 1 AS `total`,
- 1 AS `dueDate`,
- 1 AS `bank`,
- 1 AS `client`,
- 1 AS `remittance`,
- 1 AS `remit`,
- 1 AS `worker`,
- 1 AS `creationDate`,
- 1 AS `company`,
- 1 AS `liquidacion?`,
- 1 AS `isPdf`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `outgoingInvoiceVat`
---
-
-DROP TABLE IF EXISTS `outgoingInvoiceVat`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `outgoingInvoiceVat` (
- `outgoingInvoice` mediumint(8) NOT NULL,
- `taxBase` decimal(12,2) DEFAULT NULL,
- `equalizationTax` decimal(12,2) DEFAULT NULL,
- `Vat` decimal(12,2) DEFAULT NULL,
- PRIMARY KEY (`outgoingInvoice`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `package`
---
-
-DROP TABLE IF EXISTS `package`;
-/*!50001 DROP VIEW IF EXISTS `package`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `package` AS SELECT
- 1 AS `id`,
- 1 AS `volume`,
- 1 AS `width`,
- 1 AS `height`,
- 1 AS `depth`,
- 1 AS `isPackageReturnable`,
- 1 AS `created`,
- 1 AS `itemFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `payMethod`
---
-
-DROP TABLE IF EXISTS `payMethod`;
-/*!50001 DROP VIEW IF EXISTS `payMethod`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `payMethod` AS SELECT
- 1 AS `id`,
- 1 AS `name`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `pgc`
---
-
-DROP TABLE IF EXISTS `pgc`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `pgc` (
- `code` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
- `rate` decimal(10,2) NOT NULL,
- `name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `cplusTaxBreakFk` int(10) unsigned DEFAULT '1',
- `mod340` tinyint(1) NOT NULL DEFAULT '0',
- `mod347` tinyint(1) NOT NULL DEFAULT '0',
- `cplusTrascendency477Fk` int(10) unsigned DEFAULT '1',
- PRIMARY KEY (`code`),
- KEY `pgc_fk1_idx` (`cplusTaxBreakFk`),
- KEY `pgc_fk2_idx` (`cplusTrascendency477Fk`),
- CONSTRAINT `pgc_fk1` FOREIGN KEY (`cplusTaxBreakFk`) REFERENCES `cplusTaxBreak` (`id`) ON UPDATE CASCADE,
- CONSTRAINT `pgc_fk2` FOREIGN KEY (`cplusTrascendency477Fk`) REFERENCES `cplusTrascendency477` (`id`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Plan General Contable';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `pgcEqu`
---
-
-DROP TABLE IF EXISTS `pgcEqu`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `pgcEqu` (
- `vatFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Cuenta de IVA',
- `equFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Cuenta de recargo de equivalencia',
- PRIMARY KEY (`vatFk`,`equFk`),
- KEY `pgcEqu_fk2_idx` (`equFk`),
- CONSTRAINT `pgcEqu_fk1` FOREIGN KEY (`vatFk`) REFERENCES `pgc` (`code`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `pgcEqu_fk2` FOREIGN KEY (`equFk`) REFERENCES `pgc` (`code`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Recoge las cuentas contables con recargo de equivalencia e identifica a la que corresponde al iva y la que corresponde al recargo';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `plantpassport`
---
-
-DROP TABLE IF EXISTS `plantpassport`;
-/*!50001 DROP VIEW IF EXISTS `plantpassport`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `plantpassport` AS SELECT
- 1 AS `producerFk`,
- 1 AS `plantpassportAuthorityFk`,
- 1 AS `number`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `plantpassportAuthority`
---
-
-DROP TABLE IF EXISTS `plantpassportAuthority`;
-/*!50001 DROP VIEW IF EXISTS `plantpassportAuthority`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `plantpassportAuthority` AS SELECT
- 1 AS `id`,
- 1 AS `denomination`,
- 1 AS `countryFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `priceFixed`
---
-
-DROP TABLE IF EXISTS `priceFixed`;
-/*!50001 DROP VIEW IF EXISTS `priceFixed`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `priceFixed` AS SELECT
- 1 AS `itemFk`,
- 1 AS `rate0`,
- 1 AS `rate1`,
- 1 AS `rate2`,
- 1 AS `rate3`,
- 1 AS `started`,
- 1 AS `ended`,
- 1 AS `bonus`,
- 1 AS `warehouseFk`,
- 1 AS `created`,
- 1 AS `id`,
- 1 AS `grouping`,
- 1 AS `packing`,
- 1 AS `box`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `printServerQueue`
---
-
-DROP TABLE IF EXISTS `printServerQueue`;
-/*!50001 DROP VIEW IF EXISTS `printServerQueue`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `printServerQueue` AS SELECT
- 1 AS `id`,
- 1 AS `printerFk`,
- 1 AS `priorityFk`,
- 1 AS `reportFk`,
- 1 AS `statusFk`,
- 1 AS `started`,
- 1 AS `finished`,
- 1 AS `param1`,
- 1 AS `workerFk`,
- 1 AS `param2`,
- 1 AS `param3`,
- 1 AS `error`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `printingQueue`
---
-
-DROP TABLE IF EXISTS `printingQueue`;
-/*!50001 DROP VIEW IF EXISTS `printingQueue`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `printingQueue` AS SELECT
- 1 AS `id`,
- 1 AS `printer`,
- 1 AS `priority`,
- 1 AS `report`,
- 1 AS `state`,
- 1 AS `startingTime`,
- 1 AS `endingTime`,
- 1 AS `text`,
- 1 AS `worker`,
- 1 AS `text2`,
- 1 AS `text3`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `producer`
---
-
-DROP TABLE IF EXISTS `producer`;
-/*!50001 DROP VIEW IF EXISTS `producer`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `producer` AS SELECT
- 1 AS `id`,
- 1 AS `name`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `province`
---
-
-DROP TABLE IF EXISTS `province`;
-/*!50001 DROP VIEW IF EXISTS `province`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `province` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `countryFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `referenceRate`
---
-
-DROP TABLE IF EXISTS `referenceRate`;
-/*!50001 DROP VIEW IF EXISTS `referenceRate`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `referenceRate` AS SELECT
- 1 AS `currencyFk`,
- 1 AS `dated`,
- 1 AS `value`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `role`
---
-
-DROP TABLE IF EXISTS `role`;
-/*!50001 DROP VIEW IF EXISTS `role`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `role` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `description`,
- 1 AS `hasLogin`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `route`
---
-
-DROP TABLE IF EXISTS `route`;
-/*!50001 DROP VIEW IF EXISTS `route`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `route` AS SELECT
- 1 AS `id`,
- 1 AS `workerFk`,
- 1 AS `created`,
- 1 AS `vehicleFk`,
- 1 AS `agencyFk`,
- 1 AS `agencyModeFk`,
- 1 AS `time`,
- 1 AS `isOk`,
- 1 AS `kmStart`,
- 1 AS `kmEnd`,
- 1 AS `started`,
- 1 AS `finished`,
- 1 AS `gestdocFk`,
- 1 AS `cost`,
- 1 AS `m3`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `sale`
---
-
-DROP TABLE IF EXISTS `sale`;
-/*!50001 DROP VIEW IF EXISTS `sale`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `sale` AS SELECT
- 1 AS `id`,
- 1 AS `itemFk`,
- 1 AS `ticketFk`,
- 1 AS `concept`,
- 1 AS `quantity`,
- 1 AS `price`,
- 1 AS `discount`,
- 1 AS `reserved`,
- 1 AS `isPicked`,
- 1 AS `created`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `saleComponent`
---
-
-DROP TABLE IF EXISTS `saleComponent`;
-/*!50001 DROP VIEW IF EXISTS `saleComponent`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `saleComponent` AS SELECT
- 1 AS `saleFk`,
- 1 AS `componentFk`,
- 1 AS `value`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `solunionCAP`
---
-
-DROP TABLE IF EXISTS `solunionCAP`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `solunionCAP` (
- `creditInsurance` int(11) NOT NULL,
- `dateStart` date NOT NULL,
- `dateEnd` date NOT NULL,
- `dateLeaving` date DEFAULT NULL,
- PRIMARY KEY (`creditInsurance`,`dateStart`),
- KEY `solunionCAPdateLeavingIdx` (`dateLeaving`),
- CONSTRAINT `solunionCAP` FOREIGN KEY (`creditInsurance`) REFERENCES `creditInsurance` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `vn`.`solunionCAP_AFTER_INSERT` AFTER INSERT ON `solunionCAP` FOR EACH ROW
-BEGIN
- UPDATE vn2008.Clientes c
- JOIN creditClassification cc ON c.Id_Cliente = cc.client
- JOIN creditInsurance ci ON ci.creditClassification = cc.id
- SET creditInsurance = ci.credit * 2 WHERE ci.id = NEW.creditInsurance;
-END */;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `vn`.`solunionCAP_AFTER_UPDATE` AFTER UPDATE ON `solunionCAP` FOR EACH ROW
-BEGIN
- IF NEW.dateLeaving IS NOT NULL THEN
- UPDATE vn2008.Clientes c
- JOIN creditClassification cc ON c.Id_Cliente = cc.client
- JOIN creditInsurance ci ON ci.creditClassification = cc.id
- SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance;
- ELSE
- UPDATE vn2008.Clientes c
- JOIN creditClassification cc ON c.Id_Cliente = cc.client
- JOIN creditInsurance ci ON ci.creditClassification = cc.id
- SET creditInsurance = ci.credit * 2 WHERE ci.id = OLD.creditInsurance;
- 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 */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `vn`.`solunionCAP_BEFORE_DELETE` BEFORE DELETE ON `solunionCAP` FOR EACH ROW
-BEGIN
- UPDATE vn2008.Clientes c
- JOIN creditClassification cc ON c.Id_Cliente = cc.client
- JOIN creditInsurance ci ON ci.creditClassification = cc.id
- SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance;
-END */;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Temporary view structure for view `state`
---
-
-DROP TABLE IF EXISTS `state`;
-/*!50001 DROP VIEW IF EXISTS `state`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `state` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `order`,
- 1 AS `alertLevel`,
- 1 AS `code`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `stockBuyed`
---
-
-DROP TABLE IF EXISTS `stockBuyed`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `stockBuyed` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `user` int(10) unsigned DEFAULT NULL,
- `buyed` decimal(10,2) DEFAULT NULL,
- `date` date DEFAULT NULL,
- `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
- `reserved` decimal(10,2) DEFAULT NULL,
- `requested` decimal(10,2) DEFAULT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `date_UNIQUE` (`date`,`user`),
- KEY `stockBuyed_user_idx` (`user`),
- CONSTRAINT `stockBuyedUserFk` FOREIGN KEY (`user`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `supplier`
---
-
-DROP TABLE IF EXISTS `supplier`;
-/*!50001 DROP VIEW IF EXISTS `supplier`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `supplier` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `account`,
- 1 AS `countryFk`,
- 1 AS `nif`,
- 1 AS `isFarmer`,
- 1 AS `retAccount`,
- 1 AS `commission`,
- 1 AS `created`,
- 1 AS `postcodeFk`,
- 1 AS `isActive`*/;
-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`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `taxArea`
---
-
-DROP TABLE IF EXISTS `taxArea`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `taxArea` (
- `code` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`code`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `taxClass`
---
-
-DROP TABLE IF EXISTS `taxClass`;
-/*!50001 DROP VIEW IF EXISTS `taxClass`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `taxClass` AS SELECT
- 1 AS `id`,
- 1 AS `description`,
- 1 AS `code`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `taxClassCode`
---
-
-DROP TABLE IF EXISTS `taxClassCode`;
-/*!50001 DROP VIEW IF EXISTS `taxClassCode`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `taxClassCode` AS SELECT
- 1 AS `taxClassFk`,
- 1 AS `effectived`,
- 1 AS `taxCodeFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `taxCode`
---
-
-DROP TABLE IF EXISTS `taxCode`;
-/*!50001 DROP VIEW IF EXISTS `taxCode`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `taxCode` AS SELECT
- 1 AS `id`,
- 1 AS `dated`,
- 1 AS `code`,
- 1 AS `taxTypeFk`,
- 1 AS `rate`,
- 1 AS `equalizationTax`,
- 1 AS `type`,
- 1 AS `linkFk`,
- 1 AS `isActive`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `taxType`
---
-
-DROP TABLE IF EXISTS `taxType`;
-/*!50001 DROP VIEW IF EXISTS `taxType`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `taxType` AS SELECT
- 1 AS `id`,
- 1 AS `nickname`,
- 1 AS `serial`,
- 1 AS `TIPOOPE`,
- 1 AS `description`,
- 1 AS `countryFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `ticket`
---
-
-DROP TABLE IF EXISTS `ticket`;
-/*!50001 DROP VIEW IF EXISTS `ticket`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ticket` AS SELECT
- 1 AS `id`,
- 1 AS `clientFk`,
- 1 AS `warehouseFk`,
- 1 AS `shipped`,
- 1 AS `landed`,
- 1 AS `nickname`,
- 1 AS `refFk`,
- 1 AS `addressFk`,
- 1 AS `isSigned`,
- 1 AS `location`,
- 1 AS `blocked`,
- 1 AS `solution`,
- 1 AS `path`,
- 1 AS `routeFk`,
- 1 AS `company`,
- 1 AS `companyFk`,
- 1 AS `agencyModeFk`,
- 1 AS `loadingOrder`,
- 1 AS `created`,
- 1 AS `shipment`,
- 1 AS `landing`,
- 1 AS `customer`,
- 1 AS `warehouse`,
- 1 AS `client`,
- 1 AS `address`,
- 1 AS `agencyMode`,
- 1 AS `signed`,
- 1 AS `creationDate`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `ticketObservation`
---
-
-DROP TABLE IF EXISTS `ticketObservation`;
-/*!50001 DROP VIEW IF EXISTS `ticketObservation`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ticketObservation` AS SELECT
- 1 AS `id`,
- 1 AS `ticketFk`,
- 1 AS `observationTypeFk`,
- 1 AS `description`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `ticketPackage`
---
-
-DROP TABLE IF EXISTS `ticketPackage`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `ticketPackage` (
- `ticket` int(11) NOT NULL,
- `counter` int(10) unsigned NOT NULL DEFAULT '0',
- PRIMARY KEY (`ticket`),
- CONSTRAINT `ticketPackage_ticketFk` FOREIGN KEY (`ticket`) REFERENCES `vn2008`.`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 `ticketPackaging`
---
-
-DROP TABLE IF EXISTS `ticketPackaging`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `ticketPackaging` (
- `id` int(11) NOT NULL,
- `ticketFk` int(11) NOT NULL,
- `packagingFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
- `quantity` int(10) DEFAULT '0',
- `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `pvp` double DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `ticketPackaging_fk1_idx` (`ticketFk`),
- KEY `ticketPackaging_fk2_idx` (`packagingFk`),
- CONSTRAINT `ticketPackaging_fk1` FOREIGN KEY (`ticketFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON UPDATE CASCADE,
- CONSTRAINT `ticketPackaging_fk2` FOREIGN KEY (`packagingFk`) REFERENCES `vn2008`.`Cubos` (`Id_Cubo`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `ticketState`
---
-
-DROP TABLE IF EXISTS `ticketState`;
-/*!50001 DROP VIEW IF EXISTS `ticketState`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ticketState` AS SELECT
- 1 AS `ticketFk`,
- 1 AS `ticket`,
- 1 AS `state`,
- 1 AS `productionOrder`,
- 1 AS `alertLevel`,
- 1 AS `code`,
- 1 AS `worker`,
- 1 AS `workerFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `ticketStateToday`
---
-
-DROP TABLE IF EXISTS `ticketStateToday`;
-/*!50001 DROP VIEW IF EXISTS `ticketStateToday`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ticketStateToday` AS SELECT
- 1 AS `ticket`,
- 1 AS `state`,
- 1 AS `productionOrder`,
- 1 AS `alertLevel`,
- 1 AS `worker`,
- 1 AS `code`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `ticketTracking`
---
-
-DROP TABLE IF EXISTS `ticketTracking`;
-/*!50001 DROP VIEW IF EXISTS `ticketTracking`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ticketTracking` AS SELECT
- 1 AS `id`,
- 1 AS `stateFk`,
- 1 AS `created`,
- 1 AS `ticketFk`,
- 1 AS `workerFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `ticketTrolley`
---
-
-DROP TABLE IF EXISTS `ticketTrolley`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `ticketTrolley` (
- `ticket` int(11) NOT NULL,
- `labelCount` int(11) NOT NULL DEFAULT '0',
- PRIMARY KEY (`ticket`),
- CONSTRAINT `fk_ticketTrolley_vs_ticket` FOREIGN KEY (`ticket`) REFERENCES `vn2008`.`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 */;
-
---
--- Temporary view structure for view `time`
---
-
-DROP TABLE IF EXISTS `time`;
-/*!50001 DROP VIEW IF EXISTS `time`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `time` AS SELECT
- 1 AS `dated`,
- 1 AS `period`,
- 1 AS `month`,
- 1 AS `year`,
- 1 AS `day`,
- 1 AS `week`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `travel`
---
-
-DROP TABLE IF EXISTS `travel`;
-/*!50001 DROP VIEW IF EXISTS `travel`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `travel` AS SELECT
- 1 AS `id`,
- 1 AS `shipped`,
- 1 AS `shipmentHour`,
- 1 AS `landed`,
- 1 AS `landingHour`,
- 1 AS `warehouseInFk`,
- 1 AS `warehouseOutFk`,
- 1 AS `agencyFk`,
- 1 AS `ref`,
- 1 AS `isDelivered`,
- 1 AS `isReceived`,
- 1 AS `m3`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `travelObservation`
---
-
-DROP TABLE IF EXISTS `travelObservation`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `travelObservation` (
- `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
- `originFk` int(11) NOT NULL,
- `userFk` int(11) NOT NULL,
- `description` text COLLATE utf8_unicode_ci NOT NULL,
- `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de travel';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `unary`
---
-
-DROP TABLE IF EXISTS `unary`;
-/*!50001 DROP VIEW IF EXISTS `unary`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `unary` AS SELECT
- 1 AS `id`,
- 1 AS `parent`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `unaryScan`
---
-
-DROP TABLE IF EXISTS `unaryScan`;
-/*!50001 DROP VIEW IF EXISTS `unaryScan`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `unaryScan` AS SELECT
- 1 AS `unaryFk`,
- 1 AS `name`,
- 1 AS `created`,
- 1 AS `type`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `unaryScanLine`
---
-
-DROP TABLE IF EXISTS `unaryScanLine`;
-/*!50001 DROP VIEW IF EXISTS `unaryScanLine`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `unaryScanLine` AS SELECT
- 1 AS `id`,
- 1 AS `code`,
- 1 AS `created`,
- 1 AS `unaryScanFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `unaryScanLineBuy`
---
-
-DROP TABLE IF EXISTS `unaryScanLineBuy`;
-/*!50001 DROP VIEW IF EXISTS `unaryScanLineBuy`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `unaryScanLineBuy` AS SELECT
- 1 AS `unaryScanLineFk`,
- 1 AS `itemFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `unaryScanLineExpedition`
---
-
-DROP TABLE IF EXISTS `unaryScanLineExpedition`;
-/*!50001 DROP VIEW IF EXISTS `unaryScanLineExpedition`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `unaryScanLineExpedition` AS SELECT
- 1 AS `unaryScanLineFk`,
- 1 AS `expeditionFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `user`
---
-
-DROP TABLE IF EXISTS `user`;
-/*!50001 DROP VIEW IF EXISTS `user`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `user` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `password`,
- 1 AS `role`,
- 1 AS `active`,
- 1 AS `recoverPass`,
- 1 AS `lastPassChange`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `vehicle`
---
-
-DROP TABLE IF EXISTS `vehicle`;
-/*!50001 DROP VIEW IF EXISTS `vehicle`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `vehicle` AS SELECT
- 1 AS `id`,
- 1 AS `numberPlate`,
- 1 AS `tradeMark`,
- 1 AS `model`,
- 1 AS `companyFk`,
- 1 AS `warehouseFk`,
- 1 AS `description`,
- 1 AS `m3`,
- 1 AS `isActive`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `warehouse`
---
-
-DROP TABLE IF EXISTS `warehouse`;
-/*!50001 DROP VIEW IF EXISTS `warehouse`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `warehouse` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `isInventory`,
- 1 AS `hasComission`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `warehouseAlias`
---
-
-DROP TABLE IF EXISTS `warehouseAlias`;
-/*!50001 DROP VIEW IF EXISTS `warehouseAlias`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `warehouseAlias` AS SELECT
- 1 AS `id`,
- 1 AS `name`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `worker`
---
-
-DROP TABLE IF EXISTS `worker`;
-/*!50001 DROP VIEW IF EXISTS `worker`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `worker` AS SELECT
- 1 AS `id`,
- 1 AS `workerCode`,
- 1 AS `firstName`,
- 1 AS `name`,
- 1 AS `userFk`,
- 1 AS `bossFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `workerDocument`
---
-
-DROP TABLE IF EXISTS `workerDocument`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `workerDocument` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `worker` int(10) unsigned DEFAULT NULL,
- `document` int(11) DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `workerDocument_ibfk_1` (`worker`),
- KEY `workerDocument_ibfk_2` (`document`),
- CONSTRAINT `workerDocument_ibfk_1` FOREIGN KEY (`worker`) REFERENCES `vn2008`.`Trabajadores` (`user_id`) ON UPDATE CASCADE,
- CONSTRAINT `workerDocument_ibfk_2` FOREIGN KEY (`document`) REFERENCES `vn2008`.`gestdoc` (`id`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `workerTeam`
---
-
-DROP TABLE IF EXISTS `workerTeam`;
-/*!50001 DROP VIEW IF EXISTS `workerTeam`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `workerTeam` 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 `workerTeam_kk`
---
-
-DROP TABLE IF EXISTS `workerTeam_kk`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `workerTeam_kk` (
- `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 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `workingHours`
---
-
-DROP TABLE IF EXISTS `workingHours`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `workingHours` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `timeIn` datetime NOT NULL,
- `timeOut` datetime DEFAULT NULL,
- `userId` int(10) unsigned NOT NULL,
- PRIMARY KEY (`id`),
- KEY `user_working_hour_idx` (`userId`),
- CONSTRAINT `user_working_hour` FOREIGN KEY (`userId`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena horas de Entrada y de Salida del personal';
-/*!40101 SET character_set_client = @saved_cs_client */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `vn`.`workingHoursBeforeInsert` BEFORE INSERT ON `workingHours` FOR EACH ROW
-BEGIN
- IF (SELECT COUNT(*) FROM workingHours WHERE userId = NEW.userId AND DATE(timeIn) = CURDATE()) > 0 THEN
- CALL util.throw ('ALREADY_LOGGED');
- 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 */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Table structure for table `zone`
---
-
-DROP TABLE IF EXISTS `zone`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `zone` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
- `hour` int(11) NOT NULL,
- `warehouseFk` int(11) NOT NULL,
- `agencyFk` int(11) NOT NULL,
- `travelingDays` int(11) NOT NULL DEFAULT '1',
- PRIMARY KEY (`id`,`name`),
- UNIQUE KEY `name_UNIQUE` (`name`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `zoneCalendar`
---
-
-DROP TABLE IF EXISTS `zoneCalendar`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `zoneCalendar` (
- `zoneFk` int(11) NOT NULL,
- `delivered` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (`zoneFk`,`delivered`),
- CONSTRAINT `zoneFk` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`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 `zoneGeo`
---
-
-DROP TABLE IF EXISTS `zoneGeo`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `zoneGeo` (
- `zoneFk` varchar(45) CHARACTER SET utf8 NOT NULL,
- `geoFk` int(11) NOT NULL,
- `isIncluded` tinyint(1) DEFAULT NULL,
- PRIMARY KEY (`zoneFk`,`geoFk`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Dumping events for database 'vn'
---
-
---
--- Dumping routines for database 'vn'
---
-/*!50003 DROP FUNCTION IF EXISTS `agencyIsAvailable` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `agencyIsAvailable`(vAgency INT, vDate DATE, vAddress INT) RETURNS tinyint(1)
-BEGIN
-
- DECLARE vMaxDays INT DEFAULT DATEDIFF(vDate, CURDATE());
- DECLARE vWday TINYINT DEFAULT WEEKDAY(vDate);
- DECLARE vHour TINYINT DEFAULT HOUR(NOW());
- DECLARE vProvince INT;
- DECLARE isAvailable BOOL;
-
- SELECT province INTO vProvince
- FROM address
- WHERE id = vAddress;
-
- SELECT COUNT(*) > 0 INTO isAvailable
- FROM agencyHour h
- JOIN agencyMode a
- ON a.agency = h.agency
- WHERE (h.province = vProvince
- OR h.province IS NULL)
- AND (h.weekDay = vWday
- OR h.weekDay IS NULL)
- AND (h.substractDay < vMaxDays
- OR (h.substractDay = vMaxDays AND h.maxHour > vHour))
- AND a.id = vAgency;
-
- RETURN isAvailable;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `clientGetDebt` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `clientGetDebt`(vClient INT, vDate DATE) RETURNS decimal(10,2)
-BEGIN
-
- DECLARE vDateEnd DATETIME;
- DECLARE vDateIni DATETIME;
- DECLARE vDebt DECIMAL(10,2);
-
- SET vDate = IFNULL(vDate, CURDATE());
-
- SET vDateIni = TIMESTAMPADD(MONTH,-2,CURDATE());
- SET vDateEnd = TIMESTAMP(vDate, '23:59:59');
-
- DROP TEMPORARY TABLE IF EXISTS vn2008.ticket_tmp;
- CREATE TEMPORARY TABLE vn2008.ticket_tmp
- (INDEX (ticket_id))
- ENGINE = MEMORY
- SELECT id ticket_id
- FROM ticket
- WHERE clientfK = vClient
- AND refFk IS NULL
- AND shipped BETWEEN vDateIni AND vDateEnd;
-
- CALL vn2008.ticket_total ();
-
- SELECT IFNULL(SUM(t.amount), 0) INTO vDebt
- FROM (
- SELECT SUM(total) amount
- FROM vn2008.ticket_total
- UNION ALL
- SELECT SUM(Entregado)
- FROM vn2008.Recibos
- WHERE Id_Cliente = vClient
- AND Fechacobro > vDateEnd
- UNION ALL
- SELECT SUM(amount)
- FROM bi.customer_risk r
- WHERE customer_id = vClient
- UNION ALL
- SELECT CAST(-SUM(amount) / 100 AS DECIMAL(10,2))
- FROM hedera.tpv_transaction
- WHERE customer_id = vClient
- AND receipt_id IS NULL
- AND `status` = 'ok'
- ) t;
-
- DROP TEMPORARY TABLE
- vn2008.ticket_tmp,
- vn2008.ticket_total;
-
- RETURN vDebt;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `clientGetDebtKK` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `clientGetDebtKK`(vClient INT, vDate DATE) RETURNS decimal(10,2)
-BEGIN
-
- DECLARE vDateEnd DATETIME;
- DECLARE vDateIni DATETIME;
- DECLARE vDebt DECIMAL(10,2);
-
- SET vDate = IFNULL(vDate, CURDATE());
-
- SET vDateIni = TIMESTAMPADD(MONTH,-2,CURDATE());
- SET vDateEnd = TIMESTAMP(vDate, '23:59:59');
-
- DROP TEMPORARY TABLE IF EXISTS vn2008.ticket_tmp;
- CREATE TEMPORARY TABLE vn2008.ticket_tmp
- (INDEX (ticket_id))
- ENGINE = MEMORY
- SELECT id ticket_id
- FROM ticket
- WHERE `client` = vClient
- AND refFk IS NULL
- AND shipment BETWEEN vDateIni AND vDateEnd;
-
- CALL vn2008.ticket_total ();
-
- SELECT IFNULL(SUM(t.amount), 0) INTO vDebt
- FROM (
- SELECT SUM(total) amount
- FROM vn2008.ticket_total
- UNION ALL
- SELECT SUM(Entregado)
- FROM vn2008.Recibos
- WHERE Id_Cliente = vClient
- AND Fechacobro > vDateEnd
- UNION ALL
- SELECT SUM(amount)
- FROM bi.customer_risk r
- WHERE customer_id = vClient
- UNION ALL
- SELECT CAST(-SUM(amount) / 100 AS DECIMAL(10,2))
- FROM hedera.tpv_transaction
- WHERE customer_id = vClient
- AND receipt_id IS NULL
- AND `status` = 'ok'
- ) t;
-
- DROP TEMPORARY TABLE
- vn2008.ticket_tmp,
- vn2008.ticket_total;
-
- RETURN vDebt;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `clientGetMana` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `clientGetMana`(vClient INT) RETURNS decimal(10,2)
-BEGIN
-
-
-DECLARE vMana DECIMAL(10,2);
-DECLARE vFromDated DATE;
-
-SELECT max(dated) INTO vFromDated
-FROM vn.clientManaCache
-WHERE clientFk = vClient;
-
-SELECT sum(mana) INTO vMana
- FROM
- (
- SELECT mana
- FROM vn.clientManaCache
- WHERE clientFk = vClient
- AND dated = vFromDated
-
- UNION ALL
-
- SELECT s.quantity * Valor
- 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 > vFromDated
- AND t.clientFk = vClient
-
- UNION ALL
-
- SELECT - Entregado
- FROM vn2008.Recibos r
- JOIN vn2008.Clientes c using(Id_Cliente)
- WHERE r.Id_Banco = 66
- AND r.Fechacobro > vFromDated
- AND c.Id_Cliente = vClient
-
- UNION ALL
-
- SELECT g.Importe
- FROM vn2008.Greuges g
- JOIN vn2008.Clientes c using(Id_Cliente)
- WHERE g.Greuges_type_id = 3
- AND g.Fecha > vFromDated
- AND c.Id_Cliente = vClient
-
- ) sub;
-
-RETURN IFNULL(vMana,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 `clientTaxArea` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `clientTaxArea`(vClientFk INT, vCompanyFk INT) RETURNS varchar(25) CHARSET utf8
-BEGIN
-
- DECLARE vTaxArea VARCHAR(25);
- DECLARE vCee INT;
-
- SELECT ct.Cee INTO vCee
- FROM `client` c
- JOIN country ct ON ct.id = c.countryFk
- JOIN supplier s ON s.id = vCompanyFk
- WHERE
- c.id = vClientFk
- AND c.vies
- AND c.countryFk != s.countryFk;
-
- IF vCee < 2 THEN
- SET vTaxArea = 'CEE';
- ELSEIF vCee = 2 THEN
- SET vTaxArea = 'WORLD';
- ELSE
- SET vTaxArea = 'NATIONAL';
- END IF;
-
- RETURN vTaxArea;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `getAlert3State` */;
-ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `getAlert3State`(vTicket INT) RETURNS varchar(45) CHARSET latin1
-BEGIN
- DECLARE vDeliveryType INTEGER DEFAULT 0;
- DECLARE vWorker INT;
- DECLARE isWaitingForPickUp BOOLEAN DEFAULT FALSE;
- DECLARE vCode VARCHAR(45);
-
- SELECT IFNULL(aw.Vista,a.Vista) INTO vDeliveryType
- FROM vn2008.Tickets t
- JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia
- LEFT JOIN vn2008.agency_warehouse aw ON a.agency_id = aw.agency_id AND t.warehouse_id = aw.warehouse_id
- WHERE Id_Ticket = vTicket;
-
- SELECT getUser() INTO vWorker;
-
- CASE vDeliveryType
- WHEN 1 THEN
- SELECT COUNT(*) INTO isWaitingForPickUp
- FROM vn2008.Tickets t
- JOIN vn2008.warehouse_pickup w ON w.agency_id = t.Id_Agencia
- WHERE t.Id_Ticket = vTicket AND w.warehouse_id <> t.warehouse_id;
-
- IF isWaitingForPickUp THEN
- SET vCode = 'WAITING_FOR_PICKUP';
- ELSE
- SET vCode = 'DELIVERED';
- END IF;
-
- WHEN 2 THEN
- SET vCode = 'ON_DELIVERY';
-
- ELSE
- SET vCode = 'DELIVERED';
- END CASE;
- RETURN vCode;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `getDueDate` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `getDueDate`(vDated DATE, vDayToPay INT) RETURNS date
-BEGIN
-
-DECLARE vDued DATE;
-
-SET vDued = IF (vDayToPay > 30 or vDayToPay < 1
- ,TIMESTAMPADD(DAY, vDayToPay, vDated)
- ,TIMESTAMPADD(DAY, vDayToPay, LAST_DAY(vDated)));
-
-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 */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `getInventoryDate` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `getInventoryDate`() RETURNS date
- DETERMINISTIC
-BEGIN
- RETURN vn2008.date_inv();
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `getShipmentHour` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `getShipmentHour`(vTicket INT) RETURNS int(11)
-BEGIN
- DECLARE vShipmentHour INT;
-
- SELECT HOUR(shipment) INTO vShipmentHour
- FROM ticket
- WHERE id = vTicket;
-
- IF vShipmentHour = 0
- THEN
- DROP TEMPORARY TABLE IF EXISTS tmp.production_buffer;
- CREATE TEMPORARY TABLE tmp.production_buffer
- ENGINE = MEMORY
- SELECT am.agency as agency_id
- , t.warehouse as warehouse_id
- , a.province as province_id
- , 0 as Hora
- , 0 as Departure
- FROM ticket t
- JOIN agencyMode am on am.id = t.agencyMode
- JOIN address a on a.id = t.address
- WHERE t.id = vTicket;
-
- CALL vn2008.production_buffer_set_priority;
-
- SELECT Hora INTO vShipmentHour
- FROM tmp.production_buffer;
- END IF;
-
- RETURN vShipmentHour;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `getSpecialPrice` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `getSpecialPrice`(vItemFk int(11),vClientFk int(11)) RETURNS decimal(10,2)
-BEGIN
- DECLARE price DECIMAL(10,2);
-
- SELECT rate3 INTO price
- FROM vn.priceFixed
- WHERE itemFk = vItemFk
- AND CURDATE() BETWEEN started AND ended ORDER BY created DESC LIMIT 1;
-
- SELECT `value` INTO price
- FROM vn.especialPrice
- WHERE itemFk = vItemFk
- AND clientFk = vClientFk ;
-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 `getTicketToPrepare` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_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' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` FUNCTION `getTicketToPrepare`(`vWorker` INT, `vWarehouse` INT) RETURNS int(11)
-BEGIN
-
- DECLARE vToday DATETIME DEFAULT CURDATE();
- DECLARE vYesterday DATETIME;
- DECLARE vTodayvMidniight DATETIME DEFAULT midnight(vToday);
- DECLARE vTicket INT DEFAULT NULL;
-
- SET vYesterday = TIMESTAMPADD(DAY,-1,vToday);
-
- DROP TEMPORARY TABLE IF EXISTS tmp.workerComercial;
- CREATE TEMPORARY TABLE tmp.workerComercial
- ENGINE = MEMORY
- SELECT worker FROM `grant` g
- JOIN grantGroup gg ON g.group = gg.id
- WHERE gg.description = 'Comerciales'
- AND worker != 2;
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.production_buffer;
- CREATE TEMPORARY TABLE tmp.production_buffer
- ENGINE = MEMORY
- SELECT t.id as ticket
- , am.agency as agency_id
- , t.warehouse as warehouse_id
- , a.province as province_id
- , Hour(t.shipment) as Hora
- , Hour(t.shipment) as Departure
- , tls.code
- , IFNULL(t.loadingOrder,0) loadingOrder
- FROM ticket t
- JOIN ticketState tls on t.id = tls.ticket
- JOIN agencyMode am on am.id = t.agencyMode
- JOIN address a on a.id = t.address
- LEFT JOIN tmp.workerComercial wc ON wc.worker = vWorker
- WHERE t.shipment BETWEEN vYesterday AND vTodayvMidniight
- AND t.warehouse = vWarehouse
- AND
- (
- (tls.code = 'PRINTED' AND wc.worker IS NULL)
- OR
- (tls.code ='PICKER_DESIGNED' AND tls.worker = vWorker)
- OR
- (tls.code = 'PRINTED_BACK')
- );
-
-
- CALL vn2008.production_buffer_set_priority;
-
- SELECT ticket INTO vTicket
- FROM tmp.production_buffer
- ORDER BY (code = 'PICKER_DESIGNED') DESC , Hora, loadingOrder
- LIMIT 1;
-
- RETURN vTicket;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `getTicketTrolleyLabelCount` */;
-ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `getTicketTrolleyLabelCount`(vTicket INT) RETURNS int(11)
-BEGIN
-
-DECLARE vLabelCount INT DEFAULT 0;
-
-SELECT labelCount INTO vLabelCount
-FROM ticketTrolley
-WHERE ticket = vTicket;
-
-SET vLabelCount = vLabelCount +1 ;
-
-REPLACE ticketTrolley(ticket,labelCount)
-SELECT vTicket, vLabelCount;
-
-RETURN vlabelCount;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `getUser` */;
-ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `getUser`() RETURNS int(11)
- DETERMINISTIC
-BEGIN
- RETURN getWorker();
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `getUserId` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `getUserId`(userName varchar(30)) RETURNS int(11)
-BEGIN
- DECLARE vUser INT;
-
- SELECT id INTO vUser
- FROM account.user
- WHERE `name` = userName;
-
- RETURN vUser;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `getWorker` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `getWorker`() RETURNS int(11)
- DETERMINISTIC
-BEGIN
- DECLARE vUser INT;
-
- SELECT id INTO vUser
- FROM worker
- WHERE userFk = account.userGetId();
-
- RETURN vUser;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `getWorkerkk` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `getWorkerkk`() RETURNS int(11)
- DETERMINISTIC
-BEGIN
- DECLARE vUser INT;
-
- SELECT id INTO vUser
- FROM worker
- WHERE user = account.userGetId();
-
- RETURN vUser;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `hasAnyNegativeBase` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `hasAnyNegativeBase`() RETURNS tinyint(1)
-BEGIN
-
-
-
- DECLARE vCountry INT;
- DECLARE hasAnyNegativeBase BOOLEAN;
-
- SELECT s.countryFk
- INTO vCountry
- FROM supplier s
- JOIN ticket t ON t.companyFk = s.id
- JOIN vn.ticketToInvoice tl ON tl.id = t.id
- LIMIT 1;
-
- SELECT COUNT(*) INTO hasAnyNegativeBase
- FROM (
- SELECT SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2)) taxableBase
- FROM sale s
- JOIN item i ON i.id = s.itemFk
- JOIN itemTaxCountry itc
- ON itc.itemFk = i.id AND itc.countryFk = vCountry
- JOIN vn.ticketToInvoice tl ON tl.id = s.ticketFk
- GROUP BY itc.taxClassFk
- HAVING taxableBase < 0
- ) t1 ;
-
- RETURN hasAnyNegativeBase;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `hasSomeNegativeBase` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `hasSomeNegativeBase`(vTicket INT) RETURNS tinyint(1)
-BEGIN
-
- DECLARE vCountry INT;
- DECLARE hasSomeNegativeBase BOOLEAN;
-
- SELECT s.countryFk
- INTO vCountry
- FROM supplier s
- JOIN ticket t ON t.companyFk = s.id
- WHERE t.id = vTicket;
-
- SELECT COUNT(*) INTO hasSomeNegativeBase
- FROM (
- SELECT SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2)) taxableBase
- FROM sale s
- JOIN item i ON i.id = s.itemFk
- JOIN itemTaxCountry itc
- ON itc.itemFk = i.id AND itc.countryFk = vCountry
- WHERE s.ticketFk = vTicket
- GROUP BY itc.taxClassFk
- HAVING taxableBase < 0
- ) t1 ;
-
- RETURN hasSomeNegativeBase;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `invoiceOutAmount` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceOutAmount`(vInvoiceRef VARCHAR(15)) RETURNS decimal(10,2)
-BEGIN
- DECLARE totalAmount DECIMAL(10,2);
-
- SELECT SUM(vat) INTO totalAmount
- FROM
- (
- SELECT iot.vat
- FROM invoiceOutTax iot
- JOIN invoiceOut io ON io.id = iot.invoiceOutFk
- WHERE io.ref = vInvoiceRef
- UNION ALL
- SELECT ioe.amount
- FROM invoiceOutExpence ioe
- JOIN invoiceOut io ON io.id = ioe.invoiceOutFk
- WHERE io.ref = vInvoiceRef
- ) t1;
-
-RETURN totalAmount;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `invoiceSerial` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceSerial`(vClientFk INT, vCompanyFk INT, vType CHAR(1)) RETURNS char(1) CHARSET utf8
-BEGIN
-
- DECLARE vArea VARCHAR(25);
- DECLARE vSerie CHAR(1);
-
- SELECT clientTaxArea(vClientFk, vCompanyFk) INTO vArea;
-
-
- IF vType = 'R' THEN
- SELECT
- CASE vArea
- WHEN 'CEE'
- THEN 'H'
- WHEN 'WORLD'
- THEN 'E'
- WHEN 'NATIONAL'
- THEN 'T'
- END
- INTO vSerie;
-
- ELSEIF vType = 'M' THEN
- SELECT
- CASE vArea
- WHEN 'CEE'
- THEN 'H'
- WHEN 'WORLD'
- THEN 'E'
- WHEN 'NATIONAL'
- THEN 'M'
- END
- INTO vSerie;
-
- ELSEIF vType = 'G' THEN
- SELECT
- CASE vArea
- WHEN 'CEE'
- THEN 'V'
- WHEN 'WORLD'
- THEN 'X'
- WHEN 'NATIONAL'
- THEN 'A'
- END
- INTO vSerie;
- END IF;
-RETURN vSerie;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `isWorkerBoss` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `isWorkerBoss`(vUserId INT(11)) RETURNS tinyint(1)
- DETERMINISTIC
-BEGIN
-
- DECLARE subjectId INT(11) DEFAULT vUserId;
- DECLARE tmpSubjectId INT(11);
- DECLARE tmpBossId INT(11);
-
- LOOP
- SELECT
- bossWorker.user_id AS tmpBossId,
- subjectWorker.user_id AS tmpSubjectId
- INTO tmpBossId, tmpSubjectId
- FROM
- vn2008.Trabajadores AS subjectWorker
- JOIN
- vn2008.Trabajadores AS bossWorker ON bossWorker.Id_Trabajador = subjectWorker.boss
- WHERE
- subjectWorker.user_id = subjectId;
-
- IF tmpBossId = tmpSubjectId THEN
- RETURN FALSE;
- ELSEIF tmpBossId = account.userGetId() THEN
- RETURN TRUE;
- ELSE
- SET subjectId = tmpBossId;
- END IF;
- END LOOP;
-
-RETURN 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 */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `messageSend` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `messageSend`(vRecipient VARCHAR(255), vMessage TEXT) RETURNS int(11)
-BEGIN
-
- DECLARE vCount INT;
- DECLARE vUuid VARCHAR(255);
- DECLARE vSendDate DATETIME DEFAULT NOW();
- DECLARE vUser VARCHAR(255) DEFAULT account.userGetName();
-
- SET vRecipient = LOWER(vRecipient);
-
- DROP TEMPORARY TABLE IF EXISTS tRecipients;
- CREATE TEMPORARY TABLE tRecipients
- SELECT u.name finalRecipient
- FROM account.mailAlias a
- JOIN account.mailAliasAccount aa ON aa.mailAlias = a.id
- JOIN account.user u ON u.id = aa.account
- WHERE a.alias = vRecipient COLLATE utf8_unicode_ci
- AND u.name != vUser
- AND u.active
- UNION
- SELECT u.name FROM account.user u
- WHERE u.name = vRecipient
- AND u.active;
-
- SELECT COUNT(*) INTO vCount FROM tRecipients;
-
- IF vCount = 0 THEN
- RETURN vCount;
- END IF;
-
- SET vUuid = UUID();
-
- INSERT INTO message
- SET uuid = vUuid,
- sender = vUser,
- recipient = vRecipient,
- message = vMessage,
- sendDate = vSendDate;
-
- INSERT INTO messageInbox (uuid, sender, recipient, finalRecipient, message, sendDate)
- SELECT vUuid, vUser, vRecipient, finalRecipient, vMessage, vSendDate
- FROM tRecipients;
-
- DROP TEMPORARY TABLE tRecipients;
- RETURN vCount;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `midnight` */;
-ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `midnight`(vDate DATE) RETURNS datetime
- DETERMINISTIC
-BEGIN
- RETURN TIMESTAMP(vDate,'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 */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `noticeHasActive` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `noticeHasActive`(vCategoryKey VARCHAR(50), vUser INT) RETURNS tinyint(1)
-BEGIN
-
- DECLARE vActive INT;
-
- SELECT COUNT(*) INTO vActive
- FROM noticeSubscription s
- JOIN noticeCategory c ON c.id = s.noticeCategoryFk
- WHERE c.keyName = vCategoryKey AND userFk = vUser;
-
- RETURN vActive;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `phytoPassport` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `phytoPassport`(vRef VARCHAR(15)) RETURNS text CHARSET utf8
-BEGIN
-DECLARE vPhyto TEXT CHARSET utf8 COLLATE utf8_unicode_ci;
-SELECT
- GROUP_CONCAT(i.id,
- ':',
- ppa.denomination,
- ' ',
- pp.number,
- CHAR(13,10)
- SEPARATOR '') fitosanitario
- INTO vPhyto
-FROM
- sale s
- JOIN
- ticket t ON t.id = s.ticketFk
- JOIN
- item i ON i.id = s.itemFk
- JOIN
- plantpassport pp ON pp.producerFk = i.producerFk
- JOIN
- plantpassportAuthority ppa ON ppa.id = pp.plantpassportAuthorityFk
- JOIN
- itemBotanicalWithGenus ib ON ib.itemFk = i.id
- JOIN
- botanicExport be ON be.restriction = 'Se Requiere Certificado'
- LEFT JOIN
- ediGenus eg ON eg.id = be.ediGenusFk
- LEFT JOIN
- ediSpecie es ON es.id = be.ediSpecieFk
-WHERE
- t.refFk = vRef
- AND ib.ediBotanic LIKE CONCAT(IFNULL(eg.latinGenusName, ''),
- IF(latinSpeciesName > '',
- CONCAT(' ', latinSpeciesName),
- ''),
- '%');
-RETURN vPhyto;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `ticketPositionInPath` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketPositionInPath`(vTicketId INT) RETURNS varchar(10) CHARSET utf8
-BEGIN
-
- DECLARE vRestTicketsMaxOrder INT;
- DECLARE vRestTicketsMinOrder INT;
- DECLARE vRestTicketsPacking INT;
- DECLARE vMyProductionOrder INT;
- DECLARE vPosition VARCHAR(10) DEFAULT 'MID';
- DECLARE vMyPath INT;
- DECLARE vMyWarehouse INT;
- DECLARE PACKING_ORDER INT;
- DECLARE vExpeditionsCount INT;
- DECLARE vIsValenciaPath BOOLEAN DEFAULT FALSE;
-
-SELECT `order`
- INTO PACKING_ORDER
- FROM state
- WHERE code = 'PACKING';
-
-SELECT t.routeFk, t.warehouseFk, IFNULL(ts.productionOrder,0)
- INTO vMyPath, vMyWarehouse, vMyProductionOrder
- FROM ticket t
- LEFT JOIN ticketState ts on ts.ticket = t.id
- WHERE t.id = vTicketId;
-
-SELECT (ag.`name` = 'VN_VALENCIA')
- INTO vIsValenciaPath
- FROM vn2008.Rutas r
- JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia
- JOIN vn2008.agency ag on ag.agency_id = a.agency_id
- WHERE r.Id_Ruta = vMyPath;
-
-IF vIsValenciaPath THEN
-
- SELECT COUNT(*)
- INTO vExpeditionsCount
- FROM expedition e
- JOIN ticket t ON t.id = e.ticket
- WHERE t.routeFk = vMyPath;
-
- SELECT MAX(ts.productionOrder), MIN(ts.productionOrder)
- INTO vRestTicketsMaxOrder, vRestTicketsMinOrder
- FROM ticket t
- LEFT JOIN ticketState ts on t.id = ts.ticket
- WHERE t.routeFk = vMyPath
- AND t.warehouseFk = vMyWarehouse
- AND t.id != vTicketid;
-
- SELECT COUNT(*)
- INTO vRestTicketsPacking
- FROM ticket t
- LEFT JOIN ticketState ts on t.id = ts.ticket
- WHERE ts.productionOrder = PACKING_ORDER
- AND t.routeFk = vMyPath
- AND t.warehouseFk = vMyWarehouse
- AND t.id != vTicketid;
-
- IF vExpeditionsCount = 1 THEN
- SET vPosition = 'FIRST';
- ELSEIF vRestTicketsMinOrder > PACKING_ORDER THEN
- SET vPosition = 'LAST';
- ELSEIF vRestTicketsPacking THEN
- SET vPosition = 'SHARED';
- ELSE
- SET vPosition = 'MID';
- END IF;
-
-ELSE
- SET vPosition = 'MID';
-
-END IF;
-
-RETURN vPosition;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `ticketPositionInPathkk` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketPositionInPathkk`(vTicketId INT) RETURNS varchar(10) CHARSET utf8
-BEGIN
-
-
-DECLARE vRestTicketsMaxOrder INT;
-DECLARE vRestTicketsMinOrder INT;
-DECLARE vRestTicketsPacking INT;
-DECLARE vMyProductionOrder INT;
-DECLARE vPosition VARCHAR(10) DEFAULT 'MID';
-DECLARE vMyPath INT;
-DECLARE vMyWarehouse INT;
-DECLARE PACKING_ORDER INT;
-DECLARE vExpeditionsCount INT;
-DECLARE vIsValenciaPath BOOLEAN DEFAULT FALSE;
-
-SELECT `order`
- INTO PACKING_ORDER
- FROM state
- WHERE code = 'PACKING';
-
-SELECT path, warehouse, IFNULL(productionOrder,0)
- INTO vMyPath, vMyWarehouse, vMyProductionOrder
- FROM ticket t
- LEFT JOIN ticketState ts on ts.ticket = t.id
- WHERE id = vTicketId;
-
-SELECT (ag.`name` = 'VN_VALENCIA')
- INTO vIsValenciaPath
- FROM vn2008.Rutas r
- JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia
- JOIN vn2008.agency ag on ag.agency_id = a.agency_id
- WHERE r.Id_Ruta = vMyPath;
-
-
-IF vIsValenciaPath THEN
-
- SELECT COUNT(*)
- INTO vExpeditionsCount
- FROM expedition e
- JOIN ticket t ON t.id = e.ticket
- WHERE t.path = vMyPath;
-
- SELECT MAX(productionOrder), MIN(productionOrder)
- INTO vRestTicketsMaxOrder, vRestTicketsMinOrder
- FROM ticket t
- LEFT JOIN ticketState ts on t.id = ts.ticket
- WHERE t.path = vMyPath
- AND t.warehouse = vMyWarehouse
- AND t.id != vTicketid;
-
- SELECT COUNT(*)
- INTO vRestTicketsPacking
- FROM ticket t
- LEFT JOIN ticketState ts on t.id = ts.ticket
- WHERE productionOrder = PACKING_ORDER
- AND t.path = vMyPath
- AND t.warehouse = vMyWarehouse
- AND t.id != vTicketid;
-
-
-
- IF vExpeditionsCount = 1 THEN
-
- SET vPosition = 'FIRST';
-
- ELSEIF vRestTicketsMinOrder > PACKING_ORDER THEN
-
- SET vPosition = 'LAST';
-
- ELSEIF vRestTicketsPacking THEN
-
- SET vPosition = 'SHARED';
-
- ELSE
-
- SET vPosition = 'MID';
-
- END IF;
-
-ELSE
-
- SET vPosition = 'MID';
-
-END IF;
-
-RETURN vPosition;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `workerIsBoss` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `workerIsBoss`(vUserId INT) RETURNS int(11)
-BEGIN
-
- DECLARE vWorkerId INT;
- DECLARE vBossId INT;
-
- SELECT id INTO vWorkerId
- FROM vn.worker
- WHERE userFk = vUserId;
- IF vWorkerId IS NULL THEN
- CALL util.throw('USER_NOT_FOUND');
- END IF;
-
- DROP TEMPORARY TABLE IF EXISTS tCheckedWorker;
- CREATE TEMPORARY TABLE tCheckedWorker
- (PRIMARY KEY (workerFk))
- ENGINE = MEMORY
- SELECT id workerFk FROM worker LIMIT 0;
- LOOP
- SELECT bossFk INTO vBossId
- FROM vn.worker
- WHERE id = vWorkerId;
- IF (SELECT COUNT(*) FROM tCheckedWorker WHERE workerFk = vBossId) THEN
- CALL util.throw('INFINITE_LOOP');
- END IF;
- IF vBossId = vWorkerId THEN
- RETURN FALSE;
- ELSEIF vBossId = vn.getWorker() THEN
- RETURN TRUE;
- ELSE
- INSERT INTO tCheckedWorker VALUES (vWorkerId);
- SET vWorkerId = vBossId;
- END IF;
- END LOOP;
- DROP TEMPORARY TABLE tCheckedWorker;
- RETURN 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 `agencyListAvailable` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `agencyListAvailable`(vDate DATE, vAddress INT)
-BEGIN
-
- DECLARE vMaxDays INT DEFAULT DATEDIFF(vDate, CURDATE());
- DECLARE vWday TINYINT DEFAULT WEEKDAY(vDate);
- DECLARE vHour TINYINT DEFAULT HOUR(NOW());
- DECLARE vProvince INT;
-
- SELECT province INTO vProvince
- FROM address
- WHERE id = vAddress;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.agencyAvailable;
- CREATE TEMPORARY TABLE tmp.agencyAvailable
- (INDEX (agency))
- ENGINE = MEMORY
- SELECT agency, warehouse
- FROM agencyHour h
- WHERE (province = vProvince
- OR province IS NULL)
- AND (weekDay = vWday
- OR weekDay IS NULL)
- AND (substractDay < vMaxDays
- OR (substractDay = vMaxDays AND maxHour > vHour));
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `agencyListForMethod` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `agencyListForMethod`(
- vDate DATE, vAddress INT, vMethod VARCHAR(255))
-BEGIN
-
- CALL agencyListAvailable (vDate, vAddress);
-
- SELECT DISTINCT m.id, m.description
- FROM tmp.agencyAvailable a
- JOIN agencyMode m
- ON m.agency = a.agency
- JOIN deliveryMethod d
- ON d.id = m.deliveryMethod
- WHERE d.code = vMethod COLLATE 'utf8_unicode_ci';
-
- DROP TEMPORARY TABLE tmp.agencyAvailable;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!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`()
-BEGIN
-
- DECLARE vDateShort DATETIME;
-
- SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE());
-
- INSERT INTO vn.dailyTaskLog(state) VALUES('clean START');
-
- DELETE FROM vn.message WHERE sendDate < vDateShort;
-
- INSERT INTO vn.dailyTaskLog(state) 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 `clientFreeze` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `clientFreeze`()
-BEGIN
-
- IF day(CURDATE()) IN (10,20,30) THEN
-
- UPDATE vn.client c
- JOIN bi.defaulters d ON d.client = c.id AND d.date = CURDATE()
- JOIN vn.config ON TRUE
- SET c.isFreezed = TRUE
- WHERE d.amount > config.defaultersMaxAmount;
-
- 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 `copyComponentsFromSaleList` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `copyComponentsFromSaleList`(vTargetTicketFk INT)
-BEGIN
-
-
-
- INSERT INTO vn.sale(ticketFk, itemFk, quantity,concept,price,discount)
- SELECT vTargetTicketFk, itemFk, quantity,concept,price,discount
- FROM tmp.saleList
- ORDER BY orden;
-
- SET @order = 0;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.newSaleList;
-
- CREATE TEMPORARY TABLE tmp.newSaleList
- SELECT id as saleFk, @order := @order + 1 as orden
- FROM vn.sale
- WHERE ticketFk = vTargetTicketFk
- ORDER BY saleFk;
-
- INSERT INTO vn.saleComponent(saleFk,componentFk,value)
- SELECT ns.saleFk, sc.componentFk, sc.value
- FROM vn.saleComponent sc
- JOIN tmp.saleList s ON s.saleFk = sc.saleFk
- JOIN tmp.newSaleList ns ON ns.orden = s.orden;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `createExternalWorker` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `createExternalWorker`(
- vFirstName VARCHAR(50),
- vSurname1 VARCHAR(50),
- vSurname2 VARCHAR(50),
- vUser VARCHAR(20),
- vPassword VARCHAR(50),
- vWorkerCode VARCHAR(3)
- )
-BEGIN
-
- DECLARE vUserId INT;
- DECLARE vWorkerPako INT DEFAULT 2;
-
- INSERT INTO account.user(name,password,role)
- SELECT vUser,MD5(vPassword),1;
-
- SET vUserId = LAST_INSERT_ID();
-
-
- INSERT INTO vn2008.Trabajadores(Nombre,Apellidos,boss,CodigoTrabajador,user_id)
- SELECT vFirstName,CONCAT(vSurname1,' ',vSurname2),vWorkerPako,vWorkerCode,vUserId;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `entryConverter` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `entryConverter`(vEntry INT)
-BEGIN
-
- DECLARE vWarehouseIn INT;
- DECLARE vWarehouseOut INT;
- DECLARE vTravel INT;
-
- DECLARE done BOOL DEFAULT FALSE;
-
- DECLARE vId_Entrada INT;
- DECLARE vId_Article INT;
- DECLARE vEtiquetas INT;
- DECLARE vId_Cubo VARCHAR(10);
- DECLARE vPacking INT;
- DECLARE vGrouping INT;
- DECLARE vCantidad INT;
- DECLARE vCostefijo DECIMAL(10,3);
- DECLARE vPortefijo DECIMAL(10,3);
- DECLARE vEmbalajefijo DECIMAL(10);
- DECLARE vComisionfija DECIMAL(10,3);
- DECLARE vCaja INT;
- DECLARE vNicho VARCHAR(5);
- DECLARE vTarifa1 DECIMAL(10,2);
- DECLARE vTarifa2 DECIMAL(10,2);
- DECLARE vTarifa3 DECIMAL(10,2);
- DECLARE vPVP DECIMAL(10,2);
- DECLARE vCompra INT;
-
- DECLARE rs CURSOR FOR
- SELECT
- b.Id_Entrada,
- b.Id_Article,
- b.Etiquetas,
- b.Id_Cubo,
- b.Packing,
- b.grouping,
- b.Cantidad,
- b.Costefijo,
- b.Portefijo,
- b.Embalajefijo,
- b.Comisionfija,
- b.caja,
- b.Nicho,
- b.Tarifa1,
- b.Tarifa2,
- b.Tarifa3,
- b.PVP
- FROM vn2008.Compres b
- JOIN vn.itemConversor ic ON ic.espItemFk = b.Id_Article
- WHERE Id_Entrada = vEntry;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-
- SELECT warehouseInFk, warehouseOutFk, tr.id
- INTO vWarehouseIn, vWarehouseOut, vTravel
- FROM travel tr
- JOIN entry e ON e.travelFk = tr.id
- WHERE e.id = vEntry;
-
- UPDATE travel
- SET warehouseInFk = vWarehouseOut,
- warehouseOutFk = vWarehouseIn
- WHERE id = vTravel;
-
- UPDATE vn2008.Compres c
- LEFT JOIN vn.itemConversor ic ON ic.espItemFk = c.Id_Article
- SET Etiquetas = 0, Cantidad = 0
- WHERE c.Id_Entrada = vEntry
- AND ic.espItemFk IS NULL;
-
- OPEN rs;
-
- DELETE FROM vn2008.Compres WHERE Id_Entrada = vEntry;
-
- FETCH rs INTO
- vId_Entrada,
- vId_Article,
- vEtiquetas,
- vId_Cubo,
- vPacking,
- vGrouping,
- vCantidad,
- vCostefijo,
- vPortefijo,
- vEmbalajefijo,
- vComisionfija,
- vCaja,
- vNicho,
- vTarifa1,
- vTarifa2,
- vTarifa3,
- vPVP;
-
- WHILE NOT done DO
-
-
- INSERT INTO vn2008.Compres
- (
- Id_Entrada,
- Id_Article,
- Etiquetas,
- Id_Cubo,
- Packing,
- grouping,
- Cantidad,
- Costefijo,
- Portefijo,
- Embalajefijo,
- Comisionfija,
- caja,
- Nicho,
- Tarifa1,
- Tarifa2,
- Tarifa3,
- PVP
- )
- VALUES
- (
- vId_Entrada,
- vId_Article,
- - vEtiquetas,
- vId_Cubo,
- vPacking,
- vGrouping,
- - vCantidad,
- vCostefijo,
- vPortefijo,
- vEmbalajefijo,
- vComisionfija,
- vCaja,
- vNicho,
- vTarifa1,
- vTarifa2,
- vTarifa3,
- vPVP);
-
-
- INSERT INTO vn2008.Compres
- (
- Id_Entrada,
- Id_Article,
- Etiquetas,
- Id_Cubo,
- Packing,
- grouping,
- Cantidad,
- Costefijo,
- Portefijo,
- Embalajefijo,
- Comisionfija,
- caja,
- Nicho,
- Tarifa1,
- Tarifa2,
- Tarifa3,
- PVP
- )
- SELECT
- vId_Entrada,
- genItemFk as Id_Article,
- vEtiquetas,
- vId_Cubo,
- vPacking,
- vGrouping,
- vCantidad,
- vCostefijo,
- vPortefijo,
- vEmbalajefijo,
- vComisionfija,
- vCaja,
- vNicho,
- vTarifa1,
- vTarifa2,
- vTarifa3,
- vPVP
- FROM itemConversor
- WHERE espItemFk = vId_Article;
-
- SELECT LAST_INSERT_ID()
- INTO vCompra;
-
- REPLACE vn2008.Compres_mark(Id_Compra,`comment`)
- SELECT vCompra, vId_Article;
-
-
- FETCH rs INTO
- vId_Entrada,
- vId_Article,
- vEtiquetas,
- vId_Cubo,
- vPacking,
- vGrouping,
- vCantidad,
- vCostefijo,
- vPortefijo,
- vEmbalajefijo,
- vComisionfija,
- vCaja,
- vNicho,
- vTarifa1,
- vTarifa2,
- vTarifa3,
- vPVP;
-
- 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 `getDebt` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `getDebt`(vDate DATE)
-BEGIN
-
-
- DECLARE vDateIni DATETIME DEFAULT TIMESTAMPADD(DAY, - DAYOFMONTH(CURDATE()) - 5, CURDATE());
- DECLARE vDateEnd DATETIME;
+ -- DECLARE startingDate DATETIME DEFAULT TIMESTAMPADD(DAY, -40, CURDATE());
+ DECLARE startingDate DATETIME DEFAULT TIMESTAMPADD(DAY, - DAYOFMONTH(CURDATE()) - 5, CURDATE());
+ DECLARE endingDate DATETIME;
DECLARE MAX_RISK_ALLOWED INT DEFAULT 200;
- SET vDateEnd = TIMESTAMP(IFNULL(vDate, CURDATE()), '23:59:59');
-
- DROP TEMPORARY TABLE IF EXISTS tmp.clientList2;
- CREATE TEMPORARY TABLE tmp.clientList2
- (PRIMARY KEY (Id_Cliente))
- ENGINE = MEMORY
- SELECT *
- FROM tmp.client_list;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.clientList3;
- CREATE TEMPORARY TABLE tmp.clientList3
- (PRIMARY KEY (Id_Cliente))
- ENGINE = MEMORY
- SELECT *
- FROM tmp.client_list;
+ SET maxRiskDate = IFNULL(maxRiskDate, CURDATE());
+ SET endingDate = TIMESTAMP(maxRiskDate, '23:59:59');
- DROP TEMPORARY TABLE IF EXISTS vn2008.ticket_tmp;
- CREATE TEMPORARY TABLE vn2008.ticket_tmp
- (INDEX (ticket_id))
- ENGINE = MEMORY
- SELECT id ticket_id, cl.Id_Cliente
- FROM ticket t
- JOIN tmp.clientList2 cl ON t.clientFk = cl.Id_Cliente
- WHERE refFk IS NULL
- AND shipped BETWEEN vDateIni AND vDateEnd;
-
- CALL vn2008.ticket_total ();
-
- DROP TEMPORARY TABLE IF EXISTS tmp.risk;
- CREATE TEMPORARY TABLE tmp.risk
- (PRIMARY KEY (Id_Cliente))
- ENGINE = MEMORY
- SELECT Id_Cliente, SUM(amount) risk
- FROM vn2008.Clientes c
- JOIN (
- SELECT customer_id, SUM(amount) amount
- FROM bi.customer_risk cr
- JOIN tmp.client_list on tmp.client_list.Id_Cliente = cr.customer_id
- GROUP BY customer_id
- UNION ALL
- SELECT Id_Cliente, SUM(Entregado)
- FROM vn2008.Recibos
- JOIN tmp.clientList2 using(Id_Cliente)
- WHERE Fechacobro > vDateIni
- GROUP BY Id_Cliente
- UNION ALL
- SELECT t.Id_Cliente, total
- FROM vn2008.ticket_total tt
- JOIN vn2008.ticket_tmp t ON tt.ticket_id = t.ticket_id
- UNION ALL
- SELECT t.customer_id, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
- FROM hedera.tpv_transaction t
- JOIN tmp.clientList3 on Id_Cliente = customer_id
- WHERE t.receipt_id IS NULL
- AND t.status = 'ok'
- GROUP BY t.customer_id
- ) t ON c.Id_Cliente = t.customer_id
- WHERE c.activo != FALSE
- GROUP BY c.Id_Cliente;
-
- DROP TEMPORARY TABLE vn2008.ticket_tmp;
- DROP TEMPORARY TABLE tmp.clientList2;
- DROP TEMPORARY TABLE tmp.clientList3;
- DROP TEMPORARY TABLE vn2008.ticket_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 PROCEDURE IF EXISTS `getDebtkk` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `getDebtkk`(vDate DATE)
-BEGIN
-
-
- DECLARE vDateIni DATETIME DEFAULT TIMESTAMPADD(DAY, - DAYOFMONTH(CURDATE()) - 5, CURDATE());
- DECLARE vDateEnd DATETIME;
- DECLARE MAX_RISK_ALLOWED INT DEFAULT 200;
-
- SET vDateEnd = TIMESTAMP(IFNULL(vDate, CURDATE()), '23:59:59');
-
- DROP TEMPORARY TABLE IF EXISTS tmp.clientList2;
- CREATE TEMPORARY TABLE tmp.clientList2
+ DROP TEMPORARY TABLE IF EXISTS tmp.client_list_2;
+ CREATE TEMPORARY TABLE tmp.client_list_2
(PRIMARY KEY (Id_Cliente))
ENGINE = MEMORY
SELECT *
FROM tmp.client_list;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.clientList3;
- CREATE TEMPORARY TABLE tmp.clientList3
+ select 1;
+ DROP TEMPORARY TABLE IF EXISTS tmp.client_list_3;
+ CREATE TEMPORARY TABLE tmp.client_list_3
(PRIMARY KEY (Id_Cliente))
ENGINE = MEMORY
SELECT *
FROM tmp.client_list;
- DROP TEMPORARY TABLE IF EXISTS vn2008.ticket_tmp;
- CREATE TEMPORARY TABLE vn2008.ticket_tmp
- (INDEX (ticket_id))
+ select 2;
+ DROP TEMPORARY TABLE IF EXISTS tmp.tickets_sin_facturar;
+ CREATE TEMPORARY TABLE tmp.tickets_sin_facturar
+ (PRIMARY KEY (Id_Cliente))
ENGINE = MEMORY
- SELECT id ticket_id, cl.Id_Cliente
- FROM ticket t
- JOIN tmp.clientList2 cl ON t.client = cl.Id_Cliente
- WHERE refFk IS NULL
- AND shipment BETWEEN vDateIni AND vDateEnd;
-
- CALL vn2008.ticket_total ();
-
+ SELECT t.Id_Cliente, Cantidad as total
+ FROM Movimientos m
+ JOIN Tickets t on m.Id_Ticket = t.Id_Ticket
+ JOIN tmp.client_list c on c.Id_Cliente = t.Id_Cliente
+ WHERE Factura IS NULL
+ AND Fecha BETWEEN startingDate AND endingDate
+ GROUP BY t.Id_Cliente;
+select 3;
DROP TEMPORARY TABLE IF EXISTS tmp.risk;
CREATE TEMPORARY TABLE tmp.risk
(PRIMARY KEY (Id_Cliente))
ENGINE = MEMORY
- SELECT Id_Cliente, SUM(amount) risk
- FROM vn2008.Clientes c
+ SELECT Id_Cliente, SUM(amount) risk, sum(saldo) saldo
+ FROM Clientes c
JOIN (
- SELECT customer_id, SUM(amount) amount
- FROM bi.customer_risk cr
- JOIN tmp.client_list on tmp.client_list.Id_Cliente = cr.customer_id
+ SELECT customer_id, SUM(amount) amount,SUM(amount) saldo
+ FROM bi.customer_risk
+ JOIN tmp.client_list on Id_Cliente = customer_id
GROUP BY customer_id
UNION ALL
- SELECT Id_Cliente, SUM(Entregado)
- FROM vn2008.Recibos
- JOIN tmp.clientList2 using(Id_Cliente)
- WHERE Fechacobro > vDateIni
+ SELECT Id_Cliente, SUM(Entregado),SUM(Entregado)
+ FROM Recibos
+ JOIN tmp.client_list_2 using(Id_Cliente)
+ WHERE Fechacobro > endingDate
GROUP BY Id_Cliente
UNION ALL
- SELECT t.Id_Cliente, total
- FROM vn2008.ticket_total tt
- JOIN vn2008.ticket_tmp t ON tt.ticket_id = t.ticket_id
+ SELECT Id_Cliente, total,0
+ FROM tmp.tickets_sin_facturar
UNION ALL
- SELECT t.customer_id, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
- FROM hedera.tpv_transaction t
- JOIN tmp.clientList3 on Id_Cliente = customer_id
- WHERE t.receipt_id IS NULL
+ SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2)), CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
+ FROM hedera.tpvTransaction t
+ JOIN tmp.client_list_3 on Id_Cliente = clientFk
+ WHERE t.receiptFk IS NULL
AND t.status = 'ok'
- GROUP BY t.customer_id
+ GROUP BY t.clientFk
) t ON c.Id_Cliente = t.customer_id
- WHERE c.activo != FALSE
+ WHERE c.activo != FALSE
GROUP BY c.Id_Cliente;
-
- DROP TEMPORARY TABLE vn2008.ticket_tmp;
- DROP TEMPORARY TABLE tmp.clientList2;
- DROP TEMPORARY TABLE tmp.clientList3;
- DROP TEMPORARY TABLE vn2008.ticket_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 PROCEDURE IF EXISTS `getItemVisibleAvailable` */;
-ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `getItemVisibleAvailable`(IN vItem INT,IN vDate DATE,IN vWarehouse TINYINT,IN isForcedToRecalculate BOOLEAN)
-BEGIN
-
- DECLARE vCacheVisibleCalculated INTEGER;
- DECLARE vCacheAvailableCalculated INTEGER;
-
- CALL cache.visible_refresh(vCacheVisibleCalculated, isForcedToRecalculate, vWarehouse);
- CALL cache.available_refresh(vCacheAvailableCalculated, isForcedToRecalculate, vWarehouse, vDate);
-
- SELECT a.Id_Article, a.Article, a.Medida, a.Tallos, a.caja, O.Abreviatura as origen, a.Color, tipo_id, an.Nicho,
- a.Categoria, p.`name` as producer, v.visible, av.available
- FROM vn2008.Articles a
- LEFT JOIN vn2008.Articles_nicho an ON a.Id_Article = an.Id_Article AND an.warehouse_id = vWarehouse
- LEFT JOIN vn2008.Origen O ON O.id = a.id_origen
- LEFT JOIN vn2008.producer p ON p.producer_id = a.producer_id
- LEFT JOIN cache.visible v ON (vItem IS NULL OR v.item_id = vItem) AND v.calc_id = vCacheVisibleCalculated
- LEFT JOIN cache.available av ON (vItem IS NULL OR av.item_id = vItem) AND av.calc_id = vCacheAvailableCalculated
- WHERE (vItem IS NULL OR a.Id_Article = 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 */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `invoiceCorrectedSale` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceCorrectedSale`(vInvoiceOut INT)
-BEGIN
-
-
-
-
-SELECT
- s.id,
- s.itemFk,
- s.quantity,
- s.price,
- s.discount
- FROM sale s
- JOIN ticket t ON t.id = s.ticketFk
- WHERE t.invoice = vInvoiceOut;
-
-
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `invoiceExpenceMake` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceExpenceMake`(IN vInvoice INT)
-BEGIN
-
- DELETE FROM invoiceOutExpence
- WHERE invoiceOutFk = vInvoice;
-
- INSERT INTO invoiceOutExpence(
- invoiceOutFk,
- expenceFk,
- amount
- )
- SELECT
- vInvoice,
- expenceFk,
- SUM(ROUND(quantity * price * (100 - discount)/100,2)) amount
- FROM ticketToInvoice t
- JOIN sale s ON s.ticketFk = t.id
- JOIN item i ON i.id = s.itemFk
- GROUP BY i.expenceFk
- HAVING amount != 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 `invoiceFromAddress` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceFromAddress`(vMaxTicketDate DATETIME,vAddress INT,vCompany INT)
-BEGIN
-
- DECLARE vMinDateTicket DATE DEFAULT TIMESTAMPADD(MONTH, -3, CURDATE());
-
- SET vMaxTicketDate = vn2008.DAYEND(vMaxTicketDate);
-
- DROP TEMPORARY TABLE IF EXISTS `ticketToInvoice`;
-
- CREATE TEMPORARY TABLE `ticketToInvoice`
- (PRIMARY KEY (`id`))
- ENGINE = MEMORY
- SELECT Id_Ticket id FROM vn2008.Tickets WHERE (Fecha BETWEEN vMinDateTicket
- AND vMaxTicketDate) AND Id_Consigna = vAddress
- AND Factura IS NULL AND empresa_id = vCompany;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `invoiceFromClient` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceFromClient`(vMaxTicketDate DATETIME, vClient INT, vCompany INT)
-BEGIN
-
- DECLARE vMinDateTicket DATE DEFAULT TIMESTAMPADD(YEAR, -3, CURDATE());
-
- SET vMaxTicketDate = vn2008.DAYEND(vMaxTicketDate);
-
- DROP TEMPORARY TABLE IF EXISTS `ticketToInvoice`;
-
- CREATE TEMPORARY TABLE `ticketToInvoice`
- (PRIMARY KEY (`id`))
- ENGINE = MEMORY
- SELECT Id_Ticket id FROM vn2008.Tickets
- WHERE Id_Cliente = vClient
- AND Factura IS NULL
- AND empresa_id = vCompany
- AND (Fecha BETWEEN vMinDateTicket AND vMaxTicketDate)
- ;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `invoiceFromTicket` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceFromTicket`(IN vTicket INT)
-BEGIN
-
- DROP TEMPORARY TABLE IF EXISTS `ticketToInvoice`;
-
- CREATE TEMPORARY TABLE `ticketToInvoice`
- (PRIMARY KEY (`id`))
- ENGINE = MEMORY
- SELECT id FROM vn.ticket
- WHERE id = vTicket AND refFk 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 `invoiceInBooking` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceInBooking`(vInvoiceInId INT)
-BEGIN
- DECLARE vSerialNumber, vBookNumber, vBookNumberPlus1 INT;
- DECLARE vTotalAmount DECIMAL(10,2);
-
- DROP TEMPORARY TABLE IF EXISTS newInvoiceIn;
-
- CREATE TEMPORARY TABLE newInvoiceIn
- SELECT
- i.*,
- YEAR(i.booked) datedYear,
-
- CONCAT('s/fra',RIGHT(i.supplierRef,8),':',LEFT(s.name, 10)) conceptWithSupplier,
- (cc.id = c.id) isSameCountry,
- cit.id invoicesCount
- FROM invoiceIn i
- JOIN cplusInvoiceType472 cit ON cit.id = i.cplusInvoiceType472Fk
- JOIN supplier s ON s.id = i.supplierFk
- JOIN country c ON c.id = s.countryFk
- JOIN supplier sc ON sc.id = i.companyFk
- JOIN country cc ON cc.id = sc.countryFk
- WHERE i.id = vInvoiceInId;
-
- DROP TEMPORARY TABLE IF EXISTS newSupplier;
- CREATE TEMPORARY TABLE newSupplier
- SELECT
- s.*,
- REPLACE(s.account,' ','') supplierAccount,
- IF(c.CEE < 2, TRUE, FALSE) isUeeMember
- FROM supplier s
- JOIN newInvoiceIn n
- JOIN country c ON c.id = s.countryFk
- WHERE s.id = n.supplierFk;
-
- IF (SELECT isActive FROM newSupplier) = 0 THEN
- CALL util.throw('INACTIVE_PROVIDER');
- END IF;
-
- SELECT IFNULL(MAX(i.serialNumber) + 1,1)
- INTO vSerialNumber
- FROM invoiceIn i
- JOIN newInvoiceIn n
- WHERE i.serial LIKE n.serial
- AND YEAR(i.booked) = n.datedYear
- AND i.companyFk = n.companyFk
- GROUP BY i.companyFk;
-
- SELECT MAX(ASIEN) + 1
- INTO vBookNumber
- FROM vn2008.XDiario;
-
- SET vBookNumberPlus1 = vBookNumber + 1;
-
- SELECT SUM(iit.taxableBase * IF(i.serial = 'R', 1 +(tc.rate/100),1))
- INTO vTotalAmount
- FROM invoiceIn i
- JOIN invoiceInTax iit ON iit.invoiceInFk = i.id
- JOIN taxCode tc ON iit.taxCodeFk = tc.id
- WHERE i.id = vInvoiceInId;
-
-
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- EUROHABER,
- CONCEPTO,
- NFACTICK,
- empresa_id)
- SELECT
- vBookNumber,
- n.booked,
- s.supplierAccount,
- vTotalAmount,
- n.conceptWithSupplier,
- n.invoicesCount,
- n.companyFk
- FROM newInvoiceIn n
- JOIN newSupplier s;
-
-
- INSERT INTO vn2008.XDiario (
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EURODEBE,
- EUROHABER,
- CONCEPTO,
- NFACTICK,
- empresa_id
- )
- SELECT
- vBookNumber ASIEN,
- n.booked FECHA,
- if(
- e.isWithheld,
- LPAD(RIGHT(s.supplierAccount ,5),10,iit.expenceFk),
- iit.expenceFk
- ) SUBCTA,
- s.supplierAccount CONTRA,
- if(
- e.isWithheld,
- NULL,
- ABS(ROUND(SUM(iit.taxableBase),2))
- ) EURODEBE,
- if(
- e.isWithheld,
- ABS(ROUND(SUM(iit.taxableBase),2)),
- NULL
- ) EUROHABER,
- n.conceptWithSupplier CONCEPTO,
- n.invoicesCount NFACTICK,
- n.companyFk empresa_id
- FROM newInvoiceIn n
- JOIN newSupplier s
- JOIN invoiceInTax iit ON iit.invoiceInFk = n.id
- JOIN taxCode tc ON tc.id = iit.taxCodeFk
- JOIN expence e ON e.id = iit.expenceFk AND e.taxTypeFk = tc.taxTypeFk
- WHERE iit.expenceFk != 5660000002
- GROUP BY iit.expenceFk;
-
-
- INSERT INTO vn2008.XDiario (
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EURODEBE,
- CONCEPTO,
- NFACTICK,
- empresa_id
- )
- SELECT
- vBookNumberPlus1 ASIEN,
- IFNULL(a.booked, n.booked) FECHA,
- iit.expenceFk SUBCTA,
- s.account CONTRA,
- ROUND(SUM(iit.taxableBase) * (iie.percentage / 100),2) EURODEBE,
- CONCAT('COMPRA s/fra ',i.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
- n.invoicesCount NFACTICK,
- n.companyFk empresa_id
- FROM newInvoiceIn n
- JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = n.id
- JOIN invoiceInTax iit ON iit.invoiceInFk = iie.invoiceInFk
- JOIN invoiceIn i ON i.id = iit.invoiceInFk
- JOIN supplier s ON s.id = i.supplierFk
- LEFT JOIN invoiceInAwb iia ON iia.invoiceInFk = n.id
- LEFT JOIN awb a ON a.id = iia.awbFk
- WHERE iie.percentage
- GROUP BY i.id;
-
-
- INSERT INTO vn2008.XDiario (
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EUROHABER,
- CONCEPTO,
- NFACTICK,
- empresa_id
- )
- SELECT
- vBookNumberPlus1 ASIEN,
- IFNULL(a.booked, n.booked) FECHA,
- s.account SUBCTA,
- iit.expenceFk CONTRA,
- ROUND(SUM(iit.taxableBase) * (iie.percentage / 100),2) EUROHABER,
- CONCAT('COMPRA s/fra ',i.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
- n.invoicesCount NFACTICK,
- n.companyFk empresa_id
- FROM newInvoiceIn n
- JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = n.id
- JOIN invoiceInTax iit ON iit.invoiceInFk = iie.invoiceInFk
- JOIN invoiceIn i ON i.id = iit.invoiceInFk
- JOIN supplier s ON s.id = i.supplierFk
- LEFT JOIN invoiceInAwb iia ON iia.invoiceInFk = n.id
- LEFT JOIN awb a ON a.id = iia.awbFk
- WHERE iie.percentage
- GROUP BY i.id;
-
-
-
-
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EURODEBE,
- BASEEURO,
- CONCEPTO,
- FACTURA,
- IVA,
- AUXILIAR,
- SERIE,
- TIPOOPE,
- FECHA_EX,
- FECHA_OP,
- NFACTICK,
- FACTURAEX,
- L340,
- LRECT349,
- TIPOCLAVE,
- TIPOEXENCI,
- TIPONOSUJE,
- TIPOFACT,
- TIPORECTIF,
- TERIDNIF,
- TERNIF,
- TERNOM,
- FECREGCON,
- empresa_id
- )
- SELECT vBookNumber ASIEN,
- n.booked FECHA,
- tc.code SUBCTA,
- s.supplierAccount CONTRA,
- SUM(ROUND(tc.rate/100*it.taxableBase + 0.0001,2)) EURODEBE,
- SUM(it.taxableBase) BASEEURO,
- GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO,
- vSerialNumber FACTURA,
- tc.rate IVA,
- IF(isUeeMember AND eWithheld.id IS NULL,'','*') AUXILIAR,
- n.serial SERIE,
- tt.TIPOOPE,
- n.issued FECHA_EX,
- n.operated FECHA_OP,
- n.invoicesCount NFACTICK,
- n.supplierRef FACTURAEX,
- TRUE L340,
- (isSameCountry OR NOT isUeeMember) LRECT349,
- n.cplusTrascendency472Fk TIPOCLAVE,
- n.cplusTaxBreakFk TIPOEXENCI,
- n.cplusSubjectOpFk TIPONOSUJE,
- n.cplusInvoiceType472Fk TIPOFACT,
- n.cplusRectificationTypeFk TIPORECTIF,
- iis.cplusTerIdNifFk TERIDNIF,
- s.nif AS TERNIF,
- s.name AS TERNOM,
- n.booked FECREGCON,
- n.companyFk
-
- FROM newInvoiceIn n
- JOIN newSupplier s
- JOIN invoiceInTax it ON n.id = it.invoiceInFk
- JOIN taxCode tc ON tc.id = it.taxCodeFk
- JOIN taxType tt ON tt.id = tc.taxTypeFk
- JOIN invoiceInSerial iis ON iis.code = tt.serial
- JOIN expence e ON e.id = it.expenceFk AND e.taxTypeFk = tc.taxTypeFk
- LEFT JOIN
- (SELECT eWithheld.id
- FROM invoiceInTax hold
- JOIN expence eWithheld ON eWithheld.id = hold.expenceFk AND eWithheld.isWithheld
- WHERE hold.invoiceInFk = 58262 LIMIT 1
- ) eWithheld ON TRUE
- WHERE tc.type != '-'
- AND tc.isActive
- GROUP BY tc.rate;
-
-
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EUROHABER,
- BASEEURO,
- CONCEPTO,
- FACTURA,
- IVA,
- AUXILIAR,
- SERIE,
- TIPOOPE,
- FECHA_EX,
- FECHA_OP,
- NFACTICK,
- FACTURAEX,
- L340,
- LRECT349,
- TIPOCLAVE,
- TIPOEXENCI,
- TIPONOSUJE,
- TIPOFACT,
- TIPORECTIF,
- TERIDNIF,
- TERNIF,
- TERNOM,
- empresa_id
- )
-
- SELECT
- vBookNumber ASIEN,
- n.booked FECHA,
- tcLink.code SUBCTA,
- s.supplierAccount CONTRA,
- ROUND(tcLink.rate/100*SUM(it.taxableBase) + 0.0001,2) EUROHABER,
- ROUND(SUM(it.taxableBase),2) BASEEURO,
- GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO,
- vSerialNumber FACTURA,
- tcLink.rate IVA,
- '*' AUXILIAR,
- n.serial SERIE,
- tt.TIPOOPE,
- n.issued FECHA_EX,
- n.operated FECHA_OP,
- n.invoicesCount NFACTICK,
- n.supplierRef FACTURAEX,
- FALSE L340,
- (isSameCountry OR NOT isUeeMember) LRECT349,
- 1 TIPOCLAVE,
- n.cplusTaxBreakFk TIPOEXENCI,
- n.cplusSubjectOpFk TIPONOSUJE,
- n.cplusInvoiceType472Fk TIPOFACT,
- n.cplusRectificationTypeFk TIPORECTIF,
- iis.cplusTerIdNifFk TERIDNIF,
- s.nif AS TERNIF,
- s.name AS TERNOM,
- n.companyFk
-
- FROM newInvoiceIn n
- JOIN newSupplier s
- JOIN invoiceInTax it ON n.id = it.invoiceInFk
- JOIN taxCode tc ON tc.id = it.taxCodeFk
- JOIN taxType tt ON tt.id = tc.taxTypeFk
- JOIN invoiceInSerial iis ON iis.code = tt.serial
- JOIN taxCode tcLink ON tcLink.linkFk = tc.linkFk AND tc.id != tcLink.id
- JOIN expence e ON e.id = it.expenceFk AND e.taxTypeFk = tc.taxTypeFk
- WHERE tc.isActive
- GROUP BY tcLink.rate, e.id;
-
-
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- CONCEPTO,
- EUROHABER,
- SERIE,
- empresa_id)
-
- SELECT
- vBookNumberPlus1,
- a.booked,
- '4700000999',
- n.conceptWithSupplier,
- ROUND(SUM(iii.amount * (tc.rate/100)),2) eurohaber,
- n.serial,
- n.companyFk
- FROM newInvoiceIn n
- JOIN invoiceInIntrastat iii ON n.id = iii.invoiceInFk
- JOIN intrastat ii ON ii.id = iii.intrastatFk
- JOIN taxCode tc ON tc.id = ii.taxCodeFk
- JOIN invoiceInAwb iia ON iia.invoiceInFk = iii.invoiceInFk
- JOIN awb a ON a.id = iia.awbFk
- HAVING eurohaber IS NOT NULL;
-
-
-
-
- SET @cont:=1;
- SET @total:=0;
- SET @base:=2;
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EURODEBE,
- BASEEURO,
- CONCEPTO,
- FACTURA,
- IVA,
- AUXILIAR,
- SERIE,
- FECHA_EX,
- FECHA_OP,
- FACTURAEX,
- NFACTICK,
- L340,
- LDIFADUAN,
- TIPOCLAVE,
- TIPOEXENCI,
- TIPONOSUJE,
- TIPOFACT,
- TIPORECTIF,
- TERIDNIF,
- TERNIF,
- TERNOM,
- empresa_id,
- FECREGCON
- )
-
- SELECT
- vBookNumberPlus1 ASIEN,
- x.FECHA,
- x.SUBCTA,
- x.CONTRA,
- IF (n.isSameCountry OR NOT s.isUeeMember,
- x.EURODEBE,
- NULL
- ) EURODEBE,
- x.BASEEURO,
- x.CONCEPTO,
- vSerialNumber FACTURA,
- x.IVA,
- '*' AUXILIAR,
- x.SERIE,
- x.FECHA_EX,
- x.FECHA_OP,
- x.dua FACTURAEX,
- n.invoicesCount NFACTICK,
- IF(@total:=@total + x.EURODEBE AND @cont:=@cont + 1 ,1,1) L340,
- TRUE LDIFADUAN,
- x.TIPOCLAVE,
- n.cplusTaxBreakFk TIPOEXENCI,
- n.cplusSubjectOpFk TIPONOSUJE,
- 5 TIPOFACT,
- n.cplusRectificationTypeFk TIPORECTIF,
- x.TERIDNIF,
- x.TERNIF,
- x.TERNOM,
- n.companyFk,
- IFNULL(x.FECREGCON,n.booked) FECREGCON
-
- FROM newInvoiceIn n
- JOIN newSupplier s
- JOIN (
- SELECT
-
- CONCAT('COMPRA s/fra ',ii.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
- tc.code SUBCTA,
- s.account CONTRA,
- tc.rate IVA,
- ROUND(sum(b.buyingValue * b.quantity / intraSub.intrastatSum * taxSub.amount)*(tc.rate/100),2) EURODEBE,
- ROUND(sum(b.buyingValue * b.quantity / intraSub.intrastatSum * taxSub.amount),2) BASEEURO,
- ii.serial SERIE,
- e.supplierFk,
- iia.dua,
- iis.cplusTerIdNifFk TERIDNIF,
- s.nif AS TERNIF,
- s.name AS TERNOM,
- ii.booked FECREGCON,
- ii.cplusTrascendency472Fk TIPOCLAVE,
- a.issued FECHA_EX,
- a.operated FECHA_OP,
- a.booked FECHA
- FROM invoiceInAwb iia
- JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = iia.invoiceInFk
- JOIN awb a ON a.id = iia.awbFk
- JOIN invoiceIn ii ON ii.id = iie.invoiceInFk
- JOIN invoiceInSerial iis ON iis.code = ii.serial
- JOIN buy b ON b.entryFk = iie.entryFk
- JOIN item i ON i.id = b.itemFk
- JOIN (
- SELECT
- i.intrastatFk,
- sum(b.buyingValue * b.quantity) as intrastatSum
- FROM buy b
- JOIN item i ON i.id = b.itemFk
- JOIN invoiceInEntry iie
- ON iie.entryFk = b.entryFk
- JOIN invoiceInAwb iia
- ON iia.invoiceInFk = iie.invoiceInAwbFk
- JOIN awb aw ON aw.id =iia.awbFk
- WHERE iie.percentage AND iia.invoiceInFk = vInvoiceInId
- GROUP BY i.intrastatFk
- ) intraSub ON intraSub.intrastatFk = i.intrastatFk
- JOIN (
- SELECT
- iii.intrastatFk,
- iii.amount,
- intr.taxCodeFk
- FROM invoiceInIntrastat iii
- JOIN intrastat intr
- ON intr.id = iii.intrastatFk
- WHERE iii.invoiceInFk = vInvoiceInId
- ) taxSub ON taxSub.intrastatFk = i.intrastatFk
- JOIN taxCode tc ON tc.id = taxSub.taxCodeFk
- JOIN entry e ON e.id = iie.entryFk
- JOIN supplier s ON s.id = e.supplierFk
- WHERE iie.invoiceInAwbFk = vInvoiceInId AND iie.percentage
- GROUP BY e.supplierFk, taxSub.taxCodeFk
- ) x
- GROUP BY x.supplierFk, x.IVA;
-
-
- UPDATE newInvoiceIn n
- JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = vInvoiceInId
- JOIN invoiceIn ii ON ii.id = iie.invoiceInFk
- SET ii.booked = IFNULL(ii.booked,n.booked),
- ii.operated = IFNULL(ii.operated,n.issued);
-
-
- UPDATE invoiceIn
- SET
- serialNumber = vSerialNumber,
- isBooked = TRUE
- WHERE
- id = vInvoiceInId;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `invoiceInBookingCommon` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceInBookingCommon`(vInvoiceInId INT, OUT vSerialNumber INT)
-BEGIN
-
- DROP TEMPORARY TABLE IF EXISTS newInvoiceIn;
-
- CREATE TEMPORARY TABLE newInvoiceIn
- SELECT
- i.*,
- YEAR(i.booked) datedYear,
-
- CONCAT('s/fra',RIGHT(i.supplierRef,8),':',LEFT(s.name, 10)) conceptWithSupplier,
- (cc.id = c.id) isSameCountry,
- cit.id invoicesCount
- FROM invoiceIn i
- JOIN cplusInvoiceType472 cit ON cit.id = i.cplusInvoiceType472Fk
- JOIN supplier s ON s.id = i.supplierFk
- JOIN country c ON c.id = s.countryFk
- JOIN supplier sc ON sc.id = i.companyFk
- JOIN country cc ON cc.id = sc.countryFk
- WHERE i.id = vInvoiceInId;
-
- DROP TEMPORARY TABLE IF EXISTS newSupplier;
- CREATE TEMPORARY TABLE newSupplier
- SELECT
- s.*,
- REPLACE(s.account,' ','') supplierAccount,
- IF(c.CEE < 2, TRUE, FALSE) isUeeMember
- FROM supplier s
- JOIN newInvoiceIn n
- JOIN country c ON c.id = s.countryFk
- WHERE s.id = n.supplierFk;
-
- IF (SELECT isActive FROM newSupplier) = 0 THEN
- CALL util.throw('INACTIVE_PROVIDER');
- END IF;
-
- SELECT IFNULL(MAX(i.serialNumber) + 1,1)
- INTO vSerialNumber
- FROM invoiceIn i
- JOIN newInvoiceIn n
- WHERE i.serial LIKE n.serial
- AND YEAR(i.booked) = n.datedYear
- AND i.companyFk = n.companyFk
- GROUP BY i.companyFk;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `invoiceInBookingExtra` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceInBookingExtra`(vInvoiceInId INT)
-BEGIN
- DECLARE vBookNumber,vSerialNumber INT;
-
- CALL invoiceInBookingCommon(vInvoiceInId,vSerialNumber);
-
- SELECT MAX(ASIEN) + 1
- INTO vBookNumber
- FROM vn2008.XDiario;
-
-
- INSERT INTO vn2008.XDiario (
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EURODEBE,
- CONCEPTO,
- NFACTICK,
- empresa_id
- )
- SELECT
- vBookNumber ASIEN,
- IFNULL(a.booked, n.booked) FECHA,
- iit.expenceFk SUBCTA,
- s.account CONTRA,
- ROUND(SUM(iit.taxableBase) * (iie.percentage / 100),2) EURODEBE,
- CONCAT('COMPRA s/fra ',i.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
- n.invoicesCount NFACTICK,
- n.companyFk empresa_id
- FROM newInvoiceIn n
- JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = n.id
- JOIN invoiceInTax iit ON iit.invoiceInFk = iie.invoiceInFk
- JOIN invoiceIn i ON i.id = iit.invoiceInFk
- JOIN supplier s ON s.id = i.supplierFk
- LEFT JOIN invoiceInAwb iia ON iia.invoiceInFk = n.id
- LEFT JOIN awb a ON a.id = iia.awbFk
- WHERE iie.percentage
- GROUP BY i.id;
-
-
- INSERT INTO vn2008.XDiario (
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EUROHABER,
- CONCEPTO,
- NFACTICK,
- empresa_id
- )
- SELECT
- vBookNumber ASIEN,
- IFNULL(a.booked, n.booked) FECHA,
- s.account SUBCTA,
- iit.expenceFk CONTRA,
- ROUND(SUM(iit.taxableBase) * (iie.percentage / 100),2) EUROHABER,
- CONCAT('COMPRA s/fra ',i.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
- n.invoicesCount NFACTICK,
- n.companyFk empresa_id
- FROM newInvoiceIn n
- JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = n.id
- JOIN invoiceInTax iit ON iit.invoiceInFk = iie.invoiceInFk
- JOIN invoiceIn i ON i.id = iit.invoiceInFk
- JOIN supplier s ON s.id = i.supplierFk
- LEFT JOIN invoiceInAwb iia ON iia.invoiceInFk = n.id
- LEFT JOIN awb a ON a.id = iia.awbFk
- WHERE iie.percentage
- GROUP BY i.id;
-
-
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- CONCEPTO,
- EUROHABER,
- SERIE,
- empresa_id)
-
- SELECT
- vBookNumber,
- a.booked,
- '4700000999',
- n.conceptWithSupplier,
- ROUND(SUM(iii.amount * (tc.rate/100)),2) eurohaber,
- n.serial,
- n.companyFk
- FROM newInvoiceIn n
- JOIN invoiceInIntrastat iii ON n.id = iii.invoiceInFk
- JOIN intrastat ii ON ii.id = iii.intrastatFk
- JOIN taxCode tc ON tc.id = ii.taxCodeFk
- JOIN invoiceInAwb iia ON iia.invoiceInFk = iii.invoiceInFk
- JOIN awb a ON a.id = iia.awbFk
- HAVING eurohaber IS NOT NULL;
-
-
-
- SET @cont:=1;
- SET @total:=0;
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EURODEBE,
- BASEEURO,
- CONCEPTO,
- FACTURA,
- IVA,
- AUXILIAR,
- SERIE,
- FECHA_EX,
- FECHA_OP,
- FACTURAEX,
- NFACTICK,
- L340,
- LDIFADUAN,
- TIPOCLAVE,
- TIPOEXENCI,
- TIPONOSUJE,
- TIPOFACT,
- TIPORECTIF,
- TERIDNIF,
- TERNIF,
- TERNOM,
- empresa_id,
- FECREGCON
- )
-
- SELECT
- vBookNumber ASIEN,
- x.FECHA,
- x.SUBCTA,
- x.CONTRA,
- IF (n.isSameCountry OR NOT s.isUeeMember,
- x.EURODEBE,
- NULL
- ) EURODEBE,
- x.BASEEURO,
- x.CONCEPTO,
- vSerialNumber FACTURA,
- x.IVA,
- '*' AUXILIAR,
- x.SERIE,
- x.FECHA_EX,
- x.FECHA_OP,
- x.dua FACTURAEX,
- n.invoicesCount NFACTICK,
- IF(@total:=@total + x.EURODEBE AND @cont:=@cont + 1 ,1,1) L340,
- TRUE LDIFADUAN,
- x.TIPOCLAVE,
- n.cplusTaxBreakFk TIPOEXENCI,
- n.cplusSubjectOpFk TIPONOSUJE,
- 5 TIPOFACT,
- n.cplusRectificationTypeFk TIPORECTIF,
- x.TERIDNIF,
- x.TERNIF,
- x.TERNOM,
- n.companyFk,
- IFNULL(x.FECREGCON,n.booked) FECREGCON
-
- FROM newInvoiceIn n
- JOIN newSupplier s
- JOIN (
- SELECT
-
- CONCAT('COMPRA s/fra ',ii.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
- tc.code SUBCTA,
- s.account CONTRA,
- tc.rate IVA,
- ROUND(sum(b.buyingValue * b.quantity / intraSub.intrastatSum * taxSub.amount)*(tc.rate/100),2) EURODEBE,
- ROUND(sum(b.buyingValue * b.quantity / intraSub.intrastatSum * taxSub.amount),2) BASEEURO,
- ii.serial SERIE,
- e.supplierFk,
- iia.dua,
- iis.cplusTerIdNifFk TERIDNIF,
- s.nif AS TERNIF,
- s.name AS TERNOM,
- ii.booked FECREGCON,
- ii.cplusTrascendency472Fk TIPOCLAVE,
- a.issued FECHA_EX,
- a.operated FECHA_OP,
- a.booked FECHA
- FROM invoiceInAwb iia
- JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = iia.invoiceInFk
- JOIN awb a ON a.id = iia.awbFk
- JOIN invoiceIn ii ON ii.id = iie.invoiceInFk
- JOIN invoiceInSerial iis ON iis.code = ii.serial
- JOIN buy b ON b.entryFk = iie.entryFk
- JOIN item i ON i.id = b.itemFk
- JOIN (
- SELECT
- i.intrastatFk,
- sum(b.buyingValue * b.quantity) as intrastatSum
- FROM buy b
- JOIN item i ON i.id = b.itemFk
- JOIN invoiceInEntry iie ON iie.entryFk = b.entryFk
- JOIN invoiceInAwb iia ON iia.invoiceInFk = iie.invoiceInAwbFk
- JOIN awb aw ON aw.id =iia.awbFk
- WHERE iie.percentage AND iia.invoiceInFk = vInvoiceInId
- GROUP BY i.intrastatFk
- ) intraSub ON intraSub.intrastatFk = i.intrastatFk
- JOIN (
- SELECT
- iii.intrastatFk,
- iii.amount,
- intr.taxCodeFk
- FROM invoiceInIntrastat iii
- JOIN intrastat intr ON intr.id = iii.intrastatFk
- WHERE iii.invoiceInFk = vInvoiceInId
- ) taxSub ON taxSub.intrastatFk = i.intrastatFk
- JOIN taxCode tc ON tc.id = taxSub.taxCodeFk
- JOIN entry e ON e.id = iie.entryFk
- JOIN supplier s ON s.id = e.supplierFk
- WHERE iie.invoiceInAwbFk = vInvoiceInId AND iie.percentage
- GROUP BY e.supplierFk, taxSub.taxCodeFk
- ) x
- GROUP BY x.supplierFk, x.IVA;
-
-
- UPDATE newInvoiceIn n
- JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = vInvoiceInId
- JOIN invoiceIn ii ON ii.id = iie.invoiceInFk
- SET ii.isBooked = TRUE,
- ii.booked = IFNULL(ii.booked,n.booked),
- ii.operated = IFNULL(ii.operated,n.issued);
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `invoiceInBookingkk` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceInBookingkk`(vInvoiceInId INT)
-BEGIN
- DECLARE vDocument VARCHAR(255);
- DECLARE vSerialNumber, vBookNumber, vBookNumberPlus1 INT;
- DECLARE vTotalAmount DECIMAL(10,2);
-
- DROP TEMPORARY TABLE IF EXISTS newInvoiceIn;
-
- CREATE TEMPORARY TABLE newInvoiceIn
- SELECT
- i.*,
- YEAR(i.booked) datedYear,
-
- CONCAT('s/fra',RIGHT(i.supplierRef,8),':',LEFT(s.name, 10)) conceptWithSupplier,
- (cc.id = c.id) isSameCountry,
- cit.id invoicesCount
- FROM invoiceIn i
- JOIN cplusInvoiceType472 cit ON cit.id = i.cplusInvoiceType472Fk
- JOIN supplier s ON s.id = i.supplierFk
- JOIN country c ON c.id = s.countryFk
- JOIN supplier sc ON sc.id = i.companyFk
- JOIN country cc ON cc.id = sc.countryFk
- WHERE i.id = vInvoiceInId;
-
- DROP TEMPORARY TABLE IF EXISTS newSupplier;
- CREATE TEMPORARY TABLE newSupplier
- SELECT
- s.*,
- REPLACE(s.account,' ','') supplierAccount,
- IF(c.CEE < 2, TRUE, FALSE) isUeeMember
- FROM supplier s
- JOIN newInvoiceIn n
- JOIN country c ON c.id = s.countryFk
- WHERE s.id = n.supplierFk;
-
- IF (SELECT isActive FROM newSupplier) = 0 THEN
- CALL util.throw('INACTIVE_PROVIDER');
- END IF;
-
- SELECT IFNULL(MAX(i.serialNumber) + 1,1)
- INTO vSerialNumber
- FROM invoiceIn i
- JOIN newInvoiceIn n
- WHERE i.serial LIKE n.serial
- AND YEAR(i.booked) = n.datedYear
- AND i.companyFk = n.companyFk
- GROUP BY i.companyFk;
-
- SELECT MAX(ASIEN) + 1
- INTO vBookNumber
- FROM vn2008.XDiario;
-
- SET vBookNumberPlus1 = vBookNumber + 1;
-
- SELECT CONCAT(serial,'/', LPAD(vSerialNumber,5,'0'))
- INTO vDocument
- FROM newInvoiceIn;
-
- SELECT SUM(iit.taxableBase * IF(i.serial = 'R', 1 +(tc.rate/100),1))
- INTO vTotalAmount
- FROM invoiceIn i
- JOIN invoiceInTax iit ON iit.invoiceInFk = i.id
- JOIN taxCode tc ON iit.taxCodeFk = tc.id
- WHERE i.id = vInvoiceInId;
-
-
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- EUROHABER,
- CONCEPTO,
- NFACTICK,
- empresa_id)
- SELECT
- vBookNumber,
- n.booked,
- s.supplierAccount,
- vTotalAmount,
- n.conceptWithSupplier,
- n.invoicesCount,
- n.companyFk
- FROM newInvoiceIn n
- JOIN newSupplier s;
-
-
- INSERT INTO vn2008.XDiario (
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EURODEBE,
- EUROHABER,
- CONCEPTO,
- NFACTICK,
- empresa_id
- )
- SELECT
- vBookNumber ASIEN,
- n.booked FECHA,
- if(
- e.isWithheld,
- LPAD(RIGHT(s.supplierAccount ,5),10,iit.expenceFk),
- iit.expenceFk
- ) SUBCTA,
- s.supplierAccount CONTRA,
- if(
- e.isWithheld,
- NULL,
- ABS(ROUND(SUM(iit.taxableBase),2))
- ) EURODEBE,
- if(
- e.isWithheld,
- ABS(ROUND(SUM(iit.taxableBase),2)),
- NULL
- ) EUROHABER,
- n.conceptWithSupplier CONCEPTO,
- n.invoicesCount NFACTICK,
- n.companyFk empresa_id
- FROM newInvoiceIn n
- JOIN newSupplier s
- JOIN invoiceInTax iit ON iit.invoiceInFk = n.id
- JOIN taxCode tc ON tc.id = iit.taxCodeFk
- JOIN expence e ON e.id = iit.expenceFk AND e.taxTypeFk = tc.taxTypeFk
- WHERE iit.expenceFk != 5660000002
- GROUP BY iit.expenceFk;
-
-
- INSERT INTO vn2008.XDiario (
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EURODEBE,
- CONCEPTO,
- NFACTICK,
- empresa_id
- )
- SELECT
- vBookNumberPlus1 ASIEN,
- IFNULL(a.booked, n.booked) FECHA,
- iit.expenceFk SUBCTA,
- s.account CONTRA,
- ROUND(SUM(iit.taxableBase) * (iie.percentage / 100),2) EURODEBE,
- CONCAT('COMPRA s/fra ',i.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
- n.invoicesCount NFACTICK,
- n.companyFk empresa_id
- FROM newInvoiceIn n
- JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = n.id
- JOIN invoiceInTax iit ON iit.invoiceInFk = iie.invoiceInFk
- JOIN invoiceIn i ON i.id = iit.invoiceInFk
- JOIN supplier s ON s.id = i.supplierFk
- LEFT JOIN invoiceInAwb iia ON iia.invoiceInFk = n.id
- LEFT JOIN awb a ON a.id = iia.awbFk
- WHERE iie.percentage
- GROUP BY i.id;
-
-
- INSERT INTO vn2008.XDiario (
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EUROHABER,
- CONCEPTO,
- NFACTICK,
- empresa_id
- )
- SELECT
- vBookNumberPlus1 ASIEN,
- IFNULL(a.booked, n.booked) FECHA,
- s.account SUBCTA,
- iit.expenceFk CONTRA,
- ROUND(SUM(iit.taxableBase) * (iie.percentage / 100),2) EUROHABER,
- CONCAT('COMPRA s/fra ',i.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
- n.invoicesCount NFACTICK,
- n.companyFk empresa_id
- FROM newInvoiceIn n
- JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = n.id
- JOIN invoiceInTax iit ON iit.invoiceInFk = iie.invoiceInFk
- JOIN invoiceIn i ON i.id = iit.invoiceInFk
- JOIN supplier s ON s.id = i.supplierFk
- LEFT JOIN invoiceInAwb iia ON iia.invoiceInFk = n.id
- LEFT JOIN awb a ON a.id = iia.awbFk
- WHERE iie.percentage
- GROUP BY i.id;
-
-
-
-
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EURODEBE,
- BASEEURO,
- CONCEPTO,
- FACTURA,
- IVA,
- AUXILIAR,
- SERIE,
- TIPOOPE,
- FECHA_EX,
- FECHA_OP,
- NFACTICK,
- FACTURAEX,
- L340,
- LRECT349,
- TIPOCLAVE,
- TIPOEXENCI,
- TIPONOSUJE,
- TIPOFACT,
- TIPORECTIF,
- TERIDNIF,
- TERNIF,
- TERNOM,
- FECREGCON,
- empresa_id
- )
- SELECT
- vBookNumber ASIEN,
- n.booked FECHA,
- tc.code SUBCTA,
- s.supplierAccount CONTRA,
- ROUND(tc.rate/100*it.taxableBase + 0.0001,2) EURODEBE,
- it.taxableBase BASEEURO,
- GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO,
- vSerialNumber FACTURA,
- tc.rate IVA,
- IF(isUeeMember AND eWithheld.id IS NULL,'','*') AUXILIAR,
- n.serial SERIE,
- tt.TIPOOPE,
- n.issued FECHA_EX,
- n.operated FECHA_OP,
- n.invoicesCount NFACTICK,
- n.supplierRef FACTURAEX,
- TRUE L340,
- (isSameCountry OR NOT isUeeMember) LRECT349,
- n.cplusTrascendency472Fk TIPOCLAVE,
- n.cplusTaxBreakFk TIPOEXENCI,
- n.cplusSubjectOpFk TIPONOSUJE,
- n.cplusInvoiceType472Fk TIPOFACT,
- n.cplusRectificationTypeFk TIPORECTIF,
- iis.cplusTerIdNifFk TERIDNIF,
- s.nif AS TERNIF,
- s.name AS TERNOM,
- n.booked FECREGCON,
- n.companyFk
-
- FROM newInvoiceIn n
- JOIN newSupplier s
- JOIN invoiceInTax it ON n.id = it.invoiceInFk
- JOIN taxCode tc ON tc.id = it.taxCodeFk
- JOIN taxType tt ON tt.id = tc.taxTypeFk
- JOIN invoiceInSerial iis ON iis.code = tt.serial
- JOIN expence e ON e.id = it.expenceFk AND e.taxTypeFk = tc.taxTypeFk
- LEFT JOIN invoiceInTax hold ON hold.invoiceInFk = n.id
- LEFT JOIN expence eWithheld ON eWithheld.id = hold.expenceFk AND eWithheld.isWithheld
- WHERE tc.type != '-'
- AND tc.isActive
- GROUP BY tc.rate;
-
-
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EUROHABER,
- BASEEURO,
- CONCEPTO,
- FACTURA,
- IVA,
- AUXILIAR,
- SERIE,
- TIPOOPE,
- FECHA_EX,
- FECHA_OP,
- NFACTICK,
- FACTURAEX,
- L340,
- LRECT349,
- TIPOCLAVE,
- TIPOEXENCI,
- TIPONOSUJE,
- TIPOFACT,
- TIPORECTIF,
- TERIDNIF,
- TERNIF,
- TERNOM,
- empresa_id
- )
-
- SELECT
- vBookNumber ASIEN,
- n.booked FECHA,
- tcLink.code SUBCTA,
- s.supplierAccount CONTRA,
- ROUND(tcLink.rate/100*SUM(it.taxableBase) + 0.0001,2) EUROHABER,
- ROUND(SUM(it.taxableBase),2) BASEEURO,
- GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO,
- vSerialNumber FACTURA,
- tcLink.rate IVA,
- '*' AUXILIAR,
- n.serial SERIE,
- tt.TIPOOPE,
- n.issued FECHA_EX,
- n.operated FECHA_OP,
- n.invoicesCount NFACTICK,
- n.supplierRef FACTURAEX,
- FALSE L340,
- (isSameCountry OR NOT isUeeMember) LRECT349,
- 1 TIPOCLAVE,
- n.cplusTaxBreakFk TIPOEXENCI,
- n.cplusSubjectOpFk TIPONOSUJE,
- n.cplusInvoiceType472Fk TIPOFACT,
- n.cplusRectificationTypeFk TIPORECTIF,
- iis.cplusTerIdNifFk TERIDNIF,
- s.nif AS TERNIF,
- s.name AS TERNOM,
- n.companyFk
-
- FROM newInvoiceIn n
- JOIN newSupplier s
- JOIN invoiceInTax it ON n.id = it.invoiceInFk
- JOIN taxCode tc ON tc.id = it.taxCodeFk
- JOIN taxType tt ON tt.id = tc.taxTypeFk
- JOIN invoiceInSerial iis ON iis.code = tt.serial
- JOIN taxCode tcLink ON tcLink.linkFk = tc.linkFk AND tc.id != tcLink.id
- JOIN expence e ON e.id = it.expenceFk AND e.taxTypeFk = tc.taxTypeFk
- WHERE tc.isActive
- GROUP BY tcLink.rate, e.id;
-
-
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- CONCEPTO,
- EUROHABER,
- SERIE,
- empresa_id)
-
- SELECT
- vBookNumberPlus1,
- a.booked,
- '4700000999',
- n.conceptWithSupplier,
- ROUND(SUM(iii.amount * (tc.rate/100)),2) eurohaber,
- n.serial,
- n.companyFk
- FROM newInvoiceIn n
- JOIN invoiceInIntrastat iii ON n.id = iii.invoiceInFk
- JOIN intrastat ii ON ii.id = iii.intrastatFk
- JOIN taxCode tc ON tc.id = ii.taxCodeFk
- JOIN invoiceInAwb iia ON iia.invoiceInFk = iii.invoiceInFk
- JOIN awb a ON a.id = iia.awbFk
- HAVING eurohaber IS NOT NULL;
-
-
-
-
- SET @cont:=1;
- SET @total:=0;
- SET @base:=2;
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EURODEBE,
- BASEEURO,
- CONCEPTO,
- FACTURA,
- IVA,
- AUXILIAR,
- SERIE,
- FECHA_EX,
- FECHA_OP,
- FACTURAEX,
- NFACTICK,
- L340,
- LDIFADUAN,
- TIPOCLAVE,
- TIPOEXENCI,
- TIPONOSUJE,
- TIPOFACT,
- TIPORECTIF,
- TERIDNIF,
- TERNIF,
- TERNOM,
- empresa_id,
- FECREGCON
- )
-
- SELECT
- vBookNumberPlus1 ASIEN,
- x.FECHA,
- x.SUBCTA,
- x.CONTRA,
- IF (n.isSameCountry OR NOT s.isUeeMember,
- x.EURODEBE,
- NULL
- ) EURODEBE,
- x.BASEEURO,
- x.CONCEPTO,
- vSerialNumber FACTURA,
- x.IVA,
- '*' AUXILIAR,
- x.SERIE,
- x.FECHA_EX,
- x.FECHA_OP,
- x.dua FACTURAEX,
- n.invoicesCount NFACTICK,
- IF(@total:=@total + x.EURODEBE AND @cont:=@cont + 1 ,1,1) L340,
- TRUE LDIFADUAN,
- x.TIPOCLAVE,
- n.cplusTaxBreakFk TIPOEXENCI,
- n.cplusSubjectOpFk TIPONOSUJE,
- 5 TIPOFACT,
- n.cplusRectificationTypeFk TIPORECTIF,
- x.TERIDNIF,
- x.TERNIF,
- x.TERNOM,
- n.companyFk,
- IFNULL(x.FECREGCON,n.booked) FECREGCON
-
- FROM newInvoiceIn n
- JOIN newSupplier s
- JOIN (
- SELECT
-
- CONCAT('COMPRA s/fra ',ii.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
- tc.code SUBCTA,
- s.account CONTRA,
- tc.rate IVA,
- ROUND(sum(b.buyingValue * b.quantity / intraSub.intrastatSum * taxSub.amount)*(tc.rate/100),2) EURODEBE,
- ROUND(sum(b.buyingValue * b.quantity / intraSub.intrastatSum * taxSub.amount),2) BASEEURO,
- ii.serial SERIE,
- e.supplierFk,
- iia.dua,
- iis.cplusTerIdNifFk TERIDNIF,
- s.nif AS TERNIF,
- s.name AS TERNOM,
- ii.booked FECREGCON,
- ii.cplusTrascendency472Fk TIPOCLAVE,
- a.issued FECHA_EX,
- a.operated FECHA_OP,
- a.booked FECHA
- FROM invoiceInAwb iia
- JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = iia.invoiceInFk
- JOIN awb a ON a.id = iia.awbFk
- JOIN invoiceIn ii ON ii.id = iie.invoiceInFk
- JOIN invoiceInSerial iis ON iis.code = ii.serial
- JOIN buy b ON b.entryFk = iie.entryFk
- JOIN item i ON i.id = b.itemFk
- JOIN (
- SELECT
- i.intrastatFk,
- sum(b.buyingValue * b.quantity) as intrastatSum
- FROM buy b
- JOIN item i ON i.id = b.itemFk
- JOIN invoiceInEntry iie
- ON iie.entryFk = b.entryFk
- JOIN invoiceInAwb iia
- ON iia.invoiceInFk = iie.invoiceInAwbFk
- JOIN awb aw ON aw.id =iia.awbFk
- WHERE iie.percentage AND iia.invoiceInFk = vInvoiceInId
- GROUP BY i.intrastatFk
- ) intraSub ON intraSub.intrastatFk = i.intrastatFk
- JOIN (
- SELECT
- iii.intrastatFk,
- iii.amount,
- intr.taxCodeFk
- FROM invoiceInIntrastat iii
- JOIN intrastat intr
- ON intr.id = iii.intrastatFk
- WHERE iii.invoiceInFk = vInvoiceInId
- ) taxSub ON taxSub.intrastatFk = i.intrastatFk
- JOIN taxCode tc ON tc.id = taxSub.taxCodeFk
- JOIN entry e ON e.id = iie.entryFk
- JOIN supplier s ON s.id = e.supplierFk
- WHERE iie.invoiceInAwbFk = vInvoiceInId AND iie.percentage
- GROUP BY e.supplierFk, taxSub.taxCodeFk
- ) x
- GROUP BY x.supplierFk, x.IVA;
-
-
- UPDATE newInvoiceIn n
- JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = vInvoiceInId
- JOIN invoiceIn ii ON ii.id = iie.invoiceInFk
- SET ii.booked = IFNULL(ii.booked,n.booked),
- ii.operated = IFNULL(ii.operated,n.issued);
-
-
- UPDATE invoiceIn
- SET
- serialNumber = vSerialNumber,
- isBooked = TRUE
- WHERE
- id = vInvoiceInId;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `invoiceInBookingMain` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceInBookingMain`(vInvoiceInId INT)
-BEGIN
- DECLARE vTotalAmount DECIMAL(10,2);
- DECLARE vBookNumber,vSerialNumber INT;
-
- CALL invoiceInBookingCommon(vInvoiceInId,vSerialNumber);
-
- SELECT MAX(ASIEN) + 1
- INTO vBookNumber
- FROM vn2008.XDiario;
-
- SELECT SUM(iit.taxableBase * IF(i.serial = 'R', 1 +(tc.rate/100),1))
- INTO vTotalAmount
- FROM newInvoiceIn i
- JOIN invoiceInTax iit ON iit.invoiceInFk = i.id
- JOIN taxCode tc ON iit.taxCodeFk = tc.id;
-
-
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- EUROHABER,
- CONCEPTO,
- NFACTICK,
- empresa_id)
- SELECT
- vBookNumber,
- n.booked,
- s.supplierAccount,
- vTotalAmount,
- n.conceptWithSupplier,
- n.invoicesCount,
- n.companyFk
- FROM newInvoiceIn n
- JOIN newSupplier s;
-
-
- INSERT INTO vn2008.XDiario (
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EURODEBE,
- EUROHABER,
- CONCEPTO,
- NFACTICK,
- empresa_id
- )
- SELECT
- vBookNumber ASIEN,
- n.booked FECHA,
- if(
- e.isWithheld,
- LPAD(RIGHT(s.supplierAccount ,5),10,iit.expenceFk),
- iit.expenceFk
- ) SUBCTA,
- s.supplierAccount CONTRA,
- if(
- e.isWithheld,
- NULL,
- ABS(ROUND(SUM(iit.taxableBase),2))
- ) EURODEBE,
- if(
- e.isWithheld,
- ABS(ROUND(SUM(iit.taxableBase),2)),
- NULL
- ) EUROHABER,
- n.conceptWithSupplier CONCEPTO,
- n.invoicesCount NFACTICK,
- n.companyFk empresa_id
- FROM newInvoiceIn n
- JOIN newSupplier s
- JOIN invoiceInTax iit ON iit.invoiceInFk = n.id
- JOIN taxCode tc ON tc.id = iit.taxCodeFk
- JOIN expence e ON e.id = iit.expenceFk AND e.taxTypeFk = tc.taxTypeFk
- WHERE iit.expenceFk != 5660000002
- GROUP BY iit.expenceFk;
-
-
-
-
-
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EURODEBE,
- BASEEURO,
- CONCEPTO,
- FACTURA,
- IVA,
- AUXILIAR,
- SERIE,
- TIPOOPE,
- FECHA_EX,
- FECHA_OP,
- NFACTICK,
- FACTURAEX,
- L340,
- LRECT349,
- TIPOCLAVE,
- TIPOEXENCI,
- TIPONOSUJE,
- TIPOFACT,
- TIPORECTIF,
- TERIDNIF,
- TERNIF,
- TERNOM,
- FECREGCON,
- empresa_id
- )
- SELECT vBookNumber ASIEN,
- n.booked FECHA,
- tc.code SUBCTA,
- s.supplierAccount CONTRA,
- SUM(ROUND(tc.rate/100*it.taxableBase + 0.0001,2)) EURODEBE,
- SUM(it.taxableBase) BASEEURO,
- GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO,
- vSerialNumber FACTURA,
- tc.rate IVA,
- IF(isUeeMember AND eWithheld.id IS NULL,'','*') AUXILIAR,
- n.serial SERIE,
- tt.TIPOOPE,
- n.issued FECHA_EX,
- n.operated FECHA_OP,
- n.invoicesCount NFACTICK,
- n.supplierRef FACTURAEX,
- TRUE L340,
- (isSameCountry OR NOT isUeeMember) LRECT349,
- n.cplusTrascendency472Fk TIPOCLAVE,
- n.cplusTaxBreakFk TIPOEXENCI,
- n.cplusSubjectOpFk TIPONOSUJE,
- n.cplusInvoiceType472Fk TIPOFACT,
- n.cplusRectificationTypeFk TIPORECTIF,
- iis.cplusTerIdNifFk TERIDNIF,
- s.nif AS TERNIF,
- s.name AS TERNOM,
- n.booked FECREGCON,
- n.companyFk
-
- FROM newInvoiceIn n
- JOIN newSupplier s
- JOIN invoiceInTax it ON n.id = it.invoiceInFk
- JOIN taxCode tc ON tc.id = it.taxCodeFk
- JOIN taxType tt ON tt.id = tc.taxTypeFk
- JOIN invoiceInSerial iis ON iis.code = tt.serial
- JOIN expence e ON e.id = it.expenceFk AND e.taxTypeFk = tc.taxTypeFk
- LEFT JOIN
- (SELECT eWithheld.id
- FROM invoiceInTax hold
- JOIN expence eWithheld ON eWithheld.id = hold.expenceFk AND eWithheld.isWithheld
- WHERE hold.invoiceInFk = 58262 LIMIT 1
- ) eWithheld ON TRUE
- WHERE tc.type != '-'
- AND tc.isActive
- GROUP BY tc.rate;
-
+select 4;
+ DELETE r.*
+ FROM tmp.risk r
+ JOIN vn2008.Clientes c on c.Id_Cliente = r.Id_Cliente
+ JOIN vn2008.pay_met pm on pm.id = c.pay_met_id
+ WHERE IFNULL(r.saldo,0) < 10
+ AND r.risk <= MAX_RISK_ALLOWED
+ AND pm.`name` = 'TARJETA';
+select 5;
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EUROHABER,
- BASEEURO,
- CONCEPTO,
- FACTURA,
- IVA,
- AUXILIAR,
- SERIE,
- TIPOOPE,
- FECHA_EX,
- FECHA_OP,
- NFACTICK,
- FACTURAEX,
- L340,
- LRECT349,
- TIPOCLAVE,
- TIPOEXENCI,
- TIPONOSUJE,
- TIPOFACT,
- TIPORECTIF,
- TERIDNIF,
- TERNIF,
- TERNOM,
- empresa_id
- )
-
- SELECT
- vBookNumber ASIEN,
- n.booked FECHA,
- tcLink.code SUBCTA,
- s.supplierAccount CONTRA,
- ROUND(tcLink.rate/100*SUM(it.taxableBase) + 0.0001,2) EUROHABER,
- ROUND(SUM(it.taxableBase),2) BASEEURO,
- GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO,
- vSerialNumber FACTURA,
- tcLink.rate IVA,
- '*' AUXILIAR,
- n.serial SERIE,
- tt.TIPOOPE,
- n.issued FECHA_EX,
- n.operated FECHA_OP,
- n.invoicesCount NFACTICK,
- n.supplierRef FACTURAEX,
- FALSE L340,
- (isSameCountry OR NOT isUeeMember) LRECT349,
- 1 TIPOCLAVE,
- n.cplusTaxBreakFk TIPOEXENCI,
- n.cplusSubjectOpFk TIPONOSUJE,
- n.cplusInvoiceType472Fk TIPOFACT,
- n.cplusRectificationTypeFk TIPORECTIF,
- iis.cplusTerIdNifFk TERIDNIF,
- s.nif AS TERNIF,
- s.name AS TERNOM,
- n.companyFk
-
- FROM newInvoiceIn n
- JOIN newSupplier s
- JOIN invoiceInTax it ON n.id = it.invoiceInFk
- JOIN taxCode tc ON tc.id = it.taxCodeFk
- JOIN taxType tt ON tt.id = tc.taxTypeFk
- JOIN invoiceInSerial iis ON iis.code = tt.serial
- JOIN taxCode tcLink ON tcLink.linkFk = tc.linkFk AND tc.id != tcLink.id
- JOIN expence e ON e.id = it.expenceFk AND e.taxTypeFk = tc.taxTypeFk
- WHERE tc.isActive
- GROUP BY tcLink.rate, e.id;
-
-
- UPDATE invoiceIn ii
- JOIN newInvoiceIn ni ON ii.id = ni.id
- SET
- ii.serialNumber = vSerialNumber,
- ii.isBooked = 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 `invoiceMakeByClient` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceMakeByClient`(vClientFk INT, vSerial CHAR(1), vShipped DATE, vCompanyFk INT, OUT vInvoiceId INT)
-BEGIN
-
- CALL invoiceFromClient(vShipped, vClientFk, vCompanyFk);
- CALL invoiceOutMake(vSerial, CURDATE(), vInvoiceId);
-
- IF vSerial <> 'R' AND NOT ISNULL(vInvoiceId) AND vInvoiceId <> 0 THEN
- CALL invoiceOutBooking(vInvoiceId);
- INSERT INTO printServerQueue(priorityFk, reportFk, param1) VALUES(1, 3, vInvoiceId);
- 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 `invoiceMakeByTicket` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceMakeByTicket`(vTicketFk INT, vSerial CHAR(1), OUT vInvoiceId INT)
-BEGIN
-
- CALL invoiceFromTicket(vTicketFk);
- CALL invoiceOutMake(vSerial, CURDATE(), vInvoiceId);
-
- IF vSerial <> 'R' AND NOT ISNULL(vInvoiceId) AND vInvoiceId <> 0 THEN
- CALL invoiceOutBooking(vInvoiceId);
- INSERT INTO printServerQueue(priorityFk, reportFk, param1) VALUES(1, 3, vInvoiceId);
- 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 `invoiceOutAgain` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceOutAgain`(IN vInvoiceRef VARCHAR(15))
-BEGIN
-
-
-
- DECLARE vInvoice INT;
- DECLARE vCountry INT;
- DECLARE vTaxArea VARCHAR(15);
- DECLARE vSpainCountryCode INT DEFAULT 1;
-
- SELECT id
- INTO vInvoice
- FROM invoiceOut
- WHERE ref = vInvoiceRef;
-
- UPDATE invoiceOut
- SET pdf = 0
- WHERE id = vInvoice;
-
- SELECT s.countryFk
- INTO vCountry
- FROM supplier s
- JOIN invoiceOut io ON io.companyFk = s.id
- WHERE io.id = vInvoice;
-
- SELECT IF(a.isEqualizated
- AND c.countryFk = vSpainCountryCode
- AND i.taxAreaFk = 'NATIONAL',
- 'EQU',
- i.taxAreaFk)
- INTO vTaxArea
- FROM invoiceOutSerial i
- JOIN invoiceOut io ON io.serial = i.code
- JOIN ticket t ON t.refFk = io.ref
- JOIN address a ON a.id = t.addressFk
- JOIN client c ON c.id = t.clientFk
- WHERE io.id = vInvoice
- LIMIT 1;
-
- DROP TEMPORARY TABLE IF EXISTS ticketToInvoice;
-
- CREATE TEMPORARY TABLE ticketToInvoice
- SELECT id
- FROM ticket
- WHERE refFk = vInvoiceRef;
-
- CALL invoiceExpenceMake(vInvoice);
- CALL invoiceTaxMake(vInvoice,vCountry,vTaxArea);
-
- UPDATE invoiceOut io
- JOIN (
- SELECT SUM(amount) AS total
- FROM invoiceOutExpence
- WHERE invoiceOutFk = vInvoice
- ) base
- JOIN (
- SELECT SUM(vat) AS total
- FROM invoiceOutTax
- WHERE invoiceOutFk = vInvoice
- ) vat
- SET io.amount = base.total + vat.total
- WHERE io.id = vInvoice;
-
- CALL vn.invoiceOutBooking(vInvoice);
-
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `invoiceOutAgainDateRange` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceOutAgainDateRange`(IN vFirstDate DATE, IN vLastDate DATE)
-BEGIN
-
- DECLARE done BOOL DEFAULT FALSE;
- DECLARE vInvoice INT;
- DECLARE vInvoiceRef VARCHAR(15);
- DECLARE vContador INT DEFAULT 0;
-
- DECLARE rs CURSOR FOR
- SELECT id, ref
- FROM vn.invoiceOut
- WHERE issued BETWEEN vFirstDate AND vLastDate
- AND booked IS NULL;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-
- OPEN rs;
-
- FETCH rs INTO vInvoice, vInvoiceRef;
-
- WHILE NOT done DO
-
- CALL vn.invoiceOutAgain(vInvoiceRef);
-
- FETCH rs INTO vInvoice, vInvoiceRef;
-
- SET vContador = vContador + 1;
-
- IF vContador MOD 50 = 0 THEN
-
- SELECT CONCAT(vContador, ' de momento') AS FACTURAS_ASENTADAS;
-
- END IF;
- END WHILE;
-
- CLOSE rs;
-
- SELECT CONCAT(vContador, ' total') AS FACTURAS_ASENTADAS;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_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 `invoiceOutBooking` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceOutBooking`(IN vInvoice INT)
-BEGIN
-
-
-
- DECLARE vBookNumber INT;
- DECLARE vExpenceConcept VARCHAR(50);
- DECLARE isUEENotSpain INT DEFAULT 1;
- DECLARE vOldBookNumber INT;
-
- SELECT ASIEN
- INTO vOldBookNumber
- FROM vn2008.XDiario x
- JOIN vn.invoiceOut io ON io.id = vInvoice
- WHERE x.SERIE = io.serial
- AND x.FACTURA = RIGHT(io.ref, LENGTH(io.ref) - 1)
- LIMIT 1;
-
- DELETE
- FROM vn2008.XDiario
- WHERE ASIEN = vOldBookNumber;
-
- SELECT MAX(ASIEN) + 1
- INTO vBookNumber
- FROM vn2008.XDiario;
-
- DROP TEMPORARY TABLE IF EXISTS rs;
- CREATE TEMPORARY TABLE rs
- SELECT
- c.accountingAccount AS clientBookingAccount,
- io.amount as totalAmount,
- CONCAT('n/fra ', io.ref) as simpleConcept,
- CONCAT('n/fra ', io.ref, ' ', c.name) as Concept,
- io.serial AS SERIE,
- io.issued AS FECHA_EX,
- opDate.FECHA_OP,
- io.issued AS FECHA,
- 1 AS NFACTICK,
- IF(ic.correctingFk,'D','') AS TIPOOPE,
- io.cplusTrascendency477Fk AS TIPOCLAVE,
- io.cplusTaxBreakFk AS TIPOEXENCI,
- io.cplusSubjectOpFk AS TIPONOSUJE,
- io.cplusInvoiceType477Fk AS TIPOFACT,
- ic.cplusRectificationTypeFk AS TIPORECTIF,
- io.companyFk,
- RIGHT(io.ref, LENGTH(io.ref) - 1) AS invoiceNum,
- IF(ct.CEE = 0, 1, IF(ct.CEE = isUEENotSpain,2,4)) AS TERIDNIF,
- CONCAT(IF(ct.CEE = isUEENotSpain,ct.code,''),c.fi) AS TERNIF,
- c.socialName AS TERNOM,
- ior.serial AS SERIE_RT,
- RIGHT(ior.ref, LENGTH(ior.ref) - 1) AS FACTU_RT,
- ior.issued AS FECHA_RT,
- IF(ior.id,TRUE,FALSE) AS RECTIFICA
-
- FROM invoiceOut io
- JOIN (
- SELECT MAX(shipped) as FECHA_OP
- FROM ticket t
- JOIN invoiceOut io ON io.ref = t.refFk
- WHERE io.id = vInvoice ) opDate
- JOIN invoiceOutSerial ios ON ios.code = io.serial
- JOIN client c ON c.id = io.clientFk
- JOIN country ct ON ct.id = c.countryFk
- LEFT JOIN invoiceCorrection ic ON ic.correctingFk = io.id
- LEFT JOIN invoiceOut ior ON ior.id = ic.correctedFk
- WHERE io.id = vInvoice;
-
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- EURODEBE,
- CONCEPTO,
- FECHA_EX,
- FECHA_OP,
- empresa_id
- )
- SELECT
- vBookNumber AS ASIEN,
- rs.FECHA,
- rs.clientBookingAccount AS SUBCTA,
- rs.totalAmount AS EURODEBE,
- rs.simpleConcept AS CONCEPTO,
- rs.FECHA_EX,
- rs.FECHA_OP,
- rs.companyFk AS empresa_id
- FROM rs;
-
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EUROHABER,
- CONCEPTO,
- FECHA_EX,
- FECHA_OP,
- empresa_id
- )
- SELECT
- vBookNumber AS ASIEN,
- rs.FECHA,
- ioe.expenceFk AS SUBCTA,
- rs.clientBookingAccount AS CONTRA,
- ioe.amount AS EUROHABER,
- rs.Concept AS CONCEPTO,
- rs.FECHA_EX,
- rs.FECHA_OP,
- rs.companyFk AS empresa_id
- FROM rs
- JOIN invoiceOutExpence ioe
- WHERE ioe.invoiceOutFk = vInvoice;
-
- SELECT GROUP_CONCAT(`name` SEPARATOR ',')
- INTO vExpenceConcept
- FROM expence e
- JOIN invoiceOutExpence ioe ON ioe.expenceFk = e.id
- WHERE ioe.invoiceOutFk = vInvoice;
-
-
- INSERT INTO vn2008.XDiario(
- ASIEN,
- FECHA,
- SUBCTA,
- CONTRA,
- EUROHABER,
- BASEEURO,
- CONCEPTO,
- FACTURA,
- IVA,
- RECEQUIV,
- AUXILIAR,
- SERIE,
- SERIE_RT,
- FACTU_RT,
- RECTIFICA,
- FECHA_RT,
- FECHA_OP,
- FECHA_EX,
- TIPOOPE,
- NFACTICK,
- TERIDNIF,
- TERNIF,
- TERNOM,
- L340,
- TIPOCLAVE,
- TIPOEXENCI,
- TIPONOSUJE,
- TIPOFACT,
- TIPORECTIF,
- empresa_id
- )
- SELECT
- vBookNumber AS ASIEN,
- rs.FECHA,
- iot.pgcFk AS SUBCTA,
- rs.clientBookingAccount AS CONTRA,
- iot.vat AS EUROHABER,
- iot.taxableBase AS BASEEURO,
- CONCAT(vExpenceConcept,' : ',rs.Concept) AS CONCEPTO,
- rs.invoiceNum AS FACTURA,
- IF(pe2.equFk,0,pgc.rate) AS IVA,
- IF(pe2.equFk,0,pgce.rate) AS RECEQUIV,
- IF(pgc.mod347,'','*') AS AUXILIAR,
- rs.SERIE,
- rs.SERIE_RT,
- rs.FACTU_RT,
- rs.RECTIFICA,
- rs.FECHA_RT,
- rs.FECHA_OP,
- rs.FECHA_EX,
- rs.TIPOOPE,
- rs.NFACTICK,
- rs.TERIDNIF,
- rs.TERNIF,
- rs.TERNOM,
- pgc.mod340 AS L340,
- pgc.cplusTrascendency477Fk AS TIPOCLAVE,
- pgc.cplusTaxBreakFk as TIPOEXENCI,
- rs.TIPONOSUJE,
- rs.TIPOFACT,
- rs.TIPORECTIF,
- rs.companyFk AS empresa_id
- FROM rs
- JOIN invoiceOutTax iot
- JOIN pgc ON pgc.code = iot.pgcFk
- LEFT JOIN pgcEqu pe ON pe.vatFk = iot.pgcFk
- LEFT JOIN pgc pgce ON pgce.code = pe.equFk
- LEFT JOIN pgcEqu pe2 ON pe2.equFk = iot.pgcFk
- WHERE iot.invoiceOutFk = vInvoice;
-
- UPDATE invoiceOut
- SET booked = CURDATE()
- WHERE id = vInvoice;
-
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `invoiceOutBookingRange` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceOutBookingRange`()
-BEGIN
-
-
-
-
- DECLARE vInvoice INT;
- DECLARE vContador INT DEFAULT 0;
-
- DECLARE done BOOL DEFAULT FALSE;
-
- DECLARE rs CURSOR FOR
- SELECT io.id
- FROM invoiceOut io
- WHERE RIGHT(ref,7) BETWEEN 1724215 AND 1724224
- AND serial = 'T';
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-
- OPEN rs;
-
- FETCH rs INTO vInvoice;
-
- WHILE NOT done DO
-
- CALL invoiceOutBooking(vInvoice);
-
- FETCH rs INTO vInvoice ;
-
- SET vContador = vContador + 1;
-
- IF vContador MOD 50 = 0 THEN
-
- SELECT CONCAT(vContador, ' de momento') AS FACTURAS_ASENTADAS;
-
- END IF;
-
- END WHILE;
-
- CLOSE rs;
-
- SELECT CONCAT(vContador, ' total') AS FACTURAS_ASENTADAS;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `invoiceOutFix_BI_RE_IVA` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceOutFix_BI_RE_IVA`()
-BEGIN
-
-DECLARE done BOOL DEFAULT FALSE;
-DECLARE vInvoice INT;
-
-DECLARE rs CURSOR FOR
- SELECT factura_id
- FROM vn2008.Facturas
- WHERE Importe != BI7 + BI16 + RE4 + RE1 + IVA7 + IVA16
- AND Fecha >= '2017-07-01';
-
-DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-
-OPEN rs;
-
-FETCH rs INTO vInvoice;
-
-SELECT vInvoice, done;
-
-WHILE NOT done DO
-
- UPDATE invoiceOut io
- JOIN (
- SELECT SUM(amount) AS total
- FROM invoiceOutExpence
- WHERE invoiceOutFk = vInvoice
- ) base
- JOIN (
- SELECT SUM(vat) AS total
- FROM invoiceOutTax
- WHERE invoiceOutFk = vInvoice
- ) vat
- SET io.amount = base.total + vat.total
- WHERE io.id = vInvoice;
-
- UPDATE vn2008.Facturas
- SET BI16 = 0,
- BI7 = 0,
- RE1 = 0,
- RE4 = 0,
- IVA7 = 0,
- IVA16 = 0
- WHERE factura_id = vInvoice;
-
- UPDATE vn2008.Facturas f
- JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
- SET f.BI16 = iot.taxableBase, f.IVA16 = iot.vat
- WHERE f.factura_id = vInvoice
- AND iot.pgcFk IN ('4770000021' ,'4770000215', '4770000002','4771000000','4770000000','4770000020');
-
- UPDATE vn2008.Facturas f
- JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
- SET f.RE4 = iot.vat
- WHERE f.factura_id = vInvoice
- AND iot.pgcFk = '4770000521';
-
- UPDATE vn2008.Facturas f
- JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
- SET f.BI7 = iot.taxableBase, f.IVA7 = iot.vat
- WHERE f.factura_id = vInvoice
- AND iot.pgcFk IN ('4770000010' ,'4770000101');
-
- UPDATE vn2008.Facturas f
- JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
- SET f.RE1 = iot.vat
- WHERE f.factura_id = vInvoice
- AND iot.pgcFk = '4770000110';
-
-FETCH rs INTO vInvoice;
-
-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 `invoiceOutListByCompany` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceOutListByCompany`(vCompany INT, vStarted DATE, vEnded DATE)
-BEGIN
-
-SELECT
- c.socialName as RazonSocial,
- c.fi as NIF,
- io.ref as Factura,
- io.serial as Serie,
- io.issued as Fecha,
- io.amount as Importe,
- c.id as Id_Cliente,
- iot.taxableBase as Base,
- pgc.rate as Tipo,
- iot.vat as Cuota,
- pgc.name as Concepto
-
- FROM vn.invoiceOut io
- JOIN vn.invoiceOutTax iot ON iot.invoiceOutFk = io.id
- JOIN vn.client c ON c.id = io.clientFk
- JOIN vn.pgc ON pgc.code = iot.pgcFk
- WHERE io.companyFk = vCompany
- AND io.issued BETWEEN vStarted AND vEnded
- ORDER BY io.ref 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 `invoiceOutMake` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceOutMake`(
- vSerial VARCHAR(255),
- vInvoiceDate DATETIME,
- OUT vNewInvoiceId INT)
-BEGIN
-
-
-
- DECLARE vSpainCountryCode INT DEFAULT 1;
- DECLARE vIsAnySaleToInvoice BOOL;
- DECLARE vCountry TINYINT DEFAULT 1;
- DECLARE vTaxArea VARCHAR(15);
- DECLARE vNewRef VARCHAR(255);
- DECLARE vWorker INT DEFAULT vn.getWorker();
- DECLARE vCompany INT;
- DECLARE vClient INT;
- DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1;
- DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6;
- DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R';
-
- SET vInvoiceDate = IFNULL(vInvoiceDate,CURDATE());
-
- SELECT t.clientFk, t.companyFk
- INTO vClient, vCompany
- FROM ticketToInvoice tt
- JOIN ticket t ON t.id = tt.id
- LIMIT 1;
-
- SELECT countryFk
- INTO vCountry
- FROM supplier
- WHERE id = vCompany;
-
- SELECT IF(a.isEqualizated
- AND c.countryFk = vSpainCountryCode
- AND i.taxAreaFk = 'NATIONAL',
- 'EQU',
- i.taxAreaFk)
- INTO vTaxArea
- FROM invoiceOutSerial i
- JOIN ticketToInvoice tti
- JOIN ticket t ON t.id = tti.id
- JOIN address a ON a.id = t.addressFk
- JOIN client c ON c.id = t.clientFk
- WHERE i.code = vSerial
- LIMIT 1;
-
- INSERT INTO dailyTaskLog(state) VALUES('invoiceOutMake 1: START');
-
- START TRANSACTION;
-
-
- UPDATE ticket t
- JOIN ticketToInvoice ti ON ti.id = t.id
- LEFT JOIN sale s ON s.ticketFk = ti.id
- SET t.shipped = '2000-02-01 00:00:00'
- WHERE s.id IS NULL;
-
- INSERT INTO dailyTaskLog(state) VALUES('invoiceOutMake 1.1');
-
-
- DELETE ti.*
- FROM ticketToInvoice ti
- JOIN ticket t ON t.id = ti.id
- JOIN client c ON c.id = t.clientFk
- WHERE YEAR(t.shipped) < 2001
- OR c.isTaxDataChecked = FALSE;
- INSERT INTO dailyTaskLog(state) VALUES('invoiceOutMake 1.2');
-
- SELECT SUM(quantity * price * (100 - discount)/100)
- INTO vIsAnySaleToInvoice
- FROM sale s
- JOIN ticketToInvoice t on t.id = s.ticketFk;
-
- INSERT INTO dailyTaskLog(state) VALUES('invoiceOutMake 1.3');
-
- IF vIsAnySaleToInvoice THEN
-
-
-
- INSERT INTO invoiceOut
- (
- ref,
- serial,
- issued,
- clientFk,
- dued,
- companyFk,
- cplusInvoiceType477Fk
- )
- SELECT
- 1,
- vSerial,
- vInvoiceDate,
- vClient,
- getDueDate(vInvoiceDate, dueDay),
- vCompany,
- IF(vSerial = vCorrectingSerial, vCplusCorrectingInvoiceTypeFk, vCplusStandardInvoiceTypeFk)
- FROM client
- WHERE id = vClient;
-
-
- SET vNewInvoiceId = LAST_INSERT_ID();
-
- SELECT ref
- INTO vNewRef
- FROM invoiceOut
- WHERE id = vNewInvoiceId;
-
- UPDATE ticket t
- JOIN ticketToInvoice ti ON ti.id = t.id
- SET t.refFk = vNewRef;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.updateInter;
- CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY
- SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador
- FROM ticketToInvoice ti
- JOIN vn.ticketState ts ON ti.id = ts.ticket
- JOIN state s
- WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = vn.getAlert3State(ti.id);
-
- INSERT INTO vncontrol.inter(state_id,Id_Ticket,Id_Trabajador)
- SELECT * FROM tmp.updateInter;
-
- INSERT INTO logTicket (action, userFk,originFk, description)
- SELECT 'UPDATE',account.userGetId(),ti.id, CONCAT('CREA FACTURA ',vNewRef)
- FROM ticketToInvoice ti;
-
- CALL invoiceExpenceMake(vNewInvoiceId);
- CALL invoiceTaxMake(vNewInvoiceId,vCountry,vTaxArea);
-
- UPDATE invoiceOut io
- JOIN (
- SELECT SUM(amount) AS total
- FROM invoiceOutExpence
- WHERE invoiceOutFk = vNewInvoiceId
- ) base
- JOIN (
- SELECT SUM(vat) AS total
- FROM invoiceOutTax
- WHERE invoiceOutFk = vNewInvoiceId
- ) vat
- SET io.amount = base.total + vat.total
- WHERE io.id = vNewInvoiceId;
- INSERT INTO dailyTaskLog(state) VALUES('invoiceOutMake 2: START');
-
- UPDATE vn2008.Facturas f
- JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
- SET f.BI16 = iot.taxableBase, f.IVA16 = iot.vat
- WHERE f.factura_id = vNewInvoiceId
- AND iot.pgcFk IN ('4770000021' ,'4770000215', '4770000002','4771000000','4770000000','4770000020');
-
- UPDATE vn2008.Facturas f
- JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
- SET f.RE4 = iot.vat
- WHERE f.factura_id = vNewInvoiceId
- AND iot.pgcFk = '4770000521';
-
- UPDATE vn2008.Facturas f
- JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
- SET f.BI7 = iot.taxableBase, f.IVA7 = iot.vat
- WHERE f.factura_id = vNewInvoiceId
- AND iot.pgcFk IN ('4770000010' ,'4770000101');
-
- UPDATE vn2008.Facturas f
- JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
- SET f.RE1 = iot.vat
- WHERE f.factura_id = vNewInvoiceId
- AND iot.pgcFk = '4770000110';
- END IF;
-
-
- INSERT INTO dailyTaskLog(state) VALUES('invoiceOutMake 3: END');
-
- DROP TEMPORARY TABLE `ticketToInvoice`;
- 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 `invoiceOutTaxAndExpence` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceOutTaxAndExpence`()
-BEGIN
-
-
-
-
-
- DECLARE vInvoice INT;
- DECLARE vInvoiceRef VARCHAR(15);
- DECLARE vCountry INT;
- DECLARE vTaxArea VARCHAR(15);
- DECLARE vContador INT DEFAULT 0;
-
- DECLARE done BOOL DEFAULT FALSE;
-
- DECLARE rs CURSOR FOR
- SELECT id,ref
- FROM invoiceOut io
-
- WHERE issued >= '2017-07-01'
- AND companyFk = 1381
- AND io.amount IS NULL
- ;
-
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-
- OPEN rs;
-
- FETCH rs INTO vInvoice ,vInvoiceRef;
-
- WHILE NOT done DO
-
- SELECT s.countryFk
- INTO vCountry
- FROM supplier s
- JOIN invoiceOut io ON io.companyFk = s.id
- WHERE io.id = vInvoice;
-
- SELECT IF(c.isEqualizated AND i.taxAreaFk = 'NATIONAL','EQU',i.taxAreaFk)
- INTO vTaxArea
- FROM invoiceOutSerial i
- JOIN invoiceOut io ON io.serial = i.code
- JOIN client c ON c.id = io.clientFk
- WHERE io.id = vInvoice;
-
- DROP TEMPORARY TABLE IF EXISTS ticketToInvoice;
-
- CREATE TEMPORARY TABLE ticketToInvoice
- SELECT id
- FROM ticket
- WHERE refFk = vInvoiceRef;
-
- CALL invoiceExpenceMake(vInvoice);
- CALL invoiceTaxMake(vInvoice,vCountry,vTaxArea);
-
- FETCH rs INTO vInvoice ,vInvoiceRef;
-
- SET vContador = vContador + 1;
-
- IF vContador MOD 50 = 0 THEN
-
- SELECT CONCAT(vContador, ' de momento') AS FACTURAS_ASENTADAS;
-
- END IF;
-
- END WHILE;
-
- CLOSE rs;
-
- SELECT CONCAT(vContador, ' total') AS FACTURAS_ASENTADAS;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `invoiceTaxMake` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoiceTaxMake`(IN vInvoice INT, IN vCountry INT, IN vTaxArea VARCHAR(15))
-BEGIN
-
-
- DELETE FROM invoiceOutTax
- WHERE invoiceOutFk = vInvoice;
-
- INSERT INTO invoiceOutTax(
- invoiceOutFk,
- pgcFk,
- taxableBase,
- vat
- )
- SELECT vInvoice,
- bp.pgcFk,
- SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2)
- ) taxableBase,
- SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2)
- ) * pgc.rate / 100
- FROM ticketToInvoice t
- JOIN sale s ON s.ticketFk = t.id
- JOIN item i ON i.id = s.itemFk
- JOIN itemTaxCountry itc
- ON itc.itemFk = i.id AND itc.countryFk = vCountry
- JOIN bookingPlanner bp
- ON bp.countryFk = vCountry
- AND bp.taxAreaFk = vTaxArea
- AND bp.taxClassFk = itc.taxClassFk
- JOIN pgc ON pgc.code = bp.pgcFk
- GROUP BY pgc.code
- HAVING taxableBase != 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 `itemTagArrangedUpdate` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `itemTagArrangedUpdate`(IN vItem BIGINT)
-BEGIN
-
- DELETE
- FROM itemTagArranged
- WHERE vItem IS NULL
- OR vItem = itemFk;
-
- INSERT INTO itemTagArranged(itemFk)
- SELECT id
- FROM item
- WHERE vItem IS NULL
- OR vItem = id;
-
- REPLACE itemTagArranged
- SELECT i.id,
- 'Medida' as tag1,
- LEFT(i.size,15) as val1,
- 'Color' as tag2,
- LEFT(ink.`name`,15) as val2,
- 'Categoria' as tag3,
- LEFT(i.category,15) as val3,
- 'Productor' as tag4,
- LEFT(p.`name`,15) as val4,
- 'Tallos' as tag5,
- i.stems as val5,
- 'Origen' as tag6,
- o.code as val6,
- i.description
- FROM item i
- LEFT JOIN itemTagged it ON it.itemFk = i.id
- LEFT JOIN ink on ink.id = i.inkFk
- JOIN origin o ON o.id = i.originFk
- LEFT JOIN producer p ON p.id = i.producerFk
- WHERE it.itemFk IS NULL
- AND (vItem IS NULL OR vItem = i.id);
-
- CALL itemTagUpdatePriority(vItem);
-
- UPDATE itemTagArranged ita
- JOIN itemTag it ON it.itemFk = ita.itemFk
- JOIN tag t ON t.id = it.tagFk
- SET tag1 = t.name, val1 = it.value
- WHERE it.priority = 1
- AND (vItem IS NULL OR vItem = it.itemFk);
-
- UPDATE itemTagArranged ita
- JOIN itemTag it ON it.itemFk = ita.itemFk
- JOIN tag t ON t.id = it.tagFk
- SET tag2 = t.name, val2 = it.value
- WHERE it.priority = 2
- AND (vItem IS NULL OR vItem = it.itemFk);
-
- UPDATE itemTagArranged ita
- JOIN itemTag it ON it.itemFk = ita.itemFk
- JOIN tag t ON t.id = it.tagFk
- SET tag3 = t.name, val3 = it.value
- WHERE it.priority = 3
- AND (vItem IS NULL OR vItem = it.itemFk);
-
- UPDATE itemTagArranged ita
- JOIN itemTag it ON it.itemFk = ita.itemFk
- JOIN tag t ON t.id = it.tagFk
- SET tag4 = t.name, val4 = it.value
- WHERE it.priority = 4
- AND (vItem IS NULL OR vItem = it.itemFk);
-
- UPDATE itemTagArranged ita
- JOIN itemTag it ON it.itemFk = ita.itemFk
- JOIN tag t ON t.id = it.tagFk
- SET tag5 = t.name, val5 = it.value
- WHERE it.priority = 5
- AND (vItem IS NULL OR vItem = it.itemFk);
-
- UPDATE itemTagArranged ita
- JOIN itemTag it ON it.itemFk = ita.itemFk
- JOIN tag t ON t.id = it.tagFk
- SET tag6 = t.name, val6 = it.value
- WHERE it.priority = 6
- AND (vItem IS NULL OR vItem = it.itemFk);
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `itemTagUpdatePriority` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `itemTagUpdatePriority`(IN vItem INT)
-BEGIN
-
-
- SET vItem = IFNULL(vItem,0);
-
- SET @p := 0;
- SET @a := 0;
-
- UPDATE itemTag a
- JOIN (
- SELECT
- id,
- @p := IF(itemFk = @a, @p, 0) + 1 as NewPriority,
- @a := itemFk
- FROM itemTag
- WHERE vItem IS NULL
- OR vItem = itemFk
- ORDER BY itemFk, priority
- ) sub ON sub.id = a.id
- SET a.priority = NewPriority;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `itemTagUpdatePriority_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 `itemTagUpdatePriority_launcher`()
-BEGIN
-
- CALL vn.itemTagUpdatePriority(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 `logAdd` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `logAdd`(vOriginFk INT, vActionCode VARCHAR(45), vTypeCode VARCHAR(45), vDescription TEXT)
-BEGIN
-
- DECLARE vTableName VARCHAR(45);
-
- SELECT logTableName INTO vTableName
- FROM vn.logType
- WHERE `code` = vTypeCode;
-
- IF ISNULL(vTableName) THEN
- CALL util.throw('CODE_NOT_FOUND');
- END IF;
-
- SET @qryLog := CONCAT(
- 'INSERT INTO ', vTableName, ' (originFk, userFk, action, description)',
- ' VALUES (', vOriginFk, ', ', account.userGetId(), ', "', vActionCode, '", "', vDescription, '")'
- );
-
- PREPARE stmt FROM @qryLog;
- EXECUTE stmt;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `logShow` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `logShow`(vOriginFk INT, vTypeCode VARCHAR(45))
-BEGIN
-
- DECLARE vTableName VARCHAR(45);
-
- SELECT logTableName INTO vTableName
- FROM vn.logType
- WHERE `code` = vTypeCode;
-
- IF ISNULL(vTableName) THEN
- CALL util.throw('CODE_NOT_FOUND');
- END IF;
-
- SET @qryLog := CONCAT(
- 'SELECT ot.id, ot.originFk, ot.userFk, u.name, ot.action, ot.creationDate, ot.description FROM ', vTableName, ' AS ot',
- ' INNER JOIN account.user u ON u.id = ot.userFk',
- ' WHERE ot.originFk = ', vOriginFk, ' ORDER BY ot.creationDate DESC'
- );
-
- PREPARE stmt FROM @qryLog;
- EXECUTE stmt;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `mergeTicketUnattended` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `mergeTicketUnattended`(IN vMainTicket INT(11), IN hasSameAgency BOOLEAN)
-BEGIN
-
- DECLARE isBilled BOOLEAN;
- DECLARE arrayTickets VARCHAR(255);
-
- SELECT Factura IS NOT NULL INTO isBilled FROM vn2008.Tickets WHERE Id_Ticket = vMainTicket;
-
- IF NOT isBilled THEN
-
- SELECT GROUP_CONCAT(distinct T.Id_Ticket) INTO arrayTickets
- FROM vn2008.Tickets T LEFT JOIN vn.ticketState ts ON T.Id_Ticket = ts.ticket
- JOIN vn2008.Tickets ticketOriginal ON ticketOriginal.Id_Ticket = vMainTicket
- AND T.empresa_id = ticketOriginal.empresa_id
- AND T.Id_Consigna = ticketOriginal.Id_Consigna
- AND DATE(T.Fecha) = DATE(ticketOriginal.Fecha)
- AND T.warehouse_id = ticketOriginal.warehouse_id
- AND IF(hasSameAgency <> 0,T.Id_Agencia = ticketOriginal.Id_Agencia,TRUE)
- LEFT JOIN vn.ticketState tsOriginal ON ticketOriginal.Id_Ticket = tsOriginal.ticket
- WHERE ts.alertLevel < 3
- AND T.Factura IS NULL
- AND T.Anotadoencaja = FALSE
- AND T.Id_Ticket <> vMainTicket
- AND ts.alertLevel = tsOriginal.alertLevel;
-
- CALL mergeTicketWithArray(vMainTicket,arrayTickets);
-
- 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 */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `mergeTicketWithArray` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `mergeTicketWithArray`(IN vMainTicket INT(11), IN arrayTickets VARCHAR(50))
-BEGIN
-
- DECLARE isBilled BOOLEAN;
- DECLARE messageLog VARCHAR(50);
- DECLARE company INT;
- DECLARE messageForSplit VARCHAR(255);
- DECLARE vMainSplit INT;
- DECLARE worker INT(3);
-
- SELECT Factura IS NOT NULL INTO isBilled FROM vn2008.Tickets WHERE Id_Ticket = vMainTicket;
-
- IF NOT isBilled THEN
-
- SELECT Id_Trabajador INTO worker from vn2008.Trabajadores where user_id = account.userGetId();
- IF worker IS NULL THEN
- SET worker = 20;
- END IF;
-
- DROP TEMPORARY TABLE IF EXISTS vn2008.Tickets_to_fusion;
-
-
- CALL hedera.sql_query(sql_printf('
- CREATE TEMPORARY TABLE vn2008.Tickets_to_fusion
- SELECT Id_Ticket, Localizacion
- FROM vn2008.Tickets T
- WHERE Id_Ticket IN (%s);',arrayTickets));
-
- INSERT INTO vn2008.ticket_observation (Id_Ticket,observation_type_id,text)
- SELECT vMainTicket,observation_type_id,CONCAT(' Ticket ', Id_Ticket, ':' , tco.text, '. ')
- FROM vn2008.Tickets_to_fusion tf
- INNER JOIN vn2008.ticket_observation tco USING(Id_Ticket)
- ON DUPLICATE KEY UPDATE `text` = CONCAT(ticket_observation.`text`,CONCAT(' Ticket ', VALUES(Id_Ticket), ':' , VALUES(`text`), '. '));
-
- UPDATE vn2008.Movimientos M
- JOIN vn2008.Tickets_to_fusion USING(Id_Ticket)
- SET M.Id_Ticket = vMainTicket;
-
- UPDATE vn2008.expeditions M
- JOIN vn2008.Tickets_to_fusion t ON t.Id_Ticket = M.ticket_id
- SET M.ticket_id = vMainTicket;
-
- UPDATE vn2008.Tickets
- SET Bultos = (SELECT COUNT(*) FROM vn2008.expeditions WHERE ticket_id = vMainTicket AND EsBulto)
- WHERE Id_Ticket = vMainTicket;
-
- UPDATE vn2008.Tickets
- JOIN vn2008.Tickets_to_fusion USING(Id_Ticket)
- SET Fecha = TIMESTAMPADD(YEAR,-1 * (YEAR(Fecha)-2000), Fecha);
-
- UPDATE vn2008.Tickets_dits ts
- JOIN vn2008.Tickets_to_fusion t USING(Id_Ticket)
- SET ts.Id_Ticket = vMainTicket;
-
- UPDATE vn2008.Tickets
- SET Localizacion = CONCAT(Tickets.Localizacion,' ',IFNULL((SELECT GROUP_CONCAT(Localizacion SEPARATOR ' ') FROM vn2008.Tickets_to_fusion),''))
- WHERE Id_Ticket = vMainTicket;
-
- UPDATE vn2008.Splits s
- RIGHT JOIN vn2008.Tickets_to_fusion t USING(Id_Ticket)
- SET s.Id_Ticket = vMainTicket;
-
- IF (SELECT COUNT(*) FROM vn2008.Splits WHERE Id_Ticket=vMainTicket) > 1 THEN
-
- SELECT Id_Split INTO vMainSplit FROM vn2008.Splits WHERE Id_Ticket = vMainTicket LIMIT 1;
-
- SELECT group_concat(Notas,',') INTO messageForSplit FROM vn2008.Splits WHERE Id_Ticket = vMainTicket;
- UPDATE vn2008.Splits SET Notas = messageForSplit WHERE Id_Split=vMainSplit;
- UPDATE vn2008.Split_lines sl JOIN vn2008.Splits s USING (Id_Split) SET sl.Id_Split=vMainSplit WHERE Id_Ticket=vMainTicket;
- DELETE FROM vn2008.Splits WHERE Id_Ticket=vMainTicket AND Id_Split<>vMainSplit;
- END IF;
-
- SELECT GROUP_CONCAT(Id_Ticket SEPARATOR ',') into messageLog FROM vn2008.Tickets_to_fusion;
- CALL vn2008.Ditacio(vMainTicket,'Fusion','T',worker,messageLog,NULL);
-
- DELETE ts FROM vn2008.Tickets_state ts JOIN vn2008.Tickets_to_fusion t USING(Id_Ticket);
-
- 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 `noticeSend` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `noticeSend`(vCategoryKey VARCHAR(50), vSender INT, vRecipient INT, vBody TEXT)
-BEGIN
- DECLARE vCategoryId INT;
- DECLARE vIsEnabled TINYINT(1);
-
-
- SELECT c.id, c.isEnabled INTO vCategoryId, vIsEnabled FROM vn.noticeCategory c WHERE keyName = vCategoryKey;
-
- IF vn.noticeHasActive(vCategoryKey, vRecipient) AND vIsEnabled THEN
-
- INSERT INTO vn.noticeInbox (noticeCategoryFk, senderFk, recipientFk, body)
- VALUES (vCategoryId, vSender, vRecipient, vBody);
-
- SELECT vSender, vRecipient;
- 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 */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `observationAdd` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `observationAdd`(vOriginFk INT, vTableCode VARCHAR(45), vDescription TEXT)
-BEGIN
-
- DECLARE vTableName VARCHAR(45);
-
- SET vTableName = CONCAT(vTableCode,'Observation');
-
- IF ISNULL(vTableName) THEN
- CALL util.throw('CODE_NOT_FOUND');
- END IF;
-
- SET @qryLog := CONCAT(
- 'INSERT INTO ', vTableName, ' (originFk, userFk, description)',
- ' VALUES (', vOriginFk, ', ', account.userGetId(), ', "', vDescription, '")'
- );
-
- PREPARE stmt FROM @qryLog;
- EXECUTE stmt;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `printTrolleyLabel` */;
-ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `printTrolleyLabel`(vTicket INT, vPrinter INT, vReport INT)
-BEGIN
-
- DECLARE vlabelCount INT DEFAULT 0;
- DECLARE PRIORITY INT DEFAULT 3;
- DECLARE vWorker INT;
- DECLARE vShipmentHour VARCHAR(10);
-
- SELECT getTicketTrolleyLabelCount(vTicket) INTO vLabelCount;
- SELECT getUser() INTO vWorker;
- SELECT CONCAT(getShipmentHour(vTicket),':00') INTO vShipmentHour;
-
- INSERT INTO printingQueue(printer
- , priority
- , report
- , `text`
- , worker
- , text2
- , text3)
- VALUES (vPrinter
- , PRIORITY
- , vReport
- , vTicket
- , vWorker
- , vLabelCount
- , vShipmentHour);
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `refund` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `refund`(IN vMainTicket INT, OUT vNewTicket INT)
-BEGIN
-
- DECLARE vCustomer MEDIUMINT;
- DECLARE vNewDate DATE;
- DECLARE vWarehouse TINYINT;
- DECLARE vCompany MEDIUMINT;
- DECLARE vAddress MEDIUMINT;
- DECLARE vRefundAgencyMode INT DEFAULT 23;
-
- SELECT customer, TIMESTAMPADD(DAY, 1,shipment), warehouse, company, address
- INTO vCustomer, vNewDate, vWarehouse, vCompany, vAddress
- FROM ticket
- WHERE id = vMainTicket;
-
- CALL ticketCreate(vCustomer, vNewDate, vWarehouse, vCompany, vAddress, vRefundAgencyMode,NULL,vNewDate,vNewTicket);
-
- INSERT INTO vn2008.Movimientos(Id_Ticket, Id_Article, Cantidad, Concepte, Preu, Descuento, PrecioFijado)
- SELECT vNewTicket, Id_Article, - Cantidad, Concepte, Preu, Descuento, TRUE FROM vn2008.Movimientos WHERE Id_Ticket = vMainTicket;
- SELECT vNewTicket;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `solunionRiskRequest` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `solunionRiskRequest`()
-BEGIN
-
- DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
- CREATE TEMPORARY TABLE tmp.client_list
- (PRIMARY KEY (Id_Cliente))
- ENGINE = MEMORY
- SELECT * FROM (SELECT cc.client Id_Cliente, ci.grade FROM vn.creditClassification cc
- JOIN vn.creditInsurance ci ON cc.id = ci.creditClassification
- WHERE dateEnd IS NULL
- ORDER BY ci.creationDate DESC) t1 GROUP BY Id_Cliente;
-
- CALL vn2008.risk_vs_client_list(CURDATE());
-
- SELECT
- c.Id_Cliente, c.Cliente, c.Credito credito_vn, c.creditInsurance solunion, cast(r.risk as DECIMAL(10,0)) riesgo_vivo,
- cast(c.creditInsurance - r.risk as decimal(10,0)) margen_vivo,
- f.Consumo consumo_anual, c.Vencimiento, ci.grade
- FROM
- vn2008.Clientes c
- JOIN tmp.risk r ON r.Id_Cliente = c.Id_Cliente
- JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente
- JOIN bi.facturacion_media_anual f ON c.Id_Cliente = f.Id_Cliente
- GROUP BY Id_cliente;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.risk;
- DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `stockBuyed` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `stockBuyed`(vDate DATE)
-BEGIN
- DECLARE vVolume DECIMAL(10,2);
- DECLARE vWarehouse INT DEFAULT 7;
-
- CALL stockTraslation(vDate);
-
- SELECT Volumen INTO vVolume FROM vn2008.Cubos WHERE Id_Cubo = 'cc' LIMIT 1;
-
- INSERT INTO stockBuyed(user, buyed, `date`)
- SELECT tr.user_id, SUM(0.6 * ( amount / c.packing ) * vn2008.cm3(Id_Compra))/vVolume buyed, vDate
- FROM tmp_item i
- JOIN vn2008.Articles a ON a.Id_Article = i.item_id
- JOIN vn2008.Tipos t ON a.tipo_id = t.tipo_id
- JOIN vn2008.reinos r ON r.id = t.reino_id
- JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = t.Id_Trabajador
- JOIN vn2008.t_item_last_buy ilb ON ilb.item_id = Id_Article AND ilb.warehouse_id = vWarehouse
- JOIN vn2008.Compres c ON c.Id_compra = ilb.buy_id
- WHERE r.display <> 0
- GROUP BY tr.Id_Trabajador
- ON DUPLICATE KEY UPDATE buyed = VALUES(buyed);
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `stockBuyedByWorker` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `stockBuyedByWorker`(vDate DATE, vWorker INT)
-BEGIN
-
- DECLARE vVolume DECIMAL(10,2);
- DECLARE vWarehouse INT DEFAULT 7;
- CALL stockTraslation(vDate);
-
- SELECT Volumen INTO vVolume FROM vn2008.Cubos WHERE Id_Cubo = 'cc' LIMIT 1;
-
- SELECT c.Id_Entrada, a.Id_Article, a.Article, c.Cantidad, (0.6 * ( amount / c.packing ) * vn2008.cm3(Id_Compra))/vVolume buyed
- FROM tmp_item i
- JOIN vn2008.Articles a ON a.Id_Article = i.item_id
- JOIN vn2008.Tipos t ON a.tipo_id = t.tipo_id
- JOIN vn2008.reinos r ON r.id = t.reino_id
- JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = t.Id_Trabajador
- JOIN vn2008.t_item_last_buy ilb ON ilb.item_id = a.Id_Article AND ilb.warehouse_id = vWarehouse
- JOIN vn2008.Compres c ON c.Id_compra = ilb.buy_id
- WHERE r.display <> 0 AND tr.user_id = vWorker;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `stockTraslation` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `stockTraslation`(vDate DATE)
-BEGIN
-
-
- DECLARE vWarehouse INT DEFAULT 7;
-
- DELETE FROM stockBuyed WHERE `date` = vDate;
-
- DROP TEMPORARY TABLE IF EXISTS tmp_item;
- CREATE TEMPORARY TABLE tmp_item
- (UNIQUE INDEX i USING HASH (item_id))
- ENGINE = MEMORY
- SELECT item_id, SUM(amount) amount FROM vn2008.item_entry_in
- WHERE dat = vDate
- AND warehouse_id = vWarehouse
- GROUP BY item_id HAVING amount != 0;
-
- CALL `cache`.stock_refresh (FALSE);
-
- INSERT INTO tmp_item (item_id,amount)
- SELECT item_id,s.amount FROM `cache`.stock s
- WHERE warehouse_id = vWarehouse
- ON DUPLICATE KEY UPDATE
- amount = tmp_item.amount + VALUES(amount);
-
- CALL vn2008.item_last_buy_(vWarehouse,vDate);
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `ticketClosure` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketClosure`()
-BEGIN
-
-
- DECLARE vDone BOOL;
- DECLARE vClientFk INT;
- DECLARE vCredit INT;
- DECLARE vPayMethod INT;
- DECLARE vTicketFk INT;
- DECLARE vIsToBeMailed BOOL;
- DECLARE vIsTaxDataChecked BOOL;
- DECLARE vCompanyFk INT;
- DECLARE vDeliveryMethod INT;
- DECLARE vAgencyFk INT;
- DECLARE vAgencyModeFk INT;
- DECLARE vWarehouseFk INT;
- DECLARE vShipped DATE;
- DECLARE vWarehouseVnh INT DEFAULT 7;
- DECLARE vWarehouseFloramondo INT DEFAULT 40;
- DECLARE vCompanyBlk INT DEFAULT 965;
- DECLARE vCompanyCcs INT DEFAULT 69;
- DECLARE vAgencyPackage INT DEFAULT 628;
- DECLARE vPayMethodCard INT DEFAULT 5;
- DECLARE vhasPackage BOOL DEFAULT 0;
- DECLARE vPriority INT DEFAULT 1;
- DECLARE vReportDeliveryNote INT DEFAULT 1;
- DECLARE vReportInvoice INT DEFAULT 3;
- DECLARE vNewPackageTicket INT;
- DECLARE vNewInvoiceId INT;
-
- DECLARE cur CURSOR FOR
- SELECT ticketFk FROM tmp.ticketClosure;
-
-
-
-
-
-
-
- INSERT INTO dailyTaskLog(state) VALUES('ticketClosure START');
-
- OPEN cur;
-
- proc: LOOP
- SET vDone = FALSE;
- SET vNewPackageTicket = 0;
-
- FETCH cur INTO vTicketFk;
-
- IF vDone THEN
- LEAVE proc;
- END IF;
-
-
- INSERT INTO dailyTaskLog(state) VALUES(CONCAT('ticketClosure: ', vTicketFk, ' START'));
- SELECT 1;
- SELECT
- c.id,
- c.credit,
- c.paymentMethodFk,
- c.isToBeMailed,
- c.isTaxDataChecked,
- t.companyFk,
- IFNULL(aw.agencyType, a.deliveryMethod) AS deliveryMethod,
- a.id AS agencyFk,
- t.agencyModeFk,
- t.warehouseFk,
- t.shipped
- INTO vClientFk,
- vCredit,
- vPayMethod,
- vIsToBeMailed,
- vIsTaxDataChecked,
- vCompanyFk,
- vDeliveryMethod,
- vAgencyFk,
- vAgencyModeFk,
- vWarehouseFk,
- vShipped
- FROM ticket t
- INNER JOIN `client` c ON c.id = t.clientFk
- LEFT JOIN agencyMode a ON a.id = t.agencyModeFk
- LEFT JOIN agencyWarehouse aw ON a.id = aw.agencyFk AND t.warehouseFk = aw.warehouseFk
- WHERE t.id = vTicketFk;
- SELECT 2;
-
- CALL mergeTicketUnattended(vTicketFk, TRUE);
- IF vWarehouseFk = vWarehouseVnh OR vWareHouseFk = vWarehouseFloramondo THEN
- SELECT 2.2;
-
- SELECT COUNT(*) INTO vhasPackage
- FROM expedition e
- JOIN package p ON p.itemFk = e.itemFk
- WHERE e.ticketFk = vTicketFk
- AND p.isPackageReturnable
- LIMIT 1;
-
- IF vhasPackage THEN
-
-
- SELECT id INTO vNewPackageTicket
- FROM ticket
- WHERE companyFk = vCompanyCcs
- AND agencyModeFk = vAgencyPackage
- AND clientFk = vClientFk
- AND shipped = CURDATE()
- AND refFk IS NULL
- LIMIT 1;
-
- IF ISNULL(vNewPackageTicket) OR vNewPackageTicket = 0 THEN
- CALL ticketCreate(vClientFk, CURDATE(), vWarehouseFk, vCompanyCcs, '', vAgencyPackage, '', DATE_ADD(CURDATE(), INTERVAL 1 DAY), vNewPackageTicket);
- END IF;
- SELECT 2.3;
-
- INSERT INTO movement (item, ticket, concept, amount, price, priceFixed)
- (SELECT e.itemFk, vNewPackageTicket, i.name, COUNT(*) AS amount, getSpecialPrice(e.itemFk, vClientFk), 1
- FROM expedition e
- JOIN item i ON i.id = e.itemFk
- LEFT JOIN package p ON p.itemFk = i.id
- WHERE e.ticketFk = vTicketFk AND p.isPackageReturnable
- GROUP BY e.itemFk);
-
- END IF;
-
-
- INSERT INTO movement (item, ticket, concept, amount, price, priceFixed)
- (SELECT e.itemFk, vTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.itemFk, vClientFk), 1
- FROM expedition e
- JOIN item i ON i.id = e.itemFk
- LEFT JOIN package p ON p.itemFk = i.id
- WHERE e.ticketFk = vTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0
- GROUP BY e.itemFk);
-
-
- CALL ticketTrackingAdd(vTicketFk, (SELECT vn.getAlert3State(vTicketFk)), 20);
- INSERT INTO printServerQueue(priorityFk, reportFk, param1) VALUES(vPriority, vReportDeliveryNote, vTicketFk);
-
- ELSE
-
- INSERT INTO movement (item, ticket, concept, amount, price, priceFixed)
- (SELECT e.item, vTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.itemFk, vClientFk), 1
- FROM expedition e
- JOIN item i ON i.id = e.itemFk
- WHERE e.ticketFk = vTicketFk
- GROUP BY e.itemFk);
- END IF;
-
- IF(vCredit <= 1 OR vCompanyFk = vCompanyBlk OR vPayMethod = vPayMethodCard) THEN
- SELECT 4;
-
- CALL ticketTrackingAdd(vTicketFk, 'DELIVERED', 20);
-
- IF vIsTaxDataChecked THEN
-
- IF (SELECT clientTaxArea(vClientFk, vCompanyFk)) = 'NATIONAL' THEN
- CALL invoiceMakeByClient(
- vClientFk,
- (SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')),
- vShipped,
- vCompanyFk,
- vNewInvoiceId);
- ELSE
- CALL invoiceMakeByTicket(vTicketFk, (SELECT invoiceSerial(vClientFk, vCompanyFk, 'R')), vNewInvoiceId);
- END IF;
-
-
- END IF;
- ELSE
- SELECT 5;
-
- CALL ticketTrackingAdd(vTicketFk, (SELECT vn.getAlert3State(vTicketFk)), 20);
- INSERT INTO printServerQueue(priorityFk, reportFk, param1) VALUES(vPriority, vReportDeliveryNote, vTicketFk);
- END IF;
-
-
- INSERT INTO dailyTaskLog(state) VALUES(CONCAT('ticketClosure: ', vTicketFk, ' END'));
- END LOOP;
-
- CLOSE cur;
-
- INSERT INTO dailyTaskLog(state) VALUES('ticketClosure 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 `ticketClosureAgencyList` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketClosureAgencyList`(vWarehouseFk INT, vDateTo DATE)
-BEGIN
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure;
-
- CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY (
- SELECT
- t.id AS ticketFk
- FROM expedition e
- INNER JOIN ticket t ON t.id = e.ticketFk
- INNER JOIN tmp.ticketClosureAgencyList al ON al.agencyModeFk = t.agencyModeFk
- LEFT JOIN ticketState ts ON ts.ticketFk = t.id
- WHERE
- ts.alertLevel = 2
- AND t.warehouseFk = vWarehouseFk
- AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo
- AND t.refFk IS NULL
- GROUP BY e.ticketFk);
-
- DROP TEMPORARY TABLE tmp.ticketClosureAgencyList;
-
- CALL ticketClosure();
-
- DROP TEMPORARY TABLE tmp.ticketClosure;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `ticketClosureAgencyListAdd` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketClosureAgencyListAdd`(vAgencyModeFk INT)
-BEGIN
-
- CREATE TEMPORARY TABLE IF NOT EXISTS tmp.ticketClosureAgencyList (
- `agencyModeFk` INT,
- PRIMARY KEY(agencyModeFk)) ENGINE = MEMORY;
-
- INSERT INTO tmp.ticketClosureAgencyList(agencyModeFk) VALUES(vAgencyModeFk);
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `ticketClosureMultiWarehouse` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketClosureMultiWarehouse`(vDateTo DATE)
-BEGIN
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure;
-
- CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY (
- SELECT
- t.id AS ticketFk
- FROM expedition e
- INNER JOIN ticket t ON t.id = e.ticketFk
- INNER JOIN warehouse w ON w.id = t.warehouseFk AND hasComission
- LEFT JOIN ticketState ts ON ts.ticketFk = t.id
- WHERE
- ts.alertLevel = 2
- AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo
- AND t.refFk IS NULL
- GROUP BY e.ticketFk);
-
- CALL ticketClosure();
-
- DROP TEMPORARY TABLE tmp.ticketClosure;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `ticketClosureRoute` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketClosureRoute`(vWarehouseFk INT, vRouteFk INT, vDateTo DATE)
-BEGIN
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure;
-
- CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY (
- SELECT
- t.id AS ticketFk
- FROM expedition e
- INNER JOIN ticket t ON t.id = e.ticketFk
- LEFT JOIN ticketState ts ON ts.ticketFk = t.id
- WHERE
- ts.alertLevel = 2
- AND t.warehouseFk = vWarehouseFk
- AND t.routeFk = vRouteFk
- AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo
- AND t.refFk IS NULL
- GROUP BY e.ticketFk);
-
- CALL ticketClosure();
-
- DROP TEMPORARY TABLE tmp.ticketClosure;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `ticketClosureTicket` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketClosureTicket`(vTicketFk INT)
-BEGIN
-
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure;
-
- CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY (
- SELECT
- t.id AS ticketFk
- FROM expedition e
- INNER JOIN ticket t ON t.id = e.ticketFk
- LEFT JOIN ticketState ts ON ts.ticketFk = t.id
- WHERE
- ts.alertLevel = 2
- AND t.id = vTicketFk
- AND t.refFk IS NULL
- GROUP BY e.ticketFk);
-
- CALL ticketClosure();
-
- DROP TEMPORARY TABLE tmp.ticketClosure;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `ticketClosureWarehouse` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketClosureWarehouse`(vWarehouseFk INT, vDateTo DATE)
-BEGIN
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure;
-
- CREATE TEMPORARY TABLE ticketClosure ENGINE = MEMORY(
- SELECT
- t.id AS ticketFk
- FROM expedition e
- INNER JOIN ticket t ON t.id = e.ticketFk
- LEFT JOIN ticketState ts ON ts.ticketFk = t.id
- WHERE
- ts.alertLevel = 2
- AND t.warehouseFk = vWarehouseFk
- AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo
- AND t.refFk IS NULL
- GROUP BY e.ticketFk);
-
- CALL ticketClosure();
-
- DROP TEMPORARY TABLE tmp.ticketClosure;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `ticketCreate` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketCreate`(
- IN vClientId INT
- , IN vShipped DATE
- , IN vWarehouseId INT
- , IN vCompanyFk INT
- , IN vAddressFk INT
- , IN vAgencyType INT
- , IN vRouteFk INT
- , IN vlanded DATE
- , OUT vNewTicket INT)
-BEGIN
- DECLARE vClientOrnamentales INT DEFAULT 5270;
- DECLARE vCompanyOrn INT DEFAULT 1381;
- DECLARE vProvinceName VARCHAR(255);
-
- SELECT p.name INTO vProvinceName
- FROM vn.client c
- JOIN province p ON p.id = c.province
- WHERE c.id = vClientId;
-
- IF vProvinceName IN ('SANTA CRUZ DE TENERIFE','LAS PALMAS DE GRAN CANARIA') AND vClientId <> vClientOrnamentales THEN
- SET vCompanyFk = vCompanyOrn;
- END IF;
-
- INSERT INTO vn2008.Tickets (
- Id_Cliente,
- Fecha,
- Id_Consigna,
- Id_Agencia,
- Alias,
- warehouse_id,
- Id_Ruta,
- empresa_id,
- landing)
- SELECT
- vClientId,
- vShipped,
- a.id,
- IF(vAgencyType,vAgencyType,a.agencyFk),
- a.nickname,
- vWarehouseId,
- IF(vRouteFk,vRouteFk,NULL),
- vCompanyFk,
- vlanded
- FROM address a
- JOIN agencyMode am ON am.id = a.agencyFk
- WHERE IF(vAddressFk, a.id = vAddressFk, a.defaultAddress != 0)
- AND a.clientFk = vClientId
- LIMIT 1;
-
- SET vNewTicket = LAST_INSERT_ID();
-
- INSERT INTO ticketObservation(ticketFk, observationTypeFk, description)
- SELECT vNewTicket,ao.observationTypeFk, ao.description
- FROM addressObservation ao
- JOIN address a ON a.id =ao.addressFk
- WHERE a.clientFk = vClientId
- AND IF(vAddressFk, a.id = vAddressFk, a.defaultAddress != 0);
-
- CALL logAdd(vNewTicket,'insert','ticket',concat('CREA EL TICKET',' ',vNewTicket));
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `ticketToInvoiceByAddress` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketToInvoiceByAddress`(
- vStarted DATE,
- vEnded DATETIME,
- vAddress INT,
- vCompany INT
- )
-BEGIN
-
- SET vEnded = util.dayEnd(vEnded);
-
- DROP TEMPORARY TABLE IF EXISTS vn.ticketToInvoice;
-
- CREATE TEMPORARY TABLE vn.ticketToInvoice
- SELECT id
- FROM vn.ticket
- WHERE addressFk = vAddress
- AND companyFk = vCompany
- AND shipped BETWEEN vStarted AND vEnded
- AND refFk 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 `ticketToInvoiceByClient` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketToInvoiceByClient`(
- vStarted DATE,
- vEnded DATETIME,
- vClient INT,
- vCompany INT
- )
-BEGIN
-
- SET vEnded = util.dayEnd(vEnded);
-
- DROP TEMPORARY TABLE IF EXISTS vn.ticketToInvoice;
-
- CREATE TEMPORARY TABLE vn.ticketToInvoice
- SELECT id
- FROM vn.ticket
- WHERE clientFk = vClient
- AND companyFk = vCompany
- AND shipped BETWEEN vStarted AND vEnded
- AND refFk 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 `ticketToInvoiceByDate` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketToInvoiceByDate`(
- vStarted DATE,
- vEnded DATETIME,
- vClient INT,
- vCompany INT
- )
-BEGIN
-
- SET vEnded = util.dayEnd(vEnded);
-
- DROP TEMPORARY TABLE IF EXISTS vn.ticketToInvoice;
-
- CREATE TEMPORARY TABLE vn.ticketToInvoice
- SELECT id
- FROM vn.ticket
- WHERE clientFk = vClient
- AND companyFk = vCompany
- AND shipped BETWEEN vStarted AND vEnded
- AND refFk 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 `ticketToInvoiceByRef` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketToInvoiceByRef`(IN vInvoiceRef VARCHAR(15))
-BEGIN
-
-
-
- DECLARE vInvoice INT;
- DECLARE vCountry INT;
- DECLARE vTaxArea VARCHAR(15);
- DECLARE vSpainCountryCode INT DEFAULT 1;
-
- SELECT id
- INTO vInvoice
- FROM vn.invoiceOut
- WHERE ref = vInvoiceRef;
-
- SELECT s.countryFk
- INTO vCountry
- FROM vn.supplier s
- JOIN vn.invoiceOut io ON io.companyFk = s.id
- WHERE io.id = vInvoice;
-
- SELECT IF(
- c.isEqualizated
- AND c.countryFk = vSpainCountryCode
- AND i.taxAreaFk = 'NATIONAL',
- 'EQU',
- i.taxAreaFk
- )
- INTO vTaxArea
- FROM vn.invoiceOutSerial i
- JOIN vn.invoiceOut io ON io.serial = i.code
- JOIN vn.client c ON c.id = io.clientFk
- WHERE io.id = vInvoice;
-
- DROP TEMPORARY TABLE IF EXISTS vn.ticketToInvoice;
-
- CREATE TEMPORARY TABLE vn.ticketToInvoice
- SELECT id
- FROM vn.ticket
- WHERE refFk = vInvoiceRef;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `ticketToInvoiceByTicket` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketToInvoiceByTicket`(vTicket INT)
-BEGIN
-
- DROP TEMPORARY TABLE IF EXISTS vn.ticketToInvoice;
-
- CREATE TEMPORARY TABLE vn.ticketToInvoice
- SELECT id
- FROM vn.ticket
- WHERE id = vTicket
- AND refFk 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 `ticketTrackingAdd` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketTrackingAdd`(vTicketFk INT, vState VARCHAR(25) CHARSET UTF8, vWorkerFk INT)
-BEGIN
-
- INSERT INTO ticketTracking (stateFk, ticketFk, workerFk)
- SELECT s.id, vTicketFk, vWorkerFk FROM state s WHERE s.code = vState;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `workerDisable` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `workerDisable`(vUserId int)
-BEGIN
-
- DELETE FROM account.account
- WHERE user_id = vUserId;
-
- UPDATE account.user
- SET role = 2
- WHERE id = vUserId;
-
- UPDATE `client`
- SET credit = 0
- WHERE id = vUserId;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `workingHours` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `workingHours`(username varchar(255), logon boolean)
-BEGIN
- DECLARE userid int(11);
-
- SELECT vn.getUserId(username) INTO userid;
- SELECT username, userid;
- IF userid IS NOT NULL THEN
- IF (logon) THEN
- CALL vn.workingHoursTimeIn(userid);
- ELSE
- CALL vn.workingHoursTimeOut(userid);
- 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 */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `workingHoursTimeIn` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `workingHoursTimeIn`(vUserId INT(11))
-BEGIN
- INSERT INTO vn.workingHours (timeIn, userId)
- VALUES (NOW(),vUserId);
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `workingHoursTimeOut` */;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `workingHoursTimeOut`(vUserId INT(11))
-BEGIN
- UPDATE vn.workingHours
- SET timeOut = NOW()
- WHERE userId = vUserId
- AND DATE(timeIn) = 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 */ ;
-ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Current Database: `salix`
---
-
-CREATE DATABASE /*!32312 IF NOT EXISTS*/ `salix` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
-
-USE `salix`;
-
---
--- Table structure for table `ACL`
---
-
-DROP TABLE IF EXISTS `ACL`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `ACL` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `model` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
- `property` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
- `accessType` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
- `permission` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
- `principalType` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
- `principalId` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
- PRIMARY KEY (`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 `AccessToken`
---
-
-DROP TABLE IF EXISTS `AccessToken`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `AccessToken` (
- `id` varchar(255) CHARACTER SET utf8 NOT NULL,
- `ttl` int(11) DEFAULT NULL,
- `scopes` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
- `created` datetime DEFAULT NULL,
- `userId` int(11) DEFAULT NULL,
- 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 `Account`
---
-
-DROP TABLE IF EXISTS `Account`;
-/*!50001 DROP VIEW IF EXISTS `Account`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Account` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `password`,
- 1 AS `roleFk`,
- 1 AS `active`,
- 1 AS `email`,
- 1 AS `created`,
- 1 AS `updated`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Accounting`
---
-
-DROP TABLE IF EXISTS `Accounting`;
-/*!50001 DROP VIEW IF EXISTS `Accounting`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Accounting` AS SELECT
- 1 AS `id`,
- 1 AS `bank`,
- 1 AS `account`,
- 1 AS `accountingTypeFk`,
- 1 AS `entityFk`,
- 1 AS `isActive`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Address`
---
-
-DROP TABLE IF EXISTS `Address`;
-/*!50001 DROP VIEW IF EXISTS `Address`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Address` AS SELECT
- 1 AS `id`,
- 1 AS `consignee`,
- 1 AS `street`,
- 1 AS `city`,
- 1 AS `postcode`,
- 1 AS `provinceFk`,
- 1 AS `phone`,
- 1 AS `mobile`,
- 1 AS `isEnabled`,
- 1 AS `isDefaultAddress`,
- 1 AS `clientFk`,
- 1 AS `defaultAgencyFk`,
- 1 AS `longitude`,
- 1 AS `latitude`,
- 1 AS `isEqualizated`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Agency`
---
-
-DROP TABLE IF EXISTS `Agency`;
-/*!50001 DROP VIEW IF EXISTS `Agency`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Agency` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `warehouseFk`,
- 1 AS `isVolumetric`,
- 1 AS `bankFk`,
- 1 AS `warehouseAliasFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `AgencyMode`
---
-
-DROP TABLE IF EXISTS `AgencyMode`;
-/*!50001 DROP VIEW IF EXISTS `AgencyMode`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `AgencyMode` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `description`,
- 1 AS `agencyTypeFk`,
- 1 AS `m3`,
- 1 AS `agencyFk`,
- 1 AS `inflation`,
- 1 AS `sendMailTo`,
- 1 AS `isForTicket`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Bank`
---
-
-DROP TABLE IF EXISTS `Bank`;
-/*!50001 DROP VIEW IF EXISTS `Bank`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Bank` AS SELECT
- 1 AS `id`,
- 1 AS `bank`,
- 1 AS `account`,
- 1 AS `cash`,
- 1 AS `entityFk`,
- 1 AS `isActive`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `City`
---
-
-DROP TABLE IF EXISTS `City`;
-/*!50001 DROP VIEW IF EXISTS `City`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `City` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `provinceFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Client`
---
-
-DROP TABLE IF EXISTS `Client`;
-/*!50001 DROP VIEW IF EXISTS `Client`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Client` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `fi`,
- 1 AS `socialName`,
- 1 AS `contact`,
- 1 AS `street`,
- 1 AS `city`,
- 1 AS `postcode`,
- 1 AS `provinceFk`,
- 1 AS `countryFk`,
- 1 AS `email`,
- 1 AS `phone`,
- 1 AS `mobile`,
- 1 AS `fax`,
- 1 AS `active`,
- 1 AS `discount`,
- 1 AS `credit`,
- 1 AS `creditInsurance`,
- 1 AS `iban`,
- 1 AS `dueDay`,
- 1 AS `equalizationTax`,
- 1 AS `hasToInvoice`,
- 1 AS `isToBeMailed`,
- 1 AS `payMethodFk`,
- 1 AS `salesPersonFk`,
- 1 AS `contactChannelFk`,
- 1 AS `sepaVnl`,
- 1 AS `coreVnl`,
- 1 AS `coreVnh`,
- 1 AS `eypbc`,
- 1 AS `quality`,
- 1 AS `vies`,
- 1 AS `isRelevant`,
- 1 AS `typeFk`,
- 1 AS `accountingAccount`,
- 1 AS `created`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `ClientCredit`
---
-
-DROP TABLE IF EXISTS `ClientCredit`;
-/*!50001 DROP VIEW IF EXISTS `ClientCredit`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ClientCredit` AS SELECT
- 1 AS `id`,
- 1 AS `clientFk`,
- 1 AS `employeeFk`,
- 1 AS `amount`,
- 1 AS `created`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `ClientCreditLimit`
---
-
-DROP TABLE IF EXISTS `ClientCreditLimit`;
-/*!50001 DROP VIEW IF EXISTS `ClientCreditLimit`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ClientCreditLimit` AS SELECT
- 1 AS `id`,
- 1 AS `maxAmount`,
- 1 AS `roleFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `ClientObservation`
---
-
-DROP TABLE IF EXISTS `ClientObservation`;
-/*!50001 DROP VIEW IF EXISTS `ClientObservation`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ClientObservation` AS SELECT
- 1 AS `id`,
- 1 AS `clientFk`,
- 1 AS `employeeFk`,
- 1 AS `text`,
- 1 AS `created`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `ClientType`
---
-
-DROP TABLE IF EXISTS `ClientType`;
-/*!50001 DROP VIEW IF EXISTS `ClientType`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ClientType` AS SELECT
- 1 AS `id`,
- 1 AS `code`,
- 1 AS `type`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `ContactChannel`
---
-
-DROP TABLE IF EXISTS `ContactChannel`;
-/*!50001 DROP VIEW IF EXISTS `ContactChannel`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ContactChannel` AS SELECT
- 1 AS `id`,
- 1 AS `name`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Country`
---
-
-DROP TABLE IF EXISTS `Country`;
-/*!50001 DROP VIEW IF EXISTS `Country`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Country` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `inCee`,
- 1 AS `code`,
- 1 AS `currencyFk`,
- 1 AS `realCountryFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `CreditClassification`
---
-
-DROP TABLE IF EXISTS `CreditClassification`;
-/*!50001 DROP VIEW IF EXISTS `CreditClassification`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `CreditClassification` AS SELECT
- 1 AS `id`,
- 1 AS `clientFk`,
- 1 AS `started`,
- 1 AS `ended`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Employee`
---
-
-DROP TABLE IF EXISTS `Employee`;
-/*!50001 DROP VIEW IF EXISTS `Employee`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Employee` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `surname`,
- 1 AS `userFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `FakeProduction`
---
-
-DROP TABLE IF EXISTS `FakeProduction`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `FakeProduction` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `ticketFk` int(11) NOT NULL DEFAULT '0',
- `clientFk` int(11) NOT NULL DEFAULT '0',
- `client` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `date` date DEFAULT NULL,
- `hour` time DEFAULT NULL,
- `city` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `province` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `provinceFk` smallint(6) unsigned NOT NULL DEFAULT '0',
- `agency` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `agencyFk` smallint(6) NOT NULL,
- `lines` int(1) NOT NULL DEFAULT '0',
- `m3` decimal(5,2) NOT NULL DEFAULT '0.00',
- `problems` int(1) NOT NULL DEFAULT '0',
- `problem` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `stateFk` bigint(4) NOT NULL DEFAULT '0',
- `workerfk` int(11) NOT NULL DEFAULT '0',
- `worker` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `salesPersonFk` int(11) NOT NULL DEFAULT '0',
- `salesPerson` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `state` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `boxes` double DEFAULT NULL,
- `routeFk` int(10) unsigned 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 `Message`
---
-
-DROP TABLE IF EXISTS `Message`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `Message` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `uuid` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `sender` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `recipient` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `message` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `sendDate` datetime DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `MessageInbox`
---
-
-DROP TABLE IF EXISTS `MessageInbox`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `MessageInbox` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `uuid` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `sender` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `recipient` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `finalRecipient` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `message` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
- `sendDate` datetime DEFAULT CURRENT_TIMESTAMP,
- 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 `PayMethod`
---
-
-DROP TABLE IF EXISTS `PayMethod`;
-/*!50001 DROP VIEW IF EXISTS `PayMethod`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `PayMethod` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `graceDays`,
- 1 AS `outstandingDebt`,
- 1 AS `ibanRequired`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Province`
---
-
-DROP TABLE IF EXISTS `Province`;
-/*!50001 DROP VIEW IF EXISTS `Province`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Province` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `countryFk`,
- 1 AS `warehouseFk`,
- 1 AS `zoneFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Role`
---
-
-DROP TABLE IF EXISTS `Role`;
-/*!50001 DROP VIEW IF EXISTS `Role`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Role` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `description`,
- 1 AS `created`,
- 1 AS `modified`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `RoleMapping`
---
-
-DROP TABLE IF EXISTS `RoleMapping`;
-/*!50001 DROP VIEW IF EXISTS `RoleMapping`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `RoleMapping` AS SELECT
- 1 AS `id`,
- 1 AS `principalType`,
- 1 AS `principalId`,
- 1 AS `roleId`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Route`
---
-
-DROP TABLE IF EXISTS `Route`;
-/*!50001 DROP VIEW IF EXISTS `Route`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Route` AS SELECT
- 1 AS `id`,
- 1 AS `date`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `State`
---
-
-DROP TABLE IF EXISTS `State`;
-/*!50001 DROP VIEW IF EXISTS `State`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `State` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `order`,
- 1 AS `alertLevel`,
- 1 AS `code`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Ticket`
---
-
-DROP TABLE IF EXISTS `Ticket`;
-/*!50001 DROP VIEW IF EXISTS `Ticket`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Ticket` AS SELECT
- 1 AS `id`,
- 1 AS `agencyFk`,
- 1 AS `employeeFk`,
- 1 AS `date`,
- 1 AS `hour`,
- 1 AS `clientFk`,
- 1 AS `addressFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `TicketState`
---
-
-DROP TABLE IF EXISTS `TicketState`;
-/*!50001 DROP VIEW IF EXISTS `TicketState`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `TicketState` AS SELECT
- 1 AS `id`,
- 1 AS `ticketFk`,
- 1 AS `stateFk`,
- 1 AS `employeeFk`,
- 1 AS `updated`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Vehicle`
---
-
-DROP TABLE IF EXISTS `Vehicle`;
-/*!50001 DROP VIEW IF EXISTS `Vehicle`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Vehicle` AS SELECT
- 1 AS `id`,
- 1 AS `numberPlate`,
- 1 AS `tradeMark`,
- 1 AS `model`,
- 1 AS `companyFk`,
- 1 AS `warehouseFk`,
- 1 AS `description`,
- 1 AS `m3`,
- 1 AS `isActive`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Warehouse`
---
-
-DROP TABLE IF EXISTS `Warehouse`;
-/*!50001 DROP VIEW IF EXISTS `Warehouse`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Warehouse` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `tpv`,
- 1 AS `inventory`,
- 1 AS `isManaged`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `WarehouseAlias`
---
-
-DROP TABLE IF EXISTS `WarehouseAlias`;
-/*!50001 DROP VIEW IF EXISTS `WarehouseAlias`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `WarehouseAlias` AS SELECT
- 1 AS `id`,
- 1 AS `name`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Worker`
---
-
-DROP TABLE IF EXISTS `Worker`;
-/*!50001 DROP VIEW IF EXISTS `Worker`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Worker` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `surname`,
- 1 AS `userFk`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `Zone`
---
-
-DROP TABLE IF EXISTS `Zone`;
-/*!50001 DROP VIEW IF EXISTS `Zone`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `Zone` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `printingOrder`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `user`
---
-
-DROP TABLE IF EXISTS `user`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `user` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `realm` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
- `username` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
- `password` varchar(512) CHARACTER SET utf8 NOT NULL,
- `email` varchar(512) CHARACTER SET utf8 NOT NULL,
- `emailVerified` tinyint(1) DEFAULT NULL,
- `verificationToken` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Dumping events for database 'salix'
---
-
---
--- Dumping routines for database 'salix'
---
-/*!50003 DROP PROCEDURE IF EXISTS `production_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 `production_control_source`(IN idWarehouse INT, IN scopeDays TINYINT)
-BEGIN
-
- call vn2008.production_control_source(idWarehouse, scopeDays);
-
-
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-
---
--- Current Database: `bs`
---
-
-CREATE DATABASE /*!32312 IF NOT EXISTS*/ `bs` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
-
-USE `bs`;
-
---
--- Temporary view structure for view `VentasPorCliente`
---
-
-DROP TABLE IF EXISTS `VentasPorCliente`;
-/*!50001 DROP VIEW IF EXISTS `VentasPorCliente`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `VentasPorCliente` AS SELECT
- 1 AS `Id_Cliente`,
- 1 AS `VentaBasica`,
- 1 AS `year`,
- 1 AS `month`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `bancos_evolution`
---
-
-DROP TABLE IF EXISTS `bancos_evolution`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `bancos_evolution` (
- `Fecha` date NOT NULL,
- `Id_Banco` int(11) NOT NULL,
- `saldo` double NOT NULL DEFAULT '0',
- `quilla` double NOT NULL DEFAULT '0',
- `deuda` double NOT NULL DEFAULT '0',
- `liquidez` double NOT NULL DEFAULT '0',
- `disponibilidad ajena` double NOT NULL DEFAULT '0',
- `saldo_aux` double NOT NULL DEFAULT '0' COMMENT 'Saldo auxiliar para el calculo de lo dispuesto en las polizas',
- PRIMARY KEY (`Fecha`,`Id_Banco`),
- KEY `fk_banco_evolution_idx` (`Id_Banco`),
- CONSTRAINT `fk_banco_evolution` FOREIGN KEY (`Id_Banco`) REFERENCES `vn2008`.`Bancos` (`Id_Banco`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los saldos bancarios';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `carteras`
---
-
-DROP TABLE IF EXISTS `carteras`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `carteras` (
- `CodigoTrabajador` varchar(3) CHARACTER SET latin1 NOT NULL,
- `Año` int(11) NOT NULL,
- `Mes` int(11) NOT NULL,
- `Peso` decimal(10,2) DEFAULT NULL,
- PRIMARY KEY (`CodigoTrabajador`,`Año`,`Mes`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `compradores`
---
-
-DROP TABLE IF EXISTS `compradores`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `compradores` (
- `Id_Trabajador` int(11) NOT NULL,
- `año` int(4) NOT NULL,
- `semana` int(2) NOT NULL,
- `importe` decimal(10,2) DEFAULT NULL,
- `comision` decimal(10,2) DEFAULT NULL,
- PRIMARY KEY (`Id_Trabajador`,`año`,`semana`),
- CONSTRAINT `comprador_trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) 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 `compradores_evolution`
---
-
-DROP TABLE IF EXISTS `compradores_evolution`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `compradores_evolution` (
- `Id_Trabajador` int(11) NOT NULL,
- `fecha` date NOT NULL,
- `importe` decimal(10,2) DEFAULT NULL,
- PRIMARY KEY (`Id_Trabajador`,`fecha`),
- CONSTRAINT `evo_trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) 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 `experienceIberflora2016`
---
-
-DROP TABLE IF EXISTS `experienceIberflora2016`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `experienceIberflora2016` (
- `Id_Cliente` int(11) NOT NULL,
- `isVisitor` tinyint(4) NOT NULL DEFAULT '0',
- PRIMARY KEY (`Id_Cliente`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de clientes que participan en el estudio sobre la mejora del consumo tras la visita a las instalaciones de Silla';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `fondo_maniobra`
---
-
-DROP TABLE IF EXISTS `fondo_maniobra`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `fondo_maniobra` (
- `fecha` date NOT NULL,
- `fondo` double DEFAULT NULL,
- `clientes_facturas` double DEFAULT NULL,
- `clientes_cobros` double DEFAULT NULL,
- `proveedores_facturas` double DEFAULT NULL,
- `proveedores_pagos` double DEFAULT NULL,
- `fondo_medio` double DEFAULT NULL,
- PRIMARY KEY (`fecha`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `manaCustomer`
---
-
-DROP TABLE IF EXISTS `manaCustomer`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `manaCustomer` (
- `Id_Cliente` int(11) NOT NULL,
- `Mana` decimal(10,0) NOT NULL DEFAULT '0',
- `dated` date NOT NULL,
- PRIMARY KEY (`Id_Cliente`,`dated`),
- CONSTRAINT `cliente_fk` FOREIGN KEY (`Id_Cliente`) REFERENCES `vn2008`.`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 `mana_spellers`
---
-
-DROP TABLE IF EXISTS `mana_spellers`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `mana_spellers` (
- `Id_Trabajador` int(11) NOT NULL,
- `size` int(11) NOT NULL DEFAULT '300',
- `used` int(11) NOT NULL DEFAULT '0',
- `prices_modifier_rate` double NOT NULL DEFAULT '0',
- `prices_modifier_activated` tinyint(1) NOT NULL DEFAULT '1',
- PRIMARY KEY (`Id_Trabajador`),
- KEY `fk_mana_spellers_Trabajadores_idx` (`Id_Trabajador`),
- CONSTRAINT `fk_mana_spellers_Trabajadores` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `bs`.`mana_spellers_AFTER_INSERT` AFTER INSERT ON `mana_spellers` FOR EACH ROW
-BEGIN
-
-
- REPLACE vn2008.Permisos(Id_Grupo, Id_Trabajador)
- VALUES(6, NEW.Id_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 */ ;
-ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Table structure for table `nightTask`
---
-
-DROP TABLE IF EXISTS `nightTask`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `nightTask` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `started` datetime DEFAULT NULL,
- `finished` datetime DEFAULT NULL,
- `order` int(11) DEFAULT NULL,
- `schema` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
- `procedure` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`)
-) 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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `bs`.`nightTaskBeforeInsert` BEFORE INSERT ON `nightTask` FOR EACH ROW
-BEGIN
-
- IF NOT (NEW.`schema`REGEXP '^[0-9a-zA-Z_]+$') OR NOT (NEW.`procedure`REGEXP '^[0-9a-zA-Z_]+$') THEN
-
- CALL util.throw('ONLY_ALPHANUMERICS_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 */ ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `bs`.`nightTaskBeforeUpdate` BEFORE UPDATE ON `nightTask` FOR EACH ROW
-BEGIN
-
- IF NOT (NEW.`schema`REGEXP '^[0-9a-zA-Z_]+$') OR NOT (NEW.`procedure`REGEXP '^[0-9a-zA-Z_]+$') THEN
-
- CALL util.throw('ONLY_ALPHANUMERICS_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 */ ;
-
---
--- Temporary view structure for view `v_ventas`
---
-
-DROP TABLE IF EXISTS `v_ventas`;
-/*!50001 DROP VIEW IF EXISTS `v_ventas`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `v_ventas` AS SELECT
- 1 AS `importe`,
- 1 AS `recargo`,
- 1 AS `year`,
- 1 AS `month`,
- 1 AS `week`,
- 1 AS `day`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `vendedores`
---
-
-DROP TABLE IF EXISTS `vendedores`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `vendedores` (
- `Id_Trabajador` int(11) NOT NULL,
- `año` int(4) NOT NULL,
- `mes` int(2) NOT NULL,
- `importe` decimal(10,2) DEFAULT NULL,
- `comision` decimal(10,2) DEFAULT NULL,
- `comisionArrendada` decimal(10,2) DEFAULT NULL COMMENT 'comision proveniente de clientes que han sido donados. Ver tabla Clientes_cedidos',
- `comisionCedida` decimal(10,2) DEFAULT NULL COMMENT 'comision generada por los clientes que han sido donados. Ver tabla Clientes_cedidos',
- PRIMARY KEY (`Id_Trabajador`,`año`,`mes`),
- CONSTRAINT `trabajador_trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) 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 `vendedores_evolution`
---
-
-DROP TABLE IF EXISTS `vendedores_evolution`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `vendedores_evolution` (
- `Id_Trabajador` int(11) NOT NULL,
- `fecha` date NOT NULL,
- `importe` decimal(10,2) DEFAULT NULL,
- PRIMARY KEY (`Id_Trabajador`,`fecha`),
- CONSTRAINT `evo_vendedor_trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) 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 `ventas`
---
-
-DROP TABLE IF EXISTS `ventas`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `ventas` (
- `Id_Movimiento` int(11) NOT NULL,
- `importe` decimal(10,3) NOT NULL DEFAULT '0.000',
- `recargo` decimal(10,3) NOT NULL DEFAULT '0.000',
- `fecha` date NOT NULL,
- `tipo_id` smallint(5) unsigned NOT NULL,
- `Id_Cliente` int(11) NOT NULL DEFAULT '1',
- `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442',
- PRIMARY KEY (`Id_Movimiento`),
- KEY `tip_to_tip_idx` (`tipo_id`),
- KEY `clientes_bs_ventas_idx` (`Id_Cliente`),
- KEY `empresa_bs_ventas_idx` (`empresa_id`),
- KEY `fecha_bs` (`fecha`),
- CONSTRAINT `clientes_bs_ventas` FOREIGN KEY (`Id_Cliente`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `empresa_bs_ventas` FOREIGN KEY (`empresa_id`) REFERENCES `vn2008`.`empresa` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `mov_to_mov` FOREIGN KEY (`Id_Movimiento`) REFERENCES `vn2008`.`Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `tip_to_tip` FOREIGN KEY (`tipo_id`) REFERENCES `vn2008`.`Tipos` (`tipo_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 `ventas_contables`
---
-
-DROP TABLE IF EXISTS `ventas_contables`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `ventas_contables` (
- `year` int(4) NOT NULL,
- `month` int(2) NOT NULL,
- `venta` decimal(10,2) DEFAULT NULL,
- `grupo` int(1) NOT NULL,
- `reino_id` int(10) unsigned NOT NULL,
- `tipo_id` smallint(5) unsigned NOT NULL,
- `empresa_id` int(4) NOT NULL,
- `gasto` varchar(10) CHARACTER SET latin1 NOT NULL,
- PRIMARY KEY (`year`,`month`,`grupo`,`reino_id`,`tipo_id`,`empresa_id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Dumping events for database 'bs'
---
-
---
--- Dumping routines for database 'bs'
---
-/*!50003 DROP PROCEDURE IF EXISTS `bancos_evolution_add` */;
-ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `bancos_evolution_add`()
-BEGIN
-
-
-
-DECLARE vCurrentDate DATE;
-DECLARE vStartingDate DATE DEFAULT '2015-01-01';
-DECLARE vMaxDate DATE DEFAULT TIMESTAMPADD(MONTH, 2, CURDATE());
-
-SELECT max(Fecha)
- INTO vStartingDate
- FROM bs.bancos_evolution
- WHERE Fecha > '2015-01-01';
-
-DELETE FROM bs.bancos_evolution
-WHERE Fecha > vStartingDate;
-
-SET vCurrentDate = vStartingDate;
-
-
-
-
- WHILE vCurrentDate < vMaxDate DO
-
- IF day(vCurrentDate) mod 28 = 0 then
- SELECT vCurrentDate;
- end if;
-
-
- REPLACE bs.bancos_evolution( Fecha
- ,Id_Banco
- ,saldo)
-
- SELECT vCurrentDate
- , Id_Banco
- , sum(saldo)
-
- FROM
- (
-
- SELECT Id_Banco
- ,saldo_aux as saldo
- FROM bs.bancos_evolution
-
- WHERE Fecha = TIMESTAMPADD(DAY,-1,vCurrentDate)
-
- UNION ALL
-
- SELECT c.Id_Banco, IFNULL(sum(Entrada),0) - ifnull(sum(Salida),0) as saldo
- FROM vn2008.Cajas c
- JOIN vn2008.Bancos b using(Id_Banco)
- WHERE cash IN (0,3)
- AND Cajafecha = vCurrentDate
- AND (Serie = 'MB' OR cash = 3)
- GROUP BY Id_Banco
-
- UNION ALL
-
- SELECT id_banco, - importe
- FROM vn2008.pago
- WHERE fecha = vCurrentDate
- AND fecha >= CURDATE()
- AND NOT conciliado
-
- UNION ALL
-
- SELECT Id_Banco, Entregado
- FROM vn2008.Recibos
- WHERE Fechacobro = vCurrentDate
- AND Fechacobro > CURDATE()
-
- UNION ALL
-
- SELECT sp.Id_Banco, Importe
- FROM vn2008.Saldos_Prevision sp
- JOIN vn2008.Bancos b using(Id_Banco)
- WHERE cash IN (0,3)
- AND Fecha = vCurrentDate
-
-
-
- )sub
- GROUP BY Id_Banco;
-
-
-
- UPDATE bs.bancos_evolution be
- SET saldo_aux = saldo;
-
-
- UPDATE bs.bancos_evolution be
- LEFT JOIN
- (
- SELECT Id_Banco, - sum(importe) as quilla
- FROM vn2008.Bancos_poliza
- WHERE vCurrentDate between apertura AND IFNULL(cierre, vCurrentDate)
- GROUP BY Id_Banco
- ) sub using(Id_Banco)
- SET be.quilla = sub.quilla
- WHERE be.Fecha = vCurrentDate;
-
-
- SET vCurrentDate = TIMESTAMPADD(DAY,1,vCurrentDate);
-
- END WHILE;
-
-
-
- UPDATE bs.bancos_evolution be
- JOIN vn2008.Bancos using(Id_Banco)
- SET be.deuda = IF(cash = 3, be.saldo_aux, 0)
- , be.saldo = IF(cash = 3, 0, be.saldo_aux)
- WHERE Fecha >= vStartingDate;
-
-
-
- update bs.bancos_evolution set liquidez = saldo - quilla + deuda WHERE Fecha >= vStartingDate;
-
-
- update bs.bancos_evolution set `disponibilidad ajena` = - quilla + deuda WHERE Fecha >= vStartingDate;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `campaignComparative` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `campaignComparative`(vDateFrom DATE, vDateTo DATE)
-BEGIN
- SELECT
- workerName,
- id,
- name,
- CAST(SUM(previousAmmount) AS DECIMAL(10, 0)) AS previousAmmount,
- CAST(SUM(currentAmmount) AS DECIMAL(10, 0)) AS currentAmmount
- FROM (
- (SELECT
- CONCAT(w.firstname, ' ', w.name) AS workerName,
- c.id,
- c.name,
- SUM(v.importe) AS previousAmmount,
- 0 currentAmmount
- FROM bs.ventas v
- INNER JOIN vn.`client` c ON v.Id_Cliente = c.id
- INNER JOIN vn.worker w ON c.workerFk = w.id
- WHERE v.fecha BETWEEN DATE_ADD(vDateFrom, INTERVAL - 1 YEAR)
- AND DATE_ADD(vDateTo, INTERVAL - 1 YEAR)
- GROUP BY w.id, v.Id_Cliente)
- UNION ALL
- (SELECT
- CONCAT(w.firstname, ' ', w.name) AS workerName,
- c.id,
- c.name,
- 0 AS previousAmmount,
- SUM(s.quantity * s.price) AS currentAmmount
- FROM vn.sale s
- JOIN vn.ticket t ON t.id = s.ticketFk
- JOIN vn.client c ON c.id = t.clientFk
- JOIN vn.worker w ON c.workerFk = w.id
- WHERE t.shipped BETWEEN vDateFrom
- AND vDateTo
- GROUP BY w.id, c.id)
- ) comparative
- GROUP BY workerName, id
- HAVING (previousAmmount <> 0 OR currentAmmount <> 0)
- ORDER BY workerName, 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 `carteras_add` */;
-ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `carteras_add`()
-BEGIN
-
-DELETE FROM bs.carteras
-WHERE Año >= YEAR(CURDATE()) - 1;
-
-INSERT INTO bs.carteras(Año,Mes,CodigoTrabajador,Peso)
-SELECT year as Año, month as Mes, CodigoTrabajador, sum(importe) as Peso
-FROM vn2008.time t
-JOIN bs.ventas v on t.date = v.fecha
-JOIN vn2008.Clientes c on c.Id_Cliente = v.Id_Cliente
-JOIN vn2008.Trabajadores tr on tr.Id_Trabajador = c.Id_Trabajador
-WHERE t.year >= YEAR(CURDATE()) - 1
-GROUP BY CodigoTrabajador, Año, Mes;
-
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `comercialesCompleto` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `comercialesCompleto`(IN vWorker INT)
-BEGIN
-
-SELECT
- c.Id_Cliente id_cliente,
- c.calidad,
- c.Cliente cliente,
- cr.recobro * 100 tarifa,
- c.Telefono telefono,
- c.movil,
- c.POBLACION poblacion,
- p.`name` provincia,
- vn2008.red(f.futur) futur,
- c.Credito credito,
- pm.`name` forma_pago,
- vn2008.red(c365 / 12) consumo_medio365,
- vn2008.red(c365) consumo365,
- vn2008.red(CmLy.peso) peso_mes_año_pasado,
- vn2008.red(CmLy.peso * 1.19) objetivo,
- tr.CodigoTrabajador,
- vn2008.red(mes_actual.consumo) consumoMes,
- vn2008.red(IFNULL(mes_actual.consumo, 0) - IFNULL(CmLy.peso * 1.19, 0)) como_lo_llevo,
- DATE(LastTicket) ultimo_ticket,
- dead.muerto,
- g.Greuge,
- cr.recobro
-FROM
- vn2008.Clientes c
- LEFT JOIN
- (SELECT Id_Cliente, Greuge
- FROM bi.Greuge_Evolution
- WHERE Fecha = (SELECT MAX(Fecha) FROM bi.Greuge_Evolution)
- ) g ON g.Id_Cliente = c.Id_Cliente
- LEFT JOIN
- vn2008.province p ON p.province_id = c.province_id
- JOIN
- vn2008.pay_met pm ON pm.id = c.pay_met_id
- LEFT JOIN
- vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
- LEFT JOIN
- bi.claims_ratio cr on cr.Id_Cliente = c.Id_Cliente
- LEFT JOIN
- (SELECT
- v.Id_Cliente, SUM(importe) c365
- FROM
- bs.ventas v
- INNER JOIN vn2008.Clientes c USING (Id_Cliente)
- LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
- WHERE
- (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
- AND v.fecha BETWEEN TIMESTAMPADD(YEAR, - 1, CURDATE()) AND CURDATE()
- GROUP BY v.Id_Cliente) c365 ON c365.Id_Cliente = c.Id_Cliente
- LEFT JOIN
- (SELECT
- Id_Cliente, SUM(importe) consumo
- FROM
- bs.ventas v
- INNER JOIN vn2008.Clientes c USING (Id_Cliente)
- LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
- WHERE
- (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
- AND (v.fecha BETWEEN TIMESTAMPADD(DAY, - DAY(CURDATE()) + 1, CURDATE()) AND CURDATE() - 1)
- GROUP BY Id_Cliente) mes_actual ON mes_actual.Id_Cliente = c.Id_Cliente
- LEFT JOIN
- (SELECT
- t.Id_Cliente,
- SUM(m.preu * m.Cantidad * (1 - m.Descuento / 100)) futur
- FROM
- vn2008.Tickets t
- JOIN vn2008.Clientes c ON c.Id_Cliente = t.Id_Cliente
- JOIN vn2008.Movimientos m ON m.Id_Ticket = t.Id_Ticket
- LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
- WHERE
- (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
- AND DATE(Fecha) BETWEEN CURDATE() AND LAST_DAY(CURDATE())
- GROUP BY Id_Cliente) f ON c.Id_Cliente = f.Id_Cliente
- LEFT JOIN
- (SELECT
- MAX(t.Fecha) LastTicket, c.Id_Cliente
- FROM
- vn2008.Tickets t
- JOIN vn2008.Clientes c ON c.Id_cliente = t.Id_Cliente
- LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
-
- WHERE
- (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
- GROUP BY t.Id_Cliente) LastTicket ON LastTicket.Id_Cliente = c.Id_Cliente
- LEFT JOIN
- (SELECT
- SUM(importe) peso, c.Id_Cliente
- FROM
- bs.ventas v
- JOIN vn2008.Clientes c ON c.Id_Cliente = v.Id_Cliente
- LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
- WHERE
- MONTH(fecha) = MONTH(CURDATE())
- AND YEAR(fecha) = YEAR(CURDATE()) - 1
- AND (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
- GROUP BY c.Id_Cliente) CmLy ON CmLy.Id_Cliente = c.Id_Cliente
- LEFT JOIN
- (SELECT
- c.Id_Cliente,
- IF(MAX(Fecha) < DATE_FORMAT(TIMESTAMPADD(MONTH, - 1, CURDATE()), '%Y- %m-01'), TRUE, FALSE) muerto
- FROM
- vn2008.Facturas f
- JOIN vn2008.Clientes c ON c.Id_cliente = f.Id_Cliente
- LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
- WHERE
- (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
- GROUP BY Id_Cliente) dead ON dead.Id_Cliente = c.Id_Cliente
-WHERE
- (c.Id_Trabajador = vWorker OR tr.boss = vWorker);
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `compradores_add` */;
-ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `compradores_add`(IN intYEAR INT, IN intWEEK_START INT, IN intWEEK_END INT)
-BEGIN
-
-REPLACE bs.compradores
-
-SELECT tp.Id_Trabajador
- , intYEAR as año
- , tm.week as semana
- , sum(importe) as importe
- , 0 as comision
-
-FROM bs.ventas v
-JOIN vn2008.time tm on tm.date = v.fecha
-JOIN vn2008.Tipos tp using(tipo_id)
-WHERE tm.year = intYEAR and tm.week between intWEEK_START and intWEEK_END
-AND reino_id != 6
-GROUP BY tp.Id_Trabajador, tm.week;
-
-
-
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `compradores_evolution_add` */;
-ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `compradores_evolution_add`()
-BEGIN
-
-
-DECLARE datFEC DATE;
-
-
-SELECT TIMESTAMPADD(DAY,1,MAX(fecha)) INTO datFEC FROM bs.compradores_evolution;
-
- WHILE datFEC < CURDATE() DO
-
- SELECT datFEC;
-
- REPLACE bs.compradores_evolution( Id_Trabajador
- , fecha
- , importe)
-
- SELECT Id_Trabajador
- , datFEC as fecha
- , sum(importe) as importe
-
- FROM
- (
-
- SELECT Id_Trabajador
- , importe
- FROM bs.compradores_evolution
- WHERE fecha = TIMESTAMPADD(DAY,-1,datFEC)
-
- UNION ALL
-
- SELECT Id_Trabajador
- , importe * IF(v.fecha < datFEC,-1,1)
- FROM bs.ventas v
- JOIN vn2008.Tipos tp using(tipo_id)
- WHERE fecha IN (datFEC, TIMESTAMPADD(DAY,-365,datFEC))
- AND reino_id != 6
-
- )sub
- GROUP BY Id_Trabajador;
-
-
-
-
- SET datFEC = TIMESTAMPADD(DAY,1,datFEC);
-
- 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 */ ;
-ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `fondo_evolution_add` */;
-ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `fondo_evolution_add`()
-BEGIN
-
-
-DECLARE datFEC DATE DEFAULT '2015-01-01';
-
-
-SELECT TIMESTAMPADD(DAY,1,MAX(fecha)) INTO datFEC FROM bs.fondo_maniobra;
-
- WHILE datFEC < CURDATE() DO
-
-
-
- IF day(datFEC) mod 28 = 0 then
- SELECT datFEC;
- end if;
-
-
- REPLACE bs.fondo_maniobra(Fecha, clientes_facturas, clientes_cobros,proveedores_facturas,proveedores_pagos, fondo)
- SELECT datFEC as Fecha, Facturas, Cobros,Recibidas,Pagos, Facturas + Cobros + Recibidas + Pagos
- FROM
- (
- SELECT Sum(Facturas.Importe) AS Facturas
- FROM vn2008.Facturas
- INNER JOIN vn2008.Clientes ON Facturas.Id_Cliente = Clientes.Id_cliente
- WHERE Clientes.`real`
- AND empresa_id <>1381
- AND Fecha between '2011-01-01' and datFEC) fac
- JOIN
- (
- SELECT - Sum(Entregado) AS Cobros
- FROM vn2008.Recibos
- INNER JOIN vn2008.Clientes ON Recibos.Id_Cliente = Clientes.Id_cliente
- WHERE Clientes.`real`
- AND empresa_id <> 1381
- AND Fechacobro Between '2011-01-01' and datFEC) cob
- JOIN
- (
- SELECT - Sum(cantidad) AS Recibidas
- FROM vn2008.recibida
- INNER JOIN vn2008.recibida_vencimiento ON recibida.id = recibida_vencimiento.recibida_id
- WHERE empresa_id <> 1381
- AND recibida.fecha Between '2015-01-01' and datFEC) rec
- JOIN
- (
- SELECT Sum(importe) AS Pagos
- FROM vn2008.pago
- WHERE empresa_id <>1381 AND pago.fecha Between '2015-01-01' and datFEC) pag;
-
-
-
- UPDATE bs.fondo_maniobra
- JOIN
- (SELECT avg(fondo) as media
- FROM bs.fondo_maniobra
- WHERE fecha <= datFEC) sub
- SET fondo_medio = media
- WHERE fecha = datFEC;
-
-
- SET datFEC = TIMESTAMPADD(DAY,1,datFEC);
-
- 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 */ ;
-ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `manaCustomerFill_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 `manaCustomerFill_kk`()
-BEGIN
-
-
-
-
-DECLARE vFromDated DATE;
-DECLARE vToDated DATETIME DEFAULT '2015-12-31 23:59:59';
-DECLARE isDone BOOLEAN DEFAULT FALSE;
-
-DELETE FROM bs.manaCustomer;
-
-WHILE NOT isDone DO
-
- SELECT TIMESTAMPADD(DAY,1,vToDated), TIMESTAMPADD(MONTH, 1, vToDated)
- INTO vFromDated, vToDated;
-
- IF vToDated >= CURDATE() THEN
-
- SET vToDated = TIMESTAMPADD(SECOND,-1,CURDATE());
- SET isDone = TRUE;
-
- END IF;
-
- INSERT INTO bs.manaCustomer(Id_Cliente, Mana)
- SELECT Id_Cliente, newMana
- FROM
- (SELECT cs.Id_Cliente, - sum(Cantidad * Valor) as newMana
- FROM vn2008.Tickets t
- JOIN vn2008.Consignatarios cs using(Id_Consigna)
- JOIN vn2008.Movimientos m using(Id_Ticket)
- JOIN vn2008.Movimientos_componentes mc using(Id_Movimiento)
- WHERE Id_Componente IN (39, 37)
- AND Fecha BETWEEN vFromDated AND vToDated
- GROUP BY cs.Id_Cliente
- ) t1
- ON DUPLICATE KEY UPDATE Mana = Mana + newMana;
-
- SELECT vFromDated, vToDated;
-
-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 `manaCustomerUpdate` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `manaCustomerUpdate`()
-BEGIN
-DECLARE vToDated DATE;
- DECLARE vFromDated DATE;
- DECLARE vForDeleteDated DATE;
- DECLARE vManaId INT DEFAULT 37;
- DECLARE vManaAutoId INT DEFAULT 39;
- DECLARE vManaBankId INT DEFAULT 66;
- DECLARE vManaGreugeTypeId INT DEFAULT 3;
-
- SELECT IFNULL(max(dated), '2016-01-01')
- INTO vFromDated
- FROM bs.manaCustomer;
-
- WHILE timestampadd(week,1,vFromDated) < CURDATE() DO
-
- SELECT
- timestampadd(week,1,vFromDated),
- timestampadd(week,-4,vFromDated)
- INTO
- vToDated,
- vForDeleteDated;
-
- DELETE FROM bs.manaCustomer
- WHERE dated <= vForDeleteDated;
-
-
- INSERT INTO bs.manaCustomer(Id_Cliente, Mana, dated)
-
- SELECT
- Id_Cliente,
- cast(sum(mana) as decimal(10,2)) as mana,
- vToDated as dated
- FROM
-
- (
- SELECT cs.Id_Cliente, Cantidad * Valor as mana
- FROM vn2008.Tickets t
- JOIN vn2008.Consignatarios cs using(Id_Consigna)
- JOIN vn2008.Movimientos m on m.Id_Ticket = t.Id_Ticket
- JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento
- WHERE Id_Componente IN (vManaAutoId, vManaId)
- AND Fecha > vFromDated
- AND Fecha <= vToDated
-
-
- UNION ALL
-
- SELECT r.Id_Cliente, - Entregado
- FROM vn2008.Recibos r
- WHERE Id_Banco = vManaBankId
- AND Fechacobro > vFromDated
- AND Fechacobro <= vToDated
-
- UNION ALL
-
- SELECT g.Id_Cliente, g.Importe
- FROM vn2008.Greuges g
- WHERE Greuges_type_id = vManaGreugeTypeId
- AND Fecha > vFromDated
- AND Fecha <= vToDated
-
- UNION ALL
-
- SELECT Id_Cliente, mana
- FROM bs.manaCustomer
- WHERE dated = vFromDated
- ) sub
-
- GROUP BY Id_Cliente
- HAVING Id_Cliente;
-
- SET vFromDated = vToDated;
-
- 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 `mana_price_modifier_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 `mana_price_modifier_update`()
-BEGIN
-
-INSERT INTO vn2008.daily_task_log(consulta)
-VALUES ('bs.mana_price_modifier_update');
-
-UPDATE mana_spellers
-JOIN
- (SELECT Id_Trabajador, floor(sum(importe)/12) as pesoCarteraMensual
- FROM bs.vendedores v
- WHERE año * 100 + mes >= (year(curdate()) -1) * 100 + month(curdate())
- GROUP BY Id_Trabajador
- ) ultimo_año_de_ventas using(Id_Trabajador)
-SET prices_modifier_rate = GREATEST(-0.05,LEAST(0.05,round(- used/pesoCarteraMensual,3))) ;
-
-
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `nightly_tasks` */;
-ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `nightly_tasks`()
-BEGIN
-
-DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN
- INSERT INTO vn2008.mail SET `to` = 'informatica@verdnatura.es', subject = 'bs.nightly_tasks', `text` = CONCAT('ERROR ', @errno, ' (', @sqlstate, '): ', @text);
- INSERT INTO vn2008.mail SET `to` = 'pako@verdnatura.es', subject = 'bs.nightly_tasks', `text` = CONCAT('ERROR ', @errno, ' (', @sqlstate, '): ', @text);
-END;
-
- insert into vn2008.daily_task_log(consulta) VALUES('arranca el event bs.nightly_tasks');
-
- call bancos_evolution_add;
-
- call fondo_evolution_add;
-
- call ventas_add(timestampadd(month,-1,curdate()),curdate());
-
- call ventas_contables_add(YEAR(TIMESTAMPADD(MONTH,-1,CURDATE())), MONTH(TIMESTAMPADD(MONTH,-1,CURDATE())));
-
- call bs.vendedores_add(year(curdate()), month(curdate()));
-
- call bs.vendedores_add(year(timestampadd(month,-1,curdate()))
- , month(timestampadd(month,-1,curdate()))
- );
-
- call carteras_add;
-
- call vn2008.mana_inventory_requery;
-
- call bs.mana_price_modifier_update;
-
- call bs.manaCustomerUpdate;
-
- insert into vn2008.daily_task_log(consulta) VALUES('finalitza el event bs.nightly_tasks');
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `nightTaskLauncher` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `nightTaskLauncher`()
-BEGIN
-
- DECLARE done BOOL DEFAULT FALSE;
- DECLARE vSchema VARCHAR(255);
- DECLARE vProcedure VARCHAR(255);
- DECLARE vId INT;
-
- DECLARE rs CURSOR FOR
- SELECT id,`schema`, `procedure`
- FROM bs.nightTask
- WHERE IFNULL(finished,0) <= CURDATE()
- ORDER BY `order`;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-
- OPEN rs;
-
- FETCH rs INTO vId, vSchema, vProcedure;
-
- WHILE NOT done DO
-
- SELECT vId, vSchema, vProcedure;
-
- UPDATE bs.nightTask
- SET started = now()
- WHERE id = vId;
-
- CALL vn2008.sql_query (sql_printf('CALL %s.%s',vSchema, vProcedure));
-
- UPDATE bs.nightTask
- SET finished = now()
- WHERE id = vId;
-
- FETCH rs INTO vId, vSchema, vProcedure;
-
- 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 `nocturnEvent_Tickets_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 `nocturnEvent_Tickets_Bionizar`()
-BEGIN
-
-DECLARE MyDate DATE;
-
-
-
-SET MyDate = timestampadd(week,-1,curdate());
-
- INSERT INTO vn2008.daily_task_log(consulta) VALUES('Comença la rebionització de tickets ');
-
-WHILE MyDate < CURDATE() DO
-
- CALL `vn2008`.`bionic_tickets_range_bionizar`(MyDate, MyDate);
-
- SET MyDate = timestampadd(DAY,1,MyDate);
-
- SELECT MyDate;
-
-END WHILE;
-
- INSERT INTO vn2008.daily_task_log(consulta) VALUES('finalitza la rebionització de tickets ');
-
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `vendedores_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `vendedores_add`(IN intYEAR INT, IN intMONTH INT)
-BEGIN
-
-REPLACE vendedores
-
-SELECT c.Id_Trabajador
- , intYEAR
- , intMONTH
- , sum(importe) as importe
- , sum(importe) * 0.029 as comision
- , 0 as comisionCedida
- , 0 as comisionArrendada
-
-FROM ventas v
-JOIN vn2008.Clientes c on v.Id_Cliente = c.Id_Cliente
-JOIN vn2008.time on time.date = v.fecha
-WHERE time.year = intYEAR and time.month = intMONTH
-AND c.Id_Trabajador is not null
-GROUP BY c.Id_Trabajador;
-
-
-
-UPDATE vendedores
-JOIN
-(
-SELECT cc.Id_Trabajador_old as Id_Trabajador
- , sum(importe) * 0.029 * comision_old as cedido
-
-FROM ventas v
-JOIN vn2008.Clientes c on v.Id_Cliente = c.Id_Cliente
-JOIN vn2008.Clientes_cedidos cc on cc.Id_Cliente = c.Id_Cliente
-JOIN vn2008.time on time.date = v.fecha
-WHERE time.year = intYEAR and time.month = intMONTH
-AND c.Id_Trabajador is not null
-GROUP BY cc.Id_Trabajador_old
-) sub using(Id_Trabajador)
-SET comisionCedida = cedido, comision = comision - cedido
-WHERE año = intYEAR and mes = intMONTH;
-
-
-
-UPDATE vendedores
-JOIN
-(
-SELECT cc.Id_Trabajador_new as Id_Trabajador
- , sum(importe) * 0.029 * comision_new as arrendada
-
-FROM ventas v
-JOIN vn2008.Clientes c on v.Id_Cliente = c.Id_Cliente
-JOIN vn2008.Clientes_cedidos cc on cc.Id_Cliente = c.Id_Cliente AND v.fecha between datSTART and datEND
-JOIN vn2008.time on time.date = v.fecha
-WHERE time.year = intYEAR and time.month = intMONTH
-AND c.Id_Trabajador is not null
-GROUP BY cc.Id_Trabajador_new
-) sub using(Id_Trabajador)
-SET comisionArrendada = arrendada, comision = comision - arrendada
-WHERE año = intYEAR and mes = intMONTH;
-
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `vendedores_add_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 `vendedores_add_launcher`()
-BEGIN
-
- call bs.vendedores_add(year(curdate()), month(curdate()));
- call bs.vendedores_add(year(timestampadd(month,-1,curdate())), month(timestampadd(month,-1,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 `vendedores_evolution_add` */;
-ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `vendedores_evolution_add`()
-BEGIN
-
-
-DECLARE datFEC DATE;
-
-
-SELECT TIMESTAMPADD(DAY,1,MAX(fecha)) INTO datFEC FROM bs.vendedores_evolution;
-
- WHILE datFEC < CURDATE() DO
-
- SELECT datFEC;
-
- REPLACE bs.vendedores_evolution( Id_Trabajador
- , fecha
- , importe)
-
- SELECT Id_Trabajador
- , datFEC as fecha
- , sum(importe) as importe
-
- FROM
- (
-
- SELECT Id_Trabajador
- , importe
- FROM bs.vendedores_evolution
- WHERE fecha = TIMESTAMPADD(DAY,-1,datFEC)
-
- UNION ALL
-
- SELECT c.Id_Trabajador
- , importe * IF(v.fecha < datFEC,-1,1)
- FROM bs.ventas v
- JOIN vn2008.Movimientos m using(Id_Movimiento)
- JOIN vn2008.Tickets t using(Id_Ticket)
- JOIN vn2008.Consignatarios cs using(Id_Consigna)
- JOIN vn2008.Clientes c on cs.Id_Cliente = c.Id_Cliente
- JOIN vn2008.Tipos using(tipo_id)
- WHERE v.fecha IN (datFEC, TIMESTAMPADD(DAY,-365,datFEC))
- AND c.Id_Trabajador is not null
- AND (Id_Article = 98 or Id_Article = 95 or reino_id != 6)
- GROUP BY c.Id_Trabajador
-
-
- )sub
- GROUP BY Id_Trabajador;
-
-
-
-
- SET datFEC = TIMESTAMPADD(DAY,1,datFEC);
-
- 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 */ ;
-ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `ventas_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `ventas_add`(IN datSTART DATE, IN datEND DATE)
-BEGIN
-
-
-DECLARE vStartingPeriod INT;
-DECLARE vStartingDate DATETIME;
-DECLARE vEndingDate DATETIME;
-DECLARE TIPO_PATRIMONIAL INT DEFAULT 188;
-
-SET datEND = vn2008.dayend(datEND);
-SET vStartingDate = GREATEST('2015-10-01',datSTART);
-SET vEndingDate = vn2008.dayend(vStartingDate);
-
-DELETE FROM ventas
-WHERE fecha between vStartingDate and datEND;
-
-WHILE vEndingDate <= datEND DO
-
-
-
- SELECT vStartingDate,vEndingDate;
-
- INSERT INTO ventas(Id_Movimiento, importe, recargo, fecha, tipo_id, Id_Cliente, empresa_id)
- SELECT Id_Movimiento
- , sum( IF(base, Cantidad * Valor, 0) ) as importe
- , sum( IF(base, 0, Cantidad * Valor) ) as recargo
- , vStartingDate
- , a.tipo_id
- , cs.Id_Cliente
- , t.empresa_id
- FROM vn2008.Movimientos_componentes mc
- JOIN bi.tarifa_componentes tc using(Id_Componente)
- JOIN bi.tarifa_componentes_series tcs using(tarifa_componentes_series_id)
- JOIN vn2008.Movimientos m using(Id_Movimiento)
- JOIN vn2008.Articles a using(Id_Article)
- JOIN vn2008.Tipos tp using(tipo_id)
- JOIN vn2008.reinos r on r.id = tp.reino_id
- 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.empresa e on e.id = empresa_id
- WHERE t.Fecha between vStartingDate and vEndingDate
- AND datEND >= '2015-10-01'
- AND (
- c.`Real` != 0
- OR c.Razonsocial = 'MIRIAM FERRER TORIBIO'
- OR c.Razonsocial = 'VERDNATURA COMPLEMENTOS'
- )
- AND Cantidad <> 0
- AND a.tipo_id != TIPO_PATRIMONIAL
- AND c.Id_Trabajador IS NOT NULL
- AND m.Descuento <> 100
- AND (m.Id_Article = 98 or m.Id_Article = 95 or r.mercancia != 0)
- GROUP BY mc.Id_Movimiento
- HAVING IFNULL(importe,0) <> 0 OR IFNULL(recargo,0) <> 0;
-
-
-
- SET vStartingDate = TIMESTAMPADD(DAY,1, vStartingDate);
- SET vEndingDate = vn2008.dayend(vStartingDate);
-
- IF CURDATE() = '2017-02-28' THEN
- SELECT vStartingDate;
- END IF;
-
-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 `ventas_add_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 `ventas_add_launcher`()
-BEGIN
-
- call bs.ventas_add(timestampadd(week,-2,curdate()),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 `ventas_contables_add` */;
-ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ventas_contables_add`(IN vYear INT, IN vMonth INT)
-BEGIN
-
-DECLARE TIPO_PATRIMONIAL INT DEFAULT 188;
-
-DELETE FROM bs.ventas_contables
- WHERE year = vYear
- AND month = vMonth;
-
-DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list;
-
-CREATE TEMPORARY TABLE tmp.ticket_list
- (PRIMARY KEY (Id_Ticket))
- SELECT Id_Ticket
- FROM vn2008.Tickets t
- JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura
- WHERE year(f.Fecha) = vYear
- AND month(f.Fecha) = vMonth;
-
-
-INSERT INTO bs.ventas_contables(year
- , month
- , venta
- , grupo
- , reino_id
- , tipo_id
- , empresa_id
- , gasto)
-
- SELECT vYear
- , vMonth
- , round(sum(Cantidad * Preu * (100 - m.Descuento)/100))
- , if(
- e.empresa_grupo = e2.empresa_grupo
- ,1
- ,if(e2.empresa_grupo,2,0)
- ) as grupo
- , tp.reino_id
- , a.tipo_id
- , t.empresa_id
- , 7000000000
- + if(e.empresa_grupo = e2.empresa_grupo
- ,1
- ,if(e2.empresa_grupo,2,0)
- ) * 1000000
- + IF(tp.Id_Trabajador = 24 , 7,tp.reino_id) * 10000 as Gasto
- FROM vn2008.Movimientos m
- JOIN vn2008.Tickets t on t.Id_Ticket = m.Id_Ticket
- JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna
- JOIN vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente
- JOIN tmp.ticket_list tt on tt.Id_Ticket = t.Id_Ticket
- JOIN vn2008.Articles a on m.Id_Article = a.Id_Article
- JOIN vn2008.empresa e on e.id = t.empresa_id
- LEFT JOIN vn2008.empresa e2 on e2.Id_Cliente = c.Id_Cliente
- JOIN vn2008.Tipos tp on tp.tipo_id = a.tipo_id
- WHERE Cantidad <> 0
- AND Preu <> 0
- AND m.Descuento <> 100
- AND a.tipo_id != TIPO_PATRIMONIAL
- GROUP BY grupo, reino_id, tipo_id, empresa_id, Gasto;
-
-
-DROP TEMPORARY TABLE tmp.ticket_list;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `ventas_contables_add_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 `ventas_contables_add_launcher`()
-BEGIN
-
- call bs.ventas_contables_add(YEAR(TIMESTAMPADD(MONTH,-1,CURDATE())), MONTH(TIMESTAMPADD(MONTH,-1,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 `ventas_contables_por_cliente` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ventas_contables_por_cliente`(IN vYear INT, IN vMonth INT)
-BEGIN
-
-
-DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list;
-
-CREATE TEMPORARY TABLE tmp.ticket_list
- (PRIMARY KEY (Id_Ticket))
- SELECT Id_Ticket
- FROM vn2008.Tickets t
- JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura
- WHERE year(f.Fecha) = vYear
- AND month(f.Fecha) = vMonth;
-
-
-
- SELECT vYear Año
- , vMonth Mes
- , t.Id_Cliente
- , round(sum(Cantidad * Preu * (100 - m.Descuento)/100)) Venta
- , if(
- e.empresa_grupo = e2.empresa_grupo
- ,1
- ,if(e2.empresa_grupo,2,0)
- ) as grupo
- , t.empresa_id empresa
- FROM vn2008.Movimientos m
- JOIN vn2008.Tickets t on t.Id_Ticket = m.Id_Ticket
- JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna
- JOIN vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente
- JOIN tmp.ticket_list tt on tt.Id_Ticket = t.Id_Ticket
- JOIN vn2008.Articles a on m.Id_Article = a.Id_Article
- JOIN vn2008.empresa e on e.id = t.empresa_id
- LEFT JOIN vn2008.empresa e2 on e2.Id_Cliente = c.Id_Cliente
- JOIN vn2008.Tipos tp on tp.tipo_id = a.tipo_id
- WHERE Cantidad <> 0
- AND Preu <> 0
- AND m.Descuento <> 100
- AND a.tipo_id != 188
- GROUP BY t.Id_Cliente, grupo,t.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 */ ;
-
---
--- Current Database: `account`
---
-
-CREATE DATABASE /*!32312 IF NOT EXISTS*/ `account` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
-
-USE `account`;
-
---
--- Table structure for table `account`
---
-
-DROP TABLE IF EXISTS `account`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `account` (
- `id` int(10) unsigned NOT NULL,
- PRIMARY KEY (`id`),
- CONSTRAINT `account_ibfk_3` FOREIGN KEY (`id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Users allowed to have an account';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `accountConfig`
---
-
-DROP TABLE IF EXISTS `accountConfig`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `accountConfig` (
- `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
- `homedir` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The base folder for users home directories',
- `shell` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The default shell',
- `min` smallint(6) NOT NULL,
- `max` smallint(6) NOT NULL,
- `warn` smallint(6) NOT NULL,
- `inact` smallint(6) NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters for accounts';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `accountDovecot`
---
-
-DROP TABLE IF EXISTS `accountDovecot`;
-/*!50001 DROP VIEW IF EXISTS `accountDovecot`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `accountDovecot` AS SELECT
- 1 AS `name`,
- 1 AS `password`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `accountLog`
---
-
-DROP TABLE IF EXISTS `accountLog`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `accountLog` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `msg` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `pid` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `user` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `host` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `rhost` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `time` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `accountNss`
---
-
-DROP TABLE IF EXISTS `accountNss`;
-/*!50001 DROP VIEW IF EXISTS `accountNss`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `accountNss` AS SELECT
- 1 AS `surname`,
- 1 AS `name`,
- 1 AS `password`,
- 1 AS `home`,
- 1 AS `shell`,
- 1 AS `min`,
- 1 AS `max`,
- 1 AS `warn`,
- 1 AS `inact`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `accountPam`
---
-
-DROP TABLE IF EXISTS `accountPam`;
-/*!50001 DROP VIEW IF EXISTS `accountPam`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `accountPam` AS SELECT
- 1 AS `name`,
- 1 AS `password`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `ldapConfig`
---
-
-DROP TABLE IF EXISTS `ldapConfig`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `ldapConfig` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `host` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The hostname of LDAP server',
- `rdn` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The LDAP user',
- `password` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Base64 encoded password',
- `baseDn` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The base DN to do the query',
- `filter` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Filter to apply to the query',
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='LDAP server configuration parameters';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `mailAlias`
---
-
-DROP TABLE IF EXISTS `mailAlias`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `mailAlias` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `alias` varchar(50) CHARACTER SET utf8 NOT NULL,
- `isPublic` tinyint(4) NOT NULL DEFAULT '1',
- PRIMARY KEY (`id`),
- UNIQUE KEY `alias` (`alias`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Mail aliases';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `mailAliasAccount`
---
-
-DROP TABLE IF EXISTS `mailAliasAccount`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `mailAliasAccount` (
- `mailAlias` int(10) unsigned NOT NULL,
- `account` int(10) unsigned NOT NULL,
- PRIMARY KEY (`mailAlias`,`account`),
- KEY `account` (`account`),
- CONSTRAINT `account` FOREIGN KEY (`account`) REFERENCES `account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `mailAlias` FOREIGN KEY (`mailAlias`) REFERENCES `mailAlias` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Mail alias that is assigned to each account';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `mailForward`
---
-
-DROP TABLE IF EXISTS `mailForward`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `mailForward` (
- `account` int(10) unsigned NOT NULL,
- `forwardTo` varchar(250) CHARACTER SET utf8 NOT NULL,
- PRIMARY KEY (`account`),
- CONSTRAINT `mailForward_ibfk_1` FOREIGN KEY (`account`) REFERENCES `account` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Mail forwarding';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `role`
---
-
-DROP TABLE IF EXISTS `role`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `role` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `name` varchar(14) COLLATE utf8_unicode_ci NOT NULL,
- `description` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
- `hasLogin` tinyint(3) unsigned NOT NULL DEFAULT '0',
- `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- PRIMARY KEY (`id`),
- UNIQUE KEY `name` (`name`)
-) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Roles';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `roleInherit`
---
-
-DROP TABLE IF EXISTS `roleInherit`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `roleInherit` (
- `role` int(10) unsigned NOT NULL,
- `inheritsFrom` int(10) unsigned NOT NULL,
- PRIMARY KEY (`role`,`inheritsFrom`),
- KEY `owner_id` (`inheritsFrom`),
- CONSTRAINT `roleInherit_ibfk_1` FOREIGN KEY (`role`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `roleInherit_ibfk_2` FOREIGN KEY (`inheritsFrom`) REFERENCES `role` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Role inheritance';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `roleRole`
---
-
-DROP TABLE IF EXISTS `roleRole`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `roleRole` (
- `role` int(10) unsigned NOT NULL,
- `inheritsFrom` int(10) unsigned NOT NULL,
- UNIQUE KEY `role` (`role`,`inheritsFrom`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Calculated role inheritance';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `sambaConfig`
---
-
-DROP TABLE IF EXISTS `sambaConfig`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `sambaConfig` (
- `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
- `host` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The hosname of Samba server',
- `sshUser` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The SSH user to connect to servers',
- `sshPass` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The SSH password base64 encoded',
- `domain` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The default domain for mail accounts, its appended to the user name',
- `uidBase` int(10) unsigned NOT NULL DEFAULT '10000' COMMENT 'The base for Unix uids',
- PRIMARY KEY (`id`)
-) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters for accounts';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `user`
---
-
-DROP TABLE IF EXISTS `user`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `user` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `name` varchar(30) CHARACTER SET utf8 NOT NULL,
- `password` char(64) COLLATE utf8_unicode_ci NOT NULL,
- `role` int(10) unsigned NOT NULL DEFAULT '2',
- `active` tinyint(1) NOT NULL DEFAULT '1',
- `email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
- `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `sync` tinyint(4) NOT NULL DEFAULT '0',
- `recoverPass` tinyint(3) unsigned NOT NULL DEFAULT '1',
- `lastPassChange` datetime DEFAULT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `name` (`name`),
- KEY `role` (`role`),
- KEY `email` (`email`),
- CONSTRAINT `user_ibfk_2` FOREIGN KEY (`role`) REFERENCES `role` (`id`) ON UPDATE CASCADE
-) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global users';
-/*!40101 SET character_set_client = @saved_cs_client */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `account`.`userBeforeInsert`
-BEFORE INSERT ON `user` FOR EACH ROW
-BEGIN
- CALL userCheckName (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 */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `account`.`userBeforeUpdate`
-BEFORE UPDATE ON `user` FOR EACH ROW
-BEGIN
- IF OLD.`name` != NEW.`name` THEN
- CALL userCheckName (NEW.`name`);
- END IF;
-
- IF NEW.`password` != OLD.`password`
- OR (OLD.`password` IS NULL AND NEW.`password` IS NOT NULL)
- THEN
- SET NEW.lastPassChange = NOW();
- 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 */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userAfterUpdate`
-AFTER UPDATE ON `user` FOR EACH ROW
-BEGIN
- IF NEW.role <> OLD.role
- THEN
- INSERT INTO vn2008.mail(`to`,reply_to,`subject`,`text`)
- SELECT 'jgallego@verdnatura.es','jgallego@verdnatura.es','Rol modificado',
- CONCAT(`name`,' ha modificado el rol del usuario ',NEW.`name`,' de ',OLD.role,' a ',NEW.role)
- FROM account.user WHERE id = account.userGetId();
- 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 */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Table structure for table `userPassword`
---
-
-DROP TABLE IF EXISTS `userPassword`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `userPassword` (
- `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
- `length` tinyint(3) unsigned NOT NULL,
- `nAlpha` tinyint(3) unsigned NOT NULL,
- `nUpper` tinyint(3) unsigned NOT NULL,
- `nDigits` tinyint(3) unsigned NOT NULL,
- `nPunct` tinyint(3) unsigned NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Restrictions on user passwords';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `userRole`
---
-
-DROP TABLE IF EXISTS `userRole`;
-/*!50001 DROP VIEW IF EXISTS `userRole`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `userRole` AS SELECT
- 1 AS `id`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `userSession`
---
-
-DROP TABLE IF EXISTS `userSession`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `userSession` (
- `connectionId` int(10) unsigned NOT NULL,
- `user` int(10) unsigned NOT NULL,
- `userName` varchar(30) CHARACTER SET utf8 DEFAULT NULL,
- `creationDate` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (`connectionId`),
- KEY `creationDate` (`creationDate`)
-) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `userView`
---
-
-DROP TABLE IF EXISTS `userView`;
-/*!50001 DROP VIEW IF EXISTS `userView`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `userView` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `active`,
- 1 AS `email`,
- 1 AS `role`,
- 1 AS `recoverPass`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Dumping events for database 'account'
---
-
---
--- Dumping routines for database 'account'
---
-/*!50003 DROP FUNCTION IF EXISTS `toUnixDays` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `toUnixDays`(vDate DATE) RETURNS int(11)
- DETERMINISTIC
-BEGIN
-
- RETURN UNIX_TIMESTAMP(vDate) DIV 86400;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `userGetId` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userGetId`() RETURNS int(11)
- DETERMINISTIC
-BEGIN
-
- DECLARE vUser INT DEFAULT NULL;
-
- SELECT user INTO vUser FROM userSession
- WHERE connectionId = CONNECTION_ID();
-
- IF vUser IS NULL THEN
- SELECT id INTO vUser FROM user
- WHERE name = LEFT(USER(), INSTR(USER(), '@') - 1);
- END IF;
-
- RETURN vUser;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `userGetMysqlRole` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userGetMysqlRole`(vUserName VARCHAR(255)) RETURNS varchar(255) CHARSET utf8
-BEGIN
-
- DECLARE vRole VARCHAR(255);
-
- SELECT CONCAT(IF(r.hasLogin, 'z-', ''), r.name) INTO vRole
- FROM role r
- JOIN user u ON u.role = r.id
- WHERE u.name = vUserName;
-
- RETURN vRole;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `userGetName` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userGetName`() RETURNS varchar(30) CHARSET utf8
- DETERMINISTIC
-BEGIN
-
- DECLARE vUser VARCHAR(30) DEFAULT NULL;
-
-
- SELECT userName INTO vUser
- FROM userSession
- WHERE connectionId = CONNECTION_ID();
-
- IF vUser IS NULL THEN
- SET vUser = LEFT(USER(), INSTR(USER(), '@') - 1);
- END IF;
-
- RETURN vUser;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `userGetNameFromId` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userGetNameFromId`(vId INT) RETURNS varchar(30) CHARSET utf8
-BEGIN
-
- DECLARE vName VARCHAR(30);
-
- SELECT `name` INTO vName
- FROM user
- WHERE id = vId;
-
- RETURN vName;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `userHasRole` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userHasRole`(vRoleName VARCHAR(255)) RETURNS tinyint(1)
- DETERMINISTIC
-BEGIN
-
- DECLARE vRoleId INT;
-
- SELECT id INTO vRoleId
- FROM role
- WHERE `name` = vRoleName COLLATE 'utf8_unicode_ci';
-
- RETURN userHasRoleId (vRoleId);
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP FUNCTION IF EXISTS `userHasRoleId` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userHasRoleId`(vRoleId INT) RETURNS tinyint(1)
- DETERMINISTIC
-BEGIN
-
- DECLARE vHasRole BOOL DEFAULT FALSE;
-
- SELECT COUNT(*) > 0 INTO vHasRole
- FROM userRole
- WHERE id = vRoleId;
-
- RETURN vHasRole;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `privSync` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `privSync`()
-proc: BEGIN
-
- DECLARE vTplUser VARCHAR(255) DEFAULT 'any';
- DECLARE vHost VARCHAR(255) DEFAULT '%';
- DECLARE vPrefix VARCHAR(2) DEFAULT 'z-';
-
- DECLARE vTplExists BOOL;
- DECLARE vTplHost VARCHAR(255);
- DECLARE vPrefixedLike VARCHAR(255);
-
-
-
- SELECT COUNT(*) > 0, `Host`
- INTO vTplExists, vTplHost
- FROM mysql.user
- WHERE `User` = vTplUser
- LIMIT 1;
-
- IF NOT vTplExists THEN
- SIGNAL SQLSTATE '45000'
- SET MESSAGE_TEXT = 'TEMPLATE_USER_NOT_EXISTS';
- END IF;
-
-
-
- SET vPrefixedLike = CONCAT(vPrefix, '%');
-
- DELETE FROM mysql.user
- WHERE `User` LIKE vPrefixedLike;
-
- DELETE FROM mysql.db
- WHERE `User` LIKE vPrefixedLike;
-
- DELETE FROM mysql.tables_priv
- WHERE `User` LIKE vPrefixedLike;
-
- DELETE FROM mysql.columns_priv
- WHERE `User` LIKE vPrefixedLike;
-
- DELETE FROM mysql.procs_priv
- WHERE `User` LIKE vPrefixedLike;
-
- DELETE FROM mysql.proxies_priv
- WHERE `Proxied_user` LIKE vPrefixedLike;
-
-
-
- DROP TEMPORARY TABLE IF EXISTS tRole;
- CREATE TEMPORARY TABLE tRole
- ENGINE = MEMORY
- SELECT
- `name` role,
- CONCAT(vPrefix, `name`) prefixedRole
- FROM role
- WHERE hasLogin;
-
- DROP TEMPORARY TABLE IF EXISTS tRoleInherit;
- CREATE TEMPORARY TABLE tRoleInherit
- (INDEX (inheritsFrom))
- ENGINE = MEMORY
- SELECT
- CONCAT(vPrefix, r.`name`) prefixedRole,
- ri.`name` inheritsFrom
- FROM role r
- JOIN roleRole rr ON rr.role = r.id
- JOIN role ri ON ri.id = rr.inheritsFrom;
-
-
-
- INSERT INTO mysql.user (
- `User`,
- `Host`,
- `Password`,
- `ssl_type`,
- `ssl_cipher`,
- `x509_issuer`,
- `x509_subject`,
- `max_questions`,
- `max_updates`,
- `max_connections`,
- `max_user_connections`
- )
- SELECT
- r.prefixedRole,
- vTplHost,
- IF('' != u.`Password`,
- u.`Password`, t.`Password`),
- IF('' != u.`ssl_type`,
- u.`ssl_type`, t.`ssl_type`),
- IF('' != u.`ssl_cipher`,
- u.`ssl_cipher`, t.`ssl_cipher`),
- IF('' != u.`x509_issuer`,
- u.`x509_issuer`, t.`x509_issuer`),
- IF('' != u.`x509_subject`,
- u.`x509_subject`, t.`x509_subject`),
- IF(0 != u.`max_questions`,
- u.`max_questions`, t.`max_questions`),
- IF(0 != u.`max_updates`,
- u.`max_updates`, t.`max_updates`),
- IF(0 != u.`max_connections`,
- u.`max_connections`, t.`max_connections`),
- IF(0 != u.`max_user_connections`,
- u.`max_user_connections`, t.`max_user_connections`)
- FROM tRole r
- JOIN mysql.user t
- ON t.`User` = vTplUser
- AND t.`Host` = vTplHost
- LEFT JOIN mysql.user u
- ON u.`User` = r.role
- AND u.`Host` = vHost;
-
- INSERT INTO mysql.proxies_priv (
- `User`,
- `Host`,
- `Proxied_user`,
- `Proxied_host`,
- `Grantor`
- )
- SELECT
- '',
- vHost,
- prefixedRole,
- vHost,
- CONCAT(prefixedRole, '@', vTplHost)
- FROM tRole;
-
-
-
- DROP TEMPORARY TABLE IF EXISTS tUserPriv;
- CREATE TEMPORARY TABLE tUserPriv
- (INDEX (prefixedRole))
- ENGINE = MEMORY
- SELECT
- r.prefixedRole,
- MAX(u.`Select_priv`) `Select_priv`,
- MAX(u.`Insert_priv`) `Insert_priv`,
- MAX(u.`Update_priv`) `Update_priv`,
- MAX(u.`Delete_priv`) `Delete_priv`,
- MAX(u.`Create_priv`) `Create_priv`,
- MAX(u.`Drop_priv`) `Drop_priv`,
- MAX(u.`Reload_priv`) `Reload_priv`,
- MAX(u.`Shutdown_priv`) `Shutdown_priv`,
- MAX(u.`Process_priv`) `Process_priv`,
- MAX(u.`File_priv`) `File_priv`,
- MAX(u.`Grant_priv`) `Grant_priv`,
- MAX(u.`References_priv`) `References_priv`,
- MAX(u.`Index_priv`) `Index_priv`,
- MAX(u.`Alter_priv`) `Alter_priv`,
- MAX(u.`Show_db_priv`) `Show_db_priv`,
- MAX(u.`Super_priv`) `Super_priv`,
- MAX(u.`Create_tmp_table_priv`) `Create_tmp_table_priv`,
- MAX(u.`Lock_tables_priv`) `Lock_tables_priv`,
- MAX(u.`Execute_priv`) `Execute_priv`,
- MAX(u.`Repl_slave_priv`) `Repl_slave_priv`,
- MAX(u.`Repl_client_priv`) `Repl_client_priv`,
- MAX(u.`Create_view_priv`) `Create_view_priv`,
- MAX(u.`Show_view_priv`) `Show_view_priv`,
- MAX(u.`Create_routine_priv`) `Create_routine_priv`,
- MAX(u.`Alter_routine_priv`) `Alter_routine_priv`,
- MAX(u.`Create_user_priv`) `Create_user_priv`,
- MAX(u.`Event_priv`) `Event_priv`,
- MAX(u.`Trigger_priv`) `Trigger_priv`,
- MAX(u.`Create_tablespace_priv`) `Create_tablespace_priv`
- FROM tRoleInherit r
- JOIN mysql.user u
- ON u.`User` = r.inheritsFrom
- AND u.`Host`= vHost
- GROUP BY r.prefixedRole;
-
- UPDATE mysql.user u
- JOIN tUserPriv t
- ON u.`User` = t.prefixedRole
- AND u.`Host` = vHost
- SET
- u.`Select_priv`
- = t.`Select_priv`,
- u.`Insert_priv`
- = t.`Insert_priv`,
- u.`Update_priv`
- = t.`Update_priv`,
- u.`Delete_priv`
- = t.`Delete_priv`,
- u.`Create_priv`
- = t.`Create_priv`,
- u.`Drop_priv`
- = t.`Drop_priv`,
- u.`Reload_priv`
- = t.`Reload_priv`,
- u.`Shutdown_priv`
- = t.`Shutdown_priv`,
- u.`Process_priv`
- = t.`Process_priv`,
- u.`File_priv`
- = t.`File_priv`,
- u.`Grant_priv`
- = t.`Grant_priv`,
- u.`References_priv`
- = t.`References_priv`,
- u.`Index_priv`
- = t.`Index_priv`,
- u.`Alter_priv`
- = t.`Alter_priv`,
- u.`Show_db_priv`
- = t.`Show_db_priv`,
- u.`Super_priv`
- = t.`Super_priv`,
- u.`Create_tmp_table_priv`
- = t.`Create_tmp_table_priv`,
- u.`Lock_tables_priv`
- = t.`Lock_tables_priv`,
- u.`Execute_priv`
- = t.`Execute_priv`,
- u.`Repl_slave_priv`
- = t.`Repl_slave_priv`,
- u.`Repl_client_priv`
- = t.`Repl_client_priv`,
- u.`Create_view_priv`
- = t.`Create_view_priv`,
- u.`Show_view_priv`
- = t.`Show_view_priv`,
- u.`Create_routine_priv`
- = t.`Create_routine_priv`,
- u.`Alter_routine_priv`
- = t.`Alter_routine_priv`,
- u.`Create_user_priv`
- = t.`Create_user_priv`,
- u.`Event_priv`
- = t.`Event_priv`,
- u.`Trigger_priv`
- = t.`Trigger_priv`,
- u.`Create_tablespace_priv`
- = t.`Create_tablespace_priv`;
-
- DROP TEMPORARY TABLE tUserPriv;
-
-
-
- INSERT INTO mysql.db (
- `User`,
- `Host`,
- `Db`,
- `Select_priv`,
- `Insert_priv`,
- `Update_priv`,
- `Delete_priv`,
- `Create_priv`,
- `Drop_priv`,
- `Grant_priv`,
- `References_priv`,
- `Index_priv`,
- `Alter_priv`,
- `Create_tmp_table_priv`,
- `Lock_tables_priv`,
- `Create_view_priv`,
- `Show_view_priv`,
- `Create_routine_priv`,
- `Alter_routine_priv`,
- `Execute_priv`,
- `Event_priv`,
- `Trigger_priv`
- )
- SELECT
- r.prefixedRole,
- vTplHost,
- t.`Db`,
- MAX(t.`Select_priv`),
- MAX(t.`Insert_priv`),
- MAX(t.`Update_priv`),
- MAX(t.`Delete_priv`),
- MAX(t.`Create_priv`),
- MAX(t.`Drop_priv`),
- MAX(t.`Grant_priv`),
- MAX(t.`References_priv`),
- MAX(t.`Index_priv`),
- MAX(t.`Alter_priv`),
- MAX(t.`Create_tmp_table_priv`),
- MAX(t.`Lock_tables_priv`),
- MAX(t.`Create_view_priv`),
- MAX(t.`Show_view_priv`),
- MAX(t.`Create_routine_priv`),
- MAX(t.`Alter_routine_priv`),
- MAX(t.`Execute_priv`),
- MAX(t.`Event_priv`),
- MAX(t.`Trigger_priv`)
- FROM tRoleInherit r
- JOIN mysql.db t
- ON t.`User` = r.inheritsFrom
- AND t.`Host`= vHost
- GROUP BY r.prefixedRole, t.`Db`;
-
-
-
- INSERT INTO mysql.tables_priv (
- `User`,
- `Host`,
- `Db`,
- `Table_name`,
- `Grantor`,
- `Timestamp`,
- `Table_priv`,
- `Column_priv`
- )
- SELECT
- r.prefixedRole,
- vTplHost,
- t.`Db`,
- t.`Table_name`,
- t.`Grantor`,
- MAX(t.`Timestamp`),
- GROUP_CONCAT(CONCAT(t.`Table_priv`, ',')),
- GROUP_CONCAT(CONCAT(t.`Column_priv`, ','))
- FROM tRoleInherit r
- JOIN mysql.tables_priv t
- ON t.`User` = r.inheritsFrom
- AND t.`Host`= vHost
- GROUP BY r.prefixedRole, t.`Db`, t.`Table_name`;
-
-
-
- INSERT INTO mysql.columns_priv (
- `User`,
- `Host`,
- `Db`,
- `Table_name`,
- `Column_name`,
- `Timestamp`,
- `Column_priv`
- )
- SELECT
- r.prefixedRole,
- vTplHost,
- t.`Db`,
- t.`Table_name`,
- t.`Column_name`,
- MAX(t.`Timestamp`),
- GROUP_CONCAT(CONCAT(t.`Column_priv`, ','))
- FROM tRoleInherit r
- JOIN mysql.columns_priv t
- ON t.`User` = r.inheritsFrom
- AND t.`Host`= vHost
- GROUP BY r.prefixedRole, t.`Db`, t.`Table_name`, t.`Column_name`;
-
-
-
- INSERT IGNORE INTO mysql.procs_priv (
- `User`,
- `Host`,
- `Db`,
- `Routine_name`,
- `Routine_type`,
- `Grantor`,
- `Timestamp`,
- `Proc_priv`
- )
- SELECT
- r.prefixedRole,
- vTplHost,
- t.`Db`,
- t.`Routine_name`,
- t.`Routine_type`,
- t.`Grantor`,
- t.`Timestamp`,
- t.`Proc_priv`
- FROM tRoleInherit r
- JOIN mysql.procs_priv t
- ON t.`User` = r.inheritsFrom
- AND t.`Host`= vHost;
-
-
-
- DROP TEMPORARY TABLE
- tRole,
- tRoleInherit;
-
- FLUSH PRIVILEGES;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `roleGetDescendents` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `roleGetDescendents`(vRole INT)
-BEGIN
-
- DECLARE vIsRoot BOOL;
-
- DROP TEMPORARY TABLE IF EXISTS
- tmp.role, parents, childs;
-
- CREATE TEMPORARY TABLE tmp.role
- (UNIQUE (id))
- ENGINE = MEMORY
- SELECT vRole AS id;
-
- CREATE TEMPORARY TABLE parents
- ENGINE = MEMORY
- SELECT vRole AS id;
-
- CREATE TEMPORARY TABLE childs
- LIKE parents;
-
- REPEAT
- DELETE FROM childs;
- INSERT INTO childs
- SELECT DISTINCT r.inheritsFrom id
- FROM parents p
- JOIN roleInherit r ON r.role = p.id
- LEFT JOIN tmp.role t ON t.id = r.inheritsFrom
- WHERE t.id IS NULL;
-
- DELETE FROM parents;
- INSERT INTO parents
- SELECT * FROM childs;
-
- INSERT INTO tmp.role
- SELECT * FROM childs;
-
- UNTIL ROW_COUNT() <= 0
- END REPEAT;
-
-
-
- SELECT COUNT(*) > 0 INTO vIsRoot
- FROM tmp.role
- WHERE id = 0;
-
- IF vIsRoot THEN
- INSERT IGNORE INTO tmp.role (id)
- SELECT id FROM role;
- END IF;
-
-
-
- DROP TEMPORARY TABLE
- parents, childs;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `roleSync` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `roleSync`()
-BEGIN
-
- DECLARE vRoleId INT;
- DECLARE vDone BOOL;
-
- DECLARE cur CURSOR FOR
- SELECT id FROM role;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
-
- TRUNCATE TABLE roleRole;
-
- OPEN cur;
-
- l: LOOP
- SET vDone = FALSE;
- FETCH cur INTO vRoleId;
-
- IF vDone THEN
- LEAVE l;
- END IF;
-
- CALL roleGetDescendents (vRoleId);
-
- INSERT INTO roleRole (role, inheritsFrom)
- SELECT vRoleId, id FROM tmp.role;
-
- DROP TEMPORARY TABLE tmp.role;
- END LOOP;
-
- CLOSE cur;
-
- CALL privSync();
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `userChangePassword` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userChangePassword`(vOldPassword VARCHAR(255), vPassword VARCHAR(255))
-BEGIN
-
- DECLARE vPasswordOk BOOL;
-
- SELECT `password` = MD5(vOldPassword) OR recoverPass
- INTO vPasswordOk
- FROM user WHERE id = account.userGetId();
-
- IF NOT vPasswordOk THEN
- SIGNAL SQLSTATE '45000'
- SET MESSAGE_TEXT = 'Invalid password';
- END IF;
-
- CALL userSetPassword (userGetName(), vPassword);
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `userCheckName` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userCheckName`(vUserName VARCHAR(255))
-BEGIN
-
- IF vUserName NOT REGEXP '^[a-z0-9_]*$' THEN
- SIGNAL SQLSTATE '45000'
- SET MESSAGE_TEXT = 'INVALID_USER_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 */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `userCheckPassword` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userCheckPassword`(vPassword VARCHAR(255))
-BEGIN
-
- DECLARE vChr CHAR(1);
- DECLARE vPasswordOk TINYINT;
- DECLARE vI TINYINT DEFAULT 1;
- DECLARE vNAlpha TINYINT DEFAULT 0;
- DECLARE vNUpper TINYINT DEFAULT 0;
- DECLARE vNDigits TINYINT DEFAULT 0;
- DECLARE vNPunct TINYINT DEFAULT 0;
-
- WHILE vI <= CHAR_LENGTH(vPassword)
- DO
- SET vChr = SUBSTRING(vPassword, vI, 1);
-
- IF vChr REGEXP '[[:alpha:]]'
- THEN
- SET vNAlpha = vNAlpha+1;
-
- IF vChr REGEXP '[A-Z]'
- THEN
- SET vNUpper = vNUpper+1;
- END IF;
- ELSEIF vChr REGEXP '[[:digit:]]'
- THEN
- SET vNDigits = vNDigits+1;
- ELSEIF vChr REGEXP '[[:punct:]]'
- THEN
- SET vNPunct = vNPunct+1;
- END IF;
-
- SET vI = vI+1;
- END WHILE;
-
- SELECT
- CHAR_LENGTH(vPassword) >= length
- AND vNAlpha >= nAlpha
- AND vNUpper >= nUpper
- AND vNDigits >= nDigits
- AND vNPunct >= nPunct
- INTO vPasswordOk
- FROM userPassword LIMIT 1;
-
- IF NOT vPasswordOk THEN
- SIGNAL SQLSTATE '45000'
- SET MESSAGE_TEXT = 'Password does not meet requirements';
- 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 */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `userLogin` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userLogin`(vUserName VARCHAR(255), vPassword VARCHAR(255))
-BEGIN
-
- DECLARE vUserId INT DEFAULT NULL;
-
- SELECT id INTO vUserId FROM user
- WHERE name = vUserName
- AND password = MD5(vPassword)
- AND active;
-
- IF vUserId IS NOT NULL
- THEN
- REPLACE INTO userSession (connectionId, user, userName)
- VALUES (CONNECTION_ID(), vUserId, vUserName);
- ELSE
- SIGNAL SQLSTATE '45000'
- SET MESSAGE_TEXT = 'INVALID_CREDENTIALS';
- 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 */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `userLoginWithName` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userLoginWithName`(vUserName VARCHAR(255))
-BEGIN
-
- DECLARE vUserId INT DEFAULT NULL;
-
- SELECT id INTO vUserId FROM user
- WHERE name = vUserName;
-
- REPLACE INTO userSession (connectionId, user, userName)
- VALUES (CONNECTION_ID(), vUserId, 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 */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `userLogout` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userLogout`()
-BEGIN
-
- DECLARE vCleanTime DATETIME
- DEFAULT TIMESTAMPADD(MINUTE, -30, NOW());
-
- DELETE FROM userSession
- WHERE connectionId = CONNECTION_ID()
- OR creationDate < vCleanTime;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `userSetPassword` */;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userSetPassword`(vUserName VARCHAR(255), vPassword VARCHAR(255))
-BEGIN
-
- CALL userCheckPassword (vPassword);
-
- UPDATE user SET
- password = MD5(vPassword),
- recoverPass = FALSE
- WHERE `name` = 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 */ ;
-ALTER DATABASE `account` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Current Database: `cache`
---
-
-CREATE DATABASE /*!32312 IF NOT EXISTS*/ `cache` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
-
-USE `cache`;
-
---
--- Table structure for table `available`
---
-
-DROP TABLE IF EXISTS `available`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `available` (
- `calc_id` int(10) unsigned NOT NULL,
- `item_id` int(11) NOT NULL,
- `available` int(11) NOT NULL,
- KEY `calc_id_4` (`calc_id`) USING BTREE,
- KEY `calc_id` (`item_id`,`calc_id`)
-) ENGINE=MEMORY 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` (
- `code` varchar(22) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
- `Id_Article` int(11) NOT NULL DEFAULT '0',
- `Article` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `Medida` int(10) unsigned DEFAULT NULL,
- `Color` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL,
- `Categoria` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL,
- `Producer` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- PRIMARY KEY (`code`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `cache`
---
-
-DROP TABLE IF EXISTS `cache`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `cache` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `name` varchar(50) CHARACTER SET utf8 NOT NULL,
- `lifetime` time NOT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `name` (`name`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `cache_calc`
---
-
-DROP TABLE IF EXISTS `cache_calc`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `cache_calc` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `cache_id` int(10) unsigned NOT NULL,
- `cacheName` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
- `params` varchar(100) CHARACTER SET utf8 NOT NULL DEFAULT '',
- `last_refresh` datetime DEFAULT NULL,
- `expires` datetime DEFAULT NULL,
- `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `connection_id` int(10) unsigned DEFAULT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `cache_name` (`cache_id`,`params`),
- KEY `cache_id` (`cache_id`),
- KEY `cacheName` (`cacheName`),
- KEY `expires` (`expires`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `cache_valid`
---
-
-DROP TABLE IF EXISTS `cache_valid`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `cache_valid` (
- `valid` tinyint(3) unsigned NOT NULL
-) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!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` (
- `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
- `created` 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 `departure_limit`
---
-
-DROP TABLE IF EXISTS `departure_limit`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `departure_limit` (
- `warehouse_id` smallint(6) unsigned NOT NULL,
- `fecha` date NOT NULL,
- `hora` int(11) NOT NULL DEFAULT '0',
- `minSpeed` decimal(10,2) NOT NULL DEFAULT '0.00',
- PRIMARY KEY (`warehouse_id`,`fecha`),
- CONSTRAINT `warehouse_departure` FOREIGN KEY (`warehouse_id`) REFERENCES `vn2008`.`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 `equalizator`
---
-
-DROP TABLE IF EXISTS `equalizator`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `equalizator` (
- `warehouse_id` int(11) NOT NULL,
- `Vista` int(11) NOT NULL,
- `Pedido` int(11) DEFAULT NULL,
- `Impreso` int(11) DEFAULT NULL,
- `Encajado` int(11) DEFAULT NULL,
- PRIMARY KEY (`Vista`,`warehouse_id`)
-) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `itemTagFormat`
---
-
-DROP TABLE IF EXISTS `itemTagFormat`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `itemTagFormat` (
- `itemFk` int(11) NOT NULL,
- `labels1` varchar(80) CHARACTER SET utf8 DEFAULT NULL,
- `values1` varchar(80) CHARACTER SET utf8 DEFAULT NULL,
- `labels2` varchar(80) CHARACTER SET utf8 DEFAULT NULL,
- `values2` varchar(80) CHARACTER SET utf8 DEFAULT NULL,
- `description` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
- PRIMARY KEY (`itemFk`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena el formato para los tags de los articulos';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `item_range`
---
-
-DROP TABLE IF EXISTS `item_range`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `item_range` (
- `calc_id` int(11) NOT NULL,
- `item_id` int(11) NOT NULL,
- `date_end` datetime DEFAULT NULL,
- KEY `calc_item` (`calc_id`,`item_id`),
- KEY `calc_id` (`calc_id`) USING BTREE
-) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `last_buy`
---
-
-DROP TABLE IF EXISTS `last_buy`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `last_buy` (
- `item_id` int(10) unsigned NOT NULL,
- `warehouse_id` smallint(5) unsigned NOT NULL,
- `buy_id` int(10) unsigned DEFAULT NULL,
- `landing` date DEFAULT NULL,
- KEY `buy_id` (`buy_id`),
- KEY `item_id` (`item_id`,`warehouse_id`),
- KEY `warehouse_id` (`warehouse_id`) USING BTREE
-) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `prod_graphic_source`
---
-
-DROP TABLE IF EXISTS `prod_graphic_source`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `prod_graphic_source` (
- `m3` double NOT NULL DEFAULT '0',
- `warehouse_id` int(11) NOT NULL,
- `hora` int(11) NOT NULL,
- `order` int(11) NOT NULL DEFAULT '0',
- `alert_level` int(11) NOT NULL DEFAULT '0',
- `Agencia` varchar(45) CHARACTER SET utf8 NOT NULL
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `stock`
---
-
-DROP TABLE IF EXISTS `stock`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `stock` (
- `warehouse_id` smallint(5) unsigned NOT NULL,
- `item_id` int(10) unsigned NOT NULL,
- `amount` int(11) NOT NULL,
- KEY `warehouse_id` (`warehouse_id`,`item_id`),
- KEY `warehouse_id_2` (`warehouse_id`) USING BTREE
-) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `visible`
---
-
-DROP TABLE IF EXISTS `visible`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `visible` (
- `calc_id` int(10) unsigned NOT NULL,
- `item_id` int(11) NOT NULL,
- `visible` int(11) NOT NULL,
- KEY `id` (`calc_id`) USING BTREE,
- KEY `calc_id` (`calc_id`,`item_id`)
-) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `weekly_sales`
---
-
-DROP TABLE IF EXISTS `weekly_sales`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `weekly_sales` (
- `week` int(10) unsigned NOT NULL,
- `item_id` int(10) unsigned NOT NULL,
- `warehouse_id` smallint(5) unsigned NOT NULL,
- `amount` int(11) NOT NULL,
- `price` double NOT NULL,
- KEY `item_id` (`item_id`,`warehouse_id`),
- KEY `week` (`week`) USING BTREE
-) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Dumping events for database 'cache'
---
-
---
--- Dumping routines for database 'cache'
---
-/*!50003 DROP PROCEDURE IF EXISTS `available_refresh` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `available_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT, v_date DATE)
-proc: BEGIN
- DECLARE v_date_ini DATE;
- DECLARE v_date_end DATETIME;
- DECLARE v_reserve_date DATETIME;
- DECLARE v_params CHAR(100);
- DECLARE v_date_inv DATE;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- CALL cache_calc_unlock (v_calc);
- RESIGNAL;
- END;
-
- IF v_date < CURDATE()
- THEN
- LEAVE proc;
- END IF;
-
- CALL vn2008.item_stock (v_warehouse, v_date, NULL);
-
- SET v_params = CONCAT_WS('/', v_warehouse, v_date);
- CALL cache_calc_start (v_calc, v_refresh, 'available', v_params);
-
- IF !v_refresh
- THEN
- LEAVE proc;
- END IF;
-
-
-
- DELETE a
- FROM available a
- LEFT JOIN cache_calc c ON c.id = a.calc_id
- WHERE c.id IS NULL;
-
-
-
- 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;
-
-
-
- DROP TEMPORARY TABLE IF EXISTS item_range;
- CREATE TEMPORARY TABLE item_range
- (PRIMARY KEY (item_id))
- ENGINE = MEMORY
- SELECT c.item_id, IF(t.life IS NULL, NULL, TIMESTAMP(TIMESTAMPADD(DAY, t.life, c.landing), '23:59:59')) AS date_end
- FROM (
- SELECT c.Id_Article item_id, MAX(landing) landing
- 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 = v_warehouse
- AND NOT e.Inventario
- AND NOT e.Redada
- GROUP BY Id_Article
- ) 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_copy1;
- CREATE TEMPORARY TABLE item_range_copy1 LIKE item_range;
- INSERT INTO item_range_copy1
- SELECT * FROM item_range;
-
- DROP TEMPORARY TABLE IF EXISTS item_range_copy2;
- CREATE TEMPORARY TABLE item_range_copy2 LIKE item_range;
- INSERT INTO item_range_copy2
- SELECT * FROM item_range;
-
- DROP TEMPORARY TABLE IF EXISTS item_range_copy3;
- CREATE TEMPORARY TABLE item_range_copy3 LIKE item_range;
- INSERT INTO item_range_copy3
- SELECT * FROM item_range;
-
- DROP TEMPORARY TABLE IF EXISTS item_range_copy4;
- CREATE TEMPORARY TABLE item_range_copy4 LIKE item_range;
- INSERT INTO item_range_copy4
- SELECT * FROM item_range;
-
-
-
- DELETE FROM available WHERE calc_id = v_calc;
-
- INSERT INTO available (calc_id, item_id, available)
- SELECT v_calc, t.item_id, SUM(stock) amount 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 = v_warehouse
- 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 = v_warehouse
- 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 = v_warehouse
- 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 = v_warehouse
- 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 amount != 0;
-
-
- DROP TEMPORARY TABLE
- vn2008.tmp_item
- ,item_range
- ,item_range_copy1
- ,item_range_copy2
- ,item_range_copy3
- ,item_range_copy4;
-
- CALL cache_calc_end (v_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 `available_refreshtest` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `available_refreshtest`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT, v_date DATE)
-proc: BEGIN
- DECLARE v_date_ini DATE;
- DECLARE v_date_end DATETIME;
- DECLARE v_reserve_date DATETIME;
- DECLARE v_params CHAR(100);
- DECLARE v_date_inv DATE;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- CALL cache_calc_unlock (v_calc);
- RESIGNAL;
- END;
-
- IF v_date < CURDATE()
- THEN
- LEAVE proc;
- END IF;
-
- CALL vn2008.item_stock (v_warehouse, v_date, NULL);
-
- SET v_params = CONCAT_WS('/', v_warehouse, v_date);
- CALL cache_calc_start (v_calc, v_refresh, 'available', v_params);
-
- IF !v_refresh
- THEN
- LEAVE proc;
- END IF;
-
-
-
- IF TRUE
- THEN
- DELETE FROM available WHERE calc_id NOT IN (
- SELECT cc.id
- FROM `cache` c
- JOIN cache_calc cc ON c.id = cc.cache_id
- WHERE c.`name` = 'available');
-
-
- END IF;
-
-
-
- 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;
-
-
-
- DROP TEMPORARY TABLE IF EXISTS item_range;
- CREATE TEMPORARY TABLE item_range
- (PRIMARY KEY (item_id))
- ENGINE = MEMORY
- SELECT c.item_id, IF(t.life IS NULL, NULL, TIMESTAMP(TIMESTAMPADD(DAY, t.life, c.landing), '23:59:59')) AS date_end
- FROM (
- SELECT c.Id_Article item_id, MAX(landing) landing
- 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 = v_warehouse
- AND NOT e.Inventario
- AND NOT e.Redada
- GROUP BY Id_Article
- ) 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_copy1;
- CREATE TEMPORARY TABLE item_range_copy1 LIKE item_range;
- INSERT INTO item_range_copy1
- SELECT * FROM item_range;
-
- DROP TEMPORARY TABLE IF EXISTS item_range_copy2;
- CREATE TEMPORARY TABLE item_range_copy2 LIKE item_range;
- INSERT INTO item_range_copy2
- SELECT * FROM item_range;
-
- DROP TEMPORARY TABLE IF EXISTS item_range_copy3;
- CREATE TEMPORARY TABLE item_range_copy3 LIKE item_range;
- INSERT INTO item_range_copy3
- SELECT * FROM item_range;
-
- DROP TEMPORARY TABLE IF EXISTS item_range_copy4;
- CREATE TEMPORARY TABLE item_range_copy4 LIKE item_range;
- INSERT INTO item_range_copy4
- SELECT * FROM item_range;
-
-
-
- DELETE FROM available WHERE calc_id = v_calc;
-
- INSERT INTO available (calc_id, item_id, available)
- SELECT v_calc, t.item_id, SUM(stock) amount 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 = v_warehouse
- 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 = v_warehouse
- 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 = v_warehouse
- 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 = v_warehouse
- 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 amount != 0;
-
- DROP TEMPORARY TABLE
- vn2008.tmp_item
- ,item_range
- ,item_range_copy1
- ,item_range_copy2
- ,item_range_copy3
- ,item_range_copy4;
-
- CALL cache_calc_end (v_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 `barcodes_articles_update` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `barcodes_articles_update`()
-BEGIN
-
-REPLACE cache.barcodes
-
- SELECT
- `Articles`.`Id_Article` AS `code`,
- `Articles`.`Id_Article` AS `Id_Article`,
- `Articles`.`Article` AS `Article`,
- `Articles`.`Medida` AS `Medida`,
- `Articles`.`Color` AS `Color`,
- `Articles`.`Categoria` AS `Categoria`,
- `p`.`name` AS `Producer`
- FROM
- vn2008.Articles
- LEFT JOIN vn2008.`producer` `p` using(producer_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 */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `barcodes_barcodes_update` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `barcodes_barcodes_update`()
-BEGIN
-
-REPLACE cache.barcodes
-
- SELECT
- `barcodes`.`code` AS `code`,
- `barcodes`.`Id_Article` AS `Id_Article`,
- `Articles`.`Article` AS `Article`,
- `Articles`.`Medida` AS `Medida`,
- `Articles`.`Color` AS `Color`,
- `Articles`.`Categoria` AS `Categoria`,
- `p`.`name` AS `Producer`
- FROM
- vn2008.`barcodes`
- JOIN
- vn2008.Articles using(Id_Article)
- LEFT JOIN vn2008.`producer` `p` using(producer_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 */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `barcodes_compres_update` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `barcodes_compres_update`()
-BEGIN
-
-REPLACE cache.barcodes
-
- SELECT
- Compres.`Id_Compra` AS `code`,
- Compres.`Id_Article` AS `Id_Article`,
- `Articles`.`Article` AS `Article`,
- `Articles`.`Medida` AS `Medida`,
- `Articles`.`Color` AS `Color`,
- `Articles`.`Categoria` AS `Categoria`,
- producer.`name` AS `Producer`
-
-
- FROM
- vn2008.Compres
- JOIN vn2008.Articles using(Id_Article)
- LEFT JOIN vn2008.producer using(producer_id)
- JOIN vn2008.Entradas using(Id_Entrada)
- JOIN vn2008.travel on travel.id = travel_id
- WHERE
- landing >= TIMESTAMPADD(WEEK, -2, 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 */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `barcodes_expeditions_update` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `barcodes_expeditions_update`(IN idExpedition BIGINT)
-BEGIN
-
-REPLACE cache.barcodes
-
- SELECT
- `e`.`expeditions_id` AS `code`,
- `Tickets`.`Id_Ruta` AS `Id_Article`,
- `Tickets`.`Alias` AS `Article`,
- `Tickets`.`Bultos` AS `Medida`,
- `Tickets`.`Id_Ruta` AS `Color`,
- `w`.`name` AS `Categoria`,
- `a`.`Agencia` AS `Producer`
- FROM
- vn2008.expeditions `e`
- JOIN vn2008.Tickets ON `Tickets`.`Id_Ticket` = `e`.`ticket_id`
- JOIN vn2008.warehouse `w` ON `w`.`id` = `Tickets`.`warehouse_id`
- JOIN vn2008.Rutas `r` ON `r`.`Id_Ruta` = `Tickets`.`Id_Ruta`
- JOIN vn2008.Agencias `a` ON `a`.`Id_Agencia` = `r`.`Id_Agencia`
- WHERE
- idExpedition IN (e.expeditions_id,0)
- AND
- `Tickets`.`Fecha` >= (CURDATE() + INTERVAL -(2) DAY)
-
-
- ;
-
-
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `barcodes_update` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `barcodes_update`()
-BEGIN
-
- declare allExpeditions int default 0;
-
- call barcodes_articles_update;
-
- call barcodes_barcodes_update;
-
- call barcodes_compres_update;
-
- call barcodes_expeditions_update(allExpeditions);
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `cacheCalcClean` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `cacheCalcClean`()
-BEGIN
- DECLARE vCleanTime DATETIME DEFAULT TIMESTAMPADD(MINUTE, -5, NOW());
-
- DELETE FROM cache_calc WHERE expires < vCleanTime;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `cache_calc_end` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `cache_calc_end`(v_calc INT)
-BEGIN
- DECLARE v_cache_name VARCHAR(255);
- DECLARE v_params VARCHAR(255);
-
-
-
- UPDATE cache_calc cc JOIN cache c ON c.id = cc.cache_id
- SET
- cc.last_refresh = NOW(),
- cc.expires = ADDTIME(NOW(), c.lifetime),
- cc.connection_id = NULL
- WHERE cc.id = v_calc;
-
- SELECT c.name, ca.params INTO v_cache_name, v_params
- FROM cache c
- JOIN cache_calc ca ON c.id = ca.cache_id
- WHERE ca.id = v_calc;
-
- DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, '')));
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `cache_calc_start` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `cache_calc_start`(OUT v_calc INT, INOUT v_refresh BOOL, v_cache_name VARCHAR(50), v_params VARCHAR(100))
-proc: BEGIN
- DECLARE v_valid BOOL;
- DECLARE v_lock_id VARCHAR(100);
- DECLARE v_cache_id INT;
- DECLARE v_expires DATETIME;
- DECLARE v_clean_time DATETIME;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- DO RELEASE_LOCK(v_lock_id);
- RESIGNAL;
- END;
-
- SET v_params = IFNULL(v_params, '');
-
-
-
- SELECT COUNT(*) > 0 INTO v_valid FROM cache_valid;
-
- IF !v_valid
- THEN
- DELETE FROM cache_calc;
- INSERT INTO cache_valid (valid) VALUES (TRUE);
- END IF;
-
-
-
- SET v_lock_id = CONCAT_WS('/', v_cache_name, v_params);
-
- IF !GET_LOCK(v_lock_id, 30)
- THEN
- SET v_calc = NULL;
- SET v_refresh = FALSE;
- LEAVE proc;
- END IF;
-
-
-
- SELECT c.id, ca.id, ca.expires
- INTO v_cache_id, v_calc, v_expires
- FROM cache c
- LEFT JOIN cache_calc ca
- ON ca.cache_id = c.id AND ca.params = v_params COLLATE 'utf8_general_ci'
- WHERE c.name = v_cache_name COLLATE 'utf8_general_ci';
-
-
-
- IF !v_refresh AND NOW() < v_expires
- THEN
- DO RELEASE_LOCK(v_lock_id);
- SET v_refresh = FALSE;
- LEAVE proc;
- END IF;
-
-
-
- IF v_calc IS NULL
- THEN
- INSERT INTO cache_calc SET
- cache_id = v_cache_id,
- cacheName = v_cache_name,
- params = v_params,
- last_refresh = NULL,
- expires = NULL,
- connection_id = CONNECTION_ID();
-
- SET v_calc = LAST_INSERT_ID();
- ELSE
- UPDATE cache_calc
- SET
- last_refresh = NULL,
- expires = NULL,
- connection_id = CONNECTION_ID()
- WHERE id = v_calc;
- END IF;
-
-
-
- SET v_refresh = 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 `cache_calc_unlock` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `cache_calc_unlock`(v_calc INT)
-BEGIN
- DECLARE v_cache_name VARCHAR(50);
- DECLARE v_params VARCHAR(100);
-
- SELECT c.name, ca.params INTO v_cache_name, v_params
- FROM cache c
- JOIN cache_calc ca ON c.id = ca.cache_id
- WHERE ca.id = v_calc;
-
- DELETE FROM cache_calc WHERE id = v_calc;
-
- DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, '')));
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!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`()
-BEGIN
-
- DECLARE vDateShort DATETIME;
-
- SET vDateShort = TIMESTAMPADD(MONTH, -1, CURDATE());
-
- INSERT INTO cache.daily_task_log(state) VALUES('clean START');
-
- DELETE FROM cache.departure_limit WHERE Fecha < vDateShort;
-
- INSERT INTO cache.daily_task_log(state) 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 `departure_timing` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `departure_timing`()
-BEGIN
-
-DECLARE done BOOL DEFAULT FALSE;
-DECLARE rsDeparture INT;
-DECLARE rsHoras DECIMAL(5,2);
-DECLARE rsInicio DECIMAL(5,2);
-DECLARE resto DECIMAL(5,2);
-DECLARE horasProd DECIMAL(5,2);
-DECLARE inicioProd DECIMAL(5,2) DEFAULT 24.00;
-DECLARE myTime DECIMAL(5,2);
-DECLARE departureLimit INT;
-DECLARE myWarehouse INT;
-DECLARE myMinSpeed DECIMAL(10,2);
-
-
-DECLARE rs CURSOR FOR
- SELECT Departure
- , Sum(pb.m3)/(GREATEST(v.m3,IFNULL(minSpeed,0))/1.3) AS Horas
- , curDate()+(Departure-(Sum(pb.m3)/(GREATEST(v.m3,IFNULL(minSpeed,0))/1.3))/24) AS InicioPreparacion
- FROM tmp.production_buffer pb
- JOIN vn2008.v_encajado_ultima_hora v ON v.warehouse_id = pb.warehouse_id
- LEFT JOIN cache.departure_limit dp ON dp.warehouse_id = pb.warehouse_id AND dp.fecha = CURDATE()
- WHERE pb.Fecha = CURDATE()
- AND alert_level < 2
- AND IFNULL(Departure,0) > 0
- GROUP BY Departure
- ORDER BY Departure DESC;
-
-DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-
-SET myTime = HOUR(now()) + MINUTE(now()) / 60;
-
-SELECT warehouse_id INTO myWarehouse
-FROM tmp.production_buffer
-LIMIT 1;
-
-OPEN rs;
-
-FETCH rs INTO rsDeparture, rsHoras , rsInicio;
-
-
-
-WHILE NOT done DO
-
- SET resto = IF(inicioProd < rsDeparture, rsDeparture - inicioProd,0);
-
- SET inicioProd = rsDeparture - rsHoras;
-
- IF inicioProd - resto < myTime THEN
-
- SET done = TRUE;
-
- ELSE
-
- SET departureLimit = rsDeparture;
-
- FETCH rs INTO rsDeparture, rsHoras , rsInicio;
-
-
-
- END IF;
-
-END WHILE;
-
-SET departureLimit = IFNULL(departureLimit,24);
-SET departureLimit = IF(departureLimit = 0, 24, departureLimit);
-
- SELECT minSpeed INTO myMinSpeed
- FROM cache.departure_limit
- WHERE warehouse_id = myWarehouse
- AND fecha = CURDATE();
-
- REPLACE cache.departure_limit(warehouse_id, fecha, hora, minSpeed)
- VALUES (myWarehouse, CURDATE(), IFNULL(departureLimit,24), IFNULL(myMinSpeed,0));
-
-
-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 `departure_timing_beta` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `departure_timing_beta`()
-BEGIN
-
-DECLARE done BOOL DEFAULT FALSE;
-DECLARE rsDeparture INT;
-DECLARE rsHoras DECIMAL(5,2);
-DECLARE rsInicio DECIMAL(5,2);
-DECLARE resto DECIMAL(5,2);
-DECLARE horasProd DECIMAL(5,2);
-DECLARE inicioProd DECIMAL(5,2) DEFAULT 24.00;
-DECLARE myTime DECIMAL(5,2);
-DECLARE departureLimit INT;
-DECLARE myWarehouse INT;
-
-DECLARE rs CURSOR FOR
- SELECT Departure
- , Sum(pb.m3)/GREATEST(v.m3,IFNULL(minSpeed,0)) AS Horas
- , curDate()+(Departure-(Sum(pb.m3)/GREATEST(v.m3,IFNULL(minSpeed,0)))/24) AS InicioPreparacion
- FROM tmp.production_buffer pb
- JOIN vn2008.v_encajado_ultima_hora v ON v.warehouse_id = pb.warehouse_id
- LEFT JOIN cache.departure_limit dp ON dp.warehouse_id = pb.warehouse_id AND dp.fecha = CURDATE()
- WHERE pb.Fecha = CURDATE()
- AND alert_level < 2
- AND IFNULL(Departure,0) > 0
- GROUP BY Departure
- ORDER BY Departure DESC;
-
-DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-
-
-
-SET myTime = HOUR(now()) + MINUTE(now()) / 60;
-
-SELECT warehouse_id INTO myWarehouse
-FROM tmp.production_buffer
-LIMIT 1;
-
-OPEN rs;
-
-FETCH rs INTO rsDeparture, rsHoras , rsInicio;
-
-SELECT rsDeparture, rsHoras , rsInicio, myWarehouse, done;
-
-WHILE NOT done DO
-
- SET resto = IF(inicioProd < rsDeparture, rsDeparture - inicioProd,0);
-
- SET inicioProd = rsDeparture - rsHoras;
-
- SELECT rsDeparture, rsHoras , rsInicio, resto,inicioProd;
-
- IF inicioProd - resto < myTime THEN
-
- SET done = TRUE;
-
- ELSE
-
- SET departureLimit = rsDeparture;
-
- FETCH rs INTO rsDeparture, rsHoras , rsInicio;
-
- END IF;
-
-END WHILE;
-
-SELECT rsDeparture, rsHoras , rsInicio, resto,inicioProd;
-
-
-SET departureLimit = IFNULL(departureLimit,24);
-
-IF departureLimit > 0 THEN
-
- REPLACE cache.departure_limit(warehouse_id, fecha, hora, minSpeed)
- VALUES (myWarehouse, CURDATE(), departureLimit, myMinSpeed);
-
-END IF;
-
-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 */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `departure_timing_kk` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `departure_timing_kk`()
-BEGIN
-
-DECLARE done BOOL DEFAULT FALSE;
-DECLARE rsDeparture INT;
-DECLARE rsHoras DECIMAL(5,2);
-DECLARE rsInicio DECIMAL(5,2);
-DECLARE resto DECIMAL(5,2);
-DECLARE horasProd DECIMAL(5,2);
-DECLARE inicioProd DECIMAL(5,2) DEFAULT 24.00;
-DECLARE myTime DECIMAL(5,2);
-DECLARE departureLimit INT;
-DECLARE myWarehouse INT;
-DECLARE myMinSpeed DECIMAL(10,2);
-
-
-DECLARE rs CURSOR FOR
- SELECT Departure
- , Sum(pb.m3)/(GREATEST(v.m3, 100)/1.3) AS Horas
- , curDate()+(Departure-Sum(pb.m3)/(GREATEST(v.m3, 100)/1.3))/24 AS InicioPreparacion
- FROM tmp.production_buffer pb
- JOIN vn2008.v_encajado_ultima_hora v ON v.warehouse_id = pb.warehouse_id
- WHERE Fecha = CURDATE()
- AND alert_level < 2
- AND IFNULL(Departure,0) > 0
- GROUP BY Departure
- ORDER BY Departure DESC;
-
-DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
-
-SELECT IFNULL(minSpeed,0) INTO myMinSpeed
-FROM cache.departure_limit
-WHERE warehouse_id = myWarehouse
-AND fecha = CURDATE();
-
-SET myTime = HOUR(now()) + MINUTE(now()) / 60;
-
-SELECT warehouse_id INTO myWarehouse
-FROM tmp.production_buffer
-LIMIT 1;
-
-OPEN rs;
-
-FETCH rs INTO rsDeparture, rsHoras , rsInicio;
-
-WHILE NOT done DO
-
- SET resto = IF(inicioProd < rsDeparture, rsDeparture - inicioProd,0);
-
- SET inicioProd = rsDeparture - rsHoras;
-
- IF inicioProd - resto < myTime THEN
-
- SET done = TRUE;
-
- ELSE
-
- SET departureLimit = rsDeparture;
-
- FETCH rs INTO rsDeparture, rsHoras , rsInicio;
-
- END IF;
-
-END WHILE;
-
-IF departureLimit > 0 THEN
-
- REPLACE cache.departure_limit(warehouse_id, fecha, hora, minSpeed)
- VALUES (myWarehouse, CURDATE(), departureLimit, myMinSpeed);
-
-END IF;
-
-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 */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `equaliza` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `equaliza`(wh_id INT)
-BEGIN
-
-
-
-
- CALL equalizator_refresh (FALSE, wh_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 */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `equalizator_refresh` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `equalizator_refresh`(v_refresh BOOL, wh_id INT)
-proc: BEGIN
- DECLARE datEQ DATETIME;
- DECLARE timDIF TIME;
- DECLARE v_calc INT;
-
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `item_range_refresh` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `item_range_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT, v_date DATE)
-proc: BEGIN
- DECLARE v_params CHAR(100);
- DECLARE v_date_inv DATE;
-
- IF v_date < CURDATE()
- THEN
- LEAVE proc;
- END IF;
-
- SET v_params = CONCAT_WS('/', v_warehouse, v_date);
- CALL cache_calc_start (v_calc, v_refresh, 'item_range', v_params);
-
- IF !v_refresh
- THEN
- LEAVE proc;
- END IF;
-
-
-
- DELETE FROM item_range WHERE calc_id NOT IN (
- SELECT cc.id
- FROM `cache` c
- JOIN cache_calc cc ON c.id = cc.cache_id
- WHERE c.`name` = 'item_range');
-
-
-
- CALL last_buy_refresh (FALSE);
-
- SET v_date_inv = vn2008.date_inv();
-
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.item_range;
- CREATE TEMPORARY TABLE tmp.item_range
- (INDEX (item_id))
- ENGINE = MEMORY
- SELECT c.item_id, IF(t.life IS NULL, NULL, TIMESTAMPADD(DAY, t.life + 1, GREATEST(c.landing, b.landing))) AS date_end
- FROM last_buy b
- JOIN (
- SELECT c.Id_Article item_id, MAX(landing) landing
- 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
- AND t.warehouse_id = v_warehouse
- AND NOT e.Inventario
- AND NOT e.Redada
- GROUP BY item_id
- ) c ON c.item_id = b.item_id
- JOIN vn2008.Articles a ON a.Id_Article = b.item_id
- JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id
- WHERE b.warehouse_id = v_warehouse
- HAVING date_end >= v_date OR date_end IS NULL;
-
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.fix_range;
- CREATE TEMPORARY TABLE tmp.fix_range
- ENGINE = MEMORY
- SELECT item_id, date_end FROM (
- SELECT p.item_id, p.date_end
- FROM vn2008.price_fixed p
- LEFT JOIN tmp.item_range i USING(item_id)
- WHERE IFNULL(i.date_end, v_date) BETWEEN p.date_start AND p.date_end
- AND warehouse_id IN (0, v_warehouse)
- ORDER BY item_id, warehouse_id DESC, date_end DESC
- ) t GROUP BY item_id;
-
-
-
- DELETE FROM item_range WHERE calc_id = v_calc;
-
- INSERT INTO item_range (calc_id, item_id, date_end)
- SELECT v_calc, item_id, date_end
- FROM (
- SELECT * FROM tmp.fix_range
- UNION ALL
- SELECT * FROM tmp.item_range
- ) t
- GROUP BY item_id;
-
-
-
- DROP TEMPORARY TABLE tmp.item_range;
- DROP TEMPORARY TABLE tmp.fix_range;
-
- CALL cache_calc_end (v_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 */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `last_buy_refresh` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `last_buy_refresh`(v_refresh BOOL)
-proc: BEGIN
-
- DECLARE v_calc INT;
- DECLARE v_date_ini DATE;
- DECLARE v_date_end DATE;
- DECLARE v_last_refresh DATE;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- CALL cache_calc_unlock (v_calc);
- RESIGNAL;
- END;
-
- CALL cache_calc_start (v_calc, v_refresh, 'last_buy', NULL);
-
- IF !v_refresh
- THEN
- LEAVE proc;
- END IF;
-
-
- SET v_date_ini = vn2008.date_inv();
- SET v_date_end = CURDATE();
-
- CALL vn2008.item_last_buy_from_interval (NULL, v_date_ini, v_date_end);
-
- DELETE FROM last_buy;
-
- INSERT INTO last_buy (item_id, warehouse_id, buy_id, landing)
- SELECT item_id, warehouse_id, buy_id, landing
- FROM tmp.item_last_buy_from_interval;
-
- DROP TEMPORARY TABLE tmp.item_last_buy_from_interval;
-
- CALL cache_calc_end (v_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 */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `prod_graphic_refresh` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `prod_graphic_refresh`(v_refresh BOOL, wh_id INT)
-proc: BEGIN
- DECLARE datEQ DATETIME;
- DECLARE timDIF TIME;
- DECLARE v_calc INT;
-
- CALL cache_calc_start (v_calc, v_refresh, 'prod_graphic', wh_id);
-
- IF !v_refresh
- THEN
- LEAVE proc;
- END IF;
-
- CALL vn2008.production_control_source(wh_id, 0);
-
- DELETE FROM prod_graphic_source;
-
- INSERT INTO prod_graphic_source (warehouse_id, alert_level, m3, hora, `order`, Agencia)
- SELECT
- wh_id,
- pb.alert_level,
- m3,
- pb.Hora,
- pb.state_order,
- pb.Agencia
- FROM tmp.production_buffer pb
- WHERE Fecha = CURDATE()
- ;
-
-
- CALL cache_calc_end (v_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 */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `sales_refresh` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `sales_refresh`()
-proc:BEGIN
-
- DECLARE v_calc INT;
- DECLARE v_refresh BOOL DEFAULT TRUE;
- DECLARE datMONTH INT;
- DECLARE datYEAR INT;
-
- CALL cache_calc_start (v_calc, v_refresh, 'sales', NULL);
-
- IF !v_refresh
- THEN
- LEAVE proc;
- END IF;
-
-
- SELECT MONTH(CURDATE()) INTO datMONTH;
- SELECT YEAR(CURDATE()) INTO datYEAR;
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.periods;
- CREATE TEMPORARY TABLE tmp.periods
- select distinct month, year(date) as year
- from vn2008.time
- where date <= CURDATE()
- order by year desc, month desc
- limit 3;
-
-
- DELETE s.*
- FROM bi.sales s
- join tmp.periods using(year,month);
-
-
- REPLACE bi.sales(Id_Trabajador, year, month, weight, boss_id)
- select v.Id_Trabajador, year, month, round(sum(total)) as weight, IFNULL(j.boss_id,20)
- from bi.v_ticket_total v
- join tmp.periods using(year,month)
- left join (SELECT jerarquia.boss_id, jerarquia.worker_id
- FROM vn2008.jerarquia
- ) j on j.worker_id = v.Id_Trabajador
- group by v.Id_Trabajador, year, month;
-
-
-
-
-
-
-
-
-
-
-
-update bi.sales s
-set comision = weight * 0.029;
-
- DROP TEMPORARY TABLE IF EXISTS tmp.periods;
-
- CALL cache_calc_end (v_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 */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `stock_refresh` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `stock_refresh`(v_refresh BOOL)
-proc: BEGIN
-
- DECLARE v_calc INT;
- DECLARE v_date_inv DATE;
- DECLARE v_curdate DATE;
- DECLARE v_last_refresh DATETIME;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- CALL cache_calc_unlock (v_calc);
- RESIGNAL;
- END;
-
- CALL cache_calc_start (v_calc, v_refresh, 'stock', NULL);
-
- IF !v_refresh
- THEN
- LEAVE proc;
- END IF;
-
- SET v_date_inv = (SELECT FechaInventario FROM vn2008.tblContadores LIMIT 1);
- SET v_curdate = CURDATE();
-
- DELETE FROM stock;
-
- INSERT INTO stock (item_id, warehouse_id, amount)
- SELECT item_id, warehouse_id, SUM(amount) amount FROM
- (
- SELECT item_id, warehouse_id, amount FROM vn2008.item_out
- WHERE dat >= v_date_inv AND dat < v_curdate
- UNION ALL
- SELECT item_id, warehouse_id, amount FROM vn2008.item_entry_in
- WHERE dat >= v_date_inv AND dat < v_curdate
- UNION ALL
- SELECT item_id ,warehouse_id, amount FROM vn2008.item_entry_out
- WHERE dat >= v_date_inv AND dat < v_curdate
- ) t
- GROUP BY item_id, warehouse_id HAVING amount != 0;
-
- CALL cache_calc_end (v_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 `visible_refresh` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `visible_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT)
-proc: BEGIN
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- CALL cache_calc_unlock (v_calc);
- RESIGNAL;
- END;
-
- CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse);
-
- IF !v_refresh
- THEN
- LEAVE proc;
- END IF;
-
-
-
- IF TRUE
- THEN
- DELETE FROM visible WHERE calc_id NOT IN (
- SELECT cc.id
- FROM `cache` c
- JOIN cache_calc cc ON c.id = cc.cache_id
- WHERE c.`name` = 'visible');
-
-
- END IF;
-
-
-
- CALL `cache`.stock_refresh(false);
-
- DROP TEMPORARY TABLE IF EXISTS vn2008.tmp_item;
- CREATE TEMPORARY TABLE vn2008.tmp_item
- (PRIMARY KEY (item_id))
- ENGINE = MEMORY
- SELECT item_id, amount stock, amount visible FROM `cache`.stock
- WHERE warehouse_id = v_warehouse;
-
-
-
- CALL vn2008.item_stock_visible(v_warehouse, NULL);
-
- DELETE FROM visible WHERE calc_id = v_calc;
-
- INSERT INTO visible (calc_id, item_id,visible)
- SELECT v_calc, item_id, visible FROM vn2008.tmp_item;
-
- CALL cache_calc_end (v_calc);
-
- DROP TEMPORARY TABLE vn2008.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 */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `weekly_sales_refresh` */;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `weekly_sales_refresh`(v_refresh BOOL)
-BEGIN
- DECLARE v_week_ini INT;
- DECLARE v_week_end INT;
- DECLARE v_date_ini DATE;
- DECLARE v_date_end DATE;
- DECLARE v_last_refresh DATE;
-
- IF GET_LOCK('weekly_sales', 300)
- THEN
- SELECT last_refresh INTO v_last_refresh FROM weekly_sales_info;
-
- IF v_last_refresh IS NULL THEN
- SET v_refresh = TRUE;
- END IF;
-
- IF v_refresh || v_last_refresh < CURDATE()
- THEN
- SET v_date_ini = TIMESTAMPADD(DAY, -(366 * 1.5), CURDATE());
- SET v_date_end = TIMESTAMPADD(DAY, -1, CURDATE());
-
- IF v_refresh
- THEN
- TRUNCATE TABLE weekly_sales;
- ELSE
- SET v_week_ini = vn2008.to_weeks (v_date_ini);
- SET v_date_ini = TIMESTAMPADD(DAY, -WEEKDAY(v_last_refresh) - 7, v_last_refresh);
- SET v_week_end = vn2008.to_weeks (v_date_ini);
-
- DELETE FROM weekly_sales
- WHERE week < v_week_ini OR week >= v_week_end;
- END IF;
-
- CALL vn2008.weekly_sales_new (0, v_date_ini, v_date_end);
-
- INSERT INTO weekly_sales (item_id, week, warehouse_id, amount, price)
- SELECT item_id, week, warehouse_id, amount, price FROM vn2008.weekly_sales;
-
- DROP TEMPORARY TABLE vn2008.weekly_sales;
-
- TRUNCATE TABLE weekly_sales_info;
- INSERT INTO weekly_sales_info (last_refresh) VALUES (CURDATE());
- END IF;
-
- DO RELEASE_LOCK('weekly_sales');
- 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 */ ;
-ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Current Database: `pbx`
---
-
-CREATE DATABASE /*!32312 IF NOT EXISTS*/ `pbx` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
-
-USE `pbx`;
-
---
--- Table structure for table `blacklist`
---
-
-DROP TABLE IF EXISTS `blacklist`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `blacklist` (
- `phone` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`phone`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Hangup input calls from this list';
-/*!40101 SET character_set_client = @saved_cs_client */;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `pbx`.`blacklistBeforeInsert`
-BEFORE INSERT ON `blacklist` FOR EACH ROW
-BEGIN
- CALL phoneIsValid (NEW.phone);
-END */;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `pbx`.`blacklistBerforeUpdate`
-BEFORE UPDATE ON `blacklist` FOR EACH ROW
-BEGIN
- CALL phoneIsValid (NEW.phone);
-END */;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Table structure for table `cdr`
---
-
-DROP TABLE IF EXISTS `cdr`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `cdr` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `call_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `clid` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
- `src` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
- `dst` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
- `dcontext` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
- `channel` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
- `dst_channel` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
- `last_app` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
- `last_data` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
- `duration` int(11) NOT NULL DEFAULT '0',
- `billsec` int(11) NOT NULL DEFAULT '0',
- `disposition` varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
- `ama_flags` int(11) NOT NULL DEFAULT '0',
- `account_code` varchar(20) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
- `unique_id` varchar(32) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
- `user_field` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
- PRIMARY KEY (`id`),
- KEY `calldate` (`call_date`),
- KEY `dst` (`dst`),
- KEY `accountcode` (`account_code`),
- KEY `dstchannel` (`dst_channel`),
- KEY `disposition` (`disposition`),
- KEY `src` (`src`)
-) ENGINE=MyISAM AUTO_INCREMENT=156174 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `cdrConf`
---
-
-DROP TABLE IF EXISTS `cdrConf`;
-/*!50001 DROP VIEW IF EXISTS `cdrConf`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `cdrConf` 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 `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(10) unsigned NOT NULL AUTO_INCREMENT,
- `sundayFestive` tinyint(4) NOT NULL,
- `countryPrefix` varchar(20) CHARACTER SET utf8 DEFAULT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `followme`
---
-
-DROP TABLE IF EXISTS `followme`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `followme` (
- `extension` varchar(128) CHARACTER SET utf8 NOT NULL,
- `phone` varchar(20) CHARACTER SET utf8 NOT NULL,
- PRIMARY KEY (`extension`),
- CONSTRAINT `followme_ibfk_1` FOREIGN KEY (`extension`) REFERENCES `sip` (`extension`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `pbx`.`followmeBeforeInsert`
-BEFORE INSERT ON `followme` FOR EACH ROW
-BEGIN
- CALL pbx.phoneIsValid (NEW.phone);
-END */;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `pbx`.`followmeBeforeUpdate`
-BEFORE UPDATE ON `followme` FOR EACH ROW
-BEGIN
- CALL pbx.phoneIsValid (NEW.phone);
-END */;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Temporary view structure for view `followmeConf`
---
-
-DROP TABLE IF EXISTS `followmeConf`;
-/*!50001 DROP VIEW IF EXISTS `followmeConf`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `followmeConf` AS SELECT
- 1 AS `name`,
- 1 AS `music`,
- 1 AS `context`,
- 1 AS `takecall`,
- 1 AS `declinecall`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `followmeConfig`
---
-
-DROP TABLE IF EXISTS `followmeConfig`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `followmeConfig` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `music` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
- `context` varchar(50) CHARACTER SET utf8 NOT NULL,
- `takeCall` char(1) CHARACTER SET utf8 NOT NULL,
- `declineCall` char(1) CHARACTER SET utf8 NOT NULL,
- `timeout` int(11) NOT NULL,
- 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 `followmeNumberConf`
---
-
-DROP TABLE IF EXISTS `followmeNumberConf`;
-/*!50001 DROP VIEW IF EXISTS `followmeNumberConf`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `followmeNumberConf` AS SELECT
- 1 AS `name`,
- 1 AS `ordinal`,
- 1 AS `phonenumber`,
- 1 AS `timeout`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `queue`
---
-
-DROP TABLE IF EXISTS `queue`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `queue` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `description` varchar(128) CHARACTER SET utf8 NOT NULL,
- `name` varchar(128) CHARACTER SET utf8 NOT NULL,
- `config` int(10) unsigned NOT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `name` (`name`),
- UNIQUE KEY `description` (`description`),
- KEY `config` (`config`),
- CONSTRAINT `queue_ibfk_1` FOREIGN KEY (`config`) REFERENCES `queueConfig` (`id`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queues';
-/*!40101 SET character_set_client = @saved_cs_client */;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `pbx`.`queueBeforeInsert`
-BEFORE INSERT ON `queue` FOR EACH ROW
-BEGIN
- CALL queueIsValid (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 */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `pbx`.`queueBeforeUpdate`
-BEFORE UPDATE ON `queue` FOR EACH ROW
-BEGIN
- CALL queueIsValid (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 */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Temporary view structure for view `queueConf`
---
-
-DROP TABLE IF EXISTS `queueConf`;
-/*!50001 DROP VIEW IF EXISTS `queueConf`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `queueConf` AS SELECT
- 1 AS `name`,
- 1 AS `strategy`,
- 1 AS `timeout`,
- 1 AS `retry`,
- 1 AS `weight`,
- 1 AS `maxlen`,
- 1 AS `ringinuse`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `queueConfig`
---
-
-DROP TABLE IF EXISTS `queueConfig`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `queueConfig` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `strategy` varchar(128) CHARACTER SET utf8 NOT NULL,
- `timeout` int(10) unsigned NOT NULL,
- `retry` int(10) unsigned NOT NULL,
- `weight` int(10) unsigned NOT NULL,
- `maxLen` int(10) unsigned NOT NULL,
- `ringInUse` tinyint(4) NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Default values for queues configuration';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `queueMember`
---
-
-DROP TABLE IF EXISTS `queueMember`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `queueMember` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `queue` varchar(128) CHARACTER SET utf8 NOT NULL,
- `extension` varchar(128) CHARACTER SET utf8 NOT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `queue` (`queue`,`extension`),
- KEY `extension` (`extension`),
- CONSTRAINT `queueMember_ibfk_1` FOREIGN KEY (`queue`) REFERENCES `queue` (`name`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `queueMember_ibfk_2` FOREIGN KEY (`extension`) REFERENCES `sip` (`extension`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queue members';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `queueMemberConf`
---
-
-DROP TABLE IF EXISTS `queueMemberConf`;
-/*!50001 DROP VIEW IF EXISTS `queueMemberConf`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `queueMemberConf` AS SELECT
- 1 AS `uniqueid`,
- 1 AS `queue_name`,
- 1 AS `interface`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `queuePhone`
---
-
-DROP TABLE IF EXISTS `queuePhone`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `queuePhone` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `queue` varchar(128) CHARACTER SET utf8 NOT NULL,
- `phone` varchar(128) CHARACTER SET utf8 NOT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `queue` (`queue`,`phone`),
- CONSTRAINT `queuePhone_ibfk_1` FOREIGN KEY (`queue`) REFERENCES `queue` (`name`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `pbx`.`queuePhoneBeforeInsert`
-BEFORE INSERT ON `queuePhone` FOR EACH ROW
-BEGIN
- CALL phoneIsValid (NEW.phone);
-END */;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `pbx`.`queuePhoneBeforeUpdate`
-BEFORE UPDATE ON `queuePhone` FOR EACH ROW
-BEGIN
- CALL phoneIsValid (NEW.phone);
-END */;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Table structure for table `schedule`
---
-
-DROP TABLE IF EXISTS `schedule`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `schedule` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `weekDay` tinyint(3) unsigned NOT NULL COMMENT '0 = Monday, 6 = Sunday',
- `timeStart` time NOT NULL,
- `timeEnd` time NOT 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 `sip`
---
-
-DROP TABLE IF EXISTS `sip`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `sip` (
- `user_id` int(10) unsigned NOT NULL DEFAULT '0',
- `extension` varchar(128) CHARACTER SET utf8 NOT NULL,
- `secret` varchar(80) CHARACTER SET utf8 NOT NULL,
- `caller_id` varchar(80) CHARACTER SET utf8 NOT NULL,
- PRIMARY KEY (`user_id`),
- UNIQUE KEY `extension` (`extension`),
- CONSTRAINT `sip_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='SIP accounts';
-/*!40101 SET character_set_client = @saved_cs_client */;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `pbx`.`sipBeforeInsert`
-BEFORE INSERT ON `sip` FOR EACH ROW
-BEGIN
- CALL extensionIsValid (NEW.extension);
-END */;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `sipAfterInsert`
-AFTER INSERT ON `sip` FOR EACH ROW
-BEGIN
- INSERT INTO sipReg (userId) VALUES (NEW.user_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 */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `pbx`.`sipBeforeUpdate`
-BEFORE UPDATE ON `sip` FOR EACH ROW
-BEGIN
- CALL extensionIsValid (NEW.extension);
-END */;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Temporary view structure for view `sipConf`
---
-
-DROP TABLE IF EXISTS `sipConf`;
-/*!50001 DROP VIEW IF EXISTS `sipConf`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `sipConf` AS SELECT
- 1 AS `id`,
- 1 AS `name`,
- 1 AS `secret`,
- 1 AS `callerid`,
- 1 AS `host`,
- 1 AS `deny`,
- 1 AS `permit`,
- 1 AS `type`,
- 1 AS `context`,
- 1 AS `incominglimit`,
- 1 AS `pickupgroup`,
- 1 AS `careinvite`,
- 1 AS `ipaddr`,
- 1 AS `regseconds`,
- 1 AS `port`,
- 1 AS `defaultuser`,
- 1 AS `useragent`,
- 1 AS `lastms`,
- 1 AS `fullcontact`,
- 1 AS `regserver`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `sipConfig`
---
-
-DROP TABLE IF EXISTS `sipConfig`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `sipConfig` (
- `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
- `host` varchar(40) CHARACTER SET utf8 DEFAULT NULL,
- `deny` varchar(95) CHARACTER SET utf8 NOT NULL,
- `permit` varchar(95) CHARACTER SET utf8 NOT NULL,
- `type` enum('user','peer','friend') CHARACTER SET utf8 NOT NULL,
- `context` varchar(80) CHARACTER SET utf8 NOT NULL,
- `incomingLimit` varchar(10) CHARACTER SET utf8 NOT NULL,
- `pickupGroup` varchar(10) CHARACTER SET utf8 NOT NULL,
- `careInvite` varchar(10) CHARACTER SET utf8 NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Default values for SIP accounts';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `sipReg`
---
-
-DROP TABLE IF EXISTS `sipReg`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `sipReg` (
- `userId` int(10) unsigned NOT NULL,
- `ipAddr` varchar(40) CHARACTER SET utf8 DEFAULT NULL,
- `regSeconds` int(10) unsigned DEFAULT NULL,
- `port` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
- `defaultUser` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
- `userAgent` varchar(80) CHARACTER SET utf8 DEFAULT NULL,
- `lastMs` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
- `fullContact` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
- `regServer` varchar(20) CHARACTER SET utf8 DEFAULT NULL,
- PRIMARY KEY (`userId`),
- CONSTRAINT `sipReg_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `sip` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='SIP registrations';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Dumping events for database 'pbx'
---
-
---
--- Dumping routines for database 'pbx'
---
-/*!50003 DROP FUNCTION IF EXISTS `clientFromPhone` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `clientFromPhone`(vPhone VARCHAR(255)) RETURNS int(11)
- DETERMINISTIC
-BEGIN
- DECLARE vClient INT DEFAULT NULL;
-
-
-
-
-
- DROP TEMPORARY TABLE IF EXISTS tmp.customer;
- CREATE TEMPORARY TABLE tmp.customer
- ENGINE = MEMORY
- SELECT id_cliente customer
- FROM vn2008.Clientes c
- WHERE telefono = vPhone
- OR movil = vPhone
- UNION
- SELECT id_cliente
- FROM vn2008.Consignatarios
- WHERE telefono = vPhone
- OR movil = vPhone
- UNION
- SELECT r.id_cliente
- FROM vn2008.Relaciones r
- JOIN vn2008.Contactos c ON r.Id_Contacto = c.Id_Contacto
- WHERE c.telefono = vPhone
- OR c.movil = vPhone;
-
- SELECT t.customer INTO vClient
- FROM tmp.customer t
- JOIN vn2008.Clientes c ON c.id_cliente = t.customer
- WHERE c.activo
- LIMIT 1;
-
- DROP TEMPORARY TABLE tmp.customer;
-
- RETURN 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 FUNCTION IF EXISTS `phoneFormat` */;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `phoneFormat`(vPhone VARCHAR(255)) RETURNS varchar(255) CHARSET utf8
-BEGIN
- DECLARE vI INT DEFAULT 0;
- DECLARE vChr VARCHAR(1);
- DECLARE vLen INT DEFAULT LENGTH(vPhone);
- DECLARE vNewPhone VARCHAR(255) DEFAULT '';
-
- WHILE vI < vLen
- DO
- SET vChr = SUBSTR(vPhone, vI + 1, 1);
-
- IF vChr REGEXP '^[0-9]$'
- THEN
- SET vNewPhone = CONCAT(vNewPhone, vChr);
- ELSEIF vChr = '+' AND vI = 0
- THEN
- SET vNewPhone = CONCAT(vNewPhone, '00');
- END IF;
-
- SET vI = vI + 1;
- END WHILE;
-
- IF vNewPhone REGEXP '^0+$' OR vNewPhone = '' THEN
- RETURN NULL;
- END IF;
-
- IF vNewPhone REGEXP '^0034' THEN
- SET vNewPhone = SUBSTR(vNewPhone, 5);
- END IF;
-
- RETURN vNewPhone;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `extensionIsValid` */;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `extensionIsValid`(vExtension VARCHAR(255))
- DETERMINISTIC
-BEGIN
- DECLARE vIsValid BOOLEAN;
-
- SET vIsValid = vExtension IS NULL
- OR (vExtension REGEXP '^[0-9]{4}$'
- AND MOD(vExtension, 100) != 0);
-
- IF NOT vIsValid
- THEN
- SIGNAL SQLSTATE '45000'
- SET MESSAGE_TEXT = 'EXTENSION_INVALID_FORMAT';
- 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 */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `phoneIsValid` */;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `phoneIsValid`(vPhone VARCHAR(255))
-BEGIN
- DECLARE vIsValid BOOLEAN;
-
- SET vIsValid = vPhone IS NULL
- OR (vPhone REGEXP '^[0-9]+$'
- AND vPhone NOT REGEXP '^0+$'
- AND vPhone NOT REGEXP '^0034');
-
- IF NOT vIsValid
- THEN
- SIGNAL SQLSTATE '45000'
- SET MESSAGE_TEXT = 'PHONE_INVALID_FORMAT';
- 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 */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-/*!50003 DROP PROCEDURE IF EXISTS `queueIsValid` */;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `queueIsValid`(vQueue VARCHAR(255))
- DETERMINISTIC
-BEGIN
- DECLARE vIsValid BOOLEAN;
-
- SET vIsValid = vQueue IS NULL
- OR vQueue REGEXP '^[1-9][0-9]00$';
-
- IF NOT vIsValid
- THEN
- SIGNAL SQLSTATE '45000'
- SET MESSAGE_TEXT = 'QUEUE_INVALID_FORMAT';
- 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 */ ;
-ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
-
---
--- Current Database: `hedera`
---
-
-CREATE DATABASE /*!32312 IF NOT EXISTS*/ `hedera` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
-
-USE `hedera`;
-
---
--- Temporary view structure for view `address_view`
---
-
-DROP TABLE IF EXISTS `address_view`;
-/*!50001 DROP VIEW IF EXISTS `address_view`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `address_view` AS SELECT
- 1 AS `id`,
- 1 AS `customer_id`,
- 1 AS `warehouse_id`,
- 1 AS `name`,
- 1 AS `city`,
- 1 AS `province_id`,
- 1 AS `zip_code`,
- 1 AS `consignee`,
- 1 AS `default`,
- 1 AS `type_id`,
- 1 AS `specs`,
- 1 AS `insurance`,
- 1 AS `postage`,
- 1 AS `active`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `basket`
---
-
-DROP TABLE IF EXISTS `basket`;
-/*!50001 DROP VIEW IF EXISTS `basket`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `basket` 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 `company_id`,
- 1 AS `note`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `basket_defaults`
---
-
-DROP TABLE IF EXISTS `basket_defaults`;
-/*!50001 DROP VIEW IF EXISTS `basket_defaults`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `basket_defaults` AS SELECT
- 1 AS `address_id`,
- 1 AS `agency_id`,
- 1 AS `delivery_method`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `basket_item`
---
-
-DROP TABLE IF EXISTS `basket_item`;
-/*!50001 DROP VIEW IF EXISTS `basket_item`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `basket_item` AS SELECT
- 1 AS `id`,
- 1 AS `order_id`,
- 1 AS `warehouse_id`,
- 1 AS `item_id`,
- 1 AS `amount`,
- 1 AS `price`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `browser`
---
-
-DROP TABLE IF EXISTS `browser`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `browser` (
- `name` varchar(30) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Browser name in browscap',
- `version` float NOT NULL COMMENT 'Minimal version',
- UNIQUE KEY `name` (`name`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='List of compatible web browsers and its version';
-/*!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` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
- `default_lang` char(2) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The default language if none is specified',
- `https` tinyint(3) unsigned NOT NULL COMMENT 'Wether to force de use of HTTPS',
- `cookie_life` smallint(5) unsigned NOT NULL COMMENT 'The cookies life, in days',
- `jwtKey` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The key used to encode/decode JWT tokens',
- `default_form` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Form loaded at web login',
- `restUri` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `testRestUri` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `image_host` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL,
- `image_dir` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Directory where images are allocated',
- `guest_user` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Guest user name',
- `guest_pass` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Guest password, base64 encoded',
- `test_domain` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The address for beta website',
- `production_domain` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The address for production website',
- `pdfs_dir` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Directory where pdfs are allocated',
- PRIMARY KEY (`id`)
-) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `contact`
---
-
-DROP TABLE IF EXISTS `contact`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `contact` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `recipient` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- 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 `customer_user`
---
-
-DROP TABLE IF EXISTS `customer_user`;
-/*!50001 DROP VIEW IF EXISTS `customer_user`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `customer_user` AS SELECT
- 1 AS `user_id`,
- 1 AS `name`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `customer_view`
---
-
-DROP TABLE IF EXISTS `customer_view`;
-/*!50001 DROP VIEW IF EXISTS `customer_view`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `customer_view` AS SELECT
- 1 AS `user_id`,
- 1 AS `name`,
- 1 AS `email`,
- 1 AS `mail`,
- 1 AS `default_address`,
- 1 AS `credit`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `form`
---
-
-DROP TABLE IF EXISTS `form`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `form` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `description` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
- `path` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `role_id` int(10) unsigned NOT NULL,
- `parent` int(10) unsigned DEFAULT NULL,
- `display_order` tinyint(4) unsigned NOT NULL DEFAULT '1',
- PRIMARY KEY (`id`),
- KEY `group_id` (`role_id`),
- KEY `parent` (`parent`),
- CONSTRAINT `form_ibfk_1` FOREIGN KEY (`role_id`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE,
- CONSTRAINT `form_ibfk_2` FOREIGN KEY (`parent`) REFERENCES `form` (`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 `gallery`
---
-
-DROP TABLE IF EXISTS `gallery`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `gallery` (
- `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
- `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `comment` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=MyISAM AUTO_INCREMENT=33 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `image_config`
---
-
-DROP TABLE IF EXISTS `image_config`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `image_config` (
- `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Identifier',
- `max_size` int(10) unsigned NOT NULL COMMENT 'Maximun size for uploaded images in MB',
- `use_xsendfile` tinyint(4) NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global image parameters';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `image_file`
---
-
-DROP TABLE IF EXISTS `image_file`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `image_file` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `schema_id` int(10) unsigned NOT NULL,
- `file` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `stamp` int(11) DEFAULT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `schema_id_file` (`schema_id`,`file`),
- CONSTRAINT `image_file_ibfk_1` FOREIGN KEY (`schema_id`) REFERENCES `image_schema` (`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 `image_schema`
---
-
-DROP TABLE IF EXISTS `image_schema`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `image_schema` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `desc` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `max_width` int(10) unsigned NOT NULL,
- `max_height` int(10) unsigned NOT NULL,
- `schema` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `table` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `column` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `name` (`name`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `image_schema_size`
---
-
-DROP TABLE IF EXISTS `image_schema_size`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `image_schema_size` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `image_schema_id` int(10) unsigned NOT NULL,
- `width` int(10) unsigned NOT NULL,
- `height` int(10) unsigned NOT NULL,
- `crop` tinyint(3) unsigned NOT NULL DEFAULT '0',
- PRIMARY KEY (`id`),
- KEY `image_schema_id` (`image_schema_id`),
- CONSTRAINT `image_schema_size_ibfk_1` FOREIGN KEY (`image_schema_id`) REFERENCES `image_schema` (`id`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `invoice_view`
---
-
-DROP TABLE IF EXISTS `invoice_view`;
-/*!50001 DROP VIEW IF EXISTS `invoice_view`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `invoice_view` AS SELECT
- 1 AS `invoice_id`,
- 1 AS `serial_num`,
- 1 AS `issued`,
- 1 AS `amount`*/;
-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) unsigned 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` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
- `description` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `link` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `image` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=MyISAM AUTO_INCREMENT=35 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `location`
---
-
-DROP TABLE IF EXISTS `location`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `location` (
- `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
- `lat` varchar(12) COLLATE utf8_unicode_ci NOT NULL,
- `lng` varchar(12) COLLATE utf8_unicode_ci NOT NULL,
- `title` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `address` varchar(75) COLLATE utf8_unicode_ci DEFAULT NULL,
- `postcode` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
- `city` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `province` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `phone` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
- `language` char(2) COLLATE utf8_unicode_ci DEFAULT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `mail_config`
---
-
-DROP TABLE IF EXISTS `mail_config`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `mail_config` (
- `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Identifier',
- `host` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'localhost' COMMENT 'SMTP host',
- `port` smallint(6) NOT NULL DEFAULT '465' COMMENT 'SMTP port',
- `secure` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Wether to use a secure connection',
- `sender` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The sender mail address',
- `sender_name` varchar(75) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The sender name',
- `user` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'SMTP user',
- `password` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'SMTP password, base64 encoded',
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `metatag`
---
-
-DROP TABLE IF EXISTS `metatag`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `metatag` (
- `id` int(11) NOT NULL,
- `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `content` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `name` (`name`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `news`
---
-
-DROP TABLE IF EXISTS `news`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `news` (
- `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
- `title` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
- `text` text COLLATE utf8_unicode_ci NOT NULL,
- `image` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
- `user_id` int(10) unsigned NOT NULL,
- `date_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `priority` tinyint(3) unsigned NOT NULL DEFAULT '3',
- `tag` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'new',
- PRIMARY KEY (`id`),
- KEY `user` (`user_id`),
- KEY `tag` (`tag`),
- CONSTRAINT `news_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `account`.`account` (`id`) ON UPDATE CASCADE,
- CONSTRAINT `news_ibfk_2` FOREIGN KEY (`tag`) REFERENCES `news_tag` (`name`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `news_tag`
---
-
-DROP TABLE IF EXISTS `news_tag`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `news_tag` (
- `name` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
- `description` varchar(25) 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 */;
-
---
--- Table structure for table `order`
---
-
-DROP TABLE IF EXISTS `order`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `order` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `date_send` date NOT NULL DEFAULT '0000-00-00',
- `customer_id` int(11) NOT NULL,
- `delivery_method_id` int(11) DEFAULT '3',
- `agency_id` int(11) DEFAULT '2',
- `address_id` int(11) DEFAULT NULL,
- `company_id` smallint(5) unsigned DEFAULT '442',
- `note` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
- `source_app` set('WEB','ANDROID','IOS','TPV','TABLET_VN','') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'TPV',
- `is_bionic` tinyint(1) NOT NULL DEFAULT '1',
- `confirmed` tinyint(1) NOT NULL DEFAULT '0',
- `date_make` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `first_row_stamp` datetime DEFAULT NULL,
- `confirm_date` datetime DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `address` (`address_id`),
- KEY `delivery_method` (`delivery_method_id`),
- KEY `agency` (`agency_id`),
- KEY `customer_id` (`customer_id`),
- KEY `company_id` (`company_id`),
- KEY `id` (`id`,`customer_id`),
- KEY `source_app` (`source_app`),
- CONSTRAINT `order_ibfk_5` FOREIGN KEY (`address_id`) REFERENCES `vn2008`.`Consignatarios` (`id_consigna`) ON UPDATE CASCADE,
- CONSTRAINT `order_ibfk_8` FOREIGN KEY (`delivery_method_id`) REFERENCES `vn2008`.`Vistas` (`vista_id`) ON UPDATE CASCADE,
- CONSTRAINT `order_ibfk_9` FOREIGN KEY (`agency_id`) REFERENCES `vn2008`.`Agencias` (`Id_Agencia`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `order_basket`
---
-
-DROP TABLE IF EXISTS `order_basket`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `order_basket` (
- `order_id` int(10) unsigned NOT NULL,
- `customer_id` int(11) NOT NULL,
- PRIMARY KEY (`order_id`,`customer_id`),
- UNIQUE KEY `customer_id` (`customer_id`),
- CONSTRAINT `order_basket_ibfk_1` FOREIGN KEY (`order_id`, `customer_id`) REFERENCES `order` (`id`, `customer_id`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `order_basket_ibfk_2` FOREIGN KEY (`order_id`) REFERENCES `order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `order_basket_ibfk_3` FOREIGN KEY (`customer_id`) REFERENCES `vn2008`.`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 `order_check`
---
-
-DROP TABLE IF EXISTS `order_check`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `order_check` (
- `id` tinyint(1) unsigned NOT NULL AUTO_INCREMENT,
- `max_time` time NOT NULL,
- `deny_sunday` tinyint(1) unsigned NOT NULL,
- `deny_day` date DEFAULT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Conditions to check when an order is confirmed';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `order_check_festive`
---
-
-DROP TABLE IF EXISTS `order_check_festive`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `order_check_festive` (
- `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
- `date` date NOT NULL,
- `accept_orders` tinyint(1) unsigned NOT NULL DEFAULT '1',
- PRIMARY KEY (`id`),
- UNIQUE KEY `date` (`date`)
-) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `order_check_wday`
---
-
-DROP TABLE IF EXISTS `order_check_wday`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `order_check_wday` (
- `weekday` tinyint(3) unsigned NOT NULL COMMENT '0 = Monday, 6 = Sunday',
- `max_time` time NOT NULL,
- PRIMARY KEY (`weekday`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `order_component`
---
-
-DROP TABLE IF EXISTS `order_component`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `order_component` (
- `order_row_id` int(10) unsigned NOT NULL,
- `component_id` int(11) NOT NULL,
- `price` decimal(12,4) NOT NULL,
- PRIMARY KEY (`order_row_id`,`component_id`),
- KEY `component_id` (`component_id`),
- CONSTRAINT `order_component_ibfk_1` FOREIGN KEY (`order_row_id`) REFERENCES `order_row` (`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 `order_config`
---
-
-DROP TABLE IF EXISTS `order_config`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `order_config` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `employee_id` int(11) NOT NULL,
- `delivery_agency` int(11) NOT NULL,
- `guest_method` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
- `guest_agency` int(11) NOT NULL,
- `reserve_time` time NOT NULL,
- PRIMARY KEY (`id`),
- KEY `employee_id` (`employee_id`),
- KEY `delivery_agency` (`delivery_agency`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `order_confirm_time`
---
-
-DROP TABLE IF EXISTS `order_confirm_time`;
-/*!50001 DROP VIEW IF EXISTS `order_confirm_time`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `order_confirm_time` AS SELECT
- 1 AS `date_make`,
- 1 AS `source_app`,
- 1 AS `customer_id`,
- 1 AS `confirm_date`,
- 1 AS `first_row_stamp`,
- 1 AS `minutos`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `order_row`
---
-
-DROP TABLE IF EXISTS `order_row`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `order_row` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `order_id` int(10) unsigned NOT NULL DEFAULT '0',
- `item_id` int(11) NOT NULL DEFAULT '0',
- `warehouse_id` int(11) DEFAULT NULL,
- `shipment` date DEFAULT NULL,
- `amount` smallint(6) unsigned NOT NULL DEFAULT '0',
- `price` decimal(12,2) DEFAULT NULL,
- `rate` smallint(5) unsigned DEFAULT NULL,
- `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `Id_Movimiento` int(11) DEFAULT NULL COMMENT 'Deprecated',
- PRIMARY KEY (`id`),
- KEY `item` (`item_id`),
- KEY `order_id` (`order_id`),
- KEY `created` (`created`),
- KEY `warehouse_shipment` (`warehouse_id`,`shipment`),
- CONSTRAINT `order_row_ibfk_2` FOREIGN KEY (`item_id`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON UPDATE CASCADE,
- CONSTRAINT `order_row_ibfk_3` FOREIGN KEY (`order_id`) REFERENCES `order` (`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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `order_row_bi` BEFORE INSERT ON `order_row`
-FOR EACH ROW
-BEGIN
- DECLARE v_is_first BOOLEAN;
-
- SELECT (first_row_stamp IS NULL) INTO v_is_first
- FROM `order`
- WHERE id = NEW.order_id;
-
- IF v_is_first THEN
- UPDATE `order` SET first_row_stamp = NOW()
- WHERE id = NEW.order_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 */ ;
-
---
--- Temporary view structure for view `order_row_view`
---
-
-DROP TABLE IF EXISTS `order_row_view`;
-/*!50001 DROP VIEW IF EXISTS `order_row_view`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `order_row_view` AS SELECT
- 1 AS `id`,
- 1 AS `order_id`,
- 1 AS `warehouse_id`,
- 1 AS `item_id`,
- 1 AS `amount`,
- 1 AS `price2`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `order_view`
---
-
-DROP TABLE IF EXISTS `order_view`;
-/*!50001 DROP VIEW IF EXISTS `order_view`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `order_view` 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 `note`,
- 1 AS `address_id`,
- 1 AS `company_id`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `restPriv`
---
-
-DROP TABLE IF EXISTS `restPriv`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `restPriv` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `methodPath` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `role` int(10) unsigned NOT NULL,
- PRIMARY KEY (`id`),
- KEY `role` (`role`),
- CONSTRAINT `restPriv_ibfk_1` FOREIGN KEY (`role`) REFERENCES `account`.`role` (`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 `shelf`
---
-
-DROP TABLE IF EXISTS `shelf`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `shelf` (
- `id` int(10) unsigned NOT NULL,
- `name` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
- `nTrays` tinyint(3) unsigned NOT NULL,
- `trayheight` mediumint(8) unsigned NOT NULL,
- `topTrayHeight` mediumint(8) unsigned NOT NULL,
- `width` mediumint(8) unsigned NOT NULL,
- `depth` mediumint(8) unsigned NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Dimensiones de las estanterias';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `shelfConfig`
---
-
-DROP TABLE IF EXISTS `shelfConfig`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `shelfConfig` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `name` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
- `namePrefix` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
- `warehouse` smallint(5) unsigned NOT NULL,
- `family` smallint(5) unsigned NOT NULL,
- `shelf` int(10) unsigned NOT NULL,
- `maxAmount` smallint(5) unsigned DEFAULT NULL,
- `showPacking` tinyint(4) NOT NULL,
- `stack` tinyint(4) NOT NULL DEFAULT '0',
- PRIMARY KEY (`id`),
- KEY `shelf_id` (`shelf`),
- KEY `family_id` (`family`),
- KEY `warehouse_id` (`warehouse`),
- CONSTRAINT `shelfConfig_ibfk_1` FOREIGN KEY (`family`) REFERENCES `vn2008`.`Tipos` (`tipo_id`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `shelfConfig_ibfk_2` FOREIGN KEY (`shelf`) REFERENCES `shelf` (`id`) ON UPDATE CASCADE,
- CONSTRAINT `shelfConfig_ibfk_3` FOREIGN KEY (`warehouse`) REFERENCES `vn2008`.`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 `sms_config`
---
-
-DROP TABLE IF EXISTS `sms_config`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `sms_config` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `uri` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `user` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `password` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `title` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='SMS configuration parameters';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `social`
---
-
-DROP TABLE IF EXISTS `social`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `social` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `title` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `link` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `icon` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `priority` tinyint(3) unsigned NOT NULL,
- PRIMARY KEY (`id`),
- KEY `priority` (`priority`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `sql_message`
---
-
-DROP TABLE IF EXISTS `sql_message`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `sql_message` (
- `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
- `code` char(35) COLLATE utf8_unicode_ci NOT NULL,
- `description` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `code` (`code`)
-) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `survey`
---
-
-DROP TABLE IF EXISTS `survey`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `survey` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `question` varchar(255) COLLATE utf8_unicode_ci NOT 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 `survey_answer`
---
-
-DROP TABLE IF EXISTS `survey_answer`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `survey_answer` (
- `id` int(10) unsigned NOT NULL,
- `survey_id` int(10) unsigned NOT NULL,
- `answer` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
- `votes` int(10) unsigned NOT NULL DEFAULT '0',
- PRIMARY KEY (`id`),
- KEY `survey` (`survey_id`),
- CONSTRAINT `survey_answer_ibfk_1` FOREIGN KEY (`survey_id`) REFERENCES `survey` (`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 `survey_vote`
---
-
-DROP TABLE IF EXISTS `survey_vote`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `survey_vote` (
- `survey_id` int(10) unsigned NOT NULL,
- `user_id` int(10) unsigned NOT NULL,
- PRIMARY KEY (`survey_id`,`user_id`),
- KEY `user_id` (`user_id`),
- CONSTRAINT `survey_vote_ibfk_1` FOREIGN KEY (`survey_id`) REFERENCES `survey` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `survey_vote_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `ticket_row_view`
---
-
-DROP TABLE IF EXISTS `ticket_row_view`;
-/*!50001 DROP VIEW IF EXISTS `ticket_row_view`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ticket_row_view` AS SELECT
- 1 AS `id`,
- 1 AS `item_id`,
- 1 AS `ticket_id`,
- 1 AS `concept`,
- 1 AS `amount`,
- 1 AS `price`,
- 1 AS `fixed`,
- 1 AS `discount`,
- 1 AS `cost`,
- 1 AS `reserved`,
- 1 AS `ok`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Temporary view structure for view `ticket_view`
---
-
-DROP TABLE IF EXISTS `ticket_view`;
-/*!50001 DROP VIEW IF EXISTS `ticket_view`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `ticket_view` AS SELECT
- 1 AS `id`,
- 1 AS `customer_id`,
- 1 AS `warehouse_id`,
- 1 AS `date`,
- 1 AS `delivery`,
- 1 AS `alias`,
- 1 AS `agency_id`,
- 1 AS `note`,
- 1 AS `invoice`,
- 1 AS `address_id`,
- 1 AS `employee_id`,
- 1 AS `comments`,
- 1 AS `signed`,
- 1 AS `packages`,
- 1 AS `location`,
- 1 AS `hour`,
- 1 AS `blocked`,
- 1 AS `solution`,
- 1 AS `company_id`,
- 1 AS `type`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `tpv_config`
---
-
-DROP TABLE IF EXISTS `tpv_config`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `tpv_config` (
- `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
- `currency` smallint(5) unsigned NOT NULL,
- `terminal` tinyint(3) unsigned NOT NULL,
- `transaction_type` tinyint(3) unsigned NOT NULL,
- `employee_id` int(10) NOT NULL,
- `url` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The bank web service URL for production environment',
- `test_mode` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'Whether test mode is enabled',
- `test_url` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The bank web service URL for test environment',
- `test_key` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The bank secret key for test environment',
- `merchant_url` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `employee_id` (`employee_id`),
- CONSTRAINT `employee_id` FOREIGN KEY (`employee_id`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Virtual TPV parameters';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `tpv_error`
---
-
-DROP TABLE IF EXISTS `tpv_error`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `tpv_error` (
- `code` char(7) COLLATE utf8_unicode_ci NOT NULL,
- `message` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`code`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT=' List of possible TPV errors';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `tpv_imap_config`
---
-
-DROP TABLE IF EXISTS `tpv_imap_config`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `tpv_imap_config` (
- `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
- `host` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
- `user` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `pass` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
- `clean_period` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
- `success_folder` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL,
- `error_folder` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='IMAP configuration parameters for virtual TPV';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `tpv_merchant`
---
-
-DROP TABLE IF EXISTS `tpv_merchant`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `tpv_merchant` (
- `id` int(10) unsigned NOT NULL COMMENT 'Merchant identifier',
- `description` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Small description',
- `company_id` smallint(6) unsigned DEFAULT NULL COMMENT 'Company associated with the merchant',
- `bank_id` int(10) NOT NULL COMMENT 'The bank where merchant receipts are created',
- `secret_key` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The merchant secret key to sign transactions',
- PRIMARY KEY (`id`),
- KEY `bank_id` (`bank_id`),
- KEY `company_id` (`company_id`),
- KEY `id` (`id`,`company_id`),
- CONSTRAINT `company_id` FOREIGN KEY (`company_id`) REFERENCES `vn2008`.`empresa` (`id`) ON UPDATE CASCADE,
- CONSTRAINT `tpv_merchant_ibfk_1` FOREIGN KEY (`bank_id`) REFERENCES `vn2008`.`Bancos` (`Id_Banco`) ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Virtual TPV users and its associated company';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `tpv_merchant_enable`
---
-
-DROP TABLE IF EXISTS `tpv_merchant_enable`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `tpv_merchant_enable` (
- `merchant_id` int(10) unsigned NOT NULL DEFAULT '0',
- `company_id` smallint(6) unsigned NOT NULL,
- PRIMARY KEY (`merchant_id`,`company_id`),
- UNIQUE KEY `company_id` (`company_id`),
- CONSTRAINT `tpv_merchant_enable_ibfk_1` FOREIGN KEY (`merchant_id`, `company_id`) REFERENCES `tpv_merchant` (`id`, `company_id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Virtual TPV enabled users';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `tpv_response`
---
-
-DROP TABLE IF EXISTS `tpv_response`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `tpv_response` (
- `id` smallint(5) unsigned NOT NULL,
- `message` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='List of possible TPV reponses';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `tpv_transaction`
---
-
-DROP TABLE IF EXISTS `tpv_transaction`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `tpv_transaction` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `merchant_id` int(10) unsigned NOT NULL,
- `customer_id` int(11) NOT NULL,
- `receipt_id` int(11) DEFAULT NULL,
- `amount` int(10) unsigned NOT NULL,
- `response` smallint(5) unsigned DEFAULT NULL COMMENT 'Status notified by bank: NULL if no notification, 0 if success, error otherwise',
- `error_code` char(7) COLLATE utf8_unicode_ci DEFAULT NULL,
- `status` enum('started','ok','ko') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'started',
- `date_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (`id`),
- KEY `merchant_id` (`merchant_id`),
- KEY `receipt_id` (`receipt_id`),
- KEY `user_id` (`customer_id`),
- KEY `response` (`response`),
- KEY `error_code` (`error_code`),
- CONSTRAINT `receipt_id` FOREIGN KEY (`receipt_id`) REFERENCES `vn2008`.`Recibos` (`Id`) ON DELETE SET NULL ON UPDATE CASCADE,
- CONSTRAINT `tpv_transaction_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `tpv_transaction_ibfk_2` FOREIGN KEY (`merchant_id`) REFERENCES `tpv_merchant` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Transactions realized through the virtual TPV';
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `tpv_transaction_view`
---
-
-DROP TABLE IF EXISTS `tpv_transaction_view`;
-/*!50001 DROP VIEW IF EXISTS `tpv_transaction_view`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `tpv_transaction_view` AS SELECT
- 1 AS `id`,
- 1 AS `merchant_id`,
- 1 AS `customer_id`,
- 1 AS `receipt_id`,
- 1 AS `amount`,
- 1 AS `response`,
- 1 AS `status`,
- 1 AS `date_time`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `userSession`
---
-
-DROP TABLE IF EXISTS `userSession`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `userSession` (
- `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `lastUpdate` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
- `ssid` char(64) COLLATE utf8_unicode_ci DEFAULT NULL,
- `data` text COLLATE utf8_unicode_ci,
- `userVisit` int(10) unsigned DEFAULT NULL,
- UNIQUE KEY `ssid` (`ssid`),
- KEY `userVisit` (`userVisit`),
- KEY `lastUpdate` (`lastUpdate`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Table structure for table `user_android`
---
-
-DROP TABLE IF EXISTS `user_android`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `user_android` (
- `user_id` int(10) unsigned NOT NULL,
- `android_id` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
- PRIMARY KEY (`user_id`,`android_id`),
- CONSTRAINT `user_android_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Temporary view structure for view `user_android_view`
---
-
-DROP TABLE IF EXISTS `user_android_view`;
-/*!50001 DROP VIEW IF EXISTS `user_android_view`*/;
-SET @saved_cs_client = @@character_set_client;
-SET character_set_client = utf8;
-/*!50001 CREATE VIEW `user_android_view` AS SELECT
- 1 AS `user_id`,
- 1 AS `android_id`*/;
-SET character_set_client = @saved_cs_client;
-
---
--- Table structure for table `visit`
---
-
-DROP TABLE IF EXISTS `visit`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `visit` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `firstAgent` int(10) unsigned DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `firstAgent` (`firstAgent`),
- CONSTRAINT `visit_ibfk_1` FOREIGN KEY (`firstAgent`) REFERENCES `visitAgent` (`id`) 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 `visitAccess`
---
-
-DROP TABLE IF EXISTS `visitAccess`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `visitAccess` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `agent` int(10) unsigned NOT NULL,
- `stamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `ip` int(10) unsigned DEFAULT NULL,
- `referer` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `visit_access_idx_agent` (`agent`),
- KEY `stamp` (`stamp`),
- CONSTRAINT `visitAccess_ibfk_1` FOREIGN KEY (`agent`) REFERENCES `visitAgent` (`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 `visitAgent`
---
-
-DROP TABLE IF EXISTS `visitAgent`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `visitAgent` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `visit` int(10) unsigned NOT NULL,
- `firstAccess` int(10) unsigned DEFAULT NULL,
- `platform` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
- `browser` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
- `version` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
- `javascript` tinyint(3) unsigned DEFAULT NULL,
- `cookies` tinyint(3) unsigned DEFAULT NULL,
- `agent` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `visit_id` (`visit`),
- KEY `firstAccess` (`firstAccess`),
- CONSTRAINT `visitAgent_ibfk_1` FOREIGN KEY (`visit`) REFERENCES `visit` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `visitAgent_ibfk_2` FOREIGN KEY (`firstAccess`) REFERENCES `visitAccess` (`id`) 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 `visitUser`
---
-
-DROP TABLE IF EXISTS `visitUser`;
-/*!40101 SET @saved_cs_client = @@character_set_client */;
-/*!40101 SET character_set_client = utf8 */;
-CREATE TABLE `visitUser` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `access` int(10) unsigned NOT NULL,
- `user` int(10) unsigned DEFAULT NULL,
- `stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
- PRIMARY KEY (`id`),
- KEY `access_id` (`access`),
- KEY `date_time` (`stamp`),
- KEY `user_id` (`user`),
- CONSTRAINT `visitUser_ibfk_1` FOREIGN KEY (`access`) REFERENCES `visitAccess` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-/*!40101 SET character_set_client = @saved_cs_client */;
-
---
--- Dumping events for database 'hedera'
---
-
---
--- Dumping routines for database 'hedera'
---
-/*!50003 DROP FUNCTION IF EXISTS `basketGetId` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `basketGetId`() RETURNS int(11)
- DETERMINISTIC
-BEGIN
- DECLARE v_order INT;
-
- SELECT order_id INTO v_order FROM order_basket
- WHERE customer_id = account.userGetId();
-
- RETURN v_order;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `customer_get_debt` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `customer_get_debt`() RETURNS double
-BEGIN
- DECLARE v_debt DOUBLE;
-
- CALL customer_get_debt_by_company ();
-
- SELECT SUM(amount) INTO v_debt
- FROM t_customer_debt;
-
- DROP TEMPORARY TABLE t_customer_debt;
-
- RETURN v_debt;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `invoice_get_path` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `invoice_get_path`(v_invoice INT) RETURNS varchar(255) CHARSET utf8
-BEGIN
- DECLARE v_issued DATE;
- DECLARE v_serial VARCHAR(15);
-
- SELECT Fecha, Id_Factura
- INTO v_issued, v_serial
- FROM vn2008.Facturas WHERE factura_id = v_invoice;
-
- RETURN CONCAT_WS('/'
- ,'invoice'
- ,YEAR(v_issued)
- ,MONTH(v_issued)
- ,DAY(v_issued)
- ,CONCAT(YEAR(v_issued), v_serial, '.pdf')
- );
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `orderRowCheckAmount` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `orderRowCheckAmount`(vOrder INT, vItem INT, vAmount INT) RETURNS int(11)
-BEGIN
- DECLARE vGroup INT;
- DECLARE vMod INT;
- DECLARE vIsBionic BOOLEAN;
-
- SELECT CASE caja WHEN 0 THEN 1 WHEN 2 THEN packing ELSE grouping END, o.is_bionic
- INTO vGroup, vIsBionic
- FROM `order` o
- JOIN vn2008.v_compres c ON c.warehouse_id = o.wh_id
- WHERE Id_Article = vItem AND o.id = vOrder AND c.landing <= o.date_send
- ORDER BY landing DESC LIMIT 1;
-
- IF !vIsBionic
- THEN
- SET vMod = MOD(vAmount, vGroup);
-
- IF vMod
- THEN
- SET vAmount = vAmount + vGroup - vMod;
-
- END IF;
- END IF;
-
- RETURN vAmount;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `order_get_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 = '' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` FUNCTION `order_get_total`(v_order INT) RETURNS double
-BEGIN
-
-
- DECLARE v_total DOUBLE;
-
- CALL order_get_vat (v_order);
-
- SELECT SUM(tax_base) + SUM(vat) + SUM(surcharge) INTO v_total
- FROM t_order_vat;
-
- DROP TEMPORARY TABLE t_order_vat;
-
- 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 `userCheckRestPriv` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `userCheckRestPriv`(vMethodPath VARCHAR(255)) RETURNS tinyint(1)
- DETERMINISTIC
-BEGIN
-
- DECLARE vRole INT DEFAULT NULL;
-
- SELECT role INTO vRole FROM restPriv
- WHERE methodPath = vMethodPath;
-
- RETURN vRole IS NULL
- OR account.userHasRoleId (vRole);
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `agency_list_from_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 `agency_list_from_date`(v_date DATE, v_address INT)
-BEGIN
-
- DECLARE v_agency INT;
- DECLARE v_done BOOLEAN;
-
- DECLARE cur CURSOR FOR
- SELECT agency_id FROM vn2008.agency;
-
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;
-
- DROP TEMPORARY TABLE IF EXISTS t_agency;
- CREATE TEMPORARY TABLE t_agency
- (
- agency_id INT,
- PRIMARY KEY (agency_id)
- )
- ENGINE = MEMORY;
-
- OPEN cur;
-
- l: LOOP
- SET v_done = FALSE;
- FETCH cur INTO v_agency;
-
- IF v_done THEN
- LEAVE l;
- END IF;
-
- CALL vn2008.travel_tree (v_date, v_address, v_agency);
-
-
-
- INSERT INTO t_agency
- SELECT a.Id_Agencia
- FROM vn2008.Agencias a
- JOIN vn2008.travel_tree t
- JOIN vn2008.warehouse w on w.id = t.warehouse_id
- WHERE a.agency_id = v_agency
- ON DUPLICATE KEY UPDATE
- agency_id = VALUES(agency_id);
- END LOOP;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `basket_check` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `basket_check`()
-BEGIN
-
- DECLARE v_order INT;
- DECLARE v_created DATETIME;
- DECLARE v_status VARCHAR(15) DEFAULT 'OK';
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_status = 'NOT_EXISTS';
- DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET v_status = 'BAD_CONFIG';
-
- SELECT id, date_make
- INTO v_order, v_created
- FROM basket;
-
- IF v_status = 'OK'
- THEN
- CALL order_check_config (v_order);
-
- IF v_status = 'OK' AND v_created < TIMESTAMPADD(DAY, -1, NOW())
- THEN
- CALL order_update (v_order);
- SET v_status = 'UPDATED';
- END IF;
- END IF;
-
- SELECT v_status stat;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `basket_configure` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `basket_configure`(
- v_delivery DATE,
- v_delivery_method VARCHAR(45),
- v_agency INT,
- v_address INT)
-BEGIN
-
- DECLARE v_order INT;
- DECLARE v_company INT;
- DECLARE v_delivery_method_id INT;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND
- SET v_order = NULL;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- ROLLBACK;
- RESIGNAL;
- END;
-
- START TRANSACTION;
-
- SELECT vista_id INTO v_delivery_method_id
- FROM vn2008.Vistas
- WHERE code = v_delivery_method;
-
- IF v_delivery_method = 'DELIVERY'
- THEN
- SELECT delivery_agency INTO v_agency
- FROM order_config;
- END IF;
-
- IF v_delivery_method = 'PICKUP' AND v_address IS NULL
- THEN
- SELECT default_address INTO v_address
- FROM customer_view;
- END IF;
-
- SET v_order = basketGetId();
-
- IF v_order IS NULL
- THEN
- SELECT empresa_id INTO v_company
- FROM vn2008.Clientes_empresa
- WHERE Id_Cliente = account.userGetId()
- AND CURDATE() BETWEEN fecha_ini AND fecha_fin
- LIMIT 1;
-
- INSERT INTO `order`
- SET
- customer_id = account.userGetId(),
- date_send = v_delivery,
- delivery_method_id = v_delivery_method_id,
- agency_id = v_agency,
- address_id = v_address,
- source_app = 'WEB',
- company_id = IFNULL(v_company, 442);
-
- SET v_order = LAST_INSERT_ID();
-
- INSERT INTO order_basket SET
- customer_id = account.userGetId(),
- order_id = v_order;
- ELSE
- UPDATE `order`
- SET
- date_send = v_delivery,
- delivery_method_id = v_delivery_method_id,
- agency_id = v_agency,
- address_id = v_address
- WHERE
- id = v_order;
-
- CALL order_update (v_order);
- END IF;
-
- CALL order_check_config (v_order);
-
- 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 `basket_configure_for_guest` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `basket_configure_for_guest`()
-BEGIN
- DECLARE v_method VARCHAR(45);
- DECLARE v_agency INT;
-
- SELECT guest_method, guest_agency
- INTO v_method, v_agency
- FROM order_config
- LIMIT 1;
-
- CALL basket_configure (CURDATE(), v_method, v_agency, 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 `basket_confirm` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `basket_confirm`()
-BEGIN
- DECLARE v_order INT DEFAULT basketGetId ();
-
- IF v_order IS NOT NULL
- THEN
- CALL order_confirm_bionic (v_order);
-
- DELETE FROM order_basket
- WHERE order_id = v_order;
- 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 `basket_get_vat` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `basket_get_vat`()
-BEGIN
- CALL order_get_vat (basketGetId());
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `basket_item_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `basket_item_add`(
- v_warehouse INT,
- v_item INT,
- v_amount INT)
-BEGIN
- DECLARE v_calc INT;
- DECLARE v_order INT;
- DECLARE v_type INT;
- DECLARE v_row INT;
- DECLARE v_add INT;
- DECLARE v_available INT;
- DECLARE v_done BOOLEAN;
- DECLARE v_grouping INT;
- DECLARE v_rate INT;
- DECLARE v_shipment DATE;
- DECLARE v_price DECIMAL(10,2);
-
- DECLARE cur CURSOR FOR
- SELECT grouping, price, rate
- FROM tmp.bionic_price
- WHERE warehouse_id = v_warehouse
- AND item_id = v_item
- ORDER BY grouping DESC;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND
- SET v_done = TRUE;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- ROLLBACK;
- RESIGNAL;
- END;
-
- CALL bionic_from_item (v_item);
-
- START TRANSACTION;
-
- SET v_order = basketGetId();
-
- SELECT Fecha_envio INTO v_shipment
- FROM tmp.travel_tree
- WHERE warehouse_id = v_warehouse;
-
- SELECT available INTO v_available
- FROM tmp.bionic_lot
- WHERE warehouse_id = v_warehouse
- AND item_id = v_item;
-
- IF v_amount > v_available
- THEN
- CALL util.throw ('ORDER_ROW_UNAVAILABLE');
- END IF;
-
- OPEN cur;
-
- l: LOOP
- SET v_done = FALSE;
- FETCH cur INTO v_grouping, v_price, v_rate;
-
- IF v_done THEN
- LEAVE l;
- END IF;
-
- SET v_add = v_amount - MOD(v_amount, v_grouping);
- SET v_amount = v_amount - v_add;
-
- IF v_add = 0 THEN
- ITERATE l;
- END IF;
-
- INSERT INTO order_row SET
- order_id = v_order,
- item_id = v_item,
- warehouse_id = v_warehouse,
- shipment = v_shipment,
- rate = v_rate,
- amount = v_add,
- price = v_price;
-
- SET v_row = LAST_INSERT_ID();
-
- INSERT INTO order_component (order_row_id, component_id, price)
- SELECT v_row, c.component_id, c.cost
- FROM tmp.bionic_component c
- JOIN bi.tarifa_componentes t
- ON t.Id_Componente = c.component_id
- AND (t.tarifa_class IS NULL OR t.tarifa_class = v_rate)
- WHERE c.warehouse_id = v_warehouse
- AND c.item_id = v_item;
- END LOOP;
-
- CLOSE cur;
- COMMIT;
-
- CALL vn2008.bionic_free ();
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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`()
-BEGIN
- DECLARE v_date DATE;
- DECLARE v_address INT;
- DECLARE v_agency INT;
-
- SELECT date_send, address_id, agency_id
- INTO v_date, v_address, v_agency
- FROM basket;
-
- CALL vn2008.bionic_calc (v_date, v_address, v_agency);
-
- IF account.userGetName () = 'visitor'
- THEN
- DROP TEMPORARY TABLE tmp.bionic_component;
- UPDATE tmp.bionic_item SET price = 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 DROP PROCEDURE IF EXISTS `bionic_from_basket` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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_basket`()
-BEGIN
- DECLARE v_order INT;
- DECLARE v_date DATE;
- DECLARE v_address INT;
- DECLARE v_agency INT;
-
- SELECT id, date_send, address_id, agency_id
- INTO v_order, v_date, v_address, v_agency
- FROM basket;
-
- CALL vn2008.bionic_from_order (v_date, v_address, v_agency, v_order);
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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_item INT)
-BEGIN
- DECLARE v_date DATE;
- DECLARE v_address INT;
- DECLARE v_agency INT;
-
- SELECT date_send, address_id, agency_id
- INTO v_date, v_address, v_agency
- FROM basket;
-
- CALL vn2008.bionic_from_item (v_date, v_address, v_agency, v_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 `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 = '' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `bionic_from_type`(v_type INT)
-BEGIN
- DECLARE v_date DATE;
- DECLARE v_address INT;
- DECLARE v_agency INT;
-
- SELECT date_send, address_id, agency_id
- INTO v_date, v_address, v_agency
- FROM basket;
-
- CALL vn2008.bionic_from_type (v_date, v_address, v_agency, v_type);
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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`()
-BEGIN
- DECLARE v_i INT DEFAULT 0;
-
- WHILE v_i < 5
- DO
- DROP TEMPORARY TABLE IF EXISTS tmp;
-
- CREATE TEMPORARY TABLE tmp
- ENGINE = MEMORY
- SELECT id, COUNT(*) c
- FROM order_component
- GROUP BY order_row_id, component_id
- HAVING c > 1;
-
- DELETE c FROM order_component c JOIN tmp t ON t.id = c.id;
-
- DROP TEMPORARY TABLE tmp;
-
- SET v_i = v_i + 1;
- 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 `customer_get_debt_by_company` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `customer_get_debt_by_company`()
-BEGIN
-
- DECLARE v_date_ini DATETIME DEFAULT TIMESTAMP(DATE_FORMAT(TIMESTAMPADD(YEAR, -1, CURDATE()), '%Y-01-01'));
- DECLARE v_date_end DATETIME DEFAULT TIMESTAMP(CURDATE(), '23:59:59');
-
- DROP TEMPORARY TABLE IF EXISTS vn2008.ticket_tmp;
-
- CREATE TEMPORARY TABLE vn2008.ticket_tmp
- (INDEX (ticket_id))
- ENGINE = MEMORY
- SELECT t.id ticket_id
- FROM ticket_view t
- JOIN ticket_row_view r ON t.id = r.ticket_id
- JOIN tpv_merchant_enable m ON m.company_id = t.company_id
- WHERE invoice IS NULL
- AND date BETWEEN v_date_ini AND v_date_end
- GROUP BY ticket_id
- HAVING BIT_AND(fixed);
-
- CALL vn2008.ticket_total ();
-
- CREATE TEMPORARY TABLE t_customer_debt
- ENGINE = MEMORY
- SELECT e.id, e.abbreviation, IFNULL(SUM(t.amount), 0) amount
- FROM vn2008.empresa e
- JOIN tpv_merchant_enable m ON m.company_id = e.id
- LEFT JOIN
- (
- SELECT SUM(t.total) amount, i.company_id
- FROM vn2008.ticket_total t
- JOIN ticket_view i ON i.id = t.ticket_id
- GROUP BY i.company_id
- UNION ALL
- SELECT r.amount, r.company_id
- FROM bi.customer_risk r
- JOIN tpv_merchant_enable m ON m.company_id = r.company_id
- WHERE customer_id = account.userGetId()
- UNION ALL
- SELECT -SUM(amount) / 100, company_id
- FROM tpv_transaction_view t
- JOIN tpv_merchant m ON m.id = t.merchant_id
- WHERE t.receipt_id IS NULL AND t.status = 'ok'
- GROUP BY company_id
- ) t
- ON t.company_id = e.id
- GROUP BY e.id;
-
- DROP TEMPORARY TABLE vn2008.ticket_tmp;
- DROP TEMPORARY TABLE vn2008.ticket_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 PROCEDURE IF EXISTS `formList` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `formList`()
-BEGIN
-
- SELECT f.id, f.path, f.description, f.parent
- FROM form f
- WHERE role_id IN (SELECT id FROM account.userRole)
- ORDER BY f.parent, f.display_order, f.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 `itemAllocator` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `itemAllocator`(
- vWh TINYINT
- ,vDate DATE
- ,vType INT
- ,vPrefix VARCHAR(255)
- ,vUseIds BOOLEAN
-)
-BEGIN
- DECLARE vPrefixLen SMALLINT;
- DECLARE vFilter VARCHAR(255) DEFAULT NULL;
- DECLARE vDateInv DATE DEFAULT vn2008.date_inv();
-
- SET vPrefixLen = LENGTH(vPrefix);
-
- IF vPrefix IS NOT NULL AND vPrefixLen > 0
- THEN
- SET vFilter = CONCAT(vPrefix, '%');
- SET vPrefixLen = vPrefixLen + 1;
- END IF;
-
- DROP TEMPORARY TABLE IF EXISTS filter;
- CREATE TEMPORARY TABLE filter
- (INDEX (item_id))
- ENGINE = MEMORY
- SELECT Id_Article item_id FROM vn2008.Articles
- WHERE tipo_id = vType
- AND (vFilter IS NULL OR Article LIKE vFilter);
-
- DROP TEMPORARY TABLE IF EXISTS current_stock;
- CREATE TEMPORARY TABLE current_stock
- (INDEX (item_id))
- ENGINE = MEMORY
- SELECT item_id, SUM(Cantidad) amount FROM
- (
- SELECT Id_Article item_id, Cantidad
- FROM vn2008.Compres c
- JOIN vn2008.Entradas e USING(Id_Entrada)
- JOIN vn2008.travel t ON t.id = e.travel_id
- WHERE landing BETWEEN vDateInv AND vDate
- AND warehouse_id = vWh
- AND NOT Redada
- UNION ALL
- SELECT Id_Article, -Cantidad
- FROM vn2008.Compres c
- JOIN vn2008.Entradas e USING(Id_Entrada)
- JOIN vn2008.travel t ON t.id = e.travel_id
- WHERE shipment BETWEEN vDateInv AND CURDATE()
- AND warehouse_id_out = vWh
- AND NOT Redada
- AND delivered
- UNION ALL
- SELECT m.Id_Article, -m.Cantidad
- FROM vn2008.Movimientos m
- JOIN vn2008.Tickets t USING(Id_Ticket)
- JOIN vn.ticketState s ON s.ticket = t.Id_Ticket
- WHERE t.Fecha BETWEEN vDateInv AND CURDATE()
- AND t.warehouse_id = vWh
- AND (t.Etiquetasemitidas OR s.alertLevel = 3)
- ) t
- GROUP BY item_id
- HAVING amount > 0;
-
- DROP TEMPORARY TABLE IF EXISTS tmp;
- CREATE TEMPORARY TABLE tmp
- (INDEX (item_id))
- ENGINE = MEMORY
- SELECT * FROM
- (
- SELECT c.Id_Article item_id, c.Id_Compra id, c.Id_Cubo, c.packing
- FROM vn2008.Compres c
- JOIN vn2008.Entradas e USING(Id_Entrada)
- JOIN vn2008.travel t ON t.id = e.travel_id
- WHERE t.landing BETWEEN vDateInv AND vDate
- AND c.Novincular = FALSE
- AND c.Tarifa2 >= 0
- AND Id_Cubo IS NOT NULL
- ORDER BY t.warehouse_id = 1 DESC, t.landing DESC
- ) t GROUP BY item_id;
-
- DROP TEMPORARY TABLE IF EXISTS result;
- CREATE TEMPORARY TABLE result
- ENGINE = MEMORY
- SELECT a.Id_Article, IF(vPrefixLen > 0, SUBSTRING(a.Article, vPrefixLen), a.Article) Article,
- t.packing, CEIL(s.amount / t.packing) etiquetas, t.Id_Cubo, IF(c.z > 0, c.z, 0) z, c.x, c.y, a.Nicho
- FROM vn2008.Articles a
- JOIN filter f ON f.item_id = a.Id_Article
- JOIN current_stock s ON s.item_id = a.Id_Article
- LEFT JOIN tmp t ON t.item_id = a.Id_Article
- LEFT JOIN vn2008.Cubos c ON c.Id_Cubo = t.Id_Cubo
- WHERE CEIL(s.amount / t.packing) > 0
- AND c.box;
-
- IF vUseIds
- THEN
- SELECT * FROM result
- ORDER BY Id_Article;
- ELSE
- SELECT * FROM result
- ORDER BY Article, packing;
- END IF;
-
- DROP TEMPORARY TABLE
- filter,
- current_stock,
- tmp,
- result;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `itemListVisible` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `itemListVisible`(
- vWh TINYINT
- ,vDate DATE
- ,vType VARCHAR(255)
- ,vPrefix VARCHAR(255)
-)
-BEGIN
- DECLARE vPrefixLen SMALLINT;
- DECLARE vFilter VARCHAR(255) DEFAULT NULL;
- DECLARE vDateInv DATE DEFAULT vn2008.date_inv();
-
- SET vPrefixLen = LENGTH(vPrefix);
-
- IF vPrefix IS NOT NULL AND vPrefixLen > 0
- THEN
- SET vFilter = CONCAT(vPrefix, '%');
- SET vPrefixLen = vPrefixLen + 1;
- END IF;
-
- DROP TEMPORARY TABLE IF EXISTS filter;
- CREATE TEMPORARY TABLE filter
- (INDEX (item_id))
- ENGINE = MEMORY
- SELECT a.Id_Article item_id
- FROM vn2008.Articles a
- JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id
- WHERE t.Id_Tipo = vType
- AND (vFilter IS NULL OR a.Article LIKE vFilter);
-
- DROP TEMPORARY TABLE IF EXISTS current_stock;
- CREATE TEMPORARY TABLE current_stock
- (INDEX (item_id))
- ENGINE = MEMORY
- SELECT item_id, SUM(Cantidad) amount FROM
- (
- SELECT Id_Article item_id, Cantidad
- FROM vn2008.Compres c
- JOIN vn2008.Entradas e USING(Id_Entrada)
- JOIN vn2008.travel t ON t.id = e.travel_id
- WHERE landing BETWEEN vDateInv AND vDate
- AND warehouse_id = vWh
- AND NOT Redada
- UNION ALL
- SELECT Id_Article, -Cantidad
- FROM vn2008.Compres c
- JOIN vn2008.Entradas e USING(Id_Entrada)
- JOIN vn2008.travel t ON t.id = e.travel_id
- WHERE shipment BETWEEN vDateInv AND CURDATE()
- AND warehouse_id_out = vWh
- AND NOT Redada
- AND delivered
- UNION ALL
- SELECT m.Id_Article, -m.Cantidad
- FROM vn2008.Movimientos m
- JOIN vn2008.Tickets t USING(Id_Ticket)
- JOIN vn.ticketState s ON s.ticket = t.Id_Ticket
- WHERE t.Fecha BETWEEN vDateInv AND CURDATE()
- AND t.warehouse_id = vWh
- AND (t.Etiquetasemitidas OR s.alertLevel = 3)
- ) t
- GROUP BY item_id
- HAVING amount > 0;
-
- DROP TEMPORARY TABLE IF EXISTS tmp;
- CREATE TEMPORARY TABLE tmp
- (INDEX (item_id))
- ENGINE = MEMORY
- SELECT * FROM
- (
- SELECT c.Id_Article item_id, c.Id_Compra id, c.Id_Cubo, c.packing
- FROM vn2008.Compres c
- JOIN vn2008.Entradas e USING(Id_Entrada)
- JOIN vn2008.travel t ON t.id = e.travel_id
- WHERE t.landing BETWEEN vDateInv AND vDate
- AND c.Novincular = FALSE
- AND c.Tarifa2 >= 0
- AND Id_Cubo IS NOT NULL
- ORDER BY t.warehouse_id = 1 DESC, t.landing DESC
- ) t GROUP BY item_id;
-
- DROP TEMPORARY TABLE IF EXISTS result;
- CREATE TEMPORARY TABLE result
- ENGINE = MEMORY
- SELECT a.Id_Article itemId, IF(vPrefixLen > 0, SUBSTRING(a.Article, vPrefixLen), a.Article) item,
- Medida size, CEIL(s.amount) amount, '' location
- FROM vn2008.Articles a
- JOIN filter f ON f.item_id = a.Id_Article
- JOIN current_stock s ON s.item_id = a.Id_Article
- LEFT JOIN tmp t ON t.item_id = a.Id_Article
- LEFT JOIN vn2008.Cubos c ON c.Id_Cubo = t.Id_Cubo
- WHERE s.amount > 0;
-
- SELECT * FROM result
- ORDER BY item, size;
-
- DROP TEMPORARY TABLE
- filter,
- current_stock,
- tmp,
- result;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `item_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 = '' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `item_available`()
-BEGIN
-
- DECLARE v_delivery DATE;
- DECLARE v_address INT;
- DECLARE v_agency INT;
-
- SELECT date_send, address_id, agency_id
- INTO v_delivery, v_address, v_agency
- FROM basket;
-
- CALL vn2008.bionic_available_ (v_delivery, v_address, v_agency);
-
- DROP TEMPORARY TABLE IF EXISTS tmp.item_available;
- CREATE TEMPORARY TABLE tmp.item_available
- (INDEX (item_id))
- ENGINE = MEMORY
- SELECT c.item_id
- FROM `cache`.available c
- JOIN vn2008.t_bionic_available a ON c.calc_id = a.calc_id
- WHERE c.available > 0
- GROUP BY c.item_id;
-
- DROP TEMPORARY TABLE vn2008.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 `item_list` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `item_list`(v_warehouse SMALLINT, v_shipping DATE, v_realm INT, v_rate TINYINT)
-BEGIN
- DECLARE v_calc INT;
-
- CALL cache.available_refresh (v_calc, TRUE, v_warehouse, v_shipping);
- CALL vn2008.item_last_buy_ (v_warehouse, v_shipping);
-
- SELECT a.Id_Article, a.Article, a.Categoria, a.Medida, a.Tallos,
- c.available, a.Color, o.Abreviatura, t.Tipo, a.tipo_id, a.Foto,
- CASE b.caja
- WHEN 0 THEN 1
- WHEN 2 THEN b.packing
- ELSE b.grouping
- END AS grouping,
- CASE v_rate
- WHEN 1 THEN b.Tarifa1
- WHEN 2 THEN b.Tarifa2
- WHEN 3 THEN b.Tarifa3
- ELSE NULL
- END AS price
- FROM cache.available c
- JOIN vn2008.Articles a ON a.Id_Article = c.item_id
- JOIN vn2008.t_item_last_buy l ON l.item_id = c.item_id
- JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id
- JOIN vn2008.reinos r ON t.reino_id = r.id
- JOIN vn2008.Compres b ON b.Id_Compra = l.buy_id
- LEFT JOIN vn2008.Origen o ON a.id_origen = o.id
- WHERE c.calc_id = v_calc
- AND c.available > 0
- AND c.item_id != 90
- AND r.display
- AND (v_realm IS NULL OR v_realm = r.id)
- ORDER BY a.tipo_id, Article, Medida;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `orderCheckDate` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `orderCheckDate`(vDate DATE)
-BEGIN
- DECLARE vMaxTime TIME;
- DECLARE vFestive BOOLEAN;
- DECLARE vDenyDay DATE;
- DECLARE vDenySunday BOOLEAN;
-
- SELECT COUNT(*) INTO vFestive
- FROM order_check_festive
- WHERE TIMESTAMPADD(YEAR, -YEAR(vDate), vDate) = date
- AND accept_orders = FALSE;
-
- IF vDate < CURDATE()
- THEN
- CALL util.throw ('ORDER_DATE_PAST');
- ELSEIF vFestive > 0
- THEN
- CALL util.throw ('ORDER_DATE_HOLIDAY');
- ELSE
- SELECT c.deny_sunday, c.deny_day, IFNULL(w.max_time, c.max_time)
- INTO vDenySunday, vDenyDay, vMaxTime
- FROM order_check c
- LEFT JOIN order_check_wday w
- ON w.weekday = WEEKDAY(CURDATE());
-
- IF vDate = CURDATE() AND CURTIME() > vMaxTime
- THEN
- CALL util.throw ('ORDER_DATE_LAST');
- ELSEIF WEEKDAY(vDate) = 6 AND vDenySunday
- THEN
- CALL util.throw ('ORDER_DATE_SUNDAY');
- ELSEIF vDate = vDenyDay
- THEN
- CALL util.throw ('ORDER_DATE_SATURATED');
- 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 `orderNew` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `orderNew`()
-BEGIN
- DECLARE vCount INT;
- DECLARE vDeliveryMethod INT;
- DECLARE vAgency INT;
- DECLARE vAddress INT;
- DECLARE vWarehouse INT DEFAULT NULL;
-
- SELECT COUNT(*) INTO vCount FROM order_view;
-
- IF vCount >= 3 THEN
- CALL util.throw ('ORDER_MAX_EXCEEDED');
- END IF;
-
- SELECT co.Id_Consigna, co.Id_Agencia, a.Vista
- INTO vAddress, vAgency, vDeliveryMethod
- FROM vn2008.Clientes c
- LEFT JOIN vn2008.Consignatarios co ON co.Id_Consigna = c.default_address
- JOIN vn2008.Agencias a ON a.Id_Agencia = co.Id_Agencia
- WHERE c.Id_cliente = user_id();
-
- INSERT INTO `order`
- SET
- date_send = CURDATE(),
- customer_id = user_id(),
- delivery_method_id = IFNULL(vDeliveryMethod, DEFAULT(delivery_method_id)),
- agency_id = IFNULL(vAgency, DEFAULT(agency_id)),
- address_id = IFNULL(vAddress, DEFAULT(address_id)),
- wh_id = IFNULL(vWarehouse, DEFAULT(wh_id)),
- type_id = IFNULL(vAgency, DEFAULT(type_id)),
- is_bionic = FALSE;
-
- SELECT LAST_INSERT_ID() order_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 `order_check_config` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `order_check_config`(v_order INT)
-proc:
-BEGIN
-
- DECLARE v_delivery_method VARCHAR(45);
- DECLARE v_delivery DATE;
- DECLARE v_agency INT;
- DECLARE v_address INT;
- DECLARE v_ok BOOLEAN;
-
- SELECT v.code, o.date_send, o.agency_id, o.address_id
- INTO v_delivery_method, v_delivery, v_agency, v_address
- FROM `order` o
- JOIN vn2008.Vistas v ON v.vista_id = o.delivery_method_id
- WHERE o.id = v_order;
-
-
-
- IF v_delivery_method IN ('AGENCY', 'DELIVERY')
- && v_address IS NULL
- THEN
- CALL util.throw ('ORDER_EMPTY_ADDRESS');
- END IF;
-
-
-
- CALL agency_list_from_date (v_delivery, v_address);
-
- SELECT COUNT(*) > 0 INTO v_ok
- FROM t_agency
- WHERE agency_id = v_agency;
-
- DROP TEMPORARY TABLE t_agency;
-
- IF !v_ok THEN
- CALL util.throw ('ORDER_INVALID_AGENCY');
- 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 `order_confirm_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`@`%` PROCEDURE `order_confirm_bionic`(v_order INT)
-BEGIN
-
- DECLARE v_ok BOOLEAN;
- DECLARE v_done BOOLEAN DEFAULT FALSE;
- DECLARE v_wh INT;
- DECLARE v_shipment DATETIME;
- DECLARE v_ticket INT;
- DECLARE v_note VARCHAR(255);
- DECLARE i_article INT;
- DECLARE v_concepte VARCHAR(30);
- DECLARE i_amount INT;
- DECLARE d_price DOUBLE;
- DECLARE i_movimiento INT;
- DECLARE i_rate INT;
- DECLARE i_worker INT;
- DECLARE i_order_row INT;
- DECLARE d_delivery DATE;
- DECLARE i_address INT;
- DECLARE i_agency INT;
- DECLARE b_confirmed BOOLEAN;
- DECLARE TICKET_FREE INT DEFAULT 2;
- DECLARE SYSTEM_WORKER INT DEFAULT 20;
-
- DECLARE cur_tick CURSOR FOR
- SELECT t.Fecha_envio, r.warehouse_id
- FROM `order` o
- JOIN order_row r ON r.order_id = o.id
- LEFT JOIN vn2008.travel_tree t ON t.warehouse_id = r.warehouse_id
- WHERE o.id = v_order AND r.amount != 0
- GROUP BY warehouse_id;
-
- DECLARE cur_mov CURSOR FOR
- SELECT r.id, r.item_id, a.Article, r.amount, r.price, r.rate
- FROM order_row r
- JOIN vn2008.Articles a ON a.Id_Article = r.item_id
- WHERE r.amount != 0
- AND r.warehouse_id = v_wh
- AND r.order_id = v_order
- ORDER BY r.rate DESC;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND
- SET v_done = TRUE;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- ROLLBACK;
- RESIGNAL;
- END;
-
-
-
- SELECT o.date_send, o.address_id, o.note, a.agency_id, o.confirmed
- INTO d_delivery, i_address, v_note, i_agency, b_confirmed
- FROM `order` o
- JOIN vn2008.Agencias a ON a.Id_Agencia = o.agency_id
- WHERE id = v_order;
-
-
-
- IF b_confirmed THEN
- CALL util.throw ('ORDER_ALREADY_CONFIRMED');
- END IF;
-
-
-
- SELECT COUNT(*) > 0 INTO v_ok
- FROM order_row WHERE order_id = v_order AND amount > 0;
-
- IF !v_ok THEN
- CALL util.throw ('ORDER_EMPTY');
- END IF;
-
-
-
- CALL vn2008.travel_tree (d_delivery, i_address, i_agency);
-
-
-
- SELECT Id_Trabajador INTO i_worker
- FROM vn2008.Trabajadores
- WHERE user_id = account.userGetId();
-
- IF i_worker IS NULL THEN
- SELECT employee_id INTO i_worker FROM order_config;
- END IF;
-
-
-
- START TRANSACTION;
-
- OPEN cur_tick;
-
- tick_loop:
- LOOP
- SET v_ticket = NULL;
- SET v_done = FALSE;
- FETCH cur_tick INTO v_shipment, v_wh;
-
- IF v_done THEN
- LEAVE tick_loop;
- END IF;
-
-
-
- SELECT Id_Ticket INTO v_ticket
- FROM vn2008.Tickets t
- LEFT JOIN vn.ticketState tls on tls.ticket = t.Id_Ticket
- JOIN `order` o
- ON o.address_id = t.Id_Consigna
- AND v_wh = t.warehouse_id
- AND o.agency_id = t.Id_Agencia
- AND t.landing = o.date_send
- AND v_shipment = DATE(t.Fecha)
- WHERE o.id = v_order
- AND t.Factura IS NULL
- AND IFNULL(tls.alertLevel,0) = 0
-
- AND t.Id_Cliente <> 1118
- LIMIT 1;
-
-
-
- IF v_ticket IS NULL
- THEN
- INSERT INTO vn2008.Tickets (
- Id_Cliente, Fecha, Alias, Id_Agencia, Id_Consigna,
- Id_Trabajador, blocked, warehouse_id, Localizacion, landing
- )
- SELECT cs.Id_Cliente, IFNULL(v_shipment,CURDATE()), cs.Consignatario, o.agency_id, o.address_id,
- i_worker, FALSE, v_wh, IF(v_shipment,'BIONIC','ERROR FECHA ENVIO'), o.date_send
- FROM `order` o
- JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = o.address_id
- WHERE o.id = v_order;
-
- SET v_ticket = LAST_INSERT_ID();
- ELSE
-
- INSERT INTO vncontrol.inter(Id_Ticket, Id_Trabajador, state_id)
- VALUES(v_ticket, SYSTEM_WORKER, TICKET_FREE);
-
- END IF;
-
- INSERT IGNORE INTO vn2008.order_Tickets (order_id, Id_Ticket)
- VALUES (v_order, v_ticket);
-
-
-
- IF v_note IS NOT NULL && v_note != ''
- THEN
- INSERT INTO vn2008.ticket_observation (Id_Ticket, observation_type_id, text)
- VALUES (v_ticket, 4 , v_note)
- ON DUPLICATE KEY UPDATE text = CONCAT(VALUES(text),'. ', text);
- END IF;
-
-
-
- OPEN cur_mov;
-
- mov_loop:
- LOOP
- SET v_done = FALSE;
- FETCH cur_mov INTO i_order_row, i_article, v_concepte, i_amount, d_price, i_rate;
-
- IF v_done THEN
- LEAVE mov_loop;
- END IF;
-
- INSERT INTO vn2008.Movimientos
- SET
- Id_Article = i_article,
- Id_Ticket = v_ticket,
- Concepte = v_concepte,
- Cantidad = i_amount,
- Preu = d_price,
- CostFixat = 0,
- PrecioFijado = TRUE;
-
- SET i_movimiento = LAST_INSERT_ID();
-
- INSERT INTO vn2008.Movimientos_componentes (Id_Movimiento, Id_Componente, Valor)
- SELECT i_movimiento, cm.component_id, cm.price
- FROM order_component cm
- JOIN bi.tarifa_componentes tc ON tc.Id_Componente = cm.component_id
- WHERE cm.order_row_id = i_order_row
- GROUP BY i_movimiento, cm.component_id;
-
- UPDATE order_row SET Id_Movimiento = i_movimiento
- WHERE id = i_order_row;
-
- END LOOP;
-
- CLOSE cur_mov;
-
-
- UPDATE vn2008.Movimientos m
- JOIN (SELECT SUM(mc.Valor) sum_valor,mc.Id_Movimiento
- FROM vn2008.Movimientos_componentes mc
- 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
- JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento
- where m.Id_Ticket = v_ticket
- GROUP BY mc.Id_Movimiento) mc ON mc.Id_Movimiento = m.Id_Movimiento
- SET m.CostFixat = sum_valor;
- END LOOP;
-
- CLOSE cur_tick;
-
- DELETE FROM order_basket WHERE order_id = v_order;
- UPDATE `order` SET confirmed = TRUE, confirm_date = NOW()
- WHERE id = v_order;
-
- 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 `order_get_vat` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `order_get_vat`(v_order INT)
-BEGIN
-
- DECLARE v_billing_date DATE DEFAULT CURDATE();
-
- DECLARE clean CONDITION FOR SQLSTATE 'HY000';
- DECLARE CONTINUE HANDLER FOR clean
- BEGIN
- DROP TEMPORARY TABLE IF EXISTS t_vat_group;
- DROP TEMPORARY TABLE IF EXISTS t_vat_tax;
- END;
-
- SIGNAL clean;
-
-
-
- CREATE TEMPORARY TABLE t_vat_group
- (INDEX (country_id, vat_group_id))
- ENGINE = MEMORY
- SELECT * FROM (
- SELECT Id_Pais country_id, iva_group_id vat_group_id, c.tipo rate
- FROM vn2008.iva_group_codigo g
- JOIN vn2008.iva_codigo c ON g.iva_codigo_id = c.id
- JOIN vn2008.iva_tipo t ON t.id = c.iva_tipo_id
- WHERE date <= v_billing_date
- ORDER BY date DESC
- ) t
- GROUP BY country_id, vat_group_id;
-
-
-
- CREATE TEMPORARY TABLE t_vat_tax
- (INDEX (country_id, rate))
- ENGINE = MEMORY
- SELECT * FROM (
- SELECT Id_Pais country_id, tipo rate,
- CAST(iva / 100 AS DECIMAL(12, 2)) vat,
- CAST(recargo / 100 AS DECIMAL(12, 2)) surcharge
- FROM vn2008.iva_codigo
- JOIN vn2008.iva_tipo t ON t.id = iva_tipo_id
- WHERE Fecha <= v_billing_date AND iva
- ORDER BY fecha DESC, recargo DESC
- ) t
- GROUP BY country_id, rate;
-
-
-
- DROP TEMPORARY TABLE IF EXISTS t_order_vat;
- CREATE TEMPORARY TABLE t_order_vat
- (INDEX (order_id))
- ENGINE = MEMORY
- SELECT order_id, t.rate, t.tax_base,
- IF(t.has_vat, t.tax_base * x.vat, 0) vat,
- IF(t.has_surcharge, t.tax_base * x.surcharge, 0) surcharge
- FROM (
- SELECT o.id order_id, g.country_id, g.rate
- ,SUM(m.amount * m.price) AS tax_base
- ,NOT(c.VIES AND p.pais_id <> c.Id_Pais) AS has_vat
- ,c.RE != FALSE AS has_surcharge
- FROM `order` o
- JOIN order_row m ON m.order_id = o.id
- JOIN vn2008.Articles a ON a.Id_Article = m.item_id
- JOIN vn2008.Clientes c ON c.Id_Cliente = o.customer_id
- JOIN vn2008.Proveedores p ON p.Id_Proveedor = o.company_id
- JOIN t_vat_group g ON g.country_id = p.pais_id AND g.vat_group_id = a.iva_group_id
- WHERE o.id = v_order
- GROUP BY order_id, rate
- ) t
- JOIN t_vat_tax x ON x.country_id = t.country_id AND x.rate = t.rate;
-
- SIGNAL clean;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `order_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 `order_update`(v_order INT)
-BEGIN
- DECLARE v_date DATE;
- DECLARE v_address INT;
- DECLARE v_agency INT;
- DECLARE v_nrows INT;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- ROLLBACK;
- RESIGNAL;
- END;
-
- START TRANSACTION;
-
- SELECT COUNT(*) INTO v_nrows
- FROM order_row WHERE order_id = v_order;
-
- IF v_nrows > 0
- THEN
- SELECT date_send, address_id, agency_id
- INTO v_date, v_address, v_agency
- FROM `order`
- WHERE id = v_order;
-
- CALL vn2008.bionic_from_order (v_date, v_address, v_agency, v_order);
-
- DELETE c
- FROM order_row r
- JOIN order_component c ON c.order_row_id = r.id
- WHERE r.order_id = v_order;
-
- UPDATE order_row r
- LEFT JOIN tmp.bionic_price l
- ON l.warehouse_id = r.warehouse_id
- AND l.item_id = r.item_id
- AND l.rate = r.rate
- LEFT JOIN tmp.travel_tree t
- ON t.warehouse_id = r.warehouse_id
- SET
- r.price = l.price,
- r.amount = IF(l.item_id IS NOT NULL, r.amount + IF(@m := MOD(r.amount, l.grouping), l.grouping - @m, 0), 0),
- r.shipment = t.Fecha_envio
- WHERE r.order_id = v_order;
-
- INSERT INTO order_component (order_row_id, component_id, price)
- SELECT r.id, c.component_id, c.cost
- FROM order_row r
- JOIN tmp.bionic_component c
- ON c.warehouse_id = r.warehouse_id
- AND c.item_id = r.item_id
- JOIN bi.tarifa_componentes t
- ON t.Id_Componente = c.component_id
- AND (t.tarifa_class IS NULL OR t.tarifa_class = r.rate)
- WHERE r.order_id = v_order;
- END IF;
-
- UPDATE `order` SET date_make = NOW()
- WHERE id = v_order;
-
- 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 `sql_query` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `sql_query`(IN v_sql TEXT)
-BEGIN
- SET @v_sql = v_sql;
-
- PREPARE stmt FROM @v_sql;
- EXECUTE stmt;
- DEALLOCATE PREPARE stmt;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `surveyVote` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `surveyVote`(vAnswer INT)
-BEGIN
- DECLARE vSurvey INT;
- DECLARE vCount TINYINT;
- DECLARE EXIT HANDLER FOR 1062
- CALL util.throw ('SURVEY_MAX_ONE_VOTE');
-
- SELECT survey_id INTO vSurvey
- FROM survey_answer WHERE id = vAnswer;
-
- INSERT INTO survey_vote
- VALUES (vSurvey, account.userGetId());
-
- UPDATE survey_answer SET votes = votes + 1
- WHERE id = vAnswer;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `ticketLog` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `ticketLog`(vticket INT)
-BEGIN
- INSERT INTO vn2008.Tickets_dits
- (idaccion_dits, Id_Trabajador, Id_Ticket)
- SELECT 146, 4, id
- FROM ticket_view WHERE id = vTicket;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `ticket_list` */;
-/*!50003 SET @saved_cs_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' */ ;
-DELIMITER ;;
-CREATE DEFINER=`root`@`%` PROCEDURE `ticket_list`()
-BEGIN
-
- DROP TEMPORARY TABLE IF EXISTS vn2008.ticket_tmp;
- CREATE TEMPORARY TABLE vn2008.ticket_tmp
- (KEY (ticket_id))
- ENGINE = MEMORY
- SELECT t.id ticket_id FROM ticket_view t
- WHERE date > TIMESTAMP(DATE_FORMAT(TIMESTAMPADD(DAY, -25, CURDATE()), '%Y-%m-01'));
-
- CALL vn2008.ticket_total ();
-
- DROP TEMPORARY TABLE IF EXISTS t_movement_fixed;
- CREATE TEMPORARY TABLE t_movement_fixed
- (KEY (ticket_id))
- ENGINE = MEMORY
- SELECT ticket_id, BIT_AND(fixed != FALSE) all_fixed
- FROM ticket_row_view
- JOIN vn2008.ticket_tmp USING(ticket_id)
- GROUP BY ticket_id;
-
- SELECT i.ticket_id, IFNULL(v.delivery, v.`date`) `date`, city, consignee, type, company_id,
- IF(all_fixed, t.total, NULL) total,
- IF(v.date >= CURDATE() AND v.invoice IS NULL AND all_fixed
- ,t.total
- ,NULL
- ) pending
- FROM vn2008.ticket_tmp i
- JOIN ticket_view v ON i.ticket_id = v.id
- JOIN address_view c ON v.address_id = c.id
- JOIN vn2008.ticket_total t USING(ticket_id)
- LEFT JOIN t_movement_fixed m USING(ticket_id)
- ORDER BY IFNULL(v.delivery, v.`date`) DESC, i.ticket_id DESC;
-
- DROP TEMPORARY TABLE vn2008.ticket_tmp;
- DROP TEMPORARY TABLE vn2008.ticket_total;
- DROP TEMPORARY TABLE t_movement_fixed;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `transactionConfirm` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `transactionConfirm`(
- vAmount INT
- ,vOrder INT
- ,vMerchant INT
- ,vCurrency INT
- ,vResponse INT
- ,vErrorCode VARCHAR(10)
-)
-BEGIN
- DECLARE vReceipt INT;
- DECLARE vStatus VARCHAR(10);
- DECLARE vCustomer INT;
- DECLARE vBank INT;
- DECLARE vCompany INT;
- DECLARE vEmployee INT;
- DECLARE vIsDuplicated BOOLEAN;
- DECLARE vDate DATE;
- DECLARE vConcept VARCHAR(25) DEFAULT 'Cobro Web';
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- ROLLBACK;
- RESIGNAL;
- END;
-
- START TRANSACTION;
-
- SELECT COUNT(*) > 0 INTO vIsDuplicated
- FROM tpv_transaction
- WHERE id = vOrder AND response IS NOT NULL
- FOR UPDATE;
-
- IF vIsDuplicated
- THEN
- CALL util.throw ('TRANSACTION_DUPLICATED');
- END IF;
-
- IF vResponse BETWEEN 0 AND 99
- THEN
- SELECT
- t.customer_id
- ,m.bank_id
- ,m.company_id
- ,c.employee_id
- ,DATE(t.date_time)
- INTO
- vCustomer
- ,vBank
- ,vCompany
- ,vEmployee
- ,vDate
- FROM tpv_merchant m
- JOIN tpv_config c ON c.id = 1
- LEFT JOIN tpv_transaction t ON t.id = vOrder
- WHERE m.id = vMerchant;
-
- INSERT INTO vn2008.Recibos
- SET
- Entregado = vAmount / 100
- ,Fechacobro = vDate
- ,Id_Trabajador = vEmployee
- ,Id_Banco = vBank
- ,Id_Cliente = vCustomer
- ,empresa_id = vCompany
- ,Id_Factura = vConcept
- ,conciliado = TRUE;
-
- SET vReceipt = LAST_INSERT_ID();
- SET vStatus = 'ok';
-
-
-
- DO vn2008.till_entry
- (
- vCustomer
- ,vBank
- ,vAmount / 100
- ,vConcept
- ,vDate
- ,'A'
- ,TRUE
- ,vCustomer
- ,vCompany
- ,vEmployee
- );
- ELSE
- SET vReceipt = NULL;
- SET vStatus = 'ko';
- END IF;
-
- UPDATE tpv_transaction
- SET
- merchant_id = vMerchant
- ,receipt_id = vReceipt
- ,amount = vAmount
- ,response = vResponse
- ,error_code = vErrorCode
- ,status = vStatus
- WHERE id = vOrder;
-
- 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 `transactionConfirmAll` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `transactionConfirmAll`(vDate DATE)
-BEGIN
- DECLARE vOrder INT;
- DECLARE vDone BOOLEAN DEFAULT FALSE;
- DECLARE vDateIni DATETIME DEFAULT TIMESTAMP(vDate, '00:00:00');
- DECLARE vDateEnd DATETIME DEFAULT TIMESTAMP(vDate, '23:59:59');
-
- DECLARE transactions CURSOR FOR
- SELECT id
- FROM tpv_transaction
- WHERE date_time BETWEEN vDateIni AND vDateEnd
- AND status = 'ok'
- AND response IS NULL;
-
- DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
-
- OPEN transactions;
-
- l: LOOP
- FETCH transactions INTO vOrder;
-
- IF vDone THEN
- LEAVE l;
- END IF;
-
- CALL transactionConfirmById (vOrder);
- END LOOP l;
-
- CLOSE transactions;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `transactionConfirmById` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `transactionConfirmById`(
- vOrder INT
-)
-BEGIN
- DECLARE vAmount INT;
- DECLARE vMerchant INT;
- DECLARE vCurrency INT;
-
- SELECT amount, merchant_id, currency
- INTO vAmount, vMerchant, vCurrency
- FROM tpv_transaction t
- JOIN tpv_merchant m ON t.merchant_id = m.id
- JOIN tpv_config c
- WHERE t.id = vOrder;
-
- CALL transactionConfirm (
- vAmount
- ,vOrder
- ,vMerchant
- ,vCurrency
- ,0
- ,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 `transactionEnd` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `transactionEnd`(vTransaction INT, vStatus VARCHAR(12))
-BEGIN
-
- IF vStatus IN ('ok', 'ko')
- THEN
- UPDATE tpv_transaction_view SET status = vStatus
- WHERE id = vTransaction AND response IS 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 DROP PROCEDURE IF EXISTS `transactionStart` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `transactionStart`(vAmount INT, vCompany INT)
-BEGIN
-
-
- DECLARE vTransaction CHAR(12);
- DECLARE vMerchant INT;
- DECLARE vUrl VARCHAR(255);
- DECLARE vKey VARCHAR(50);
- DECLARE vTestMode BOOLEAN;
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- ROLLBACK;
- RESIGNAL;
- END;
-
- START TRANSACTION;
-
- IF vCompany IS NULL
- THEN
- SELECT company_id INTO vCompany
- FROM tpv_merchant_enable LIMIT 1;
- END IF;
-
- SELECT merchant_id INTO vMerchant
- FROM tpv_merchant_enable WHERE company_id = vCompany;
-
- SELECT test_mode INTO vTestMode
- FROM tpv_config;
-
- IF NOT vTestMode
- THEN
- SELECT c.url, m.secret_key INTO vUrl, vKey
- FROM tpv_merchant m
- JOIN tpv_config c
- WHERE m.id = vMerchant;
- ELSE
- SELECT test_url, test_key INTO vUrl, vKey
- FROM tpv_config;
- END IF;
-
- INSERT INTO tpv_transaction_view
- SET
- merchant_id = vMerchant
- ,customer_id = account.userGetId()
- ,amount = vAmount;
-
- SET vTransaction = LAST_INSERT_ID();
-
- SELECT
- vAmount amount
- ,vTransaction transactionId
- ,vMerchant merchant
- ,currency
- ,transaction_type transactionType
- ,terminal
- ,merchant_url merchantUrl
- ,vUrl url
- ,vKey secretKey
- FROM tpv_config;
-
- 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 `transactionUndo` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `transactionUndo`(
- vOrder INT
-)
-BEGIN
- DECLARE vCustomer INT;
- DECLARE vAmount DOUBLE;
- DECLARE vReceipt INT;
- DECLARE vDate DATE;
- DECLARE vBank INT;
- DECLARE vAccount VARCHAR(12);
- DECLARE vSubaccount VARCHAR(12);
-
- DECLARE EXIT HANDLER FOR SQLEXCEPTION
- BEGIN
- ROLLBACK;
- RESIGNAL;
- END;
-
- START TRANSACTION;
-
- SELECT
- t.customer_id
- ,t.amount / 100
- ,t.receipt_id
- ,DATE(t.date_time)
- ,m.bank_id
- INTO
- vCustomer
- ,vAmount
- ,vReceipt
- ,vDate
- ,vBank
- FROM tpv_transaction t
- JOIN tpv_merchant m ON m.id = t.merchant_id
- JOIN tpv_config c
- WHERE t.id = vOrder
- FOR UPDATE;
-
-
-
- DELETE FROM vn2008.Recibos
- WHERE Id = vReceipt LIMIT 1;
-
-
-
- DELETE FROM vn2008.Cajas
- WHERE Id_Banco = vBank
- AND DATE(CajaFecha) = vDate
- AND Entrada = vAmount
- LIMIT 1;
-
-
-
- SELECT Cuenta INTO vSubaccount
- FROM vn2008.Clientes WHERE Id_Cliente = vCustomer;
-
- SELECT Cuenta INTO vAccount
- FROM vn2008.Bancos WHERE Id_Banco = vBank;
-
- DELETE FROM vn2008.XDiario
- WHERE SUBCTA = vSubaccount
- AND CONTRA = vAccount
- AND DATE(FECHA) = vDate
- AND EUROHABER = vAmount
- LIMIT 1;
-
- DELETE FROM vn2008.XDiario
- WHERE CONTRA = vSubaccount
- AND SUBCTA = vAccount
- AND DATE(FECHA) = vDate
- AND EURODEBE = vAmount
- LIMIT 1;
-
-
-
- UPDATE tpv_transaction
- SET response = NULL, status = 'started'
- WHERE id = vOrder;
-
- 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 `type_list` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `type_list`(v_realm INT)
-BEGIN
-
- DECLARE v_date DATE;
- DECLARE v_address INT;
- DECLARE v_agency INT;
-
- SELECT date_send, address_id, agency_id
- INTO v_date, v_address, v_agency
- FROM basket;
-
- CALL vn2008.bionic_available_types_ (v_date, v_address, v_agency);
-
- SELECT t.tipo_id, t.Tipo
- FROM vn2008.Tipos t
- JOIN vn2008.t_bionic_available_types bt ON bt.tipo_id = t.tipo_id
- WHERE t.reino_id = v_realm
- ORDER BY t.Orden DESC, t.Tipo;
-
- DROP TEMPORARY TABLE vn2008.t_bionic_available_types;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `visitRegister` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `visitRegister`(
- vVisit INT
- ,vPlatform VARCHAR(30)
- ,vBrowser VARCHAR(30)
- ,vVersion VARCHAR(15)
- ,vJavascript TINYINT
- ,vCookies TINYINT
- ,vAgent VARCHAR(255)
- ,vIp INT
- ,vReferer VARCHAR(255)
-)
-BEGIN
- DECLARE vFirstVisit TINYINT DEFAULT FALSE;
- DECLARE vFirstAgent TINYINT DEFAULT FALSE;
- DECLARE vAgentId INT DEFAULT NULL;
- DECLARE vAccessId INT DEFAULT NULL;
-
-
-
- IF vVisit IS NULL || (SELECT COUNT(*) FROM visit WHERE id = vVisit) = 0
- THEN
- INSERT INTO visit SET id = DEFAULT;
- SET vVisit = LAST_INSERT_ID();
- SET vFirstVisit = TRUE;
- END IF;
-
- SELECT id INTO vAgentId FROM visitAgent
- WHERE visit = vVisit
- AND (agent = vAgent OR (vAgent IS NULL AND agent IS NULL))
- LIMIT 1;
-
-
-
- IF vAgentId IS NULL
- THEN
- INSERT INTO visitAgent SET
- visit = vVisit
- ,platform = vPlatform
- ,browser = vBrowser
- ,version = vVersion
- ,javascript = vJavascript
- ,cookies = vCookies
- ,agent = vAgent;
-
- SET vAgentId = LAST_INSERT_ID();
- SET vFirstAgent = TRUE;
- END IF;
-
- IF vFirstVisit
- THEN
- UPDATE visit SET firstAgent = vAgentId
- WHERE id = vVisit;
- END IF;
-
-
-
- INSERT INTO visitAccess SET
- agent = vAgentId
- ,ip = vIp
- ,referer = vReferer;
-
- SET vAccessId = LAST_INSERT_ID();
-
- IF vFirstAgent
- THEN
- UPDATE visitAgent SET firstAccess = vAccessId
- WHERE id = vAgentId;
- END IF;
-
-
-
- SELECT vVisit visit, vAccessId access;
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_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 `visitUserNew` */;
-/*!50003 SET @saved_cs_client = @@character_set_client */ ;
-/*!50003 SET @saved_cs_results = @@character_set_results */ ;
-/*!50003 SET @saved_col_connection = @@collation_connection */ ;
-/*!50003 SET character_set_client = utf8 */ ;
-/*!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 `visitUserNew`(
- vAccess INT
- ,vSsid VARCHAR(64)
-)
-BEGIN
- DECLARE vUserVisit INT;
-
- INSERT INTO visitUser SET
- access = vAccess,
- user = account.userGetId();
-
- SET vUserVisit = LAST_INSERT_ID();
-
- UPDATE userSession SET userVisit = vUserVisit
- WHERE ssid = vSsid;
-
- DELETE FROM userSession
- WHERE lastUpdate < TIMESTAMPADD(HOUR, -1, NOW());
-END ;;
-DELIMITER ;
-/*!50003 SET sql_mode = @saved_sql_mode */ ;
-/*!50003 SET character_set_client = @saved_cs_client */ ;
-/*!50003 SET character_set_results = @saved_cs_results */ ;
-/*!50003 SET collation_connection = @saved_col_connection */ ;
-
---
--- Current Database: `vncontrol`
---
-
-USE `vncontrol`;
-
---
--- Current Database: `edi`
---
-
-USE `edi`;
-
---
--- Current Database: `vn2008`
---
-
-USE `vn2008`;
-
---
--- Final view structure for view `V_edi_item_track`
---
-
-/*!50001 DROP VIEW IF EXISTS `V_edi_item_track`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `V_edi_item_track` AS select `edi`.`item_track`.`item_id` AS `item_id`,`edi`.`item_track`.`s1` AS `s1`,`edi`.`item_track`.`s2` AS `s2`,`edi`.`item_track`.`s3` AS `s3`,`edi`.`item_track`.`s4` AS `s4`,`edi`.`item_track`.`s5` AS `s5`,`edi`.`item_track`.`s6` AS `s6`,`edi`.`item_track`.`kop` AS `kop`,`edi`.`item_track`.`pac` AS `pac`,`edi`.`item_track`.`cat` AS `cat`,`edi`.`item_track`.`ori` AS `ori`,`edi`.`item_track`.`pro` AS `pro`,`edi`.`item_track`.`sub` AS `sub`,`edi`.`item_track`.`package` AS `package` from `edi`.`item_track` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `VerEspionaje`
---
-
-/*!50001 DROP VIEW IF EXISTS `VerEspionaje`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `VerEspionaje` AS select `Trabajadores`.`CodigoTrabajador` AS `CodigoTrabajador`,`Espionajes`.`Fecha` AS `Fecha`,`Espionajes`.`HoraEntrada` AS `HoraEntrada`,`Espionajes`.`HoraSalida` AS `HoraSalida`,`Espionajes`.`Id_Equipo` AS `Id_Equipo`,`Trabajadores`.`Id_Trabajador` AS `Id_Trabajador` from (`Espionajes` join `Trabajadores` on((`Espionajes`.`Id_Trabajador` = `Trabajadores`.`Id_Trabajador`))) order by `Trabajadores`.`CodigoTrabajador`,`Espionajes`.`Fecha` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `account_customer`
---
-
-/*!50001 DROP VIEW IF EXISTS `account_customer`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `account_customer` AS select `e`.`description` AS `description`,`vn2008`.`cc_to_iban`(concat(`a`.`entity_id`,`a`.`office`,`a`.`DC`,`a`.`number`)) AS `iban`,`a`.`entity_id` AS `entity_id`,`a`.`office` AS `office`,`a`.`DC` AS `dc`,`a`.`number` AS `number` from ((`provider_account_customer` `c` join `Proveedores_account` `a` on((`a`.`Id_Proveedores_account` = `c`.`account_id`))) join `entity` `e` on((`a`.`entity_id` = `e`.`entity_id`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `awb_volume`
---
-
-/*!50001 DROP VIEW IF EXISTS `awb_volume`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `awb_volume` AS select `ar`.`awb_id` AS `awb_id`,(((`c`.`Etiquetas` * `t`.`density`) * if((`cu`.`Volumen` > 0),`cu`.`Volumen`,((`cu`.`X` * `cu`.`Y`) * if((`cu`.`Z` = 0),(`a`.`Medida` + 10),`cu`.`Z`)))) / 167000) AS `volume` from (((((((`Compres` `c` join `Articles` `a` on((`c`.`Id_Article` = `a`.`Id_Article`))) join `Tipos` `t` on((`a`.`tipo_id` = `t`.`tipo_id`))) join `Cubos` `cu` on((`cu`.`Id_Cubo` = `c`.`Id_Cubo`))) join `Entradas` `e` on((`c`.`Id_Entrada` = `e`.`Id_Entrada`))) join `travel` `tr` on((`tr`.`id` = `e`.`travel_id`))) join `recibida_entrada` `re` on((`c`.`Id_Entrada` = `re`.`Id_Entrada`))) join `awb_recibida` `ar` on((`re`.`awb_recibida` = `ar`.`recibida_id`))) where (`tr`.`shipment` > makedate((year(curdate()) - 1),1)) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `cdr`
---
-
-/*!50001 DROP VIEW IF EXISTS `cdr`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `cdr` AS select `c`.`call_date` AS `calldate`,`c`.`clid` AS `clid`,`c`.`src` AS `src`,`c`.`dst` AS `dst`,`c`.`dcontext` AS `dcontext`,`c`.`channel` AS `channel`,`c`.`dst_channel` AS `dstchannel`,`c`.`last_app` AS `lastapp`,`c`.`last_data` AS `lastdata`,`c`.`duration` AS `duration`,`c`.`billsec` AS `billsec`,`c`.`disposition` AS `disposition`,`c`.`ama_flags` AS `amaflags`,`c`.`account_code` AS `accountcode`,`c`.`unique_id` AS `uniqueid`,`c`.`user_field` AS `userfield` from `pbx`.`cdr` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `clientMana`
---
-
-/*!50001 DROP VIEW IF EXISTS `clientMana`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `clientMana` AS select `t`.`Id_Cliente` AS `Id_Cliente`,`mc`.`Valor` AS `ManaUnitario`,(`mc`.`Valor` * `m`.`Cantidad`) AS `ManaTotal`,`t`.`Id_Ticket` AS `Id_Ticket`,`m`.`Id_Article` AS `Id_Article`,`m`.`Concepte` AS `Concepte`,`m`.`Cantidad` AS `Cantidad`,`m`.`Preu` AS `Preu`,`t`.`Fecha` AS `Fecha`,`m`.`Id_Movimiento` AS `Id_Movimiento` from ((((`vn2008`.`Tickets` `t` join `vn2008`.`Movimientos` `m` on((`m`.`Id_Ticket` = `t`.`Id_Ticket`))) join `vn2008`.`Movimientos_componentes` `mc` on((`mc`.`Id_Movimiento` = `m`.`Id_Movimiento`))) join `vn2008`.`tarifa_componentes` `tc` on((`tc`.`Id_Componente` = `mc`.`Id_Componente`))) join `vn2008`.`tarifa_componentes_series` `tcs` on((`tc`.`tarifa_componentes_series_id` = `tcs`.`tarifa_componentes_series_id`))) where ((`t`.`Fecha` >= '2016-01-01') and (`tcs`.`Serie` = 'cartera_comercial') and (`mc`.`Valor` <> 0)) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `edi_article`
---
-
-/*!50001 DROP VIEW IF EXISTS `edi_article`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `edi_article` AS select `edi`.`item`.`id` AS `id`,`edi`.`item`.`product_name` AS `product_name`,`edi`.`item`.`name` AS `name`,`edi`.`item`.`plant_id` AS `plant_id`,`edi`.`item`.`group_id` AS `group_id`,`edi`.`item`.`entry_date` AS `entry_date`,`edi`.`item`.`expiry_date` AS `expiry_date`,`edi`.`item`.`change_date_time` AS `change_date_time` from `edi`.`item` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `edi_bucket`
---
-
-/*!50001 DROP VIEW IF EXISTS `edi_bucket`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `edi_bucket` AS select (cast(`edi`.`bucket`.`bucket_id` as char charset utf8) collate utf8_general_ci) AS `bucket_id`,`edi`.`bucket`.`bucket_type_id` AS `bucket_type_id`,`edi`.`bucket`.`description` AS `description`,`edi`.`bucket`.`x_size` AS `x_size`,`edi`.`bucket`.`y_size` AS `y_size`,`edi`.`bucket`.`z_size` AS `z_size`,`edi`.`bucket`.`entry_date` AS `entry_date`,`edi`.`bucket`.`expiry_date` AS `expiry_date`,`edi`.`bucket`.`change_date_time` AS `change_date_time` from `edi`.`bucket` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `edi_bucket_type`
---
-
-/*!50001 DROP VIEW IF EXISTS `edi_bucket_type`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `edi_bucket_type` AS select `edi`.`bucket_type`.`bucket_type_id` AS `bucket_type_id`,`edi`.`bucket_type`.`description` AS `description`,`edi`.`bucket_type`.`entry_date` AS `entry_date`,`edi`.`bucket_type`.`expiry_date` AS `expiry_date`,`edi`.`bucket_type`.`change_date_time` AS `change_date_time` from `edi`.`bucket_type` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `edi_feature`
---
-
-/*!50001 DROP VIEW IF EXISTS `edi_feature`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `edi_feature` AS select `edi`.`feature`.`item_id` AS `item_id`,`edi`.`feature`.`feature_type_id` AS `feature_type_id`,`edi`.`feature`.`feature_value` AS `feature_value`,`edi`.`feature`.`entry_date` AS `entry_date`,`edi`.`feature`.`expiry_date` AS `expiry_date`,`edi`.`feature`.`change_date_time` AS `change_date_time` from `edi`.`feature` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `edi_genus`
---
-
-/*!50001 DROP VIEW IF EXISTS `edi_genus`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `edi_genus` AS select `edi`.`genus`.`genus_id` AS `genus_id`,`edi`.`genus`.`latin_genus_name` AS `latin_genus_name`,`edi`.`genus`.`entry_date` AS `entry_date`,`edi`.`genus`.`expiry_date` AS `expiry_date`,`edi`.`genus`.`change_date_time` AS `change_date_time` from `edi`.`genus` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `edi_item_feature`
---
-
-/*!50001 DROP VIEW IF EXISTS `edi_item_feature`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `edi_item_feature` AS select `edi`.`item_feature`.`item_id` AS `item_id`,`edi`.`item_feature`.`presentation_order` AS `presentation_order`,`edi`.`item_feature`.`feature` AS `feature`,`edi`.`item_feature`.`regulation_type` AS `regulation_type`,`edi`.`item_feature`.`entry_date` AS `entry_date`,`edi`.`item_feature`.`expiry_date` AS `expiry_date`,`edi`.`item_feature`.`change_date_time` AS `change_date_time` from `edi`.`item_feature` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `edi_plant`
---
-
-/*!50001 DROP VIEW IF EXISTS `edi_plant`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `edi_plant` AS select `edi`.`plant`.`plant_id` AS `plant_id`,`edi`.`plant`.`genus_id` AS `genus_id`,`edi`.`plant`.`specie_id` AS `specie_id`,`edi`.`plant`.`entry_date` AS `entry_date`,`edi`.`plant`.`expiry_date` AS `expiry_date`,`edi`.`plant`.`change_date_time` AS `change_date_time` from `edi`.`plant` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `edi_specie`
---
-
-/*!50001 DROP VIEW IF EXISTS `edi_specie`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `edi_specie` AS select `edi`.`specie`.`specie_id` AS `specie_id`,`edi`.`specie`.`genus_id` AS `genus_id`,`edi`.`specie`.`latin_species_name` AS `latin_species_name`,`edi`.`specie`.`entry_date` AS `entry_date`,`edi`.`specie`.`expiry_date` AS `expiry_date`,`edi`.`specie`.`change_date_time` AS `change_date_time` from `edi`.`specie` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `edi_supplier`
---
-
-/*!50001 DROP VIEW IF EXISTS `edi_supplier`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `edi_supplier` AS select `edi`.`supplier`.`supplier_id` AS `supplier_id`,`edi`.`supplier`.`company_name` AS `company_name` from `edi`.`supplier` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `edi_type`
---
-
-/*!50001 DROP VIEW IF EXISTS `edi_type`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `edi_type` AS select `edi`.`type`.`type_id` AS `type_id`,`edi`.`type`.`type_group_id` AS `type_group_id`,`edi`.`type`.`description` AS `description`,`edi`.`type`.`entry_date` AS `entry_date`,`edi`.`type`.`expiry_date` AS `expiry_date`,`edi`.`type`.`change_date_time` AS `change_date_time` from `edi`.`type` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `edi_value`
---
-
-/*!50001 DROP VIEW IF EXISTS `edi_value`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `edi_value` AS select `edi`.`value`.`type_id` AS `type_id`,`edi`.`value`.`type_value` AS `type_value`,`edi`.`value`.`type_description` AS `type_description`,`edi`.`value`.`entry_date` AS `entry_date`,`edi`.`value`.`expiry_date` AS `expiry_date`,`edi`.`value`.`change_date_time` AS `change_date_time` from `edi`.`value` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `itemTagArranged`
---
-
-/*!50001 DROP VIEW IF EXISTS `itemTagArranged`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `itemTagArranged` AS select `i`.`itemFk` AS `itemFk`,`i`.`tag1` AS `tag1`,`i`.`val1` AS `val1`,`i`.`tag2` AS `tag2`,`i`.`val2` AS `val2`,`i`.`tag3` AS `tag3`,`i`.`val3` AS `val3`,`i`.`tag4` AS `tag4`,`i`.`val4` AS `val4`,`i`.`tag5` AS `tag5`,`i`.`val5` AS `val5`,`i`.`tag6` AS `tag6`,`i`.`val6` AS `val6`,`i`.`description` AS `description` from `vn`.`itemTagArranged` `i` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `item_entry_in`
---
-
-/*!50001 DROP VIEW IF EXISTS `item_entry_in`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `item_entry_in` AS select `t`.`warehouse_id` AS `warehouse_id`,`t`.`landing` AS `dat`,`m`.`Id_Article` AS `item_id`,`m`.`Cantidad` AS `amount`,`t`.`received` AS `received` from ((`Compres` `m` join `Entradas` `e` on((`m`.`Id_Entrada` = `e`.`Id_Entrada`))) join `travel` `t` on((`e`.`travel_id` = `t`.`id`))) where ((`e`.`Inventario` = 0) and (`m`.`Cantidad` <> 0)) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `item_entry_out`
---
-
-/*!50001 DROP VIEW IF EXISTS `item_entry_out`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `item_entry_out` AS select `t`.`warehouse_id_out` AS `warehouse_id`,`t`.`shipment` AS `dat`,`m`.`Id_Article` AS `item_id`,-(`m`.`Cantidad`) AS `amount`,`t`.`delivered` AS `delivered` from ((`Compres` `m` join `Entradas` `e` on((`m`.`Id_Entrada` = `e`.`Id_Entrada`))) join `travel` `t` on((`e`.`travel_id` = `t`.`id`))) where ((`e`.`Inventario` = 0) and (`e`.`Redada` = 0) and (`m`.`Cantidad` <> 0)) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `item_out`
---
-
-/*!50001 DROP VIEW IF EXISTS `item_out`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `item_out` AS select `t`.`warehouse_id` AS `warehouse_id`,`t`.`Fecha` AS `dat`,`m`.`Id_Article` AS `item_id`,-(`m`.`Cantidad`) AS `amount`,`m`.`OK` AS `ok`,`m`.`Reservado` AS `Reservado`,(`ts`.`alertLevel` = 3) AS `ready`,`t`.`Factura` AS `invoice`,ifnull(`ts`.`alertLevel`,0) AS `alertLevel` from ((`vn2008`.`Movimientos` `m` join `vn2008`.`Tickets` `t` on((`m`.`Id_Ticket` = `t`.`Id_Ticket`))) left join `vn`.`ticketState` `ts` on((`t`.`Id_Ticket` = `ts`.`ticket`))) where (`m`.`Cantidad` <> 0) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `new_view`
---
-
-/*!50001 DROP VIEW IF EXISTS `new_view`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `new_view` AS select `vn`.`workerDocument`.`id` AS `id`,`vn`.`workerDocument`.`worker` AS `worker`,`vn`.`workerDocument`.`document` AS `document` from `vn`.`workerDocument` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `order`
---
-
-/*!50001 DROP VIEW IF EXISTS `order`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `order` AS select `hedera`.`order`.`id` AS `id`,`hedera`.`order`.`date_make` AS `date_make`,`hedera`.`order`.`date_send` AS `date_send`,`hedera`.`order`.`customer_id` AS `customer_id`,`hedera`.`order`.`delivery_method_id` AS `delivery_method_id`,`hedera`.`order`.`agency_id` AS `agency_id`,`hedera`.`order`.`address_id` AS `address_id`,`hedera`.`order`.`note` AS `note`,`hedera`.`order`.`confirmed` AS `confirmed`,`hedera`.`order`.`is_bionic` AS `is_bionic`,`hedera`.`order`.`source_app` AS `source_app` from `hedera`.`order` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `order_component`
---
-
-/*!50001 DROP VIEW IF EXISTS `order_component`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `order_component` AS select `c`.`order_row_id` AS `order_row_id`,`c`.`component_id` AS `component_id`,`c`.`price` AS `price` from `hedera`.`order_component` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `order_row`
---
-
-/*!50001 DROP VIEW IF EXISTS `order_row`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `order_row` AS select `hedera`.`order_row`.`id` AS `id`,`hedera`.`order_row`.`order_id` AS `order_id`,`hedera`.`order_row`.`item_id` AS `item_id`,`hedera`.`order_row`.`warehouse_id` AS `warehouse_id`,`hedera`.`order_row`.`shipment` AS `shipment`,`hedera`.`order_row`.`amount` AS `amount`,`hedera`.`order_row`.`price` AS `price`,`hedera`.`order_row`.`rate` AS `rate`,`hedera`.`order_row`.`created` AS `created`,`hedera`.`order_row`.`Id_Movimiento` AS `Id_Movimiento` from `hedera`.`order_row` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `person_user`
---
-
-/*!50001 DROP VIEW IF EXISTS `person_user`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `person_user` AS select `u`.`id` AS `id`,`u`.`role` AS `mysql_user_id`,`u`.`name` AS `name`,`u`.`password` AS `password`,`u`.`active` AS `active`,`u`.`lastPassChange` AS `last_pass_change` from `account`.`user` `u` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `person_user_idtrabajador`
---
-
-/*!50001 DROP VIEW IF EXISTS `person_user_idtrabajador`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `person_user_idtrabajador` AS select `t`.`Id_Trabajador` AS `Id_Trabajador` from (`vn2008`.`person_user` `p` join `vn2008`.`Trabajadores` `t` on((`p`.`id` = `t`.`user_id`))) where (`t`.`user_id` = `account`.`userGetId`()) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `proveedores_clientes`
---
-
-/*!50001 DROP VIEW IF EXISTS `proveedores_clientes`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `proveedores_clientes` AS select `Proveedores`.`Id_Proveedor` AS `Id_Proveedor`,`Proveedores`.`Proveedor` AS `Proveedor`,`Clientes`.`id_cliente` AS `Id_Cliente`,`Clientes`.`cliente` AS `Cliente` from (`Proveedores` join `Clientes` on((`Proveedores`.`NIF` = `Clientes`.`if`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `root`
---
-
-/*!50001 DROP VIEW IF EXISTS `root`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`z-developer`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `root` AS select dayname(`h`.`confirm_date`) AS `DiadelaSemana`,hour(`h`.`confirm_date`) AS `Hora`,cast(`h`.`confirm_date` as date) AS `Fecha`,`h`.`source_app` AS `Dispositivo` from `hedera`.`order` `h` where `h`.`confirm_date` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `tarifa_componentes`
---
-
-/*!50001 DROP VIEW IF EXISTS `tarifa_componentes`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `tarifa_componentes` AS select `bi`.`tarifa_componentes`.`Id_Componente` AS `Id_Componente`,`bi`.`tarifa_componentes`.`Componente` AS `Componente`,`bi`.`tarifa_componentes`.`tarifa_componentes_series_id` AS `tarifa_componentes_series_id`,`bi`.`tarifa_componentes`.`tarifa_class` AS `tarifa_class`,`bi`.`tarifa_componentes`.`tax` AS `tax`,`bi`.`tarifa_componentes`.`is_renewable` AS `is_renewable` from `bi`.`tarifa_componentes` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `tarifa_componentes_series`
---
-
-/*!50001 DROP VIEW IF EXISTS `tarifa_componentes_series`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `tarifa_componentes_series` AS select `bi`.`tarifa_componentes_series`.`tarifa_componentes_series_id` AS `tarifa_componentes_series_id`,`bi`.`tarifa_componentes_series`.`Serie` AS `Serie`,`bi`.`tarifa_componentes_series`.`base` AS `base` from `bi`.`tarifa_componentes_series` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ticketCreationData`
---
-
-/*!50001 DROP VIEW IF EXISTS `ticketCreationData`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`z-developer`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ticketCreationData` AS select dayname(`h`.`confirm_date`) AS `DiadelaSemana`,hour(`h`.`confirm_date`) AS `Hora`,cast(`h`.`confirm_date` as date) AS `Fecha`,`h`.`source_app` AS `Dispositivo` from `hedera`.`order` `h` where `h`.`confirm_date` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_Agenda`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_Agenda`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_Agenda` AS select 'P' AS `Tipo`,`Proveedores`.`Id_Proveedor` AS `Id`,`Proveedores`.`Proveedor` AS `Nombre`,`Proveedores`.`Telefono` AS `Telephone` from `Proveedores` where (`Proveedores`.`Telefono` is not null) union select 'C' AS `Tipo`,`Clientes`.`id_cliente` AS `Id`,`Clientes`.`cliente` AS `Cliente`,`Clientes`.`telefono` AS `Telefono` from `Clientes` where (`Clientes`.`telefono` is not null) union select 'C' AS `Tipo`,`Clientes`.`id_cliente` AS `Id`,`Clientes`.`cliente` AS `Cliente`,`Clientes`.`movil` AS `Movil` from `Clientes` where (`Clientes`.`movil` is not null) union select if(isnull(`Relaciones`.`Id_Proveedor`),'C','P') AS `Tipo`,if(isnull(`Relaciones`.`Id_Proveedor`),`Relaciones`.`Id_Cliente`,`Relaciones`.`Id_Proveedor`) AS `Id`,`Contactos`.`Nombre` AS `Nombre`,`Contactos`.`Telefono` AS `Telefono` from (`Contactos` join `Relaciones` on((`Contactos`.`Id_Contacto` = `Relaciones`.`Id_Contacto`))) where (`Contactos`.`Telefono` is not null) union select if(isnull(`Relaciones`.`Id_Proveedor`),'C','P') AS `Tipo`,if(isnull(`Relaciones`.`Id_Proveedor`),`Relaciones`.`Id_Cliente`,`Relaciones`.`Id_Proveedor`) AS `Id`,`Contactos`.`Nombre` AS `Nombre`,`Contactos`.`Movil` AS `Movil` from (`Contactos` join `Relaciones` on((`Contactos`.`Id_Contacto` = `Relaciones`.`Id_Contacto`))) where (`Contactos`.`Movil` is not null) union select 'T' AS `Tipo`,`Trabajadores`.`Id_Trabajador` AS `Id_Trabajador`,`Trabajadores`.`CodigoTrabajador` AS `CodigoTrabajador`,`Trabajadores`.`extension` AS `extension` from `Trabajadores` where (`Trabajadores`.`extension` is not null) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_Agenda2`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_Agenda2`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_Agenda2` AS select `v_Agenda`.`Tipo` AS `Tipo`,`v_Agenda`.`Id` AS `Id`,`v_Agenda`.`Nombre` AS `Nombre`,replace(`v_Agenda`.`Telephone`,' ','') AS `Telefono` from `v_Agenda` where `v_Agenda`.`Telephone` group by replace(`v_Agenda`.`Telephone`,' ','') */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_Articles_botanical`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_Articles_botanical`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_Articles_botanical` AS select `ab`.`Id_Article` AS `Id_Article`,ifnull(`ab`.`botanical`,concat(`g`.`latin_genus_name`,' ',ifnull(`s`.`latin_species_name`,''))) AS `edi_botanic` from ((`vn2008`.`Articles_botanical` `ab` left join `edi`.`genus` `g` on((`ab`.`genus_id` = `g`.`genus_id`))) left join `edi`.`specie` `s` on((`s`.`specie_id` = `ab`.`specie_id`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_Movimientos_Volumen_shipping_charge`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_Movimientos_Volumen_shipping_charge`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_Movimientos_Volumen_shipping_charge` AS select `M`.`Id_Ticket` AS `Id_Ticket`,`M`.`Id_Movimiento` AS `Id_Movimiento`,`t`.`Fecha` AS `Fecha`,`az`.`price` AS `price`,((`M`.`Cantidad` * ((`CM3`(`b`.`Id_Compra`) / 1000000) / `C`.`Packing`)) * (`az`.`price` / 0.08)) AS `freight` from (((((((`vn2008`.`Movimientos` `M` join `vn2008`.`Tickets` `t` on((`t`.`Id_Ticket` = `M`.`Id_Ticket`))) join `vn2008`.`Consignatarios` `c` on((`c`.`id_consigna` = `t`.`Id_Consigna`))) join `bi`.`Last_buy_id` `b` on(((`M`.`Id_Article` = `b`.`Id_Article`) and (`t`.`warehouse_id` = `b`.`warehouse_id`)))) join `vn2008`.`Compres` `C` on((`b`.`Id_Compra` = `C`.`Id_Compra`))) join `vn2008`.`Agencias` `a` on((`a`.`Id_Agencia` = `t`.`Id_Agencia`))) join `vn2008`.`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 `vn2008`.`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)))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_Ordenes`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_Ordenes`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_Ordenes` AS select `Ordenes`.`Id_ORDEN` AS `Id_ORDEN`,`Ordenes`.`ORDEN` AS `ORDEN`,`Ordenes`.`datORDEN` AS `datORDEN`,`Ordenes`.`datTICKET` AS `datTICKET`,`Ordenes`.`CodVENDEDOR` AS `CodVENDEDOR`,`Ordenes`.`CodCOMPRADOR` AS `CodCOMPRADOR`,`Ordenes`.`CANTIDAD` AS `CANTIDAD`,`Ordenes`.`PRECIOMAX` AS `PRECIOMAX`,`Ordenes`.`PREU` AS `PREU`,`Ordenes`.`Id_ARTICLE` AS `Id_ARTICLE`,`Ordenes`.`Id_CLIENTE` AS `Id_CLIENTE`,`Ordenes`.`COMENTARIO` AS `COMENTARIO`,`Ordenes`.`OK` AS `OK`,`Ordenes`.`TOTAL` AS `TOTAL`,`Ordenes`.`datCOMPRA` AS `datCOMPRA`,`Ordenes`.`KO` AS `KO`,`Ordenes`.`Id_Movimiento` AS `Id_Movimiento`,`Ordenes`.`odbc_date` AS `odbc_date` from `Ordenes` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_XDiario_ALL`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_XDiario_ALL`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_XDiario_ALL` AS select `bi`.`XDiario_ALL`.`empresa_id` AS `empresa_id`,`bi`.`XDiario_ALL`.`SUBCTA` AS `SUBCTA`,`bi`.`XDiario_ALL`.`Eurodebe` AS `Eurodebe`,`bi`.`XDiario_ALL`.`Eurohaber` AS `Eurohaber`,`bi`.`XDiario_ALL`.`Fecha` AS `Fecha`,`bi`.`XDiario_ALL`.`FECHA_EX` AS `FECHA_EX` from `bi`.`XDiario_ALL` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_accion`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_accion`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_accion` AS select `vncontrol`.`accion`.`accion_id` AS `accion_id`,`vncontrol`.`accion`.`accion` AS `accion` from `vncontrol`.`accion` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_account`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_account`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_account` AS select `a`.`id` AS `user_id` from `account`.`account` `a` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_analisis_ventas`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_analisis_ventas`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_analisis_ventas` AS select `bi`.`analisis_ventas`.`Familia` AS `Familia`,`bi`.`analisis_ventas`.`Reino` AS `Reino`,`bi`.`analisis_ventas`.`Comercial` AS `Comercial`,`bi`.`analisis_ventas`.`Comprador` AS `Comprador`,`bi`.`analisis_ventas`.`Provincia` AS `Provincia`,`bi`.`analisis_ventas`.`almacen` AS `almacen`,`bi`.`analisis_ventas`.`Año` AS `Año`,`bi`.`analisis_ventas`.`Mes` AS `Mes`,`bi`.`analisis_ventas`.`Semana` AS `Semana`,`bi`.`analisis_ventas`.`Vista` AS `Vista`,`bi`.`analisis_ventas`.`Importe` AS `Importe` from `bi`.`analisis_ventas` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_awb_volumen`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_awb_volumen`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_awb_volumen` AS select `a`.`id` AS `awb_id`,`a`.`codigo` AS `codigo`,`a`.`importe` AS `importe`,cast(sum(`v`.`volume`) as signed) AS `Vol_Total` from (`awb` `a` join `awb_volume` `v` on((`v`.`awb_id` = `a`.`id`))) group by `a`.`id` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_barcodes`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_barcodes`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_barcodes` AS select `Articles`.`Id_Article` AS `code`,`Articles`.`Id_Article` AS `Id_Article` from `Articles` union all select `barcodes`.`code` AS `code`,`barcodes`.`Id_Article` AS `Id_Article` from `barcodes` union all select `c`.`Id_Compra` AS `Id_Compra`,`c`.`Id_Article` AS `Id_Article` from ((`Compres` `c` join `Entradas` `e` on((`c`.`Id_Entrada` = `e`.`Id_Entrada`))) join `travel` `tr` on((`tr`.`id` = `e`.`travel_id`))) where (`tr`.`landing` >= (curdate() + interval -(15) day)) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_barcodes_plus`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_barcodes_plus`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_barcodes_plus` AS select `cache`.`barcodes`.`code` AS `code`,`cache`.`barcodes`.`Id_Article` AS `Id_Article`,`cache`.`barcodes`.`Article` AS `Article`,`cache`.`barcodes`.`Medida` AS `Medida`,`cache`.`barcodes`.`Color` AS `Color`,`cache`.`barcodes`.`Categoria` AS `Categoria`,`cache`.`barcodes`.`Producer` AS `Producer` from `cache`.`barcodes` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_botanic_export`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_botanic_export`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_botanic_export` AS select concat(ifnull(concat(`eg`.`latin_genus_name`,' '),''),ifnull(`es`.`latin_species_name`,'')) AS `Nom_botanic`,`be`.`Id_Paises` AS `Id_Paises`,`be`.`restriction` AS `restriction`,`be`.`description` AS `description` from ((`vn2008`.`botanic_export` `be` left join `vn2008`.`edi_genus` `eg` on((`be`.`edi_genus_id` = `eg`.`genus_id`))) left join `vn2008`.`edi_specie` `es` on((`be`.`edi_specie_id` = `es`.`specie_id`))) order by concat(`eg`.`latin_genus_name`,' ',`es`.`latin_species_name`) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_compres`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_compres`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_compres` AS select `TP`.`Id_Tipo` AS `Familia`,`RN`.`id` AS `reino_id`,`C`.`Id_Compra` AS `Id_Compra`,`C`.`Id_Entrada` AS `Id_Entrada`,`C`.`Id_Article` AS `Id_Article`,`C`.`Cantidad` AS `Cantidad`,`C`.`Costefijo` AS `Costefijo`,`C`.`Portefijo` AS `Portefijo`,`C`.`Novincular` AS `Novincular`,`C`.`Etiquetas` AS `Etiquetas`,`C`.`Packing` AS `Packing`,`C`.`grouping` AS `grouping`,`C`.`Comisionfija` AS `Comisionfija`,`C`.`Embalajefijo` AS `Embalajefijo`,`an`.`nicho` AS `Nicho`,`C`.`Id_Cubo` AS `Id_Cubo`,`C`.`Tarifa1` AS `Tarifa1`,`C`.`Tarifa2` AS `Tarifa2`,`C`.`Tarifa3` AS `Tarifa3`,`C`.`PVP` AS `PVP`,`C`.`Vida` AS `Vida`,`C`.`Id_Trabajador` AS `Id_Trabajador`,`C`.`punteo` AS `punteo`,`C`.`odbc_date` AS `odbc_date`,`E`.`Inventario` AS `Inventario`,`E`.`Id_Proveedor` AS `Id_Proveedor`,`E`.`Fecha` AS `Fecha`,`E`.`Confirmada` AS `Confirmada`,`E`.`Redada` AS `Redada`,`E`.`empresa_id` AS `empresa_id`,`E`.`travel_id` AS `travel_id`,`E`.`Pedida` AS `Pedida`,`E`.`recibida_id` AS `recibida_id`,`TR`.`id` AS `id`,`TR`.`shipment` AS `shipment`,`TR`.`landing` AS `landing`,`TR`.`warehouse_id` AS `warehouse_id`,`TR`.`warehouse_id_out` AS `warehouse_id_out`,`TR`.`agency_id` AS `agency_id`,`TR`.`ref` AS `ref`,`TR`.`delivered` AS `delivered`,`TR`.`received` AS `received`,`A`.`Article` AS `Article`,`A`.`Medida` AS `Medida`,`A`.`Tallos` AS `Tallos`,`C`.`caja` AS `caja`,`A`.`Categoria` AS `Categoria`,`A`.`id_origen` AS `id_origen`,`TP`.`Id_Tipo` AS `Tipo`,`A`.`tipo_id` AS `tipo_id`,`A`.`Color` AS `Color`,`A`.`Min` AS `Min`,(((`C`.`Costefijo` + `C`.`Embalajefijo`) + `C`.`Comisionfija`) + `C`.`Portefijo`) AS `Coste`,`W_OUT`.`fuente` AS `fuente`,`A`.`iva_group_id` AS `iva_group_id`,(if((`cb`.`Volumen` > 0),`cb`.`Volumen`,((`cb`.`X` * `cb`.`Y`) * if((`cb`.`Z` = 0),(`A`.`Medida` + 10),`cb`.`Z`))) * `C`.`Etiquetas`) AS `cm3`,`A`.`producer_id` AS `producer_id` from (((((((((`Compres` `C` join `Entradas` `E` on((`C`.`Id_Entrada` = `E`.`Id_Entrada`))) join `travel` `TR` on((`TR`.`id` = `E`.`travel_id`))) join `warehouse` `W_IN` on((`W_IN`.`id` = `TR`.`warehouse_id`))) join `warehouse` `W_OUT` on((`W_OUT`.`id` = `TR`.`warehouse_id_out`))) join `Articles` `A` on((`C`.`Id_Article` = `A`.`Id_Article`))) join `Tipos` `TP` on((`A`.`tipo_id` = `TP`.`tipo_id`))) join `reinos` `RN` on((`RN`.`id` = `TP`.`reino_id`))) join `Cubos` `cb` on((`cb`.`Id_Cubo` = `C`.`Id_Cubo`))) left join `Articles_nicho` `an` on(((`A`.`Id_Article` = `an`.`Id_Article`) and (`an`.`warehouse_id` = `W_IN`.`id`)))) where ((not(`W_IN`.`fuente`)) and (not(`E`.`Inventario`)) and (not(`E`.`Redada`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_departure_limit`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_departure_limit`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_departure_limit` AS select `cache`.`departure_limit`.`warehouse_id` AS `warehouse_id`,`cache`.`departure_limit`.`fecha` AS `fecha`,`cache`.`departure_limit`.`hora` AS `hora`,`cache`.`departure_limit`.`minSpeed` AS `minSpeed` from `cache`.`departure_limit` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_descuadre_bionic`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_descuadre_bionic`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_descuadre_bionic` AS select `t`.`Id_Ticket` AS `Id_Ticket`,`t`.`Alias` AS `Alias`,`m`.`Concepte` AS `Concepte`,sum(`mc`.`Valor`) AS `suma_componente`,`m`.`Preu` AS `Preu`,`m`.`Descuento` AS `Descuento`,(((`m`.`Preu` * (100 - `m`.`Descuento`)) / 100) - sum(`mc`.`Valor`)) AS `diferencia`,`t`.`Fecha` AS `Fecha`,((`m`.`Preu` > 0) and (`tp`.`reino_id` <> 6) and (`a`.`tipo_id` not in (7,115)) and (`t`.`warehouse_id` <> 41)) AS `benvenut` from ((((((`Movimientos` `m` join `Tickets` `t` on((`m`.`Id_Ticket` = `t`.`Id_Ticket`))) join `Clientes` `c` on((`t`.`Id_Cliente` = `c`.`id_cliente`))) join `warehouse` `w` on((`w`.`id` = `t`.`warehouse_id`))) join `Articles` `a` on((`m`.`Id_Article` = `a`.`Id_Article`))) join `Tipos` `tp` on((`a`.`tipo_id` = `tp`.`tipo_id`))) left join `Movimientos_componentes` `mc` on((`m`.`Id_Movimiento` = `mc`.`Id_Movimiento`))) where ((`t`.`Fecha` >= '2015-09-01') and (`t`.`empresa_id` in (442,791,567)) and `w`.`reserve` and `c`.`real` and (`tp`.`reino_id` <> 6)) group by `m`.`Id_Movimiento` having ((abs(`diferencia`) > 0.01) or isnull(`diferencia`)) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_descuadre_porte`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_descuadre_porte`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_descuadre_porte` AS select `t`.`Id_Ticket` AS `Id_Ticket`,round(sum((`mc`.`Valor` * `m`.`Cantidad`)),2) AS `suma_componente`,round(`es`.`shipping_charge`,2) AS `teorico_agencia`,round((sum((`mc`.`Valor` * `m`.`Cantidad`)) - `es`.`shipping_charge`),2) AS `diferencia`,`t`.`Fecha` AS `Fecha` from ((((`vn2008`.`Movimientos` `m` left join `vn2008`.`Movimientos_componentes` `mc` on((`m`.`Id_Movimiento` = `mc`.`Id_Movimiento`))) join `vn2008`.`tarifa_componentes` `tc` on(((`tc`.`Id_Componente` = `mc`.`Id_Componente`) and (`tc`.`tarifa_componentes_series_id` = 6)))) join `vn2008`.`Tickets` `t` on((`t`.`Id_Ticket` = `m`.`Id_Ticket`))) left join `vn2008`.`v_expeditions_shipping_charge` `es` on((`es`.`Id_Ticket` = `t`.`Id_Ticket`))) where ((`t`.`Fecha` >= '2015-09-01') and (`t`.`empresa_id` in (442,791,567))) group by `t`.`Id_Ticket` having ((abs(`diferencia`) > 0.01) or isnull(`diferencia`)) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_descuadre_porte2`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_descuadre_porte2`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_descuadre_porte2` AS select `t`.`Id_Ticket` AS `Id_Ticket`,(`mc`.`Valor` * `m`.`Cantidad`) AS `suma_componente`,`t`.`Fecha` AS `Fecha` from (((`vn2008`.`Movimientos` `m` left join `vn2008`.`Movimientos_componentes` `mc` on((`m`.`Id_Movimiento` = `mc`.`Id_Movimiento`))) join `vn2008`.`tarifa_componentes` `tc` on(((`tc`.`Id_Componente` = `mc`.`Id_Componente`) and (`tc`.`tarifa_componentes_series_id` = 6)))) join `vn2008`.`Tickets` `t` on((`t`.`Id_Ticket` = `m`.`Id_Ticket`))) where ((`t`.`Fecha` >= '2015-09-01') and (`t`.`empresa_id` in (442,791,567))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_empresa`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_empresa`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_empresa` AS select `e`.`logo` AS `logo`,`e`.`id` AS `id`,`e`.`registro` AS `registro`,`e`.`gerente_id` AS `gerente_id`,`e`.`alta` AS `alta`,`t`.`Nombre` AS `Nombre`,`t`.`Apellidos` AS `Apellidos`,`p`.`Proveedor` AS `Proveedor`,`p`.`Domicilio` AS `Domicilio`,`p`.`CP` AS `CP`,`p`.`Localidad` AS `Localidad`,`p`.`NIF` AS `NIF`,`p`.`Telefono` AS `Telefono`,`p`.`Alias` AS `Alias`,`e`.`abbreviation` AS `abbreviation` from ((`empresa` `e` join `Trabajadores` `t` on((`t`.`Id_Trabajador` = `e`.`gerente_id`))) join `Proveedores` `p` on((`p`.`Id_Proveedor` = `e`.`id`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_encajado`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_encajado`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_encajado` AS select hour(`e`.`odbc_date`) AS `hora`,minute(`e`.`odbc_date`) AS `minuto`,ifnull(`c`.`Volumen`,94500) AS `cm3`,`t`.`warehouse_id` AS `warehouse_id` from ((`expeditions` `e` left join `Cubos` `c` on((`c`.`item_id` = `e`.`EsBulto`))) join `Tickets` `t` on((`t`.`Id_Ticket` = `e`.`ticket_id`))) where (`e`.`odbc_date` between curdate() and `DAYEND`(curdate())) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_encajado_ultima_hora`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_encajado_ultima_hora`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_encajado_ultima_hora` AS select sum((ifnull(`c`.`Volumen`,94500) / 1000000)) AS `m3`,`t`.`warehouse_id` AS `warehouse_id` from ((`expeditions` `e` left join `Cubos` `c` on((`c`.`item_id` = `e`.`EsBulto`))) join `Tickets` `t` on((`t`.`Id_Ticket` = `e`.`ticket_id`))) where ((`e`.`odbc_date` > (now() + interval -(1) hour)) and (`t`.`warehouse_id` in (1,44))) group by `t`.`warehouse_id` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_expeditions_shipping_charge`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_expeditions_shipping_charge`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_expeditions_shipping_charge` AS select `t`.`Id_Ticket` AS `Id_Ticket`,sum((`az`.`price` * if(((`e`.`EsBulto` = 71) and isnull(`e`.`Id_Article`) and (`a`.`Vista` = 2)),0.75,1))) AS `shipping_charge`,`t`.`Fecha` AS `Fecha` from ((((((`Tickets` `t` join `Clientes` `cli` on((`cli`.`id_cliente` = `t`.`Id_Cliente`))) left join `expeditions` `e` 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 (`cli`.`real` <> 0) and (`t`.`empresa_id` in (442,791,567))) group by `t`.`Id_Ticket` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_expeditions_shipping_charge2`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_expeditions_shipping_charge2`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_expeditions_shipping_charge2` AS select `t`.`Id_Ticket` AS `Id_Ticket`,(`az`.`price` * if(((`e`.`EsBulto` = 71) and isnull(`e`.`Id_Article`) and (`a`.`Vista` = 2)),0.75,1)) AS `shipping_charge`,`t`.`Fecha` AS `Fecha`,`t`.`warehouse_id` AS `warehouse_id` from (((((`Tickets` `t` left join `expeditions` `e` 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` >= '2016-01-01') and (`t`.`empresa_id` in (442,567))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_fallo`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_fallo`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_fallo` AS select `vncontrol`.`fallo`.`queja_id` AS `queja_id`,`vncontrol`.`fallo`.`accion_id` AS `accion_id` from `vncontrol`.`fallo` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_inter`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_inter`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_inter` AS select `vncontrol`.`inter`.`inter_id` AS `inter_id`,`vncontrol`.`inter`.`state_id` AS `state_id`,`vncontrol`.`inter`.`nota` AS `nota`,`vncontrol`.`inter`.`odbc_date` AS `odbc_date`,`vncontrol`.`inter`.`Id_Ticket` AS `Id_Ticket`,`vncontrol`.`inter`.`Id_Trabajador` AS `Id_Trabajador`,`vncontrol`.`inter`.`Id_Supervisor` AS `Id_supervisor` from `vncontrol`.`inter` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_jerarquia`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_jerarquia`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_jerarquia` AS select `jerarquia`.`worker_id` AS `Id_Trabajador`,`jerarquia`.`boss_id` AS `boss_id` from `jerarquia` union all select distinct `jerarquia`.`boss_id` AS `Id_Trabajador`,`jerarquia`.`boss_id` AS `boss_id` from `jerarquia` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_location`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_location`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_location` AS select `tl`.`longitude` AS `longitude`,`tl`.`latitude` AS `latitude`,`t`.`Id_Consigna` AS `Id_Consigna` from (`ticket_location` `tl` join `Tickets` `t` on((`t`.`Id_Ticket` = `tl`.`Id_Ticket`))) where (`t`.`Fecha` >= (curdate() + interval -(3) month)) group by `t`.`Id_Consigna` order by `t`.`Id_Ticket` desc */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_mana_spellers`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_mana_spellers`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_mana_spellers` AS select `bs`.`mana_spellers`.`Id_Trabajador` AS `Id_Trabajador`,`bs`.`mana_spellers`.`size` AS `size`,`bs`.`mana_spellers`.`used` AS `used` from `bs`.`mana_spellers` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_miriam`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_miriam`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_miriam` AS select `M`.`Id_Article` AS `Id_Article`,`M`.`Concepte` AS `Concepte`,`M`.`Cantidad` AS `Cantidad`,`M`.`Preu` AS `Preu`,`M`.`Descuento` AS `Descuento`,`T`.`Fecha` AS `Fecha`,`T`.`Id_Cliente` AS `Id_Cliente`,(((`M`.`Cantidad` * `M`.`Preu`) * (100 - `M`.`Descuento`)) / 100) AS `Importe` from (((`Tickets` `T` join `Movimientos` `M` on((`T`.`Id_Ticket` = `M`.`Id_Ticket`))) join `Articles` `A` on((`M`.`Id_Article` = `A`.`Id_Article`))) join `Tipos` `TP` on((`A`.`tipo_id` = `TP`.`tipo_id`))) where ((`T`.`Fecha` >= '2011-01-01') and (`A`.`tipo_id` = 7)) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_movimientos_log`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_movimientos_log`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_movimientos_log` AS select `bi`.`movimientos_log`.`idmovimientos_log` AS `idmovimientos_log`,`bi`.`movimientos_log`.`Id_Movimiento` AS `Id_Movimiento`,`bi`.`movimientos_log`.`odbc_date` AS `odbc_date`,`bi`.`movimientos_log`.`Id_Trabajador` AS `Id_Trabajador`,`bi`.`movimientos_log`.`field_name` AS `field_name`,`bi`.`movimientos_log`.`new_value` AS `new_value` from `bi`.`movimientos_log` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_movimientos_mark`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_movimientos_mark`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_movimientos_mark` AS select `Movimientos_mark`.`Id_Movimiento` AS `Id_Movimiento`,max(`Movimientos_mark`.`Id_Accion`) AS `Accion` from `Movimientos_mark` group by `Movimientos_mark`.`Id_Movimiento` having ((max(`Movimientos_mark`.`Id_Accion`) = '6') or (max(`Movimientos_mark`.`Id_Accion`) = '7')) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_pedidos_auto_preparados`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_pedidos_auto_preparados`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_pedidos_auto_preparados` AS select `t`.`CodigoTrabajador` AS `CodigoTrabajador`,`i`.`Id_Ticket` AS `Id_Ticket`,`i`.`odbc_date` AS `Momento` from ((`vn2008`.`v_jerarquia` `j` left join `vn2008`.`v_inter` `i` on((`j`.`Id_Trabajador` = `i`.`Id_Trabajador`))) join `vn2008`.`Trabajadores` `t` on((`t`.`Id_Trabajador` = `j`.`Id_Trabajador`))) where (`i`.`state_id` = 20) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_pedidos_auto_preparadoskk`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_pedidos_auto_preparadoskk`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_pedidos_auto_preparadoskk` AS select `t`.`CodigoTrabajador` AS `CodigoTrabajador`,`TK`.`Fecha` AS `Fecha`,`TK`.`Id_Ticket` AS `Id_Ticket`,`i`.`odbc_date` AS `Momento` from (((`vn2008`.`v_jerarquia` `j` left join `vn2008`.`v_inter` `i` on((`j`.`Id_Trabajador` = `i`.`Id_Trabajador`))) join `vn2008`.`Trabajadores` `t` on((`t`.`Id_Trabajador` = `j`.`Id_Trabajador`))) left join `vn2008`.`Tickets` `TK` on((`TK`.`Id_Ticket` = `i`.`Id_Ticket`))) where (`i`.`state_id` = 5) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_phonebook`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_phonebook`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_phonebook` AS select `Clientes`.`id_cliente` AS `Id_Cliente`,replace(`Clientes`.`telefono`,' ','') AS `Telefono` from `Clientes` where (`Clientes`.`telefono` and `Clientes`.`activo`) union select `Clientes`.`id_cliente` AS `Id_Cliente`,replace(`Clientes`.`movil`,' ','') AS `Movil` from `Clientes` where (`Clientes`.`movil` and `Clientes`.`activo`) union select `Consignatarios`.`Id_cliente` AS `Id_Cliente`,replace(`Consignatarios`.`telefono`,' ','') AS `TRIM(telefono)` from (`Consignatarios` join `Clientes` `c` on((`Consignatarios`.`Id_cliente` = `c`.`id_cliente`))) where (`Consignatarios`.`telefono` and `c`.`activo`) union select `Consignatarios`.`Id_cliente` AS `Id_Cliente`,replace(`Consignatarios`.`movil`,' ','') AS `TRIM(movil)` from (`Consignatarios` join `Clientes` `c` on((`Consignatarios`.`Id_cliente` = `c`.`id_cliente`))) where (`Consignatarios`.`movil` and `c`.`activo`) union select `r`.`Id_Cliente` AS `Id_Cliente`,replace(`c`.`Telefono`,' ','') AS `REPLACE(c.telefono,' ','')` from ((`Clientes` `cl` join `Relaciones` `r` on((`cl`.`id_cliente` = `r`.`Id_Cliente`))) join `Contactos` `c` on((`r`.`Id_Contacto` = `c`.`Id_Contacto`))) where (`cl`.`telefono` and `cl`.`activo`) union select `r`.`Id_Cliente` AS `Id_Cliente`,replace(`c`.`Movil`,' ','') AS `REPLACE(c.Movil,' ','')` from ((`Clientes` `cl` join `Relaciones` `r` on((`cl`.`id_cliente` = `r`.`Id_Cliente`))) join `Contactos` `c` on((`r`.`Id_Contacto` = `c`.`Id_Contacto`))) where (`cl`.`movil` and `cl`.`activo`) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_price_fixed`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_price_fixed`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_price_fixed` AS select `pf`.`warehouse_id` AS `warehouse_id`,`pf`.`item_id` AS `item_id`,`pf`.`rate_0` AS `rate_0`,`pf`.`rate_1` AS `rate_1`,`pf`.`rate_2` AS `rate_2`,`pf`.`rate_3` AS `rate_3`,`pf`.`date_start` AS `date_start`,`pf`.`date_end` AS `date_end`,`pf`.`bonus` AS `bonus`,`pf`.`grouping` AS `grouping`,`pf`.`Packing` AS `Packing`,`pf`.`caja` AS `caja` from `price_fixed` `pf` where (`pf`.`warehouse_id` < 1000) union all select `wg`.`warehouse_id` AS `warehouse_id`,`pf`.`item_id` AS `item_id`,`pf`.`rate_0` AS `rate_0`,`pf`.`rate_1` AS `rate_1`,`pf`.`rate_2` AS `rate_2`,`pf`.`rate_3` AS `rate_3`,`pf`.`date_start` AS `date_start`,`pf`.`date_end` AS `date_end`,`pf`.`bonus` AS `bonus`,`pf`.`grouping` AS `grouping`,`pf`.`Packing` AS `Packing`,`pf`.`caja` AS `caja` from (`price_fixed` `pf` join `warehouse_group` `wg`) where ((`wg`.`warehouse_alias_id` + 1000) = `pf`.`warehouse_id`) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_price_fixed_group`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_price_fixed_group`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_price_fixed_group` AS select `pf`.`warehouse_id` AS `warehouse_id`,`pf`.`item_id` AS `item_id`,`pf`.`rate_0` AS `rate_0`,`pf`.`rate_1` AS `rate_1`,`pf`.`rate_2` AS `rate_2`,`pf`.`rate_3` AS `rate_3`,`pf`.`date_start` AS `date_start`,`pf`.`date_end` AS `date_end`,`pf`.`bonus` AS `bonus`,`pf`.`grouping` AS `grouping`,`pf`.`Packing` AS `Packing`,`pf`.`caja` AS `caja` from `v_price_fixed` `pf` group by `pf`.`warehouse_id`,`pf`.`item_id`,`pf`.`date_start`,`pf`.`date_end` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_session`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_session`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_session` AS select 1 AS `id`,`t`.`CodigoTrabajador` AS `CodigoTrabajador`,if(isnull(`sc`.`Id_Suplente`),`c`.`Id_Trabajador`,`sc`.`Id_Suplente`) AS `Id_Trabajador`,`c`.`id_cliente` AS `Id_Cliente`,`c`.`cliente` AS `Cliente`,`s`.`lastUpdate` AS `Fecha` from ((((`hedera`.`userSession` `s` join `hedera`.`visitUser` `v` on((`v`.`id` = `s`.`userVisit`))) join `vn2008`.`Clientes` `c` on((`c`.`id_cliente` = `v`.`user`))) left join `vn2008`.`Trabajadores` `t` on((`c`.`Id_Trabajador` = `t`.`Id_Trabajador`))) left join `vn2008`.`sharingcart` `sc` on(((`sc`.`Id_Trabajador` = `c`.`Id_Trabajador`) and (curdate() between `sc`.`datSTART` and `sc`.`datEND`)))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_ticket_amount`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_ticket_amount`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_ticket_amount` AS select `Movimientos`.`Id_Ticket` AS `Id_Ticket`,sum((((`Movimientos`.`Cantidad` * `Movimientos`.`Preu`) * (100 - `Movimientos`.`Descuento`)) / 100)) AS `amount` from (`Movimientos` join `Tickets` on((`Movimientos`.`Id_Ticket` = `Tickets`.`Id_Ticket`))) where (`Tickets`.`Fecha` >= (curdate() + interval -(6) month)) group by `Movimientos`.`Id_Ticket` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_trabajadores`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_trabajadores`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_trabajadores` AS select `t`.`CodigoTrabajador` AS `CodigoTrabajador`,`t`.`Nombre` AS `Nombre`,`t`.`Fecha_Inicio` AS `Fecha_Inicio`,`t`.`Password` AS `Password`,`t`.`user` AS `user`,`t`.`Apellidos` AS `Apellidos`,`t`.`Id_Trabajador` AS `Id_Trabajador`,`t`.`Foto` AS `Foto` from `vn2008`.`Trabajadores` `t` where (`t`.`Id_Cliente_Interno` = `account`.`userGetId`()) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_user`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_user`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_user` AS select `u`.`id` AS `id`,`u`.`role` AS `mysql_user_id`,`u`.`name` AS `name`,`u`.`password` AS `password`,`u`.`active` AS `active` from `account`.`user` `u` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_ventes`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_ventes`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_ventes` AS select `Agencias`.`Agencia` AS `Agencia`,`A`.`Categoria` AS `Categoria`,`A`.`tipo_id` AS `tipo_id`,`A`.`Medida` AS `Medida`,`A`.`Article` AS `Article`,`A`.`Color` AS `Color`,`CS`.`Id_cliente` AS `Id_Cliente`,`TP`.`Id_Tipo` AS `Tipo`,`T`.`Factura` AS `Factura`,`T`.`warehouse_id` AS `warehouse_id`,`M`.`Id_Movimiento` AS `Id_Movimiento`,`M`.`Id_Article` AS `Id_Article`,`TP`.`Id_Tipo` AS `Familia`,`M`.`Id_Ticket` AS `Id_Ticket`,`M`.`Concepte` AS `Concepte`,`M`.`Cantidad` AS `Cantidad`,`M`.`quantity` AS `quantity`,`M`.`Preu` AS `Preu`,`M`.`Descuento` AS `Descuento`,if((`T`.`Fecha` >= '2015-10-01'),`M`.`CostFixat`,((`M`.`Preu` * (100 - `M`.`Descuento`)) / 100)) AS `CostFixat`,`M`.`Reservado` AS `Reservado`,`M`.`OK` AS `OK`,`M`.`PrecioFijado` AS `PrecioFijado`,`M`.`odbc_date` AS `odbc_date`,cast(`T`.`Fecha` as date) AS `Fecha`,`T`.`Fecha` AS `FechaCompleta`,`CS`.`consignatario` AS `Alias`,`T`.`Id_Consigna` AS `Id_Consigna`,(((`M`.`Cantidad` * `M`.`Preu`) * (100 - `M`.`Descuento`)) / 100) AS `Importe`,`O`.`Origen` AS `Origen`,`TP`.`reino_id` AS `reino_id`,`C`.`invoice` AS `invoice`,`A`.`producer_id` AS `producer_id` from ((((((((`Movimientos` `M` join `Tickets` `T` on((`M`.`Id_Ticket` = `T`.`Id_Ticket`))) join `Consignatarios` `CS` on((`CS`.`id_consigna` = `T`.`Id_Consigna`))) join `Clientes` `C` on((`CS`.`Id_cliente` = `C`.`id_cliente`))) join `Articles` `A` on((`M`.`Id_Article` = `A`.`Id_Article`))) join `Origen` `O` on((`O`.`id` = `A`.`id_origen`))) join `Tipos` `TP` on((`A`.`tipo_id` = `TP`.`tipo_id`))) join `reinos` `r` on((`TP`.`reino_id` = `r`.`id`))) join `Agencias` on((`Agencias`.`Id_Agencia` = `T`.`Id_Agencia`))) where ((`T`.`Fecha` >= '2013-01-01') and (`C`.`real` > 0) and (`r`.`id` <> 6)) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_venteskk`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_venteskk`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_venteskk` AS select `Agencias`.`Agencia` AS `Agencia`,`A`.`Categoria` AS `Categoria`,`A`.`tipo_id` AS `tipo_id`,`A`.`Medida` AS `Medida`,`A`.`Article` AS `Article`,`A`.`Color` AS `Color`,`CS`.`Id_cliente` AS `Id_Cliente`,`TP`.`Id_Tipo` AS `Tipo`,`T`.`Factura` AS `Factura`,`T`.`warehouse_id` AS `warehouse_id`,`M`.`Id_Movimiento` AS `Id_Movimiento`,`M`.`Id_Article` AS `Id_Article`,`TP`.`Id_Tipo` AS `Familia`,`M`.`Id_Ticket` AS `Id_Ticket`,`M`.`Concepte` AS `Concepte`,`M`.`Cantidad` AS `Cantidad`,`M`.`quantity` AS `quantity`,`M`.`Preu` AS `Preu`,`M`.`Descuento` AS `Descuento`,if((`T`.`Fecha` >= '2015-10-01'),`M`.`CostFixat`,((`M`.`Preu` * (100 - `M`.`Descuento`)) / 100)) AS `CostFixat`,`M`.`Reservado` AS `Reservado`,`M`.`OK` AS `OK`,`M`.`PrecioFijado` AS `PrecioFijado`,`M`.`odbc_date` AS `odbc_date`,cast(`T`.`Fecha` as date) AS `Fecha`,`T`.`Fecha` AS `FechaCompleta`,`CS`.`consignatario` AS `Alias`,`T`.`Id_Consigna` AS `Id_Consigna`,(((`M`.`Cantidad` * `M`.`Preu`) * (100 - `M`.`Descuento`)) / 100) AS `Importe`,`O`.`Origen` AS `Origen`,`TP`.`reino_id` AS `reino_id`,`C`.`invoice` AS `invoice`,`A`.`producer_id` AS `producer_id` from ((((((((`Movimientos` `M` join `Tickets` `T` on((`M`.`Id_Ticket` = `T`.`Id_Ticket`))) join `Consignatarios` `CS` on((`CS`.`id_consigna` = `T`.`Id_Consigna`))) join `Clientes` `C` on((`CS`.`Id_cliente` = `C`.`id_cliente`))) join `Articles` `A` on((`M`.`Id_Article` = `A`.`Id_Article`))) join `Origen` `O` on((`O`.`id` = `A`.`id_origen`))) join `Tipos` `TP` on((`A`.`tipo_id` = `TP`.`tipo_id`))) join `reinos` `r` on((`TP`.`reino_id` = `r`.`id`))) join `Agencias` on((`Agencias`.`Id_Agencia` = `T`.`Id_Agencia`))) where ((`T`.`Fecha` >= '2013-01-01') and (`C`.`real` > 0) and (`r`.`id` <> 6)) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_warehouse`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_warehouse`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_warehouse` AS select `warehouse`.`id` AS `id`,`warehouse`.`name` AS `almacen` from `warehouse` union all select (1000 + `warehouse_alias`.`warehouse_alias_id`) AS `warehouse_alias_id`,concat(`warehouse_alias`.`alias`,'(G)') AS `concat(alias, '(G)')` from `warehouse_alias` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_xsubclien`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_xsubclien`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_xsubclien` AS select distinct `Facturas`.`Id_Cliente` AS `Id_Cliente`,`Facturas`.`empresa_id` AS `empresa_id` from `Facturas` where (`Facturas`.`Fecha` > (curdate() + interval -(2) month)) union select `Recibos`.`Id_Cliente` AS `Id_Cliente`,`Recibos`.`empresa_id` AS `empresa_id` from `Recibos` where (`Recibos`.`Fechacobro` > (curdate() + interval -(2) month)) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_xsubcuentas`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_xsubcuentas`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_xsubcuentas` AS select `Clientes`.`Cuenta` AS `COD`,`Clientes`.`razonSocial` AS `TITULO`,trim(`Clientes`.`if`) AS `NIF`,`Clientes`.`domicilio` AS `DOMICILIO`,`Clientes`.`poblacion` AS `POBLACION`,`province`.`name` AS `PROVINCIA`,`Clientes`.`codPostal` AS `CODPOSTAL`,`p`.`Codigo` AS `country_code`,`v_xsubclien`.`empresa_id` AS `empresa_id`,substr(`Clientes`.`e-mail`,1,(coalesce(nullif(locate(',',`Clientes`.`e-mail`),0),99) - 1)) AS `EMAIL`,`Clientes`.`cplusTerIdNifFk` AS `IDNIF` from (((`Clientes` join `v_xsubclien` on((`Clientes`.`id_cliente` = `v_xsubclien`.`Id_Cliente`))) left join `Paises` `p` on((`p`.`Id` = `Clientes`.`Id_Pais`))) join `province` on((`Clientes`.`province_id` = `province`.`province_id`))) where (`Clientes`.`oficial` <> 0) group by `Clientes`.`id_cliente`,`v_xsubclien`.`empresa_id` union all select `Proveedores`.`cuenta` AS `Cuenta`,`Proveedores`.`Proveedor` AS `Proveedor`,trim(`Proveedores`.`NIF`) AS `NIF`,`Proveedores`.`Domicilio` AS `Domicilio`,`Proveedores`.`Localidad` AS `Localidad`,`prov`.`name` AS `Provincia`,`Proveedores`.`CP` AS `CP`,`p`.`Codigo` AS `country_code`,`v_xsubprov`.`empresa_id` AS `empresa_id`,substr(`c`.`email`,1,(coalesce(nullif(locate(',',`c`.`email`),0),99) - 1)) AS `EMAIL`,if((`p`.`CEE` = 0),1,if((`p`.`CEE` = 1),2,4)) AS `IDNIF` from (((((`Proveedores` join `v_xsubprov` on((`Proveedores`.`Id_Proveedor` = `v_xsubprov`.`proveedor_id`))) left join `Paises` `p` on((`p`.`Id` = `Proveedores`.`pais_id`))) left join `province` `prov` on((`prov`.`province_id` = `Proveedores`.`province_id`))) left join `Relaciones` `r` on((`r`.`Id_Proveedor` = `Proveedores`.`Id_Proveedor`))) left join `Contactos` `c` on((`c`.`Id_Contacto` = `r`.`Id_Contacto`))) where (`Proveedores`.`oficial` <> 0) group by `v_xsubprov`.`proveedor_id`,`v_xsubprov`.`empresa_id` union all select `Gastos`.`Id_Gasto` AS `Id_Gasto`,`Gastos`.`Gasto` AS `Gasto`,NULL AS `NULL`,NULL AS `My_exp_NULL`,NULL AS `My_exp_1_NULL`,NULL AS `My_exp_2_NULL`,NULL AS `My_exp_3_NULL`,NULL AS `country_code`,`e`.`id` AS `id`,NULL AS `EMAIL`,1 AS `IDNIF` from (`Gastos` join `empresa` `e` on((`e`.`id` = 442))) union all select `Bancos`.`Cuenta` AS `Cuenta`,`Bancos`.`Banco` AS `Banco`,NULL AS `NULL`,NULL AS `My_exp_NULL`,NULL AS `My_exp_1_NULL`,NULL AS `My_exp_2_NULL`,NULL AS `My_exp_3_NULL`,NULL AS `country_code`,`e`.`id` AS `id`,NULL AS `EMAIL`,1 AS `IDNIF` from (`Bancos` join `empresa` `e` on((`e`.`id` = 442))) union all select lpad(right(`Proveedores`.`cuenta`,5),10,'47510000') AS `Cuenta`,`Proveedores`.`Proveedor` AS `Proveedor`,`Proveedores`.`NIF` AS `NIF`,`Proveedores`.`Domicilio` AS `Domicilio`,`Proveedores`.`Localidad` AS `Localidad`,`prov`.`name` AS `Provincia`,`Proveedores`.`CP` AS `CP`,`p`.`Codigo` AS `country_code`,`v_xsubprov`.`empresa_id` AS `empresa_id`,substr(`c`.`email`,1,(coalesce(nullif(locate(',',`c`.`email`),0),99) - 1)) AS `EMAIL`,if((`p`.`CEE` = 0),1,if((`p`.`CEE` = 1),2,4)) AS `IDNIF` from (((((`Proveedores` join `v_xsubprov` on((`Proveedores`.`Id_Proveedor` = `v_xsubprov`.`proveedor_id`))) left join `Paises` `p` on((`p`.`Id` = `Proveedores`.`pais_id`))) left join `province` `prov` on((`prov`.`province_id` = `Proveedores`.`province_id`))) left join `Relaciones` `r` on((`r`.`Id_Proveedor` = `Proveedores`.`Id_Proveedor`))) left join `Contactos` `c` on((`c`.`Id_Contacto` = `r`.`Id_Contacto`))) where (((`Proveedores`.`cuenta` like '_____3____') or (`Proveedores`.`cuenta` like '_____2____')) and (`Proveedores`.`oficial` = 1)) group by `v_xsubprov`.`proveedor_id`,`v_xsubprov`.`empresa_id` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_xsubprov`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_xsubprov`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_xsubprov` AS select `recibida`.`proveedor_id` AS `proveedor_id`,`recibida`.`empresa_id` AS `empresa_id` from `recibida` where (`recibida`.`fecha` > (curdate() + interval -(3) month)) group by `recibida`.`proveedor_id`,`recibida`.`empresa_id` union all select `pago`.`id_proveedor` AS `id_proveedor`,`pago`.`empresa_id` AS `empresa_id` from `pago` where (`pago`.`fecha` > (curdate() + interval -(3) month)) group by `pago`.`id_proveedor`,`pago`.`empresa_id` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `vnCreditClassification`
---
-
-/*!50001 DROP VIEW IF EXISTS `vnCreditClassification`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `vnCreditClassification` AS select `vn`.`creditClassification`.`id` AS `id`,`vn`.`creditClassification`.`client` AS `client`,`vn`.`creditClassification`.`dateStart` AS `dateStart`,`vn`.`creditClassification`.`dateEnd` AS `dateEnd` from `vn`.`creditClassification` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `vnCreditInsurance`
---
-
-/*!50001 DROP VIEW IF EXISTS `vnCreditInsurance`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `vnCreditInsurance` AS select `vn`.`creditInsurance`.`id` AS `id`,`vn`.`creditInsurance`.`creditClassification` AS `creditClassification`,`vn`.`creditInsurance`.`credit` AS `credit`,`vn`.`creditInsurance`.`creationDate` AS `creationDate`,`vn`.`creditInsurance`.`grade` AS `grade` from `vn`.`creditInsurance` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `vnSolunionCAP`
---
-
-/*!50001 DROP VIEW IF EXISTS `vnSolunionCAP`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `vnSolunionCAP` AS select `vn`.`solunionCAP`.`creditInsurance` AS `creditInsurance`,`vn`.`solunionCAP`.`dateStart` AS `dateStart`,`vn`.`solunionCAP`.`dateEnd` AS `dateEnd`,`vn`.`solunionCAP`.`dateLeaving` AS `dateLeaving` from `vn`.`solunionCAP` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `workerDocument`
---
-
-/*!50001 DROP VIEW IF EXISTS `workerDocument`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `workerDocument` AS select `vn`.`workerDocument`.`id` AS `id`,`vn`.`workerDocument`.`worker` AS `worker`,`vn`.`workerDocument`.`document` AS `document` from `vn`.`workerDocument` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `workerTeamCollegues`
---
-
-/*!50001 DROP VIEW IF EXISTS `workerTeamCollegues`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `workerTeamCollegues` AS select distinct `w`.`Id_Trabajador` AS `workerId`,`t`.`Id_Trabajador` AS `collegueId` from (`vn`.`workerTeam` `w` join `vn`.`workerTeam` `t` on((`w`.`team` = `t`.`team`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `workerTeam_kk`
---
-
-/*!50001 DROP VIEW IF EXISTS `workerTeam_kk`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `workerTeam_kk` AS select `w`.`team` AS `team`,`w`.`user` AS `user`,`w`.`id` AS `id`,`t`.`Id_Trabajador` AS `Id_Trabajador` from (`vn`.`workerTeam` `w` left join `vn2008`.`Trabajadores` `t` on((`t`.`user_id` = `w`.`user`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Current Database: `bi`
---
-
-USE `bi`;
-
---
--- Final view structure for view `analisis_grafico_ventas`
---
-
-/*!50001 DROP VIEW IF EXISTS `analisis_grafico_ventas`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `analisis_grafico_ventas` AS select `analisis_ventas`.`Año` AS `Año`,`analisis_ventas`.`Semana` AS `Semana`,sum(`analisis_ventas`.`Importe`) AS `Importe` from `analisis_ventas` group by `analisis_ventas`.`Año`,`analisis_ventas`.`Semana` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `analisis_ventas_simple`
---
-
-/*!50001 DROP VIEW IF EXISTS `analisis_ventas_simple`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `analisis_ventas_simple` AS select `analisis_ventas`.`Año` AS `Año`,`analisis_ventas`.`Semana` AS `Semana`,sum(`analisis_ventas`.`Importe`) AS `Importe` from `analisis_ventas` group by `analisis_ventas`.`Año`,`analisis_ventas`.`Semana` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `customerRiskOverdue`
---
-
-/*!50001 DROP VIEW IF EXISTS `customerRiskOverdue`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `customerRiskOverdue` AS select `cr`.`customer_id` AS `customer_id`,`cr`.`amount` AS `amount`,`cr`.`company_id` AS `company_id` from (((`bi`.`customer_risk` `cr` join `vn2008`.`empresa` `e` on((`e`.`id` = `cr`.`company_id`))) join `vn2008`.`Clientes` `c` on((`cr`.`customer_id` = `c`.`id_cliente`))) join `vn2008`.`pay_met` `pm` on((`pm`.`id` = `c`.`pay_met_id`))) where (`cr`.`amount` and `e`.`morosidad` and `pm`.`deudaviva`) union all select `f`.`Id_Cliente` AS `Id_Cliente`,-(round(`f`.`Importe`,2)) AS `importe`,`f`.`empresa_id` AS `empresa_id` from (((`vn2008`.`Facturas` `f` join `vn2008`.`Clientes` `c` on((`f`.`Id_Cliente` = `c`.`id_cliente`))) join `vn2008`.`empresa` `e` on((`e`.`id` = `f`.`empresa_id`))) join `vn2008`.`pay_met` `pm` on((`pm`.`id` = `c`.`pay_met_id`))) where ((`f`.`Fecha` > (curdate() + interval -(101) day)) and ((`vn2008`.`paymentday`(`f`.`Fecha`,`c`.`vencimiento`) + interval `pm`.`graceDays` day) > curdate()) and (`f`.`Importe` > 0) and `e`.`morosidad` and `pm`.`deudaviva`) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `last_Id_Cubo`
---
-
-/*!50001 DROP VIEW IF EXISTS `last_Id_Cubo`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `last_Id_Cubo` AS select `C`.`Id_Compra` AS `Id_Compra`,`C`.`Id_Article` AS `Id_Article`,`tr`.`warehouse_id` AS `warehouse_id`,`C`.`Id_Cubo` AS `Id_Cubo`,`C`.`Packing` AS `Packing` from ((`vn2008`.`Compres` `C` join `vn2008`.`Entradas` `E` on((`C`.`Id_Entrada` = `E`.`Id_Entrada`))) join `vn2008`.`travel` `tr` on((`E`.`travel_id` = `tr`.`id`))) where ((`C`.`Id_Cubo` is not null) and (`C`.`Id_Cubo` <> '--') and (`tr`.`landing` > (curdate() - interval 18 month))) order by `C`.`Id_Compra` desc */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_clientes_jerarquia`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_clientes_jerarquia`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_clientes_jerarquia` AS select `c`.`id_cliente` AS `Id_Cliente`,`c`.`cliente` AS `Cliente`,`t`.`CodigoTrabajador` AS `Comercial`,`tj`.`CodigoTrabajador` AS `Jefe` from (((`vn2008`.`Clientes` `c` join `vn2008`.`Trabajadores` `t` on((`t`.`Id_Trabajador` = `c`.`Id_Trabajador`))) join `vn2008`.`jerarquia` on((`vn2008`.`jerarquia`.`worker_id` = `c`.`Id_Trabajador`))) join `vn2008`.`Trabajadores` `tj` on((`tj`.`Id_Trabajador` = `vn2008`.`jerarquia`.`boss_id`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_ventas_contables`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_ventas_contables`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_ventas_contables` AS select `vn2008`.`time`.`year` AS `year`,`vn2008`.`time`.`month` AS `month`,cast(sum((((`m`.`Cantidad` * `m`.`Preu`) * (100 - `m`.`Descuento`)) / 100)) as decimal(10,0)) AS `importe` from (((`vn2008`.`Tickets` `t` join `bi`.`f_tvc` on((`t`.`Id_Ticket` = `bi`.`f_tvc`.`Id_Ticket`))) join `vn2008`.`Movimientos` `m` on((`t`.`Id_Ticket` = `m`.`Id_Ticket`))) join `vn2008`.`time` on((`vn2008`.`time`.`date` = cast(`t`.`Fecha` as date)))) where (`t`.`Fecha` >= '2014-01-01') group by `vn2008`.`time`.`year`,`vn2008`.`time`.`month` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Current Database: `vn`
---
-
-USE `vn`;
-
---
--- Final view structure for view `accounting`
---
-
-/*!50001 DROP VIEW IF EXISTS `accounting`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `accounting` AS select `b`.`Id_Banco` AS `id`,`b`.`Banco` AS `bank`,`b`.`Cuenta` AS `account`,`b`.`cash` AS `accountingTypeFk`,`b`.`entity_id` AS `entityFk`,`b`.`activo` AS `isActive` from `vn2008`.`Bancos` `b` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `address`
---
-
-/*!50001 DROP VIEW IF EXISTS `address`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `address` AS select `cs`.`Id_cliente` AS `customer`,`cs`.`warehouse_id` AS `warehouse`,`cs`.`domicilio` AS `street`,`cs`.`poblacion` AS `city`,`cs`.`province_id` AS `province`,`cs`.`codPostal` AS `postalCode`,`cs`.`telefono` AS `phone`,`cs`.`movil` AS `celular`,`cs`.`consignatario` AS `nickname`,`cs`.`id_consigna` AS `id`,`cs`.`predeterminada` AS `defaultAddress`,`cs`.`Id_Agencia` AS `agency`,`cs`.`active` AS `active`,`cs`.`longitude` AS `longitude`,`cs`.`latitude` AS `latitude`,`cs`.`Id_cliente` AS `clientFk`,`cs`.`warehouse_id` AS `warehouseFk`,`cs`.`province_id` AS `provinceFk`,`cs`.`movil` AS `mobile`,`cs`.`Id_Agencia` AS `agencyFk`,`cs`.`isEqualizated` AS `isEqualizated` from `vn2008`.`Consignatarios` `cs` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `addressObservation`
---
-
-/*!50001 DROP VIEW IF EXISTS `addressObservation`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `addressObservation` AS select `co`.`consignatarios_observation_id` AS `id`,`co`.`Id_Consigna` AS `addressFk`,`co`.`observation_type_id` AS `observationTypeFk`,`co`.`text` AS `description` from `vn2008`.`consignatarios_observation` `co` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `agency`
---
-
-/*!50001 DROP VIEW IF EXISTS `agency`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `agency` AS select `a`.`agency_id` AS `id`,`a`.`name` AS `name`,`a`.`warehouse_id` AS `warehouse`,`a`.`warehouse_id` AS `warehouseFk`,`a`.`por_volumen` AS `isVolumetric`,`a`.`Id_Banco` AS `bank`,`a`.`Id_Banco` AS `bankFk`,`a`.`warehouse_alias_id` AS `warehouseNickname`,`a`.`warehouse_alias_id` AS `warehouseAliasFk`,`a`.`propios` AS `own`,`a`.`zone_label` AS `labelZone` from `vn2008`.`agency` `a` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `agencyHour`
---
-
-/*!50001 DROP VIEW IF EXISTS `agencyHour`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `agencyHour` AS select `h`.`agency_hour_id` AS `id`,`h`.`agency_id` AS `agency`,`h`.`week_day` AS `weekDay`,`h`.`warehouse_id` AS `warehouse`,`h`.`province_id` AS `province`,`h`.`subtract_day` AS `substractDay`,`h`.`max_hour` AS `maxHour` from `vn2008`.`agency_hour` `h` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `agencyMode`
---
-
-/*!50001 DROP VIEW IF EXISTS `agencyMode`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `agencyMode` AS select `a`.`Id_Agencia` AS `id`,`a`.`Agencia` AS `name`,`a`.`description` AS `description`,`a`.`Vista` AS `view`,`a`.`Vista` AS `deliveryMethod`,`a`.`m3` AS `m3`,`a`.`cod71` AS `cod71`,`a`.`web` AS `web`,`a`.`agency_id` AS `agency`,`a`.`agency_id` AS `agencyFk`,`a`.`agency_service_id` AS `agencyService`,`a`.`agency_service_id` AS `agencyServiceFk`,`a`.`inflacion` AS `inflacion`,`a`.`is_volumetric` AS `isVolumetric`,`a`.`send_mail` AS `reportMail` from `vn2008`.`Agencias` `a` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `agencyWarehouse`
---
-
-/*!50001 DROP VIEW IF EXISTS `agencyWarehouse`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `agencyWarehouse` AS select `a`.`agency_id` AS `agencyFk`,`a`.`warehouse_id` AS `warehouseFk`,`a`.`Vista` AS `agencyType` from `vn2008`.`agency_warehouse` `a` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `awb`
---
-
-/*!50001 DROP VIEW IF EXISTS `awb`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `awb` AS select `a`.`id` AS `id`,`a`.`codigo` AS `code`,`a`.`bultos` AS `package`,`a`.`peso` AS `weight`,`a`.`MYSQL_TIME` AS `created`,`a`.`transitario_id` AS `transitoryFk`,`a`.`iva_id` AS `taxFk`,`a`.`gestdoc_id` AS `docFk`,`a`.`importe` AS `amount`,`a`.`carguera_id` AS `freightFk`,`a`.`m3` AS `m3`,`a`.`stems` AS `stems`,`a`.`flight_id` AS `flightFk`,`a`.`volume_weight` AS `volumeWeight`,`a`.`hb` AS `hb`,`a`.`rate` AS `rate`,`a`.`booked` AS `booked`,`a`.`issued` AS `issued`,`a`.`operated` AS `operated` from `vn2008`.`awb` `a` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `bank`
---
-
-/*!50001 DROP VIEW IF EXISTS `bank`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `bank` AS select `b`.`Id_Banco` AS `id`,`b`.`Banco` AS `bank`,`b`.`Cuenta` AS `account`,`b`.`cash` AS `cash`,`b`.`entity_id` AS `entityFk`,`b`.`activo` AS `isActive` from `vn2008`.`Bancos` `b` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `botanicExport`
---
-
-/*!50001 DROP VIEW IF EXISTS `botanicExport`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `botanicExport` AS select `be`.`botanic_export_id` AS `id`,`be`.`edi_genus_id` AS `ediGenusFk`,`be`.`edi_specie_id` AS `ediSpecieFk`,`be`.`Id_Paises` AS `countryFk`,`be`.`restriction` AS `restriction`,`be`.`description` AS `description` from `vn2008`.`botanic_export` `be` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `buy`
---
-
-/*!50001 DROP VIEW IF EXISTS `buy`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `buy` AS select `c`.`Id_Compra` AS `id`,`c`.`Id_Entrada` AS `entryFk`,`c`.`Id_Article` AS `itemFk`,`c`.`Cantidad` AS `amount`,`c`.`Costefijo` AS `buyingValue`,`c`.`Cantidad` AS `quantity`,`c`.`Id_Cubo` AS `packageFk`,`c`.`Etiquetas` AS `stickers`,`c`.`Portefijo` AS `freightValue`,`c`.`Embalajefijo` AS `packageValue`,`c`.`Comisionfija` AS `comissionValue`,`c`.`Packing` AS `packing`,`c`.`grouping` AS `grouping`,`c`.`caja` AS `groupingMode`,`c`.`Nicho` AS `location`,`c`.`Tarifa1` AS `price1`,`c`.`Tarifa2` AS `price2`,`c`.`Tarifa3` AS `price3`,`c`.`PVP` AS `minPrice`,`c`.`Productor` AS `producer`,`c`.`Vida` AS `printedStickers`,`c`.`punteo` AS `isChecked` from `vn2008`.`Compres` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `city`
---
-
-/*!50001 DROP VIEW IF EXISTS `city`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `city` AS select `c`.`city_id` AS `id`,`c`.`name` AS `name`,`c`.`province_id` AS `provinceFk` from `vn2008`.`city` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `client`
---
-
-/*!50001 DROP VIEW IF EXISTS `client`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `client` AS select `c`.`id_cliente` AS `id`,`c`.`cliente` AS `name`,`c`.`if` AS `fi`,`c`.`razonSocial` AS `socialName`,`c`.`contacto` AS `contact`,`c`.`domicilio` AS `street`,`c`.`poblacion` AS `city`,`c`.`codPostal` AS `postcode`,`c`.`telefono` AS `phone`,`c`.`movil` AS `mobile`,`c`.`fax` AS `fax`,`c`.`real` AS `isRelevant`,`c`.`e-mail` AS `email`,`c`.`iban` AS `iban`,`c`.`vencimiento` AS `dueDay`,`c`.`Cuenta` AS `accountingAccount`,`c`.`RE` AS `isEqualizated`,`c`.`province_id` AS `provinceFk`,`c`.`invoice` AS `hasToInvoice`,`c`.`credito` AS `credit`,`c`.`Id_Pais` AS `countryFk`,`c`.`activo` AS `isActive`,`c`.`gestdoc_id` AS `gestdocFk`,`c`.`calidad` AS `quality`,`c`.`pay_met_id` AS `payMethodFk`,`c`.`created` AS `created`,`c`.`mail` AS `isToBeMailed`,`c`.`chanel_id` AS `contactChannelFk`,`c`.`sepaVnl` AS `hasSepaVnl`,`c`.`coreVnl` AS `hasCoreVnl`,`c`.`coreVnh` AS `hasCoreVnh`,`c`.`risk_calculated` AS `riskCalculated`,`c`.`clientes_tipo_id` AS `clientTypeFk`,`c`.`mail_address` AS `mailAddress`,`c`.`cplusTerIdNifFk` AS `cplusTerIdNifFk`,`c`.`invoiceByAddress` AS `hasToInvoiceByAddress`,`c`.`contabilizado` AS `isTaxDataChecked`,`c`.`congelado` AS `isFreezed`,`c`.`creditInsurance` AS `creditInsurance`,`c`.`isCreatedAsServed` AS `isCreatedAsServed`,`c`.`hasInvoiceSimplified` AS `hasInvoiceSimplified`,`c`.`Id_Trabajador` AS `salesPersonFk`,`c`.`vies` AS `isVies`,`c`.`EYPBC` AS `eypbc` from `vn2008`.`Clientes` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `clientManaCache`
---
-
-/*!50001 DROP VIEW IF EXISTS `clientManaCache`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `clientManaCache` AS select `mc`.`Id_Cliente` AS `clientFk`,`mc`.`Mana` AS `mana`,`mc`.`dated` AS `dated` from `bs`.`manaCustomer` `mc` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `clientObservation`
---
-
-/*!50001 DROP VIEW IF EXISTS `clientObservation`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `clientObservation` AS select `vn2008`.`client_observation`.`client_observation_id` AS `id`,`vn2008`.`client_observation`.`Id_Cliente` AS `client`,`vn2008`.`client_observation`.`Id_Trabajador` AS `worker`,`vn2008`.`client_observation`.`text` AS `text`,`vn2008`.`client_observation`.`odbc_date` AS `creationDate` from `vn2008`.`client_observation` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `clientType`
---
-
-/*!50001 DROP VIEW IF EXISTS `clientType`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `clientType` AS select `ct`.`clientes_tipo_id` AS `id`,`ct`.`code` AS `code`,`ct`.`tipo` AS `type` from `vn2008`.`clientes_tipo` `ct` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `company`
---
-
-/*!50001 DROP VIEW IF EXISTS `company`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `company` AS select `e`.`id` AS `id`,`e`.`abbreviation` AS `code` from `vn2008`.`empresa` `e` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `country`
---
-
-/*!50001 DROP VIEW IF EXISTS `country`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `country` AS select `p`.`Id` AS `id`,`p`.`Pais` AS `country`,`p`.`CEE` AS `CEE`,if((`p`.`CEE` < 2),1,0) AS `isUeeMember`,`p`.`Codigo` AS `Code`,`p`.`Id_Moneda` AS `currencyFk`,`p`.`Id_Paisreal` AS `politicalCountryFk`,`p`.`geoFk` AS `geoFk` from `vn2008`.`Paises` `p` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `deliveryMethod`
---
-
-/*!50001 DROP VIEW IF EXISTS `deliveryMethod`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `deliveryMethod` AS select `d`.`vista_id` AS `id`,`d`.`code` AS `code`,`d`.`vista` AS `description` from `vn2008`.`Vistas` `d` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ediGenus`
---
-
-/*!50001 DROP VIEW IF EXISTS `ediGenus`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ediGenus` AS select `g`.`genus_id` AS `id`,`g`.`latin_genus_name` AS `latinGenusName`,`g`.`entry_date` AS `entried`,`g`.`expiry_date` AS `dued`,`g`.`change_date_time` AS `modified` from `edi`.`genus` `g` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ediSpecie`
---
-
-/*!50001 DROP VIEW IF EXISTS `ediSpecie`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ediSpecie` AS select `s`.`specie_id` AS `id`,`s`.`genus_id` AS `genusFk`,`s`.`latin_species_name` AS `latinSpeciesName`,`s`.`entry_date` AS `entried`,`s`.`expiry_date` AS `dued`,`s`.`change_date_time` AS `modified` from `edi`.`specie` `s` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `entry`
---
-
-/*!50001 DROP VIEW IF EXISTS `entry`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `entry` AS select `e`.`Id_Entrada` AS `id`,`e`.`Id_Proveedor` AS `supplierFk`,`e`.`Referencia` AS `ref`,`e`.`Inventario` AS `isInventory`,`e`.`Confirmada` AS `isConfirmed`,`e`.`Pedida` AS `isOrdered`,`e`.`Redada` AS `isRaid`,`e`.`comision` AS `commission`,`e`.`odbc_date` AS `created`,`e`.`Notas_Eva` AS `evaNotes`,`e`.`travel_id` AS `travelFk`,`e`.`Id_Moneda` AS `currencyFk`,`e`.`empresa_id` AS `companyFk`,`e`.`gestdoc_id` AS `gestDocFk`,`e`.`recibida_id` AS `invoiceReceivedFk` from `vn2008`.`Entradas` `e` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `especialPrice`
---
-
-/*!50001 DROP VIEW IF EXISTS `especialPrice`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `especialPrice` AS select `p`.`Id_PrecioEspecial` AS `id`,`p`.`Id_Cliente` AS `clientFk`,`p`.`Id_Article` AS `itemFk`,`p`.`PrecioEspecial` AS `value` from `vn2008`.`PreciosEspeciales` `p` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `expedition`
---
-
-/*!50001 DROP VIEW IF EXISTS `expedition`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `expedition` AS select `e`.`expeditions_id` AS `id`,`e`.`agency_id` AS `agency`,`e`.`agency_id` AS `agencyFk`,`e`.`ticket_id` AS `ticket`,`e`.`ticket_id` AS `ticketFk`,`e`.`EsBulto` AS `isBox`,`e`.`odbc_date` AS `printingTime`,`e`.`Id_Article` AS `item`,`e`.`Id_Article` AS `itemFk`,`e`.`counter` AS `counter`,`e`.`checked` AS `checked`,`e`.`workerFk` AS `workerFk` from `vn2008`.`expeditions` `e` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `expence`
---
-
-/*!50001 DROP VIEW IF EXISTS `expence`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `expence` AS select `g`.`Id_Gasto` AS `id`,`g`.`iva_tipo_id` AS `taxTypeFk`,`g`.`Gasto` AS `name`,`g`.`isWithheld` AS `isWithheld` from `vn2008`.`Gastos` `g` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `family`
---
-
-/*!50001 DROP VIEW IF EXISTS `family`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `family` AS select `t`.`tipo_id` AS `id`,`t`.`Tipo` AS `name`,`t`.`life` AS `life` from `vn2008`.`Tipos` `t` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `grant`
---
-
-/*!50001 DROP VIEW IF EXISTS `grant`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `grant` AS select `vn2008`.`Permisos`.`Id_Grupo` AS `group`,`vn2008`.`Permisos`.`Id_Trabajador` AS `worker`,`vn2008`.`Permisos`.`empresa_id` AS `company` from `vn2008`.`Permisos` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `grantGroup`
---
-
-/*!50001 DROP VIEW IF EXISTS `grantGroup`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `grantGroup` AS select `vn2008`.`Grupos`.`id` AS `id`,`vn2008`.`Grupos`.`Grupo` AS `description`,`vn2008`.`Grupos`.`observation_type_id` AS `observationType` from `vn2008`.`Grupos` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ink`
---
-
-/*!50001 DROP VIEW IF EXISTS `ink`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ink` AS select `c`.`Id_Tinta` AS `id`,`c`.`name` AS `name`,`c`.`Tinta` AS `picture` from `vn2008`.`Tintas` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `intrastat`
---
-
-/*!50001 DROP VIEW IF EXISTS `intrastat`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `intrastat` AS select `i`.`Codintrastat` AS `id`,`i`.`Definicion` AS `description`,`i`.`iva_group_id` AS `taxGroupFk`,`i`.`iva_codigo_id` AS `taxCodeFk` from `vn2008`.`Intrastat` `i` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `invoiceCorrection`
---
-
-/*!50001 DROP VIEW IF EXISTS `invoiceCorrection`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `invoiceCorrection` AS select `ic`.`correctingFk` AS `correctingFk`,`ic`.`correctedFk` AS `correctedFk`,`ic`.`cplusRectificationTypeFk` AS `cplusRectificationTypeFk`,`ic`.`cplusInvoiceType477Fk` AS `cplusInvoiceType477Fk`,`ic`.`invoiceCorrectionTypeFk` AS `invoiceCorrectionTypeFk` from `vn2008`.`invoiceCorrection` `ic` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `invoiceCorrectionDataSource`
---
-
-/*!50001 DROP VIEW IF EXISTS `invoiceCorrectionDataSource`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `invoiceCorrectionDataSource` AS select `s`.`itemFk` AS `itemFk`,`s`.`quantity` AS `quantity`,`s`.`concept` AS `concept`,`s`.`price` AS `price`,`s`.`discount` AS `discount`,`t`.`refFk` AS `refFk`,`s`.`id` AS `saleFk` from (`vn`.`sale` `s` join `vn`.`ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `invoiceIn`
---
-
-/*!50001 DROP VIEW IF EXISTS `invoiceIn`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `invoiceIn` AS select `r`.`id` AS `id`,`r`.`num_recibida` AS `serialNumber`,`r`.`serie` AS `serial`,`r`.`proveedor_id` AS `supplierFk`,`r`.`fecha` AS `issued`,`r`.`sref` AS `supplierRef`,`r`.`contabilizada` AS `isBooked`,`r`.`moneda_id` AS `currencyFk`,`r`.`MYSQL_TIME` AS `created`,`r`.`empresa_id` AS `companyFk`,`r`.`gestdoc_id` AS `docFk`,`r`.`dateBooking` AS `booked`,`r`.`dateOperation` AS `operated`,`r`.`cplusInvoiceType472Fk` AS `cplusInvoiceType472Fk`,`r`.`cplusRectificationTypeFk` AS `cplusRectificationTypeFk`,`r`.`cplusSubjectOpFk` AS `cplusSubjectOpFk`,`r`.`cplusTaxBreakFk` AS `cplusTaxBreakFk`,`r`.`cplusTrascendency472Fk` AS `cplusTrascendency472Fk` from `vn2008`.`recibida` `r` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `invoiceInAwb`
---
-
-/*!50001 DROP VIEW IF EXISTS `invoiceInAwb`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `invoiceInAwb` AS select `a`.`recibida_id` AS `invoiceInFk`,`a`.`awb_id` AS `awbFk`,`a`.`dua` AS `dua` from `vn2008`.`awb_recibida` `a` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `invoiceInEntry`
---
-
-/*!50001 DROP VIEW IF EXISTS `invoiceInEntry`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `invoiceInEntry` AS select `i`.`recibida_entrada_id` AS `id`,`i`.`recibida_id` AS `invoiceInFk`,`i`.`Id_Entrada` AS `entryFk`,`i`.`percentage` AS `percentage`,`i`.`awb_recibida` AS `invoiceInAwbFk`,`i`.`Contabilizado` AS `isBooked` from `vn2008`.`recibida_entrada` `i` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `invoiceInIntrastat`
---
-
-/*!50001 DROP VIEW IF EXISTS `invoiceInIntrastat`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `invoiceInIntrastat` AS select `r`.`recibida_id` AS `invoiceInFk`,`r`.`Codintrastat` AS `intrastatFk`,`r`.`importe` AS `amount` from `vn2008`.`recibida_intrastat` `r` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `invoiceInTax`
---
-
-/*!50001 DROP VIEW IF EXISTS `invoiceInTax`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `invoiceInTax` AS select `r`.`id` AS `id`,`r`.`recibida_id` AS `invoiceInFk`,`r`.`iva_id` AS `taxCodeFk`,`r`.`bi` AS `taxableBase`,`r`.`gastos_id` AS `expenceFk`,`r`.`divisa` AS `foreignValue`,`r`.`MYSQL_TIME` AS `created` from `vn2008`.`recibida_iva` `r` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `invoiceOut`
---
-
-/*!50001 DROP VIEW IF EXISTS `invoiceOut`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `invoiceOut` AS select `f`.`factura_id` AS `id`,`f`.`Id_Factura` AS `ref`,`f`.`Serie` AS `serial`,`f`.`Fecha` AS `issued`,`f`.`Importe` AS `amount`,`f`.`Id_Cliente` AS `clientFk`,`f`.`odbc_date` AS `created`,`f`.`empresa_id` AS `companyFk`,`f`.`Vencimiento` AS `dued`,`f`.`booked` AS `booked`,`f`.`cplusInvoiceType477Fk` AS `cplusInvoiceType477Fk`,`f`.`cplusTaxBreakFk` AS `cplusTaxBreakFk`,`f`.`cplusSubjectOpFk` AS `cplusSubjectOpFk`,`f`.`cplusTrascendency477Fk` AS `cplusTrascendency477Fk`,`f`.`pdf` AS `pdf` from `vn2008`.`Facturas` `f` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `item`
---
-
-/*!50001 DROP VIEW IF EXISTS `item`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `item` AS select `t`.`Id_Article` AS `id`,`t`.`Article` AS `name`,`t`.`tipo_id` AS `familyFk`,`t`.`Medida` AS `size`,`t`.`Color` AS `inkFk`,`t`.`Categoria` AS `category`,`t`.`Tallos` AS `stems`,`t`.`id_origen` AS `originFk`,`t`.`description` AS `description`,`t`.`producer_id` AS `producerFk`,`t`.`Codintrastat` AS `intrastatFk`,`t`.`expenceFk` AS `expenceFk` from `vn2008`.`Articles` `t` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `itemBotanical`
---
-
-/*!50001 DROP VIEW IF EXISTS `itemBotanical`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `itemBotanical` AS select `ab`.`Id_Article` AS `itemFk`,`ab`.`botanical` AS `botanical`,`ab`.`genus_id` AS `genusFk`,`ab`.`specie_id` AS `specieFk` from `vn2008`.`Articles_botanical` `ab` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `itemBotanicalWithGenus`
---
-
-/*!50001 DROP VIEW IF EXISTS `itemBotanicalWithGenus`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `itemBotanicalWithGenus` AS select `ib`.`itemFk` AS `itemFk`,ifnull(`ib`.`botanical`,concat(`g`.`latinGenusName`,' ',ifnull(`s`.`latinSpeciesName`,''))) AS `ediBotanic` from ((`vn`.`itemBotanical` `ib` left join `vn`.`ediGenus` `g` on((`g`.`id` = `ib`.`genusFk`))) left join `vn`.`ediSpecie` `s` on((`s`.`id` = `ib`.`specieFk`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `itemTag`
---
-
-/*!50001 DROP VIEW IF EXISTS `itemTag`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `itemTag` AS select `t`.`id` AS `id`,`t`.`itemFk` AS `itemFk`,`t`.`tagFk` AS `tagFk`,`t`.`value` AS `value`,`t`.`priority` AS `priority` from `vn2008`.`itemTag` `t` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `itemTagged`
---
-
-/*!50001 DROP VIEW IF EXISTS `itemTagged`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `itemTagged` AS select distinct `itemTag`.`itemFk` AS `itemFk` from `vn`.`itemTag` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `mail`
---
-
-/*!50001 DROP VIEW IF EXISTS `mail`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `mail` AS select `vn2008`.`mail`.`id` AS `id`,`vn2008`.`mail`.`senderFk` AS `senderFk`,`vn2008`.`mail`.`recipientFk` AS `recipientFk`,`vn2008`.`mail`.`to` AS `sender`,`vn2008`.`mail`.`reply_to` AS `replyTo`,`vn2008`.`mail`.`subject` AS `subject`,`vn2008`.`mail`.`text` AS `body`,`vn2008`.`mail`.`plainTextBody` AS `plainTextBody`,`vn2008`.`mail`.`path` AS `attachment`,`vn2008`.`mail`.`DATE_ODBC` AS `creationDate`,`vn2008`.`mail`.`sent` AS `sent`,`vn2008`.`mail`.`error` AS `status` from `vn2008`.`mail` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `manaSpellers`
---
-
-/*!50001 DROP VIEW IF EXISTS `manaSpellers`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `manaSpellers` AS select `bs`.`mana_spellers`.`Id_Trabajador` AS `worker`,`bs`.`mana_spellers`.`size` AS `size`,`bs`.`mana_spellers`.`used` AS `used`,`bs`.`mana_spellers`.`prices_modifier_rate` AS `pricesModifierRate`,`bs`.`mana_spellers`.`prices_modifier_activated` AS `pricesModifierActivated`,`vn2008`.`Trabajadores`.`CodigoTrabajador` AS `workerCode`,`vn2008`.`Trabajadores`.`Nombre` AS `firstname`,`vn2008`.`Trabajadores`.`Apellidos` AS `name` from (`bs`.`mana_spellers` join `vn2008`.`Trabajadores` on((`bs`.`mana_spellers`.`Id_Trabajador` = `vn2008`.`Trabajadores`.`Id_Trabajador`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `movement`
---
-
-/*!50001 DROP VIEW IF EXISTS `movement`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `movement` AS select `m`.`Id_Movimiento` AS `id`,`m`.`Id_Article` AS `item`,`m`.`Id_Ticket` AS `ticket`,`m`.`Concepte` AS `concept`,`m`.`Cantidad` AS `amount`,`m`.`quantity` AS `quantity`,`m`.`Preu` AS `price`,`m`.`Descuento` AS `discount`,`m`.`CostFixat` AS `cost`,`m`.`Reservado` AS `reservado`,`m`.`OK` AS `od`,`m`.`PrecioFijado` AS `priceFixed`,`m`.`odbc_date` AS `lastUpdate` from `vn2008`.`Movimientos` `m` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `observationType`
---
-
-/*!50001 DROP VIEW IF EXISTS `observationType`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `observationType` AS select `ot`.`observation_type_id` AS `id`,`ot`.`description` AS `description` from `vn2008`.`observation_type` `ot` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `origin`
---
-
-/*!50001 DROP VIEW IF EXISTS `origin`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `origin` AS select `o`.`id` AS `id`,`o`.`Abreviatura` AS `code`,`o`.`Origen` AS `name` from `vn2008`.`Origen` `o` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `outgoingInvoice`
---
-
-/*!50001 DROP VIEW IF EXISTS `outgoingInvoice`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `outgoingInvoice` AS select `vn2008`.`Facturas`.`Id_Factura` AS `id`,`vn2008`.`Facturas`.`Serie` AS `serie`,`vn2008`.`Facturas`.`Fecha` AS `dateInvoice`,`vn2008`.`Facturas`.`Importe` AS `total`,`vn2008`.`Facturas`.`Vencimiento` AS `dueDate`,`vn2008`.`Facturas`.`Id_Banco` AS `bank`,`vn2008`.`Facturas`.`Id_Cliente` AS `client`,`vn2008`.`Facturas`.`Id_Remesa` AS `remittance`,`vn2008`.`Facturas`.`Remesar` AS `remit`,`vn2008`.`Facturas`.`Id_Trabajador` AS `worker`,`vn2008`.`Facturas`.`odbc_date` AS `creationDate`,`vn2008`.`Facturas`.`empresa_id` AS `company`,`vn2008`.`Facturas`.`liquidacion` AS `liquidacion?`,`vn2008`.`Facturas`.`pdf` AS `isPdf` from `vn2008`.`Facturas` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `package`
---
-
-/*!50001 DROP VIEW IF EXISTS `package`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `package` AS select `c`.`Id_Cubo` AS `id`,`c`.`Volumen` AS `volume`,`c`.`X` AS `width`,`c`.`Y` AS `height`,`c`.`Z` AS `depth`,`c`.`Retornable` AS `isPackageReturnable`,`c`.`odbc_date` AS `created`,`c`.`item_id` AS `itemFk` from `vn2008`.`Cubos` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `payMethod`
---
-
-/*!50001 DROP VIEW IF EXISTS `payMethod`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `payMethod` AS select `pm`.`id` AS `id`,`pm`.`name` AS `name` from `vn2008`.`pay_met` `pm` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `plantpassport`
---
-
-/*!50001 DROP VIEW IF EXISTS `plantpassport`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `plantpassport` AS select `pp`.`producer_id` AS `producerFk`,`pp`.`plantpassport_authority_id` AS `plantpassportAuthorityFk`,`pp`.`number` AS `number` from `vn2008`.`plantpassport` `pp` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `plantpassportAuthority`
---
-
-/*!50001 DROP VIEW IF EXISTS `plantpassportAuthority`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `plantpassportAuthority` AS select `ppa`.`plantpassport_authority_id` AS `id`,`ppa`.`denomination` AS `denomination`,`ppa`.`Paises_Id` AS `countryFk` from `vn2008`.`plantpassport_authority` `ppa` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `priceFixed`
---
-
-/*!50001 DROP VIEW IF EXISTS `priceFixed`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `priceFixed` AS select `p`.`item_id` AS `itemFk`,`p`.`rate_0` AS `rate0`,`p`.`rate_1` AS `rate1`,`p`.`rate_2` AS `rate2`,`p`.`rate_3` AS `rate3`,`p`.`date_start` AS `started`,`p`.`date_end` AS `ended`,`p`.`bonus` AS `bonus`,`p`.`warehouse_id` AS `warehouseFk`,`p`.`odbc_date` AS `created`,`p`.`price_fixed_id` AS `id`,`p`.`grouping` AS `grouping`,`p`.`Packing` AS `packing`,`p`.`caja` AS `box` from `vn2008`.`price_fixed` `p` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `printServerQueue`
---
-
-/*!50001 DROP VIEW IF EXISTS `printServerQueue`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `printServerQueue` AS select `c`.`Id_Cola` AS `id`,`c`.`Id_Impresora` AS `printerFk`,`c`.`Id_Prioridad` AS `priorityFk`,`c`.`Id_Informe` AS `reportFk`,`c`.`Id_Estado` AS `statusFk`,`c`.`Hora_Inicio` AS `started`,`c`.`Hora_Fin` AS `finished`,`c`.`Cola` AS `param1`,`c`.`Id_Trabajador` AS `workerFk`,`c`.`Cola2` AS `param2`,`c`.`Cola3` AS `param3`,`c`.`error` AS `error` from `vn2008`.`Colas` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `printingQueue`
---
-
-/*!50001 DROP VIEW IF EXISTS `printingQueue`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `printingQueue` AS select `c`.`Id_Cola` AS `id`,`c`.`Id_Impresora` AS `printer`,`c`.`Id_Prioridad` AS `priority`,`c`.`Id_Informe` AS `report`,`c`.`Id_Estado` AS `state`,`c`.`Hora_Inicio` AS `startingTime`,`c`.`Hora_Fin` AS `endingTime`,`c`.`Cola` AS `text`,`c`.`Id_Trabajador` AS `worker`,`c`.`Cola2` AS `text2`,`c`.`Cola3` AS `text3` from `vn2008`.`Colas` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `producer`
---
-
-/*!50001 DROP VIEW IF EXISTS `producer`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `producer` AS select `p`.`producer_id` AS `id`,`p`.`name` AS `name` from `vn2008`.`producer` `p` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `province`
---
-
-/*!50001 DROP VIEW IF EXISTS `province`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `province` AS select `t`.`province_id` AS `id`,`t`.`name` AS `name`,`t`.`Paises_Id` AS `countryFk` from `vn2008`.`province` `t` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `referenceRate`
---
-
-/*!50001 DROP VIEW IF EXISTS `referenceRate`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `referenceRate` AS select `r`.`moneda_id` AS `currencyFk`,`r`.`date` AS `dated`,`r`.`rate` AS `value` from `vn2008`.`reference_rate` `r` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `role`
---
-
-/*!50001 DROP VIEW IF EXISTS `role`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `role` AS select `account`.`role`.`id` AS `id`,`account`.`role`.`name` AS `name`,`account`.`role`.`description` AS `description`,`account`.`role`.`hasLogin` AS `hasLogin` from `account`.`role` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `route`
---
-
-/*!50001 DROP VIEW IF EXISTS `route`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `route` AS select `a`.`Id_Ruta` AS `id`,`a`.`Id_Trabajador` AS `workerFk`,`a`.`Fecha` AS `created`,`a`.`Id_Vehiculo` AS `vehicleFk`,`a`.`Id_Agencia` AS `agencyFk`,`a`.`Id_Agencia` AS `agencyModeFk`,`a`.`Hora` AS `time`,`a`.`ok` AS `isOk`,`a`.`km_start` AS `kmStart`,`a`.`km_end` AS `kmEnd`,`a`.`date_start` AS `started`,`a`.`date_end` AS `finished`,`a`.`gestdoc_id` AS `gestdocFk`,`a`.`cost` AS `cost`,`a`.`m3` AS `m3` from `vn2008`.`Rutas` `a` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `sale`
---
-
-/*!50001 DROP VIEW IF EXISTS `sale`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `sale` AS select `m`.`Id_Movimiento` AS `id`,`m`.`Id_Article` AS `itemFk`,`m`.`Id_Ticket` AS `ticketFk`,`m`.`Concepte` AS `concept`,`m`.`Cantidad` AS `quantity`,`m`.`Preu` AS `price`,`m`.`Descuento` AS `discount`,`m`.`Reservado` AS `reserved`,`m`.`OK` AS `isPicked`,`m`.`odbc_date` AS `created` from `vn2008`.`Movimientos` `m` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `saleComponent`
---
-
-/*!50001 DROP VIEW IF EXISTS `saleComponent`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `saleComponent` AS select `mc`.`Id_Movimiento` AS `saleFk`,`mc`.`Id_Componente` AS `componentFk`,`mc`.`Valor` AS `value` from `vn2008`.`Movimientos_componentes` `mc` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `state`
---
-
-/*!50001 DROP VIEW IF EXISTS `state`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `state` AS select `s`.`id` AS `id`,`s`.`name` AS `name`,`s`.`order` AS `order`,`s`.`alert_level` AS `alertLevel`,`s`.`code` AS `code` from `vn2008`.`state` `s` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `supplier`
---
-
-/*!50001 DROP VIEW IF EXISTS `supplier`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `supplier` AS select `p`.`Id_Proveedor` AS `id`,`p`.`Proveedor` AS `name`,`p`.`cuenta` AS `account`,`p`.`pais_id` AS `countryFk`,`p`.`NIF` AS `nif`,`p`.`Agricola` AS `isFarmer`,`p`.`cuentaret` AS `retAccount`,`p`.`ComisionProveedor` AS `commission`,`p`.`odbc_time` AS `created`,`p`.`postcode_id` AS `postcodeFk`,`p`.`active` AS `isActive` from `vn2008`.`Proveedores` `p` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `tag`
---
-
-/*!50001 DROP VIEW IF EXISTS `tag`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `tag` AS select `t`.`id` AS `id`,`t`.`name` AS `name`,`t`.`free` AS `free` from `vn2008`.`tag` `t` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `taxClass`
---
-
-/*!50001 DROP VIEW IF EXISTS `taxClass`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `taxClass` AS select `c`.`iva_group_id` AS `id`,`c`.`description` AS `description`,`c`.`code` AS `code` from `vn2008`.`iva_group` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `taxClassCode`
---
-
-/*!50001 DROP VIEW IF EXISTS `taxClassCode`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `taxClassCode` AS select `c`.`iva_group_id` AS `taxClassFk`,`c`.`date` AS `effectived`,`c`.`iva_codigo_id` AS `taxCodeFk` from `vn2008`.`iva_group_codigo` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `taxCode`
---
-
-/*!50001 DROP VIEW IF EXISTS `taxCode`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `taxCode` AS select `ic`.`id` AS `id`,`ic`.`fecha` AS `dated`,`ic`.`codigo` AS `code`,`ic`.`iva_tipo_id` AS `taxTypeFk`,`ic`.`iva` AS `rate`,`ic`.`recargo` AS `equalizationTax`,`ic`.`tipo` AS `type`,`ic`.`link` AS `linkFk`,`ic`.`isActive` AS `isActive` from `vn2008`.`iva_codigo` `ic` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `taxType`
---
-
-/*!50001 DROP VIEW IF EXISTS `taxType`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `taxType` AS select `t`.`id` AS `id`,`t`.`alias` AS `nickname`,`t`.`serie_id` AS `serial`,`t`.`TIPOOPE` AS `TIPOOPE`,`t`.`descripcion` AS `description`,`t`.`Id_Pais` AS `countryFk` from `vn2008`.`iva_tipo` `t` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ticket`
---
-
-/*!50001 DROP VIEW IF EXISTS `ticket`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ticket` AS select `t`.`Id_Ticket` AS `id`,`t`.`Id_Cliente` AS `clientFk`,`t`.`warehouse_id` AS `warehouseFk`,`t`.`Fecha` AS `shipped`,`t`.`landing` AS `landed`,`t`.`Alias` AS `nickname`,`t`.`Factura` AS `refFk`,`t`.`Id_Consigna` AS `addressFk`,`t`.`Firmado` AS `isSigned`,`t`.`Localizacion` AS `location`,`t`.`blocked` AS `blocked`,`t`.`Solucion` AS `solution`,`t`.`Id_Ruta` AS `path`,`t`.`Id_Ruta` AS `routeFk`,`t`.`empresa_id` AS `company`,`t`.`empresa_id` AS `companyFk`,`t`.`Id_Agencia` AS `agencyModeFk`,`t`.`Prioridad` AS `loadingOrder`,`t`.`odbc_date` AS `created`,`t`.`Fecha` AS `shipment`,`t`.`landing` AS `landing`,`t`.`Id_Cliente` AS `customer`,`t`.`warehouse_id` AS `warehouse`,`t`.`Id_Cliente` AS `client`,`t`.`Id_Consigna` AS `address`,`t`.`Id_Agencia` AS `agencyMode`,`t`.`Firmado` AS `signed`,`t`.`odbc_date` AS `creationDate` from `vn2008`.`Tickets` `t` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ticketObservation`
---
-
-/*!50001 DROP VIEW IF EXISTS `ticketObservation`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ticketObservation` AS select `to`.`ticket_observation_id` AS `id`,`to`.`Id_Ticket` AS `ticketFk`,`to`.`observation_type_id` AS `observationTypeFk`,`to`.`text` AS `description` from `vn2008`.`ticket_observation` `to` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ticketState`
---
-
-/*!50001 DROP VIEW IF EXISTS `ticketState`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ticketState` AS select `ts`.`Id_Ticket` AS `ticketFk`,`ts`.`Id_Ticket` AS `ticket`,`s`.`id` AS `state`,`s`.`order` AS `productionOrder`,`s`.`alert_level` AS `alertLevel`,`s`.`code` AS `code`,`i`.`Id_Trabajador` AS `worker`,`i`.`Id_Trabajador` AS `workerFk` from ((`vn2008`.`Tickets_state` `ts` join `vncontrol`.`inter` `i` on((`i`.`inter_id` = `ts`.`inter_id`))) join `vn2008`.`state` `s` on((`s`.`id` = `i`.`state_id`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ticketStateToday`
---
-
-/*!50001 DROP VIEW IF EXISTS `ticketStateToday`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ticketStateToday` AS select `ts`.`ticket` AS `ticket`,`ts`.`state` AS `state`,`ts`.`productionOrder` AS `productionOrder`,`ts`.`alertLevel` AS `alertLevel`,`ts`.`worker` AS `worker`,`ts`.`code` AS `code` from (`vn`.`ticketState` `ts` join `vn`.`ticket` `t` on((`t`.`id` = `ts`.`ticket`))) where (`t`.`shipment` between curdate() and `midnight`(curdate())) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ticketTracking`
---
-
-/*!50001 DROP VIEW IF EXISTS `ticketTracking`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ticketTracking` AS select `i`.`inter_id` AS `id`,`i`.`state_id` AS `stateFk`,`i`.`odbc_date` AS `created`,`i`.`Id_Ticket` AS `ticketFk`,`i`.`Id_Trabajador` AS `workerFk` from `vncontrol`.`inter` `i` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `time`
---
-
-/*!50001 DROP VIEW IF EXISTS `time`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `time` AS select `t`.`date` AS `dated`,`t`.`period` AS `period`,`t`.`month` AS `month`,`t`.`year` AS `year`,`t`.`day` AS `day`,`t`.`week` AS `week` from `vn2008`.`time` `t` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `travel`
---
-
-/*!50001 DROP VIEW IF EXISTS `travel`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `travel` AS select `t`.`id` AS `id`,`t`.`shipment` AS `shipped`,`t`.`shipment_hour` AS `shipmentHour`,`t`.`landing` AS `landed`,`t`.`landing_hour` AS `landingHour`,`t`.`warehouse_id` AS `warehouseInFk`,`t`.`warehouse_id_out` AS `warehouseOutFk`,`t`.`agency_id` AS `agencyFk`,`t`.`ref` AS `ref`,`t`.`delivered` AS `isDelivered`,`t`.`received` AS `isReceived`,`t`.`m3` AS `m3` from `vn2008`.`travel` `t` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `unary`
---
-
-/*!50001 DROP VIEW IF EXISTS `unary`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `unary` AS select `a`.`id` AS `id`,`a`.`parent` AS `parent` from `vn2008`.`unary` `a` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `unaryScan`
---
-
-/*!50001 DROP VIEW IF EXISTS `unaryScan`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `unaryScan` AS select `u`.`unary_id` AS `unaryFk`,`u`.`name` AS `name`,`u`.`odbc_date` AS `created`,`u`.`type` AS `type` from `vn2008`.`unary_scan` `u` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `unaryScanLine`
---
-
-/*!50001 DROP VIEW IF EXISTS `unaryScanLine`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `unaryScanLine` AS select `u`.`id` AS `id`,`u`.`code` AS `code`,`u`.`odbc_date` AS `created`,`u`.`unary_id` AS `unaryScanFk` from `vn2008`.`unary_scan_line` `u` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `unaryScanLineBuy`
---
-
-/*!50001 DROP VIEW IF EXISTS `unaryScanLineBuy`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `unaryScanLineBuy` AS select `u`.`scan_line_id` AS `unaryScanLineFk`,`u`.`Id_Article` AS `itemFk` from `vn2008`.`unary_scan_line_buy` `u` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `unaryScanLineExpedition`
---
-
-/*!50001 DROP VIEW IF EXISTS `unaryScanLineExpedition`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `unaryScanLineExpedition` AS select `u`.`scan_line_id` AS `unaryScanLineFk`,`u`.`expedition_id` AS `expeditionFk` from `vn2008`.`unary_scan_line_expedition` `u` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `user`
---
-
-/*!50001 DROP VIEW IF EXISTS `user`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `user` AS select `account`.`user`.`id` AS `id`,`account`.`user`.`name` AS `name`,`account`.`user`.`password` AS `password`,`account`.`user`.`role` AS `role`,`account`.`user`.`active` AS `active`,`account`.`user`.`recoverPass` AS `recoverPass`,`account`.`user`.`lastPassChange` AS `lastPassChange` from `account`.`user` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `vehicle`
---
-
-/*!50001 DROP VIEW IF EXISTS `vehicle`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `vehicle` AS select `v`.`Id_Vehiculo` AS `id`,`v`.`Matricula` AS `numberPlate`,`v`.`Marca` AS `tradeMark`,`v`.`Modelo` AS `model`,`v`.`empresa_id` AS `companyFk`,`v`.`warehouseFk` AS `warehouseFk`,`v`.`description` AS `description`,`v`.`m3` AS `m3`,`v`.`active` AS `isActive` from `vn2008`.`Vehiculos` `v` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `warehouse`
---
-
-/*!50001 DROP VIEW IF EXISTS `warehouse`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `warehouse` AS select `t`.`id` AS `id`,`t`.`name` AS `name`,`t`.`inventario` AS `isInventory`,`t`.`comisionantes` AS `hasComission` from `vn2008`.`warehouse` `t` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `warehouseAlias`
---
-
-/*!50001 DROP VIEW IF EXISTS `warehouseAlias`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `warehouseAlias` AS select `wa`.`warehouse_alias_id` AS `id`,`wa`.`alias` AS `name` from `vn2008`.`warehouse_alias` `wa` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `worker`
---
-
-/*!50001 DROP VIEW IF EXISTS `worker`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `worker` AS select `t`.`Id_Trabajador` AS `id`,`t`.`CodigoTrabajador` AS `workerCode`,`t`.`Nombre` AS `firstName`,`t`.`Apellidos` AS `name`,`t`.`user_id` AS `userFk`,`t`.`boss` AS `bossFk` from `vn2008`.`Trabajadores` `t` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `workerTeam`
---
-
-/*!50001 DROP VIEW IF EXISTS `workerTeam`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `workerTeam` AS select `w`.`team` AS `team`,`w`.`user` AS `user`,`w`.`id` AS `id`,`t`.`Id_Trabajador` AS `Id_Trabajador` from (`vn2008`.`workerTeam` `w` left join `vn2008`.`Trabajadores` `t` on((`t`.`user_id` = `w`.`user`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Current Database: `salix`
---
-
-USE `salix`;
-
---
--- Final view structure for view `Account`
---
-
-/*!50001 DROP VIEW IF EXISTS `Account`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Account` AS select `u`.`id` AS `id`,`u`.`name` AS `name`,`u`.`password` AS `password`,`u`.`role` AS `roleFk`,`u`.`active` AS `active`,`u`.`email` AS `email`,`u`.`created` AS `created`,`u`.`updated` AS `updated` from `account`.`user` `u` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Accounting`
---
-
-/*!50001 DROP VIEW IF EXISTS `Accounting`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Accounting` AS select `b`.`Id_Banco` AS `id`,`b`.`Banco` AS `bank`,`b`.`Cuenta` AS `account`,`b`.`cash` AS `accountingTypeFk`,`b`.`entity_id` AS `entityFk`,`b`.`activo` AS `isActive` from `vn2008`.`Bancos` `b` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Address`
---
-
-/*!50001 DROP VIEW IF EXISTS `Address`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Address` AS select `a`.`id_consigna` AS `id`,`a`.`consignatario` AS `consignee`,`a`.`domicilio` AS `street`,`a`.`poblacion` AS `city`,`a`.`codPostal` AS `postcode`,`a`.`province_id` AS `provinceFk`,`a`.`telefono` AS `phone`,`a`.`movil` AS `mobile`,`a`.`active` AS `isEnabled`,`a`.`predeterminada` AS `isDefaultAddress`,`a`.`Id_cliente` AS `clientFk`,`a`.`Id_Agencia` AS `defaultAgencyFk`,`a`.`longitude` AS `longitude`,`a`.`latitude` AS `latitude`,`a`.`isEqualizated` AS `isEqualizated` from `vn2008`.`Consignatarios` `a` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Agency`
---
-
-/*!50001 DROP VIEW IF EXISTS `Agency`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Agency` AS select `a`.`agency_id` AS `id`,`a`.`name` AS `name`,`a`.`warehouse_id` AS `warehouseFk`,`a`.`por_volumen` AS `isVolumetric`,`a`.`Id_Banco` AS `bankFk`,`a`.`warehouse_alias_id` AS `warehouseAliasFk` from `vn2008`.`agency` `a` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `AgencyMode`
---
-
-/*!50001 DROP VIEW IF EXISTS `AgencyMode`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `AgencyMode` AS select `a`.`Id_Agencia` AS `id`,`a`.`Agencia` AS `name`,`a`.`description` AS `description`,`a`.`Vista` AS `agencyTypeFk`,`a`.`m3` AS `m3`,`a`.`agency_id` AS `agencyFk`,`a`.`inflacion` AS `inflation`,`a`.`send_mail` AS `sendMailTo`,`a`.`tpv` AS `isForTicket` from `vn2008`.`Agencias` `a` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Bank`
---
-
-/*!50001 DROP VIEW IF EXISTS `Bank`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Bank` AS select `b`.`Id_Banco` AS `id`,`b`.`Banco` AS `bank`,`b`.`Cuenta` AS `account`,`b`.`cash` AS `cash`,`b`.`entity_id` AS `entityFk`,`b`.`activo` AS `isActive` from `vn2008`.`Bancos` `b` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `City`
---
-
-/*!50001 DROP VIEW IF EXISTS `City`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `City` AS select `c`.`city_id` AS `id`,`c`.`name` AS `name`,`c`.`province_id` AS `provinceFk` from `vn2008`.`city` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Client`
---
-
-/*!50001 DROP VIEW IF EXISTS `Client`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Client` AS select `c`.`id_cliente` AS `id`,`c`.`cliente` AS `name`,`c`.`if` AS `fi`,`c`.`razonSocial` AS `socialName`,`c`.`contacto` AS `contact`,`c`.`domicilio` AS `street`,`c`.`poblacion` AS `city`,`c`.`codPostal` AS `postcode`,`c`.`province_id` AS `provinceFk`,`c`.`Id_Pais` AS `countryFk`,`c`.`e-mail` AS `email`,`c`.`telefono` AS `phone`,`c`.`movil` AS `mobile`,`c`.`fax` AS `fax`,`c`.`activo` AS `active`,`c`.`descuento` AS `discount`,`c`.`credito` AS `credit`,`c`.`creditInsurance` AS `creditInsurance`,`c`.`cc` AS `iban`,`c`.`vencimiento` AS `dueDay`,`c`.`RE` AS `equalizationTax`,`c`.`invoice` AS `hasToInvoice`,`c`.`mail` AS `isToBeMailed`,`c`.`pay_met_id` AS `payMethodFk`,`c`.`Id_Trabajador` AS `salesPersonFk`,`c`.`chanel_id` AS `contactChannelFk`,`c`.`sepaVnl` AS `sepaVnl`,`c`.`coreVnl` AS `coreVnl`,`c`.`coreVnh` AS `coreVnh`,`c`.`EYPBC` AS `eypbc`,`c`.`calidad` AS `quality`,`c`.`vies` AS `vies`,`c`.`real` AS `isRelevant`,`c`.`clientes_tipo_id` AS `typeFk`,`c`.`Cuenta` AS `accountingAccount`,`c`.`created` AS `created` from `vn2008`.`Clientes` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ClientCredit`
---
-
-/*!50001 DROP VIEW IF EXISTS `ClientCredit`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ClientCredit` AS select `c`.`id` AS `id`,`c`.`Id_Cliente` AS `clientFk`,`c`.`Id_Trabajador` AS `employeeFk`,`c`.`amount` AS `amount`,`c`.`odbc_date` AS `created` from `vn2008`.`credit` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ClientCreditLimit`
---
-
-/*!50001 DROP VIEW IF EXISTS `ClientCreditLimit`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ClientCreditLimit` AS select `l`.`id` AS `id`,`l`.`maxAmount` AS `maxAmount`,`l`.`roleFk` AS `roleFk` from `vn`.`clientCreditLimit` `l` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ClientObservation`
---
-
-/*!50001 DROP VIEW IF EXISTS `ClientObservation`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ClientObservation` AS select `o`.`client_observation_id` AS `id`,`o`.`Id_Cliente` AS `clientFk`,`o`.`Id_Trabajador` AS `employeeFk`,`o`.`text` AS `text`,`o`.`odbc_date` AS `created` from `vn2008`.`client_observation` `o` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ClientType`
---
-
-/*!50001 DROP VIEW IF EXISTS `ClientType`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ClientType` AS select `ct`.`clientes_tipo_id` AS `id`,`ct`.`code` AS `code`,`ct`.`tipo` AS `type` from `vn2008`.`clientes_tipo` `ct` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ContactChannel`
---
-
-/*!50001 DROP VIEW IF EXISTS `ContactChannel`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ContactChannel` AS select `c`.`chanel_id` AS `id`,`c`.`name` AS `name` from `vn2008`.`chanel` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Country`
---
-
-/*!50001 DROP VIEW IF EXISTS `Country`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Country` AS select `c`.`Id` AS `id`,`c`.`Pais` AS `name`,`c`.`CEE` AS `inCee`,`c`.`Codigo` AS `code`,`c`.`Id_Moneda` AS `currencyFk`,`c`.`Id_Paisreal` AS `realCountryFk` from `vn2008`.`Paises` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `CreditClassification`
---
-
-/*!50001 DROP VIEW IF EXISTS `CreditClassification`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `CreditClassification` AS select `vn`.`creditClassification`.`id` AS `id`,`vn`.`creditClassification`.`client` AS `clientFk`,`vn`.`creditClassification`.`dateStart` AS `started`,`vn`.`creditClassification`.`dateEnd` AS `ended` from `vn`.`creditClassification` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Employee`
---
-
-/*!50001 DROP VIEW IF EXISTS `Employee`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Employee` AS select `e`.`Id_Trabajador` AS `id`,`e`.`Nombre` AS `name`,`e`.`Apellidos` AS `surname`,`e`.`user_id` AS `userFk` from `vn2008`.`Trabajadores` `e` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `PayMethod`
---
-
-/*!50001 DROP VIEW IF EXISTS `PayMethod`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `PayMethod` AS select `m`.`id` AS `id`,`m`.`name` AS `name`,`m`.`graceDays` AS `graceDays`,`m`.`deudaviva` AS `outstandingDebt`,`m`.`ibanRequired` AS `ibanRequired` from `vn2008`.`pay_met` `m` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Province`
---
-
-/*!50001 DROP VIEW IF EXISTS `Province`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Province` AS select `p`.`province_id` AS `id`,`p`.`name` AS `name`,`p`.`Paises_Id` AS `countryFk`,`p`.`warehouse_id` AS `warehouseFk`,`p`.`zone` AS `zoneFk` from `vn2008`.`province` `p` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Role`
---
-
-/*!50001 DROP VIEW IF EXISTS `Role`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Role` AS select `r`.`id` AS `id`,`r`.`name` AS `name`,`r`.`description` AS `description`,`r`.`created` AS `created`,`r`.`modified` AS `modified` from `account`.`role` `r` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `RoleMapping`
---
-
-/*!50001 DROP VIEW IF EXISTS `RoleMapping`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `RoleMapping` AS select ((`u`.`id` * 1000) + `r`.`inheritsFrom`) AS `id`,'USER' AS `principalType`,`u`.`id` AS `principalId`,`r`.`inheritsFrom` AS `roleId` from (`account`.`user` `u` join `account`.`roleRole` `r` on((`r`.`role` = `u`.`role`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Route`
---
-
-/*!50001 DROP VIEW IF EXISTS `Route`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Route` AS select `r`.`Id_Ruta` AS `id`,`r`.`Fecha` AS `date` from `vn2008`.`Rutas` `r` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `State`
---
-
-/*!50001 DROP VIEW IF EXISTS `State`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `State` AS select `s`.`id` AS `id`,`s`.`name` AS `name`,`s`.`order` AS `order`,`s`.`alert_level` AS `alertLevel`,`s`.`code` AS `code` from `vn2008`.`state` `s` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Ticket`
---
-
-/*!50001 DROP VIEW IF EXISTS `Ticket`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Ticket` AS select `t`.`Id_Ticket` AS `id`,`t`.`Id_Agencia` AS `agencyFk`,`t`.`Id_Trabajador` AS `employeeFk`,`t`.`Fecha` AS `date`,`t`.`Hora` AS `hour`,`t`.`Id_Cliente` AS `clientFk`,`t`.`Id_Consigna` AS `addressFk` from `vn2008`.`Tickets` `t` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `TicketState`
---
-
-/*!50001 DROP VIEW IF EXISTS `TicketState`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `TicketState` AS select `i`.`inter_id` AS `id`,`i`.`Id_Ticket` AS `ticketFk`,`i`.`state_id` AS `stateFk`,`i`.`Id_Trabajador` AS `employeeFk`,`i`.`odbc_date` AS `updated` from `vncontrol`.`inter` `i` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Vehicle`
---
-
-/*!50001 DROP VIEW IF EXISTS `Vehicle`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Vehicle` AS select `v`.`Id_Vehiculo` AS `id`,`v`.`Matricula` AS `numberPlate`,`v`.`Marca` AS `tradeMark`,`v`.`Modelo` AS `model`,`v`.`empresa_id` AS `companyFk`,`v`.`warehouseFk` AS `warehouseFk`,`v`.`description` AS `description`,`v`.`m3` AS `m3`,`v`.`active` AS `isActive` from `vn2008`.`Vehiculos` `v` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Warehouse`
---
-
-/*!50001 DROP VIEW IF EXISTS `Warehouse`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Warehouse` AS select `w`.`id` AS `id`,`w`.`name` AS `name`,`w`.`tpv` AS `tpv`,`w`.`inventario` AS `inventory`,`w`.`isManaged` AS `isManaged` from `vn2008`.`warehouse` `w` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `WarehouseAlias`
---
-
-/*!50001 DROP VIEW IF EXISTS `WarehouseAlias`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `WarehouseAlias` AS select `wa`.`warehouse_alias_id` AS `id`,`wa`.`alias` AS `name` from `vn2008`.`warehouse_alias` `wa` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Worker`
---
-
-/*!50001 DROP VIEW IF EXISTS `Worker`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Worker` AS select `e`.`Id_Trabajador` AS `id`,`e`.`Nombre` AS `name`,`e`.`Apellidos` AS `surname`,`e`.`user_id` AS `userFk` from `vn2008`.`Trabajadores` `e` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `Zone`
---
-
-/*!50001 DROP VIEW IF EXISTS `Zone`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `Zone` AS select `z`.`zone_id` AS `id`,`z`.`name` AS `name`,`z`.`printingOrder` AS `printingOrder` from `vn2008`.`zones` `z` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Current Database: `bs`
---
-
-USE `bs`;
-
---
--- Final view structure for view `VentasPorCliente`
---
-
-/*!50001 DROP VIEW IF EXISTS `VentasPorCliente`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `VentasPorCliente` AS select `v`.`Id_Cliente` AS `Id_Cliente`,round(sum(`v`.`importe`),0) AS `VentaBasica`,`t`.`year` AS `year`,`t`.`month` AS `month` from (`vn2008`.`time` `t` join `bs`.`ventas` `v` on((`v`.`fecha` = `t`.`date`))) group by `v`.`Id_Cliente`,`t`.`year`,`t`.`month` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `v_ventas`
---
-
-/*!50001 DROP VIEW IF EXISTS `v_ventas`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `v_ventas` AS select (`bs`.`ventas`.`importe` * `vn2008`.`Movimientos`.`Cantidad`) AS `importe`,`bs`.`ventas`.`recargo` AS `recargo`,`vn2008`.`time`.`year` AS `year`,`vn2008`.`time`.`month` AS `month`,`vn2008`.`time`.`week` AS `week`,`vn2008`.`time`.`day` AS `day` from ((`bs`.`ventas` join `vn2008`.`time` on((`vn2008`.`time`.`date` = `bs`.`ventas`.`fecha`))) join `vn2008`.`Movimientos` on((`bs`.`ventas`.`Id_Movimiento` = `vn2008`.`Movimientos`.`Id_Movimiento`))) group by `vn2008`.`time`.`date` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Current Database: `account`
---
-
-USE `account`;
-
---
--- Final view structure for view `accountDovecot`
---
-
-/*!50001 DROP VIEW IF EXISTS `accountDovecot`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `accountDovecot` AS select `u`.`name` AS `name`,`u`.`password` AS `password` from (`user` `u` join `account` `a` on((`a`.`id` = `u`.`id`))) where `u`.`active` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `accountNss`
---
-
-/*!50001 DROP VIEW IF EXISTS `accountNss`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `accountNss` AS select `u`.`name` AS `surname`,`u`.`name` AS `name`,`u`.`password` AS `password`,concat(`c`.`homedir`,'/',`u`.`name`) AS `home`,`c`.`shell` AS `shell`,`c`.`min` AS `min`,`c`.`max` AS `max`,`c`.`warn` AS `warn`,`c`.`inact` AS `inact` from ((`user` `u` join `account` `a` on((`u`.`id` = `a`.`id`))) join `accountConfig` `c`) where (`u`.`active` <> 0) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `accountPam`
---
-
-/*!50001 DROP VIEW IF EXISTS `accountPam`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `accountPam` AS select `u`.`name` AS `name`,`u`.`password` AS `password` from (`user` `u` join `account` `a` on((`u`.`id` = `a`.`id`))) where (`u`.`active` <> 0) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `userRole`
---
-
-/*!50001 DROP VIEW IF EXISTS `userRole`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `userRole` AS select `r`.`inheritsFrom` AS `id` from (`roleRole` `r` join `user` `u` on((`u`.`role` = `r`.`role`))) where (`u`.`id` = `USERGETID`()) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `userView`
---
-
-/*!50001 DROP VIEW IF EXISTS `userView`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `userView` AS select `u`.`id` AS `id`,`u`.`name` AS `name`,`u`.`active` AS `active`,`u`.`email` AS `email`,`u`.`role` AS `role`,`u`.`recoverPass` AS `recoverPass` from `user` `u` where (`u`.`name` = `account`.`userGetName`()) */
-/*!50002 WITH CASCADED CHECK OPTION */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Current Database: `cache`
---
-
-USE `cache`;
-
---
--- Current Database: `pbx`
---
-
-USE `pbx`;
-
---
--- Final view structure for view `cdrConf`
---
-
-/*!50001 DROP VIEW IF EXISTS `cdrConf`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `cdrConf` AS select `c`.`call_date` AS `calldate`,`c`.`clid` AS `clid`,`c`.`src` AS `src`,`c`.`dst` AS `dst`,`c`.`dcontext` AS `dcontext`,`c`.`channel` AS `channel`,`c`.`dst_channel` AS `dstchannel`,`c`.`last_app` AS `lastapp`,`c`.`last_data` AS `lastdata`,`c`.`duration` AS `duration`,`c`.`billsec` AS `billsec`,`c`.`disposition` AS `disposition`,`c`.`ama_flags` AS `amaflags`,`c`.`account_code` AS `accountcode`,`c`.`unique_id` AS `uniqueid`,`c`.`user_field` AS `userfield` from `cdr` `c` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `followmeConf`
---
-
-/*!50001 DROP VIEW IF EXISTS `followmeConf`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `followmeConf` AS select `f`.`extension` AS `name`,`c`.`music` AS `music`,`c`.`context` AS `context`,`c`.`takeCall` AS `takecall`,`c`.`declineCall` AS `declinecall` from (`followme` `f` join `followmeConfig` `c`) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `followmeNumberConf`
---
-
-/*!50001 DROP VIEW IF EXISTS `followmeNumberConf`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `followmeNumberConf` AS select `f`.`extension` AS `name`,1 AS `ordinal`,`f`.`phone` AS `phonenumber`,`c`.`timeout` AS `timeout` from (`followme` `f` join `followmeConfig` `c`) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `queueConf`
---
-
-/*!50001 DROP VIEW IF EXISTS `queueConf`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `queueConf` AS select `q`.`name` AS `name`,`c`.`strategy` AS `strategy`,`c`.`timeout` AS `timeout`,`c`.`retry` AS `retry`,`c`.`weight` AS `weight`,`c`.`maxLen` AS `maxlen`,`c`.`ringInUse` AS `ringinuse` from (`queue` `q` join `queueConfig` `c` on((`q`.`config` = `c`.`id`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `queueMemberConf`
---
-
-/*!50001 DROP VIEW IF EXISTS `queueMemberConf`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `queueMemberConf` AS select `m`.`id` AS `uniqueid`,`m`.`queue` AS `queue_name`,concat('SIP/',`m`.`extension`) AS `interface` from `queueMember` `m` union all select `p`.`id` AS `id`,`p`.`queue` AS `queue`,concat('Local/',`p`.`phone`,'@outgoing') AS `phone` from `queuePhone` `p` */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `sipConf`
---
-
-/*!50001 DROP VIEW IF EXISTS `sipConf`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `sipConf` AS select `s`.`user_id` AS `id`,`s`.`extension` AS `name`,`s`.`secret` AS `secret`,`s`.`caller_id` AS `callerid`,`c`.`host` AS `host`,`c`.`deny` AS `deny`,`c`.`permit` AS `permit`,`c`.`type` AS `type`,`c`.`context` AS `context`,`c`.`incomingLimit` AS `incominglimit`,`c`.`pickupGroup` AS `pickupgroup`,`c`.`careInvite` AS `careinvite`,`r`.`ipAddr` AS `ipaddr`,`r`.`regSeconds` AS `regseconds`,`r`.`port` AS `port`,`r`.`defaultUser` AS `defaultuser`,`r`.`userAgent` AS `useragent`,`r`.`lastMs` AS `lastms`,`r`.`fullContact` AS `fullcontact`,`r`.`regServer` AS `regserver` from ((`sip` `s` left join `sipReg` `r` on((`s`.`user_id` = `r`.`userId`))) join `sipConfig` `c`) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Current Database: `hedera`
---
-
-USE `hedera`;
-
---
--- Final view structure for view `address_view`
---
-
-/*!50001 DROP VIEW IF EXISTS `address_view`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `address_view` AS select `a`.`id_consigna` AS `id`,`a`.`Id_cliente` AS `customer_id`,`a`.`warehouse_id` AS `warehouse_id`,`a`.`domicilio` AS `name`,`a`.`poblacion` AS `city`,`a`.`province_id` AS `province_id`,`a`.`codPostal` AS `zip_code`,`a`.`consignatario` AS `consignee`,`a`.`predeterminada` AS `default`,`a`.`Id_Agencia` AS `type_id`,`a`.`especificaciones` AS `specs`,`a`.`seguro` AS `insurance`,`a`.`porte` AS `postage`,`a`.`active` AS `active` from `vn2008`.`Consignatarios` `a` where (`a`.`Id_cliente` = `account`.`userGetId`()) */
-/*!50002 WITH CASCADED CHECK OPTION */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `basket`
---
-
-/*!50001 DROP VIEW IF EXISTS `basket`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `basket` AS select `o`.`id` AS `id`,`o`.`date_make` AS `date_make`,`o`.`date_send` AS `date_send`,`o`.`customer_id` AS `customer_id`,`o`.`delivery_method_id` AS `delivery_method_id`,`o`.`agency_id` AS `agency_id`,`o`.`address_id` AS `address_id`,`o`.`company_id` AS `company_id`,`o`.`note` AS `note` from `hedera`.`order` `o` where (`o`.`id` = `basketGetId`()) */
-/*!50002 WITH CASCADED CHECK OPTION */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `basket_defaults`
---
-
-/*!50001 DROP VIEW IF EXISTS `basket_defaults`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `basket_defaults` AS select `ad`.`id_consigna` AS `address_id`,`ad`.`Id_Agencia` AS `agency_id`,`v`.`code` AS `delivery_method` from (((`vn2008`.`Clientes` `c` left join `vn2008`.`Consignatarios` `ad` on((`ad`.`id_consigna` = `c`.`default_address`))) join `vn2008`.`Agencias` `a` on((`a`.`Id_Agencia` = `ad`.`Id_Agencia`))) join `vn2008`.`Vistas` `v` on((`v`.`vista_id` = `a`.`Vista`))) where (`c`.`id_cliente` = `account`.`userGetId`()) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `basket_item`
---
-
-/*!50001 DROP VIEW IF EXISTS `basket_item`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `basket_item` AS select `r`.`id` AS `id`,`r`.`order_id` AS `order_id`,`r`.`warehouse_id` AS `warehouse_id`,`r`.`item_id` AS `item_id`,`r`.`amount` AS `amount`,`r`.`price` AS `price` from `hedera`.`order_row` `r` where (`r`.`order_id` = `basketGetId`()) */
-/*!50002 WITH CASCADED CHECK OPTION */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `customer_user`
---
-
-/*!50001 DROP VIEW IF EXISTS `customer_user`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `customer_user` AS select `c`.`id_cliente` AS `user_id`,`c`.`cliente` AS `name` from `vn2008`.`Clientes` `c` where (`c`.`id_cliente` = `account`.`userGetId`()) */
-/*!50002 WITH CASCADED CHECK OPTION */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `customer_view`
---
-
-/*!50001 DROP VIEW IF EXISTS `customer_view`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `customer_view` AS select `c`.`id_cliente` AS `user_id`,`c`.`cliente` AS `name`,`c`.`e-mail` AS `email`,`c`.`mail` AS `mail`,`c`.`default_address` AS `default_address`,`c`.`credito` AS `credit` from `vn2008`.`Clientes` `c` where (`c`.`id_cliente` = `account`.`userGetId`()) */
-/*!50002 WITH CASCADED CHECK OPTION */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `invoice_view`
---
-
-/*!50001 DROP VIEW IF EXISTS `invoice_view`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `invoice_view` AS select `i`.`factura_id` AS `invoice_id`,`i`.`Id_Factura` AS `serial_num`,`i`.`Fecha` AS `issued`,`i`.`Importe` AS `amount` from `vn2008`.`Facturas` `i` where ((`i`.`Id_Cliente` = `account`.`userGetId`()) and `i`.`pdf`) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `order_confirm_time`
---
-
-/*!50001 DROP VIEW IF EXISTS `order_confirm_time`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `order_confirm_time` AS select `o`.`date_make` AS `date_make`,`o`.`source_app` AS `source_app`,`o`.`customer_id` AS `customer_id`,`o`.`confirm_date` AS `confirm_date`,`o`.`first_row_stamp` AS `first_row_stamp`,(ceiling((((unix_timestamp(`o`.`confirm_date`) - unix_timestamp(`o`.`first_row_stamp`)) / 60) / 5)) * 5) AS `minutos` from `order` `o` where ((`o`.`confirm_date` is not null) and (`o`.`first_row_stamp` is not null)) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `order_row_view`
---
-
-/*!50001 DROP VIEW IF EXISTS `order_row_view`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `order_row_view` AS select `r`.`id` AS `id`,`r`.`order_id` AS `order_id`,`r`.`warehouse_id` AS `warehouse_id`,`r`.`item_id` AS `item_id`,`r`.`amount` AS `amount`,`r`.`price` AS `price2` from `hedera`.`order_row` `r` where `r`.`order_id` in (select `order_view`.`id` AS `id` from `hedera`.`order_view`) */
-/*!50002 WITH CASCADED CHECK OPTION */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `order_view`
---
-
-/*!50001 DROP VIEW IF EXISTS `order_view`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `order_view` AS select `o`.`id` AS `id`,`o`.`date_make` AS `date_make`,`o`.`date_send` AS `date_send`,`o`.`customer_id` AS `customer_id`,`o`.`delivery_method_id` AS `delivery_method_id`,`o`.`agency_id` AS `agency_id`,`o`.`note` AS `note`,`o`.`address_id` AS `address_id`,`o`.`company_id` AS `company_id` from `hedera`.`order` `o` where ((`o`.`customer_id` = `account`.`userGetId`()) and (`o`.`is_bionic` = 0)) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ticket_row_view`
---
-
-/*!50001 DROP VIEW IF EXISTS `ticket_row_view`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ticket_row_view` AS select `m`.`Id_Movimiento` AS `id`,`m`.`Id_Article` AS `item_id`,`m`.`Id_Ticket` AS `ticket_id`,`m`.`Concepte` AS `concept`,`m`.`Cantidad` AS `amount`,`m`.`Preu` AS `price`,`m`.`PrecioFijado` AS `fixed`,`m`.`Descuento` AS `discount`,`m`.`CostFixat` AS `cost`,`m`.`Reservado` AS `reserved`,`m`.`OK` AS `ok` from (`vn2008`.`Movimientos` `m` join `hedera`.`ticket_view` `t` on((`m`.`Id_Ticket` = `t`.`id`))) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `ticket_view`
---
-
-/*!50001 DROP VIEW IF EXISTS `ticket_view`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `ticket_view` AS select `t`.`Id_Ticket` AS `id`,`t`.`Id_Cliente` AS `customer_id`,`t`.`warehouse_id` AS `warehouse_id`,`t`.`Fecha` AS `date`,`t`.`landing` AS `delivery`,`t`.`Alias` AS `alias`,`t`.`Id_Agencia` AS `agency_id`,`t`.`Notas` AS `note`,`t`.`Factura` AS `invoice`,`t`.`Id_Consigna` AS `address_id`,`t`.`Id_Trabajador` AS `employee_id`,`t`.`Observaciones` AS `comments`,`t`.`Firmado` AS `signed`,`t`.`Bultos` AS `packages`,`t`.`Localizacion` AS `location`,`t`.`Hora` AS `hour`,`t`.`blocked` AS `blocked`,`t`.`Solucion` AS `solution`,`t`.`empresa_id` AS `company_id`,`a`.`Agencia` AS `type` from (`vn2008`.`Tickets` `t` join `vn2008`.`Agencias` `a` on((`t`.`Id_Agencia` = `a`.`Id_Agencia`))) where (`t`.`Id_Cliente` = `account`.`userGetId`()) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-
---
--- Final view structure for view `tpv_transaction_view`
---
-
-/*!50001 DROP VIEW IF EXISTS `tpv_transaction_view`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `tpv_transaction_view` AS select `t`.`id` AS `id`,`t`.`merchant_id` AS `merchant_id`,`t`.`customer_id` AS `customer_id`,`t`.`receipt_id` AS `receipt_id`,`t`.`amount` AS `amount`,`t`.`response` AS `response`,`t`.`status` AS `status`,`t`.`date_time` AS `date_time` from `hedera`.`tpv_transaction` `t` where (`t`.`customer_id` = `account`.`userGetId`()) */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
---
--- Final view structure for view `user_android_view`
---
-/*!50001 DROP VIEW IF EXISTS `user_android_view`*/;
-/*!50001 SET @saved_cs_client = @@character_set_client */;
-/*!50001 SET @saved_cs_results = @@character_set_results */;
-/*!50001 SET @saved_col_connection = @@collation_connection */;
-/*!50001 SET character_set_client = utf8 */;
-/*!50001 SET character_set_results = utf8 */;
-/*!50001 SET collation_connection = utf8_general_ci */;
-/*!50001 CREATE ALGORITHM=UNDEFINED */
-/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
-/*!50001 VIEW `user_android_view` AS select `a`.`user_id` AS `user_id`,`a`.`android_id` AS `android_id` from `hedera`.`user_android` `a` where (`a`.`user_id` = `account`.`userGetId`()) */
-/*!50002 WITH CASCADED CHECK OPTION */;
-/*!50001 SET character_set_client = @saved_cs_client */;
-/*!50001 SET character_set_results = @saved_cs_results */;
-/*!50001 SET collation_connection = @saved_col_connection */;
-/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
-/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
-/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
-/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
-/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
-/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
-/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
-/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2017-12-18 14:16:38
diff --git a/services/db/localDB03StructureVn.sql b/services/db/localDB03StructureVn.sql
new file mode 100644
index 000000000..9786cfdac
--- /dev/null
+++ b/services/db/localDB03StructureVn.sql
@@ -0,0 +1,11017 @@
+CREATE DATABASE IF NOT EXISTS `vn` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
+USE `vn`;
+-- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64)
+--
+-- Host: db.verdnatura.es Database: vn
+-- ------------------------------------------------------
+-- 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 */;
+
+--
+-- Temporary view structure for view `accounting`
+--
+
+DROP TABLE IF EXISTS `accounting`;
+/*!50001 DROP VIEW IF EXISTS `accounting`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `accounting` AS SELECT
+ 1 AS `id`,
+ 1 AS `bank`,
+ 1 AS `account`,
+ 1 AS `accountingTypeFk`,
+ 1 AS `entityFk`,
+ 1 AS `isActive`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `accountingType`
+--
+
+DROP TABLE IF EXISTS `accountingType`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `accountingType` (
+ `id` smallint(6) NOT NULL DEFAULT '0',
+ `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='descripcio dels valors de la columna "cash" de la taula vn2008.Bancios';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `activityTaxDismissed`
+--
+
+DROP TABLE IF EXISTS `activityTaxDismissed`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `activityTaxDismissed` (
+ `clientFk` int(11) NOT NULL,
+ `isNotified` tinyint(1) DEFAULT '0',
+ `isDismissed` tinyint(1) DEFAULT '0',
+ `notified` int(11) DEFAULT '0',
+ PRIMARY KEY (`clientFk`),
+ CONSTRAINT `clientFk` FOREIGN KEY (`clientFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) 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 */;
+
+--
+-- Temporary view structure for view `address`
+--
+
+DROP TABLE IF EXISTS `address`;
+/*!50001 DROP VIEW IF EXISTS `address`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `address` AS SELECT
+ 1 AS `id`,
+ 1 AS `clientFk`,
+ 1 AS `street`,
+ 1 AS `city`,
+ 1 AS `postalCode`,
+ 1 AS `provinceFk`,
+ 1 AS `phone`,
+ 1 AS `celular`,
+ 1 AS `nickname`,
+ 1 AS `isDefaultAddress`,
+ 1 AS `active`,
+ 1 AS `longitude`,
+ 1 AS `latitude`,
+ 1 AS `warehouseFk`,
+ 1 AS `mobile`,
+ 1 AS `agencyFk`,
+ 1 AS `isEqualizated`,
+ 1 AS `defaultAddress`,
+ 1 AS `customer`,
+ 1 AS `agency`,
+ 1 AS `province`,
+ 1 AS `warehouse`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `addressForPackaging`
+--
+
+DROP TABLE IF EXISTS `addressForPackaging`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `addressForPackaging` (
+ `addressFk` int(11) NOT NULL,
+ `packagingValue` decimal(10,2) NOT NULL DEFAULT '0.04',
+ PRIMARY KEY (`addressFk`),
+ CONSTRAINT `addresForPackaging_fk1` FOREIGN KEY (`addressFk`) REFERENCES `vn2008`.`Consignatarios` (`id_consigna`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `addressObservation`
+--
+
+DROP TABLE IF EXISTS `addressObservation`;
+/*!50001 DROP VIEW IF EXISTS `addressObservation`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `addressObservation` AS SELECT
+ 1 AS `id`,
+ 1 AS `addressFk`,
+ 1 AS `observationTypeFk`,
+ 1 AS `description`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `agency`
+--
+
+DROP TABLE IF EXISTS `agency`;
+/*!50001 DROP VIEW IF EXISTS `agency`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `agency` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `warehouse`,
+ 1 AS `warehouseFk`,
+ 1 AS `isVolumetric`,
+ 1 AS `bank`,
+ 1 AS `bankFk`,
+ 1 AS `warehouseNickname`,
+ 1 AS `warehouseAliasFk`,
+ 1 AS `own`,
+ 1 AS `labelZone`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `agencyHour`
+--
+
+DROP TABLE IF EXISTS `agencyHour`;
+/*!50001 DROP VIEW IF EXISTS `agencyHour`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `agencyHour` AS SELECT
+ 1 AS `id`,
+ 1 AS `agency`,
+ 1 AS `weekDay`,
+ 1 AS `warehouse`,
+ 1 AS `province`,
+ 1 AS `substractDay`,
+ 1 AS `maxHour`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `agencyMode`
+--
+
+DROP TABLE IF EXISTS `agencyMode`;
+/*!50001 DROP VIEW IF EXISTS `agencyMode`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `agencyMode` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `description`,
+ 1 AS `view`,
+ 1 AS `deliveryMethod`,
+ 1 AS `m3`,
+ 1 AS `cod71`,
+ 1 AS `web`,
+ 1 AS `agency`,
+ 1 AS `agencyFk`,
+ 1 AS `agencyService`,
+ 1 AS `agencyServiceFk`,
+ 1 AS `inflacion`,
+ 1 AS `isVolumetric`,
+ 1 AS `reportMail`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `agencyWarehouse`
+--
+
+DROP TABLE IF EXISTS `agencyWarehouse`;
+/*!50001 DROP VIEW IF EXISTS `agencyWarehouse`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `agencyWarehouse` AS SELECT
+ 1 AS `agencyFk`,
+ 1 AS `warehouseFk`,
+ 1 AS `agencyType`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `autonomousRegion`
+--
+
+DROP TABLE IF EXISTS `autonomousRegion`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `autonomousRegion` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(50) CHARACTER SET utf8 NOT NULL,
+ `geoFk` int(11) DEFAULT NULL,
+ `countryFk` mediumint(8) unsigned DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `countryFk` (`countryFk`),
+ CONSTRAINT `countryFk` FOREIGN KEY (`countryFk`) REFERENCES `vn2008`.`Paises` (`Id`) ON DELETE NO ACTION ON UPDATE NO ACTION
+) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `awb`
+--
+
+DROP TABLE IF EXISTS `awb`;
+/*!50001 DROP VIEW IF EXISTS `awb`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `awb` AS SELECT
+ 1 AS `id`,
+ 1 AS `code`,
+ 1 AS `package`,
+ 1 AS `weight`,
+ 1 AS `created`,
+ 1 AS `transitoryFk`,
+ 1 AS `taxFk`,
+ 1 AS `docFk`,
+ 1 AS `amount`,
+ 1 AS `freightFk`,
+ 1 AS `m3`,
+ 1 AS `stems`,
+ 1 AS `flightFk`,
+ 1 AS `volumeWeight`,
+ 1 AS `hb`,
+ 1 AS `rate`,
+ 1 AS `booked`,
+ 1 AS `issued`,
+ 1 AS `operated`,
+ 1 AS `bookEntried`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `bank`
+--
+
+DROP TABLE IF EXISTS `bank`;
+/*!50001 DROP VIEW IF EXISTS `bank`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `bank` AS SELECT
+ 1 AS `id`,
+ 1 AS `bank`,
+ 1 AS `account`,
+ 1 AS `cash`,
+ 1 AS `entityFk`,
+ 1 AS `isActive`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `bankEntity`
+--
+
+DROP TABLE IF EXISTS `bankEntity`;
+/*!50001 DROP VIEW IF EXISTS `bankEntity`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `bankEntity` AS SELECT
+ 1 AS `id`,
+ 1 AS `countryFk`,
+ 1 AS `name`,
+ 1 AS `bic`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `bookingPlanner`
+--
+
+DROP TABLE IF EXISTS `bookingPlanner`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `bookingPlanner` (
+ `id` int(10) NOT NULL AUTO_INCREMENT,
+ `effectived` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `pgcFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
+ `taxAreaFk` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'SPAIN',
+ `priority` int(2) unsigned DEFAULT NULL,
+ `taxClassFk` tinyint(3) unsigned NOT NULL DEFAULT '1',
+ `countryFk` mediumint(8) unsigned NOT NULL DEFAULT '1',
+ PRIMARY KEY (`id`),
+ KEY `taxArea_bookingPlanner_idx` (`taxAreaFk`),
+ KEY `pgcFk_bookingPlanner_idx` (`pgcFk`),
+ KEY `taxClassFk` (`taxClassFk`),
+ KEY `countryFk` (`countryFk`),
+ CONSTRAINT `bookingPlanner_ibfk_1` FOREIGN KEY (`pgcFk`) REFERENCES `pgc` (`code`) ON DELETE CASCADE,
+ CONSTRAINT `bookingPlanner_ibfk_2` FOREIGN KEY (`taxClassFk`) REFERENCES `vn2008`.`iva_group` (`iva_group_id`) ON DELETE CASCADE,
+ CONSTRAINT `bookingPlanner_ibfk_3` FOREIGN KEY (`countryFk`) REFERENCES `vn2008`.`Paises` (`Id`) ON DELETE CASCADE,
+ CONSTRAINT `taxArea_bookingPlanner` FOREIGN KEY (`taxAreaFk`) REFERENCES `taxArea` (`code`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `botanicExport`
+--
+
+DROP TABLE IF EXISTS `botanicExport`;
+/*!50001 DROP VIEW IF EXISTS `botanicExport`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `botanicExport` AS SELECT
+ 1 AS `id`,
+ 1 AS `ediGenusFk`,
+ 1 AS `ediSpecieFk`,
+ 1 AS `countryFk`,
+ 1 AS `restriction`,
+ 1 AS `description`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `buy`
+--
+
+DROP TABLE IF EXISTS `buy`;
+/*!50001 DROP VIEW IF EXISTS `buy`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `buy` AS SELECT
+ 1 AS `id`,
+ 1 AS `entryFk`,
+ 1 AS `itemFk`,
+ 1 AS `amount`,
+ 1 AS `buyingValue`,
+ 1 AS `quantity`,
+ 1 AS `packageFk`,
+ 1 AS `stickers`,
+ 1 AS `freightValue`,
+ 1 AS `packageValue`,
+ 1 AS `comissionValue`,
+ 1 AS `packing`,
+ 1 AS `grouping`,
+ 1 AS `groupingMode`,
+ 1 AS `location`,
+ 1 AS `price1`,
+ 1 AS `price2`,
+ 1 AS `price3`,
+ 1 AS `minPrice`,
+ 1 AS `producer`,
+ 1 AS `printedStickers`,
+ 1 AS `isChecked`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `category`
+--
+
+DROP TABLE IF EXISTS `category`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `category` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
+ `nick` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `city`
+--
+
+DROP TABLE IF EXISTS `city`;
+/*!50001 DROP VIEW IF EXISTS `city`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `city` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `provinceFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `client`
+--
+
+DROP TABLE IF EXISTS `client`;
+/*!50001 DROP VIEW IF EXISTS `client`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `client` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `fi`,
+ 1 AS `socialName`,
+ 1 AS `contact`,
+ 1 AS `street`,
+ 1 AS `city`,
+ 1 AS `postcode`,
+ 1 AS `phone`,
+ 1 AS `mobile`,
+ 1 AS `fax`,
+ 1 AS `isRelevant`,
+ 1 AS `email`,
+ 1 AS `iban`,
+ 1 AS `dueDay`,
+ 1 AS `accountingAccount`,
+ 1 AS `isEqualizated`,
+ 1 AS `provinceFk`,
+ 1 AS `hasToInvoice`,
+ 1 AS `credit`,
+ 1 AS `countryFk`,
+ 1 AS `isActive`,
+ 1 AS `gestdocFk`,
+ 1 AS `quality`,
+ 1 AS `payMethodFk`,
+ 1 AS `created`,
+ 1 AS `isToBeMailed`,
+ 1 AS `contactChannelFk`,
+ 1 AS `hasSepaVnl`,
+ 1 AS `hasCoreVnl`,
+ 1 AS `hasCoreVnh`,
+ 1 AS `riskCalculated`,
+ 1 AS `clientTypeFk`,
+ 1 AS `mailAddress`,
+ 1 AS `cplusTerIdNifFk`,
+ 1 AS `hasToInvoiceByAddress`,
+ 1 AS `isTaxDataChecked`,
+ 1 AS `isFreezed`,
+ 1 AS `creditInsurance`,
+ 1 AS `isCreatedAsServed`,
+ 1 AS `hasInvoiceSimplified`,
+ 1 AS `salesPersonFk`,
+ 1 AS `isVies`,
+ 1 AS `eypbc`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `clientCredit`
+--
+
+DROP TABLE IF EXISTS `clientCredit`;
+/*!50001 DROP VIEW IF EXISTS `clientCredit`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `clientCredit` AS SELECT
+ 1 AS `id`,
+ 1 AS `clientFk`,
+ 1 AS `employeeFk`,
+ 1 AS `amount`,
+ 1 AS `created`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `clientCreditLimit`
+--
+
+DROP TABLE IF EXISTS `clientCreditLimit`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `clientCreditLimit` (
+ `id` int(11) NOT NULL,
+ `maxAmount` int(10) unsigned NOT NULL,
+ `roleFk` int(10) unsigned NOT NULL,
+ 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 `clientDefaultCompany`
+--
+
+DROP TABLE IF EXISTS `clientDefaultCompany`;
+/*!50001 DROP VIEW IF EXISTS `clientDefaultCompany`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `clientDefaultCompany` AS SELECT
+ 1 AS `id`,
+ 1 AS `ClientFk`,
+ 1 AS `CompanyFk`,
+ 1 AS `started`,
+ 1 AS `finished`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `clientLog`
+--
+
+DROP TABLE IF EXISTS `clientLog`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `clientLog` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `originFk` int(11) NOT NULL,
+ `userFk` int(10) unsigned NOT NULL,
+ `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
+ `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
+ `description` text COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `originFk` (`originFk`),
+ KEY `userFk` (`userFk`),
+ CONSTRAINT `clientLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE NO ACTION ON UPDATE NO ACTION,
+ CONSTRAINT `clientLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
+) ENGINE=InnoDB AUTO_INCREMENT=12340 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `clientManaCache`
+--
+
+DROP TABLE IF EXISTS `clientManaCache`;
+/*!50001 DROP VIEW IF EXISTS `clientManaCache`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `clientManaCache` AS SELECT
+ 1 AS `clientFk`,
+ 1 AS `mana`,
+ 1 AS `dated`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `clientNew`
+--
+
+DROP TABLE IF EXISTS `clientNew`;
+/*!50001 DROP VIEW IF EXISTS `clientNew`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `clientNew` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `fi`,
+ 1 AS `socialName`,
+ 1 AS `contact`,
+ 1 AS `street`,
+ 1 AS `city`,
+ 1 AS `postcode`,
+ 1 AS `phone`,
+ 1 AS `mobile`,
+ 1 AS `fax`,
+ 1 AS `isRelevant`,
+ 1 AS `email`,
+ 1 AS `iban`,
+ 1 AS `dueDay`,
+ 1 AS `accountingAccount`,
+ 1 AS `isEqualizated`,
+ 1 AS `provinceFk`,
+ 1 AS `hasToInvoice`,
+ 1 AS `credit`,
+ 1 AS `countryFk`,
+ 1 AS `isActive`,
+ 1 AS `gestdocFk`,
+ 1 AS `quality`,
+ 1 AS `payMethodFk`,
+ 1 AS `created`,
+ 1 AS `isToBeMailed`,
+ 1 AS `contactChannelFk`,
+ 1 AS `hasSepaVnl`,
+ 1 AS `hasCoreVnl`,
+ 1 AS `hasCoreVnh`,
+ 1 AS `riskCalculated`,
+ 1 AS `clientTypeFk`,
+ 1 AS `mailAddress`,
+ 1 AS `cplusTerIdNifFk`,
+ 1 AS `hasToInvoiceByAddress`,
+ 1 AS `isTaxDataChecked`,
+ 1 AS `isFreezed`,
+ 1 AS `creditInsurance`,
+ 1 AS `isCreatedAsServed`,
+ 1 AS `hasInvoiceSimplified`,
+ 1 AS `salesPersonFk`,
+ 1 AS `isVies`,
+ 1 AS `eypbc`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `clientNotification`
+--
+
+DROP TABLE IF EXISTS `clientNotification`;
+/*!50001 DROP VIEW IF EXISTS `clientNotification`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `clientNotification` AS SELECT
+ 1 AS `id`,
+ 1 AS `clientFk`,
+ 1 AS `clientNotificationTypeFk`,
+ 1 AS `created`,
+ 1 AS `workerFk`,
+ 1 AS `userFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `clientNotificationType`
+--
+
+DROP TABLE IF EXISTS `clientNotificationType`;
+/*!50001 DROP VIEW IF EXISTS `clientNotificationType`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `clientNotificationType` AS SELECT
+ 1 AS `id`,
+ 1 AS `code`,
+ 1 AS `description`,
+ 1 AS `isVisible`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `clientObservation`
+--
+
+DROP TABLE IF EXISTS `clientObservation`;
+/*!50001 DROP VIEW IF EXISTS `clientObservation`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `clientObservation` AS SELECT
+ 1 AS `id`,
+ 1 AS `clientFk`,
+ 1 AS `workerFk`,
+ 1 AS `text`,
+ 1 AS `creationDate`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `clientTransicion`
+--
+
+DROP TABLE IF EXISTS `clientTransicion`;
+/*!50001 DROP VIEW IF EXISTS `clientTransicion`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `clientTransicion` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `fi`,
+ 1 AS `socialName`,
+ 1 AS `contact`,
+ 1 AS `street`,
+ 1 AS `city`,
+ 1 AS `postcode`,
+ 1 AS `phone`,
+ 1 AS `mobile`,
+ 1 AS `fax`,
+ 1 AS `isRelevant`,
+ 1 AS `email`,
+ 1 AS `iban`,
+ 1 AS `dueDay`,
+ 1 AS `accountingAccount`,
+ 1 AS `isEqualizated`,
+ 1 AS `provinceFk`,
+ 1 AS `hasToInvoice`,
+ 1 AS `credit`,
+ 1 AS `countryFk`,
+ 1 AS `isActive`,
+ 1 AS `gestdocFk`,
+ 1 AS `quality`,
+ 1 AS `paymentMethodFk`,
+ 1 AS `isToBeMailed`,
+ 1 AS `contactChannelFk`,
+ 1 AS `hasSepaVnl`,
+ 1 AS `hasCoreVnl`,
+ 1 AS `hasCoreVnh`,
+ 1 AS `riskCalculated`,
+ 1 AS `clientTypeFk`,
+ 1 AS `mail_address`,
+ 1 AS `cplusTerIdNifFk`,
+ 1 AS `isTaxDataChecked`,
+ 1 AS `isFreezed`,
+ 1 AS `creditInsurance`,
+ 1 AS `isCreatedAsServed`,
+ 1 AS `hasInvoiceSimplified`,
+ 1 AS `salesPersonFk`,
+ 1 AS `isVies`,
+ 1 AS `eypbc`,
+ 1 AS `active`,
+ 1 AS `equalizationTax`,
+ 1 AS `invoiceByEmail`,
+ 1 AS `payMethodFk`,
+ 1 AS `vies`,
+ 1 AS `hasToInvoiceByAddress`,
+ 1 AS `typeFk`,
+ 1 AS `created`,
+ 1 AS `province`,
+ 1 AS `Congelado`,
+ 1 AS `Id_Trabajador`,
+ 1 AS `workerFk`,
+ 1 AS `cyc`,
+ 1 AS `Id_Pais`,
+ 1 AS `activo`,
+ 1 AS `gestdoc`,
+ 1 AS `calidad`,
+ 1 AS `paymentMethod`,
+ 1 AS `channel`,
+ 1 AS `channelFk`,
+ 1 AS `clientes_tipo_id`,
+ 1 AS `postcode_id`,
+ 1 AS `codpos`,
+ 1 AS `postalAddress`,
+ 1 AS `sepavnl`,
+ 1 AS `corevnl`,
+ 1 AS `corevnh`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `clientType`
+--
+
+DROP TABLE IF EXISTS `clientType`;
+/*!50001 DROP VIEW IF EXISTS `clientType`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `clientType` AS SELECT
+ 1 AS `id`,
+ 1 AS `code`,
+ 1 AS `type`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `clientkk`
+--
+
+DROP TABLE IF EXISTS `clientkk`;
+/*!50001 DROP VIEW IF EXISTS `clientkk`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `clientkk` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `fi`,
+ 1 AS `phone`,
+ 1 AS `fax`,
+ 1 AS `email`,
+ 1 AS `iban`,
+ 1 AS `dueDay`,
+ 1 AS `accountingAccount`,
+ 1 AS `isEqualizated`,
+ 1 AS `city`,
+ 1 AS `province`,
+ 1 AS `provinceFk`,
+ 1 AS `postcode`,
+ 1 AS `socialName`,
+ 1 AS `contact`,
+ 1 AS `hasToInvoice`,
+ 1 AS `Congelado`,
+ 1 AS `Id_Trabajador`,
+ 1 AS `workerFk`,
+ 1 AS `credit`,
+ 1 AS `cyc`,
+ 1 AS `Id_Pais`,
+ 1 AS `countryFk`,
+ 1 AS `activo`,
+ 1 AS `active`,
+ 1 AS `gestdoc`,
+ 1 AS `gestdocFk`,
+ 1 AS `calidad`,
+ 1 AS `paymentMethod`,
+ 1 AS `paymentMethodFk`,
+ 1 AS `registerDate`,
+ 1 AS `invoiceByEmail`,
+ 1 AS `isToBeMailed`,
+ 1 AS `channel`,
+ 1 AS `channelFk`,
+ 1 AS `VIES`,
+ 1 AS `sepavnl`,
+ 1 AS `corevnl`,
+ 1 AS `riskCalculated`,
+ 1 AS `corevnh`,
+ 1 AS `clientes_tipo_id`,
+ 1 AS `clientTypeFk`,
+ 1 AS `postcode_id`,
+ 1 AS `postcodeFk`,
+ 1 AS `mail_address`,
+ 1 AS `codpos`,
+ 1 AS `cplusTerIdNifFk`,
+ 1 AS `postalAddress`,
+ 1 AS `invoiceByAddress`,
+ 1 AS `isTaxDataChecked`,
+ 1 AS `isFreezed`,
+ 1 AS `creditInsurance`,
+ 1 AS `isCreatedAsServed`,
+ 1 AS `hasInvoiceSimplified`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `color`
+--
+
+DROP TABLE IF EXISTS `color`;
+/*!50001 DROP VIEW IF EXISTS `color`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `color` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `company`
+--
+
+DROP TABLE IF EXISTS `company`;
+/*!50001 DROP VIEW IF EXISTS `company`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `company` AS SELECT
+ 1 AS `id`,
+ 1 AS `code`,
+ 1 AS `supplierAccountFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `comparative`
+--
+
+DROP TABLE IF EXISTS `comparative`;
+/*!50001 DROP VIEW IF EXISTS `comparative`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `comparative` AS SELECT
+ 1 AS `timePeriod`,
+ 1 AS `itemFk`,
+ 1 AS `warehouseFk`,
+ 1 AS `quantity`,
+ 1 AS `price`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `comparativeFilter`
+--
+
+DROP TABLE IF EXISTS `comparativeFilter`;
+/*!50001 DROP VIEW IF EXISTS `comparativeFilter`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `comparativeFilter` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `whereSql`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `confectionType`
+--
+
+DROP TABLE IF EXISTS `confectionType`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `confectionType` (
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `description` 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 `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(10) unsigned NOT NULL AUTO_INCREMENT,
+ `mdbServer` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `fakeEmail` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `defaultersMaxAmount` int(10) DEFAULT '200' COMMENT 'maxima deuda permitida a partir de la cual se bloquea a un usuario',
+ PRIMARY KEY (`id`)
+) 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 `country`
+--
+
+DROP TABLE IF EXISTS `country`;
+/*!50001 DROP VIEW IF EXISTS `country`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `country` AS SELECT
+ 1 AS `id`,
+ 1 AS `country`,
+ 1 AS `CEE`,
+ 1 AS `isUeeMember`,
+ 1 AS `Code`,
+ 1 AS `currencyFk`,
+ 1 AS `politicalCountryFk`,
+ 1 AS `geoFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `cplusCorrectingType`
+--
+
+DROP TABLE IF EXISTS `cplusCorrectingType`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `cplusCorrectingType` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `description` varchar(45) 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 `cplusInvoiceType472`
+--
+
+DROP TABLE IF EXISTS `cplusInvoiceType472`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `cplusInvoiceType472` (
+ `id` int(10) unsigned NOT NULL,
+ `description` varchar(255) CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='(*18) TIPO FACTURA (Asientos)SOPORTADO – DEDUCIBLE (472)';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `cplusInvoiceType477`
+--
+
+DROP TABLE IF EXISTS `cplusInvoiceType477`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `cplusInvoiceType477` (
+ `id` int(10) unsigned NOT NULL,
+ `description` varchar(255) CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='(*18) TIPO FACTURA (Asientos)REPERCUTIDO - DEVENGADO (477)';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `cplusRectificationType`
+--
+
+DROP TABLE IF EXISTS `cplusRectificationType`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `cplusRectificationType` (
+ `id` int(10) unsigned NOT NULL,
+ `description` varchar(255) CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='(*20) TIPO RECTIFICATIVA (Asientos)';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `cplusSubjectOp`
+--
+
+DROP TABLE IF EXISTS `cplusSubjectOp`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `cplusSubjectOp` (
+ `id` int(10) unsigned NOT NULL,
+ `description` varchar(255) CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='(*17) TIPO OPERACIÓN SUJETA/NO SUJETA (Asientos)';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `cplusTaxBreak`
+--
+
+DROP TABLE IF EXISTS `cplusTaxBreak`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `cplusTaxBreak` (
+ `id` int(10) unsigned NOT NULL,
+ `description` varchar(255) CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='(*16) TIPO EXENCIÓN (Asientos)';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `cplusTerIdNif`
+--
+
+DROP TABLE IF EXISTS `cplusTerIdNif`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `cplusTerIdNif` (
+ `id` int(11) NOT NULL,
+ `description` varchar(255) CHARACTER SET utf8 NOT 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 `cplusTrascendency472`
+--
+
+DROP TABLE IF EXISTS `cplusTrascendency472`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `cplusTrascendency472` (
+ `id` int(10) unsigned NOT NULL,
+ `description` varchar(255) CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='(*15) CLAVE DE RÉGIMEN ESPECIAL O TRASCENDENCIA(Asientos)SOPORTADO – DEDUCIBLE (472)';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `cplusTrascendency477`
+--
+
+DROP TABLE IF EXISTS `cplusTrascendency477`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `cplusTrascendency477` (
+ `id` int(10) unsigned NOT NULL,
+ `description` varchar(255) CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='(*15) CLAVE DE RÉGIMEN ESPECIAL O TRASCENDENCIA(Asientos) REPERCUTIDO - DEVENGADO (477)';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `creditClassification`
+--
+
+DROP TABLE IF EXISTS `creditClassification`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `creditClassification` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `client` int(11) NOT NULL,
+ `dateStart` date NOT NULL,
+ `dateEnd` date DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `creditClassifClientFk_idx` (`client`),
+ KEY `creditClassifdateEnd_idx` (`dateEnd`),
+ CONSTRAINT `creditClassifClientFk` FOREIGN KEY (`client`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=2589 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `vn`.`creditClassification_BEFORE_UPDATE` BEFORE UPDATE ON `creditClassification` FOR EACH ROW
+BEGIN
+ IF NEW.client <> OLD.client THEN
+ CALL util.throw('NOT_ALLOWED_CHANGE_CLIENT');
+ END IF;
+ IF NEW.dateEnd IS NOT NULL AND OLD.dateEnd IS NULL THEN
+ UPDATE vn2008.Clientes c
+ SET creditInsurance = 0 WHERE c.Id_cliente = NEW.client;
+ 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 */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+
+--
+-- Table structure for table `creditInsurance`
+--
+
+DROP TABLE IF EXISTS `creditInsurance`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `creditInsurance` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `creditClassification` int(11) DEFAULT NULL,
+ `credit` int(11) DEFAULT NULL,
+ `creationDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `grade` tinyint(1) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `CreditInsurance_Fk1_idx` (`creditClassification`),
+ CONSTRAINT `CreditInsurance_Fk1` FOREIGN KEY (`creditClassification`) REFERENCES `creditClassification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=1624 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalla los clientes que tienen seguro de credito';
+/*!40101 SET character_set_client = @saved_cs_client */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `vn`.`creditInsurance_AFTER_INSERT` AFTER INSERT ON `creditInsurance` FOR EACH ROW
+BEGIN
+ UPDATE vn2008.Clientes c
+ JOIN vn.creditClassification cc ON cc.client = c.Id_Cliente
+ SET creditInsurance = NEW.credit WHERE cc.id = NEW.creditClassification;
+
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+
+--
+-- Table structure for table `dailyTaskLog`
+--
+
+DROP TABLE IF EXISTS `dailyTaskLog`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `dailyTaskLog` (
+ `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `deliveryError`
+--
+
+DROP TABLE IF EXISTS `deliveryError`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `deliveryError` (
+ `ticket` int(11) NOT NULL,
+ `description` varchar(255) CHARACTER SET latin1 NOT NULL,
+ `worker` int(11) NOT NULL,
+ `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ KEY `errorTickets_idx` (`ticket`),
+ KEY `errorWorker_idx` (`worker`),
+ CONSTRAINT `errorTickets` FOREIGN KEY (`ticket`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE NO ACTION ON UPDATE NO ACTION,
+ CONSTRAINT `errorWorker` FOREIGN KEY (`worker`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) 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 */;
+
+--
+-- Temporary view structure for view `deliveryMethod`
+--
+
+DROP TABLE IF EXISTS `deliveryMethod`;
+/*!50001 DROP VIEW IF EXISTS `deliveryMethod`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `deliveryMethod` AS SELECT
+ 1 AS `id`,
+ 1 AS `code`,
+ 1 AS `description`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `ediGenus`
+--
+
+DROP TABLE IF EXISTS `ediGenus`;
+/*!50001 DROP VIEW IF EXISTS `ediGenus`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ediGenus` AS SELECT
+ 1 AS `id`,
+ 1 AS `latinGenusName`,
+ 1 AS `entried`,
+ 1 AS `dued`,
+ 1 AS `modified`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `ediSpecie`
+--
+
+DROP TABLE IF EXISTS `ediSpecie`;
+/*!50001 DROP VIEW IF EXISTS `ediSpecie`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ediSpecie` AS SELECT
+ 1 AS `id`,
+ 1 AS `genusFk`,
+ 1 AS `latinSpeciesName`,
+ 1 AS `entried`,
+ 1 AS `dued`,
+ 1 AS `modified`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `entry`
+--
+
+DROP TABLE IF EXISTS `entry`;
+/*!50001 DROP VIEW IF EXISTS `entry`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `entry` AS SELECT
+ 1 AS `id`,
+ 1 AS `supplierFk`,
+ 1 AS `ref`,
+ 1 AS `isInventory`,
+ 1 AS `isConfirmed`,
+ 1 AS `isOrdered`,
+ 1 AS `isRaid`,
+ 1 AS `commission`,
+ 1 AS `created`,
+ 1 AS `evaNotes`,
+ 1 AS `travelFk`,
+ 1 AS `currencyFk`,
+ 1 AS `companyFk`,
+ 1 AS `gestDocFk`,
+ 1 AS `invoiceReceivedFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `entryLog`
+--
+
+DROP TABLE IF EXISTS `entryLog`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `entryLog` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `originFk` int(11) NOT NULL,
+ `userFk` int(10) unsigned NOT NULL,
+ `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
+ `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
+ `description` text COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `userFk` (`userFk`),
+ KEY `logEntry_ibfk_1` (`originFk`),
+ CONSTRAINT `entryLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `entryLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
+) ENGINE=InnoDB AUTO_INCREMENT=21666 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `especialPrice`
+--
+
+DROP TABLE IF EXISTS `especialPrice`;
+/*!50001 DROP VIEW IF EXISTS `especialPrice`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `especialPrice` AS SELECT
+ 1 AS `id`,
+ 1 AS `clientFk`,
+ 1 AS `itemFk`,
+ 1 AS `value`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `excuse`
+--
+
+DROP TABLE IF EXISTS `excuse`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `excuse` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `txt` varchar(255) CHARACTER SET latin1 NOT NULL,
+ `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `expedition`
+--
+
+DROP TABLE IF EXISTS `expedition`;
+/*!50001 DROP VIEW IF EXISTS `expedition`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `expedition` AS SELECT
+ 1 AS `id`,
+ 1 AS `agency`,
+ 1 AS `agencyFk`,
+ 1 AS `ticket`,
+ 1 AS `ticketFk`,
+ 1 AS `isBox`,
+ 1 AS `printingTime`,
+ 1 AS `item`,
+ 1 AS `itemFk`,
+ 1 AS `counter`,
+ 1 AS `checked`,
+ 1 AS `workerFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `expence`
+--
+
+DROP TABLE IF EXISTS `expence`;
+/*!50001 DROP VIEW IF EXISTS `expence`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `expence` AS SELECT
+ 1 AS `id`,
+ 1 AS `taxTypeFk`,
+ 1 AS `name`,
+ 1 AS `isWithheld`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `grant`
+--
+
+DROP TABLE IF EXISTS `grant`;
+/*!50001 DROP VIEW IF EXISTS `grant`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `grant` AS SELECT
+ 1 AS `group`,
+ 1 AS `worker`,
+ 1 AS `company`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `grantGroup`
+--
+
+DROP TABLE IF EXISTS `grantGroup`;
+/*!50001 DROP VIEW IF EXISTS `grantGroup`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `grantGroup` AS SELECT
+ 1 AS `id`,
+ 1 AS `description`,
+ 1 AS `observationType`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `greuge`
+--
+
+DROP TABLE IF EXISTS `greuge`;
+/*!50001 DROP VIEW IF EXISTS `greuge`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `greuge` AS SELECT
+ 1 AS `id`,
+ 1 AS `clientFk`,
+ 1 AS `description`,
+ 1 AS `amount`,
+ 1 AS `shipped`,
+ 1 AS `created`,
+ 1 AS `greugeTypeFk`,
+ 1 AS `ticketFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `greugeType`
+--
+
+DROP TABLE IF EXISTS `greugeType`;
+/*!50001 DROP VIEW IF EXISTS `greugeType`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `greugeType` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `ink`
+--
+
+DROP TABLE IF EXISTS `ink`;
+/*!50001 DROP VIEW IF EXISTS `ink`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ink` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `picture`,
+ 1 AS `showOrder`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `inkI18n`
+--
+
+DROP TABLE IF EXISTS `inkI18n`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `inkI18n` (
+ `inkFk` char(3) COLLATE utf8_unicode_ci NOT NULL,
+ `lang` char(2) CHARACTER SET utf8 NOT NULL,
+ `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`inkFk`,`lang`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `inkL10n`
+--
+
+DROP TABLE IF EXISTS `inkL10n`;
+/*!50001 DROP VIEW IF EXISTS `inkL10n`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `inkL10n` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `intrastat`
+--
+
+DROP TABLE IF EXISTS `intrastat`;
+/*!50001 DROP VIEW IF EXISTS `intrastat`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `intrastat` AS SELECT
+ 1 AS `id`,
+ 1 AS `description`,
+ 1 AS `taxGroupFk`,
+ 1 AS `taxCodeFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `invoiceCorrection`
+--
+
+DROP TABLE IF EXISTS `invoiceCorrection`;
+/*!50001 DROP VIEW IF EXISTS `invoiceCorrection`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `invoiceCorrection` AS SELECT
+ 1 AS `correctingFk`,
+ 1 AS `correctedFk`,
+ 1 AS `cplusRectificationTypeFk`,
+ 1 AS `cplusInvoiceType477Fk`,
+ 1 AS `invoiceCorrectionTypeFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `invoiceCorrectionDataSource`
+--
+
+DROP TABLE IF EXISTS `invoiceCorrectionDataSource`;
+/*!50001 DROP VIEW IF EXISTS `invoiceCorrectionDataSource`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `invoiceCorrectionDataSource` AS SELECT
+ 1 AS `itemFk`,
+ 1 AS `quantity`,
+ 1 AS `concept`,
+ 1 AS `price`,
+ 1 AS `discount`,
+ 1 AS `refFk`,
+ 1 AS `saleFk`,
+ 1 AS `shipped`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `invoiceCorrectionType`
+--
+
+DROP TABLE IF EXISTS `invoiceCorrectionType`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `invoiceCorrectionType` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `description_UNIQUE` (`description`)
+) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `invoiceIn`
+--
+
+DROP TABLE IF EXISTS `invoiceIn`;
+/*!50001 DROP VIEW IF EXISTS `invoiceIn`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `invoiceIn` AS SELECT
+ 1 AS `id`,
+ 1 AS `serialNumber`,
+ 1 AS `serial`,
+ 1 AS `supplierFk`,
+ 1 AS `issued`,
+ 1 AS `supplierRef`,
+ 1 AS `isBooked`,
+ 1 AS `currencyFk`,
+ 1 AS `created`,
+ 1 AS `companyFk`,
+ 1 AS `docFk`,
+ 1 AS `booked`,
+ 1 AS `operated`,
+ 1 AS `cplusInvoiceType472Fk`,
+ 1 AS `cplusRectificationTypeFk`,
+ 1 AS `cplusSubjectOpFk`,
+ 1 AS `cplusTaxBreakFk`,
+ 1 AS `cplusTrascendency472Fk`,
+ 1 AS `bookEntried`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `invoiceInAwb`
+--
+
+DROP TABLE IF EXISTS `invoiceInAwb`;
+/*!50001 DROP VIEW IF EXISTS `invoiceInAwb`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `invoiceInAwb` AS SELECT
+ 1 AS `invoiceInFk`,
+ 1 AS `awbFk`,
+ 1 AS `dua`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `invoiceInEntry`
+--
+
+DROP TABLE IF EXISTS `invoiceInEntry`;
+/*!50001 DROP VIEW IF EXISTS `invoiceInEntry`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `invoiceInEntry` AS SELECT
+ 1 AS `id`,
+ 1 AS `invoiceInFk`,
+ 1 AS `entryFk`,
+ 1 AS `percentage`,
+ 1 AS `invoiceInAwbFk`,
+ 1 AS `isBooked`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `invoiceInIntrastat`
+--
+
+DROP TABLE IF EXISTS `invoiceInIntrastat`;
+/*!50001 DROP VIEW IF EXISTS `invoiceInIntrastat`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `invoiceInIntrastat` AS SELECT
+ 1 AS `invoiceInFk`,
+ 1 AS `intrastatFk`,
+ 1 AS `amount`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `invoiceInSerial`
+--
+
+DROP TABLE IF EXISTS `invoiceInSerial`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `invoiceInSerial` (
+ `code` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
+ `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `cplusTerIdNifFk` int(11) NOT NULL DEFAULT '1',
+ PRIMARY KEY (`code`),
+ KEY `InvoiceInSerial_Fk1_idx` (`cplusTerIdNifFk`),
+ CONSTRAINT `InvoiceInSerial_Fk1` FOREIGN KEY (`cplusTerIdNifFk`) REFERENCES `cplusTerIdNif` (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `invoiceInTax`
+--
+
+DROP TABLE IF EXISTS `invoiceInTax`;
+/*!50001 DROP VIEW IF EXISTS `invoiceInTax`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `invoiceInTax` AS SELECT
+ 1 AS `id`,
+ 1 AS `invoiceInFk`,
+ 1 AS `taxCodeFk`,
+ 1 AS `taxableBase`,
+ 1 AS `expenceFk`,
+ 1 AS `foreignValue`,
+ 1 AS `created`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `invoiceOut`
+--
+
+DROP TABLE IF EXISTS `invoiceOut`;
+/*!50001 DROP VIEW IF EXISTS `invoiceOut`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `invoiceOut` AS SELECT
+ 1 AS `id`,
+ 1 AS `ref`,
+ 1 AS `serial`,
+ 1 AS `issued`,
+ 1 AS `amount`,
+ 1 AS `clientFk`,
+ 1 AS `created`,
+ 1 AS `companyFk`,
+ 1 AS `dued`,
+ 1 AS `booked`,
+ 1 AS `cplusInvoiceType477Fk`,
+ 1 AS `cplusTaxBreakFk`,
+ 1 AS `cplusSubjectOpFk`,
+ 1 AS `cplusTrascendency477Fk`,
+ 1 AS `pdf`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `invoiceOutExpence`
+--
+
+DROP TABLE IF EXISTS `invoiceOutExpence`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `invoiceOutExpence` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `invoiceOutFk` int(10) unsigned NOT NULL,
+ `amount` decimal(10,2) NOT NULL DEFAULT '0.00',
+ `expenceFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
+ `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `invoiceOutExpence_restriccion` (`expenceFk`,`invoiceOutFk`),
+ KEY `invoiceOutExpence_FK_1_idx` (`invoiceOutFk`),
+ KEY `invoiceOutExpence_FK_2_idx` (`expenceFk`),
+ CONSTRAINT `invoiceOutExpence_FK_1` FOREIGN KEY (`invoiceOutFk`) REFERENCES `vn2008`.`Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `invoiceOutExpence_FK_2` FOREIGN KEY (`expenceFk`) REFERENCES `vn2008`.`Gastos` (`Id_Gasto`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=41920 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Desglosa la base imponible de una factura en funcion del tipo de gasto/venta';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `invoiceOutSerial`
+--
+
+DROP TABLE IF EXISTS `invoiceOutSerial`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `invoiceOutSerial` (
+ `code` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
+ `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `isTaxed` tinyint(1) NOT NULL DEFAULT '1',
+ `taxAreaFk` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'NATIONAL',
+ `isCEE` tinyint(1) NOT NULL DEFAULT '0',
+ `cplusInvoiceType477Fk` int(10) unsigned DEFAULT '1',
+ PRIMARY KEY (`code`),
+ KEY `taxAreaFk_idx` (`taxAreaFk`),
+ CONSTRAINT `invoiceOutSerial_ibfk_1` FOREIGN KEY (`taxAreaFk`) REFERENCES `taxArea` (`code`) ON DELETE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `invoiceOutTax`
+--
+
+DROP TABLE IF EXISTS `invoiceOutTax`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `invoiceOutTax` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `invoiceOutFk` int(10) unsigned NOT NULL,
+ `taxableBase` decimal(10,2) NOT NULL,
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `vat` decimal(10,2) NOT NULL DEFAULT '0.00',
+ `pgcFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0000000000',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `invoiceOutTax_Resctriccion` (`invoiceOutFk`,`pgcFk`),
+ KEY `invoiceOutFk_idx` (`invoiceOutFk`),
+ KEY `pgcFk` (`pgcFk`),
+ CONSTRAINT `invoiceOutFk` FOREIGN KEY (`invoiceOutFk`) REFERENCES `vn2008`.`Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `invoiceOutTax_ibfk_1` FOREIGN KEY (`pgcFk`) REFERENCES `pgc` (`code`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=843108 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `item`
+--
+
+DROP TABLE IF EXISTS `item`;
+/*!50001 DROP VIEW IF EXISTS `item`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `item` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `typeFk`,
+ 1 AS `size`,
+ 1 AS `inkFk`,
+ 1 AS `category`,
+ 1 AS `stems`,
+ 1 AS `originFk`,
+ 1 AS `description`,
+ 1 AS `producerFk`,
+ 1 AS `intrastatFk`,
+ 1 AS `isOnOffer`,
+ 1 AS `expenceFk`,
+ 1 AS `isBargain`,
+ 1 AS `comment`,
+ 1 AS `relevancy`,
+ 1 AS `image`,
+ 1 AS `taxClassFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `itemBarcode`
+--
+
+DROP TABLE IF EXISTS `itemBarcode`;
+/*!50001 DROP VIEW IF EXISTS `itemBarcode`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `itemBarcode` AS SELECT
+ 1 AS `id`,
+ 1 AS `itemFk`,
+ 1 AS `code`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `itemBotanical`
+--
+
+DROP TABLE IF EXISTS `itemBotanical`;
+/*!50001 DROP VIEW IF EXISTS `itemBotanical`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `itemBotanical` AS SELECT
+ 1 AS `itemFk`,
+ 1 AS `botanical`,
+ 1 AS `genusFk`,
+ 1 AS `specieFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `itemBotanicalWithGenus`
+--
+
+DROP TABLE IF EXISTS `itemBotanicalWithGenus`;
+/*!50001 DROP VIEW IF EXISTS `itemBotanicalWithGenus`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `itemBotanicalWithGenus` AS SELECT
+ 1 AS `itemFk`,
+ 1 AS `ediBotanic`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `itemCategory`
+--
+
+DROP TABLE IF EXISTS `itemCategory`;
+/*!50001 DROP VIEW IF EXISTS `itemCategory`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `itemCategory` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `display`,
+ 1 AS `color`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `itemCategoryI18n`
+--
+
+DROP TABLE IF EXISTS `itemCategoryI18n`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `itemCategoryI18n` (
+ `categoryFk` int(10) unsigned NOT NULL,
+ `lang` char(2) CHARACTER SET utf8 NOT NULL,
+ `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`categoryFk`,`lang`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `itemCategoryL10n`
+--
+
+DROP TABLE IF EXISTS `itemCategoryL10n`;
+/*!50001 DROP VIEW IF EXISTS `itemCategoryL10n`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `itemCategoryL10n` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `itemConversor`
+--
+
+DROP TABLE IF EXISTS `itemConversor`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `itemConversor` (
+ `espItemFk` int(11) NOT NULL,
+ `genItemFk` int(11) DEFAULT NULL,
+ PRIMARY KEY (`espItemFk`),
+ KEY `itemConversor_fk2_idx` (`genItemFk`),
+ CONSTRAINT `itemConversor_fk1` FOREIGN KEY (`espItemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `itemConversor_fk2` FOREIGN KEY (`genItemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona los item específicos con los genéricos';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `itemPlacement`
+--
+
+DROP TABLE IF EXISTS `itemPlacement`;
+/*!50001 DROP VIEW IF EXISTS `itemPlacement`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `itemPlacement` AS SELECT
+ 1 AS `itemFk`,
+ 1 AS `warehouseFk`,
+ 1 AS `code`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `itemTag`
+--
+
+DROP TABLE IF EXISTS `itemTag`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `itemTag` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `itemFk` int(11) NOT NULL,
+ `tagFk` int(11) NOT NULL,
+ `value` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
+ `priority` int(2) NOT NULL DEFAULT '0',
+ PRIMARY KEY (`id`),
+ KEY `priorityItem` (`itemFk`,`priority`),
+ KEY `tagFk` (`tagFk`,`value`),
+ CONSTRAINT `itemFK` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=14178 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `itemTagArranged`
+--
+
+DROP TABLE IF EXISTS `itemTagArranged`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `itemTagArranged` (
+ `itemFk` int(11) NOT NULL,
+ `tag1` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `val1` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `tag2` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `val2` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `tag3` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `val3` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `tag4` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `val4` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `tag5` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `val5` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `tag6` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `val6` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`itemFk`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Cache de columnas de características de artículo';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `itemTagged`
+--
+
+DROP TABLE IF EXISTS `itemTagged`;
+/*!50001 DROP VIEW IF EXISTS `itemTagged`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `itemTagged` AS SELECT
+ 1 AS `itemFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `itemTaxCountry`
+--
+
+DROP TABLE IF EXISTS `itemTaxCountry`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `itemTaxCountry` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `itemFk` int(11) DEFAULT NULL,
+ `countryFk` mediumint(8) unsigned DEFAULT NULL,
+ `taxClassFk` tinyint(3) unsigned NOT NULL DEFAULT '1',
+ `effectived` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`),
+ KEY `taxClassFK_idx` (`taxClassFk`),
+ KEY `countryFK_paises_idx` (`countryFk`),
+ KEY `itemFK_Article_idx` (`itemFk`),
+ CONSTRAINT `countryFK_paises` FOREIGN KEY (`countryFk`) REFERENCES `vn2008`.`Paises` (`Id`) ON UPDATE CASCADE,
+ CONSTRAINT `itemFK_Article` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `taxClassFK_Iva_Group` FOREIGN KEY (`taxClassFk`) REFERENCES `vn2008`.`iva_group` (`iva_group_id`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=430357 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Define la clase de iva por artículo y pais';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `itemType`
+--
+
+DROP TABLE IF EXISTS `itemType`;
+/*!50001 DROP VIEW IF EXISTS `itemType`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `itemType` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `categoryFk`,
+ 1 AS `life`,
+ 1 AS `workerFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `itemTypeI18n`
+--
+
+DROP TABLE IF EXISTS `itemTypeI18n`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `itemTypeI18n` (
+ `typeFk` smallint(5) unsigned NOT NULL,
+ `lang` char(2) CHARACTER SET utf8 NOT NULL,
+ `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`typeFk`,`lang`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `itemTypeL10n`
+--
+
+DROP TABLE IF EXISTS `itemTypeL10n`;
+/*!50001 DROP VIEW IF EXISTS `itemTypeL10n`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `itemTypeL10n` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `itemVerdecora`
+--
+
+DROP TABLE IF EXISTS `itemVerdecora`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `itemVerdecora` (
+ `itemFk` int(11) NOT NULL,
+ `codin` int(11) DEFAULT NULL,
+ PRIMARY KEY (`itemFk`),
+ CONSTRAINT `itemVerdecora_fk1` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona nuestros articulos con los de Verdecora';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `mail`
+--
+
+DROP TABLE IF EXISTS `mail`;
+/*!50001 DROP VIEW IF EXISTS `mail`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `mail` AS SELECT
+ 1 AS `id`,
+ 1 AS `senderFk`,
+ 1 AS `recipientFk`,
+ 1 AS `sender`,
+ 1 AS `replyTo`,
+ 1 AS `subject`,
+ 1 AS `body`,
+ 1 AS `plainTextBody`,
+ 1 AS `attachment`,
+ 1 AS `creationDate`,
+ 1 AS `sent`,
+ 1 AS `status`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `mailTemplates`
+--
+
+DROP TABLE IF EXISTS `mailTemplates`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `mailTemplates` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(50) CHARACTER SET utf8 NOT NULL,
+ `attachmentPath` text CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`id`)
+) 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 `manaSpellers`
+--
+
+DROP TABLE IF EXISTS `manaSpellers`;
+/*!50001 DROP VIEW IF EXISTS `manaSpellers`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `manaSpellers` AS SELECT
+ 1 AS `worker`,
+ 1 AS `size`,
+ 1 AS `used`,
+ 1 AS `pricesModifierRate`,
+ 1 AS `pricesModifierActivated`,
+ 1 AS `workerCode`,
+ 1 AS `firstname`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `mandate`
+--
+
+DROP TABLE IF EXISTS `mandate`;
+/*!50001 DROP VIEW IF EXISTS `mandate`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `mandate` AS SELECT
+ 1 AS `id`,
+ 1 AS `clientFk`,
+ 1 AS `companyFk`,
+ 1 AS `code`,
+ 1 AS `created`,
+ 1 AS `finished`,
+ 1 AS `mandateTypeFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `mandateType`
+--
+
+DROP TABLE IF EXISTS `mandateType`;
+/*!50001 DROP VIEW IF EXISTS `mandateType`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `mandateType` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `manuscript`
+--
+
+DROP TABLE IF EXISTS `manuscript`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `manuscript` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `code` varchar(45) CHARACTER SET utf8 NOT NULL,
+ `description` text COLLATE utf8_unicode_ci,
+ `enabled` tinyint(1) NOT NULL DEFAULT '1',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `code_UNIQUE` (`code`)
+) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `message`
+--
+
+DROP TABLE IF EXISTS `message`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `message` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `uuid` varchar(50) CHARACTER SET utf8 NOT NULL,
+ `sender` varchar(50) CHARACTER SET utf8 NOT NULL,
+ `recipient` varchar(50) CHARACTER SET utf8 NOT NULL,
+ `message` longtext CHARACTER SET utf8,
+ `sendDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`),
+ KEY `sender` (`sender`),
+ KEY `recipient` (`recipient`),
+ KEY `uuid` (`uuid`(8))
+) ENGINE=InnoDB AUTO_INCREMENT=1320500 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `messageInbox`
+--
+
+DROP TABLE IF EXISTS `messageInbox`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `messageInbox` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `uuid` varchar(50) CHARACTER SET utf8 NOT NULL,
+ `sender` varchar(50) CHARACTER SET utf8 NOT NULL,
+ `recipient` varchar(45) CHARACTER SET utf8 NOT NULL,
+ `finalRecipient` varchar(50) CHARACTER SET utf8 NOT NULL,
+ `message` longtext CHARACTER SET utf8,
+ `sendDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
+ `read` varchar(45) CHARACTER SET utf8 NOT NULL DEFAULT '0',
+ PRIMARY KEY (`id`),
+ KEY `uuid` (`uuid`(8)),
+ KEY `finalRecipient` (`finalRecipient`)
+) ENGINE=InnoDB AUTO_INCREMENT=1463317 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `movConta`
+--
+
+DROP TABLE IF EXISTS `movConta`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `movConta` (
+ `MovPosicion` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `Ejercicio` smallint(6) NOT NULL,
+ `CodigoEmpresa` smallint(6) NOT NULL,
+ `Asiento` int(11) NOT NULL,
+ `CargoAbono` varchar(1) COLLATE utf8_unicode_ci NOT NULL,
+ `CodigoCuenta` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
+ `Contrapartida` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
+ `FechaAsiento` datetime NOT NULL,
+ `TipoDocumento` varchar(6) COLLATE utf8_unicode_ci NOT NULL,
+ `DocumentoConta` varchar(9) COLLATE utf8_unicode_ci NOT NULL,
+ `Comentario` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
+ `ImporteAsiento` decimal(28,10) NOT NULL,
+ `CodigoDiario` smallint(6) NOT NULL,
+ `CodigoCanal` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
+ `CodigoActividad` varchar(1) COLLATE utf8_unicode_ci NOT NULL,
+ `FechaVencimiento` datetime DEFAULT NULL,
+ `NumeroPeriodo` smallint(6) NOT NULL,
+ `CodigoUsuario` smallint(6) NOT NULL,
+ `FechaGrabacion` datetime NOT NULL,
+ `TipoEntrada` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
+ `CodigoDepartamento` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
+ `CodigoSeccion` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
+ `CodigoDivisa` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ `ImporteCambio` decimal(28,10) NOT NULL,
+ `ImporteDivisa` decimal(28,10) NOT NULL,
+ `FactorCambio` decimal(28,10) NOT NULL,
+ `CodigoProyecto` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
+ `LibreN1` int(11) NOT NULL,
+ `LibreN2` int(11) NOT NULL,
+ `LibreA1` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
+ `LibreA2` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
+ `IdDelegacion` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
+ `OrdenMovimientos` int(11) NOT NULL,
+ `MovCartera` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `IdProcesoIME` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `TipoCarteraIME` smallint(6) NOT NULL,
+ `TipoAnaliticaIME` smallint(6) NOT NULL,
+ `StatusTraspasadoIME` tinyint(4) NOT NULL,
+ `TipoImportacionIME` tinyint(4) NOT NULL,
+ `BaseIva1` decimal(28,10) NOT NULL,
+ `PorBaseCorrectora1` decimal(28,10) NOT NULL,
+ `PorIva1` decimal(28,10) NOT NULL,
+ `CuotaIva1` decimal(28,10) NOT NULL,
+ `PorRecargoEquivalencia1` decimal(28,10) NOT NULL,
+ `RecargoEquivalencia1` decimal(28,10) NOT NULL,
+ `CodigoTransaccion1` tinyint(4) NOT NULL,
+ `BaseIva2` decimal(28,10) NOT NULL,
+ `PorBaseCorrectora2` decimal(28,10) NOT NULL,
+ `PorIva2` decimal(28,10) NOT NULL,
+ `CuotaIva2` decimal(28,10) NOT NULL,
+ `PorRecargoEquivalencia2` decimal(28,10) NOT NULL,
+ `RecargoEquivalencia2` decimal(28,10) NOT NULL,
+ `CodigoTransaccion2` tinyint(4) NOT NULL,
+ `BaseIva3` decimal(28,10) NOT NULL,
+ `PorBaseCorrectora3` decimal(28,10) NOT NULL,
+ `PorIva3` decimal(28,10) NOT NULL,
+ `CuotaIva3` decimal(28,10) NOT NULL,
+ `PorRecargoEquivalencia3` decimal(28,10) NOT NULL,
+ `RecargoEquivalencia3` decimal(28,10) NOT NULL,
+ `CodigoTransaccion3` tinyint(4) NOT NULL,
+ `baseIva4` decimal(28,10) NOT NULL,
+ `PorBaseCorrectora4` decimal(28,10) NOT NULL,
+ `PorIva4` decimal(28,10) NOT NULL,
+ `CuotaIva4` decimal(28,10) NOT NULL,
+ `PorRecargoEquivalencia4` decimal(28,10) NOT NULL,
+ `RecargoEquivalencia4` decimal(28,10) NOT NULL,
+ `CodigoTransaccion4` tinyint(4) NOT NULL,
+ `Año` smallint(6) NOT NULL,
+ `Serie` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
+ `Factura` int(11) NOT NULL,
+ `SuFacturaNo` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
+ `FechaFactura` datetime DEFAULT NULL,
+ `ImporteFactura` decimal(28,10) NOT NULL,
+ `TipoFactura` varchar(1) COLLATE utf8_unicode_ci NOT NULL,
+ `CodigoCuentaFactura` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
+ `CifDni` varchar(13) COLLATE utf8_unicode_ci NOT NULL,
+ `Nombre` varchar(35) COLLATE utf8_unicode_ci NOT NULL,
+ `CodigoRetencion` smallint(6) NOT NULL,
+ `BaseRetencion` decimal(28,10) NOT NULL,
+ `PorRetencion` decimal(28,10) NOT NULL,
+ `ImporteRetencion` decimal(28,10) NOT NULL,
+ `AbonoIva` smallint(6) NOT NULL,
+ `CodigoActividadF` varchar(1) COLLATE utf8_unicode_ci NOT NULL,
+ `Intracomunitaria` smallint(6) NOT NULL,
+ `CodigoTerritorio` smallint(6) NOT NULL,
+ `SiglaNacion` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
+ `RetencionInformativa` smallint(6) NOT NULL,
+ `EjercicioFacturaOriginal` smallint(6) NOT NULL,
+ `SerieFacturaOriginal` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
+ `NumeroFacturaOriginal` int(11) NOT NULL,
+ `EjercicioFactura` smallint(6) NOT NULL,
+ `CobroPagoRetencion` varchar(1) COLLATE utf8_unicode_ci NOT NULL,
+ `FechaOperacion` datetime DEFAULT NULL,
+ `Exclusion347` smallint(6) NOT NULL,
+ `MovIdentificadorIME` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `Previsiones` varchar(1) COLLATE utf8_unicode_ci NOT NULL,
+ `MantenerAsiento` tinyint(4) NOT NULL,
+ `OrdenMovIME` smallint(6) NOT NULL,
+ `Metalico347` smallint(6) NOT NULL,
+ `ClaveOperacionFactura_` varchar(1) COLLATE utf8_unicode_ci NOT NULL,
+ `SerieAgrupacion_` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
+ `NumeroFacturaInicial_` int(11) NOT NULL,
+ `NumeroFacturaFinal_` int(11) NOT NULL,
+ `IdAsientoExterno` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `IdDiarioExterno` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
+ `IdFacturaExterno` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `IdMovimiento` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
+ `IdCuadre` smallint(6) NOT NULL,
+ `FechaCuadre` datetime NOT NULL,
+ `TipoCuadre` varchar(4) COLLATE utf8_unicode_ci NOT NULL,
+ `AgrupacionCuadre` int(11) NOT NULL,
+ `StatusSaldo` smallint(6) NOT NULL,
+ `StatusConciliacion` smallint(6) NOT NULL,
+ `CodigoConciliacion` int(11) NOT NULL,
+ `FechaConciliacion` datetime DEFAULT NULL,
+ `TipoConciliacion` smallint(6) NOT NULL,
+ `IndicadorContaBanco` varchar(1) COLLATE utf8_unicode_ci NOT NULL,
+ `Descripcion3` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
+ `Descripcion4` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
+ `Descripcion5` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
+ `Descripcion6` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
+ `Descripcion7` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
+ `Descripcion8` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `Descripcion9` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `Descripcion2` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
+ `Descripcion1` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
+ `Punteo1` smallint(6) NOT NULL,
+ `Punteo9` smallint(6) NOT NULL,
+ `Punteo8` smallint(6) NOT NULL,
+ `Punteo7` smallint(6) NOT NULL,
+ `Punteo6` smallint(6) NOT NULL,
+ `Punteo5` smallint(6) NOT NULL,
+ `Punteo4` smallint(6) NOT NULL,
+ `Punteo3` smallint(6) NOT NULL,
+ `Punteo2` smallint(6) NOT NULL,
+ `CodigoIva1` smallint(6) NOT NULL,
+ `CodigoIva2` smallint(6) NOT NULL,
+ `CodigoIva3` smallint(6) NOT NULL,
+ `CodigoIva4` smallint(6) NOT NULL,
+ `CriterioIva` tinyint(4) NOT NULL,
+ `FechaMaxVencimiento` datetime DEFAULT NULL,
+ `TipoCriterioCaja` tinyint(4) NOT NULL,
+ `MovFacturaOrigenIME` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `IdFacturaExternoFinal` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `IdFacturaExternoInicial` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `IdFacturaExternoOriginal` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `NumFacturasExternoAgrupacion` int(11) NOT NULL,
+ `CodigoMedioCobro` varchar(1) COLLATE utf8_unicode_ci NOT NULL,
+ `MedioCobro` varchar(31) COLLATE utf8_unicode_ci NOT NULL,
+ `IvaDeducible1` smallint(6) NOT NULL,
+ `IvaDeducible2` smallint(6) NOT NULL,
+ `IvaDeducible3` smallint(6) NOT NULL,
+ `IvaDeducible4` smallint(6) NOT NULL,
+ `TipoRectificativa` smallint(6) NOT NULL,
+ `FechaFacturaOriginal` datetime DEFAULT NULL,
+ `BaseImponibleOriginal` decimal(28,10) NOT NULL,
+ `CuotaIvaOriginal` decimal(28,10) NOT NULL,
+ `ClaseAbonoRectificativas` smallint(6) NOT NULL,
+ `RecargoEquivalenciaOriginal` decimal(28,10) NOT NULL,
+ `ObjetoFactura` varchar(500) COLLATE utf8_unicode_ci NOT NULL,
+ `enlazado` tinyint(1) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `movement`
+--
+
+DROP TABLE IF EXISTS `movement`;
+/*!50001 DROP VIEW IF EXISTS `movement`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `movement` AS SELECT
+ 1 AS `id`,
+ 1 AS `item`,
+ 1 AS `ticket`,
+ 1 AS `concept`,
+ 1 AS `amount`,
+ 1 AS `quantity`,
+ 1 AS `price`,
+ 1 AS `discount`,
+ 1 AS `cost`,
+ 1 AS `reservado`,
+ 1 AS `od`,
+ 1 AS `priceFixed`,
+ 1 AS `lastUpdate`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `noticeCategory`
+--
+
+DROP TABLE IF EXISTS `noticeCategory`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `noticeCategory` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `keyName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `subject` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `description` text COLLATE utf8_unicode_ci,
+ `isEnabled` tinyint(1) NOT NULL DEFAULT '1',
+ `requiredRole` int(11) NOT NULL DEFAULT '1',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `keyName_UNIQUE` (`keyName`)
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `noticeSubscription`
+--
+
+DROP TABLE IF EXISTS `noticeSubscription`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `noticeSubscription` (
+ `noticeCategoryFk` int(11) NOT NULL DEFAULT '0',
+ `userFk` int(10) unsigned NOT NULL DEFAULT '0',
+ PRIMARY KEY (`noticeCategoryFk`,`userFk`),
+ KEY `noticeSubscription_ibfk_2` (`userFk`),
+ CONSTRAINT `noticeSubscription_ibfk_1` FOREIGN KEY (`noticeCategoryFk`) REFERENCES `noticeCategory` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `noticeSubscription_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `observationType`
+--
+
+DROP TABLE IF EXISTS `observationType`;
+/*!50001 DROP VIEW IF EXISTS `observationType`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `observationType` AS SELECT
+ 1 AS `id`,
+ 1 AS `description`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `origin`
+--
+
+DROP TABLE IF EXISTS `origin`;
+/*!50001 DROP VIEW IF EXISTS `origin`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `origin` AS SELECT
+ 1 AS `id`,
+ 1 AS `code`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `originI18n`
+--
+
+DROP TABLE IF EXISTS `originI18n`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `originI18n` (
+ `originFk` tinyint(2) unsigned NOT NULL,
+ `lang` char(2) CHARACTER SET utf8 NOT NULL,
+ `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`originFk`,`lang`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `originL10n`
+--
+
+DROP TABLE IF EXISTS `originL10n`;
+/*!50001 DROP VIEW IF EXISTS `originL10n`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `originL10n` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `outgoingInvoice`
+--
+
+DROP TABLE IF EXISTS `outgoingInvoice`;
+/*!50001 DROP VIEW IF EXISTS `outgoingInvoice`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `outgoingInvoice` AS SELECT
+ 1 AS `id`,
+ 1 AS `serie`,
+ 1 AS `dateInvoice`,
+ 1 AS `total`,
+ 1 AS `dueDate`,
+ 1 AS `bank`,
+ 1 AS `client`,
+ 1 AS `remittance`,
+ 1 AS `remit`,
+ 1 AS `worker`,
+ 1 AS `creationDate`,
+ 1 AS `company`,
+ 1 AS `liquidacion?`,
+ 1 AS `isPdf`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `outgoingInvoiceVat`
+--
+
+DROP TABLE IF EXISTS `outgoingInvoiceVat`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `outgoingInvoiceVat` (
+ `outgoingInvoice` mediumint(8) NOT NULL,
+ `taxBase` decimal(12,2) DEFAULT NULL,
+ `equalizationTax` decimal(12,2) DEFAULT NULL,
+ `Vat` decimal(12,2) DEFAULT NULL,
+ PRIMARY KEY (`outgoingInvoice`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `package`
+--
+
+DROP TABLE IF EXISTS `package`;
+/*!50001 DROP VIEW IF EXISTS `package`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `package` AS SELECT
+ 1 AS `id`,
+ 1 AS `volume`,
+ 1 AS `width`,
+ 1 AS `height`,
+ 1 AS `depth`,
+ 1 AS `isPackageReturnable`,
+ 1 AS `created`,
+ 1 AS `itemFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `payMethod`
+--
+
+DROP TABLE IF EXISTS `payMethod`;
+/*!50001 DROP VIEW IF EXISTS `payMethod`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `payMethod` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `pgc`
+--
+
+DROP TABLE IF EXISTS `pgc`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `pgc` (
+ `code` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
+ `rate` decimal(10,2) NOT NULL,
+ `name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `cplusTaxBreakFk` int(10) unsigned DEFAULT '1',
+ `mod340` tinyint(1) NOT NULL DEFAULT '0',
+ `mod347` tinyint(1) NOT NULL DEFAULT '0',
+ `cplusTrascendency477Fk` int(10) unsigned DEFAULT '1',
+ PRIMARY KEY (`code`),
+ KEY `pgc_fk1_idx` (`cplusTaxBreakFk`),
+ KEY `pgc_fk2_idx` (`cplusTrascendency477Fk`),
+ CONSTRAINT `pgc_fk1` FOREIGN KEY (`cplusTaxBreakFk`) REFERENCES `cplusTaxBreak` (`id`) ON UPDATE CASCADE,
+ CONSTRAINT `pgc_fk2` FOREIGN KEY (`cplusTrascendency477Fk`) REFERENCES `cplusTrascendency477` (`id`) ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Plan General Contable';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `pgcEqu`
+--
+
+DROP TABLE IF EXISTS `pgcEqu`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `pgcEqu` (
+ `vatFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Cuenta de IVA',
+ `equFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Cuenta de recargo de equivalencia',
+ PRIMARY KEY (`vatFk`,`equFk`),
+ KEY `pgcEqu_fk2_idx` (`equFk`),
+ CONSTRAINT `pgcEqu_fk1` FOREIGN KEY (`vatFk`) REFERENCES `pgc` (`code`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `pgcEqu_fk2` FOREIGN KEY (`equFk`) REFERENCES `pgc` (`code`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Recoge las cuentas contables con recargo de equivalencia e identifica a la que corresponde al iva y la que corresponde al recargo';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `plantpassport`
+--
+
+DROP TABLE IF EXISTS `plantpassport`;
+/*!50001 DROP VIEW IF EXISTS `plantpassport`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `plantpassport` AS SELECT
+ 1 AS `producerFk`,
+ 1 AS `plantpassportAuthorityFk`,
+ 1 AS `number`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `plantpassportAuthority`
+--
+
+DROP TABLE IF EXISTS `plantpassportAuthority`;
+/*!50001 DROP VIEW IF EXISTS `plantpassportAuthority`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `plantpassportAuthority` AS SELECT
+ 1 AS `id`,
+ 1 AS `denomination`,
+ 1 AS `countryFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `postCode`
+--
+
+DROP TABLE IF EXISTS `postCode`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `postCode` (
+ `code` varchar(10) CHARACTER SET latin1 NOT NULL,
+ `townFk` int(11) NOT NULL,
+ `geoFk` int(11) DEFAULT NULL,
+ PRIMARY KEY (`code`),
+ KEY `postCode_ix1` (`townFk`),
+ KEY `postCode_ix2` (`geoFk`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `priceFixed`
+--
+
+DROP TABLE IF EXISTS `priceFixed`;
+/*!50001 DROP VIEW IF EXISTS `priceFixed`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `priceFixed` AS SELECT
+ 1 AS `itemFk`,
+ 1 AS `rate0`,
+ 1 AS `rate1`,
+ 1 AS `rate2`,
+ 1 AS `rate3`,
+ 1 AS `started`,
+ 1 AS `ended`,
+ 1 AS `bonus`,
+ 1 AS `warehouseFk`,
+ 1 AS `created`,
+ 1 AS `id`,
+ 1 AS `grouping`,
+ 1 AS `packing`,
+ 1 AS `box`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `printServerQueue`
+--
+
+DROP TABLE IF EXISTS `printServerQueue`;
+/*!50001 DROP VIEW IF EXISTS `printServerQueue`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `printServerQueue` AS SELECT
+ 1 AS `id`,
+ 1 AS `printerFk`,
+ 1 AS `priorityFk`,
+ 1 AS `reportFk`,
+ 1 AS `statusFk`,
+ 1 AS `started`,
+ 1 AS `finished`,
+ 1 AS `param1`,
+ 1 AS `workerFk`,
+ 1 AS `param2`,
+ 1 AS `param3`,
+ 1 AS `error`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `printingQueue`
+--
+
+DROP TABLE IF EXISTS `printingQueue`;
+/*!50001 DROP VIEW IF EXISTS `printingQueue`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `printingQueue` AS SELECT
+ 1 AS `id`,
+ 1 AS `printer`,
+ 1 AS `priority`,
+ 1 AS `report`,
+ 1 AS `state`,
+ 1 AS `startingTime`,
+ 1 AS `endingTime`,
+ 1 AS `text`,
+ 1 AS `worker`,
+ 1 AS `text2`,
+ 1 AS `text3`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `producer`
+--
+
+DROP TABLE IF EXISTS `producer`;
+/*!50001 DROP VIEW IF EXISTS `producer`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `producer` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `province`
+--
+
+DROP TABLE IF EXISTS `province`;
+/*!50001 DROP VIEW IF EXISTS `province`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `province` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `countryFk`,
+ 1 AS `geoFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `receipt`
+--
+
+DROP TABLE IF EXISTS `receipt`;
+/*!50001 DROP VIEW IF EXISTS `receipt`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `receipt` AS SELECT
+ 1 AS `Id`,
+ 1 AS `invoiceFk`,
+ 1 AS `amountPaid`,
+ 1 AS `amountUnpaid`,
+ 1 AS `payed`,
+ 1 AS `workerFk`,
+ 1 AS `bankFk`,
+ 1 AS `clientFk`,
+ 1 AS `created`,
+ 1 AS `companyFk`,
+ 1 AS `isConciliate`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `referenceRate`
+--
+
+DROP TABLE IF EXISTS `referenceRate`;
+/*!50001 DROP VIEW IF EXISTS `referenceRate`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `referenceRate` AS SELECT
+ 1 AS `currencyFk`,
+ 1 AS `dated`,
+ 1 AS `value`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `role`
+--
+
+DROP TABLE IF EXISTS `role`;
+/*!50001 DROP VIEW IF EXISTS `role`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `role` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `description`,
+ 1 AS `hasLogin`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `route`
+--
+
+DROP TABLE IF EXISTS `route`;
+/*!50001 DROP VIEW IF EXISTS `route`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `route` AS SELECT
+ 1 AS `id`,
+ 1 AS `workerFk`,
+ 1 AS `created`,
+ 1 AS `vehicleFk`,
+ 1 AS `agencyFk`,
+ 1 AS `agencyModeFk`,
+ 1 AS `time`,
+ 1 AS `isOk`,
+ 1 AS `kmStart`,
+ 1 AS `kmEnd`,
+ 1 AS `started`,
+ 1 AS `finished`,
+ 1 AS `gestdocFk`,
+ 1 AS `cost`,
+ 1 AS `m3`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `routeGate`
+--
+
+DROP TABLE IF EXISTS `routeGate`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `routeGate` (
+ `deviceId` varchar(30) CHARACTER SET utf8 NOT NULL,
+ `displayText` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`deviceId`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `routeLog`
+--
+
+DROP TABLE IF EXISTS `routeLog`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `routeLog` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `originFk` int(11) NOT NULL,
+ `userFk` int(10) unsigned NOT NULL,
+ `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
+ `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
+ `description` text COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=307343 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `sale`
+--
+
+DROP TABLE IF EXISTS `sale`;
+/*!50001 DROP VIEW IF EXISTS `sale`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `sale` AS SELECT
+ 1 AS `id`,
+ 1 AS `itemFk`,
+ 1 AS `ticketFk`,
+ 1 AS `concept`,
+ 1 AS `quantity`,
+ 1 AS `price`,
+ 1 AS `discount`,
+ 1 AS `reserved`,
+ 1 AS `isPicked`,
+ 1 AS `created`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `saleComponent`
+--
+
+DROP TABLE IF EXISTS `saleComponent`;
+/*!50001 DROP VIEW IF EXISTS `saleComponent`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `saleComponent` AS SELECT
+ 1 AS `saleFk`,
+ 1 AS `componentFk`,
+ 1 AS `value`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `sms`
+--
+
+DROP TABLE IF EXISTS `sms`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `sms` (
+ `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
+ `senderFk` int(11) NOT NULL,
+ `destinationFk` int(11) DEFAULT NULL,
+ `sender` varchar(15) CHARACTER SET utf8 NOT NULL DEFAULT '693474205',
+ `destination` varchar(15) CHARACTER SET utf8 NOT NULL,
+ `message` varchar(160) COLLATE utf8_unicode_ci NOT NULL,
+ `statusCode` smallint(9) NOT NULL DEFAULT '0',
+ `status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=86360 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `smsConfig`
+--
+
+DROP TABLE IF EXISTS `smsConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `smsConfig` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `uri` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `user` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `password` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `title` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='SMS configuration parameters';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `solunionCAP`
+--
+
+DROP TABLE IF EXISTS `solunionCAP`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `solunionCAP` (
+ `creditInsurance` int(11) NOT NULL,
+ `dateStart` date NOT NULL,
+ `dateEnd` date NOT NULL,
+ `dateLeaving` date DEFAULT NULL,
+ PRIMARY KEY (`creditInsurance`,`dateStart`),
+ KEY `solunionCAPdateLeavingIdx` (`dateLeaving`),
+ CONSTRAINT `solunionCAP` FOREIGN KEY (`creditInsurance`) REFERENCES `creditInsurance` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `vn`.`solunionCAP_AFTER_INSERT` AFTER INSERT ON `solunionCAP` FOR EACH ROW
+BEGIN
+ UPDATE vn2008.Clientes c
+ JOIN creditClassification cc ON c.Id_Cliente = cc.client
+ JOIN creditInsurance ci ON ci.creditClassification = cc.id
+ SET creditInsurance = ci.credit * 2 WHERE ci.id = NEW.creditInsurance;
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `vn`.`solunionCAP_AFTER_UPDATE` AFTER UPDATE ON `solunionCAP` FOR EACH ROW
+BEGIN
+ IF NEW.dateLeaving IS NOT NULL THEN
+ UPDATE vn2008.Clientes c
+ JOIN creditClassification cc ON c.Id_Cliente = cc.client
+ JOIN creditInsurance ci ON ci.creditClassification = cc.id
+ SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance;
+ ELSE
+ UPDATE vn2008.Clientes c
+ JOIN creditClassification cc ON c.Id_Cliente = cc.client
+ JOIN creditInsurance ci ON ci.creditClassification = cc.id
+ SET creditInsurance = ci.credit * 2 WHERE ci.id = OLD.creditInsurance;
+ 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 */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `vn`.`solunionCAP_BEFORE_DELETE` BEFORE DELETE ON `solunionCAP` FOR EACH ROW
+BEGIN
+ UPDATE vn2008.Clientes c
+ JOIN creditClassification cc ON c.Id_Cliente = cc.client
+ JOIN creditInsurance ci ON ci.creditClassification = cc.id
+ SET creditInsurance = ci.credit WHERE ci.id = OLD.creditInsurance;
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+
+--
+-- Temporary view structure for view `state`
+--
+
+DROP TABLE IF EXISTS `state`;
+/*!50001 DROP VIEW IF EXISTS `state`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `state` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `order`,
+ 1 AS `alertLevel`,
+ 1 AS `code`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `stockBuyed`
+--
+
+DROP TABLE IF EXISTS `stockBuyed`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `stockBuyed` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `user` int(10) unsigned DEFAULT NULL,
+ `buyed` decimal(10,2) DEFAULT NULL,
+ `date` date DEFAULT NULL,
+ `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
+ `reserved` decimal(10,2) DEFAULT NULL,
+ `requested` decimal(10,2) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `date_UNIQUE` (`date`,`user`),
+ KEY `stockBuyed_user_idx` (`user`),
+ CONSTRAINT `stockBuyedUserFk` FOREIGN KEY (`user`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=209057 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `supplier`
+--
+
+DROP TABLE IF EXISTS `supplier`;
+/*!50001 DROP VIEW IF EXISTS `supplier`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `supplier` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `account`,
+ 1 AS `countryFk`,
+ 1 AS `nif`,
+ 1 AS `isFarmer`,
+ 1 AS `retAccount`,
+ 1 AS `commission`,
+ 1 AS `created`,
+ 1 AS `postcodeFk`,
+ 1 AS `isActive`,
+ 1 AS `street`,
+ 1 AS `city`,
+ 1 AS `provinceFk`,
+ 1 AS `postCode`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `supplierAccount`
+--
+
+DROP TABLE IF EXISTS `supplierAccount`;
+/*!50001 DROP VIEW IF EXISTS `supplierAccount`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `supplierAccount` AS SELECT
+ 1 AS `id`,
+ 1 AS `iban`,
+ 1 AS `bankEntityFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `tag`
+--
+
+DROP TABLE IF EXISTS `tag`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `tag` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(25) CHARACTER SET utf8 NOT NULL,
+ `free` tinyint(1) NOT NULL DEFAULT '1',
+ `isQuantitatif` tinyint(4) NOT NULL DEFAULT '1',
+ `sourceTable` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `unit` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=67 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Categorias para etiquetar los productos';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `tagI18n`
+--
+
+DROP TABLE IF EXISTS `tagI18n`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `tagI18n` (
+ `tagFk` int(10) unsigned NOT NULL,
+ `lang` char(2) CHARACTER SET utf8 NOT NULL,
+ `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`tagFk`,`lang`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `tagL10n`
+--
+
+DROP TABLE IF EXISTS `tagL10n`;
+/*!50001 DROP VIEW IF EXISTS `tagL10n`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `tagL10n` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `taxArea`
+--
+
+DROP TABLE IF EXISTS `taxArea`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `taxArea` (
+ `code` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`code`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `taxClass`
+--
+
+DROP TABLE IF EXISTS `taxClass`;
+/*!50001 DROP VIEW IF EXISTS `taxClass`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `taxClass` AS SELECT
+ 1 AS `id`,
+ 1 AS `description`,
+ 1 AS `code`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `taxClassCode`
+--
+
+DROP TABLE IF EXISTS `taxClassCode`;
+/*!50001 DROP VIEW IF EXISTS `taxClassCode`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `taxClassCode` AS SELECT
+ 1 AS `taxClassFk`,
+ 1 AS `effectived`,
+ 1 AS `taxCodeFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `taxCode`
+--
+
+DROP TABLE IF EXISTS `taxCode`;
+/*!50001 DROP VIEW IF EXISTS `taxCode`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `taxCode` AS SELECT
+ 1 AS `id`,
+ 1 AS `dated`,
+ 1 AS `code`,
+ 1 AS `taxTypeFk`,
+ 1 AS `rate`,
+ 1 AS `equalizationTax`,
+ 1 AS `type`,
+ 1 AS `linkFk`,
+ 1 AS `isActive`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `taxType`
+--
+
+DROP TABLE IF EXISTS `taxType`;
+/*!50001 DROP VIEW IF EXISTS `taxType`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `taxType` AS SELECT
+ 1 AS `id`,
+ 1 AS `nickname`,
+ 1 AS `serial`,
+ 1 AS `TIPOOPE`,
+ 1 AS `description`,
+ 1 AS `countryFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `ticket`
+--
+
+DROP TABLE IF EXISTS `ticket`;
+/*!50001 DROP VIEW IF EXISTS `ticket`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ticket` AS SELECT
+ 1 AS `id`,
+ 1 AS `clientFk`,
+ 1 AS `warehouseFk`,
+ 1 AS `shipped`,
+ 1 AS `landed`,
+ 1 AS `nickname`,
+ 1 AS `refFk`,
+ 1 AS `addressFk`,
+ 1 AS `isSigned`,
+ 1 AS `location`,
+ 1 AS `blocked`,
+ 1 AS `solution`,
+ 1 AS `path`,
+ 1 AS `routeFk`,
+ 1 AS `company`,
+ 1 AS `companyFk`,
+ 1 AS `agencyModeFk`,
+ 1 AS `loadingOrder`,
+ 1 AS `created`,
+ 1 AS `shipment`,
+ 1 AS `landing`,
+ 1 AS `customer`,
+ 1 AS `warehouse`,
+ 1 AS `client`,
+ 1 AS `address`,
+ 1 AS `agencyMode`,
+ 1 AS `signed`,
+ 1 AS `package`,
+ 1 AS `creationDate`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `ticketLog`
+--
+
+DROP TABLE IF EXISTS `ticketLog`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `ticketLog` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `originFk` int(11) NOT NULL,
+ `userFk` int(10) unsigned NOT NULL,
+ `action` set('insert','update','delete','select') COLLATE utf8_unicode_ci NOT NULL,
+ `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
+ `description` text COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `logTicketoriginFk` (`originFk`),
+ KEY `logTicketuserFk` (`userFk`),
+ CONSTRAINT `ticketLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `ticketLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=189204 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `ticketObservation`
+--
+
+DROP TABLE IF EXISTS `ticketObservation`;
+/*!50001 DROP VIEW IF EXISTS `ticketObservation`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ticketObservation` AS SELECT
+ 1 AS `id`,
+ 1 AS `ticketFk`,
+ 1 AS `observationTypeFk`,
+ 1 AS `description`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `ticketPackage`
+--
+
+DROP TABLE IF EXISTS `ticketPackage`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `ticketPackage` (
+ `ticket` int(11) NOT NULL,
+ `counter` int(10) unsigned NOT NULL DEFAULT '0',
+ PRIMARY KEY (`ticket`),
+ CONSTRAINT `ticketPackage_ticketFk` FOREIGN KEY (`ticket`) REFERENCES `vn2008`.`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 `ticketPackaging`
+--
+
+DROP TABLE IF EXISTS `ticketPackaging`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `ticketPackaging` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `ticketFk` int(11) NOT NULL,
+ `packagingFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
+ `quantity` int(10) DEFAULT '0',
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `pvp` double DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `ticketPackaging_fk1_idx` (`ticketFk`),
+ KEY `ticketPackaging_fk2_idx` (`packagingFk`),
+ CONSTRAINT `ticketPackaging_fk1` FOREIGN KEY (`ticketFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON UPDATE CASCADE,
+ CONSTRAINT `ticketPackaging_fk2` FOREIGN KEY (`packagingFk`) REFERENCES `vn2008`.`Cubos` (`Id_Cubo`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=2310 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `ticketState`
+--
+
+DROP TABLE IF EXISTS `ticketState`;
+/*!50001 DROP VIEW IF EXISTS `ticketState`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ticketState` AS SELECT
+ 1 AS `ticketFk`,
+ 1 AS `ticket`,
+ 1 AS `state`,
+ 1 AS `productionOrder`,
+ 1 AS `alertLevel`,
+ 1 AS `code`,
+ 1 AS `worker`,
+ 1 AS `workerFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `ticketStateToday`
+--
+
+DROP TABLE IF EXISTS `ticketStateToday`;
+/*!50001 DROP VIEW IF EXISTS `ticketStateToday`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ticketStateToday` AS SELECT
+ 1 AS `ticket`,
+ 1 AS `state`,
+ 1 AS `productionOrder`,
+ 1 AS `alertLevel`,
+ 1 AS `worker`,
+ 1 AS `code`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `ticketTracking`
+--
+
+DROP TABLE IF EXISTS `ticketTracking`;
+/*!50001 DROP VIEW IF EXISTS `ticketTracking`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ticketTracking` AS SELECT
+ 1 AS `id`,
+ 1 AS `stateFk`,
+ 1 AS `created`,
+ 1 AS `ticketFk`,
+ 1 AS `workerFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `ticketTrolley`
+--
+
+DROP TABLE IF EXISTS `ticketTrolley`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `ticketTrolley` (
+ `ticket` int(11) NOT NULL,
+ `labelCount` int(11) NOT NULL DEFAULT '0',
+ PRIMARY KEY (`ticket`),
+ CONSTRAINT `fk_ticketTrolley_vs_ticket` FOREIGN KEY (`ticket`) REFERENCES `vn2008`.`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 */;
+
+--
+-- Temporary view structure for view `time`
+--
+
+DROP TABLE IF EXISTS `time`;
+/*!50001 DROP VIEW IF EXISTS `time`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `time` AS SELECT
+ 1 AS `dated`,
+ 1 AS `period`,
+ 1 AS `month`,
+ 1 AS `year`,
+ 1 AS `day`,
+ 1 AS `week`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `town`
+--
+
+DROP TABLE IF EXISTS `town`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `town` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
+ `provinceFk` smallint(6) unsigned NOT NULL,
+ `geoFk` int(11) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `provinceFk_idx` (`provinceFk`),
+ KEY `town_ix2` (`name`),
+ CONSTRAINT `provinceFk` FOREIGN KEY (`provinceFk`) REFERENCES `vn2008`.`province` (`province_id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=55237 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `travel`
+--
+
+DROP TABLE IF EXISTS `travel`;
+/*!50001 DROP VIEW IF EXISTS `travel`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `travel` AS SELECT
+ 1 AS `id`,
+ 1 AS `shipped`,
+ 1 AS `shipmentHour`,
+ 1 AS `landed`,
+ 1 AS `landingHour`,
+ 1 AS `warehouseInFk`,
+ 1 AS `warehouseOutFk`,
+ 1 AS `agencyFk`,
+ 1 AS `ref`,
+ 1 AS `isDelivered`,
+ 1 AS `isReceived`,
+ 1 AS `m3`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `travelObservation`
+--
+
+DROP TABLE IF EXISTS `travelObservation`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `travelObservation` (
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `originFk` int(11) NOT NULL,
+ `userFk` int(11) NOT NULL,
+ `description` text COLLATE utf8_unicode_ci NOT NULL,
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de travel';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `unary`
+--
+
+DROP TABLE IF EXISTS `unary`;
+/*!50001 DROP VIEW IF EXISTS `unary`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `unary` AS SELECT
+ 1 AS `id`,
+ 1 AS `parent`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `unaryScan`
+--
+
+DROP TABLE IF EXISTS `unaryScan`;
+/*!50001 DROP VIEW IF EXISTS `unaryScan`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `unaryScan` AS SELECT
+ 1 AS `unaryFk`,
+ 1 AS `name`,
+ 1 AS `created`,
+ 1 AS `type`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `unaryScanLine`
+--
+
+DROP TABLE IF EXISTS `unaryScanLine`;
+/*!50001 DROP VIEW IF EXISTS `unaryScanLine`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `unaryScanLine` AS SELECT
+ 1 AS `id`,
+ 1 AS `code`,
+ 1 AS `created`,
+ 1 AS `unaryScanFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `unaryScanLineBuy`
+--
+
+DROP TABLE IF EXISTS `unaryScanLineBuy`;
+/*!50001 DROP VIEW IF EXISTS `unaryScanLineBuy`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `unaryScanLineBuy` AS SELECT
+ 1 AS `unaryScanLineFk`,
+ 1 AS `itemFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `unaryScanLineExpedition`
+--
+
+DROP TABLE IF EXISTS `unaryScanLineExpedition`;
+/*!50001 DROP VIEW IF EXISTS `unaryScanLineExpedition`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `unaryScanLineExpedition` AS SELECT
+ 1 AS `unaryScanLineFk`,
+ 1 AS `expeditionFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `user`
+--
+
+DROP TABLE IF EXISTS `user`;
+/*!50001 DROP VIEW IF EXISTS `user`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `user` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `password`,
+ 1 AS `role`,
+ 1 AS `active`,
+ 1 AS `recoverPass`,
+ 1 AS `lastPassChange`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `vehicle`
+--
+
+DROP TABLE IF EXISTS `vehicle`;
+/*!50001 DROP VIEW IF EXISTS `vehicle`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `vehicle` AS SELECT
+ 1 AS `id`,
+ 1 AS `numberPlate`,
+ 1 AS `tradeMark`,
+ 1 AS `model`,
+ 1 AS `companyFk`,
+ 1 AS `warehouseFk`,
+ 1 AS `description`,
+ 1 AS `m3`,
+ 1 AS `isActive`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `warehouse`
+--
+
+DROP TABLE IF EXISTS `warehouse`;
+/*!50001 DROP VIEW IF EXISTS `warehouse`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `warehouse` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `isInventory`,
+ 1 AS `isComparative`,
+ 1 AS `hasComission`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `warehouseAlias`
+--
+
+DROP TABLE IF EXISTS `warehouseAlias`;
+/*!50001 DROP VIEW IF EXISTS `warehouseAlias`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `warehouseAlias` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `worker`
+--
+
+DROP TABLE IF EXISTS `worker`;
+/*!50001 DROP VIEW IF EXISTS `worker`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `worker` AS SELECT
+ 1 AS `id`,
+ 1 AS `workerCode`,
+ 1 AS `firstName`,
+ 1 AS `name`,
+ 1 AS `userFk`,
+ 1 AS `phone`,
+ 1 AS `bossFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `workerDocument`
+--
+
+DROP TABLE IF EXISTS `workerDocument`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `workerDocument` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `worker` int(10) unsigned DEFAULT NULL,
+ `document` int(11) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `workerDocument_ibfk_1` (`worker`),
+ KEY `workerDocument_ibfk_2` (`document`),
+ CONSTRAINT `workerDocument_ibfk_1` FOREIGN KEY (`worker`) REFERENCES `vn2008`.`Trabajadores` (`user_id`) ON UPDATE CASCADE,
+ CONSTRAINT `workerDocument_ibfk_2` FOREIGN KEY (`document`) REFERENCES `vn2008`.`gestdoc` (`id`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=2332 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `workerLog`
+--
+
+DROP TABLE IF EXISTS `workerLog`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `workerLog` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `originFk` int(11) NOT NULL,
+ `userFk` int(10) unsigned NOT NULL,
+ `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL,
+ `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
+ `description` text COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `workerFk_idx` (`originFk`),
+ KEY `userFk_idx` (`userFk`),
+ CONSTRAINT `userFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
+ CONSTRAINT `workerFk` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE NO ACTION
+) ENGINE=InnoDB AUTO_INCREMENT=781 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `workerTeam`
+--
+
+DROP TABLE IF EXISTS `workerTeam`;
+/*!50001 DROP VIEW IF EXISTS `workerTeam`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `workerTeam` 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 `workerTeam_kk`
+--
+
+DROP TABLE IF EXISTS `workerTeam_kk`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `workerTeam_kk` (
+ `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=77 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `workingHours`
+--
+
+DROP TABLE IF EXISTS `workingHours`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `workingHours` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `timeIn` datetime NOT NULL,
+ `timeOut` datetime DEFAULT NULL,
+ `userId` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `user_working_hour_idx` (`userId`),
+ CONSTRAINT `user_working_hour` FOREIGN KEY (`userId`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=12912 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena horas de Entrada y de Salida del personal';
+/*!40101 SET character_set_client = @saved_cs_client */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `vn`.`workingHoursBeforeInsert` BEFORE INSERT ON `workingHours` FOR EACH ROW
+BEGIN
+ IF (SELECT COUNT(*) FROM workingHours WHERE userId = NEW.userId AND DATE(timeIn) = CURDATE()) > 0 THEN
+ CALL util.throw ('ALREADY_LOGGED');
+ 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 */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+
+--
+-- Table structure for table `zone`
+--
+
+DROP TABLE IF EXISTS `zone`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `zone` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
+ `hour` int(11) NOT NULL,
+ `warehouseFk` int(11) NOT NULL,
+ `agencyFk` int(11) NOT NULL,
+ `travelingDays` int(11) NOT NULL DEFAULT '1',
+ PRIMARY KEY (`id`,`name`),
+ UNIQUE KEY `name_UNIQUE` (`name`)
+) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `zoneCalendar`
+--
+
+DROP TABLE IF EXISTS `zoneCalendar`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `zoneCalendar` (
+ `zoneFk` int(11) NOT NULL,
+ `delivered` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`zoneFk`,`delivered`),
+ CONSTRAINT `zoneFk` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`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 `zoneGeo`
+--
+
+DROP TABLE IF EXISTS `zoneGeo`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `zoneGeo` (
+ `zoneFk` varchar(45) CHARACTER SET utf8 NOT NULL,
+ `geoFk` int(11) NOT NULL,
+ `isIncluded` tinyint(1) DEFAULT NULL,
+ PRIMARY KEY (`zoneFk`,`geoFk`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `zoneNest`
+--
+
+DROP TABLE IF EXISTS `zoneNest`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `zoneNest` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `lft` int(11) DEFAULT NULL,
+ `rgt` int(11) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=20944 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `zoneNestTree`
+--
+
+DROP TABLE IF EXISTS `zoneNestTree`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `zoneNestTree` (
+ `id` int(11) NOT NULL DEFAULT '0',
+ `name` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `lft` int(11) DEFAULT NULL,
+ `rgt` int(11) DEFAULT NULL,
+ `depth` bigint(22) NOT NULL DEFAULT '0',
+ `sons` decimal(10,0) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping events for database 'vn'
+--
+/*!50106 SET @save_time_zone= @@TIME_ZONE */ ;
+/*!50106 DROP EVENT IF EXISTS `ticketClosure` */;
+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 `ticketClosure` ON SCHEDULE EVERY 1 DAY STARTS '2017-09-18 00:30:00' ON COMPLETION NOT PRESERVE ENABLE COMMENT 'Realiza el cierre de todos los almacenes del dia actual' DO CALL ticketClosureMultiWarehouse(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 */ ;;
+DELIMITER ;
+/*!50106 SET TIME_ZONE= @save_time_zone */ ;
+
+--
+-- Dumping routines for database 'vn'
+--
+/*!50003 DROP FUNCTION IF EXISTS `agencyIsAvailable` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `agencyIsAvailable`(vAgency INT, vDate DATE, vAddress INT) RETURNS tinyint(1)
+BEGIN
+/**
+ * Comprueba si la agencia esta disponible para la fecha y
+ * dirección dadas, es decir, si es posible enviar mercancía
+ * desde al menos uno de los almacenes por la agencia, fecha
+ * y direcciones especificadas.
+ *
+ * @param vAgency Id de agencia
+ * @param vDate Fecha de recepción de mercancía
+ * @param vAddress Id consignatario, %NULL para recogida
+ * @return %TRUE si la agencia esta disponible, %FALSE en caso contrario
+ */
+ DECLARE vMaxDays INT DEFAULT DATEDIFF(vDate, CURDATE());
+ DECLARE vWday TINYINT DEFAULT WEEKDAY(vDate);
+ DECLARE vHour TINYINT DEFAULT HOUR(NOW());
+ DECLARE vProvince INT;
+ DECLARE isAvailable BOOL;
+
+ SELECT province INTO vProvince
+ FROM address
+ WHERE id = vAddress;
+
+ SELECT COUNT(*) > 0 INTO isAvailable
+ FROM agencyHour h
+ JOIN agencyMode a
+ ON a.agency = h.agency
+ WHERE (h.province = vProvince
+ OR h.province IS NULL)
+ AND (h.weekDay = vWday
+ OR h.weekDay IS NULL)
+ AND (h.substractDay < vMaxDays
+ OR (h.substractDay = vMaxDays AND h.maxHour > vHour))
+ AND a.id = vAgency;
+
+ RETURN isAvailable;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `clientGetDebt` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `clientGetDebt`(vClient INT, vDate DATE) RETURNS decimal(10,2)
+BEGIN
+/**
+ * Devuelve el saldo de un cliente.
+ *
+ * @param vClient Identificador del cliente
+ * @param vDate Fecha hasta la que tener en cuenta
+ * @return Saldo del cliente
+ */
+ DECLARE vDateEnd DATETIME;
+ DECLARE vDateIni DATETIME;
+ DECLARE vDebt DECIMAL(10,2);
+
+ SET vDate = IFNULL(vDate, CURDATE());
+
+ SET vDateIni = TIMESTAMPADD(MONTH,-2,CURDATE());
+ SET vDateEnd = TIMESTAMP(vDate, '23:59:59');
+
+ DROP TEMPORARY TABLE IF EXISTS vn2008.ticket_tmp;
+ CREATE TEMPORARY TABLE tmp.ticket
+ (INDEX (ticketFk))
+ ENGINE = MEMORY
+ SELECT id ticketFk
+ FROM ticket
+ WHERE clientFk = vClient
+ AND refFk IS NULL
+ AND shipped BETWEEN vDateIni AND vDateEnd;
+
+ CALL vn.ticketGetTotal;
+
+ SELECT IFNULL(SUM(t.amount), 0) INTO vDebt
+ FROM (
+ SELECT SUM(total) amount
+ FROM tmp.ticketTotal
+ UNION ALL
+ SELECT SUM(Entregado)
+ FROM vn2008.Recibos
+ WHERE Id_Cliente = vClient
+ AND Fechacobro > vDateEnd
+ UNION ALL
+ SELECT SUM(amount)
+ FROM bi.customer_risk r
+ WHERE customer_id = vClient
+ UNION ALL
+ SELECT CAST(-SUM(amount) / 100 AS DECIMAL(10,2))
+ FROM hedera.tpvTransaction
+ WHERE clientFk = vClient
+ AND receiptFk IS NULL
+ AND `status` = 'ok'
+ ) t;
+
+ DROP TEMPORARY TABLE
+ tmp.ticket,
+ tmp.ticketTotal;
+
+ RETURN vDebt;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `clientGetMana` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `clientGetMana`(vClient INT) RETURNS decimal(10,2)
+BEGIN
+/**
+ * Devuelve el maná del cliente.
+ *
+ * @param vClient Id del cliente
+ * @return Maná del cliente
+ */
+
+DECLARE vMana DECIMAL(10,2);
+DECLARE vFromDated DATE;
+
+SELECT max(dated) INTO vFromDated
+FROM vn.clientManaCache
+WHERE clientFk = vClient;
+
+SELECT sum(mana) INTO vMana
+ FROM
+ (
+ SELECT mana
+ FROM vn.clientManaCache
+ WHERE clientFk = vClient
+ AND dated = vFromDated
+
+ UNION ALL
+
+ SELECT s.quantity * Valor
+ 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 > vFromDated
+ AND t.clientFk = vClient
+
+ UNION ALL
+
+ SELECT - Entregado
+ FROM vn2008.Recibos r
+ JOIN vn2008.Clientes c using(Id_Cliente)
+ WHERE r.Id_Banco = 66
+ AND r.Fechacobro > vFromDated
+ AND c.Id_Cliente = vClient
+
+ UNION ALL
+
+ SELECT g.Importe
+ FROM vn2008.Greuges g
+ JOIN vn2008.Clientes c using(Id_Cliente)
+ WHERE g.Greuges_type_id = 3 -- Maná
+ AND g.Fecha > vFromDated
+ AND c.Id_Cliente = vClient
+
+ ) sub;
+
+RETURN IFNULL(vMana,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 `clientTaxArea` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `clientTaxArea`(vClientId INT, vCompanyId INT) RETURNS varchar(25) CHARSET utf8
+BEGIN
+/**
+ * Devuelve el area de un cliente,
+ * intracomunitario, extracomunitario y nacional.
+ *
+ * @param vClient Id del cliente
+ * @param vCompanyFk Compañia desde la que se factura
+ * @return Código de area
+ */
+ DECLARE vTaxArea VARCHAR(25);
+ DECLARE vCee INT;
+
+ SELECT ct.Cee INTO vCee
+ FROM `client` c
+ JOIN country ct ON ct.id = c.countryFk
+ JOIN supplier s ON s.id = vCompanyId
+ WHERE
+ c.id = vClientId
+ AND c.isVies
+ AND c.countryFk != s.countryFk;
+
+ IF vCee < 2 THEN
+ SET vTaxArea = 'CEE';
+ ELSEIF vCee = 2 THEN
+ SET vTaxArea = 'WORLD';
+ ELSE
+ SET vTaxArea = 'NATIONAL';
+ END IF;
+
+ RETURN vTaxArea;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `getAlert3State` */;
+ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `getAlert3State`(vTicket INT) RETURNS varchar(45) CHARSET latin1
+BEGIN
+ DECLARE vDeliveryType INTEGER DEFAULT 0;
+ DECLARE vWorker INT;
+ DECLARE isWaitingForPickUp BOOLEAN DEFAULT FALSE;
+ DECLARE vCode VARCHAR(45);
+
+ SELECT IFNULL(aw.Vista,a.Vista) INTO vDeliveryType
+ FROM vn2008.Tickets t
+ JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia
+ LEFT JOIN vn2008.agency_warehouse aw ON a.agency_id = aw.agency_id AND t.warehouse_id = aw.warehouse_id
+ WHERE Id_Ticket = vTicket;
+
+ SELECT getUser() INTO vWorker;
+
+ CASE vDeliveryType
+ WHEN 1 THEN -- AGENCIAS
+ SELECT COUNT(*) INTO isWaitingForPickUp
+ FROM vn2008.Tickets t
+ JOIN vn2008.warehouse_pickup w ON w.agency_id = t.Id_Agencia
+ WHERE t.Id_Ticket = vTicket AND w.warehouse_id <> t.warehouse_id;
+
+ IF isWaitingForPickUp THEN
+ SET vCode = 'WAITING_FOR_PICKUP';
+ ELSE
+ SET vCode = 'DELIVERED';
+ END IF;
+
+ WHEN 2 THEN -- REPARTO
+ SET vCode = 'ON_DELIVERY';
+
+ ELSE -- MERCADO, OTROS
+ SET vCode = 'DELIVERED';
+ END CASE;
+ RETURN vCode;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `getDueDate` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `getDueDate`(vDated DATE, vDayToPay INT) RETURNS date
+BEGIN
+
+DECLARE vDued DATE;
+
+SET vDued = IF (vDayToPay > 30 or vDayToPay < 1
+ ,TIMESTAMPADD(DAY, vDayToPay, vDated)
+ ,TIMESTAMPADD(DAY, vDayToPay, LAST_DAY(vDated)));
+
+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 */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `getInventoryDate` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `getInventoryDate`() RETURNS date
+ DETERMINISTIC
+BEGIN
+ RETURN vn2008.date_inv();
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `getShipmentHour` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `getShipmentHour`(vTicket INT) RETURNS int(11)
+BEGIN
+ DECLARE vShipmentHour INT;
+
+ SELECT HOUR(shipment) INTO vShipmentHour
+ FROM ticket
+ WHERE id = vTicket;
+
+ IF vShipmentHour = 0
+ THEN
+ DROP TEMPORARY TABLE IF EXISTS tmp.production_buffer;
+ CREATE TEMPORARY TABLE tmp.production_buffer
+ ENGINE = MEMORY
+ SELECT am.agency as agency_id
+ , t.warehouse as warehouse_id
+ , a.province as province_id
+ , 0 as Hora
+ , 0 as Departure
+ FROM ticket t
+ JOIN agencyMode am on am.id = t.agencyMode
+ JOIN address a on a.id = t.address
+ WHERE t.id = vTicket;
+
+ CALL vn2008.production_buffer_set_priority;
+
+ SELECT Hora INTO vShipmentHour
+ FROM tmp.production_buffer;
+ END IF;
+
+ RETURN vShipmentHour;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `getSpecialPrice` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `getSpecialPrice`(vItemFk int(11),vClientFk int(11)) RETURNS decimal(10,2)
+BEGIN
+ DECLARE price DECIMAL(10,2);
+
+ SELECT rate3 INTO price
+ FROM vn.priceFixed
+ WHERE itemFk = vItemFk
+ AND CURDATE() BETWEEN started AND ended ORDER BY created DESC LIMIT 1;
+
+ SELECT `value` INTO price
+ FROM vn.especialPrice
+ WHERE itemFk = vItemFk
+ AND clientFk = vClientFk ;
+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 `getTicketToPrepare` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `getTicketToPrepare`(`vWorker` INT, `vWarehouse` INT) RETURNS int(11)
+BEGIN
+/**
+ * Devuelve el ticket que debe de preparar el trabajador
+ *
+ * @param vWorker Id del trabajador
+ * @param vWarehouse Id del almacén
+ * @return Id del ticket
+ **/
+
+ DECLARE vToday DATETIME DEFAULT CURDATE();
+ DECLARE vYesterday DATETIME;
+ DECLARE vTodayvMidniight DATETIME DEFAULT midnight(vToday);
+ DECLARE vTicket INT DEFAULT NULL;
+
+ SET vYesterday = TIMESTAMPADD(DAY,-1,vToday);
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.workerComercial;
+ CREATE TEMPORARY TABLE tmp.workerComercial
+ ENGINE = MEMORY
+ SELECT worker FROM `grant` g
+ JOIN grantGroup gg ON g.`group` = gg.id
+ WHERE gg.description = 'Comerciales'
+ AND worker != 2; -- PAKO numero
+
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.production_buffer;
+ CREATE TEMPORARY TABLE tmp.production_buffer
+ ENGINE = MEMORY
+ SELECT t.id as ticket
+ , am.agency as agency_id
+ , t.warehouse as warehouse_id
+ , a.province as province_id
+ , Hour(t.shipment) as Hora
+ , Hour(t.shipment) as Departure
+ , Minute(t.shipment) as Minuto
+ , tls.code
+ , IFNULL(t.loadingOrder,0) loadingOrder
+ FROM ticket t
+ JOIN ticketState tls on t.id = tls.ticket
+ JOIN agencyMode am on am.id = t.agencyMode
+ JOIN address a on a.id = t.address
+ LEFT JOIN tmp.workerComercial wc ON wc.worker = vWorker
+ WHERE t.shipment BETWEEN vYesterday AND vTodayvMidniight
+ AND t.warehouse = vWarehouse
+ AND
+ (
+ (tls.code = 'PRINTED' AND wc.worker IS NULL)
+ OR
+ (tls.code ='PICKER_DESIGNED' AND tls.worker = vWorker)
+ OR
+ (tls.code = 'PRINTED_BACK')
+ );
+
+
+ CALL vn2008.production_buffer_set_priority;
+
+ SELECT ticket INTO vTicket
+ FROM tmp.production_buffer
+ ORDER BY (code = 'PICKER_DESIGNED') DESC , Hora, Minuto, loadingOrder
+ LIMIT 1;
+
+ RETURN vTicket;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `getTicketTrolleyLabelCount` */;
+ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `getTicketTrolleyLabelCount`(vTicket INT) RETURNS int(11)
+BEGIN
+
+DECLARE vLabelCount INT DEFAULT 0;
+
+SELECT labelCount INTO vLabelCount
+FROM ticketTrolley
+WHERE ticket = vTicket;
+
+SET vLabelCount = vLabelCount +1 ;
+
+REPLACE ticketTrolley(ticket,labelCount)
+SELECT vTicket, vLabelCount;
+
+RETURN vlabelCount;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `getUser` */;
+ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `getUser`() RETURNS int(11)
+ DETERMINISTIC
+BEGIN
+ RETURN getWorker();
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `getUserId` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `getUserId`(userName varchar(30)) RETURNS int(11)
+BEGIN
+ DECLARE vUser INT;
+
+ SELECT id INTO vUser
+ FROM account.user
+ WHERE `name` = userName;
+
+ RETURN vUser;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `getWorker` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `getWorker`() RETURNS int(11)
+ DETERMINISTIC
+BEGIN
+ DECLARE vUser INT;
+
+ SELECT id INTO vUser
+ FROM worker
+ WHERE userFk = account.userGetId();
+
+ RETURN vUser;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `getWorkerkk` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `getWorkerkk`() RETURNS int(11)
+ DETERMINISTIC
+BEGIN
+ DECLARE vUser INT;
+
+ SELECT id INTO vUser
+ FROM worker
+ WHERE user = account.userGetId();
+
+ RETURN vUser;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `hasAnyNegativeBase` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `hasAnyNegativeBase`() RETURNS tinyint(1)
+BEGIN
+
+/* Calcula si existe alguna base imponible negativa
+* Requiere la tabla temporal vn.ticketToInvoice(id)
+*
+* returns BOOLEAN
+*/
+
+ DECLARE vCountry INT;
+ DECLARE hasAnyNegativeBase BOOLEAN;
+
+ SELECT s.countryFk
+ INTO vCountry
+ FROM supplier s
+ JOIN ticket t ON t.companyFk = s.id
+ JOIN vn.ticketToInvoice tl ON tl.id = t.id
+ LIMIT 1;
+
+ SELECT COUNT(*) INTO hasAnyNegativeBase
+ FROM (
+ SELECT SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2)) taxableBase
+ FROM sale s
+ JOIN item i ON i.id = s.itemFk
+ JOIN itemTaxCountry itc
+ ON itc.itemFk = i.id AND itc.countryFk = vCountry
+ JOIN vn.ticketToInvoice tl ON tl.id = s.ticketFk
+ GROUP BY itc.taxClassFk
+ HAVING taxableBase < 0
+ ) t1 ;
+
+ RETURN hasAnyNegativeBase;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `hasSomeNegativeBase` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `hasSomeNegativeBase`(vTicket INT) RETURNS tinyint(1)
+BEGIN
+
+ DECLARE vCountry INT;
+ DECLARE hasSomeNegativeBase BOOLEAN;
+
+ SELECT s.countryFk
+ INTO vCountry
+ FROM supplier s
+ JOIN ticket t ON t.companyFk = s.id
+ WHERE t.id = vTicket;
+
+ SELECT COUNT(*) INTO hasSomeNegativeBase
+ FROM (
+ SELECT SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2)) taxableBase
+ FROM sale s
+ JOIN item i ON i.id = s.itemFk
+ JOIN itemTaxCountry itc
+ ON itc.itemFk = i.id AND itc.countryFk = vCountry
+ WHERE s.ticketFk = vTicket
+ GROUP BY itc.taxClassFk
+ HAVING taxableBase < 0
+ ) t1 ;
+
+ RETURN hasSomeNegativeBase;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `invoiceOutAmount` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceOutAmount`(vInvoiceRef VARCHAR(15)) RETURNS decimal(10,2)
+BEGIN
+ DECLARE totalAmount DECIMAL(10,2);
+
+ SELECT SUM(vat) INTO totalAmount
+ FROM
+ (
+ SELECT iot.vat
+ FROM invoiceOutTax iot
+ JOIN invoiceOut io ON io.id = iot.invoiceOutFk
+ WHERE io.ref = vInvoiceRef
+ UNION ALL
+ SELECT ioe.amount
+ FROM invoiceOutExpence ioe
+ JOIN invoiceOut io ON io.id = ioe.invoiceOutFk
+ WHERE io.ref = vInvoiceRef
+ ) t1;
+
+RETURN totalAmount;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `invoiceSerial` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceSerial`(vClientFk INT, vCompanyFk INT, vType CHAR(1)) RETURNS char(1) CHARSET utf8
+BEGIN
+ /**
+ * Obtiene la serie de de una factura
+ * dependiendo del area del cliente.
+ *
+ * @param vClientFk Id del cliente
+ * @param vCompanyFk Id de la empresa
+ * @param vType Tipo de factura ["R", "M", "G"]
+ * @return Serie de la factura
+ */
+ DECLARE vArea VARCHAR(25);
+ DECLARE vSerie CHAR(1);
+
+ IF (SELECT hasInvoiceSimplified FROM client WHERE id = vClientFk) THEN
+ RETURN 'S';
+ END IF;
+
+ SELECT clientTaxArea(vClientFk, vCompanyFk) INTO vArea;
+ -- Factura rápida
+ IF vType = 'R' THEN
+ SELECT
+ CASE vArea
+ WHEN 'CEE'
+ THEN 'H'
+ WHEN 'WORLD'
+ THEN 'E'
+ WHEN 'NATIONAL'
+ THEN 'T'
+ END
+ INTO vSerie;
+ -- Factura multiple
+ ELSEIF vType = 'M' THEN
+ SELECT
+ CASE vArea
+ WHEN 'CEE'
+ THEN 'H'
+ WHEN 'WORLD'
+ THEN 'E'
+ WHEN 'NATIONAL'
+ THEN 'M'
+ END
+ INTO vSerie;
+ -- Factura global
+ ELSEIF vType = 'G' THEN
+ SELECT
+ CASE vArea
+ WHEN 'CEE'
+ THEN 'V'
+ WHEN 'WORLD'
+ THEN 'X'
+ WHEN 'NATIONAL'
+ THEN 'A'
+ END
+ INTO vSerie;
+ END IF;
+ RETURN vSerie;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `isWorkerBoss` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `isWorkerBoss`(vUserId INT(11)) RETURNS tinyint(1)
+ DETERMINISTIC
+BEGIN
+
+ DECLARE subjectId INT(11) DEFAULT vUserId;
+ DECLARE tmpSubjectId INT(11);
+ DECLARE tmpBossId INT(11);
+
+ LOOP
+ SELECT
+ bossWorker.user_id AS tmpBossId,
+ subjectWorker.user_id AS tmpSubjectId
+ INTO tmpBossId, tmpSubjectId
+ FROM
+ vn2008.Trabajadores AS subjectWorker
+ JOIN
+ vn2008.Trabajadores AS bossWorker ON bossWorker.Id_Trabajador = subjectWorker.boss
+ WHERE
+ subjectWorker.user_id = subjectId;
+
+ IF tmpBossId = tmpSubjectId THEN
+ RETURN FALSE;
+ ELSEIF tmpBossId = account.userGetId() THEN
+ RETURN TRUE;
+ ELSE
+ SET subjectId = tmpBossId;
+ END IF;
+ END LOOP;
+
+RETURN 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 */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `messageSend` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `messageSend`(vRecipient VARCHAR(255), vMessage TEXT) RETURNS int(11)
+BEGIN
+/**
+ * Envia un mensaje a un usuario o a una lista de usuarios.
+ *
+ * @param vRecipient Nombre de usuario o de alias
+ * @param vMessage Texto del mensaje
+ * @return Número de destinatarios
+ **/
+ DECLARE vCount INT;
+ DECLARE vUuid VARCHAR(255);
+ DECLARE vSendDate DATETIME DEFAULT NOW();
+ DECLARE vUser VARCHAR(255) DEFAULT account.userGetName();
+
+ SET vRecipient = LOWER(vRecipient);
+
+ DROP TEMPORARY TABLE IF EXISTS tRecipients;
+ CREATE TEMPORARY TABLE tRecipients
+ SELECT u.name finalRecipient
+ FROM account.mailAlias a
+ JOIN account.mailAliasAccount aa ON aa.mailAlias = a.id
+ JOIN account.user u ON u.id = aa.account
+ WHERE a.alias = vRecipient COLLATE utf8_unicode_ci
+ AND u.name != vUser
+ AND u.active
+ UNION
+ SELECT u.name FROM account.user u
+ WHERE u.name = vRecipient
+ AND u.active;
+
+ SELECT COUNT(*) INTO vCount FROM tRecipients;
+
+ IF vCount = 0 THEN
+ RETURN vCount;
+ END IF;
+
+ SET vUuid = UUID();
+
+ INSERT INTO message
+ SET uuid = vUuid,
+ sender = vUser,
+ recipient = vRecipient,
+ message = vMessage,
+ sendDate = vSendDate;
+
+ INSERT INTO messageInbox (uuid, sender, recipient, finalRecipient, message, sendDate)
+ SELECT vUuid, vUser, vRecipient, finalRecipient, vMessage, vSendDate
+ FROM tRecipients;
+
+ DROP TEMPORARY TABLE tRecipients;
+ RETURN vCount;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `midnight` */;
+ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `midnight`(vDate DATE) RETURNS datetime
+ DETERMINISTIC
+BEGIN
+ RETURN TIMESTAMP(vDate,'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 */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `noticeHasActive` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `noticeHasActive`(vCategoryKey VARCHAR(50), vUser INT) RETURNS tinyint(1)
+BEGIN
+/**
+ * Comprueba si el usuario tiene activada o no la categoría
+ *
+ * @param vNoticeCategory Id de la categoría
+ * @param vUser Id del usuario
+ * @return %True si el usuario tiene activada la notificación, %False en caso contrario
+ */
+ DECLARE vActive INT;
+
+ SELECT COUNT(*) INTO vActive
+ FROM noticeSubscription s
+ JOIN noticeCategory c ON c.id = s.noticeCategoryFk
+ WHERE c.keyName = vCategoryKey AND userFk = vUser;
+
+ RETURN vActive;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `phytoPassport` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `phytoPassport`(vRef VARCHAR(15)) RETURNS text CHARSET utf8
+BEGIN
+DECLARE vPhyto TEXT CHARSET utf8 COLLATE utf8_unicode_ci;
+SELECT
+ GROUP_CONCAT(i.id,
+ ':',
+ ppa.denomination,
+ ' ',
+ pp.number,
+ CHAR(13,10)
+ SEPARATOR '') fitosanitario
+ INTO vPhyto
+FROM
+ sale s
+ JOIN
+ ticket t ON t.id = s.ticketFk
+ JOIN
+ item i ON i.id = s.itemFk
+ JOIN
+ plantpassport pp ON pp.producerFk = i.producerFk
+ JOIN
+ plantpassportAuthority ppa ON ppa.id = pp.plantpassportAuthorityFk
+ JOIN
+ itemBotanicalWithGenus ib ON ib.itemFk = i.id
+ JOIN
+ botanicExport be ON be.restriction = 'Se Requiere Certificado'
+ LEFT JOIN
+ ediGenus eg ON eg.id = be.ediGenusFk
+ LEFT JOIN
+ ediSpecie es ON es.id = be.ediSpecieFk
+WHERE
+ t.refFk = vRef
+ AND ib.ediBotanic LIKE CONCAT(IFNULL(eg.latinGenusName, ''),
+ IF(latinSpeciesName > '',
+ CONCAT(' ', latinSpeciesName),
+ ''),
+ '%');
+RETURN vPhyto;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticketGetTotal` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketGetTotal`(vTicketId INT) RETURNS decimal(10,2)
+ READS SQL DATA
+ DETERMINISTIC
+BEGIN
+/**
+ * Calcula el total con IVA de un ticket.
+ *
+ * @param vTicketId Identificador del ticket
+ * @return Total del ticket
+ */
+ DECLARE vTotal DECIMAL(10,2);
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
+ CREATE TEMPORARY TABLE tmp.ticket
+ ENGINE = MEMORY
+ SELECT vTicketId ticketFk;
+
+ CALL ticketGetTotal;
+
+ SELECT total INTO vTotal FROM tmp.ticketTotal;
+
+ DROP TEMPORARY TABLE
+ tmp.ticket,
+ tmp.ticketTotal;
+
+ RETURN vTotal;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticketPositionInPath` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketPositionInPath`(vTicketId INT) RETURNS varchar(10) CHARSET utf8
+BEGIN
+
+ DECLARE vRestTicketsMaxOrder INT;
+ DECLARE vRestTicketsMinOrder INT;
+ DECLARE vRestTicketsPacking INT;
+ DECLARE vMyProductionOrder INT;
+ DECLARE vPosition VARCHAR(10) DEFAULT 'MID';
+ DECLARE vMyPath INT;
+ DECLARE vMyWarehouse INT;
+ DECLARE PACKING_ORDER INT;
+ DECLARE vExpeditionsCount INT;
+ DECLARE vIsValenciaPath BOOLEAN DEFAULT FALSE;
+
+SELECT `order`
+ INTO PACKING_ORDER
+ FROM state
+ WHERE code = 'PACKING';
+
+SELECT t.routeFk, t.warehouseFk, IFNULL(ts.productionOrder,0)
+ INTO vMyPath, vMyWarehouse, vMyProductionOrder
+ FROM ticket t
+ LEFT JOIN ticketState ts on ts.ticket = t.id
+ WHERE t.id = vTicketId;
+
+SELECT (ag.`name` = 'VN_VALENCIA')
+ INTO vIsValenciaPath
+ FROM vn2008.Rutas r
+ JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia
+ JOIN vn2008.agency ag on ag.agency_id = a.agency_id
+ WHERE r.Id_Ruta = vMyPath;
+
+IF vIsValenciaPath THEN -- Rutas Valencia
+
+ SELECT COUNT(*)
+ INTO vExpeditionsCount
+ FROM expedition e
+ JOIN ticket t ON t.id = e.ticket
+ WHERE t.routeFk = vMyPath;
+
+ SELECT MAX(ts.productionOrder), MIN(ts.productionOrder)
+ INTO vRestTicketsMaxOrder, vRestTicketsMinOrder
+ FROM ticket t
+ LEFT JOIN ticketState ts on t.id = ts.ticket
+ WHERE t.routeFk = vMyPath
+ AND t.warehouseFk = vMyWarehouse
+ AND t.id != vTicketid;
+
+ SELECT COUNT(*)
+ INTO vRestTicketsPacking
+ FROM ticket t
+ LEFT JOIN ticketState ts on t.id = ts.ticket
+ WHERE ts.productionOrder = PACKING_ORDER
+ AND t.routeFk = vMyPath
+ AND t.warehouseFk = vMyWarehouse
+ AND t.id != vTicketid;
+
+ IF vExpeditionsCount = 1 THEN
+ SET vPosition = 'FIRST';
+ ELSEIF vRestTicketsMinOrder > PACKING_ORDER THEN
+ SET vPosition = 'LAST';
+ ELSEIF vRestTicketsPacking THEN
+ SET vPosition = 'SHARED';
+ ELSE
+ SET vPosition = 'MID';
+ END IF;
+
+ELSE
+ SET vPosition = 'MID';
+
+END IF;
+
+RETURN vPosition;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticketPositionInPathkk` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketPositionInPathkk`(vTicketId INT) RETURNS varchar(10) CHARSET utf8
+BEGIN
+
+
+DECLARE vRestTicketsMaxOrder INT;
+DECLARE vRestTicketsMinOrder INT;
+DECLARE vRestTicketsPacking INT;
+DECLARE vMyProductionOrder INT;
+DECLARE vPosition VARCHAR(10) DEFAULT 'MID';
+DECLARE vMyPath INT;
+DECLARE vMyWarehouse INT;
+DECLARE PACKING_ORDER INT;
+DECLARE vExpeditionsCount INT;
+DECLARE vIsValenciaPath BOOLEAN DEFAULT FALSE;
+
+SELECT `order`
+ INTO PACKING_ORDER
+ FROM state
+ WHERE code = 'PACKING';
+
+SELECT path, warehouse, IFNULL(productionOrder,0)
+ INTO vMyPath, vMyWarehouse, vMyProductionOrder
+ FROM ticket t
+ LEFT JOIN ticketState ts on ts.ticket = t.id
+ WHERE id = vTicketId;
+
+SELECT (ag.`name` = 'VN_VALENCIA')
+ INTO vIsValenciaPath
+ FROM vn2008.Rutas r
+ JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia
+ JOIN vn2008.agency ag on ag.agency_id = a.agency_id
+ WHERE r.Id_Ruta = vMyPath;
+
+
+IF vIsValenciaPath THEN -- Rutas Valencia
+
+ SELECT COUNT(*)
+ INTO vExpeditionsCount
+ FROM expedition e
+ JOIN ticket t ON t.id = e.ticket
+ WHERE t.path = vMyPath;
+
+ SELECT MAX(productionOrder), MIN(productionOrder)
+ INTO vRestTicketsMaxOrder, vRestTicketsMinOrder
+ FROM ticket t
+ LEFT JOIN ticketState ts on t.id = ts.ticket
+ WHERE t.path = vMyPath
+ AND t.warehouse = vMyWarehouse
+ AND t.id != vTicketid;
+
+ SELECT COUNT(*)
+ INTO vRestTicketsPacking
+ FROM ticket t
+ LEFT JOIN ticketState ts on t.id = ts.ticket
+ WHERE productionOrder = PACKING_ORDER
+ AND t.path = vMyPath
+ AND t.warehouse = vMyWarehouse
+ AND t.id != vTicketid;
+
+
+
+ IF vExpeditionsCount = 1 THEN
+
+ SET vPosition = 'FIRST';
+
+ ELSEIF vRestTicketsMinOrder > PACKING_ORDER THEN
+
+ SET vPosition = 'LAST';
+
+ ELSEIF vRestTicketsPacking THEN
+
+ SET vPosition = 'SHARED';
+
+ ELSE
+
+ SET vPosition = 'MID';
+
+ END IF;
+
+ELSE
+
+ SET vPosition = 'MID';
+
+END IF;
+
+RETURN vPosition;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `workerIsBoss` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `workerIsBoss`(vUserId INT) RETURNS int(11)
+BEGIN
+/**
+ * Comprueba por jerarquía si el trabajador actual es jefe
+ * de un trabajador en concreto.
+ *
+ * @param vUserId Id del trabajador que se desea comprobar.
+ * @return Revuelve verdadero si es jefe del empleado por escala jerárquica.
+ */
+ DECLARE vWorkerId INT;
+ DECLARE vBossId INT;
+
+ SELECT id INTO vWorkerId
+ FROM vn.worker
+ WHERE userFk = vUserId;
+ IF vWorkerId IS NULL THEN
+ CALL util.throw('USER_NOT_FOUND');
+ END IF;
+
+ DROP TEMPORARY TABLE IF EXISTS tCheckedWorker;
+ CREATE TEMPORARY TABLE tCheckedWorker
+ (PRIMARY KEY (workerFk))
+ ENGINE = MEMORY
+ SELECT id workerFk FROM worker LIMIT 0;
+ LOOP
+ SELECT bossFk INTO vBossId
+ FROM vn.worker
+ WHERE id = vWorkerId;
+ IF (SELECT COUNT(*) FROM tCheckedWorker WHERE workerFk = vBossId) THEN
+ CALL util.throw('INFINITE_LOOP');
+ END IF;
+ IF vBossId = vWorkerId THEN
+ RETURN FALSE;
+ ELSEIF vBossId = vn.getWorker() THEN
+ RETURN TRUE;
+ ELSE
+ INSERT INTO tCheckedWorker VALUES (vWorkerId);
+ SET vWorkerId = vBossId;
+ END IF;
+ END LOOP;
+ DROP TEMPORARY TABLE tCheckedWorker;
+ RETURN 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 `agencyListAvailable` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `agencyListAvailable`(vDate DATE, vAddress INT)
+BEGIN
+/**
+ * Devuelve la lista de almacenes disponibles y la fecha de
+ * envío desde cada uno.
+ *
+ * @param vDate Fecha de recepción de mercancía
+ * @param vAddress Id consignatario, %NULL para recogida
+ * @table travel_tree Lista de almacenes disponibles
+ */
+ DECLARE vMaxDays INT DEFAULT DATEDIFF(vDate, CURDATE());
+ DECLARE vWday TINYINT DEFAULT WEEKDAY(vDate);
+ DECLARE vHour TINYINT DEFAULT HOUR(NOW());
+ DECLARE vProvince INT;
+
+ SELECT province INTO vProvince
+ FROM address
+ WHERE id = vAddress;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.agencyAvailable;
+ CREATE TEMPORARY TABLE tmp.agencyAvailable
+ (INDEX (agency))
+ ENGINE = MEMORY
+ SELECT agency, warehouse
+ FROM agencyHour h
+ WHERE (province = vProvince
+ OR province IS NULL)
+ AND (weekDay = vWday
+ OR weekDay IS NULL)
+ AND (substractDay < vMaxDays
+ OR (substractDay = vMaxDays AND maxHour > vHour));
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `agencyListForMethod` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `agencyListForMethod`(
+ vDate DATE, vAddress INT, vMethod VARCHAR(255))
+BEGIN
+/**
+ * Devuelve la lista de agencias disponibles para una forma
+ * de envío.
+ *
+ * @param vDate Fecha de recepción de mercancía
+ * @param vAddress Id consignatario, %NULL para recogida
+ * @param vMethod Código de la forma de envío
+ * @select Lista de agencias disponibles
+ */
+ CALL agencyListAvailable (vDate, vAddress);
+
+ SELECT DISTINCT m.id, m.description
+ FROM tmp.agencyAvailable a
+ JOIN agencyMode m
+ ON m.agency = a.agency
+ JOIN deliveryMethod d
+ ON d.id = m.deliveryMethod
+ WHERE d.code = vMethod COLLATE 'utf8_unicode_ci';
+
+ DROP TEMPORARY TABLE tmp.agencyAvailable;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!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`()
+BEGIN
+
+ DECLARE vDateShort DATETIME;
+
+ SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE());
+
+ DELETE FROM vn.dailyTaskLog WHERE created < vDateShort;
+
+ INSERT INTO vn.dailyTaskLog(state) VALUES('clean START');
+
+ DELETE FROM vn.message WHERE sendDate < vDateShort;
+ DELETE FROM vn.messageInbox WHERE sendDate < vDateShort;
+ DELETE FROM vn.messageInbox WHERE sendDate < vDateShort;
+
+ INSERT INTO vn.dailyTaskLog(state) 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 `clientFreeze` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `clientFreeze`()
+BEGIN
+
+ IF day(CURDATE()) IN (10,20,30) THEN
+
+ UPDATE vn.client c
+ JOIN bi.defaulters d ON d.client = c.id AND d.date = CURDATE()
+ JOIN vn.config ON TRUE
+ SET c.isFreezed = TRUE
+ WHERE d.amount > config.defaultersMaxAmount;
+
+ 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 `copyComponentsFromSaleList` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `copyComponentsFromSaleList`(vTargetTicketFk INT)
+BEGIN
+
+/* Copy sales and components to the target ticket
+*
+* ¡¡¡¡ Requires tmp.saleList(saleFk, itemFk, quantity, concept, price, discount, orden) !!!!!
+*
+* param VTargetTicketFk id del ticket a rellenar
+*/
+
+ INSERT INTO vn.sale(ticketFk, itemFk, quantity,concept,price,discount)
+ SELECT vTargetTicketFk, itemFk, quantity,concept,price,discount
+ FROM tmp.saleList
+ ORDER BY orden;
+
+ SET @order = 0;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.newSaleList;
+
+ CREATE TEMPORARY TABLE tmp.newSaleList
+ SELECT id as saleFk, @order := @order + 1 as orden
+ FROM vn.sale
+ WHERE ticketFk = vTargetTicketFk
+ ORDER BY saleFk;
+
+ INSERT INTO vn.saleComponent(saleFk,componentFk,value)
+ SELECT ns.saleFk, sc.componentFk, sc.value
+ FROM vn.saleComponent sc
+ JOIN tmp.saleList s ON s.saleFk = sc.saleFk
+ JOIN tmp.newSaleList ns ON ns.orden = s.orden;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `createExternalWorkerkk` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `createExternalWorkerkk`(
+ vFirstName VARCHAR(50),
+ vSurname1 VARCHAR(50),
+ vSurname2 VARCHAR(50),
+ vUser VARCHAR(20),
+ vPassword VARCHAR(50),
+ vWorkerCode VARCHAR(3)
+ )
+BEGIN
+
+ DECLARE vUserId INT;
+ DECLARE vWorkerPako INT DEFAULT 2;
+ DECLARE vSurnames VARCHAR(100);
+
+ INSERT INTO account.user(name,password,role)
+ SELECT vUser,MD5(vPassword),1;
+
+ SET vUserId = LAST_INSERT_ID();
+ /*
+ INSERT INTO vn.worker(firstName,name,bossFk,workerCode,user_id)
+ SELECT vFirstName,CONCAT(vSurname1,' ',vSurname2),2,vWorkerCode,vUser;
+ */
+
+ IF vSurname2 IS NULL THEN
+ SET vSurnames = vSurname1;
+ ELSE
+ SET vSurnames = CONCAT(vSurname1, ' ', vSurname2);
+ END IF;
+
+ INSERT INTO vn2008.Trabajadores(Nombre, Apellidos, boss, CodigoTrabajador, user_id)
+ SELECT vFirstName, vSurnames, vWorkerPako, vWorkerCode, vUserId;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `entryConverter` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `entryConverter`(vEntry INT)
+BEGIN
+
+ DECLARE vWarehouseIn INT;
+ DECLARE vWarehouseOut INT;
+ DECLARE vTravel INT;
+
+ DECLARE done BOOL DEFAULT FALSE;
+
+ DECLARE vId_Entrada INT;
+ DECLARE vId_Article INT;
+ DECLARE vEtiquetas INT;
+ DECLARE vId_Cubo VARCHAR(10);
+ DECLARE vPacking INT;
+ DECLARE vGrouping INT;
+ DECLARE vCantidad INT;
+ DECLARE vCostefijo DECIMAL(10,3);
+ DECLARE vPortefijo DECIMAL(10,3);
+ DECLARE vEmbalajefijo DECIMAL(10);
+ DECLARE vComisionfija DECIMAL(10,3);
+ DECLARE vCaja INT;
+ DECLARE vNicho VARCHAR(5);
+ DECLARE vTarifa1 DECIMAL(10,2);
+ DECLARE vTarifa2 DECIMAL(10,2);
+ DECLARE vTarifa3 DECIMAL(10,2);
+ DECLARE vPVP DECIMAL(10,2);
+ DECLARE vCompra INT;
+
+ DECLARE rs CURSOR FOR
+ SELECT
+ b.Id_Entrada,
+ b.Id_Article,
+ b.Etiquetas,
+ b.Id_Cubo,
+ b.Packing,
+ b.grouping,
+ b.Cantidad,
+ b.Costefijo,
+ b.Portefijo,
+ b.Embalajefijo,
+ b.Comisionfija,
+ b.caja,
+ b.Nicho,
+ b.Tarifa1,
+ b.Tarifa2,
+ b.Tarifa3,
+ b.PVP
+ FROM vn2008.Compres b
+ JOIN vn.itemConversor ic ON ic.espItemFk = b.Id_Article
+ WHERE Id_Entrada = vEntry;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+
+ SELECT warehouseInFk, warehouseOutFk, tr.id
+ INTO vWarehouseIn, vWarehouseOut, vTravel
+ FROM travel tr
+ JOIN entry e ON e.travelFk = tr.id
+ WHERE e.id = vEntry;
+
+ UPDATE travel
+ SET warehouseInFk = vWarehouseOut,
+ warehouseOutFk = vWarehouseIn
+ WHERE id = vTravel;
+
+ UPDATE vn2008.Compres c
+ LEFT JOIN vn.itemConversor ic ON ic.espItemFk = c.Id_Article
+ SET Etiquetas = 0, Cantidad = 0
+ WHERE c.Id_Entrada = vEntry
+ AND ic.espItemFk IS NULL;
+
+ OPEN rs;
+
+ DELETE FROM vn2008.Compres WHERE Id_Entrada = vEntry;
+
+ FETCH rs INTO
+ vId_Entrada,
+ vId_Article,
+ vEtiquetas,
+ vId_Cubo,
+ vPacking,
+ vGrouping,
+ vCantidad,
+ vCostefijo,
+ vPortefijo,
+ vEmbalajefijo,
+ vComisionfija,
+ vCaja,
+ vNicho,
+ vTarifa1,
+ vTarifa2,
+ vTarifa3,
+ vPVP;
+
+ WHILE NOT done DO
+
+ -- Primero la linea original con las cantidades invertidas
+ INSERT INTO vn2008.Compres
+ (
+ Id_Entrada,
+ Id_Article,
+ Etiquetas,
+ Id_Cubo,
+ Packing,
+ grouping,
+ Cantidad,
+ Costefijo,
+ Portefijo,
+ Embalajefijo,
+ Comisionfija,
+ caja,
+ Nicho,
+ Tarifa1,
+ Tarifa2,
+ Tarifa3,
+ PVP
+ )
+ VALUES
+ (
+ vId_Entrada,
+ vId_Article,
+ - vEtiquetas,
+ vId_Cubo,
+ vPacking,
+ vGrouping,
+ - vCantidad,
+ vCostefijo,
+ vPortefijo,
+ vEmbalajefijo,
+ vComisionfija,
+ vCaja,
+ vNicho,
+ vTarifa1,
+ vTarifa2,
+ vTarifa3,
+ vPVP);
+
+ -- Ahora la linea nueva, con el item genérico
+ INSERT INTO vn2008.Compres
+ (
+ Id_Entrada,
+ Id_Article,
+ Etiquetas,
+ Id_Cubo,
+ Packing,
+ grouping,
+ Cantidad,
+ Costefijo,
+ Portefijo,
+ Embalajefijo,
+ Comisionfija,
+ caja,
+ Nicho,
+ Tarifa1,
+ Tarifa2,
+ Tarifa3,
+ PVP
+ )
+ SELECT
+ vId_Entrada,
+ genItemFk as Id_Article,
+ vEtiquetas,
+ vId_Cubo,
+ vPacking,
+ vGrouping,
+ vCantidad,
+ vCostefijo,
+ vPortefijo,
+ vEmbalajefijo,
+ vComisionfija,
+ vCaja,
+ vNicho,
+ vTarifa1,
+ vTarifa2,
+ vTarifa3,
+ vPVP
+ FROM itemConversor
+ WHERE espItemFk = vId_Article;
+
+ SELECT LAST_INSERT_ID()
+ INTO vCompra;
+
+ REPLACE vn2008.Compres_mark(Id_Compra,`comment`)
+ SELECT vCompra, vId_Article;
+
+
+ FETCH rs INTO
+ vId_Entrada,
+ vId_Article,
+ vEtiquetas,
+ vId_Cubo,
+ vPacking,
+ vGrouping,
+ vCantidad,
+ vCostefijo,
+ vPortefijo,
+ vEmbalajefijo,
+ vComisionfija,
+ vCaja,
+ vNicho,
+ vTarifa1,
+ vTarifa2,
+ vTarifa3,
+ vPVP;
+
+ 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 `getDebt` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `getDebt`(vDate DATE)
+BEGIN
+/**
+ * Calcula el riesgo para los clientes activos de la tabla temporal tmp.client_list
+ *
+ * @table tmp.client_list
+ * @param vDate Fecha maxima de los registros
+ * @treturn tmp.risk
+ */
+ DECLARE vDateIni DATETIME DEFAULT TIMESTAMPADD(DAY, - DAYOFMONTH(CURDATE()) - 5, CURDATE());
+ DECLARE vDateEnd DATETIME;
+ DECLARE MAX_RISK_ALLOWED INT DEFAULT 200;
+
+ SET vDateEnd = TIMESTAMP(IFNULL(vDate, CURDATE()), '23:59:59');
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.clientList2;
+ CREATE TEMPORARY TABLE tmp.clientList2
+ (PRIMARY KEY (Id_Cliente))
+ ENGINE = MEMORY
+ SELECT *
+ FROM tmp.client_list;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.clientList3;
+ CREATE TEMPORARY TABLE tmp.clientList3
+ (PRIMARY KEY (Id_Cliente))
+ ENGINE = MEMORY
+ SELECT *
+ FROM tmp.client_list;
+
+ DROP TEMPORARY TABLE IF EXISTS vn2008.ticket_tmp;
+ CREATE TEMPORARY TABLE vn2008.ticket_tmp
+ (INDEX (ticket_id))
+ ENGINE = MEMORY
+ SELECT id ticket_id, cl.Id_Cliente
+ FROM ticket t
+ JOIN tmp.clientList2 cl ON t.clientFk = cl.Id_Cliente
+ WHERE refFk IS NULL
+ AND shipped BETWEEN vDateIni AND vDateEnd;
+
+ CALL vn2008.ticket_total;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.risk;
+ CREATE TEMPORARY TABLE tmp.risk
+ (PRIMARY KEY (Id_Cliente))
+ ENGINE = MEMORY
+ SELECT Id_Cliente, SUM(amount) risk
+ FROM vn2008.Clientes c
+ JOIN (
+ SELECT customer_id, SUM(amount) amount
+ FROM bi.customer_risk cr
+ JOIN tmp.client_list on tmp.client_list.Id_Cliente = cr.customer_id
+ GROUP BY customer_id
+ UNION ALL
+ SELECT Id_Cliente, SUM(Entregado)
+ FROM vn2008.Recibos
+ JOIN tmp.clientList2 using(Id_Cliente)
+ WHERE Fechacobro > vDateIni
+ GROUP BY Id_Cliente
+ UNION ALL
+ SELECT t.Id_Cliente, total
+ FROM vn2008.ticket_total tt
+ JOIN vn2008.ticket_tmp t ON tt.ticket_id = t.ticket_id
+ UNION ALL
+ SELECT t.clientFk customer_id, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2))
+ FROM hedera.tpvTransaction t
+ JOIN tmp.clientList3 l ON l.Id_Cliente = t.clientFk
+ WHERE t.receiptFk IS NULL
+ AND t.status = 'ok'
+ GROUP BY t.clientFk
+ ) t ON c.Id_Cliente = t.customer_id
+ WHERE c.activo != FALSE
+ GROUP BY c.Id_Cliente;
+
+ DROP TEMPORARY TABLE
+ vn2008.ticket_tmp,
+ vn2008.ticket_total,
+ tmp.clientList2,
+ tmp.clientList3;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `getItemVisibleAvailable` */;
+ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `getItemVisibleAvailable`(IN vItem INT,IN vDate DATE,IN vWarehouse TINYINT,IN isForcedToRecalculate BOOLEAN)
+BEGIN
+
+ DECLARE vCacheVisibleCalculated INTEGER;
+ DECLARE vCacheAvailableCalculated INTEGER;
+
+ CALL cache.visible_refresh(vCacheVisibleCalculated, isForcedToRecalculate, vWarehouse);
+ CALL cache.available_refresh(vCacheAvailableCalculated, isForcedToRecalculate, vWarehouse, vDate);
+
+ SELECT a.Id_Article, a.Article, a.Medida, a.Tallos, a.caja, O.Abreviatura as origen, a.Color, tipo_id, an.Nicho,
+ a.Categoria, p.`name` as producer, v.visible, av.available
+ FROM vn2008.Articles a
+ LEFT JOIN vn2008.Articles_nicho an ON a.Id_Article = an.Id_Article AND an.warehouse_id = vWarehouse
+ LEFT JOIN vn2008.Origen O ON O.id = a.id_origen
+ LEFT JOIN vn2008.producer p ON p.producer_id = a.producer_id
+ LEFT JOIN cache.visible v ON (vItem IS NULL OR v.item_id = vItem) AND v.calc_id = vCacheVisibleCalculated
+ LEFT JOIN cache.available av ON (vItem IS NULL OR av.item_id = vItem) AND av.calc_id = vCacheAvailableCalculated
+ WHERE (vItem IS NULL OR a.Id_Article = 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 */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `invoiceCorrectedSale` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceCorrectedSale`(vInvoiceOut INT)
+BEGIN
+
+/* Devuelve los registros de la factura en cuestion, para preparar la factura rectificativa
+*
+* param vInvoiceOutId Referencia de la factura emitida, tal como se ve en el ticket
+*
+*/
+
+
+SELECT
+ s.id,
+ s.itemFk,
+ s.quantity,
+ s.price,
+ s.discount
+ FROM sale s
+ JOIN ticket t ON t.id = s.ticketFk
+ WHERE t.invoice = vInvoiceOut;
+
+
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `invoiceExpenceMake` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceExpenceMake`(IN vInvoice INT)
+BEGIN
+/* Inserta las partidas de gasto correspondientes a la factura
+ * REQUIERE tabla ticketToInvoice
+ *
+ * @param vInvoice Numero de factura
+ *
+ */
+ DELETE FROM invoiceOutExpence
+ WHERE invoiceOutFk = vInvoice;
+
+ INSERT INTO invoiceOutExpence(
+ invoiceOutFk,
+ expenceFk,
+ amount
+ )
+ SELECT
+ vInvoice,
+ expenceFk,
+ SUM(ROUND(quantity * price * (100 - discount)/100,2)) amount
+ FROM ticketToInvoice t
+ JOIN sale s ON s.ticketFk = t.id
+ JOIN item i ON i.id = s.itemFk
+ GROUP BY i.expenceFk
+ HAVING amount != 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 `invoiceFromAddress` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceFromAddress`(vMaxTicketDate DATETIME,vAddress INT,vCompany INT)
+BEGIN
+
+ DECLARE vMinDateTicket DATE DEFAULT TIMESTAMPADD(MONTH, -3, CURDATE());
+
+ SET vMaxTicketDate = vn2008.DAYEND(vMaxTicketDate);
+
+ DROP TEMPORARY TABLE IF EXISTS `ticketToInvoice`;
+
+ CREATE TEMPORARY TABLE `ticketToInvoice`
+ (PRIMARY KEY (`id`))
+ ENGINE = MEMORY
+ SELECT Id_Ticket id FROM vn2008.Tickets WHERE (Fecha BETWEEN vMinDateTicket
+ AND vMaxTicketDate) AND Id_Consigna = vAddress
+ AND Factura IS NULL AND empresa_id = vCompany;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `invoiceFromClient` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceFromClient`(vMaxTicketDate DATETIME, vClient INT, vCompany INT)
+BEGIN
+
+ DECLARE vMinDateTicket DATE DEFAULT TIMESTAMPADD(YEAR, -3, CURDATE());
+
+ SET vMaxTicketDate = vn2008.DAYEND(vMaxTicketDate);
+
+ DROP TEMPORARY TABLE IF EXISTS `ticketToInvoice`;
+
+ CREATE TEMPORARY TABLE `ticketToInvoice`
+ (PRIMARY KEY (`id`))
+ ENGINE = MEMORY
+ SELECT Id_Ticket id FROM vn2008.Tickets
+ WHERE Id_Cliente = vClient
+ AND Factura IS NULL
+ AND empresa_id = vCompany
+ AND (Fecha BETWEEN vMinDateTicket AND vMaxTicketDate)
+ ;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `invoiceFromTicket` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceFromTicket`(IN vTicket INT)
+BEGIN
+
+ DROP TEMPORARY TABLE IF EXISTS `ticketToInvoice`;
+
+ CREATE TEMPORARY TABLE `ticketToInvoice`
+ (PRIMARY KEY (`id`))
+ ENGINE = MEMORY
+ SELECT id FROM vn.ticket
+ WHERE id = vTicket AND refFk 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 `invoiceInBookingCommon` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceInBookingCommon`(vInvoiceInId INT, OUT vSerialNumber INT)
+BEGIN
+
+ DROP TEMPORARY TABLE IF EXISTS newInvoiceIn;
+
+ CREATE TEMPORARY TABLE newInvoiceIn
+ SELECT
+ i.*,
+ YEAR(i.booked) datedYear,
+ -- CONCAT('s/fra',RIGHT(i.supplierRef,8)) concept,
+ CONCAT('s/fra',RIGHT(i.supplierRef,8),':',LEFT(s.name, 10)) conceptWithSupplier,
+ (cc.id = c.id) isSameCountry,
+ cit.id invoicesCount
+ FROM invoiceIn i
+ JOIN cplusInvoiceType472 cit ON cit.id = i.cplusInvoiceType472Fk
+ JOIN supplier s ON s.id = i.supplierFk
+ JOIN country c ON c.id = s.countryFk
+ JOIN supplier sc ON sc.id = i.companyFk
+ JOIN country cc ON cc.id = sc.countryFk
+ WHERE i.id = vInvoiceInId;
+
+ DROP TEMPORARY TABLE IF EXISTS newSupplier;
+ CREATE TEMPORARY TABLE newSupplier
+ SELECT
+ s.*,
+ REPLACE(s.account,' ','') supplierAccount,
+ IF(c.CEE < 2, TRUE, FALSE) isUeeMember
+ FROM supplier s
+ JOIN newInvoiceIn n
+ JOIN country c ON c.id = s.countryFk
+ WHERE s.id = n.supplierFk;
+
+ IF (SELECT isActive FROM newSupplier) = 0 THEN
+ CALL util.throw('INACTIVE_PROVIDER');
+ END IF;
+
+ SELECT IFNULL(MAX(i.serialNumber) + 1,1)
+ INTO vSerialNumber
+ FROM invoiceIn i
+ JOIN newInvoiceIn n
+ WHERE i.serial LIKE n.serial
+ AND YEAR(i.booked) = n.datedYear
+ AND i.companyFk = n.companyFk
+ GROUP BY i.companyFk;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `invoiceInBookingExtra` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceInBookingExtra`(vInvoiceInId INT)
+BEGIN
+ DECLARE vBookNumber,vSerialNumber INT;
+
+ CALL invoiceInBookingCommon(vInvoiceInId,vSerialNumber);
+
+ SELECT MAX(ASIEN) + 1
+ INTO vBookNumber
+ FROM vn2008.XDiario;
+
+ -- Actualizacion de la fecha de contabilizado y de operacion de las importaciones
+ UPDATE invoiceInEntry iie
+ JOIN invoiceIn ii ON ii.id = iie.invoiceInFk
+ JOIN invoiceInAwb iia ON iia.invoiceInFk = iie.invoiceInAwbFk
+ JOIN awb a ON a.id = iia.awbFk
+ SET ii.isBooked = TRUE,
+ ii.booked = IFNULL(ii.booked,a.booked),
+ ii.operated = IFNULL(ii.operated,a.operated),
+ ii.issued = IFNULL(ii.issued,a.issued),
+ ii.bookEntried = IFNULL(ii.bookEntried,a.bookEntried)
+ WHERE iie.invoiceInAwbFk = vInvoiceInId;
+
+ -- Extracomunitarias gasto contra proveedor/acreedor
+ INSERT INTO vn2008.XDiario (
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EURODEBE,
+ CONCEPTO,
+ CAMBIO,
+ DEBEME,
+ NFACTICK,
+ empresa_id
+ )
+ SELECT
+ vBookNumber ASIEN,
+ IFNULL(a.bookEntried, n.bookEntried) FECHA,
+ iit.expenceFk SUBCTA,
+ s.account CONTRA,
+ ROUND(SUM(iit.taxableBase) * (iie.percentage / 100),2) EURODEBE,
+ CONCAT('COMPRA s/fra ',i.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
+ SUM(iit.taxableBase) / SUM(iit.foreignValue) CAMBIO,
+ ROUND(SUM(iit.foreignValue) * (iie.percentage / 100),2) DEBEME,
+ n.invoicesCount NFACTICK,
+ n.companyFk empresa_id
+ FROM newInvoiceIn n
+ JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = n.id
+ JOIN invoiceInTax iit ON iit.invoiceInFk = iie.invoiceInFk
+ JOIN invoiceIn i ON i.id = iit.invoiceInFk
+ JOIN supplier s ON s.id = i.supplierFk
+ LEFT JOIN invoiceInAwb iia ON iia.invoiceInFk = n.id
+ LEFT JOIN awb a ON a.id = iia.awbFk
+ WHERE iie.percentage
+ GROUP BY i.id;
+
+ -- Extracomunitarias proveedor contra gasto
+ INSERT INTO vn2008.XDiario (
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EUROHABER,
+ CONCEPTO,
+ CAMBIO,
+ HABERME,
+ NFACTICK,
+ empresa_id
+ )
+ SELECT
+ vBookNumber ASIEN,
+ IFNULL(a.bookEntried, n.bookEntried) FECHA,
+ s.account SUBCTA,
+ iit.expenceFk CONTRA,
+ ROUND(SUM(iit.taxableBase) * (iie.percentage / 100),2) EUROHABER,
+ CONCAT('COMPRA s/fra ',i.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
+ SUM(iit.taxableBase) / SUM(iit.foreignValue) CAMBIO,
+ SUM(iit.foreignValue) HABERME,
+ n.invoicesCount NFACTICK,
+ n.companyFk empresa_id
+ FROM newInvoiceIn n
+ JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = n.id
+ JOIN invoiceInTax iit ON iit.invoiceInFk = iie.invoiceInFk
+ JOIN invoiceIn i ON i.id = iit.invoiceInFk
+ JOIN supplier s ON s.id = i.supplierFk
+ LEFT JOIN invoiceInAwb iia ON iia.invoiceInFk = n.id
+ LEFT JOIN awb a ON a.id = iia.awbFk
+ WHERE iie.percentage
+ GROUP BY i.id;
+
+ -- Iva Importacion pendiente
+
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONCEPTO,
+ EUROHABER,-- EURODEBE
+ SERIE,
+ empresa_id)
+
+ SELECT
+ vBookNumber,
+ a.bookEntried,
+ '4700000999',
+ n.conceptWithSupplier,
+ ROUND(SUM(iii.amount * (tc.rate/100)),2) eurohaber,
+ n.serial,
+ n.companyFk
+ FROM newInvoiceIn n
+ JOIN invoiceInIntrastat iii ON n.id = iii.invoiceInFk
+ JOIN intrastat ii ON ii.id = iii.intrastatFk
+ JOIN taxCode tc ON tc.id = ii.taxCodeFk
+ JOIN invoiceInAwb iia ON iia.invoiceInFk = iii.invoiceInFk
+ JOIN awb a ON a.id = iia.awbFk
+ HAVING eurohaber IS NOT NULL;
+
+ -- Linea iva importacion extracomunitaria
+
+ SET @cont:=1;
+ SET @total:=0;
+
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EURODEBE,
+ BASEEURO,
+ CONCEPTO,
+ FACTURA,
+ IVA,
+ AUXILIAR,
+ SERIE,
+ FECHA_EX,
+ FECHA_OP,
+ FACTURAEX,
+ NFACTICK,
+ L340,
+ LDIFADUAN,
+ TIPOCLAVE,
+ TIPOEXENCI,
+ TIPONOSUJE,
+ TIPOFACT,
+ TIPORECTIF,
+ TERIDNIF,
+ TERNIF,
+ TERNOM,
+ empresa_id,
+ FECREGCON
+ )
+
+ SELECT
+ vBookNumber ASIEN,
+ x.FECHA,
+ x.SUBCTA,
+ x.CONTRA,
+ IF (n.isSameCountry OR NOT s.isUeeMember,
+ x.EURODEBE,
+ NULL
+ ) EURODEBE,
+ x.BASEEURO,
+ x.CONCEPTO,
+ vSerialNumber FACTURA,
+ x.IVA,
+ '*' AUXILIAR,
+ x.SERIE,
+ x.FECHA_EX,
+ x.FECHA_OP,
+ x.dua FACTURAEX,
+ n.invoicesCount NFACTICK,
+ IF(@total:=@total + x.EURODEBE AND @cont:=@cont + 1 ,1,1) L340,
+ TRUE LDIFADUAN,
+ x.TIPOCLAVE,
+ n.cplusTaxBreakFk TIPOEXENCI,
+ n.cplusSubjectOpFk TIPONOSUJE,
+ 5 TIPOFACT,
+ n.cplusRectificationTypeFk TIPORECTIF,
+ x.TERIDNIF,
+ x.TERNIF,
+ x.TERNOM,
+ n.companyFk,
+ IFNULL(x.FECREGCON,n.booked) FECREGCON
+
+ FROM newInvoiceIn n
+ JOIN newSupplier s
+ JOIN (
+ SELECT
+ -- CONCAT('COMPRA s/fra ',sref,':',LEFT(p.Proveedor, 10))
+ CONCAT('COMPRA s/fra ',ii.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
+ tc.code SUBCTA,
+ s.account CONTRA,
+ tc.rate IVA,
+ ROUND(sum(b.buyingValue * b.quantity / intraSub.intrastatSum * taxSub.amount)*(tc.rate/100),2) EURODEBE,
+ ROUND(sum(b.buyingValue * b.quantity / intraSub.intrastatSum * taxSub.amount),2) BASEEURO,
+ ii.serial SERIE,
+ e.supplierFk,
+ iia.dua,
+ iis.cplusTerIdNifFk TERIDNIF,
+ s.nif AS TERNIF,
+ s.name AS TERNOM,
+ ii.booked FECREGCON,
+ ii.cplusTrascendency472Fk TIPOCLAVE,
+ a.issued FECHA_EX,
+ a.operated FECHA_OP,
+ a.bookEntried FECHA
+ FROM invoiceInAwb iia
+ JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = iia.invoiceInFk
+ JOIN awb a ON a.id = iia.awbFk
+ JOIN invoiceIn ii ON ii.id = iie.invoiceInFk
+ JOIN invoiceInSerial iis ON iis.code = ii.serial
+ JOIN buy b ON b.entryFk = iie.entryFk
+ JOIN item i ON i.id = b.itemFk
+ JOIN (
+ SELECT
+ i.intrastatFk,
+ sum(b.buyingValue * b.quantity) as intrastatSum
+ FROM buy b
+ JOIN item i ON i.id = b.itemFk
+ JOIN invoiceInEntry iie ON iie.entryFk = b.entryFk
+ JOIN invoiceInAwb iia ON iia.invoiceInFk = iie.invoiceInAwbFk
+ JOIN awb aw ON aw.id =iia.awbFk
+ WHERE iie.percentage AND iia.invoiceInFk = vInvoiceInId
+ GROUP BY i.intrastatFk
+ ) intraSub ON intraSub.intrastatFk = i.intrastatFk
+ JOIN (
+ SELECT
+ iii.intrastatFk,
+ iii.amount,
+ intr.taxCodeFk
+ FROM invoiceInIntrastat iii
+ JOIN intrastat intr ON intr.id = iii.intrastatFk
+ WHERE iii.invoiceInFk = vInvoiceInId
+ ) taxSub ON taxSub.intrastatFk = i.intrastatFk
+ JOIN taxCode tc ON tc.id = taxSub.taxCodeFk
+ JOIN entry e ON e.id = iie.entryFk
+ JOIN supplier s ON s.id = e.supplierFk
+ WHERE iie.invoiceInAwbFk = vInvoiceInId AND iie.percentage
+ GROUP BY e.supplierFk, taxSub.taxCodeFk
+ ) x
+ GROUP BY x.supplierFk, x.IVA;
+
+ /*UPDATE newInvoiceIn n
+ JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = vInvoiceInId
+ JOIN invoiceIn ii ON ii.id = iie.invoiceInFk
+ SET ii.isBooked = TRUE,
+ ii.booked = IFNULL(ii.booked,n.booked),
+ ii.operated = IFNULL(ii.operated,n.operated),
+ ii.issued = IFNULL(ii.issued,n.issued);*/
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `invoiceInBookingkk` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceInBookingkk`(vInvoiceInId INT)
+BEGIN
+ /* OBSOLETO usar invoiceInBookingMain o invoiceInBookingExtra */
+ DECLARE vSerialNumber, vBookNumber, vBookNumberPlus1 INT;
+ DECLARE vTotalAmount DECIMAL(10,2);
+
+ DROP TEMPORARY TABLE IF EXISTS newInvoiceIn;
+
+ CREATE TEMPORARY TABLE newInvoiceIn
+ SELECT
+ i.*,
+ YEAR(i.booked) datedYear,
+ -- CONCAT('s/fra',RIGHT(i.supplierRef,8)) concept,
+ CONCAT('s/fra',RIGHT(i.supplierRef,8),':',LEFT(s.name, 10)) conceptWithSupplier,
+ (cc.id = c.id) isSameCountry,
+ cit.id invoicesCount
+ FROM invoiceIn i
+ JOIN cplusInvoiceType472 cit ON cit.id = i.cplusInvoiceType472Fk
+ JOIN supplier s ON s.id = i.supplierFk
+ JOIN country c ON c.id = s.countryFk
+ JOIN supplier sc ON sc.id = i.companyFk
+ JOIN country cc ON cc.id = sc.countryFk
+ WHERE i.id = vInvoiceInId;
+
+ DROP TEMPORARY TABLE IF EXISTS newSupplier;
+ CREATE TEMPORARY TABLE newSupplier
+ SELECT
+ s.*,
+ REPLACE(s.account,' ','') supplierAccount,
+ IF(c.CEE < 2, TRUE, FALSE) isUeeMember
+ FROM supplier s
+ JOIN newInvoiceIn n
+ JOIN country c ON c.id = s.countryFk
+ WHERE s.id = n.supplierFk;
+
+ IF (SELECT isActive FROM newSupplier) = 0 THEN
+ CALL util.throw('INACTIVE_PROVIDER');
+ END IF;
+
+ SELECT IFNULL(MAX(i.serialNumber) + 1,1)
+ INTO vSerialNumber
+ FROM invoiceIn i
+ JOIN newInvoiceIn n
+ WHERE i.serial LIKE n.serial
+ AND YEAR(i.booked) = n.datedYear
+ AND i.companyFk = n.companyFk
+ GROUP BY i.companyFk;
+
+ SELECT MAX(ASIEN) + 1
+ INTO vBookNumber
+ FROM vn2008.XDiario;
+
+ SET vBookNumberPlus1 = vBookNumber + 1;
+
+ SELECT SUM(iit.taxableBase * IF(i.serial = 'R', 1 +(tc.rate/100),1))
+ INTO vTotalAmount
+ FROM invoiceIn i
+ JOIN invoiceInTax iit ON iit.invoiceInFk = i.id
+ JOIN taxCode tc ON iit.taxCodeFk = tc.id
+ WHERE i.id = vInvoiceInId;
+
+ -- Apunte del proveedor
+
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ EUROHABER,
+ CONCEPTO,
+ NFACTICK,
+ empresa_id)
+ SELECT
+ vBookNumber,
+ n.booked,
+ s.supplierAccount,
+ vTotalAmount,
+ n.conceptWithSupplier,
+ n.invoicesCount,
+ n.companyFk
+ FROM newInvoiceIn n
+ JOIN newSupplier s;
+
+ -- ----------------------------------------------------------- Linea de Gastos
+ INSERT INTO vn2008.XDiario (
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EURODEBE,
+ EUROHABER,
+ CONCEPTO,
+ NFACTICK,
+ empresa_id
+ )
+ SELECT
+ vBookNumber ASIEN,
+ n.booked FECHA,
+ if(
+ e.isWithheld,
+ LPAD(RIGHT(s.supplierAccount ,5),10,iit.expenceFk),
+ iit.expenceFk
+ ) SUBCTA,
+ s.supplierAccount CONTRA,
+ if(
+ e.isWithheld,
+ NULL,
+ ABS(ROUND(SUM(iit.taxableBase),2))
+ ) EURODEBE,
+ if(
+ e.isWithheld,
+ ABS(ROUND(SUM(iit.taxableBase),2)),
+ NULL
+ ) EUROHABER,
+ n.conceptWithSupplier CONCEPTO,
+ n.invoicesCount NFACTICK,
+ n.companyFk empresa_id
+ FROM newInvoiceIn n
+ JOIN newSupplier s
+ JOIN invoiceInTax iit ON iit.invoiceInFk = n.id
+ JOIN taxCode tc ON tc.id = iit.taxCodeFk
+ JOIN expence e ON e.id = iit.expenceFk AND e.taxTypeFk = tc.taxTypeFk
+ WHERE iit.expenceFk != 5660000002
+ GROUP BY iit.expenceFk;
+
+ -- Extracomunitarias gasto contra proveedor/acreedor
+ INSERT INTO vn2008.XDiario (
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EURODEBE,
+ CONCEPTO,
+ NFACTICK,
+ empresa_id
+ )
+ SELECT
+ vBookNumberPlus1 ASIEN,
+ IFNULL(a.booked, n.booked) FECHA,
+ iit.expenceFk SUBCTA,
+ s.account CONTRA,
+ ROUND(SUM(iit.taxableBase) * (iie.percentage / 100),2) EURODEBE,
+ CONCAT('COMPRA s/fra ',i.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
+ n.invoicesCount NFACTICK,
+ n.companyFk empresa_id
+ FROM newInvoiceIn n
+ JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = n.id
+ JOIN invoiceInTax iit ON iit.invoiceInFk = iie.invoiceInFk
+ JOIN invoiceIn i ON i.id = iit.invoiceInFk
+ JOIN supplier s ON s.id = i.supplierFk
+ LEFT JOIN invoiceInAwb iia ON iia.invoiceInFk = n.id
+ LEFT JOIN awb a ON a.id = iia.awbFk
+ WHERE iie.percentage
+ GROUP BY i.id;
+
+ -- Extracomunitarias proveedor contra gasto
+ INSERT INTO vn2008.XDiario (
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EUROHABER,
+ CONCEPTO,
+ NFACTICK,
+ empresa_id
+ )
+ SELECT
+ vBookNumberPlus1 ASIEN,
+ IFNULL(a.booked, n.booked) FECHA,
+ s.account SUBCTA,
+ iit.expenceFk CONTRA,
+ ROUND(SUM(iit.taxableBase) * (iie.percentage / 100),2) EUROHABER,
+ CONCAT('COMPRA s/fra ',i.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
+ n.invoicesCount NFACTICK,
+ n.companyFk empresa_id
+ FROM newInvoiceIn n
+ JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = n.id
+ JOIN invoiceInTax iit ON iit.invoiceInFk = iie.invoiceInFk
+ JOIN invoiceIn i ON i.id = iit.invoiceInFk
+ JOIN supplier s ON s.id = i.supplierFk
+ LEFT JOIN invoiceInAwb iia ON iia.invoiceInFk = n.id
+ LEFT JOIN awb a ON a.id = iia.awbFk
+ WHERE iie.percentage
+ GROUP BY i.id;
+
+ -- --------------------------------------------------------------------
+ -- ------- Lineas de IVA ---------------
+ -- --------------------------------------------------------------------
+
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EURODEBE,
+ BASEEURO,
+ CONCEPTO,
+ FACTURA,
+ IVA,
+ AUXILIAR,
+ SERIE,
+ TIPOOPE,
+ FECHA_EX,
+ FECHA_OP,
+ NFACTICK,
+ FACTURAEX,
+ L340,
+ LRECT349,
+ TIPOCLAVE,
+ TIPOEXENCI,
+ TIPONOSUJE,
+ TIPOFACT,
+ TIPORECTIF,
+ TERIDNIF,
+ TERNIF,
+ TERNOM,
+ FECREGCON,
+ empresa_id
+ )
+ SELECT vBookNumber ASIEN,
+ n.booked FECHA,
+ tc.code SUBCTA,
+ s.supplierAccount CONTRA,
+ SUM(ROUND(tc.rate/100*it.taxableBase + 0.0001,2)) EURODEBE,
+ SUM(it.taxableBase) BASEEURO,
+ GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO,
+ vSerialNumber FACTURA,
+ tc.rate IVA,
+ IF(isUeeMember AND eWithheld.id IS NULL,'','*') AUXILIAR,
+ n.serial SERIE,
+ tt.TIPOOPE,
+ n.issued FECHA_EX,
+ n.operated FECHA_OP,
+ n.invoicesCount NFACTICK,
+ n.supplierRef FACTURAEX,
+ TRUE L340,
+ (isSameCountry OR NOT isUeeMember) LRECT349,
+ n.cplusTrascendency472Fk TIPOCLAVE,
+ n.cplusTaxBreakFk TIPOEXENCI,
+ n.cplusSubjectOpFk TIPONOSUJE,
+ n.cplusInvoiceType472Fk TIPOFACT,
+ n.cplusRectificationTypeFk TIPORECTIF,
+ iis.cplusTerIdNifFk TERIDNIF,
+ s.nif AS TERNIF,
+ s.name AS TERNOM,
+ n.booked FECREGCON,
+ n.companyFk
+
+ FROM newInvoiceIn n
+ JOIN newSupplier s
+ JOIN invoiceInTax it ON n.id = it.invoiceInFk
+ JOIN taxCode tc ON tc.id = it.taxCodeFk
+ JOIN taxType tt ON tt.id = tc.taxTypeFk
+ JOIN invoiceInSerial iis ON iis.code = tt.serial
+ JOIN expence e ON e.id = it.expenceFk AND e.taxTypeFk = tc.taxTypeFk
+ LEFT JOIN
+ (SELECT eWithheld.id
+ FROM invoiceInTax hold
+ JOIN expence eWithheld ON eWithheld.id = hold.expenceFk AND eWithheld.isWithheld
+ WHERE hold.invoiceInFk = 58262 LIMIT 1
+ ) eWithheld ON TRUE
+ WHERE tc.type != '-'
+ AND tc.isActive
+ GROUP BY tc.rate;
+
+ -- Linea iva inversor sujeto pasivo
+
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EUROHABER,
+ BASEEURO,
+ CONCEPTO,
+ FACTURA,
+ IVA,
+ AUXILIAR,
+ SERIE,
+ TIPOOPE,
+ FECHA_EX,
+ FECHA_OP,
+ NFACTICK,
+ FACTURAEX,
+ L340,
+ LRECT349,
+ TIPOCLAVE,
+ TIPOEXENCI,
+ TIPONOSUJE,
+ TIPOFACT,
+ TIPORECTIF,
+ TERIDNIF,
+ TERNIF,
+ TERNOM,
+ empresa_id
+ )
+
+ SELECT
+ vBookNumber ASIEN,
+ n.booked FECHA,
+ tcLink.code SUBCTA,
+ s.supplierAccount CONTRA,
+ ROUND(tcLink.rate/100*SUM(it.taxableBase) + 0.0001,2) EUROHABER,
+ ROUND(SUM(it.taxableBase),2) BASEEURO,
+ GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO,
+ vSerialNumber FACTURA,
+ tcLink.rate IVA,
+ '*' AUXILIAR,
+ n.serial SERIE,
+ tt.TIPOOPE,
+ n.issued FECHA_EX,
+ n.operated FECHA_OP,
+ n.invoicesCount NFACTICK,
+ n.supplierRef FACTURAEX,
+ FALSE L340,
+ (isSameCountry OR NOT isUeeMember) LRECT349,
+ 1 TIPOCLAVE,
+ n.cplusTaxBreakFk TIPOEXENCI,
+ n.cplusSubjectOpFk TIPONOSUJE,
+ n.cplusInvoiceType472Fk TIPOFACT,
+ n.cplusRectificationTypeFk TIPORECTIF,
+ iis.cplusTerIdNifFk TERIDNIF,
+ s.nif AS TERNIF,
+ s.name AS TERNOM,
+ n.companyFk
+
+ FROM newInvoiceIn n
+ JOIN newSupplier s
+ JOIN invoiceInTax it ON n.id = it.invoiceInFk
+ JOIN taxCode tc ON tc.id = it.taxCodeFk
+ JOIN taxType tt ON tt.id = tc.taxTypeFk
+ JOIN invoiceInSerial iis ON iis.code = tt.serial
+ JOIN taxCode tcLink ON tcLink.linkFk = tc.linkFk AND tc.id != tcLink.id
+ JOIN expence e ON e.id = it.expenceFk AND e.taxTypeFk = tc.taxTypeFk
+ WHERE tc.isActive
+ GROUP BY tcLink.rate, e.id;
+
+ -- Iva Importacion pendiente
+
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONCEPTO,
+ EUROHABER,-- EURODEBE
+ SERIE,
+ empresa_id)
+
+ SELECT
+ vBookNumberPlus1,
+ a.booked,
+ '4700000999',
+ n.conceptWithSupplier,
+ ROUND(SUM(iii.amount * (tc.rate/100)),2) eurohaber,
+ n.serial,
+ n.companyFk
+ FROM newInvoiceIn n
+ JOIN invoiceInIntrastat iii ON n.id = iii.invoiceInFk
+ JOIN intrastat ii ON ii.id = iii.intrastatFk
+ JOIN taxCode tc ON tc.id = ii.taxCodeFk
+ JOIN invoiceInAwb iia ON iia.invoiceInFk = iii.invoiceInFk
+ JOIN awb a ON a.id = iia.awbFk
+ HAVING eurohaber IS NOT NULL;
+
+
+ -- Linea iva importacion extracomunitaria
+
+ SET @cont:=1;
+ SET @total:=0;
+ SET @base:=2;
+
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EURODEBE,
+ BASEEURO,
+ CONCEPTO,
+ FACTURA,
+ IVA,
+ AUXILIAR,
+ SERIE,
+ FECHA_EX,
+ FECHA_OP,
+ FACTURAEX,
+ NFACTICK,
+ L340,
+ LDIFADUAN,
+ TIPOCLAVE,
+ TIPOEXENCI,
+ TIPONOSUJE,
+ TIPOFACT,
+ TIPORECTIF,
+ TERIDNIF,
+ TERNIF,
+ TERNOM,
+ empresa_id,
+ FECREGCON
+ )
+
+ SELECT
+ vBookNumberPlus1 ASIEN,
+ x.FECHA,
+ x.SUBCTA,
+ x.CONTRA,
+ IF (n.isSameCountry OR NOT s.isUeeMember,
+ x.EURODEBE,
+ NULL
+ ) EURODEBE,
+ x.BASEEURO,
+ x.CONCEPTO,
+ vSerialNumber FACTURA,
+ x.IVA,
+ '*' AUXILIAR,
+ x.SERIE,
+ x.FECHA_EX,
+ x.FECHA_OP,
+ x.dua FACTURAEX,
+ n.invoicesCount NFACTICK,
+ IF(@total:=@total + x.EURODEBE AND @cont:=@cont + 1 ,1,1) L340,
+ TRUE LDIFADUAN,
+ x.TIPOCLAVE,
+ n.cplusTaxBreakFk TIPOEXENCI,
+ n.cplusSubjectOpFk TIPONOSUJE,
+ 5 TIPOFACT,
+ n.cplusRectificationTypeFk TIPORECTIF,
+ x.TERIDNIF,
+ x.TERNIF,
+ x.TERNOM,
+ n.companyFk,
+ IFNULL(x.FECREGCON,n.booked) FECREGCON
+
+ FROM newInvoiceIn n
+ JOIN newSupplier s
+ JOIN (
+ SELECT
+ -- CONCAT('COMPRA s/fra ',sref,':',LEFT(p.Proveedor, 10))
+ CONCAT('COMPRA s/fra ',ii.supplierRef,':',LEFT(s.name, 10)) CONCEPTO,
+ tc.code SUBCTA,
+ s.account CONTRA,
+ tc.rate IVA,
+ ROUND(sum(b.buyingValue * b.quantity / intraSub.intrastatSum * taxSub.amount)*(tc.rate/100),2) EURODEBE,
+ ROUND(sum(b.buyingValue * b.quantity / intraSub.intrastatSum * taxSub.amount),2) BASEEURO,
+ ii.serial SERIE,
+ e.supplierFk,
+ iia.dua,
+ iis.cplusTerIdNifFk TERIDNIF,
+ s.nif AS TERNIF,
+ s.name AS TERNOM,
+ ii.booked FECREGCON,
+ ii.cplusTrascendency472Fk TIPOCLAVE,
+ a.issued FECHA_EX,
+ a.operated FECHA_OP,
+ a.booked FECHA
+ FROM invoiceInAwb iia
+ JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = iia.invoiceInFk
+ JOIN awb a ON a.id = iia.awbFk
+ JOIN invoiceIn ii ON ii.id = iie.invoiceInFk
+ JOIN invoiceInSerial iis ON iis.code = ii.serial
+ JOIN buy b ON b.entryFk = iie.entryFk
+ JOIN item i ON i.id = b.itemFk
+ JOIN (
+ SELECT
+ i.intrastatFk,
+ sum(b.buyingValue * b.quantity) as intrastatSum
+ FROM buy b
+ JOIN item i ON i.id = b.itemFk
+ JOIN invoiceInEntry iie
+ ON iie.entryFk = b.entryFk
+ JOIN invoiceInAwb iia
+ ON iia.invoiceInFk = iie.invoiceInAwbFk
+ JOIN awb aw ON aw.id =iia.awbFk
+ WHERE iie.percentage AND iia.invoiceInFk = vInvoiceInId
+ GROUP BY i.intrastatFk
+ ) intraSub ON intraSub.intrastatFk = i.intrastatFk
+ JOIN (
+ SELECT
+ iii.intrastatFk,
+ iii.amount,
+ intr.taxCodeFk
+ FROM invoiceInIntrastat iii
+ JOIN intrastat intr
+ ON intr.id = iii.intrastatFk
+ WHERE iii.invoiceInFk = vInvoiceInId
+ ) taxSub ON taxSub.intrastatFk = i.intrastatFk
+ JOIN taxCode tc ON tc.id = taxSub.taxCodeFk
+ JOIN entry e ON e.id = iie.entryFk
+ JOIN supplier s ON s.id = e.supplierFk
+ WHERE iie.invoiceInAwbFk = vInvoiceInId AND iie.percentage
+ GROUP BY e.supplierFk, taxSub.taxCodeFk
+ ) x
+ GROUP BY x.supplierFk, x.IVA;
+
+ -- Actualizacion de la fecha de contabilizado y de operacion de las importaciones
+ UPDATE newInvoiceIn n
+ JOIN invoiceInEntry iie ON iie.invoiceInAwbFk = vInvoiceInId
+ JOIN invoiceIn ii ON ii.id = iie.invoiceInFk
+ SET ii.booked = IFNULL(ii.booked,n.booked),
+ ii.operated = IFNULL(ii.operated,n.issued);
+
+ -- Actualización del registro original
+ UPDATE invoiceIn
+ SET
+ serialNumber = vSerialNumber,
+ isBooked = TRUE
+ WHERE
+ id = vInvoiceInId;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `invoiceInBookingMain` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceInBookingMain`(vInvoiceInId INT)
+BEGIN
+ DECLARE vTotalAmount,vTotalAmountDivisa DECIMAL(10,2);
+ DECLARE vBookNumber,vSerialNumber INT;
+ DECLARE vRate DECIMAL(10,4);
+
+ CALL invoiceInBookingCommon(vInvoiceInId,vSerialNumber);
+
+ SELECT SUM(iit.taxableBase * IF(i.serial = 'R', 1 +(tc.rate/100),1)),
+ SUM(iit.foreignValue * IF(i.serial = 'R', 1 +(tc.rate/100),1)),
+ iit.taxableBase/iit.foreignValue
+ INTO vTotalAmount, vTotalAmountDivisa, vRate
+ FROM newInvoiceIn i
+ JOIN invoiceInTax iit ON iit.invoiceInFk = i.id
+ JOIN taxCode tc ON iit.taxCodeFk = tc.id;
+
+ SELECT MAX(ASIEN) + 1
+ INTO vBookNumber
+ FROM vn2008.XDiario;
+
+ -- Apunte del proveedor
+
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ EUROHABER,
+ CONCEPTO,
+ CAMBIO,
+ HABERME,
+ NFACTICK,
+ empresa_id)
+ SELECT
+ vBookNumber,
+ n.bookEntried,
+ s.supplierAccount,
+ vTotalAmount,
+ n.conceptWithSupplier,
+ vRate,
+ vTotalAmountDivisa,
+ n.invoicesCount,
+ n.companyFk
+ FROM newInvoiceIn n
+ JOIN newSupplier s;
+
+ -- ----------------------------------------------------------- Linea de Gastos
+ INSERT INTO vn2008.XDiario (
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EURODEBE,
+ EUROHABER,
+ CONCEPTO,
+ CAMBIO,
+ DEBEME,
+ HABERME,
+ NFACTICK,
+ empresa_id
+ )
+ SELECT
+ vBookNumber ASIEN,
+ n.bookEntried FECHA,
+ if(
+ e.isWithheld,
+ LPAD(RIGHT(s.supplierAccount,5),10,iit.expenceFk),
+ iit.expenceFk
+ ) SUBCTA,
+ s.supplierAccount CONTRA,
+ if(
+ e.isWithheld,
+ NULL,
+ ABS(ROUND(SUM(iit.taxableBase),2))
+ ) EURODEBE,
+ if(
+ e.isWithheld,
+ ABS(ROUND(SUM(iit.taxableBase),2)),
+ NULL
+ ) EUROHABER,
+ n.conceptWithSupplier CONCEPTO,
+ vRate,
+ if(
+ e.isWithheld,
+ NULL,
+ ABS(ROUND(SUM(iit.foreignValue),2))
+ ) DEBEME,
+ if(
+ e.isWithheld,
+ ABS(ROUND(SUM(iit.foreignValue),2)),
+ NULL
+ ) HABERME,
+ n.invoicesCount NFACTICK,
+ n.companyFk empresa_id
+ FROM newInvoiceIn n
+ JOIN newSupplier s
+ JOIN invoiceInTax iit ON iit.invoiceInFk = n.id
+ JOIN taxCode tc ON tc.id = iit.taxCodeFk
+ JOIN expence e ON e.id = iit.expenceFk AND e.taxTypeFk = tc.taxTypeFk
+ WHERE iit.expenceFk != 5660000002
+ GROUP BY iit.expenceFk;
+
+
+ -- --------------------------------------------------------------------
+ -- ------- Lineas de IVA ---------------
+ -- --------------------------------------------------------------------
+
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EURODEBE,
+ BASEEURO,
+ CONCEPTO,
+ FACTURA,
+ IVA,
+ AUXILIAR,
+ SERIE,
+ TIPOOPE,
+ FECHA_EX,
+ FECHA_OP,
+ NFACTICK,
+ FACTURAEX,
+ L340,
+ LRECT349,
+ TIPOCLAVE,
+ TIPOEXENCI,
+ TIPONOSUJE,
+ TIPOFACT,
+ TIPORECTIF,
+ TERIDNIF,
+ TERNIF,
+ TERNOM,
+ FECREGCON,
+ empresa_id
+ )
+ SELECT vBookNumber ASIEN,
+ n.bookEntried FECHA,
+ tc.code SUBCTA,
+ s.supplierAccount CONTRA,
+ SUM(ROUND(tc.rate/100*it.taxableBase + 0.0001,2)) EURODEBE,
+ SUM(it.taxableBase) BASEEURO,
+ GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO,
+ vSerialNumber FACTURA,
+ tc.rate IVA,
+ IF(isUeeMember AND eWithheld.id IS NULL,'','*') AUXILIAR,
+ n.serial SERIE,
+ tt.TIPOOPE,
+ n.issued FECHA_EX,
+ n.operated FECHA_OP,
+ n.invoicesCount NFACTICK,
+ n.supplierRef FACTURAEX,
+ TRUE L340,
+ (isSameCountry OR NOT isUeeMember) LRECT349,
+ n.cplusTrascendency472Fk TIPOCLAVE,
+ n.cplusTaxBreakFk TIPOEXENCI,
+ n.cplusSubjectOpFk TIPONOSUJE,
+ n.cplusInvoiceType472Fk TIPOFACT,
+ n.cplusRectificationTypeFk TIPORECTIF,
+ iis.cplusTerIdNifFk TERIDNIF,
+ s.nif AS TERNIF,
+ s.name AS TERNOM,
+ n.booked FECREGCON,
+ n.companyFk
+
+ FROM newInvoiceIn n
+ JOIN newSupplier s
+ JOIN invoiceInTax it ON n.id = it.invoiceInFk
+ JOIN taxCode tc ON tc.id = it.taxCodeFk
+ JOIN taxType tt ON tt.id = tc.taxTypeFk
+ JOIN invoiceInSerial iis ON iis.code = tt.serial
+ JOIN expence e ON e.id = it.expenceFk AND e.taxTypeFk = tc.taxTypeFk
+ LEFT JOIN
+ (SELECT eWithheld.id
+ FROM invoiceInTax hold
+ JOIN expence eWithheld ON eWithheld.id = hold.expenceFk AND eWithheld.isWithheld
+ WHERE hold.invoiceInFk = 58262 LIMIT 1
+ ) eWithheld ON TRUE
+ WHERE tc.type != '-'
+ AND tc.isActive
+ GROUP BY tc.rate;
+
+ -- Linea iva inversor sujeto pasivo
+
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EUROHABER,
+ BASEEURO,
+ CONCEPTO,
+ FACTURA,
+ IVA,
+ AUXILIAR,
+ SERIE,
+ TIPOOPE,
+ FECHA_EX,
+ FECHA_OP,
+ NFACTICK,
+ FACTURAEX,
+ L340,
+ LRECT349,
+ TIPOCLAVE,
+ TIPOEXENCI,
+ TIPONOSUJE,
+ TIPOFACT,
+ TIPORECTIF,
+ TERIDNIF,
+ TERNIF,
+ TERNOM,
+ empresa_id
+ )
+
+ SELECT
+ vBookNumber ASIEN,
+ n.bookEntried FECHA,
+ tcLink.code SUBCTA,
+ s.supplierAccount CONTRA,
+ ROUND(tcLink.rate/100*SUM(it.taxableBase) + 0.0001,2) EUROHABER,
+ ROUND(SUM(it.taxableBase),2) BASEEURO,
+ GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO,
+ vSerialNumber FACTURA,
+ tcLink.rate IVA,
+ '*' AUXILIAR,
+ n.serial SERIE,
+ tt.TIPOOPE,
+ n.issued FECHA_EX,
+ n.operated FECHA_OP,
+ n.invoicesCount NFACTICK,
+ n.supplierRef FACTURAEX,
+ FALSE L340,
+ (isSameCountry OR NOT isUeeMember) LRECT349,
+ 1 TIPOCLAVE,
+ n.cplusTaxBreakFk TIPOEXENCI,
+ n.cplusSubjectOpFk TIPONOSUJE,
+ n.cplusInvoiceType472Fk TIPOFACT,
+ n.cplusRectificationTypeFk TIPORECTIF,
+ iis.cplusTerIdNifFk TERIDNIF,
+ s.nif AS TERNIF,
+ s.name AS TERNOM,
+ n.companyFk
+
+ FROM newInvoiceIn n
+ JOIN newSupplier s
+ JOIN invoiceInTax it ON n.id = it.invoiceInFk
+ JOIN taxCode tc ON tc.id = it.taxCodeFk
+ JOIN taxType tt ON tt.id = tc.taxTypeFk
+ JOIN invoiceInSerial iis ON iis.code = tt.serial
+ JOIN taxCode tcLink ON tcLink.linkFk = tc.linkFk AND tc.id != tcLink.id
+ JOIN expence e ON e.id = it.expenceFk AND e.taxTypeFk = tc.taxTypeFk
+ WHERE tc.isActive
+ GROUP BY tcLink.rate, e.id;
+
+-- Actualización del registro original
+ UPDATE invoiceIn ii
+ JOIN newInvoiceIn ni ON ii.id = ni.id
+ SET
+ ii.serialNumber = vSerialNumber,
+ ii.isBooked = 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 `invoiceInBookingMainkk` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceInBookingMainkk`(vInvoiceInId INT)
+BEGIN
+ DECLARE vTotalAmount DECIMAL(10,2);
+ DECLARE vBookNumber,vSerialNumber INT;
+
+ CALL invoiceInBookingCommon(vInvoiceInId,vSerialNumber);
+
+ SELECT SUM(iit.taxableBase * IF(i.serial = 'R', 1 +(tc.rate/100),1))
+ INTO vTotalAmount
+ FROM newInvoiceIn i
+ JOIN invoiceInTax iit ON iit.invoiceInFk = i.id
+ JOIN taxCode tc ON iit.taxCodeFk = tc.id;
+
+ SELECT MAX(ASIEN) + 1
+ INTO vBookNumber
+ FROM vn2008.XDiario;
+
+ -- Apunte del proveedor
+
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ EUROHABER,
+ CONCEPTO,
+ NFACTICK,
+ empresa_id)
+ SELECT
+ vBookNumber,
+ n.bookEntried,
+ s.supplierAccount,
+ vTotalAmount,
+ n.conceptWithSupplier,
+ n.invoicesCount,
+ n.companyFk
+ FROM newInvoiceIn n
+ JOIN newSupplier s;
+
+ -- ----------------------------------------------------------- Linea de Gastos
+ INSERT INTO vn2008.XDiario (
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EURODEBE,
+ EUROHABER,
+ CONCEPTO,
+ NFACTICK,
+ empresa_id
+ )
+ SELECT
+ vBookNumber ASIEN,
+ n.bookEntried FECHA,
+ if(
+ e.isWithheld,
+ LPAD(RIGHT(s.supplierAccount ,5),10,iit.expenceFk),
+ iit.expenceFk
+ ) SUBCTA,
+ s.supplierAccount CONTRA,
+ if(
+ e.isWithheld,
+ NULL,
+ ABS(ROUND(SUM(iit.taxableBase),2))
+ ) EURODEBE,
+ if(
+ e.isWithheld,
+ ABS(ROUND(SUM(iit.taxableBase),2)),
+ NULL
+ ) EUROHABER,
+ n.conceptWithSupplier CONCEPTO,
+ n.invoicesCount NFACTICK,
+ n.companyFk empresa_id
+ FROM newInvoiceIn n
+ JOIN newSupplier s
+ JOIN invoiceInTax iit ON iit.invoiceInFk = n.id
+ JOIN taxCode tc ON tc.id = iit.taxCodeFk
+ JOIN expence e ON e.id = iit.expenceFk AND e.taxTypeFk = tc.taxTypeFk
+ WHERE iit.expenceFk != 5660000002
+ GROUP BY iit.expenceFk;
+
+
+ -- --------------------------------------------------------------------
+ -- ------- Lineas de IVA ---------------
+ -- --------------------------------------------------------------------
+
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EURODEBE,
+ BASEEURO,
+ CONCEPTO,
+ FACTURA,
+ IVA,
+ AUXILIAR,
+ SERIE,
+ TIPOOPE,
+ FECHA_EX,
+ FECHA_OP,
+ NFACTICK,
+ FACTURAEX,
+ L340,
+ LRECT349,
+ TIPOCLAVE,
+ TIPOEXENCI,
+ TIPONOSUJE,
+ TIPOFACT,
+ TIPORECTIF,
+ TERIDNIF,
+ TERNIF,
+ TERNOM,
+ FECREGCON,
+ empresa_id
+ )
+ SELECT vBookNumber ASIEN,
+ n.bookEntried FECHA,
+ tc.code SUBCTA,
+ s.supplierAccount CONTRA,
+ SUM(ROUND(tc.rate/100*it.taxableBase + 0.0001,2)) EURODEBE,
+ SUM(it.taxableBase) BASEEURO,
+ GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO,
+ vSerialNumber FACTURA,
+ tc.rate IVA,
+ IF(isUeeMember AND eWithheld.id IS NULL,'','*') AUXILIAR,
+ n.serial SERIE,
+ tt.TIPOOPE,
+ n.issued FECHA_EX,
+ n.operated FECHA_OP,
+ n.invoicesCount NFACTICK,
+ n.supplierRef FACTURAEX,
+ TRUE L340,
+ (isSameCountry OR NOT isUeeMember) LRECT349,
+ n.cplusTrascendency472Fk TIPOCLAVE,
+ n.cplusTaxBreakFk TIPOEXENCI,
+ n.cplusSubjectOpFk TIPONOSUJE,
+ n.cplusInvoiceType472Fk TIPOFACT,
+ n.cplusRectificationTypeFk TIPORECTIF,
+ iis.cplusTerIdNifFk TERIDNIF,
+ s.nif AS TERNIF,
+ s.name AS TERNOM,
+ n.booked FECREGCON,
+ n.companyFk
+
+ FROM newInvoiceIn n
+ JOIN newSupplier s
+ JOIN invoiceInTax it ON n.id = it.invoiceInFk
+ JOIN taxCode tc ON tc.id = it.taxCodeFk
+ JOIN taxType tt ON tt.id = tc.taxTypeFk
+ JOIN invoiceInSerial iis ON iis.code = tt.serial
+ JOIN expence e ON e.id = it.expenceFk AND e.taxTypeFk = tc.taxTypeFk
+ LEFT JOIN
+ (SELECT eWithheld.id
+ FROM invoiceInTax hold
+ JOIN expence eWithheld ON eWithheld.id = hold.expenceFk AND eWithheld.isWithheld
+ WHERE hold.invoiceInFk = 58262 LIMIT 1
+ ) eWithheld ON TRUE
+ WHERE tc.type != '-'
+ AND tc.isActive
+ GROUP BY tc.rate;
+
+ -- Linea iva inversor sujeto pasivo
+
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EUROHABER,
+ BASEEURO,
+ CONCEPTO,
+ FACTURA,
+ IVA,
+ AUXILIAR,
+ SERIE,
+ TIPOOPE,
+ FECHA_EX,
+ FECHA_OP,
+ NFACTICK,
+ FACTURAEX,
+ L340,
+ LRECT349,
+ TIPOCLAVE,
+ TIPOEXENCI,
+ TIPONOSUJE,
+ TIPOFACT,
+ TIPORECTIF,
+ TERIDNIF,
+ TERNIF,
+ TERNOM,
+ empresa_id
+ )
+
+ SELECT
+ vBookNumber ASIEN,
+ n.bookEntried FECHA,
+ tcLink.code SUBCTA,
+ s.supplierAccount CONTRA,
+ ROUND(tcLink.rate/100*SUM(it.taxableBase) + 0.0001,2) EUROHABER,
+ ROUND(SUM(it.taxableBase),2) BASEEURO,
+ GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO,
+ vSerialNumber FACTURA,
+ tcLink.rate IVA,
+ '*' AUXILIAR,
+ n.serial SERIE,
+ tt.TIPOOPE,
+ n.issued FECHA_EX,
+ n.operated FECHA_OP,
+ n.invoicesCount NFACTICK,
+ n.supplierRef FACTURAEX,
+ FALSE L340,
+ (isSameCountry OR NOT isUeeMember) LRECT349,
+ 1 TIPOCLAVE,
+ n.cplusTaxBreakFk TIPOEXENCI,
+ n.cplusSubjectOpFk TIPONOSUJE,
+ n.cplusInvoiceType472Fk TIPOFACT,
+ n.cplusRectificationTypeFk TIPORECTIF,
+ iis.cplusTerIdNifFk TERIDNIF,
+ s.nif AS TERNIF,
+ s.name AS TERNOM,
+ n.companyFk
+
+ FROM newInvoiceIn n
+ JOIN newSupplier s
+ JOIN invoiceInTax it ON n.id = it.invoiceInFk
+ JOIN taxCode tc ON tc.id = it.taxCodeFk
+ JOIN taxType tt ON tt.id = tc.taxTypeFk
+ JOIN invoiceInSerial iis ON iis.code = tt.serial
+ JOIN taxCode tcLink ON tcLink.linkFk = tc.linkFk AND tc.id != tcLink.id
+ JOIN expence e ON e.id = it.expenceFk AND e.taxTypeFk = tc.taxTypeFk
+ WHERE tc.isActive
+ GROUP BY tcLink.rate, e.id;
+
+-- Actualización del registro original
+ UPDATE invoiceIn ii
+ JOIN newInvoiceIn ni ON ii.id = ni.id
+ SET
+ ii.serialNumber = vSerialNumber,
+ ii.isBooked = 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 `invoiceMakeByClient` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceMakeByClient`(vClientFk INT, vSerial CHAR(1), vShipped DATE, vCompanyFk INT, OUT vInvoiceId INT)
+BEGIN
+/**
+ * Factura un ticket
+ * @param vTicketFk Id del ticket
+ * @param vSerial Serie de factura
+ * @return Id factura
+ */
+ CALL invoiceFromClient(vShipped, vClientFk, vCompanyFk);
+ CALL invoiceOutMake(vSerial, CURDATE(), vInvoiceId);
+
+ IF vSerial <> 'R' AND NOT ISNULL(vInvoiceId) AND vInvoiceId <> 0 THEN
+ CALL invoiceOutBooking(vInvoiceId);
+ INSERT INTO printServerQueue(priorityFk, reportFk, param1) VALUES(1, 3, vInvoiceId);
+ 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 `invoiceMakeByTicket` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceMakeByTicket`(vTicketFk INT, vSerial CHAR(1), OUT vInvoiceId INT)
+BEGIN
+/**
+ * Factura un ticket
+ * @param vTicketFk Id del ticket
+ * @param vSerial Serie de factura
+ * @return Id factura
+ */
+ CALL invoiceFromTicket(vTicketFk);
+ CALL invoiceOutMake(vSerial, CURDATE(), vInvoiceId);
+
+ IF vSerial <> 'R' AND NOT ISNULL(vInvoiceId) AND vInvoiceId <> 0 THEN
+ CALL invoiceOutBooking(vInvoiceId);
+ INSERT INTO printServerQueue(priorityFk, reportFk, param1) VALUES(1, 3, vInvoiceId);
+ 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 `invoiceOutAgain` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceOutAgain`(IN vInvoiceRef VARCHAR(15))
+BEGIN
+
+/* Para tickets ya facturados, vuelve a repetir el proceso de facturación.
+*
+* @param vInvoice Numero de factura
+*/
+
+ DECLARE vInvoice INT;
+ DECLARE vCountry INT;
+ DECLARE vTaxArea VARCHAR(15);
+ DECLARE vSpainCountryCode INT DEFAULT 1;
+
+ SELECT id
+ INTO vInvoice
+ FROM invoiceOut
+ WHERE ref = vInvoiceRef;
+
+ UPDATE invoiceOut
+ SET pdf = 0
+ WHERE id = vInvoice;
+
+ SELECT s.countryFk
+ INTO vCountry
+ FROM supplier s
+ JOIN invoiceOut io ON io.companyFk = s.id
+ WHERE io.id = vInvoice;
+
+ SELECT IF(a.isEqualizated
+ AND c.countryFk = vSpainCountryCode
+ AND i.taxAreaFk = 'NATIONAL',
+ 'EQU',
+ i.taxAreaFk)
+ INTO vTaxArea
+ FROM invoiceOutSerial i
+ JOIN invoiceOut io
+ JOIN ticket t ON t.refFk = io.ref
+ JOIN address a ON a.id = t.addressFk
+ JOIN client c ON c.id = t.clientFk
+ WHERE io.id = vInvoice AND i.code = invoiceSerial(io.clientFk,io.companyFk,'R')
+ LIMIT 1;
+
+ DROP TEMPORARY TABLE IF EXISTS ticketToInvoice;
+
+ CREATE TEMPORARY TABLE ticketToInvoice
+ SELECT id
+ FROM ticket
+ WHERE refFk = vInvoiceRef;
+
+ CALL invoiceExpenceMake(vInvoice);
+ CALL invoiceTaxMake(vInvoice,vCountry,vTaxArea);
+
+ UPDATE invoiceOut io
+ JOIN (
+ SELECT SUM(amount) AS total
+ FROM invoiceOutExpence
+ WHERE invoiceOutFk = vInvoice
+ ) base
+ JOIN (
+ SELECT SUM(vat) AS total
+ FROM invoiceOutTax
+ WHERE invoiceOutFk = vInvoice
+ ) vat
+ SET io.amount = base.total + vat.total
+ WHERE io.id = vInvoice;
+
+ CALL vn.invoiceOutBooking(vInvoice);
+
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `invoiceOutAgainDateRange` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceOutAgainDateRange`(IN vFirstDate DATE, IN vLastDate DATE)
+BEGIN
+
+ DECLARE done BOOL DEFAULT FALSE;
+ DECLARE vInvoice INT;
+ DECLARE vInvoiceRef VARCHAR(15);
+ DECLARE vContador INT DEFAULT 0;
+
+ DECLARE rs CURSOR FOR
+ SELECT id, ref
+ FROM vn.invoiceOut
+ WHERE issued BETWEEN vFirstDate AND vLastDate
+ AND booked IS NULL;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+
+ OPEN rs;
+
+ FETCH rs INTO vInvoice, vInvoiceRef;
+
+ WHILE NOT done DO
+
+ CALL vn.invoiceOutAgain(vInvoiceRef);
+
+ FETCH rs INTO vInvoice, vInvoiceRef;
+
+ SET vContador = vContador + 1;
+
+ IF vContador MOD 50 = 0 THEN
+
+ SELECT CONCAT(vContador, ' de momento') AS FACTURAS_ASENTADAS;
+
+ END IF;
+ END WHILE;
+
+ CLOSE rs;
+
+ SELECT CONCAT(vContador, ' total') AS FACTURAS_ASENTADAS;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `invoiceOutBooking` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceOutBooking`(IN vInvoice INT)
+BEGIN
+
+/* Asienta la factura emitida
+*
+* param vInvoice factura_id
+*/
+
+ DECLARE vBookNumber INT;
+ DECLARE vExpenceConcept VARCHAR(50);
+ DECLARE isUEENotSpain INT DEFAULT 1;
+ DECLARE vSpain INT DEFAULT 1;
+ DECLARE vOldBookNumber INT;
+
+ SELECT ASIEN
+ INTO vOldBookNumber
+ FROM vn2008.XDiario x
+ JOIN vn.invoiceOut io ON io.id = vInvoice
+ WHERE x.SERIE = io.serial
+ AND x.FACTURA = RIGHT(io.ref, LENGTH(io.ref) - 1)
+ LIMIT 1;
+
+ DELETE
+ FROM vn2008.XDiario
+ WHERE ASIEN = vOldBookNumber;
+
+ DROP TEMPORARY TABLE IF EXISTS rs;
+ CREATE TEMPORARY TABLE rs
+ SELECT
+ c.accountingAccount AS clientBookingAccount,
+ io.amount as totalAmount,
+ CONCAT('n/fra ', io.ref) as simpleConcept,
+ CONCAT('n/fra ', io.ref, ' ', c.name) as Concept,
+ io.serial AS SERIE,
+ io.issued AS FECHA_EX,
+ opDate.FECHA_OP,
+ io.issued AS FECHA,
+ 1 AS NFACTICK,
+ IF(ic.correctingFk,'D','') AS TIPOOPE,
+ io.cplusTrascendency477Fk AS TIPOCLAVE,
+ io.cplusTaxBreakFk AS TIPOEXENCI,
+ io.cplusSubjectOpFk AS TIPONOSUJE,
+ io.cplusInvoiceType477Fk AS TIPOFACT,
+ ic.cplusRectificationTypeFk AS TIPORECTIF,
+ io.companyFk,
+ RIGHT(io.ref, LENGTH(io.ref) - 1) AS invoiceNum,
+ IF(ct.politicalCountryFk = vSpain, 1, IF(ct.CEE = isUEENotSpain,2,4)) AS TERIDNIF,
+ CONCAT(IF(ct.CEE = isUEENotSpain,ct.code,''),c.fi) AS TERNIF,
+ c.socialName AS TERNOM,
+ ior.serial AS SERIE_RT,
+ RIGHT(ior.ref, LENGTH(ior.ref) - 1) AS FACTU_RT,
+ ior.issued AS FECHA_RT,
+ IF(ior.id,TRUE,FALSE) AS RECTIFICA
+
+ FROM invoiceOut io
+ JOIN (
+ SELECT MAX(shipped) as FECHA_OP
+ FROM ticket t
+ JOIN invoiceOut io ON io.ref = t.refFk
+ WHERE io.id = vInvoice ) opDate
+ JOIN invoiceOutSerial ios ON ios.code = io.serial
+ JOIN client c ON c.id = io.clientFk
+ JOIN country ct ON ct.id = c.countryFk
+ LEFT JOIN invoiceCorrection ic ON ic.correctingFk = io.id
+ LEFT JOIN invoiceOut ior ON ior.id = ic.correctedFk
+ WHERE io.id = vInvoice;
+
+ SELECT MAX(ASIEN) + 1
+ INTO vBookNumber
+ FROM vn2008.XDiario;
+
+ -- Linea del cliente
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ EURODEBE,
+ CONCEPTO,
+ FECHA_EX,
+ FECHA_OP,
+ empresa_id
+ )
+ SELECT
+ vBookNumber AS ASIEN,
+ rs.FECHA,
+ rs.clientBookingAccount AS SUBCTA,
+ rs.totalAmount AS EURODEBE,
+ rs.simpleConcept AS CONCEPTO,
+ rs.FECHA_EX,
+ rs.FECHA_OP,
+ rs.companyFk AS empresa_id
+ FROM rs;
+
+ -- Lineas de gasto
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EUROHABER,
+ CONCEPTO,
+ FECHA_EX,
+ FECHA_OP,
+ empresa_id
+ )
+ SELECT
+ vBookNumber AS ASIEN,
+ rs.FECHA,
+ ioe.expenceFk AS SUBCTA,
+ rs.clientBookingAccount AS CONTRA,
+ ioe.amount AS EUROHABER,
+ rs.Concept AS CONCEPTO,
+ rs.FECHA_EX,
+ rs.FECHA_OP,
+ rs.companyFk AS empresa_id
+ FROM rs
+ JOIN invoiceOutExpence ioe
+ WHERE ioe.invoiceOutFk = vInvoice;
+
+ SELECT GROUP_CONCAT(`name` SEPARATOR ',')
+ INTO vExpenceConcept
+ FROM expence e
+ JOIN invoiceOutExpence ioe ON ioe.expenceFk = e.id
+ WHERE ioe.invoiceOutFk = vInvoice;
+
+ -- Lineas de IVA
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EUROHABER,
+ BASEEURO,
+ CONCEPTO,
+ FACTURA,
+ IVA,
+ RECEQUIV,
+ AUXILIAR,
+ SERIE,
+ SERIE_RT,
+ FACTU_RT,
+ RECTIFICA,
+ FECHA_RT,
+ FECHA_OP,
+ FECHA_EX,
+ TIPOOPE,
+ NFACTICK,
+ TERIDNIF,
+ TERNIF,
+ TERNOM,
+ L340,
+ TIPOCLAVE,
+ TIPOEXENCI,
+ TIPONOSUJE,
+ TIPOFACT,
+ TIPORECTIF,
+ empresa_id
+ )
+ SELECT
+ vBookNumber AS ASIEN,
+ rs.FECHA,
+ iot.pgcFk AS SUBCTA,
+ rs.clientBookingAccount AS CONTRA,
+ iot.vat AS EUROHABER,
+ iot.taxableBase AS BASEEURO,
+ CONCAT(vExpenceConcept,' : ',rs.Concept) AS CONCEPTO,
+ rs.invoiceNum AS FACTURA,
+ IF(pe2.equFk,0,pgc.rate) AS IVA,
+ IF(pe2.equFk,0,pgce.rate) AS RECEQUIV,
+ IF(pgc.mod347,'','*') AS AUXILIAR,
+ rs.SERIE,
+ rs.SERIE_RT,
+ rs.FACTU_RT,
+ rs.RECTIFICA,
+ rs.FECHA_RT,
+ rs.FECHA_OP,
+ rs.FECHA_EX,
+ rs.TIPOOPE,
+ rs.NFACTICK,
+ rs.TERIDNIF,
+ rs.TERNIF,
+ rs.TERNOM,
+ pgc.mod340 AS L340,
+ pgc.cplusTrascendency477Fk AS TIPOCLAVE,
+ pgc.cplusTaxBreakFk as TIPOEXENCI,
+ rs.TIPONOSUJE,
+ rs.TIPOFACT,
+ rs.TIPORECTIF,
+ rs.companyFk AS empresa_id
+ FROM rs
+ JOIN invoiceOutTax iot
+ JOIN pgc ON pgc.code = iot.pgcFk
+ LEFT JOIN pgcEqu pe ON pe.vatFk = iot.pgcFk -- --------------- Comprueba si la linea es de iva con rec.equiv. asociado
+ LEFT JOIN pgc pgce ON pgce.code = pe.equFk
+ LEFT JOIN pgcEqu pe2 ON pe2.equFk = iot.pgcFk -- --------------- Comprueba si la linea es de rec.equiv.
+ WHERE iot.invoiceOutFk = vInvoice;
+
+ UPDATE invoiceOut
+ SET booked = CURDATE()
+ WHERE id = vInvoice;
+
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `invoiceOutBookingkk` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceOutBookingkk`(IN vInvoice INT)
+BEGIN
+
+/* Asienta la factura emitida
+*
+* param vInvoice factura_id
+*/
+
+ DECLARE vBookNumber INT;
+ DECLARE vExpenceConcept VARCHAR(50);
+ DECLARE isUEENotSpain INT DEFAULT 1;
+ DECLARE vOldBookNumber INT;
+
+ SELECT ASIEN
+ INTO vOldBookNumber
+ FROM vn2008.XDiario x
+ JOIN vn.invoiceOut io ON io.id = vInvoice
+ WHERE x.SERIE = io.serial
+ AND x.FACTURA = RIGHT(io.ref, LENGTH(io.ref) - 1)
+ LIMIT 1;
+
+ DELETE
+ FROM vn2008.XDiario
+ WHERE ASIEN = vOldBookNumber;
+
+ SELECT MAX(ASIEN) + 1
+ INTO vBookNumber
+ FROM vn2008.XDiario;
+
+ DROP TEMPORARY TABLE IF EXISTS rs;
+ CREATE TEMPORARY TABLE rs
+ SELECT
+ c.accountingAccount AS clientBookingAccount,
+ io.amount as totalAmount,
+ CONCAT('n/fra ', io.ref) as simpleConcept,
+ CONCAT('n/fra ', io.ref, ' ', c.name) as Concept,
+ io.serial AS SERIE,
+ io.issued AS FECHA_EX,
+ opDate.FECHA_OP,
+ io.issued AS FECHA,
+ 1 AS NFACTICK,
+ IF(ic.correctingFk,'D','') AS TIPOOPE,
+ io.cplusTrascendency477Fk AS TIPOCLAVE,
+ io.cplusTaxBreakFk AS TIPOEXENCI,
+ io.cplusSubjectOpFk AS TIPONOSUJE,
+ io.cplusInvoiceType477Fk AS TIPOFACT,
+ ic.cplusRectificationTypeFk AS TIPORECTIF,
+ io.companyFk,
+ RIGHT(io.ref, LENGTH(io.ref) - 1) AS invoiceNum,
+ IF(ct.CEE = 0, 1, IF(ct.CEE = isUEENotSpain,2,4)) AS TERIDNIF,
+ CONCAT(IF(ct.CEE = isUEENotSpain,ct.code,''),c.fi) AS TERNIF,
+ c.socialName AS TERNOM,
+ ior.serial AS SERIE_RT,
+ RIGHT(ior.ref, LENGTH(ior.ref) - 1) AS FACTU_RT,
+ ior.issued AS FECHA_RT,
+ IF(ior.id,TRUE,FALSE) AS RECTIFICA
+
+ FROM invoiceOut io
+ JOIN (
+ SELECT MAX(shipped) as FECHA_OP
+ FROM ticket t
+ JOIN invoiceOut io ON io.ref = t.refFk
+ WHERE io.id = vInvoice ) opDate
+ JOIN invoiceOutSerial ios ON ios.code = io.serial
+ JOIN client c ON c.id = io.clientFk
+ JOIN country ct ON ct.id = c.countryFk
+ LEFT JOIN invoiceCorrection ic ON ic.correctingFk = io.id
+ LEFT JOIN invoiceOut ior ON ior.id = ic.correctedFk
+ WHERE io.id = vInvoice;
+
+ -- Linea del cliente
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ EURODEBE,
+ CONCEPTO,
+ FECHA_EX,
+ FECHA_OP,
+ empresa_id
+ )
+ SELECT
+ vBookNumber AS ASIEN,
+ rs.FECHA,
+ rs.clientBookingAccount AS SUBCTA,
+ rs.totalAmount AS EURODEBE,
+ rs.simpleConcept AS CONCEPTO,
+ rs.FECHA_EX,
+ rs.FECHA_OP,
+ rs.companyFk AS empresa_id
+ FROM rs;
+
+ -- Lineas de gasto
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EUROHABER,
+ CONCEPTO,
+ FECHA_EX,
+ FECHA_OP,
+ empresa_id
+ )
+ SELECT
+ vBookNumber AS ASIEN,
+ rs.FECHA,
+ ioe.expenceFk AS SUBCTA,
+ rs.clientBookingAccount AS CONTRA,
+ ioe.amount AS EUROHABER,
+ rs.Concept AS CONCEPTO,
+ rs.FECHA_EX,
+ rs.FECHA_OP,
+ rs.companyFk AS empresa_id
+ FROM rs
+ JOIN invoiceOutExpence ioe
+ WHERE ioe.invoiceOutFk = vInvoice;
+
+ SELECT GROUP_CONCAT(`name` SEPARATOR ',')
+ INTO vExpenceConcept
+ FROM expence e
+ JOIN invoiceOutExpence ioe ON ioe.expenceFk = e.id
+ WHERE ioe.invoiceOutFk = vInvoice;
+
+ -- Lineas de IVA
+ INSERT INTO vn2008.XDiario(
+ ASIEN,
+ FECHA,
+ SUBCTA,
+ CONTRA,
+ EUROHABER,
+ BASEEURO,
+ CONCEPTO,
+ FACTURA,
+ IVA,
+ RECEQUIV,
+ AUXILIAR,
+ SERIE,
+ SERIE_RT,
+ FACTU_RT,
+ RECTIFICA,
+ FECHA_RT,
+ FECHA_OP,
+ FECHA_EX,
+ TIPOOPE,
+ NFACTICK,
+ TERIDNIF,
+ TERNIF,
+ TERNOM,
+ L340,
+ TIPOCLAVE,
+ TIPOEXENCI,
+ TIPONOSUJE,
+ TIPOFACT,
+ TIPORECTIF,
+ empresa_id
+ )
+ SELECT
+ vBookNumber AS ASIEN,
+ rs.FECHA,
+ iot.pgcFk AS SUBCTA,
+ rs.clientBookingAccount AS CONTRA,
+ iot.vat AS EUROHABER,
+ iot.taxableBase AS BASEEURO,
+ CONCAT(vExpenceConcept,' : ',rs.Concept) AS CONCEPTO,
+ rs.invoiceNum AS FACTURA,
+ IF(pe2.equFk,0,pgc.rate) AS IVA,
+ IF(pe2.equFk,0,pgce.rate) AS RECEQUIV,
+ IF(pgc.mod347,'','*') AS AUXILIAR,
+ rs.SERIE,
+ rs.SERIE_RT,
+ rs.FACTU_RT,
+ rs.RECTIFICA,
+ rs.FECHA_RT,
+ rs.FECHA_OP,
+ rs.FECHA_EX,
+ rs.TIPOOPE,
+ rs.NFACTICK,
+ rs.TERIDNIF,
+ rs.TERNIF,
+ rs.TERNOM,
+ pgc.mod340 AS L340,
+ pgc.cplusTrascendency477Fk AS TIPOCLAVE,
+ pgc.cplusTaxBreakFk as TIPOEXENCI,
+ rs.TIPONOSUJE,
+ rs.TIPOFACT,
+ rs.TIPORECTIF,
+ rs.companyFk AS empresa_id
+ FROM rs
+ JOIN invoiceOutTax iot
+ JOIN pgc ON pgc.code = iot.pgcFk
+ LEFT JOIN pgcEqu pe ON pe.vatFk = iot.pgcFk -- --------------- Comprueba si la linea es de iva con rec.equiv. asociado
+ LEFT JOIN pgc pgce ON pgce.code = pe.equFk
+ LEFT JOIN pgcEqu pe2 ON pe2.equFk = iot.pgcFk -- --------------- Comprueba si la linea es de rec.equiv.
+ WHERE iot.invoiceOutFk = vInvoice;
+
+ UPDATE invoiceOut
+ SET booked = CURDATE()
+ WHERE id = vInvoice;
+
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `invoiceOutBookingRange` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceOutBookingRange`()
+BEGIN
+
+/* Reasentar facturas
+*/
+
+
+ DECLARE vInvoice INT;
+ DECLARE vContador INT DEFAULT 0;
+
+ DECLARE done BOOL DEFAULT FALSE;
+
+ DECLARE rs CURSOR FOR
+ SELECT io.id
+ FROM invoiceOut io
+ WHERE RIGHT(ref,7) BETWEEN 1724215 AND 1724224
+ AND serial = 'T';
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+
+ OPEN rs;
+
+ FETCH rs INTO vInvoice;
+
+ WHILE NOT done DO
+
+ CALL invoiceOutBooking(vInvoice);
+
+ FETCH rs INTO vInvoice ;
+
+ SET vContador = vContador + 1;
+
+ IF vContador MOD 50 = 0 THEN
+
+ SELECT CONCAT(vContador, ' de momento') AS FACTURAS_ASENTADAS;
+
+ END IF;
+
+ END WHILE;
+
+ CLOSE rs;
+
+ SELECT CONCAT(vContador, ' total') AS FACTURAS_ASENTADAS;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `invoiceOutDelete` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceOutDelete`(vRef VARCHAR(15))
+BEGIN
+
+ UPDATE ticket
+ SET refFk = NULL
+ WHERE refFk = vRef;
+
+ DELETE
+ FROM invoiceOut
+ WHERE ref = vRef;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `invoiceOutFix_BI_RE_IVA` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceOutFix_BI_RE_IVA`()
+BEGIN
+
+DECLARE done BOOL DEFAULT FALSE;
+DECLARE vInvoice INT;
+
+DECLARE rs CURSOR FOR
+ SELECT factura_id
+ FROM vn2008.Facturas
+ WHERE Importe != BI7 + BI16 + RE4 + RE1 + IVA7 + IVA16
+ AND Fecha >= '2017-07-01';
+
+DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+
+OPEN rs;
+
+FETCH rs INTO vInvoice;
+
+SELECT vInvoice, done;
+
+WHILE NOT done DO
+
+ UPDATE invoiceOut io
+ JOIN (
+ SELECT SUM(amount) AS total
+ FROM invoiceOutExpence
+ WHERE invoiceOutFk = vInvoice
+ ) base
+ JOIN (
+ SELECT SUM(vat) AS total
+ FROM invoiceOutTax
+ WHERE invoiceOutFk = vInvoice
+ ) vat
+ SET io.amount = base.total + vat.total
+ WHERE io.id = vInvoice;
+
+ UPDATE vn2008.Facturas
+ SET BI16 = 0,
+ BI7 = 0,
+ RE1 = 0,
+ RE4 = 0,
+ IVA7 = 0,
+ IVA16 = 0
+ WHERE factura_id = vInvoice;
+
+ UPDATE vn2008.Facturas f
+ JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
+ SET f.BI16 = iot.taxableBase, f.IVA16 = iot.vat
+ WHERE f.factura_id = vInvoice
+ AND iot.pgcFk IN ('4770000021' ,'4770000215', '4770000002','4771000000','4770000000','4770000020');
+
+ UPDATE vn2008.Facturas f
+ JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
+ SET f.RE4 = iot.vat
+ WHERE f.factura_id = vInvoice
+ AND iot.pgcFk = '4770000521';
+
+ UPDATE vn2008.Facturas f
+ JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
+ SET f.BI7 = iot.taxableBase, f.IVA7 = iot.vat
+ WHERE f.factura_id = vInvoice
+ AND iot.pgcFk IN ('4770000010' ,'4770000101');
+
+ UPDATE vn2008.Facturas f
+ JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
+ SET f.RE1 = iot.vat
+ WHERE f.factura_id = vInvoice
+ AND iot.pgcFk = '4770000110';
+
+FETCH rs INTO vInvoice;
+
+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 `invoiceOutListByCompany` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceOutListByCompany`(vCompany INT, vStarted DATE, vEnded DATE)
+BEGIN
+
+SELECT
+ c.socialName as RazonSocial,
+ c.fi as NIF,
+ io.ref as Factura,
+ io.serial as Serie,
+ io.issued as Fecha,
+ io.amount as Importe,
+ c.id as Id_Cliente,
+ iot.taxableBase as Base,
+ pgc.rate as Tipo,
+ iot.vat as Cuota,
+ pgc.name as Concepto
+
+ FROM vn.invoiceOut io
+ JOIN vn.invoiceOutTax iot ON iot.invoiceOutFk = io.id
+ JOIN vn.client c ON c.id = io.clientFk
+ JOIN vn.pgc ON pgc.code = iot.pgcFk
+ WHERE io.companyFk = vCompany
+ AND io.issued BETWEEN vStarted AND vEnded
+ ORDER BY io.ref 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 `invoiceOutMake` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceOutMake`(
+ vSerial VARCHAR(255),
+ vInvoiceDate DATETIME,
+ OUT vNewInvoiceId INT)
+BEGIN
+
+/* Creación de facturas emitidas.
+* REQUIERE previamente tabla ticketToInvoice.
+*
+* @param vSerial, vInvoiceDate, vCompany, vClient
+*
+* @return vNewInvoiceId
+*/
+
+ DECLARE vSpainCountryCode INT DEFAULT 1;
+ DECLARE vIsAnySaleToInvoice BOOL;
+ DECLARE vCountry TINYINT DEFAULT 1;
+ DECLARE vTaxArea VARCHAR(15);
+ DECLARE vNewRef VARCHAR(255);
+ DECLARE vWorker INT DEFAULT vn.getWorker();
+ DECLARE vCompany INT;
+ DECLARE vClient INT;
+ DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1;
+ DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6;
+ DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R';
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN
+ ROLLBACK;
+ RESIGNAL;
+ END;
+
+ SET vInvoiceDate = IFNULL(vInvoiceDate,CURDATE());
+
+ SELECT t.clientFk, t.companyFk
+ INTO vClient, vCompany
+ FROM ticketToInvoice tt
+ JOIN ticket t ON t.id = tt.id
+ LIMIT 1;
+
+ SELECT countryFk
+ INTO vCountry
+ FROM supplier
+ WHERE id = vCompany;
+
+ SELECT IF(a.isEqualizated
+ AND c.countryFk = vSpainCountryCode
+ AND i.taxAreaFk = 'NATIONAL',
+ 'EQU',
+ i.taxAreaFk)
+ INTO vTaxArea
+ FROM invoiceOutSerial i
+ JOIN ticketToInvoice tti
+ JOIN ticket t ON t.id = tti.id
+ JOIN address a ON a.id = t.addressFk
+ JOIN client c ON c.id = t.clientFk
+ WHERE i.code = invoiceSerial(t.clientFk,t.companyFk,'R')
+ LIMIT 1;
+
+ START TRANSACTION;
+
+ -- Elimina tickets sense moviments
+ UPDATE ticket t
+ JOIN ticketToInvoice ti ON ti.id = t.id
+ LEFT JOIN sale s ON s.ticketFk = ti.id
+ LEFT JOIN expedition e ON e.ticketFk = t.id
+ LEFT JOIN ticketPackaging tp ON tp.ticketFk = t.id
+ SET t.shipped = '2000-02-01 00:00:00'
+ WHERE s.ticketFk IS NULL AND e.ticketFk IS NULL AND e.ticketFk IS NULL;
+
+ -- Eliminem els tickets que no han de ser facturats
+ DELETE ti.*
+ FROM ticketToInvoice ti
+ JOIN ticket t ON t.id = ti.id
+ JOIN client c ON c.id = t.clientFk
+ WHERE YEAR(t.shipped) < 2001
+ OR c.isTaxDataChecked = FALSE;
+
+ SELECT SUM(quantity * price * (100 - discount)/100)
+ INTO vIsAnySaleToInvoice
+ FROM sale s
+ JOIN ticketToInvoice t on t.id = s.ticketFk;
+
+ IF vIsAnySaleToInvoice THEN
+
+ -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial
+ -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial
+ INSERT INTO invoiceOut
+ (
+ ref,
+ serial,
+ issued,
+ clientFk,
+ dued,
+ companyFk,
+ cplusInvoiceType477Fk
+ )
+ SELECT
+ 1,
+ vSerial,
+ vInvoiceDate,
+ vClient,
+ getDueDate(vInvoiceDate, dueDay),
+ vCompany,
+ IF(vSerial = vCorrectingSerial, vCplusCorrectingInvoiceTypeFk, vCplusStandardInvoiceTypeFk)
+ FROM client
+ WHERE id = vClient;
+
+
+ SET vNewInvoiceId = LAST_INSERT_ID();
+
+ SELECT ref
+ INTO vNewRef
+ FROM invoiceOut
+ WHERE id = vNewInvoiceId;
+
+ UPDATE ticket t
+ JOIN ticketToInvoice ti ON ti.id = t.id
+ SET t.refFk = vNewRef;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.updateInter;
+ CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY
+ SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador
+ FROM ticketToInvoice ti
+ JOIN vn.ticketState ts ON ti.id = ts.ticket
+ JOIN state s
+ WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = vn.getAlert3State(ti.id);
+
+ INSERT INTO vncontrol.inter(state_id,Id_Ticket,Id_Trabajador)
+ SELECT * FROM tmp.updateInter;
+
+
+ INSERT INTO ticketLog (action, userFk,originFk, description)
+ SELECT 'UPDATE',account.userGetId(),ti.id, CONCAT('Crea factura ',vNewRef)
+ FROM ticketToInvoice ti;
+
+ CALL invoiceExpenceMake(vNewInvoiceId);
+ CALL invoiceTaxMake(vNewInvoiceId,vCountry,vTaxArea);
+
+ UPDATE invoiceOut io
+ JOIN (
+ SELECT SUM(amount) AS total
+ FROM invoiceOutExpence
+ WHERE invoiceOutFk = vNewInvoiceId
+ ) base
+ JOIN (
+ SELECT SUM(vat) AS total
+ FROM invoiceOutTax
+ WHERE invoiceOutFk = vNewInvoiceId
+ ) vat
+ SET io.amount = base.total + vat.total
+ WHERE io.id = vNewInvoiceId;
+
+ END IF;
+
+ DROP TEMPORARY TABLE `ticketToInvoice`;
+ 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 `invoiceOutMakekk` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceOutMakekk`(
+ vSerial VARCHAR(255),
+ vInvoiceDate DATETIME,
+ OUT vNewInvoiceId INT)
+BEGIN
+
+/* Creación de facturas emitidas.
+* REQUIERE previamente tabla ticketToInvoice.
+*
+* @param vSerial, vInvoiceDate, vCompany, vClient
+*
+* @return vNewInvoiceId
+*/
+
+ DECLARE vSpainCountryCode INT DEFAULT 1;
+ DECLARE vIsAnySaleToInvoice BOOL;
+ DECLARE vCountry TINYINT DEFAULT 1;
+ DECLARE vTaxArea VARCHAR(15);
+ DECLARE vNewRef VARCHAR(255);
+ DECLARE vWorker INT DEFAULT vn.getWorker();
+ DECLARE vCompany INT;
+ DECLARE vClient INT;
+ DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1;
+ DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6;
+ DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R';
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN
+ ROLLBACK;
+ RESIGNAL;
+ END;
+
+ SET vInvoiceDate = IFNULL(vInvoiceDate,CURDATE());
+
+ SELECT t.clientFk, t.companyFk
+ INTO vClient, vCompany
+ FROM ticketToInvoice tt
+ JOIN ticket t ON t.id = tt.id
+ LIMIT 1;
+
+ SELECT countryFk
+ INTO vCountry
+ FROM supplier
+ WHERE id = vCompany;
+
+ SELECT IF(a.isEqualizated
+ AND c.countryFk = vSpainCountryCode
+ AND i.taxAreaFk = 'NATIONAL',
+ 'EQU',
+ i.taxAreaFk)
+ INTO vTaxArea
+ FROM invoiceOutSerial i
+ JOIN ticketToInvoice tti
+ JOIN ticket t ON t.id = tti.id
+ JOIN address a ON a.id = t.addressFk
+ JOIN client c ON c.id = t.clientFk
+ WHERE i.code = vSerial
+ LIMIT 1;
+
+ INSERT INTO dailyTaskLog(state) VALUES('invoiceOutMake 1: START');
+
+ START TRANSACTION;
+
+ -- Elimina tickets sense moviments
+ UPDATE ticket t
+ JOIN ticketToInvoice ti ON ti.id = t.id
+ LEFT JOIN sale s ON s.ticketFk = ti.id
+ LEFT JOIN expedition e ON e.ticketFk = t.id
+ SET t.shipped = '2000-02-01 00:00:00'
+ WHERE s.id IS NULL AND e.id IS NULL;
+
+ INSERT INTO dailyTaskLog(state) VALUES('invoiceOutMake 1.1');
+
+ -- Eliminem els tickets que no han de ser facturats
+ DELETE ti.*
+ FROM ticketToInvoice ti
+ JOIN ticket t ON t.id = ti.id
+ JOIN client c ON c.id = t.clientFk
+ WHERE YEAR(t.shipped) < 2001
+ OR c.isTaxDataChecked = FALSE;
+ INSERT INTO dailyTaskLog(state) VALUES('invoiceOutMake 1.2');
+
+ SELECT SUM(quantity * price * (100 - discount)/100)
+ INTO vIsAnySaleToInvoice
+ FROM sale s
+ JOIN ticketToInvoice t on t.id = s.ticketFk;
+
+ INSERT INTO dailyTaskLog(state) VALUES('invoiceOutMake 1.3');
+
+ IF vIsAnySaleToInvoice THEN
+
+ -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial
+ -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial
+ INSERT INTO invoiceOut
+ (
+ ref,
+ serial,
+ issued,
+ clientFk,
+ dued,
+ companyFk,
+ cplusInvoiceType477Fk
+ )
+ SELECT
+ 1,
+ vSerial,
+ vInvoiceDate,
+ vClient,
+ getDueDate(vInvoiceDate, dueDay),
+ vCompany,
+ IF(vSerial = vCorrectingSerial, vCplusCorrectingInvoiceTypeFk, vCplusStandardInvoiceTypeFk)
+ FROM client
+ WHERE id = vClient;
+
+
+ SET vNewInvoiceId = LAST_INSERT_ID();
+
+ SELECT ref
+ INTO vNewRef
+ FROM invoiceOut
+ WHERE id = vNewInvoiceId;
+
+ UPDATE ticket t
+ JOIN ticketToInvoice ti ON ti.id = t.id
+ SET t.refFk = vNewRef;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.updateInter;
+ CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY
+ SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador
+ FROM ticketToInvoice ti
+ JOIN vn.ticketState ts ON ti.id = ts.ticket
+ JOIN state s
+ WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = vn.getAlert3State(ti.id);
+
+ INSERT INTO vncontrol.inter(state_id,Id_Ticket,Id_Trabajador)
+ SELECT * FROM tmp.updateInter;
+
+ INSERT INTO logTicket (action, userFk,originFk, description)
+ SELECT 'UPDATE',account.userGetId(),ti.id, CONCAT('CREA FACTURA ',vNewRef)
+ FROM ticketToInvoice ti;
+
+ CALL invoiceExpenceMake(vNewInvoiceId);
+ CALL invoiceTaxMake(vNewInvoiceId,vCountry,vTaxArea);
+
+ UPDATE invoiceOut io
+ JOIN (
+ SELECT SUM(amount) AS total
+ FROM invoiceOutExpence
+ WHERE invoiceOutFk = vNewInvoiceId
+ ) base
+ JOIN (
+ SELECT SUM(vat) AS total
+ FROM invoiceOutTax
+ WHERE invoiceOutFk = vNewInvoiceId
+ ) vat
+ SET io.amount = base.total + vat.total
+ WHERE io.id = vNewInvoiceId;
+ INSERT INTO dailyTaskLog(state) VALUES('invoiceOutMake 2: START');
+ -- Retrocompatibilidad. Borrar al cambiar el informe de facturas
+ UPDATE vn2008.Facturas f
+ JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
+ SET f.BI16 = iot.taxableBase, f.IVA16 = iot.vat
+ WHERE f.factura_id = vNewInvoiceId
+ AND iot.pgcFk IN ('4770000021' ,'4770000215', '4770000002','4771000000','4770000000','4770000020');
+
+ UPDATE vn2008.Facturas f
+ JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
+ SET f.RE4 = iot.vat
+ WHERE f.factura_id = vNewInvoiceId
+ AND iot.pgcFk = '4770000521';
+
+ UPDATE vn2008.Facturas f
+ JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
+ SET f.BI7 = iot.taxableBase, f.IVA7 = iot.vat
+ WHERE f.factura_id = vNewInvoiceId
+ AND iot.pgcFk IN ('4770000010' ,'4770000101');
+
+ UPDATE vn2008.Facturas f
+ JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id
+ SET f.RE1 = iot.vat
+ WHERE f.factura_id = vNewInvoiceId
+ AND iot.pgcFk = '4770000110';
+ END IF;
+
+
+ INSERT INTO dailyTaskLog(state) VALUES('invoiceOutMake 3: END');
+
+ DROP TEMPORARY TABLE `ticketToInvoice`;
+ 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 `invoiceOutTaxAndExpence` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceOutTaxAndExpence`()
+BEGIN
+
+/* Para tickets ya facturados, vuelve a repetir el proceso de facturación.
+*
+* @param vInvoice Numero de factura
+*/
+
+
+
+ DECLARE vInvoice INT;
+ DECLARE vInvoiceRef VARCHAR(15);
+ DECLARE vCountry INT;
+ DECLARE vTaxArea VARCHAR(15);
+ DECLARE vContador INT DEFAULT 0;
+
+ DECLARE done BOOL DEFAULT FALSE;
+
+ DECLARE rs CURSOR FOR
+ SELECT id,ref
+ FROM invoiceOut io
+
+ WHERE issued >= '2017-07-01'
+ AND companyFk = 1381
+ AND io.amount IS NULL
+ ;
+
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+
+ OPEN rs;
+
+ FETCH rs INTO vInvoice ,vInvoiceRef;
+
+ WHILE NOT done DO
+
+ SELECT s.countryFk
+ INTO vCountry
+ FROM supplier s
+ JOIN invoiceOut io ON io.companyFk = s.id
+ WHERE io.id = vInvoice;
+
+ SELECT IF(c.isEqualizated AND i.taxAreaFk = 'NATIONAL','EQU',i.taxAreaFk)
+ INTO vTaxArea
+ FROM invoiceOutSerial i
+ JOIN invoiceOut io ON io.serial = i.code
+ JOIN client c ON c.id = io.clientFk
+ WHERE io.id = vInvoice;
+
+ DROP TEMPORARY TABLE IF EXISTS ticketToInvoice;
+
+ CREATE TEMPORARY TABLE ticketToInvoice
+ SELECT id
+ FROM ticket
+ WHERE refFk = vInvoiceRef;
+
+ CALL invoiceExpenceMake(vInvoice);
+ CALL invoiceTaxMake(vInvoice,vCountry,vTaxArea);
+
+ FETCH rs INTO vInvoice ,vInvoiceRef;
+
+ SET vContador = vContador + 1;
+
+ IF vContador MOD 50 = 0 THEN
+
+ SELECT CONCAT(vContador, ' de momento') AS FACTURAS_ASENTADAS;
+
+ END IF;
+
+ END WHILE;
+
+ CLOSE rs;
+
+ SELECT CONCAT(vContador, ' total') AS FACTURAS_ASENTADAS;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `invoiceTaxMake` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceTaxMake`(IN vInvoice INT, IN vCountry INT, IN vTaxArea VARCHAR(15))
+BEGIN
+/* Inserta los registros de iva de la factura emitida
+* REQUIERE tabla ticketToInvoice
+*
+* @param vInvoice Id de la factura
+*/
+
+ DELETE FROM invoiceOutTax
+ WHERE invoiceOutFk = vInvoice;
+
+ INSERT INTO invoiceOutTax(
+ invoiceOutFk,
+ pgcFk,
+ taxableBase,
+ vat
+ )
+ SELECT vInvoice,
+ bp.pgcFk,
+ SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2)
+ ) taxableBase,
+ SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2)
+ ) * pgc.rate / 100
+ FROM ticketToInvoice t
+ JOIN sale s ON s.ticketFk = t.id
+ JOIN item i ON i.id = s.itemFk
+ JOIN itemTaxCountry itc
+ ON itc.itemFk = i.id AND itc.countryFk = vCountry
+ JOIN bookingPlanner bp
+ ON bp.countryFk = vCountry
+ AND bp.taxAreaFk = vTaxArea
+ AND bp.taxClassFk = itc.taxClassFk
+ JOIN pgc ON pgc.code = bp.pgcFk
+ GROUP BY pgc.code
+ HAVING taxableBase != 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 `itemTagArrangedUpdate` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `itemTagArrangedUpdate`(IN vItem BIGINT)
+BEGIN
+/**
+ * Actualiza la tabla itemTagArranged
+ *
+ * @param vItem El Id_item de toda la vida. Si es cero, equivale a todos.
+ **/
+ DELETE
+ FROM itemTagArranged
+ WHERE vItem IS NULL
+ OR vItem = itemFk;
+
+ INSERT INTO itemTagArranged(itemFk)
+ SELECT id
+ FROM item
+ WHERE vItem IS NULL
+ OR vItem = id;
+
+ REPLACE itemTagArranged
+ SELECT i.id,
+ 'Medida' as tag1,
+ LEFT(i.size,15) as val1,
+ 'Color' as tag2,
+ LEFT(ink.`name`,15) as val2,
+ 'Categoria' as tag3,
+ LEFT(i.category,15) as val3,
+ 'Productor' as tag4,
+ LEFT(p.`name`,15) as val4,
+ 'Tallos' as tag5,
+ i.stems as val5,
+ 'Origen' as tag6,
+ o.code as val6,
+ i.description
+ FROM item i
+ LEFT JOIN itemTagged it ON it.itemFk = i.id
+ LEFT JOIN ink on ink.id = i.inkFk
+ JOIN origin o ON o.id = i.originFk
+ LEFT JOIN producer p ON p.id = i.producerFk
+ WHERE it.itemFk IS NULL
+ AND (vItem IS NULL OR vItem = i.id);
+
+ CALL itemTagUpdatePriority(vItem);
+
+ UPDATE itemTagArranged ita
+ JOIN itemTag it ON it.itemFk = ita.itemFk
+ JOIN tag t ON t.id = it.tagFk
+ SET tag1 = t.name, val1 = it.value
+ WHERE it.priority = 1
+ AND (vItem IS NULL OR vItem = it.itemFk);
+
+ UPDATE itemTagArranged ita
+ JOIN itemTag it ON it.itemFk = ita.itemFk
+ JOIN tag t ON t.id = it.tagFk
+ SET tag2 = t.name, val2 = it.value
+ WHERE it.priority = 2
+ AND (vItem IS NULL OR vItem = it.itemFk);
+
+ UPDATE itemTagArranged ita
+ JOIN itemTag it ON it.itemFk = ita.itemFk
+ JOIN tag t ON t.id = it.tagFk
+ SET tag3 = t.name, val3 = it.value
+ WHERE it.priority = 3
+ AND (vItem IS NULL OR vItem = it.itemFk);
+
+ UPDATE itemTagArranged ita
+ JOIN itemTag it ON it.itemFk = ita.itemFk
+ JOIN tag t ON t.id = it.tagFk
+ SET tag4 = t.name, val4 = it.value
+ WHERE it.priority = 4
+ AND (vItem IS NULL OR vItem = it.itemFk);
+
+ UPDATE itemTagArranged ita
+ JOIN itemTag it ON it.itemFk = ita.itemFk
+ JOIN tag t ON t.id = it.tagFk
+ SET tag5 = t.name, val5 = it.value
+ WHERE it.priority = 5
+ AND (vItem IS NULL OR vItem = it.itemFk);
+
+ UPDATE itemTagArranged ita
+ JOIN itemTag it ON it.itemFk = ita.itemFk
+ JOIN tag t ON t.id = it.tagFk
+ SET tag6 = t.name, val6 = it.value
+ WHERE it.priority = 6
+ AND (vItem IS NULL OR vItem = it.itemFk);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `itemTagUpdatePriority` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `itemTagUpdatePriority`(IN vItem INT)
+BEGIN
+/*
+* Recalcula las prioridades de articleTag
+*
+* @param vItem Id_Article. Si es 0, lo recalcula todo
+*/
+
+ SET vItem = IFNULL(vItem,0);
+
+ SET @p := 0;
+ SET @a := 0;
+
+ UPDATE itemTag a
+ JOIN (
+ SELECT
+ id,
+ @p := IF(itemFk = @a, @p, 0) + 1 as NewPriority,
+ @a := itemFk
+ FROM itemTag
+ WHERE vItem IS NULL
+ OR vItem = itemFk
+ ORDER BY itemFk, priority
+ ) sub ON sub.id = a.id
+ SET a.priority = NewPriority;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `itemTagUpdatePriority_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 `itemTagUpdatePriority_launcher`()
+BEGIN
+
+ CALL vn.itemTagUpdatePriority(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 `logAdd` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `logAdd`(vOriginFk INT, vActionCode VARCHAR(45), vEntity VARCHAR(45), vDescription TEXT)
+BEGIN
+/**
+ * Guarda las acciones realizadas por el usuario
+ *
+ * @param vOriginFk Id del registro de origen
+ * @param vActionCode Código de la acción {insert | delete | update}
+ * @param vEntity Nombre que hace referencia a la tabla.
+ * @param descripcion Descripción de la acción realizada por el usuario
+ */
+ DECLARE vTableName VARCHAR(45);
+
+ SET vTableName = CONCAT(vEntity, 'Log');
+
+ SET @qryLog := CONCAT(
+ 'INSERT INTO ', vTableName, ' (originFk, userFk, action, description)',
+ ' VALUES (', vOriginFk, ', ', account.userGetId(), ', "', vActionCode, '", "', vDescription, '")'
+ );
+
+ PREPARE stmt FROM @qryLog;
+ EXECUTE stmt;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `logShow` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `logShow`(vOriginFk INT, vEntity VARCHAR(45))
+BEGIN
+/**
+ * Muestra las acciones realizadas por el usuario
+ *
+ * @param vOriginFk Id del registro de origen
+ * @param vEntity Nombre que hace referencia a la tabla.
+ */
+ DECLARE vTableName VARCHAR(45);
+
+ SET vTableName = CONCAT(vEntity, 'Log');
+
+ SET @qryLog := CONCAT(
+ 'SELECT ot.id, ot.originFk, ot.userFk, u.name, ot.action, ot.creationDate, ot.description FROM ', vTableName, ' AS ot',
+ ' INNER JOIN account.user u ON u.id = ot.userFk',
+ ' WHERE ot.originFk = ', vOriginFk, ' ORDER BY ot.creationDate DESC'
+ );
+
+ PREPARE stmt FROM @qryLog;
+ EXECUTE stmt;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `mergeTicketUnattended` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `mergeTicketUnattended`(IN vMainTicket INT(11), IN hasSameAgency BOOLEAN)
+BEGIN
+
+ DECLARE isBilled BOOLEAN;
+ DECLARE arrayTickets VARCHAR(255);
+
+ SELECT Factura IS NOT NULL INTO isBilled FROM vn2008.Tickets WHERE Id_Ticket = vMainTicket;
+
+ IF NOT isBilled THEN
+
+ SELECT GROUP_CONCAT(distinct T.Id_Ticket) INTO arrayTickets
+ FROM vn2008.Tickets T LEFT JOIN vn.ticketState ts ON T.Id_Ticket = ts.ticket
+ JOIN vn2008.Tickets ticketOriginal ON ticketOriginal.Id_Ticket = vMainTicket
+ AND T.empresa_id = ticketOriginal.empresa_id
+ AND T.Id_Consigna = ticketOriginal.Id_Consigna
+ AND DATE(T.Fecha) = DATE(ticketOriginal.Fecha)
+ AND T.warehouse_id = ticketOriginal.warehouse_id
+ AND IF(hasSameAgency <> 0,T.Id_Agencia = ticketOriginal.Id_Agencia,TRUE)
+ LEFT JOIN vn.ticketState tsOriginal ON ticketOriginal.Id_Ticket = tsOriginal.ticket
+ WHERE ts.alertLevel < 3
+ AND T.Factura IS NULL
+ AND T.Anotadoencaja = FALSE
+ AND T.Id_Ticket <> vMainTicket
+ AND ts.alertLevel = tsOriginal.alertLevel;
+
+ CALL mergeTicketWithArray(vMainTicket,arrayTickets);
+
+ 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 */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `mergeTicketWithArray` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `mergeTicketWithArray`(IN vMainTicket INT(11), IN arrayTickets VARCHAR(50))
+BEGIN
+
+ DECLARE isBilled BOOLEAN;
+ DECLARE messageLog VARCHAR(50);
+ DECLARE company INT;
+ DECLARE messageForSplit VARCHAR(255);
+ DECLARE vMainSplit INT;
+ DECLARE worker INT(3);
+
+ SELECT Factura IS NOT NULL INTO isBilled FROM vn2008.Tickets WHERE Id_Ticket = vMainTicket;
+
+ IF NOT isBilled THEN
+
+ SELECT Id_Trabajador INTO worker from vn2008.Trabajadores where user_id = account.userGetId();
+ IF worker IS NULL THEN
+ SET worker = 20;
+ END IF;
+
+ DROP TEMPORARY TABLE IF EXISTS vn2008.Tickets_to_fusion;
+
+ -- He usado el util.exec porque da error la variable strId_Tickets puesta dentro del IN()
+ CALL util.exec(sql_printf('
+ CREATE TEMPORARY TABLE vn2008.Tickets_to_fusion
+ SELECT Id_Ticket, Localizacion
+ FROM vn2008.Tickets T
+ WHERE Id_Ticket IN (%s);',arrayTickets));
+
+ INSERT INTO vn2008.ticket_observation (Id_Ticket,observation_type_id,text)
+ SELECT vMainTicket,observation_type_id,CONCAT(' Ticket ', Id_Ticket, ':' , tco.text, '. ')
+ FROM vn2008.Tickets_to_fusion tf
+ INNER JOIN vn2008.ticket_observation tco USING(Id_Ticket)
+ ON DUPLICATE KEY UPDATE `text` = CONCAT(ticket_observation.`text`,CONCAT(' Ticket ', VALUES(Id_Ticket), ':' , VALUES(`text`), '. '));
+
+ UPDATE vn2008.Movimientos M
+ JOIN vn2008.Tickets_to_fusion USING(Id_Ticket)
+ SET M.Id_Ticket = vMainTicket;
+
+ UPDATE vn2008.expeditions M
+ JOIN vn2008.Tickets_to_fusion t ON t.Id_Ticket = M.ticket_id
+ SET M.ticket_id = vMainTicket;
+
+ UPDATE vn.ticketPackaging tp
+ JOIN vn2008.Tickets_to_fusion t ON t.Id_Ticket = tp.ticketFk
+ SET tp.ticketFk = vMainTicket;
+
+ UPDATE vn2008.Tickets
+ SET Bultos = (SELECT COUNT(*) FROM vn2008.expeditions WHERE ticket_id = vMainTicket AND EsBulto)
+ WHERE Id_Ticket = vMainTicket;
+
+ UPDATE vn2008.Tickets
+ JOIN vn2008.Tickets_to_fusion USING(Id_Ticket)
+ SET Fecha = TIMESTAMPADD(YEAR,-1 * (YEAR(Fecha)-2000), Fecha);
+
+ UPDATE vn2008.Tickets_dits ts
+ JOIN vn2008.Tickets_to_fusion t USING(Id_Ticket)
+ SET ts.Id_Ticket = vMainTicket;
+
+ UPDATE vn2008.Tickets
+ SET Localizacion = CONCAT(Tickets.Localizacion,' ',IFNULL((SELECT GROUP_CONCAT(Localizacion SEPARATOR ' ') FROM vn2008.Tickets_to_fusion),''))
+ WHERE Id_Ticket = vMainTicket;
+
+ UPDATE vn2008.Splits s
+ RIGHT JOIN vn2008.Tickets_to_fusion t USING(Id_Ticket)
+ SET s.Id_Ticket = vMainTicket;
+
+ IF (SELECT COUNT(*) FROM vn2008.Splits WHERE Id_Ticket=vMainTicket) > 1 THEN
+
+ SELECT Id_Split INTO vMainSplit FROM vn2008.Splits WHERE Id_Ticket = vMainTicket LIMIT 1;
+
+ SELECT group_concat(Notas,',') INTO messageForSplit FROM vn2008.Splits WHERE Id_Ticket = vMainTicket;
+ UPDATE vn2008.Splits SET Notas = messageForSplit WHERE Id_Split=vMainSplit;
+ UPDATE vn2008.Split_lines sl JOIN vn2008.Splits s USING (Id_Split) SET sl.Id_Split=vMainSplit WHERE Id_Ticket=vMainTicket;
+ DELETE FROM vn2008.Splits WHERE Id_Ticket=vMainTicket AND Id_Split<>vMainSplit;
+ END IF;
+
+ SELECT GROUP_CONCAT(Id_Ticket SEPARATOR ',') into messageLog FROM vn2008.Tickets_to_fusion;
+ CALL vn2008.Ditacio(vMainTicket,'Fusion','T',worker,messageLog,NULL);
+
+ DELETE ts FROM vn2008.Tickets_state ts JOIN vn2008.Tickets_to_fusion t USING(Id_Ticket);
+ /*
+ UPDATE vncontrol.inter M
+ JOIN vn2008.Tickets_to_fusion USING(Id_Ticket)
+ SET M.Id_Ticket = vMainTicket;
+ */
+ 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 `nestAdd` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `nestAdd`(vScheme VARCHAR(45), vTable VARCHAR(45), vParentFk INT, vChild VARCHAR(45))
+BEGIN
+ DECLARE vSql TEXT;
+
+ -- Check parent childs
+ SET vSql = sql_printf('
+ SELECT COUNT(c.id) INTO @childs
+ FROM %t.%t p
+ LEFT JOIN %t.%t c ON c.lft BETWEEN p.lft AND p.rgt AND c.id != %v
+ WHERE p.id = %v',
+ vScheme, vTable, vScheme, vTable, vParentFk, vParentFk);
+ SET @qrySql := vSql;
+
+ PREPARE stmt FROM @qrySql;
+ EXECUTE stmt;
+ DEALLOCATE PREPARE stmt;
+
+ -- Select left from last child
+ IF @childs = 0 THEN
+ SET vSql = sql_printf('SELECT lft INTO @vLeft FROM %t.%t WHERE id = %v', vScheme, vTable, vParentFk);
+ SET @qrySql := vSql;
+ ELSE
+ SET vSql = sql_printf('
+ SELECT c.rgt INTO @vLeft
+ FROM %t.%t p
+ JOIN %t.%t c ON c.lft BETWEEN p.lft AND p.rgt
+ WHERE p.id = %v
+ ORDER BY c.lft
+ DESC LIMIT 1',
+ vScheme, vTable, vScheme, vTable, vParentFk);
+ SET @qrySql := vSql;
+ END IF;
+
+ PREPARE stmt FROM @qrySql;
+ EXECUTE stmt;
+ DEALLOCATE PREPARE stmt;
+
+ -- Update right
+ SET vSql = sql_printf('UPDATE %t.%t SET rgt = rgt + 2 WHERE rgt > %v ORDER BY rgt DESC', vScheme, vTable, @vLeft);
+ SET @qrySql := vSql;
+
+ PREPARE stmt FROM @qrySql;
+ EXECUTE stmt;
+ DEALLOCATE PREPARE stmt;
+
+ SET vSql = sql_printf('UPDATE %t.%t SET lft = lft + 2 WHERE lft > %v ORDER BY lft DESC', vScheme, vTable, @vLeft);
+ SET @qrySql := vSql;
+
+ PREPARE stmt FROM @qrySql;
+ EXECUTE stmt;
+ DEALLOCATE PREPARE stmt;
+
+ -- Escape character
+ SET vChild = REPLACE(vChild, "'", "\\'");
+
+ -- Add child
+ SET vSql = sql_printf('INSERT INTO %t.%t (name, lft, rgt) VALUES (%v, %v, %v)', vScheme, vTable, vChild, @vLeft + 1, @vLeft + 2);
+ SET @qrySql := vSql;
+
+ PREPARE stmt FROM @qrySql;
+ EXECUTE stmt;
+ DEALLOCATE PREPARE stmt;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `nestLeave` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `nestLeave`(vScheme VARCHAR(45), vTable VARCHAR(45), vParentFk INT)
+BEGIN
+ DECLARE vSql TEXT;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.tree;
+
+ SET vSql = sql_printf('
+ CREATE TEMPORARY TABLE tmp.tree ENGINE = MEMORY
+ SELECT
+ node.id,
+ node.name,
+ node.lft,
+ node.rgt,
+ node.depth,
+ node.sons
+ FROM
+ %t.%t AS node,
+ %t.%t AS parent
+ WHERE
+ node.lft BETWEEN parent.lft AND parent.rgt
+ AND node.depth = parent.depth + 1
+ AND parent.id = %v
+ GROUP BY node.id
+ ORDER BY node.lft',
+ vScheme, vTable, vScheme, vTable, vParentFk);
+ SET @qrySql := vSql;
+
+ PREPARE stmt FROM @qrySql;
+ EXECUTE stmt;
+ DEALLOCATE PREPARE stmt;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `nestTree` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `nestTree`(
+ vSourceSchema VARCHAR(45),
+ vSourceTable VARCHAR(45),
+ vDestinationSchema VARCHAR(45),
+ vDestinationTable VARCHAR(45))
+BEGIN
+ DECLARE vSql TEXT;
+
+
+ SET vSql = sql_printf('DROP TABLE IF EXISTS %t.%t', vDestinationSchema, vDestinationTable);
+ SET @qrySql := vSql;
+
+ PREPARE stmt FROM @qrySql;
+ EXECUTE stmt;
+ DEALLOCATE PREPARE stmt;
+
+ SET vSql = sql_printf('
+ CREATE TABLE %t.%t
+ SELECT
+ node.id,
+ node.name,
+ node.lft,
+ node.rgt,
+ COUNT(parent.id) - 1 depth,
+ CAST((node.rgt - node.lft - 1) / 2 as DECIMAL) as sons
+ FROM
+ %t.%t AS node,
+ %t.%t AS parent
+ WHERE node.lft BETWEEN parent.lft AND parent.rgt
+ GROUP BY node.id
+ ORDER BY node.lft',
+ vDestinationSchema, vDestinationTable, vSourceSchema, vSourceTable, vSourceSchema, vSourceTable);
+ SET @qrySql := vSql;
+
+ PREPARE stmt FROM @qrySql;
+ EXECUTE stmt;
+ DEALLOCATE PREPARE stmt;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `noticeSend` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `noticeSend`(vCategoryKey VARCHAR(50), vSender INT, vRecipient INT, vBody TEXT)
+BEGIN
+ DECLARE vCategoryId INT;
+ DECLARE vIsEnabled TINYINT(1);
+
+ -- Obtenemos los datos de la categoría
+ SELECT c.id, c.isEnabled INTO vCategoryId, vIsEnabled FROM vn.noticeCategory c WHERE keyName = vCategoryKey;
+
+ IF vn.noticeHasActive(vCategoryKey, vRecipient) AND vIsEnabled THEN
+
+ INSERT INTO vn.noticeInbox (noticeCategoryFk, senderFk, recipientFk, body)
+ VALUES (vCategoryId, vSender, vRecipient, vBody);
+
+ SELECT vSender, vRecipient;
+ 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 */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `observationAdd` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `observationAdd`(vOriginFk INT, vTableCode VARCHAR(45), vDescription TEXT)
+BEGIN
+/**
+ * Guarda las observaciones realizadas por el usuario
+ *
+ * @param vOriginFk Id del registro de origen
+ * @param vTypeCode Código que referencia a la tabla.
+ * @param descripcion Texto de la observacion
+ */
+ DECLARE vTableName VARCHAR(45);
+
+ SET vTableName = CONCAT(vTableCode,'Observation');
+
+ IF ISNULL(vTableName) THEN
+ CALL util.throw('CODE_NOT_FOUND');
+ END IF;
+
+ SET @qryLog := CONCAT(
+ 'INSERT INTO ', vTableName, ' (originFk, userFk, description)',
+ ' VALUES (', vOriginFk, ', ', account.userGetId(), ', "', vDescription, '")'
+ );
+
+ PREPARE stmt FROM @qryLog;
+ EXECUTE stmt;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `printTrolleyLabel` */;
+ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `printTrolleyLabel`(vTicket INT, vPrinter INT, vReport INT)
+BEGIN
+/**
+ * Inserta en la cola de impresion una nueva etiqueta de carro, para el sacador
+ *
+ * @param vTicket Numero del ticket
+ * @param vPrinter Numero de impresora
+ * @param vReport Numero del informe
+ **/
+ DECLARE vlabelCount INT DEFAULT 0;
+ DECLARE PRIORITY INT DEFAULT 3;
+ DECLARE vWorker INT;
+ DECLARE vShipmentHour VARCHAR(10);
+
+ SELECT getTicketTrolleyLabelCount(vTicket) INTO vLabelCount;
+ SELECT getUser() INTO vWorker;
+ SELECT CONCAT(getShipmentHour(vTicket),':00') INTO vShipmentHour;
+
+ INSERT INTO printingQueue(printer
+ , priority
+ , report
+ , `text`
+ , worker
+ , text2
+ , text3)
+ VALUES (vPrinter
+ , PRIORITY
+ , vReport
+ , vTicket
+ , vWorker
+ , vLabelCount
+ , vShipmentHour);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `refund` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `refund`(IN vMainTicket INT, OUT vNewTicket INT)
+BEGIN
+
+ DECLARE vCustomer MEDIUMINT;
+ DECLARE vNewDate DATE;
+ DECLARE vWarehouse TINYINT;
+ DECLARE vCompany MEDIUMINT;
+ DECLARE vAddress MEDIUMINT;
+ DECLARE vRefundAgencyMode INT DEFAULT 23;
+
+ SELECT customer, TIMESTAMPADD(DAY, 1,shipment), warehouse, company, address
+ INTO vCustomer, vNewDate, vWarehouse, vCompany, vAddress
+ FROM ticket
+ WHERE id = vMainTicket;
+
+ CALL ticketCreate(vCustomer, vNewDate, vWarehouse, vCompany, vAddress, vRefundAgencyMode,NULL,vNewDate,vNewTicket);
+
+ INSERT INTO vn2008.Movimientos(Id_Ticket, Id_Article, Cantidad, Concepte, Preu, Descuento, PrecioFijado)
+ SELECT vNewTicket, Id_Article, - Cantidad, Concepte, Preu, Descuento, TRUE FROM vn2008.Movimientos WHERE Id_Ticket = vMainTicket;
+ SELECT vNewTicket;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `saleSplit` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `saleSplit`(IN vIdMovement BIGINT, IN vQuantity int)
+BEGIN
+ DECLARE vId INT;
+ DECLARE vCreated DATE;
+ DECLARE vWarehouseId INT;
+ DECLARE vCompanyId INT;
+ DECLARE vAddressId INT;
+ DECLARE vAgencyMode INT;
+ DECLARE vNewTicketId BIGINT;
+ DECLARE vNewSale BIGINT;
+ DECLARE vLanded DATE;
+ DECLARE vStarted DATETIME;
+ DECLARE vEnded DATETIME;
+ DECLARE vCurrentTicket INT;
+
+
+
+ SELECT clientFk
+ , shipped
+ , warehouseFk
+ , companyFk
+ , addressFk
+ , AgencyModeFk
+ , Landed
+ , t.id
+
+ INTO vId
+ , vCreated
+ , vWarehouseId
+ , vCompanyId
+ , vAddressId
+ , vAgencyMode
+ , vLanded
+ , vCurrentTicket
+ FROM ticket t
+ JOIN sale m on t.id = m.ticketFk
+ WHERE m.id = vIdMovement;
+
+ -- Busca un ticket existente que coincida con los parametros del nuevo pedido
+
+ SET vStarted = TIMESTAMP(vCreated);
+ SET vEnded = TIMESTAMP(vCreated, '23:59:59');
+
+ SELECT id INTO vNewTicketId
+ FROM ticket t
+ JOIN ticketState ts on t.id = ts.ticketFk
+ WHERE vAddressId = t.addressFk
+ AND vWarehouseId = t.warehouseFk
+ AND vAgencyMode = t.AgencyModeFk
+ AND vLanded <=> t.landed
+ AND t.shipment BETWEEN vStarted AND vEnded -- uso BETWEEN para aprovechar el indice
+ AND t.refFk IS NULL
+ AND ts.alertLevel = 0
+ AND t.clientFk <> 1118
+ AND t.id <> vCurrentTicket
+ LIMIT 1;
+
+ IF vNewTicketId IS NULL THEN
+ Call vn.ticketCreate( vId
+ , vCreated
+ , vWarehouseId
+ , vCompanyId
+ , vAddressId
+ , vAgencyMode
+ , NULL
+ , vLanded
+ , vNewTicketId);
+
+ CALL vn2008.bionic_calc_ticket(vNewTicketId);
+ ELSE
+ UPDATE ticket SET landed = vLanded WHERE id = vNewTicketId;
+ END IF;
+
+ INSERT INTO vncontrol.inter(Id_Ticket, state_id)
+ SELECT vNewTicketId, s.id
+ FROM state s
+ WHERE s.code = 'FIXING';
+
+ INSERT INTO sale(ticketFk, itemFk, concept, quantity, price, discount)
+ SELECT vNewTicketId, itemFk, Concept, vQuantity, price, discount
+ FROM sale
+ WHERE id = vIdMovement;
+
+ SELECT LAST_INSERT_ID() INTO vNewSale;
+
+ INSERT INTO saleComponent(saleFk, componentFk, `value`)
+ SELECT vNewSale, componentFk, `value`
+ FROM saleComponent
+ WHERE saleFk = vIdMovement;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `solunionRiskRequest` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `solunionRiskRequest`()
+BEGIN
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
+ CREATE TEMPORARY TABLE tmp.client_list
+ (PRIMARY KEY (Id_Cliente))
+ ENGINE = MEMORY
+ SELECT * FROM (SELECT cc.client Id_Cliente, ci.grade FROM vn.creditClassification cc
+ JOIN vn.creditInsurance ci ON cc.id = ci.creditClassification
+ WHERE dateEnd IS NULL
+ ORDER BY ci.creationDate DESC) t1 GROUP BY Id_Cliente;
+
+ CALL vn2008.risk_vs_client_list(CURDATE());
+
+ SELECT
+ c.Id_Cliente, c.Cliente, c.Credito credito_vn, c.creditInsurance solunion, cast(r.risk as DECIMAL(10,0)) riesgo_vivo,
+ cast(c.creditInsurance - r.risk as decimal(10,0)) margen_vivo,
+ f.Consumo consumo_anual, c.Vencimiento, ci.grade
+ FROM
+ vn2008.Clientes c
+ JOIN tmp.risk r ON r.Id_Cliente = c.Id_Cliente
+ JOIN tmp.client_list ci ON c.Id_Cliente = ci.Id_Cliente
+ JOIN bi.facturacion_media_anual f ON c.Id_Cliente = f.Id_Cliente
+ GROUP BY Id_cliente;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.risk;
+ DROP TEMPORARY TABLE IF EXISTS tmp.client_list;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `stockBuyed` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `stockBuyed`(vDate DATE)
+BEGIN
+ DECLARE vVolume DECIMAL(10,2);
+ DECLARE vWarehouse INT DEFAULT 7;
+
+ CALL stockTraslation(vDate);
+
+ SELECT Volumen INTO vVolume FROM vn2008.Cubos WHERE Id_Cubo = 'cc' LIMIT 1;
+
+ INSERT INTO stockBuyed(user, buyed, `date`)
+ SELECT tr.user_id, SUM(0.6 * ( amount / c.packing ) * vn2008.cm3(Id_Compra))/vVolume buyed, vDate
+ FROM tmp_item i
+ JOIN vn2008.Articles a ON a.Id_Article = i.item_id
+ JOIN vn2008.Tipos t ON a.tipo_id = t.tipo_id
+ JOIN vn2008.reinos r ON r.id = t.reino_id
+ JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = t.Id_Trabajador
+ JOIN vn2008.t_item_last_buy ilb ON ilb.item_id = Id_Article AND ilb.warehouse_id = vWarehouse
+ JOIN vn2008.Compres c ON c.Id_compra = ilb.buy_id
+ WHERE r.display <> 0
+ GROUP BY tr.Id_Trabajador
+ ON DUPLICATE KEY UPDATE buyed = VALUES(buyed);
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `stockBuyedByWorker` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `stockBuyedByWorker`(vDate DATE, vWorker INT)
+BEGIN
+
+ DECLARE vVolume DECIMAL(10,2);
+ DECLARE vWarehouse INT DEFAULT 7;
+ CALL stockTraslation(vDate);
+
+ SELECT Volumen INTO vVolume FROM vn2008.Cubos WHERE Id_Cubo = 'cc' LIMIT 1;
+
+ SELECT c.Id_Entrada, a.Id_Article, a.Article, i.amount Cantidad, (0.6 * ( i.amount / c.packing ) * vn2008.cm3(Id_Compra))/vVolume buyed
+ FROM tmp_item i
+ JOIN vn2008.Articles a ON a.Id_Article = i.item_id
+ JOIN vn2008.Tipos t ON a.tipo_id = t.tipo_id
+ JOIN vn2008.reinos r ON r.id = t.reino_id
+ JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = t.Id_Trabajador
+ JOIN vn2008.t_item_last_buy ilb ON ilb.item_id = a.Id_Article AND ilb.warehouse_id = vWarehouse
+ JOIN vn2008.Compres c ON c.Id_compra = ilb.buy_id
+ WHERE r.display <> 0 AND tr.user_id = vWorker;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `stockBuyedByWorkerTest` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `stockBuyedByWorkerTest`(vDate DATE, vWorker INT)
+BEGIN
+
+ DECLARE vVolume DECIMAL(10,2);
+ DECLARE vWarehouse INT DEFAULT 7;
+ CALL stockTraslationTest(vDate);
+
+ SELECT Volumen INTO vVolume FROM vn2008.Cubos WHERE Id_Cubo = 'cc' LIMIT 1;
+
+ SELECT c.Id_Entrada, a.Id_Article, a.Article, i.amount Cantidad, (0.6 * ( i.amount / c.packing ) * vn2008.cm3(Id_Compra))/vVolume buyed
+ FROM tmp.item i
+ JOIN vn2008.Articles a ON a.Id_Article = i.item_id
+ JOIN vn2008.Tipos t ON a.tipo_id = t.tipo_id
+ JOIN vn2008.reinos r ON r.id = t.reino_id
+ JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = t.Id_Trabajador
+ JOIN vn2008.t_item_last_buy ilb ON ilb.item_id = a.Id_Article AND ilb.warehouse_id = vWarehouse
+ JOIN vn2008.Compres c ON c.Id_compra = ilb.buy_id
+ WHERE r.display <> 0 AND tr.user_id = vWorker;
+ 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 `stockTraslation` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `stockTraslation`(vDate DATE)
+BEGIN
+ /**
+ * Calcula el stock del vWarehouse desde FechaInventario hasta v_date
+ sin tener en cuenta las salidas del mismo dia vDate
+ para ver el transporte a reservar
+ **/
+
+ DECLARE vWarehouse INT DEFAULT 7;
+
+ DELETE FROM stockBuyed WHERE `date` = vDate;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp_item;
+ CREATE TEMPORARY TABLE tmp_item
+ (UNIQUE INDEX i USING HASH (item_id))
+ ENGINE = MEMORY
+ SELECT item_id, SUM(amount) amount FROM vn2008.item_entry_in
+ WHERE dat = vDate and vDate >= CURDATE()
+ AND warehouse_id = vWarehouse
+ GROUP BY item_id HAVING amount != 0;
+
+ CALL `cache`.stock_refresh (FALSE);
+
+ INSERT INTO tmp_item (item_id,amount)
+ SELECT item_id,s.amount FROM `cache`.stock s
+ WHERE warehouse_id = vWarehouse
+ ON DUPLICATE KEY UPDATE
+ amount = tmp_item.amount + VALUES(amount);
+
+ CALL vn2008.item_last_buy_(vWarehouse,vDate);
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `stockTraslationkk` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `stockTraslationkk`(vDate DATE)
+BEGIN
+ /**
+ * Calcula el stock del vWarehouse desde FechaInventario hasta v_date
+ sin tener en cuenta las salidas del mismo dia vDate
+ para ver el transporte a reservar
+ **/
+
+ DECLARE vWarehouse INT DEFAULT 7;
+
+ DELETE FROM stockBuyed WHERE `date` = vDate;
+ DROP TEMPORARY TABLE IF EXISTS tmp.item;
+
+ CREATE TEMPORARY TABLE tmp.item (
+ `item_id` INT,
+ `amount` DECIMAL(10, 2) DEFAULT 0.00,
+ PRIMARY KEY(item_id)
+ ) ENGINE = MEMORY;
+
+
+ IF vDate >= CURDATE() THEN
+ INSERT INTO tmp.item
+ SELECT item_id, SUM(amount) amount
+ FROM vn2008.item_entry_in
+ WHERE dat = vDate
+ AND warehouse_id = vWarehouse
+ GROUP BY item_id HAVING amount != 0;
+ END IF;
+
+ CALL `cache`.stock_refresh (FALSE);
+
+ INSERT INTO tmp.item (item_id,amount)
+ SELECT item_id,s.amount FROM `cache`.stock s
+ WHERE warehouse_id = vWarehouse
+ ON DUPLICATE KEY UPDATE
+ amount = tmp.item.amount + VALUES(amount);
+
+ CALL vn2008.item_last_buy_(vWarehouse,vDate);
+
+ select * FROM 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 `stockTraslationTest` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `stockTraslationTest`(vDate DATE)
+BEGIN
+ /**
+ * Calcula el stock del vWarehouse desde FechaInventario hasta v_date
+ sin tener en cuenta las salidas del mismo dia vDate
+ para ver el transporte a reservar
+ **/
+
+ DECLARE vWarehouse INT DEFAULT 7;
+
+ DELETE FROM stockBuyed WHERE `date` = vDate;
+ DROP TEMPORARY TABLE IF EXISTS tmp.item;
+
+ CREATE TEMPORARY TABLE tmp.item (
+ `item_id` INT,
+ `amount` DECIMAL(10, 2) DEFAULT 0.00,
+ PRIMARY KEY(item_id)
+ ) ENGINE = MEMORY;
+
+
+ IF vDate >= CURDATE() THEN
+ INSERT INTO tmp.item
+ SELECT item_id, SUM(amount) amount
+ FROM vn2008.item_entry_in
+ WHERE dat = vDate
+ AND warehouse_id = vWarehouse
+ GROUP BY item_id HAVING amount != 0;
+ END IF;
+
+ CALL `cache`.stock_refresh (FALSE);
+
+ INSERT INTO tmp.item (item_id,amount)
+ SELECT item_id,s.amount FROM `cache`.stock s
+ WHERE warehouse_id = vWarehouse
+ ON DUPLICATE KEY UPDATE
+ amount = tmp.item.amount + VALUES(amount);
+
+ CALL vn2008.item_last_buy_(vWarehouse,vDate);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `taxGetRates` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `taxGetRates`(vTaxDate DATE)
+ READS SQL DATA
+BEGIN
+/**
+ * Calcula una tabla con el IVA aplicable para la fecha data.
+ *
+ * @param vTaxDate
+ * @treturn tmp.taxGroup
+ * @treturn tmp.taxTax
+ */
+ SET vTaxDate = IFNULL(vTaxDate, CURDATE());
+
+ DROP TEMPORARY TABLE IF EXISTS
+ tmp.taxClass,
+ tmp.taxType;
+
+ -- Calcula el tipo de IVA para cada clase en cada país.
+
+ CREATE TEMPORARY TABLE tmp.taxClass
+ (INDEX (countryFk, taxClassFk))
+ ENGINE = MEMORY
+ SELECT *
+ FROM (
+ SELECT t.countryFk, g.taxClassFk, c.type
+ FROM vn.taxClassCode g
+ JOIN vn.taxCode c ON c.id = g.taxCodeFk
+ JOIN vn.taxType t ON t.id = c.taxTypeFk
+ WHERE g.effectived <= vTaxDate
+ ORDER BY g.effectived DESC
+ ) t
+ GROUP BY countryFk, taxClassFk;
+
+ -- Calcula el impuesto para cada tipo de IVA en cada país.
+
+ CREATE TEMPORARY TABLE tmp.taxType
+ (INDEX (countryFk, type))
+ ENGINE = MEMORY
+ SELECT *
+ FROM (
+ SELECT t.countryFk, c.type,
+ c.rate / 100 rate,
+ c.equalizationTax / 100 equalizationTax
+ FROM vn.taxCode c
+ JOIN vn.taxType t ON t.id = c.taxTypeFk
+ WHERE c.dated <= vTaxDate
+ ORDER BY c.dated DESC, c.equalizationTax DESC
+ ) t
+ GROUP BY countryFk, type;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticketClosure` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketClosure`()
+BEGIN
+/**
+ * Realiza el cierre de todos los
+ * tickets de la table ticketClosure.
+ */
+
+ DECLARE vDone BOOL;
+ DECLARE vClientFk INT;
+ DECLARE vTicketFk INT;
+ DECLARE vIsTaxDataChecked BOOL;
+ DECLARE vCompanyFk INT;
+ DECLARE vShipped DATE;
+ DECLARE vPriority INT DEFAULT 1;
+ DECLARE vReportDeliveryNote INT DEFAULT 1;
+ DECLARE vNewInvoiceId INT;
+ DECLARE vIsUeeMember BOOL;
+
+ DECLARE cur CURSOR FOR
+ SELECT ticketFk FROM tmp.ticketClosure;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN
+ RESIGNAL;
+ END;
+
+ INSERT INTO dailyTaskLog(state) VALUES('ticketClosure: START');
+
+ OPEN cur;
+
+ proc: LOOP
+ SET vDone = FALSE;
+
+ FETCH cur INTO vTicketFk;
+
+ IF vDone THEN
+ LEAVE proc;
+ END IF;
+
+ -- ticketClosure start
+ SELECT
+ c.id,
+ c.isTaxDataChecked,
+ t.companyFk,
+ t.shipped,
+ co.isUeeMember
+ INTO vClientFk,
+ vIsTaxDataChecked,
+ vCompanyFk,
+ vShipped,
+ vIsUeeMember
+ FROM ticket t
+ JOIN `client` c ON c.id = t.clientFk
+ JOIN province p ON p.id = c.provinceFk
+ JOIN country co ON co.id = p.countryFk
+ WHERE t.id = vTicketFk;
+
+ -- Fusión de ticket
+ -- CALL mergeTicketUnattended(vTicketFk, TRUE); JGF 2017/12/04
+
+ INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity)
+ (SELECT vTicketFk, p.id, COUNT(*)
+ FROM expedition e
+ JOIN package p ON p.itemFk = e.itemFk
+ WHERE e.ticketFk = vTicketFk AND p.isPackageReturnable
+ GROUP BY p.itemFk);
+
+ -- No retornables o no catalogados
+ INSERT INTO movement (item, ticket, concept, amount, price, priceFixed)
+ (SELECT e.itemFk, vTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.itemFk, vClientFk), 1
+ FROM expedition e
+ JOIN item i ON i.id = e.itemFk
+ LEFT JOIN package p ON p.itemFk = i.id
+ WHERE e.ticketFk = vTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0
+ AND getSpecialPrice(e.itemFk, vClientFk) > 0
+ GROUP BY e.itemFk);
+
+ IF(vIsUeeMember = FALSE) THEN
+
+ -- Facturacion rapida
+ CALL ticketTrackingAdd(vTicketFk, 'DELIVERED', 20);
+ -- Facturar si está contabilizado
+ IF vIsTaxDataChecked THEN
+
+ IF (SELECT clientTaxArea(vClientFk, vCompanyFk)) = 'NATIONAL' THEN
+ CALL invoiceMakeByClient(
+ vClientFk,
+ (SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')),
+ vShipped,
+ vCompanyFk,
+ vNewInvoiceId);
+ ELSE
+ CALL invoiceMakeByTicket(vTicketFk, (SELECT invoiceSerial(vClientFk, vCompanyFk, 'R')), vNewInvoiceId);
+ END IF;
+
+ END IF;
+ ELSE
+ -- Albaran_print
+ CALL ticketTrackingAdd(vTicketFk, (SELECT vn.getAlert3State(vTicketFk)), 20);
+ INSERT INTO printServerQueue(priorityFk, reportFk, param1) VALUES(vPriority, vReportDeliveryNote, vTicketFk);
+ END IF;
+
+ -- ticketClosure end
+ END LOOP;
+
+ CLOSE cur;
+
+ INSERT INTO dailyTaskLog(state) VALUES('ticketClosure: 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 `ticketClosureAgencyList` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketClosureAgencyList`(vWarehouseFk INT, vDateTo DATE)
+BEGIN
+/**
+ * Inserta los tickets de todos los almacenes en la tabla temporal
+ * para ser cerrados.
+ *
+ * @param vWarehouseFk Id del almacén
+ * @param vDate Fecha del cierre
+ */
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure;
+
+ CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY (
+ SELECT
+ t.id AS ticketFk
+ FROM expedition e
+ INNER JOIN ticket t ON t.id = e.ticketFk
+ INNER JOIN tmp.ticketClosureAgencyList al ON al.agencyModeFk = t.agencyModeFk
+ LEFT JOIN ticketState ts ON ts.ticketFk = t.id
+ WHERE
+ ts.alertLevel = 2
+ AND t.warehouseFk = vWarehouseFk
+ AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo
+ AND t.refFk IS NULL
+ GROUP BY e.ticketFk);
+
+ DROP TEMPORARY TABLE tmp.ticketClosureAgencyList;
+
+ CALL ticketClosure();
+
+ DROP TEMPORARY TABLE tmp.ticketClosure;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticketClosureAgencyListAdd` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketClosureAgencyListAdd`(vAgencyModeFk INT)
+BEGIN
+/**
+ * Prepara un listado de agencias sobre los que se realizará el cierre.
+ * Es necesario llamar al procedimiento por cada agencia.
+ *
+ * @param vAgencyModeFk Id almacén
+ */
+ CREATE TEMPORARY TABLE IF NOT EXISTS tmp.ticketClosureAgencyList (
+ `agencyModeFk` INT,
+ PRIMARY KEY(agencyModeFk)) ENGINE = MEMORY;
+
+ INSERT INTO tmp.ticketClosureAgencyList(agencyModeFk) VALUES(vAgencyModeFk);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticketClosurekk` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketClosurekk`()
+BEGIN
+/**
+ * Realiza el cierre de todos los
+ * tickets de la table ticketClosure.
+ */
+
+ DECLARE vDone BOOL;
+ DECLARE vClientFk INT;
+ DECLARE vCredit INT;
+ DECLARE vPayMethod INT;
+ DECLARE vTicketFk INT;
+ DECLARE vIsToBeMailed BOOL;
+ DECLARE vIsTaxDataChecked BOOL;
+ DECLARE vCompanyFk INT;
+ DECLARE vDeliveryMethod INT;
+ DECLARE vAgencyFk INT;
+ DECLARE vAgencyModeFk INT;
+ DECLARE vWarehouseFk INT;
+ DECLARE vShipped DATE;
+ DECLARE vPayMethodCard INT DEFAULT 5;
+ DECLARE vPriority INT DEFAULT 1;
+ DECLARE vReportDeliveryNote INT DEFAULT 1;
+ DECLARE vNewInvoiceId INT;
+ DECLARE vHasToInvoice BOOL;
+
+ DECLARE cur CURSOR FOR
+ SELECT ticketFk FROM tmp.ticketClosure;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN
+ RESIGNAL;
+ END;
+
+ INSERT INTO dailyTaskLog(state) VALUES('ticketClosure: START');
+
+ OPEN cur;
+
+ proc: LOOP
+ SET vDone = FALSE;
+
+ FETCH cur INTO vTicketFk;
+
+ IF vDone THEN
+ LEAVE proc;
+ END IF;
+
+ -- ticketClosure start
+ SELECT
+ c.id,
+ c.credit,
+ c.paymentMethodFk,
+ c.isToBeMailed,
+ c.isTaxDataChecked,
+ t.companyFk,
+ IFNULL(aw.agencyType, a.deliveryMethod) AS deliveryMethod,
+ a.id AS agencyFk,
+ t.agencyModeFk,
+ t.warehouseFk,
+ t.shipped,
+ c.hasToInvoice
+ INTO vClientFk,
+ vCredit,
+ vPayMethod,
+ vIsToBeMailed,
+ vIsTaxDataChecked,
+ vCompanyFk,
+ vDeliveryMethod,
+ vAgencyFk,
+ vAgencyModeFk,
+ vWarehouseFk,
+ vShipped,
+ vHasToInvoice
+ FROM ticket t
+ INNER JOIN `client` c ON c.id = t.clientFk
+ LEFT JOIN agencyMode a ON a.id = t.agencyModeFk
+ LEFT JOIN agencyWarehouse aw ON a.id = aw.agencyFk AND t.warehouseFk = aw.warehouseFk
+ WHERE t.id = vTicketFk;
+
+ -- Fusión de ticket
+ CALL mergeTicketUnattended(vTicketFk, TRUE);
+
+ INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity)
+ (SELECT vTicketFk, p.id, COUNT(*)
+ FROM expedition e
+ JOIN package p ON p.itemFk = e.itemFk
+ WHERE e.ticketFk = vTicketFk AND p.isPackageReturnable
+ GROUP BY p.itemFk);
+
+ -- No retornables o no catalogados
+ INSERT INTO movement (item, ticket, concept, amount, price, priceFixed)
+ (SELECT e.itemFk, vTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.itemFk, vClientFk), 1
+ FROM expedition e
+ JOIN item i ON i.id = e.itemFk
+ LEFT JOIN package p ON p.itemFk = i.id
+ WHERE e.ticketFk = vTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0
+ GROUP BY e.itemFk);
+
+ -- Albaran_print
+ CALL ticketTrackingAdd(vTicketFk, (SELECT vn.getAlert3State(vTicketFk)), 20);
+ INSERT INTO printServerQueue(priorityFk, reportFk, param1) VALUES(vPriority, vReportDeliveryNote, vTicketFk);
+
+ IF((vCredit <= 1 OR vPayMethod = vPayMethodCard) AND vHasToInvoice <> FALSE) THEN
+
+ -- Facturacion rapida
+ CALL ticketTrackingAdd(vTicketFk, 'DELIVERED', 20);
+ -- Facturar si está contabilizado
+ IF vIsTaxDataChecked THEN
+
+ IF (SELECT clientTaxArea(vClientFk, vCompanyFk)) = 'NATIONAL' THEN
+ CALL invoiceMakeByClient(
+ vClientFk,
+ (SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')),
+ vShipped,
+ vCompanyFk,
+ vNewInvoiceId);
+ ELSE
+ CALL invoiceMakeByTicket(vTicketFk, (SELECT invoiceSerial(vClientFk, vCompanyFk, 'R')), vNewInvoiceId);
+ END IF;
+
+ END IF;
+ ELSE
+ -- Albaran_print
+ CALL ticketTrackingAdd(vTicketFk, (SELECT vn.getAlert3State(vTicketFk)), 20);
+ INSERT INTO printServerQueue(priorityFk, reportFk, param1) VALUES(vPriority, vReportDeliveryNote, vTicketFk);
+ END IF;
+
+ -- ticketClosure end
+ END LOOP;
+
+ CLOSE cur;
+
+ INSERT INTO dailyTaskLog(state) VALUES('ticketClosure: 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 `ticketClosureMultiWarehouse` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketClosureMultiWarehouse`(vDateTo DATE)
+BEGIN
+/**
+ * Inserta los tickets de todos los almacenes en la tabla temporal
+ * para ser cerrados.
+ *
+ * @param vDate Fecha del cierre
+ */
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure;
+
+ CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY (
+ SELECT
+ t.id AS ticketFk
+ FROM expedition e
+ INNER JOIN ticket t ON t.id = e.ticketFk
+ INNER JOIN warehouse w ON w.id = t.warehouseFk AND hasComission
+ LEFT JOIN ticketState ts ON ts.ticketFk = t.id
+ WHERE
+ ts.alertLevel = 2
+ AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo
+ AND t.refFk IS NULL
+ GROUP BY e.ticketFk);
+
+ CALL ticketClosure();
+
+ DROP TEMPORARY TABLE tmp.ticketClosure;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticketClosureRoute` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketClosureRoute`(vWarehouseFk INT, vRouteFk INT, vDateTo DATE)
+BEGIN
+/**
+ * Inserta los tickets de la ruta en la tabla temporal
+ * para ser cerrados.
+ *
+ * @param vWarehouseFk Almacén a cerrar
+ * @param vRouteFk Ruta a cerrar
+ * @param vDate Fecha del cierre
+ */
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure;
+
+ CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY (
+ SELECT
+ t.id AS ticketFk
+ FROM expedition e
+ INNER JOIN ticket t ON t.id = e.ticketFk
+ LEFT JOIN ticketState ts ON ts.ticketFk = t.id
+ WHERE
+ ts.alertLevel = 2
+ AND t.warehouseFk = vWarehouseFk
+ AND t.routeFk = vRouteFk
+ AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo
+ AND t.refFk IS NULL
+ GROUP BY e.ticketFk);
+
+ CALL ticketClosure();
+
+ DROP TEMPORARY TABLE tmp.ticketClosure;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticketClosureTicket` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketClosureTicket`(vTicketFk INT)
+BEGIN
+
+/**
+ * Inserta el ticket en la tabla temporal
+ * para ser cerrado.
+ *
+ * @param vTicketFk Id del ticket
+ */
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure;
+
+ CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY (
+ SELECT
+ t.id AS ticketFk
+ FROM expedition e
+ INNER JOIN ticket t ON t.id = e.ticketFk
+ LEFT JOIN ticketState ts ON ts.ticketFk = t.id
+ WHERE
+ ts.alertLevel = 2
+ AND t.id = vTicketFk
+ AND t.refFk IS NULL
+ GROUP BY e.ticketFk);
+
+ CALL ticketClosure();
+
+ DROP TEMPORARY TABLE tmp.ticketClosure;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticketClosureWarehouse` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketClosureWarehouse`(vWarehouseFk INT, vDateTo DATE)
+BEGIN
+/**
+ * Inserta los tickets del almacen en la tabla temporal
+ * para ser cerrados.
+ *
+ * @param vWarehouseFk Almacén a cerrar
+ * @param vDate Fecha del cierre
+ */
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure;
+
+ CREATE TEMPORARY TABLE ticketClosure ENGINE = MEMORY(
+ SELECT
+ t.id AS ticketFk
+ FROM expedition e
+ INNER JOIN ticket t ON t.id = e.ticketFk
+ LEFT JOIN ticketState ts ON ts.ticketFk = t.id
+ WHERE
+ ts.alertLevel = 2
+ AND t.warehouseFk = vWarehouseFk
+ AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo
+ AND t.refFk IS NULL
+ GROUP BY e.ticketFk);
+
+ CALL ticketClosure();
+
+ DROP TEMPORARY TABLE tmp.ticketClosure;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticketCreate` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketCreate`(
+ IN vClientId INT
+ , IN vShipped DATE
+ , IN vWarehouseId INT
+ , IN vCompanyFk INT
+ , IN vAddressFk INT
+ , IN vAgencyType INT
+ , IN vRouteFk INT
+ , IN vlanded DATE
+ , OUT vNewTicket INT)
+BEGIN
+ DECLARE vClientOrnamentales INT DEFAULT 5270;
+ DECLARE vCompanyOrn INT DEFAULT 1381;
+ DECLARE vProvinceName VARCHAR(255);
+
+ SELECT p.name INTO vProvinceName
+ FROM vn.client c
+ JOIN province p ON p.id = c.provinceFk
+ WHERE c.id = vClientId;
+
+ IF vProvinceName IN ('SANTA CRUZ DE TENERIFE','LAS PALMAS DE GRAN CANARIA') AND vClientId <> vClientOrnamentales THEN
+ SET vCompanyFk = vCompanyOrn;
+ END IF;
+
+ INSERT INTO vn2008.Tickets (
+ Id_Cliente,
+ Fecha,
+ Id_Consigna,
+ Id_Agencia,
+ Alias,
+ warehouse_id,
+ Id_Ruta,
+ empresa_id,
+ landing)
+ SELECT
+ vClientId,
+ vShipped,
+ a.id,
+ IF(vAgencyType,vAgencyType,a.agencyFk),
+ a.nickname,
+ vWarehouseId,
+ IF(vRouteFk,vRouteFk,NULL),
+ vCompanyFk,
+ vlanded
+ FROM address a
+ JOIN agencyMode am ON am.id = a.agencyFk
+ WHERE IF(vAddressFk, a.id = vAddressFk, a.defaultAddress != 0)
+ AND a.clientFk = vClientId
+ LIMIT 1;
+
+ SET vNewTicket = LAST_INSERT_ID();
+
+ INSERT INTO ticketObservation(ticketFk, observationTypeFk, description)
+ SELECT vNewTicket,ao.observationTypeFk, ao.description
+ FROM addressObservation ao
+ JOIN address a ON a.id =ao.addressFk
+ WHERE a.clientFk = vClientId AND a.defaultAddress != 0;
+
+
+ CALL logAdd(vNewTicket,'insert','ticket',concat('CREA EL TICKET',' ',vNewTicket));
+
+ IF (SELECT isCreatedAsServed FROM vn.client WHERE id = vClientId ) <> 0
+ THEN
+ INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador)
+ SELECT id, vNewTicket, getWorker()
+ 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 DROP PROCEDURE IF EXISTS `ticketGetTax` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketGetTax`(vBillingDate DATE)
+ READS SQL DATA
+BEGIN
+/**
+ * Calcula la base imponible, el IVA y el recargo de equivalencia para
+ * un conjunto de tickets.
+ *
+ * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular
+ * @param vBillingDate Fecha de facturación
+ * @treturn tmp.ticketTax Impuesto desglosado para cada ticket
+ */
+ CALL vn.taxGetRates (vBillingDate);
+
+ -- Calcula el IVA y el recargo desglosado para cada ticket.
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax;
+ CREATE TEMPORARY TABLE tmp.ticketTax
+ (INDEX (ticketFk))
+ ENGINE = MEMORY
+ SELECT t.ticketFk, t.type, t.taxBase,
+ CAST(IF(t.hasTax, t.taxBase * x.rate, 0) AS DECIMAL(10,2)) tax,
+ CAST(IF(t.hasEqualizationTax, t.taxBase * x.equalizationTax, 0) AS DECIMAL(10,2)) equalizationTax
+ FROM (
+ SELECT i.ticketFk, g.countryFk, g.type
+ ,SUM(CAST(m.quantity * m.price * (100 - m.discount) / 100 AS DECIMAL(10,2))) AS taxBase
+ ,NOT(c.isVies AND p.countryFk <> c.countryFk) hasTax
+ ,c.isEqualizated != FALSE AS hasEqualizationTax
+ FROM tmp.ticket i
+ JOIN vn.ticket t ON t.id = i.ticketFk
+ JOIN vn.sale m ON m.ticketFk = t.id
+ JOIN vn.item a ON a.id = m.itemFk
+ JOIN vn.client c ON c.id = t.clientFk
+ JOIN vn.supplier p ON p.id = t.companyFk
+ JOIN tmp.taxClass g
+ ON g.countryFk = p.countryFk AND g.taxClassFk = a.taxClassFk
+ GROUP BY i.ticketFk, g.type
+ ) t
+ JOIN tmp.taxType x
+ ON x.countryFk = t.countryFk AND x.type = t.type;
+
+ DROP TEMPORARY TABLE
+ tmp.taxClass,
+ tmp.taxType;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticketGetTotal` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketGetTotal`()
+ READS SQL DATA
+BEGIN
+/**
+ * Calcula el total con IVA para un conjunto de tickets.
+ *
+ * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular
+ * @treturn tmp.ticketTotal Total para cada ticket
+ */
+ CALL ticketGetTax (NULL);
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticketTotal;
+ CREATE TEMPORARY TABLE tmp.ticketTotal
+ (INDEX (ticketFk))
+ ENGINE = MEMORY
+ SELECT ticketFk, SUM(taxBase + tax + equalizationTax) AS total
+ FROM tmp.ticketTax GROUP BY ticketFk;
+
+ DROP TEMPORARY TABLE tmp.ticketTax;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticketToInvoiceByAddress` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketToInvoiceByAddress`(
+ vStarted DATE,
+ vEnded DATETIME,
+ vAddress INT,
+ vCompany INT
+ )
+BEGIN
+
+ SET vEnded = util.dayEnd(vEnded);
+
+ DROP TEMPORARY TABLE IF EXISTS vn.ticketToInvoice;
+
+ CREATE TEMPORARY TABLE vn.ticketToInvoice
+ SELECT id
+ FROM vn.ticket
+ WHERE addressFk = vAddress
+ AND companyFk = vCompany
+ AND shipped BETWEEN vStarted AND vEnded
+ AND refFk 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 `ticketToInvoiceByClient` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketToInvoiceByClient`(
+ vStarted DATE,
+ vEnded DATETIME,
+ vClient INT,
+ vCompany INT
+ )
+BEGIN
+
+ SET vEnded = util.dayEnd(vEnded);
+
+ DROP TEMPORARY TABLE IF EXISTS vn.ticketToInvoice;
+
+ CREATE TEMPORARY TABLE vn.ticketToInvoice
+ SELECT id
+ FROM vn.ticket
+ WHERE clientFk = vClient
+ AND companyFk = vCompany
+ AND shipped BETWEEN vStarted AND vEnded
+ AND refFk 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 `ticketToInvoiceByDate` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketToInvoiceByDate`(
+ vStarted DATE,
+ vEnded DATETIME,
+ vClient INT,
+ vCompany INT
+ )
+BEGIN
+
+ SET vEnded = util.dayEnd(vEnded);
+
+ DROP TEMPORARY TABLE IF EXISTS vn.ticketToInvoice;
+
+ CREATE TEMPORARY TABLE vn.ticketToInvoice
+ SELECT id
+ FROM vn.ticket
+ WHERE clientFk = vClient
+ AND companyFk = vCompany
+ AND shipped BETWEEN vStarted AND vEnded
+ AND refFk 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 `ticketToInvoiceByRef` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketToInvoiceByRef`(IN vInvoiceRef VARCHAR(15))
+BEGIN
+
+/* Para tickets ya facturados, vuelve a repetir el proceso de facturación.
+*
+* @param vInvoiceRef Factura
+*/
+
+ DECLARE vInvoice INT;
+ DECLARE vCountry INT;
+ DECLARE vTaxArea VARCHAR(15);
+ DECLARE vSpainCountryCode INT DEFAULT 1;
+
+ SELECT id
+ INTO vInvoice
+ FROM vn.invoiceOut
+ WHERE ref = vInvoiceRef;
+
+ SELECT s.countryFk
+ INTO vCountry
+ FROM vn.supplier s
+ JOIN vn.invoiceOut io ON io.companyFk = s.id
+ WHERE io.id = vInvoice;
+
+ SELECT IF(
+ c.isEqualizated
+ AND c.countryFk = vSpainCountryCode
+ AND i.taxAreaFk = 'NATIONAL',
+ 'EQU',
+ i.taxAreaFk
+ )
+ INTO vTaxArea
+ FROM vn.invoiceOutSerial i
+ JOIN vn.invoiceOut io ON io.serial = i.code
+ JOIN vn.client c ON c.id = io.clientFk
+ WHERE io.id = vInvoice;
+
+ DROP TEMPORARY TABLE IF EXISTS vn.ticketToInvoice;
+
+ CREATE TEMPORARY TABLE vn.ticketToInvoice
+ SELECT id
+ FROM vn.ticket
+ WHERE refFk = vInvoiceRef;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticketToInvoiceByTicket` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketToInvoiceByTicket`(vTicket INT)
+BEGIN
+
+ DROP TEMPORARY TABLE IF EXISTS vn.ticketToInvoice;
+
+ CREATE TEMPORARY TABLE vn.ticketToInvoice
+ SELECT id
+ FROM vn.ticket
+ WHERE id = vTicket
+ AND refFk 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 `ticketTrackingAdd` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketTrackingAdd`(vTicketFk INT, vState VARCHAR(25) CHARSET UTF8, vWorkerFk INT)
+BEGIN
+/**
+ * Inserta un registro de cambios en un ticket.
+ * @param vTicketFk Id del ticket
+ * @param vState Código del estado
+ * @param vWorkerFk Id del trabajador
+ */
+ INSERT INTO ticketTracking (stateFk, ticketFk, workerFk)
+ SELECT s.id, vTicketFk, vWorkerFk FROM state s WHERE s.code = vState;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `workerCreateExternal` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `workerCreateExternal`(
+ vFirstName VARCHAR(50),
+ vSurname1 VARCHAR(50),
+ vSurname2 VARCHAR(50),
+ vUser VARCHAR(20),
+ vPassword VARCHAR(50),
+ vWorkerCode VARCHAR(3),
+ vRole INT(2)
+ )
+BEGIN
+
+ DECLARE vUserId INT;
+ DECLARE vWorkerPako INT DEFAULT 2;
+ DECLARE vSurnames VARCHAR(100);
+
+ INSERT INTO account.user(name,password,role)
+ SELECT vUser,MD5(vPassword),vRole;
+
+ SET vUserId = LAST_INSERT_ID();
+ /*
+ INSERT INTO vn.worker(firstName,name,bossFk,workerCode,user_id)
+ SELECT vFirstName,CONCAT(vSurname1,' ',vSurname2),2,vWorkerCode,vUser;
+ */
+
+ IF vSurname2 IS NULL THEN
+ SET vSurnames = vSurname1;
+ ELSE
+ SET vSurnames = CONCAT(vSurname1, ' ', vSurname2);
+ END IF;
+
+ INSERT INTO vn2008.Trabajadores(Nombre, Apellidos, boss, CodigoTrabajador, user_id)
+ SELECT vFirstName, vSurnames, vWorkerPako, vWorkerCode, vUserId;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `workerDisable` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `workerDisable`(vUserId int)
+BEGIN
+
+ DELETE FROM account.account
+ WHERE id = vUserId;
+
+ UPDATE account.user
+ SET role = 2
+ WHERE id = vUserId;
+
+ UPDATE `client`
+ SET credit = 0
+ WHERE id = vUserId;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `workingHours` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `workingHours`(username varchar(255), logon boolean)
+BEGIN
+ DECLARE userid int(11);
+
+ SELECT vn.getUserId(username) INTO userid;
+ SELECT username, userid;
+ IF userid IS NOT NULL THEN
+ IF (logon) THEN
+ CALL vn.workingHoursTimeIn(userid);
+ ELSE
+ CALL vn.workingHoursTimeOut(userid);
+ 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 */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `workingHoursTimeIn` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `workingHoursTimeIn`(vUserId INT(11))
+BEGIN
+ INSERT INTO vn.workingHours (timeIn, userId)
+ VALUES (NOW(),vUserId);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `workingHoursTimeOut` */;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `workingHoursTimeOut`(vUserId INT(11))
+BEGIN
+ UPDATE vn.workingHours
+ SET timeOut = NOW()
+ WHERE userId = vUserId
+ AND DATE(timeIn) = 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 */ ;
+ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `zoneNest` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `zoneNest`()
+BEGIN
+
+ DECLARE vDone BOOL;
+ DECLARE vParent INT DEFAULT 1;
+ DECLARE vGeoFk INT;
+ DECLARE vChildFk INT;
+ DECLARE vChildName VARCHAR(45);
+
+ DECLARE townCur CURSOR FOR
+ SELECT p.geoFk, t.id, t.`name`
+ FROM town t
+ JOIN province p ON p.id = t.provinceFk
+ WHERE t.id BETWEEN 30001 AND 40000;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
+
+ -- > Town cursor start
+ OPEN townCur;
+
+ townLoop: LOOP
+ SET vDone = FALSE;
+
+ FETCH townCur INTO vParent, vChildFk, vChildName;
+
+ IF vDone THEN
+ LEAVE townLoop;
+ END IF;
+
+ CALL nestAdd('vn', 'zoneNest', vParent, vChildName);
+
+ -- Update town geoFk
+ SET vGeoFk = LAST_INSERT_ID();
+ UPDATE town SET geoFk = vGeoFk WHERE id = vChildFk;
+ END LOOP;
+ CLOSE townCur;
+ -- < Town cursor 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 */ ;
+
+
+-- Dump completed on 2017-12-27 7:51:23
diff --git a/services/db/localDB04StructureOthersDB.sql b/services/db/localDB04StructureOthersDB.sql
new file mode 100644
index 000000000..6aafa4585
--- /dev/null
+++ b/services/db/localDB04StructureOthersDB.sql
@@ -0,0 +1,14304 @@
+-- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64)
+--
+-- Host: db.verdnatura.es Database: cache
+-- ------------------------------------------------------
+-- 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 */;
+
+--
+-- Current Database: `cache`
+--
+
+CREATE DATABASE /*!32312 IF NOT EXISTS*/ `cache` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
+
+USE `cache`;
+
+--
+-- Table structure for table `available`
+--
+
+DROP TABLE IF EXISTS `available`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `available` (
+ `calc_id` int(10) unsigned NOT NULL,
+ `item_id` int(11) NOT NULL,
+ `available` int(11) NOT NULL,
+ KEY `calc_id_4` (`calc_id`) USING BTREE,
+ KEY `calc_id` (`item_id`,`calc_id`)
+) ENGINE=MEMORY 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` (
+ `code` varchar(22) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+ `Id_Article` int(11) NOT NULL DEFAULT '0',
+ `Article` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Medida` int(10) unsigned DEFAULT NULL,
+ `Color` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Categoria` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Producer` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`code`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `cache`
+--
+
+DROP TABLE IF EXISTS `cache`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `cache` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `name` varchar(50) CHARACTER SET utf8 NOT NULL,
+ `lifetime` time NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `name` (`name`)
+) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `cache_calc`
+--
+
+DROP TABLE IF EXISTS `cache_calc`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `cache_calc` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `cache_id` int(10) unsigned NOT NULL,
+ `cacheName` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
+ `params` varchar(100) CHARACTER SET utf8 NOT NULL DEFAULT '',
+ `last_refresh` datetime DEFAULT NULL,
+ `expires` datetime DEFAULT NULL,
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `connection_id` int(10) unsigned DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `cache_name` (`cache_id`,`params`),
+ KEY `cache_id` (`cache_id`),
+ KEY `cacheName` (`cacheName`),
+ KEY `expires` (`expires`)
+) ENGINE=InnoDB AUTO_INCREMENT=44716 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `cache_valid`
+--
+
+DROP TABLE IF EXISTS `cache_valid`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `cache_valid` (
+ `valid` tinyint(3) unsigned NOT NULL
+) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `dailyTaskLog`
+--
+
+DROP TABLE IF EXISTS `dailyTaskLog`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `dailyTaskLog` (
+ `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
+ `created` 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 `departure_limit`
+--
+
+DROP TABLE IF EXISTS `departure_limit`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `departure_limit` (
+ `warehouse_id` smallint(6) unsigned NOT NULL,
+ `fecha` date NOT NULL,
+ `hora` int(11) NOT NULL DEFAULT '0',
+ `minSpeed` decimal(10,2) NOT NULL DEFAULT '0.00',
+ PRIMARY KEY (`warehouse_id`,`fecha`),
+ CONSTRAINT `warehouse_departure` FOREIGN KEY (`warehouse_id`) REFERENCES `vn2008`.`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 `equalizator`
+--
+
+DROP TABLE IF EXISTS `equalizator`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `equalizator` (
+ `warehouse_id` int(11) NOT NULL,
+ `Vista` int(11) NOT NULL,
+ `Pedido` int(11) DEFAULT NULL,
+ `Impreso` int(11) DEFAULT NULL,
+ `Encajado` int(11) DEFAULT NULL,
+ PRIMARY KEY (`Vista`,`warehouse_id`)
+) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `itemTagFormat`
+--
+
+DROP TABLE IF EXISTS `itemTagFormat`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `itemTagFormat` (
+ `itemFk` int(11) NOT NULL,
+ `labels1` varchar(80) CHARACTER SET utf8 DEFAULT NULL,
+ `values1` varchar(80) CHARACTER SET utf8 DEFAULT NULL,
+ `labels2` varchar(80) CHARACTER SET utf8 DEFAULT NULL,
+ `values2` varchar(80) CHARACTER SET utf8 DEFAULT NULL,
+ `description` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
+ PRIMARY KEY (`itemFk`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena el formato para los tags de los articulos';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `item_range`
+--
+
+DROP TABLE IF EXISTS `item_range`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `item_range` (
+ `calc_id` int(11) NOT NULL,
+ `item_id` int(11) NOT NULL,
+ `date_end` datetime DEFAULT NULL,
+ KEY `calc_item` (`calc_id`,`item_id`),
+ KEY `calc_id` (`calc_id`) USING BTREE
+) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `last_buy`
+--
+
+DROP TABLE IF EXISTS `last_buy`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `last_buy` (
+ `item_id` int(10) unsigned NOT NULL,
+ `warehouse_id` smallint(5) unsigned NOT NULL,
+ `buy_id` int(10) unsigned DEFAULT NULL,
+ `landing` date DEFAULT NULL,
+ KEY `buy_id` (`buy_id`),
+ KEY `item_id` (`item_id`,`warehouse_id`),
+ KEY `warehouse_id` (`warehouse_id`) USING BTREE
+) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `prod_graphic_source`
+--
+
+DROP TABLE IF EXISTS `prod_graphic_source`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `prod_graphic_source` (
+ `m3` double NOT NULL DEFAULT '0',
+ `warehouse_id` int(11) NOT NULL,
+ `hora` int(11) NOT NULL,
+ `order` int(11) NOT NULL DEFAULT '0',
+ `alert_level` int(11) NOT NULL DEFAULT '0',
+ `Agencia` varchar(45) CHARACTER SET utf8 NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `stock`
+--
+
+DROP TABLE IF EXISTS `stock`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `stock` (
+ `warehouse_id` smallint(5) unsigned NOT NULL,
+ `item_id` int(10) unsigned NOT NULL,
+ `amount` int(11) NOT NULL,
+ KEY `warehouse_id` (`warehouse_id`,`item_id`),
+ KEY `warehouse_id_2` (`warehouse_id`) USING BTREE
+) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `visible`
+--
+
+DROP TABLE IF EXISTS `visible`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `visible` (
+ `calc_id` int(10) unsigned NOT NULL,
+ `item_id` int(11) NOT NULL,
+ `visible` int(11) NOT NULL,
+ KEY `id` (`calc_id`) USING BTREE,
+ KEY `calc_id` (`calc_id`,`item_id`)
+) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `weekly_sales`
+--
+
+DROP TABLE IF EXISTS `weekly_sales`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `weekly_sales` (
+ `week` int(10) unsigned NOT NULL,
+ `item_id` int(10) unsigned NOT NULL,
+ `warehouse_id` smallint(5) unsigned NOT NULL,
+ `amount` int(11) NOT NULL,
+ `price` double NOT NULL,
+ KEY `item_id` (`item_id`,`warehouse_id`),
+ KEY `week` (`week`) USING BTREE
+) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping events for database 'cache'
+--
+/*!50106 SET @save_time_zone= @@TIME_ZONE */ ;
+/*!50106 DROP EVENT IF EXISTS `barcodes_update` */;
+DELIMITER ;;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;;
+/*!50003 SET character_set_client = utf8 */ ;;
+/*!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' */ ;;
+/*!50003 SET @saved_time_zone = @@time_zone */ ;;
+/*!50003 SET time_zone = 'SYSTEM' */ ;;
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `barcodes_update` ON SCHEDULE EVERY 1 HOUR STARTS '2016-08-17 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO CALL barcodes_update() */ ;;
+/*!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 */ ;;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;;
+/*!50106 DROP EVENT IF EXISTS `cacheCalcClean` */;;
+DELIMITER ;;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;;
+/*!50003 SET @saved_cs_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 `cacheCalcClean` ON SCHEDULE EVERY 30 MINUTE STARTS '2017-01-23 13:15:58' ON COMPLETION NOT PRESERVE ENABLE DO CALL cacheCalcClean() */ ;;
+/*!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 */ ;;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;;
+DELIMITER ;
+/*!50106 SET TIME_ZONE= @save_time_zone */ ;
+
+--
+-- Dumping routines for database 'cache'
+--
+/*!50003 DROP PROCEDURE IF EXISTS `available_refresh` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `available_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT, v_date DATE)
+proc: BEGIN
+ DECLARE v_date_ini DATE;
+ DECLARE v_date_end DATETIME;
+ DECLARE v_reserve_date DATETIME;
+ DECLARE v_params CHAR(100);
+ DECLARE v_date_inv DATE;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ CALL cache_calc_unlock (v_calc);
+ RESIGNAL;
+ END;
+
+ IF v_date < CURDATE()
+ THEN
+ LEAVE proc;
+ END IF;
+
+ CALL vn2008.item_stock (v_warehouse, v_date, NULL);
+
+ SET v_params = CONCAT_WS('/', v_warehouse, v_date);
+ CALL cache_calc_start (v_calc, v_refresh, 'available', v_params);
+
+ IF !v_refresh
+ THEN
+ LEAVE proc;
+ END IF;
+
+ -- Limpia las caches antiguas
+
+ DELETE a
+ FROM available a
+ LEFT JOIN cache_calc c ON c.id = a.calc_id
+ WHERE c.id IS 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.item_id, IF(t.life IS NULL, NULL, TIMESTAMP(TIMESTAMPADD(DAY, t.life, c.landing), '23:59:59')) AS date_end
+ FROM (
+ SELECT c.Id_Article item_id, MAX(landing) landing
+ 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 = v_warehouse
+ AND NOT e.Inventario
+ AND NOT e.Redada
+ GROUP BY Id_Article
+ ) 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;
+/*
+ -- Tabla con el ultimo dia de precios fijados para cada producto que hace un replace de la anterior
+
+ 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;
+
+ REPLACE item_range
+ SELECT item_id, TIMESTAMP(date_end, '23:59:59') date_end FROM (
+ SELECT p.item_id, p.date_end
+ FROM vn2008.price_fixed p
+ LEFT JOIN item_range_copy i USING(item_id)
+ WHERE IFNULL(i.date_end,v_date_ini) BETWEEN p.date_start AND p.date_end
+ AND warehouse_id IN (0, v_warehouse)
+ ORDER BY item_id, warehouse_id DESC, date_end DESC
+ ) t GROUP BY item_id;
+
+ 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 * FROM item_range;
+
+ DROP TEMPORARY TABLE IF EXISTS item_range_copy2;
+ CREATE TEMPORARY TABLE item_range_copy2 LIKE item_range;
+ INSERT INTO item_range_copy2
+ SELECT * FROM item_range;
+
+ DROP TEMPORARY TABLE IF EXISTS item_range_copy3;
+ CREATE TEMPORARY TABLE item_range_copy3 LIKE item_range;
+ INSERT INTO item_range_copy3
+ SELECT * FROM item_range;
+
+ DROP TEMPORARY TABLE IF EXISTS item_range_copy4;
+ CREATE TEMPORARY TABLE item_range_copy4 LIKE item_range;
+ INSERT INTO item_range_copy4
+ SELECT * FROM item_range;
+
+ -- Calcula el ATP
+
+ DELETE FROM available WHERE calc_id = v_calc;
+
+ INSERT INTO available (calc_id, item_id, available)
+ SELECT v_calc, t.item_id, SUM(stock) amount 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 = v_warehouse
+ 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 = v_warehouse
+ 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 = v_warehouse
+ 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 = v_warehouse
+ 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 amount != 0;
+
+
+ DROP TEMPORARY TABLE
+ vn2008.tmp_item
+ ,item_range
+ ,item_range_copy1
+ ,item_range_copy2
+ ,item_range_copy3
+ ,item_range_copy4;
+
+ CALL cache_calc_end (v_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 `available_refreshtest` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `available_refreshtest`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT, v_date DATE)
+proc: BEGIN
+ DECLARE v_date_ini DATE;
+ DECLARE v_date_end DATETIME;
+ DECLARE v_reserve_date DATETIME;
+ DECLARE v_params CHAR(100);
+ DECLARE v_date_inv DATE;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ CALL cache_calc_unlock (v_calc);
+ RESIGNAL;
+ END;
+
+ IF v_date < CURDATE()
+ THEN
+ LEAVE proc;
+ END IF;
+
+ CALL vn2008.item_stock (v_warehouse, v_date, NULL);
+
+ SET v_params = CONCAT_WS('/', v_warehouse, v_date);
+ CALL cache_calc_start (v_calc, v_refresh, 'available', v_params);
+
+ IF !v_refresh
+ THEN
+ LEAVE proc;
+ END IF;
+
+ -- Limpia las caches antiguas
+
+ IF TRUE -- GET_LOCK('available/clean', 1)
+ THEN
+ DELETE FROM available WHERE calc_id NOT IN (
+ SELECT cc.id
+ FROM `cache` c
+ JOIN cache_calc cc ON c.id = cc.cache_id
+ WHERE c.`name` = 'available');
+
+ -- DO RELEASE_LOCK('available/clean');
+ END IF;
+
+ -- 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.item_id, IF(t.life IS NULL, NULL, TIMESTAMP(TIMESTAMPADD(DAY, t.life, c.landing), '23:59:59')) AS date_end
+ FROM (
+ SELECT c.Id_Article item_id, MAX(landing) landing
+ 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 = v_warehouse
+ AND NOT e.Inventario
+ AND NOT e.Redada
+ GROUP BY Id_Article
+ ) 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;
+/*
+ -- Tabla con el ultimo dia de precios fijados para cada producto que hace un replace de la anterior
+
+ 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;
+
+ REPLACE item_range
+ SELECT item_id, TIMESTAMP(date_end, '23:59:59') date_end FROM (
+ SELECT p.item_id, p.date_end
+ FROM vn2008.price_fixed p
+ LEFT JOIN item_range_copy i USING(item_id)
+ WHERE IFNULL(i.date_end,v_date_ini) BETWEEN p.date_start AND p.date_end
+ AND warehouse_id IN (0, v_warehouse)
+ ORDER BY item_id, warehouse_id DESC, date_end DESC
+ ) t GROUP BY item_id;
+
+ 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 * FROM item_range;
+
+ DROP TEMPORARY TABLE IF EXISTS item_range_copy2;
+ CREATE TEMPORARY TABLE item_range_copy2 LIKE item_range;
+ INSERT INTO item_range_copy2
+ SELECT * FROM item_range;
+
+ DROP TEMPORARY TABLE IF EXISTS item_range_copy3;
+ CREATE TEMPORARY TABLE item_range_copy3 LIKE item_range;
+ INSERT INTO item_range_copy3
+ SELECT * FROM item_range;
+
+ DROP TEMPORARY TABLE IF EXISTS item_range_copy4;
+ CREATE TEMPORARY TABLE item_range_copy4 LIKE item_range;
+ INSERT INTO item_range_copy4
+ SELECT * FROM item_range;
+
+ -- Calcula el ATP
+
+ DELETE FROM available WHERE calc_id = v_calc;
+
+ INSERT INTO available (calc_id, item_id, available)
+ SELECT v_calc, t.item_id, SUM(stock) amount 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 = v_warehouse
+ 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 = v_warehouse
+ 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 = v_warehouse
+ 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 = v_warehouse
+ 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 amount != 0;
+
+ DROP TEMPORARY TABLE
+ vn2008.tmp_item
+ ,item_range
+ ,item_range_copy1
+ ,item_range_copy2
+ ,item_range_copy3
+ ,item_range_copy4;
+
+ CALL cache_calc_end (v_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 `barcodes_articles_update` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `barcodes_articles_update`()
+BEGIN
+
+REPLACE cache.barcodes
+
+ SELECT
+ `Articles`.`Id_Article` AS `code`,
+ `Articles`.`Id_Article` AS `Id_Article`,
+ `Articles`.`Article` AS `Article`,
+ `Articles`.`Medida` AS `Medida`,
+ `Articles`.`Color` AS `Color`,
+ `Articles`.`Categoria` AS `Categoria`,
+ `p`.`name` AS `Producer`
+ FROM
+ vn2008.Articles
+ LEFT JOIN vn2008.`producer` `p` using(producer_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 */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `barcodes_barcodes_update` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `barcodes_barcodes_update`()
+BEGIN
+
+REPLACE cache.barcodes
+
+ SELECT
+ `barcodes`.`code` AS `code`,
+ `barcodes`.`Id_Article` AS `Id_Article`,
+ `Articles`.`Article` AS `Article`,
+ `Articles`.`Medida` AS `Medida`,
+ `Articles`.`Color` AS `Color`,
+ `Articles`.`Categoria` AS `Categoria`,
+ `p`.`name` AS `Producer`
+ FROM
+ vn2008.`barcodes`
+ JOIN
+ vn2008.Articles using(Id_Article)
+ LEFT JOIN vn2008.`producer` `p` using(producer_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 */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `barcodes_compres_update` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `barcodes_compres_update`()
+BEGIN
+
+REPLACE cache.barcodes
+
+ SELECT
+ Compres.`Id_Compra` AS `code`,
+ Compres.`Id_Article` AS `Id_Article`,
+ `Articles`.`Article` AS `Article`,
+ `Articles`.`Medida` AS `Medida`,
+ `Articles`.`Color` AS `Color`,
+ `Articles`.`Categoria` AS `Categoria`,
+ producer.`name` AS `Producer`
+
+
+ FROM
+ vn2008.Compres
+ JOIN vn2008.Articles using(Id_Article)
+ LEFT JOIN vn2008.producer using(producer_id)
+ JOIN vn2008.Entradas using(Id_Entrada)
+ JOIN vn2008.travel on travel.id = travel_id
+ WHERE
+ landing >= TIMESTAMPADD(WEEK, -2, 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 */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `barcodes_expeditions_update` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `barcodes_expeditions_update`(IN idExpedition BIGINT)
+BEGIN
+
+REPLACE cache.barcodes
+
+ SELECT
+ `e`.`expeditions_id` AS `code`,
+ `Tickets`.`Id_Ruta` AS `Id_Article`,
+ `Tickets`.`Alias` AS `Article`,
+ `Tickets`.`Bultos` AS `Medida`,
+ `Tickets`.`Id_Ruta` AS `Color`,
+ `w`.`name` AS `Categoria`,
+ `a`.`Agencia` AS `Producer`
+ FROM
+ vn2008.expeditions `e`
+ JOIN vn2008.Tickets ON `Tickets`.`Id_Ticket` = `e`.`ticket_id`
+ JOIN vn2008.warehouse `w` ON `w`.`id` = `Tickets`.`warehouse_id`
+ JOIN vn2008.Rutas `r` ON `r`.`Id_Ruta` = `Tickets`.`Id_Ruta`
+ JOIN vn2008.Agencias `a` ON `a`.`Id_Agencia` = `r`.`Id_Agencia`
+ WHERE
+ idExpedition IN (e.expeditions_id,0)
+ AND
+ `Tickets`.`Fecha` >= (CURDATE() + INTERVAL -(2) DAY)
+
+
+ ;
+
+
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `barcodes_update` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `barcodes_update`()
+BEGIN
+
+ declare allExpeditions int default 0;
+
+ call barcodes_articles_update;
+
+ call barcodes_barcodes_update;
+
+ call barcodes_compres_update;
+
+ call barcodes_expeditions_update(allExpeditions);
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `cacheCalcClean` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `cacheCalcClean`()
+BEGIN
+ DECLARE vCleanTime DATETIME DEFAULT TIMESTAMPADD(MINUTE, -5, NOW());
+
+ DELETE FROM cache_calc WHERE expires < vCleanTime;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `cache_calc_end` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `cache_calc_end`(v_calc INT)
+BEGIN
+ DECLARE v_cache_name VARCHAR(255);
+ DECLARE v_params VARCHAR(255);
+
+ -- Libera el bloqueo y actualiza la fecha de ultimo refresco.
+
+ UPDATE cache_calc cc JOIN cache c ON c.id = cc.cache_id
+ SET
+ cc.last_refresh = NOW(),
+ cc.expires = ADDTIME(NOW(), c.lifetime),
+ cc.connection_id = NULL
+ WHERE cc.id = v_calc;
+
+ SELECT c.name, ca.params INTO v_cache_name, v_params
+ FROM cache c
+ JOIN cache_calc ca ON c.id = ca.cache_id
+ WHERE ca.id = v_calc;
+
+ DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, '')));
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `cache_calc_start` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `cache_calc_start`(OUT v_calc INT, INOUT v_refresh BOOL, v_cache_name VARCHAR(50), v_params VARCHAR(100))
+proc: BEGIN
+ DECLARE v_valid BOOL;
+ DECLARE v_lock_id VARCHAR(100);
+ DECLARE v_cache_id INT;
+ DECLARE v_expires DATETIME;
+ DECLARE v_clean_time DATETIME;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ DO RELEASE_LOCK(v_lock_id);
+ RESIGNAL;
+ END;
+
+ SET v_params = IFNULL(v_params, '');
+
+ -- Si el servidor se ha reiniciado invalida todos los calculos.
+
+ SELECT COUNT(*) > 0 INTO v_valid FROM cache_valid;
+
+ IF !v_valid
+ THEN
+ DELETE FROM cache_calc;
+ INSERT INTO cache_valid (valid) VALUES (TRUE);
+ END IF;
+
+ -- Obtiene un bloqueo exclusivo para que no haya problemas de concurrencia.
+
+ SET v_lock_id = CONCAT_WS('/', v_cache_name, v_params);
+
+ IF !GET_LOCK(v_lock_id, 30)
+ THEN
+ SET v_calc = NULL;
+ SET v_refresh = FALSE;
+ LEAVE proc;
+ END IF;
+
+ -- Comprueba si el calculo solicitado existe y esta actualizado.
+
+ SELECT c.id, ca.id, ca.expires
+ INTO v_cache_id, v_calc, v_expires
+ FROM cache c
+ LEFT JOIN cache_calc ca
+ ON ca.cache_id = c.id AND ca.params = v_params COLLATE 'utf8_general_ci'
+ WHERE c.name = v_cache_name COLLATE 'utf8_general_ci';
+
+ -- Si existe una calculo valido libera el bloqueo y devuelve su identificador.
+
+ IF !v_refresh AND NOW() < v_expires
+ THEN
+ DO RELEASE_LOCK(v_lock_id);
+ SET v_refresh = FALSE;
+ LEAVE proc;
+ END IF;
+
+ -- Si el calculo no existe le crea una entrada en la tabla de calculos.
+
+ IF v_calc IS NULL
+ THEN
+ INSERT INTO cache_calc SET
+ cache_id = v_cache_id,
+ cacheName = v_cache_name,
+ params = v_params,
+ last_refresh = NULL,
+ expires = NULL,
+ connection_id = CONNECTION_ID();
+
+ SET v_calc = LAST_INSERT_ID();
+ ELSE
+ UPDATE cache_calc
+ SET
+ last_refresh = NULL,
+ expires = NULL,
+ connection_id = CONNECTION_ID()
+ WHERE id = v_calc;
+ END IF;
+
+ -- Si se debe recalcular mantiene el bloqueo y devuelve su identificador.
+
+ SET v_refresh = 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 `cache_calc_unlock` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `cache_calc_unlock`(v_calc INT)
+BEGIN
+ DECLARE v_cache_name VARCHAR(50);
+ DECLARE v_params VARCHAR(100);
+
+ SELECT c.name, ca.params INTO v_cache_name, v_params
+ FROM cache c
+ JOIN cache_calc ca ON c.id = ca.cache_id
+ WHERE ca.id = v_calc;
+
+ DELETE FROM cache_calc WHERE id = v_calc;
+
+ DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, '')));
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!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`()
+BEGIN
+
+ DECLARE vDateShort DATETIME;
+
+ SET vDateShort = TIMESTAMPADD(MONTH, -1, CURDATE());
+
+ INSERT INTO cache.dailyTaskLog(state) VALUES('clean START');
+
+ DELETE FROM cache.departure_limit WHERE Fecha < vDateShort;
+
+ INSERT INTO cache.dailyTaskLog(state) 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 `departure_timing` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `departure_timing`()
+BEGIN
+
+DECLARE done BOOL DEFAULT FALSE;
+DECLARE rsDeparture INT;
+DECLARE rsHoras DECIMAL(5,2);
+DECLARE rsInicio DECIMAL(5,2);
+DECLARE resto DECIMAL(5,2);
+DECLARE horasProd DECIMAL(5,2);
+DECLARE inicioProd DECIMAL(5,2) DEFAULT 24.00;
+DECLARE myTime DECIMAL(5,2);
+DECLARE departureLimit INT;
+DECLARE myWarehouse INT;
+DECLARE myMinSpeed DECIMAL(10,2);
+DECLARE vLoadingDelay DECIMAL(5) DEFAULT 2;
+
+
+DECLARE rs CURSOR FOR
+ SELECT Departure
+ , Sum(pb.m3)/(GREATEST(v.m3,IFNULL(minSpeed,0))/1.3) AS Horas
+ , curDate()+(Departure + vLoadingDelay -(Sum(pb.m3)/(GREATEST(v.m3,IFNULL(minSpeed,0))/1.3))/24) AS InicioPreparacion
+ FROM tmp.production_buffer pb
+ JOIN vn2008.v_encajado_ultima_hora v ON v.warehouse_id = pb.warehouse_id
+ LEFT JOIN cache.departure_limit dp ON dp.warehouse_id = pb.warehouse_id AND dp.fecha = CURDATE()
+ WHERE pb.Fecha = CURDATE()
+ AND alert_level < 2
+ AND IFNULL(Departure,0) > 0
+ GROUP BY Departure
+ ORDER BY Departure DESC;
+
+DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+
+SET myTime = HOUR(now()) + MINUTE(now()) / 60;
+
+SELECT warehouse_id INTO myWarehouse
+FROM tmp.production_buffer
+LIMIT 1;
+
+OPEN rs;
+
+FETCH rs INTO rsDeparture, rsHoras , rsInicio;
+
+-- SELECT rsDeparture, rsHoras , rsInicio, myWarehouse;
+
+WHILE NOT done DO
+
+ SET resto = IF(inicioProd < rsDeparture, rsDeparture - inicioProd,0);
+
+ SET inicioProd = rsDeparture - rsHoras;
+
+ IF inicioProd - resto < myTime THEN
+
+ SET done = TRUE;
+
+ ELSE
+
+ SET departureLimit = rsDeparture;
+
+ FETCH rs INTO rsDeparture, rsHoras , rsInicio;
+
+ -- SELECT rsDeparture, rsHoras , rsInicio;
+
+ END IF;
+
+END WHILE;
+
+SET departureLimit = IFNULL(departureLimit,24);
+SET departureLimit = IF(departureLimit = 0, 24, departureLimit);
+
+ SELECT minSpeed INTO myMinSpeed
+ FROM cache.departure_limit
+ WHERE warehouse_id = myWarehouse
+ AND fecha = CURDATE();
+
+ REPLACE cache.departure_limit(warehouse_id, fecha, hora, minSpeed)
+ VALUES (myWarehouse, CURDATE(), IFNULL(departureLimit,24), IFNULL(myMinSpeed,0));
+
+
+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 `departure_timing_beta` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `departure_timing_beta`()
+BEGIN
+
+DECLARE done BOOL DEFAULT FALSE;
+DECLARE rsDeparture INT;
+DECLARE rsHoras DECIMAL(5,2);
+DECLARE rsInicio DECIMAL(5,2);
+DECLARE resto DECIMAL(5,2);
+DECLARE horasProd DECIMAL(5,2);
+DECLARE inicioProd DECIMAL(5,2) DEFAULT 24.00;
+DECLARE myTime DECIMAL(5,2);
+DECLARE departureLimit INT;
+DECLARE myWarehouse INT;
+
+DECLARE rs CURSOR FOR
+ SELECT Departure
+ , Sum(pb.m3)/GREATEST(v.m3,IFNULL(minSpeed,0)) AS Horas
+ , curDate()+(Departure-(Sum(pb.m3)/GREATEST(v.m3,IFNULL(minSpeed,0)))/24) AS InicioPreparacion
+ FROM tmp.production_buffer pb
+ JOIN vn2008.v_encajado_ultima_hora v ON v.warehouse_id = pb.warehouse_id
+ LEFT JOIN cache.departure_limit dp ON dp.warehouse_id = pb.warehouse_id AND dp.fecha = CURDATE()
+ WHERE pb.Fecha = CURDATE()
+ AND alert_level < 2
+ AND IFNULL(Departure,0) > 0
+ GROUP BY Departure
+ ORDER BY Departure DESC;
+
+DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+
+
+
+SET myTime = HOUR(now()) + MINUTE(now()) / 60;
+
+SELECT warehouse_id INTO myWarehouse
+FROM tmp.production_buffer
+LIMIT 1;
+
+OPEN rs;
+
+FETCH rs INTO rsDeparture, rsHoras , rsInicio;
+
+SELECT rsDeparture, rsHoras , rsInicio, myWarehouse, done;
+
+WHILE NOT done DO
+
+ SET resto = IF(inicioProd < rsDeparture, rsDeparture - inicioProd,0);
+
+ SET inicioProd = rsDeparture - rsHoras;
+
+ SELECT rsDeparture, rsHoras , rsInicio, resto,inicioProd;
+
+ IF inicioProd - resto < myTime THEN
+
+ SET done = TRUE;
+
+ ELSE
+
+ SET departureLimit = rsDeparture;
+
+ FETCH rs INTO rsDeparture, rsHoras , rsInicio;
+
+ END IF;
+
+END WHILE;
+
+SELECT rsDeparture, rsHoras , rsInicio, resto,inicioProd;
+
+
+SET departureLimit = IFNULL(departureLimit,24);
+
+IF departureLimit > 0 THEN
+
+ REPLACE cache.departure_limit(warehouse_id, fecha, hora, minSpeed)
+ VALUES (myWarehouse, CURDATE(), departureLimit, myMinSpeed);
+
+END IF;
+
+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 */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `departure_timing_kk` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `departure_timing_kk`()
+BEGIN
+
+DECLARE done BOOL DEFAULT FALSE;
+DECLARE rsDeparture INT;
+DECLARE rsHoras DECIMAL(5,2);
+DECLARE rsInicio DECIMAL(5,2);
+DECLARE resto DECIMAL(5,2);
+DECLARE horasProd DECIMAL(5,2);
+DECLARE inicioProd DECIMAL(5,2) DEFAULT 24.00;
+DECLARE myTime DECIMAL(5,2);
+DECLARE departureLimit INT;
+DECLARE myWarehouse INT;
+DECLARE myMinSpeed DECIMAL(10,2);
+
+
+DECLARE rs CURSOR FOR
+ SELECT Departure
+ , Sum(pb.m3)/(GREATEST(v.m3, 100)/1.3) AS Horas
+ , curDate()+(Departure-Sum(pb.m3)/(GREATEST(v.m3, 100)/1.3))/24 AS InicioPreparacion
+ FROM tmp.production_buffer pb
+ JOIN vn2008.v_encajado_ultima_hora v ON v.warehouse_id = pb.warehouse_id
+ WHERE Fecha = CURDATE()
+ AND alert_level < 2
+ AND IFNULL(Departure,0) > 0
+ GROUP BY Departure
+ ORDER BY Departure DESC;
+
+DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+
+SELECT IFNULL(minSpeed,0) INTO myMinSpeed
+FROM cache.departure_limit
+WHERE warehouse_id = myWarehouse
+AND fecha = CURDATE();
+
+SET myTime = HOUR(now()) + MINUTE(now()) / 60;
+
+SELECT warehouse_id INTO myWarehouse
+FROM tmp.production_buffer
+LIMIT 1;
+
+OPEN rs;
+
+FETCH rs INTO rsDeparture, rsHoras , rsInicio;
+
+WHILE NOT done DO
+
+ SET resto = IF(inicioProd < rsDeparture, rsDeparture - inicioProd,0);
+
+ SET inicioProd = rsDeparture - rsHoras;
+
+ IF inicioProd - resto < myTime THEN
+
+ SET done = TRUE;
+
+ ELSE
+
+ SET departureLimit = rsDeparture;
+
+ FETCH rs INTO rsDeparture, rsHoras , rsInicio;
+
+ END IF;
+
+END WHILE;
+
+IF departureLimit > 0 THEN
+
+ REPLACE cache.departure_limit(warehouse_id, fecha, hora, minSpeed)
+ VALUES (myWarehouse, CURDATE(), departureLimit, myMinSpeed);
+
+END IF;
+
+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 */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `equaliza` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `equaliza`(wh_id INT)
+BEGIN
+ -- DEPRECATED usar equalizator_refesh
+
+
+
+ CALL equalizator_refresh (FALSE, wh_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 */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `equalizator_refresh` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `equalizator_refresh`(v_refresh BOOL, wh_id INT)
+proc: BEGIN
+ DECLARE datEQ DATETIME;
+ DECLARE timDIF TIME;
+ DECLARE v_calc INT;
+ /* JGF 2017-03-20 cuelga el sistema
+ CALL cache_calc_start (v_calc, v_refresh, 'equalizator', wh_id);
+
+ IF !v_refresh
+ THEN
+ LEAVE proc;
+ END IF;
+
+ REPLACE equalizator (warehouse_id, Vista, Encajado, Impreso, Pedido)
+ SELECT
+ t.warehouse_id,
+ Vista,
+ sum(IF(t.Factura IS NOT NULL
+ OR t.Etiquetasemitidas
+ OR IFNULL(ticket_id,0), Cantidad * r.cm3, 0)) as encajado,
+ sum(IF(PedidoImpreso, Cantidad * r.cm3,0)) as impreso,
+ sum(Cantidad * r.cm3 ) as Pedido
+ FROM
+ vn2008.Movimientos m
+ JOIN
+ vn2008.Tickets t USING (Id_Ticket)
+ JOIN
+ bi.rotacion r on r.warehouse_id = t.warehouse_id and r.Id_Article = m.Id_Article
+ JOIN
+ vn2008.Agencias a ON t.Id_Agencia = a.Id_Agencia
+ JOIN
+ vn2008.Clientes C USING (Id_Cliente)
+ LEFT JOIN
+ (SELECT distinct
+ ticket_id
+ FROM
+ vn2008.expeditions e JOIN vn2008.Tickets t
+ ON t.Id_Ticket = e.ticket_id
+ WHERE Fecha >= curDate()
+ ) exp ON ticket_id = Id_Ticket
+ WHERE
+ invoice And Fecha >= curDate()
+ AND wh_id in (0,t.warehouse_id)
+ AND fecha < (TIMESTAMPADD(DAY, 1, CURDATE()))
+ GROUP BY t.warehouse_id, Vista;
+
+ -- Reducimos las cantidades para que el grafico tenga sentido
+
+ UPDATE equalizator SET
+ pedido = (pedido - (impreso - encajado) - encajado) / 1000000,
+ impreso = (impreso - encajado) / 1000000,
+ encajado = encajado / 1000000
+ WHERE wh_id in (0,warehouse_id);
+
+ CALL cache_calc_end (v_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 */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `item_range_refresh` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `item_range_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT, v_date DATE)
+proc: BEGIN
+ DECLARE v_params CHAR(100);
+ DECLARE v_date_inv DATE;
+
+ IF v_date < CURDATE()
+ THEN
+ LEAVE proc;
+ END IF;
+
+ SET v_params = CONCAT_WS('/', v_warehouse, v_date);
+ CALL cache_calc_start (v_calc, v_refresh, 'item_range', v_params);
+
+ IF !v_refresh
+ THEN
+ LEAVE proc;
+ END IF;
+
+ -- Limpia las caches antiguas
+
+ DELETE FROM item_range WHERE calc_id NOT IN (
+ SELECT cc.id
+ FROM `cache` c
+ JOIN cache_calc cc ON c.id = cc.cache_id
+ WHERE c.`name` = 'item_range');
+
+ -- Calculos previos
+
+ CALL last_buy_refresh (FALSE);
+
+ SET v_date_inv = vn2008.date_inv();
+
+ -- Calcula el ultimo dia de vida para cada producto
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.item_range;
+ CREATE TEMPORARY TABLE tmp.item_range
+ (INDEX (item_id))
+ ENGINE = MEMORY
+ SELECT c.item_id, IF(t.life IS NULL, NULL, TIMESTAMPADD(DAY, t.life + 1, GREATEST(c.landing, b.landing))) AS date_end
+ FROM last_buy b
+ JOIN (
+ SELECT c.Id_Article item_id, MAX(landing) landing
+ 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
+ AND t.warehouse_id = v_warehouse
+ AND NOT e.Inventario
+ AND NOT e.Redada
+ GROUP BY item_id
+ ) c ON c.item_id = b.item_id
+ JOIN vn2008.Articles a ON a.Id_Article = b.item_id
+ JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id
+ WHERE b.warehouse_id = v_warehouse
+ HAVING date_end >= v_date OR date_end IS NULL;
+
+ -- Tabla con el ultimo dia de precios fijados para cada producto
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.fix_range;
+ CREATE TEMPORARY TABLE tmp.fix_range
+ ENGINE = MEMORY
+ SELECT item_id, date_end FROM (
+ SELECT p.item_id, p.date_end
+ FROM vn2008.price_fixed p
+ LEFT JOIN tmp.item_range i USING(item_id)
+ WHERE IFNULL(i.date_end, v_date) BETWEEN p.date_start AND p.date_end
+ AND warehouse_id IN (0, v_warehouse)
+ ORDER BY item_id, warehouse_id DESC, date_end DESC
+ ) t GROUP BY item_id;
+
+ -- Calcula los rangos
+
+ DELETE FROM item_range WHERE calc_id = v_calc;
+
+ INSERT INTO item_range (calc_id, item_id, date_end)
+ SELECT v_calc, item_id, date_end
+ FROM (
+ SELECT * FROM tmp.fix_range
+ UNION ALL
+ SELECT * FROM tmp.item_range
+ ) t
+ GROUP BY item_id;
+
+ -- Limpieza
+
+ DROP TEMPORARY TABLE tmp.item_range;
+ DROP TEMPORARY TABLE tmp.fix_range;
+
+ CALL cache_calc_end (v_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 */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `last_buy_refresh` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `last_buy_refresh`(v_refresh BOOL)
+proc: BEGIN
+/**
+ * Crea o actualiza la cache con la última compra y fecha de cada
+ * artículo hasta ayer. Para obtener la última compra hasta una fecha
+ * determinada utilizar el procedimiento vn2008.item_last_buy_().
+ *
+ * @param v_refresh %TRUE para forzar el recálculo de la cache
+ **/
+ DECLARE v_calc INT;
+ DECLARE v_date_ini DATE;
+ DECLARE v_date_end DATE;
+ DECLARE v_last_refresh DATE;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ CALL cache_calc_unlock (v_calc);
+ RESIGNAL;
+ END;
+
+ CALL cache_calc_start (v_calc, v_refresh, 'last_buy', NULL);
+
+ IF !v_refresh
+ THEN
+ LEAVE proc;
+ END IF;
+
+ -- TODO: ¿Se puede usar la fecha del ultimo inventario?
+ SET v_date_ini = vn2008.date_inv();-- TIMESTAMPADD(DAY, -90, CURDATE());
+ SET v_date_end = CURDATE(); -- TIMESTAMPADD(DAY, -1, CURDATE());
+
+ CALL vn2008.item_last_buy_from_interval (NULL, v_date_ini, v_date_end);
+
+ DELETE FROM last_buy;
+
+ INSERT INTO last_buy (item_id, warehouse_id, buy_id, landing)
+ SELECT item_id, warehouse_id, buy_id, landing
+ FROM tmp.item_last_buy_from_interval;
+
+ DROP TEMPORARY TABLE tmp.item_last_buy_from_interval;
+
+ CALL cache_calc_end (v_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 */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `prod_graphic_refresh` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `prod_graphic_refresh`(v_refresh BOOL, wh_id INT)
+proc: BEGIN
+ DECLARE datEQ DATETIME;
+ DECLARE timDIF TIME;
+ DECLARE v_calc INT;
+
+ CALL cache_calc_start (v_calc, v_refresh, 'prod_graphic', wh_id);
+
+ IF !v_refresh
+ THEN
+ LEAVE proc;
+ END IF;
+
+ CALL vn2008.production_control_source(wh_id, 0);
+
+ DELETE FROM prod_graphic_source;
+
+ INSERT INTO prod_graphic_source (warehouse_id, alert_level, m3, hora, `order`, Agencia)
+ SELECT
+ wh_id,
+ pb.alert_level,
+ m3,
+ pb.Hora,
+ pb.state_order,
+ pb.Agencia
+ FROM tmp.production_buffer pb
+ WHERE Fecha = CURDATE()
+ ;
+
+
+ CALL cache_calc_end (v_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 `sales_refresh` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `sales_refresh`()
+proc:BEGIN
+
+ DECLARE v_calc INT;
+ DECLARE v_refresh BOOL DEFAULT TRUE;
+ DECLARE datMONTH INT;
+ DECLARE datYEAR INT;
+
+ CALL cache_calc_start (v_calc, v_refresh, 'sales', NULL);
+
+ IF !v_refresh
+ THEN
+ LEAVE proc;
+ END IF;
+
+
+ SELECT MONTH(CURDATE()) INTO datMONTH;
+ SELECT YEAR(CURDATE()) INTO datYEAR;
+
+ -- preparamos una tabla con los meses y años que interesan
+ DROP TEMPORARY TABLE IF EXISTS tmp.periods;
+ CREATE TEMPORARY TABLE tmp.periods
+ select distinct month, year(date) as year
+ from vn2008.time
+ where date <= CURDATE()
+ order by year desc, month desc
+ limit 3;
+
+ -- borramos los datos para evitar flecos
+ DELETE s.*
+ FROM bi.sales s
+ join tmp.periods using(year,month);
+
+ -- insertamos las ventas de cada comercial
+ REPLACE bi.sales(Id_Trabajador, year, month, weight, boss_id)
+ select v.Id_Trabajador, year, month, round(sum(total)) as weight, IFNULL(j.boss_id,20)
+ from bi.v_ticket_total v
+ join tmp.periods using(year,month)
+ left join (SELECT jerarquia.boss_id, jerarquia.worker_id
+ FROM vn2008.jerarquia
+ ) j on j.worker_id = v.Id_Trabajador
+ group by v.Id_Trabajador, year, month;
+
+
+
+ -- caso especial: Claudi ajuda a Josep a llegar a los 1200 euros de comision
+ /*
+ update bi.sales
+ set boss_aid = 34285 - weight
+ where Id_Trabajador = 378
+ and year >= 2015
+ and month > datmonth -2;
+
+ update bi.sales s
+ join
+ (select year, month, boss_aid
+ from bi.sales
+ where Id_Trabajador = 378
+ and year >= 2015
+ and month > datmonth -2) sub using(year,month)
+ set s.boss_aid = s.boss_aid - sub.boss_aid
+ where Id_Trabajador = 208
+ and year >= 2015
+ and month > datmonth -2;
+ */
+
+
+
+
+-- ahora, las comisiones
+
+update bi.sales s
+set comision = weight * 0.029;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.periods;
+
+ CALL cache_calc_end (v_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 */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `stock_refresh` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `stock_refresh`(v_refresh BOOL)
+proc: BEGIN
+/**
+ * Crea o actualiza la cache con el disponible hasta el día de
+ * ayer. Esta cache es usada como base para otros procedimientos
+ * como el cáculo del visible o del ATP.
+ *
+ * @param v_refresh %TRUE para forzar el recálculo de la cache
+ **/
+ DECLARE v_calc INT;
+ DECLARE v_date_inv DATE;
+ DECLARE v_curdate DATE;
+ DECLARE v_last_refresh DATETIME;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ CALL cache_calc_unlock (v_calc);
+ RESIGNAL;
+ END;
+
+ CALL cache_calc_start (v_calc, v_refresh, 'stock', NULL);
+
+ IF !v_refresh
+ THEN
+ LEAVE proc;
+ END IF;
+
+ SET v_date_inv = (SELECT FechaInventario FROM vn2008.tblContadores LIMIT 1);
+ SET v_curdate = CURDATE();
+
+ DELETE FROM stock;
+
+ INSERT INTO stock (item_id, warehouse_id, amount)
+ SELECT item_id, warehouse_id, SUM(amount) amount FROM
+ (
+ SELECT item_id, warehouse_id, amount FROM vn2008.item_out
+ WHERE dat >= v_date_inv AND dat < v_curdate
+ UNION ALL
+ SELECT item_id, warehouse_id, amount FROM vn2008.item_entry_in
+ WHERE dat >= v_date_inv AND dat < v_curdate
+ UNION ALL
+ SELECT item_id ,warehouse_id, amount FROM vn2008.item_entry_out
+ WHERE dat >= v_date_inv AND dat < v_curdate
+ ) t
+ GROUP BY item_id, warehouse_id HAVING amount != 0;
+
+ CALL cache_calc_end (v_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 `visible_refresh` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `visible_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT)
+proc: BEGIN
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ CALL cache_calc_unlock (v_calc);
+ RESIGNAL;
+ END;
+
+ CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse);
+
+ IF !v_refresh
+ THEN
+ LEAVE proc;
+ END IF;
+
+ -- Limpia las caches antiguas
+
+ IF TRUE -- GET_LOCK('visible/clean', 1)
+ THEN
+ DELETE FROM visible WHERE calc_id NOT IN (
+ SELECT cc.id
+ FROM `cache` c
+ JOIN cache_calc cc ON c.id = cc.cache_id
+ WHERE c.`name` = 'visible');
+
+ -- DO RELEASE_LOCK('visible/clean');
+ END IF;
+
+ -- Calculamos el stock hasta ayer
+
+ CALL `cache`.stock_refresh(false);
+
+ DROP TEMPORARY TABLE IF EXISTS vn2008.tmp_item;
+ CREATE TEMPORARY TABLE vn2008.tmp_item
+ (PRIMARY KEY (item_id))
+ ENGINE = MEMORY
+ SELECT item_id, amount stock, amount visible FROM `cache`.stock
+ WHERE warehouse_id = v_warehouse;
+
+ -- Calculamos los movimientos confirmados de hoy
+
+ CALL vn2008.item_stock_visible(v_warehouse, NULL);
+
+ DELETE FROM visible WHERE calc_id = v_calc;
+
+ INSERT INTO visible (calc_id, item_id,visible)
+ SELECT v_calc, item_id, visible FROM vn2008.tmp_item;
+
+ CALL cache_calc_end (v_calc);
+
+ DROP TEMPORARY TABLE vn2008.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 */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `weekly_sales_refresh` */;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `weekly_sales_refresh`(v_refresh BOOL)
+BEGIN
+
+ DECLARE v_week_ini INT;
+
+ DECLARE v_week_end INT;
+
+ DECLARE v_date_ini DATE;
+
+ DECLARE v_date_end DATE;
+
+ DECLARE v_last_refresh DATE;
+
+
+
+ IF GET_LOCK('weekly_sales', 300)
+
+ THEN
+
+ SELECT last_refresh INTO v_last_refresh FROM weekly_sales_info;
+
+
+
+ IF v_last_refresh IS NULL THEN
+
+ SET v_refresh = TRUE;
+
+ END IF;
+
+
+
+ IF v_refresh || v_last_refresh < CURDATE()
+
+ THEN
+
+ SET v_date_ini = TIMESTAMPADD(DAY, -(366 * 1.5), CURDATE());
+
+ SET v_date_end = TIMESTAMPADD(DAY, -1, CURDATE());
+
+
+
+ IF v_refresh
+
+ THEN
+
+ TRUNCATE TABLE weekly_sales;
+
+ ELSE
+
+ SET v_week_ini = vn2008.to_weeks (v_date_ini);
+
+ SET v_date_ini = TIMESTAMPADD(DAY, -WEEKDAY(v_last_refresh) - 7, v_last_refresh);
+
+ SET v_week_end = vn2008.to_weeks (v_date_ini);
+
+
+
+ DELETE FROM weekly_sales
+
+ WHERE week < v_week_ini OR week >= v_week_end;
+
+ END IF;
+
+
+
+ CALL vn2008.weekly_sales_new (0, v_date_ini, v_date_end);
+
+
+
+ INSERT INTO weekly_sales (item_id, week, warehouse_id, amount, price)
+
+ SELECT item_id, week, warehouse_id, amount, price FROM vn2008.weekly_sales;
+
+
+
+ DROP TEMPORARY TABLE vn2008.weekly_sales;
+
+
+
+ TRUNCATE TABLE weekly_sales_info;
+
+ INSERT INTO weekly_sales_info (last_refresh) VALUES (CURDATE());
+
+ END IF;
+
+
+
+ DO RELEASE_LOCK('weekly_sales');
+
+ 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 */ ;
+ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+
+--
+-- Current Database: `vncontrol`
+--
+
+CREATE DATABASE /*!32312 IF NOT EXISTS*/ `vncontrol` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
+
+USE `vncontrol`;
+
+--
+-- Table structure for table `accion`
+--
+
+DROP TABLE IF EXISTS `accion`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `accion` (
+ `accion_id` int(11) NOT NULL AUTO_INCREMENT,
+ `accion` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`accion_id`)
+) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `clientes_match`
+--
+
+DROP TABLE IF EXISTS `clientes_match`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `clientes_match` (
+ `Id_cliente` int(11) NOT NULL,
+ `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `dailyTaskLog`
+--
+
+DROP TABLE IF EXISTS `dailyTaskLog`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `dailyTaskLog` (
+ `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
+ `created` 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 `fallo`
+--
+
+DROP TABLE IF EXISTS `fallo`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `fallo` (
+ `queja_id` int(10) unsigned NOT NULL,
+ `accion_id` int(11) NOT NULL,
+ PRIMARY KEY (`queja_id`,`accion_id`),
+ KEY `accion` (`accion_id`,`queja_id`),
+ KEY `fallo` (`queja_id`),
+ CONSTRAINT `accion` FOREIGN KEY (`accion_id`) REFERENCES `accion` (`accion_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 `inter`
+--
+
+DROP TABLE IF EXISTS `inter`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `inter` (
+ `inter_id` int(11) NOT NULL AUTO_INCREMENT,
+ `state_id` tinyint(3) unsigned NOT NULL,
+ `fallo_id` int(10) unsigned NOT NULL DEFAULT '21',
+ `nota` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
+ `Id_Ticket` int(11) DEFAULT NULL,
+ `Id_Trabajador` int(11) DEFAULT NULL,
+ `Id_Supervisor` int(11) DEFAULT NULL,
+ PRIMARY KEY (`inter_id`),
+ KEY `currante` (`Id_Trabajador`),
+ KEY `responsable` (`Id_Supervisor`),
+ KEY `ticket` (`Id_Ticket`),
+ KEY `inter_state` (`state_id`),
+ CONSTRAINT `currante` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE,
+ CONSTRAINT `inter_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `inter_state` FOREIGN KEY (`state_id`) REFERENCES `vn2008`.`state` (`id`) ON UPDATE CASCADE,
+ CONSTRAINT `responsable` FOREIGN KEY (`Id_Supervisor`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=8428388 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 `interBeforeInsert`
+BEFORE INSERT ON `inter` FOR EACH ROW
+BEGIN
+
+ DECLARE contados INT;
+ DECLARE vSupervisor INT;
+
+ SELECT Id_Trabajador INTO vSupervisor FROM vn2008.Trabajadores WHERE user_id = account.userGetId();
+
+ SET NEW.Id_Supervisor = IFNULL(vSupervisor,20);
+
+ IF NEW.state_id = 5
+ THEN
+ SELECT count(Id_Ticket) INTO contados
+ FROM vncontrol.inter
+ WHERE state_id = 5
+ AND Id_Ticket = NEW.Id_Ticket
+ AND IFNULL(Id_Supervisor,-1) <> vSupervisor
+ AND TIMESTAMPADD(SECOND, 60, odbc_date) >= NOW();
+
+ IF contados <> 0 THEN
+ CALL util.throw ('FALLO_AL_INSERTAR');
+ 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 `vncontrol`.`interAfterInsert`
+AFTER INSERT ON `inter` FOR EACH ROW
+BEGIN
+ REPLACE vn2008.Tickets_state(Id_Ticket, inter_id,state_name)
+ SELECT NEW.Id_Ticket, NEW.inter_id, s.`name` FROM vn2008.state s WHERE s.id = NEW.state_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 `vncontrol`.`interAfterUpdate`
+AFTER UPDATE ON `inter` FOR EACH ROW
+BEGIN
+ DECLARE intIdTicket INT;
+ DECLARE intInterId INT;
+ DECLARE strName VARCHAR(15);
+
+ IF (NEW.state_id <> OLD.state_id) THEN
+ REPLACE INTO vn2008.Tickets_state(Id_Ticket, inter_id,state_name)
+ SELECT NEW.Id_Ticket, NEW.inter_id, s.`name`
+ FROM vn2008.state s WHERE s.id = NEW.state_id;
+ END IF;
+ IF (NEW.Id_Ticket <> OLD.Id_Ticket) THEN
+
+ SELECT i.Id_Ticket, i.inter_id, s.`name`
+ INTO intIdTicket, intInterId, strName
+ FROM vncontrol.inter i
+ JOIN vn2008.state s ON i.state_id = s.id
+ WHERE Id_Ticket = NEW.Id_Ticket
+ ORDER BY odbc_date DESC
+ LIMIT 1;
+ IF intIdTicket > 0 THEN
+ REPLACE INTO vn2008.Tickets_state(Id_Ticket, inter_id,state_name)
+ VALUES(intIdTicket, intInterId, strName);
+ 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 `vncontrol`.`interAfterDelete`
+AFTER DELETE ON `inter` FOR EACH ROW
+BEGIN
+ DECLARE intIdTicket INT;
+ DECLARE intInterId INT;
+ DECLARE strName VARCHAR(15);
+
+ DECLARE CONTINUE HANDLER FOR SQLSTATE '23000'
+ BEGIN
+ DELETE FROM vn2008.Tickets_state
+ WHERE Id_Ticket = OLD.Id_Ticket;
+ END;
+
+ IF OLD.odbc_date > TIMESTAMPADD(WEEK, -1, CURDATE()) THEN
+
+ SELECT i.Id_Ticket, i.inter_id, s.`name`
+ INTO intIdTicket, intInterId, strName
+ FROM vncontrol.inter i
+ JOIN vn2008.state s ON i.state_id = s.id
+ WHERE Id_Ticket = OLD.Id_Ticket
+ ORDER BY odbc_date DESC
+ LIMIT 1;
+
+ IF intIdTicket > 0 THEN
+ REPLACE INTO vn2008.Tickets_state(Id_Ticket, inter_id,state_name)
+ VALUES (intIdTicket, intInterId, strName);
+ 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 */ ;
+
+--
+-- Dumping events for database 'vncontrol'
+--
+
+--
+-- Dumping routines for database 'vncontrol'
+--
+/*!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`()
+BEGIN
+
+ DECLARE v_date2 DATETIME DEFAULT TIMESTAMPADD(MONTH, -2,CURDATE());
+
+ INSERT INTO vncontrol.dailyTaskLog(state) VALUES('clean START');
+
+ DELETE FROM vncontrol.inter WHERE odbc_date <= v_date2;
+
+ INSERT INTO vncontrol.dailyTaskLog(state) 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 `ResumenKK` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ResumenKK`()
+BEGIN
+
+select accion, CodigoTrabajador, semana, Pedidos, Lineas
+from accion
+join
+(
+ SELECT * FROM
+ (
+ select count(*) as Pedidos, semana, Id_Trabajador, accion_id
+ from
+ (select distinct *
+ from
+ (
+ select vn2008.semana(odbc_date) as semana
+ ,Id_Trabajador
+ ,accion_id
+ ,Id_Ticket
+ from vncontrol.inter
+ ) sub
+ ) sub2
+ group by semana, Id_Trabajador, accion_id
+ ) subpedidos
+
+ inner join
+ (
+
+ select semana, Id_Trabajador, accion_id, count(*) as Lineas
+ from vn2008.Movimientos
+ inner join
+ (
+ select distinct vn2008.semana(odbc_date) as semana, Id_Ticket, Id_Trabajador, accion_id from vncontrol.inter
+ ) vnc using(Id_Ticket)
+ group by semana, Id_Trabajador, accion_id
+
+ ) sublineas using(semana, Id_Trabajador, accion_id)
+
+) sub3 using(accion_id)
+
+join vn2008.Trabajadores using(Id_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 */ ;
+
+--
+-- Current Database: `edi`
+--
+
+CREATE DATABASE /*!32312 IF NOT EXISTS*/ `edi` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
+
+USE `edi`;
+
+--
+-- Table structure for table `batch`
+--
+
+DROP TABLE IF EXISTS `batch`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `batch` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `message_id` int(10) unsigned NOT NULL,
+ `type_id` smallint(5) unsigned NOT NULL,
+ `buy_edi_id` int(10) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `type_id` (`type_id`,`buy_edi_id`),
+ KEY `message_id` (`message_id`),
+ KEY `buy_edi_id` (`buy_edi_id`),
+ CONSTRAINT `batch_ibfk_1` FOREIGN KEY (`message_id`) REFERENCES `message` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `batch_ibfk_2` FOREIGN KEY (`buy_edi_id`) REFERENCES `vn2008`.`buy_edi` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=266998 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `batch_type`
+--
+
+DROP TABLE IF EXISTS `batch_type`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `batch_type` (
+ `id` mediumint(8) unsigned NOT NULL,
+ `description` varchar(50) COLLATE utf8_unicode_ci NOT 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 `bucket`
+--
+
+DROP TABLE IF EXISTS `bucket`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `bucket` (
+ `bucket_id` int(11) unsigned NOT NULL,
+ `bucket_type_id` mediumint(8) unsigned NOT NULL,
+ `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ `x_size` mediumint(8) unsigned NOT NULL,
+ `y_size` mediumint(8) unsigned NOT NULL,
+ `z_size` mediumint(8) unsigned NOT NULL,
+ `entry_date` date DEFAULT NULL,
+ `expiry_date` date DEFAULT NULL,
+ `change_date_time` datetime DEFAULT NULL,
+ PRIMARY KEY (`bucket_id`),
+ KEY `group_id` (`y_size`),
+ KEY `plant_id` (`x_size`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/VBN020101/CK090916.txt';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `bucket_type`
+--
+
+DROP TABLE IF EXISTS `bucket_type`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `bucket_type` (
+ `bucket_type_id` mediumint(8) unsigned NOT NULL,
+ `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ `entry_date` date DEFAULT NULL,
+ `expiry_date` date DEFAULT NULL,
+ `change_date_time` datetime DEFAULT NULL,
+ PRIMARY KEY (`bucket_type_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/VBN020101/FB090916.txt';
+/*!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` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
+ `log_mail` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Mail where the log information is sent',
+ `presale_id` mediumint(8) unsigned DEFAULT NULL,
+ `default_kop` int(10) unsigned DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `presale_id` (`presale_id`),
+ CONSTRAINT `config_ibfk_1` FOREIGN KEY (`presale_id`) REFERENCES `batch_type` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Configuration parameters';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `deliveryInformation`
+--
+
+DROP TABLE IF EXISTS `deliveryInformation`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `deliveryInformation` (
+ `ID` int(11) NOT NULL,
+ `DeliveryType` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Location` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `DeliveryPrice` decimal(10,2) DEFAULT NULL,
+ `ChargeAmount` decimal(10,2) DEFAULT NULL,
+ `BasisQuantitiy` int(11) DEFAULT NULL,
+ `MinimumQuantity` int(11) DEFAULT NULL,
+ `MaximumQuantity Integer` int(11) DEFAULT NULL,
+ `LatestDeliveryDateTime` datetime DEFAULT NULL,
+ `EarliestDespatchDateTime` datetime DEFAULT NULL,
+ `FirstOrderDateTime` datetime DEFAULT NULL,
+ `LatestOrderDateTime` datetime 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 `feature`
+--
+
+DROP TABLE IF EXISTS `feature`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `feature` (
+ `item_id` int(11) unsigned NOT NULL,
+ `feature_type_id` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ `feature_value` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ `entry_date` date NOT NULL,
+ `expiry_date` date NOT NULL,
+ `change_date_time` datetime NOT NULL,
+ PRIMARY KEY (`item_id`,`feature_type_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FF130916.txt';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `file_config`
+--
+
+DROP TABLE IF EXISTS `file_config`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `file_config` (
+ `file_name` varchar(2) COLLATE utf8_unicode_ci NOT NULL,
+ `to_table` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
+ `file` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
+ `updated` date DEFAULT NULL,
+ PRIMARY KEY (`file_name`),
+ UNIQUE KEY `to_table` (`to_table`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `ftp_config`
+--
+
+DROP TABLE IF EXISTS `ftp_config`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `ftp_config` (
+ `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
+ `host` varchar(255) CHARACTER SET utf8 NOT NULL,
+ `user` varchar(50) CHARACTER SET utf8 NOT NULL,
+ `password` varchar(50) CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Configuration parameters';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `genus`
+--
+
+DROP TABLE IF EXISTS `genus`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `genus` (
+ `genus_id` mediumint(8) unsigned NOT NULL,
+ `latin_genus_name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ `entry_date` date DEFAULT NULL,
+ `expiry_date` date DEFAULT NULL,
+ `change_date_time` datetime DEFAULT NULL,
+ PRIMARY KEY (`genus_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FG130916.txt';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `goodCharacteristic`
+--
+
+DROP TABLE IF EXISTS `goodCharacteristic`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `goodCharacteristic` (
+ `supplyResponse` varchar(26) COLLATE utf8_unicode_ci NOT NULL,
+ `type` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'edi.type',
+ `value` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'edi.value',
+ PRIMARY KEY (`supplyResponse`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `imap_config`
+--
+
+DROP TABLE IF EXISTS `imap_config`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `imap_config` (
+ `id` tinyint(3) unsigned NOT NULL,
+ `host` varchar(150) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'localhost',
+ `user` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `pass` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `clean_period` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'How long the old mails are preserved',
+ `success_folder` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `error_folder` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='IMAP configuration parameters';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `item`
+--
+
+DROP TABLE IF EXISTS `item`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `item` (
+ `id` int(11) unsigned NOT NULL,
+ `product_name` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ `plant_id` mediumint(8) unsigned DEFAULT NULL,
+ `group_id` int(11) DEFAULT NULL,
+ `entry_date` date DEFAULT NULL,
+ `expiry_date` date DEFAULT NULL,
+ `change_date_time` datetime DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `group_id` (`group_id`),
+ KEY `plant_id` (`plant_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FP130916.txt';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `item_feature`
+--
+
+DROP TABLE IF EXISTS `item_feature`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `item_feature` (
+ `item_id` int(11) NOT NULL,
+ `presentation_order` tinyint(11) unsigned NOT NULL,
+ `feature` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ `regulation_type` tinyint(3) unsigned NOT NULL,
+ `entry_date` date NOT NULL,
+ `expiry_date` date DEFAULT NULL,
+ `change_date_time` datetime NOT NULL,
+ PRIMARY KEY (`item_id`,`presentation_order`,`entry_date`,`change_date_time`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FY130916.txt';
+/*!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 `item_feature_bi` BEFORE INSERT ON `item_feature` FOR EACH ROW
+BEGIN
+ IF NEW.expiry_date = '0000-00-00' THEN
+ SET NEW.expiry_date = 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 `item_group`
+--
+
+DROP TABLE IF EXISTS `item_group`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `item_group` (
+ `group_code` int(11) unsigned NOT NULL,
+ `dutch_group_description` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ `entry_date` date NOT NULL,
+ `expiry_date` date NOT NULL,
+ `change_date_time` datetime NOT NULL,
+ PRIMARY KEY (`group_code`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FO130916.txt';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `item_track`
+--
+
+DROP TABLE IF EXISTS `item_track`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `item_track` (
+ `item_id` int(10) unsigned NOT NULL,
+ `s1` tinyint(3) NOT NULL DEFAULT '0',
+ `s2` tinyint(3) NOT NULL DEFAULT '0',
+ `s3` tinyint(3) NOT NULL DEFAULT '0',
+ `s4` tinyint(3) NOT NULL DEFAULT '0',
+ `pac` tinyint(3) NOT NULL DEFAULT '0',
+ `cat` tinyint(3) NOT NULL DEFAULT '0',
+ `ori` tinyint(3) NOT NULL DEFAULT '0',
+ `pro` tinyint(3) NOT NULL DEFAULT '0',
+ `package` tinyint(3) NOT NULL DEFAULT '0',
+ `s5` tinyint(3) NOT NULL DEFAULT '0',
+ `s6` tinyint(3) NOT NULL DEFAULT '0',
+ `kop` tinyint(3) NOT NULL DEFAULT '0',
+ `sub` tinyint(3) NOT NULL DEFAULT '0',
+ PRIMARY KEY (`item_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!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` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `mail` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
+ `kop` int(10) unsigned DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `mail` (`mail`)
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='List of allowed mailers';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `message`
+--
+
+DROP TABLE IF EXISTS `message`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `message` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `sender_id` int(10) unsigned DEFAULT NULL,
+ `mail_id` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `mail_id` (`mail_id`),
+ KEY `sender_id` (`sender_id`),
+ CONSTRAINT `message_ibfk_2` FOREIGN KEY (`sender_id`) REFERENCES `mail` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=285868 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `param`
+--
+
+DROP TABLE IF EXISTS `param`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `param` (
+ `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
+ `code` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
+ `name` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
+ `subname` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `position` tinyint(3) unsigned NOT NULL DEFAULT '1',
+ `type` enum('INTEGER','DOUBLE','STRING','DATE','TIME') COLLATE utf8_unicode_ci NOT NULL,
+ `required` tinyint(3) unsigned NOT NULL DEFAULT '1',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `name` (`name`,`subname`)
+) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Parameters to capture of every exchange';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `plant`
+--
+
+DROP TABLE IF EXISTS `plant`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `plant` (
+ `plant_id` mediumint(8) unsigned NOT NULL,
+ `genus_id` mediumint(8) unsigned NOT NULL,
+ `specie_id` mediumint(8) unsigned DEFAULT NULL,
+ `entry_date` date DEFAULT NULL,
+ `expiry_date` date DEFAULT NULL,
+ `change_date_time` datetime DEFAULT NULL,
+ PRIMARY KEY (`plant_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FT130916.txt';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `specie`
+--
+
+DROP TABLE IF EXISTS `specie`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `specie` (
+ `specie_id` mediumint(8) unsigned NOT NULL,
+ `genus_id` mediumint(8) unsigned NOT NULL,
+ `latin_species_name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ `entry_date` date DEFAULT NULL,
+ `expiry_date` date DEFAULT NULL,
+ `change_date_time` datetime DEFAULT NULL,
+ PRIMARY KEY (`specie_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FS130916.txt';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `supplier`
+--
+
+DROP TABLE IF EXISTS `supplier`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `supplier` (
+ `supplier_id` int(10) unsigned NOT NULL COMMENT 'FHRegistrationNr',
+ `glnAddressCode` varchar(13) CHARACTER SET utf8 DEFAULT NULL,
+ `company_name` varchar(70) COLLATE utf8_unicode_ci NOT NULL,
+ `entry_date` date NOT NULL,
+ `expiry_date` date NOT NULL,
+ `change_date_time` datetime NOT NULL,
+ PRIMARY KEY (`supplier_id`),
+ KEY `glnaddressCodeidx` (`glnAddressCode`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/FEC010104/CC090916.txt';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `supplyResponse`
+--
+
+DROP TABLE IF EXISTS `supplyResponse`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `supplyResponse` (
+ `ID` int(11) NOT NULL,
+ `NumberBunchesPerCask` int(11) DEFAULT NULL,
+ `SupplierGLN` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `NewItem` tinyint(1) DEFAULT NULL,
+ `SendererID` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `ItemSupplierID` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `TransactionDate` datetime DEFAULT NULL,
+ `TransactionNumber` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `AuctionClockNumber` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `SupplierID` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `FLA` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `ItemDatesupplyResponsecol` datetime DEFAULT NULL,
+ `Item_ArticleCode` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `VBNOmschrijving` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `ExtraRemark` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `ArtCodeType` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `VBNGroupCode` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `VBNGroupDescription` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `TransactionTime` time DEFAULT NULL,
+ `SupplierNumber` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `CountryOfOrigin` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `SerialNumber` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `NumberOfItemsPerCask` int(11) DEFAULT NULL,
+ `NumberOfLayersPerTrolley` int(11) DEFAULT NULL,
+ `NumberOfUnits` int(11) DEFAULT NULL,
+ `MinimumNumberToOrder` int(11) DEFAULT NULL,
+ `MinimumOrderUnitType` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Price` decimal(10,2) DEFAULT NULL,
+ `PotSize` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Height` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Length` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Weight` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Quality` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `NumberOfBuds` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `NumberOfBudsPerStem` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `ExaminiationCode1` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `ExaminiationCode2` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Diameter` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `PlantDiameter` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Potshape` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `FlowerShape` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `FlowerColor` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `PotColor` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `PotMaterial` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `MaterialHeight` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `MaterialDiameter` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `OtherMaterial` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `OrderUnitType` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `EmbalageCode` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `PictureReference` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`ID`),
+ UNIQUE KEY `ID_UNIQUE` (`ID`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `type`
+--
+
+DROP TABLE IF EXISTS `type`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `type` (
+ `type_id` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ `type_group_id` tinyint(3) unsigned NOT NULL,
+ `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ `entry_date` date NOT NULL,
+ `expiry_date` date NOT NULL,
+ `change_date_time` datetime NOT NULL,
+ PRIMARY KEY (`type_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FE130916.txt';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `value`
+--
+
+DROP TABLE IF EXISTS `value`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `value` (
+ `type_id` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ `type_value` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ `type_description` varchar(70) COLLATE utf8_unicode_ci NOT NULL,
+ `entry_date` date NOT NULL,
+ `expiry_date` date NOT NULL,
+ `change_date_time` datetime NOT NULL,
+ PRIMARY KEY (`type_id`,`type_value`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FV130916.txt';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping events for database 'edi'
+--
+
+--
+-- Dumping routines for database 'edi'
+--
+/*!50003 DROP PROCEDURE IF EXISTS `batchNew` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `batchNew`(
+ vMessage INT
+ ,vItem VARCHAR(255)
+ ,vType MEDIUMINT
+ ,vDeliveryNumber BIGINT
+ ,vDate DATE
+ ,vHour TIME
+ ,vRef INT
+ ,vAgj INT
+ ,vCat VARCHAR(2)
+ ,vPac INT
+ ,vSub MEDIUMINT
+ ,vKop INT
+ ,vPtd VARCHAR(6)
+ ,vPro MEDIUMINT
+ ,vOrigin VARCHAR(3)
+ ,vPtj MEDIUMINT
+ ,vQuantiy INT
+ ,vPrice DOUBLE
+ ,vClock SMALLINT
+ ,vS1 VARCHAR(3)
+ ,vS2 VARCHAR(3)
+ ,vS3 VARCHAR(3)
+ ,vS4 VARCHAR(4)
+ ,vS5 VARCHAR(3)
+ ,vS6 VARCHAR(3)
+ ,vK1 SMALLINT
+ ,vK2 SMALLINT
+ ,vP1 TINYINT
+ ,vP2 TINYINT
+ ,vAuction SMALLINT
+ ,vPackage INT
+)
+BEGIN
+/**
+ * Añade un nuevo lote, genera su código de barras y
+ * inserta/actualiza el registro en la tabla #vn2008.buy_edi
+ */
+ DECLARE vEdi INT;
+ DECLARE vRewriteKop INT DEFAULT NULL;
+ DECLARE vBarcode CHAR(15) DEFAULT NULL;
+ DECLARE vIsDuplicated BOOLEAN DEFAULT FALSE;
+ DECLARE vUpdateExistent BOOLEAN DEFAULT FALSE;
+
+ DECLARE CONTINUE HANDLER FOR 1062 -- ER_DUP_KEY
+ SET vIsDuplicated = TRUE;
+
+ -- Genera el código de barras
+
+ IF vAgj != 0 AND vAgj IS NOT NULL
+ THEN
+ SET vBarcode = CONCAT(
+ LPAD(vAuction, 2, 0),
+ LPAD(IFNULL(vClock, 99), 2, 0),
+ LPAD(DAYOFYEAR(vDate), 3, 0),
+ IF(vClock IS NULL OR vClock = 99,
+ LPAD(vAgj, 7, 0),
+ CONCAT(LPAD(vAgj, 5, 0), '01')
+ ),
+ '0'
+ );
+ END IF;
+
+ -- Reescribe el parámetro kop
+
+ IF vKop IS NULL
+ THEN
+ SELECT default_kop INTO vKop FROM config;
+ END IF;
+
+ SELECT e.kop INTO vRewriteKop
+ FROM mail e
+ JOIN message m ON m.sender_id = e.id
+ WHERE m.id = vMessage;
+
+ SET vKop = IFNULL(vRewriteKop, vKop);
+
+ -- Inserta el nuevo EKT
+
+ INSERT INTO vn2008.buy_edi SET
+ barcode = IFNULL(vBarcode, barcode)
+ ,delivery_number = vDeliveryNumber
+ ,entry_year = YEAR(vDate)
+ ,fec = vDate
+ ,hor = vHour
+ ,ref = vRef
+ ,item = vItem
+ ,agj = vAgj
+ ,cat = vCat
+ ,pac = vPac
+ ,sub = vSub
+ ,kop = vKop
+ ,ptd = vPtd
+ ,pro = vPro
+ ,ori = vOrigin
+ ,ptj = vPtj
+ ,qty = vQuantiy
+ ,pri = vPrice
+ ,klo = vClock
+ ,s1 = vS1
+ ,s2 = vS2
+ ,s3 = vS3
+ ,s4 = vS4
+ ,s5 = vS5
+ ,s6 = vS6
+ ,k01 = vK1
+ ,k02 = vK2
+ ,k03 = vP1
+ ,k04 = vP2
+ ,auction = vAuction
+ ,package = vPackage;
+
+
+ -- Si el EKT está duplicado y el que habia en la tabla era uno
+ -- provisional, lo actualiza con los nuevos valores.
+
+ IF NOT vIsDuplicated
+ THEN
+ SET vEdi = LAST_INSERT_ID();
+ CALL ediLoad (vEdi);
+
+ ELSEIF vDeliveryNumber != 0
+ AND vDeliveryNumber IS NOT NULL
+ THEN
+ SELECT id INTO vEdi
+ FROM vn2008.buy_edi
+ WHERE delivery_number = vDeliveryNumber;
+
+ SELECT COUNT(*) = 0 INTO vUpdateExistent
+ FROM vn2008.buy_edi e
+ JOIN batch b ON b.buy_edi_id = e.id
+ JOIN config c
+ WHERE e.delivery_number = vDeliveryNumber
+ AND b.type_id != c.presale_id;
+ END IF;
+
+ IF vUpdateExistent
+ THEN
+ UPDATE vn2008.buy_edi SET
+ barcode = IFNULL(vBarcode, barcode)
+ ,fec = vDate
+ ,hor = vHour
+ ,ref = vRef
+ ,item = vItem
+ ,agj = vAgj
+ ,cat = vCat
+ ,pac = vPac
+ ,sub = vSub
+ ,kop = vKop
+ ,ptd = vPtd
+ ,pro = vPro
+ ,ori = vOrigin
+ ,ptj = vPtj
+ ,qty = vQuantiy
+ ,pri = vPrice
+ ,klo = vClock
+ ,s1 = vS1
+ ,s2 = vS2
+ ,s3 = vS3
+ ,s4 = vS4
+ ,s5 = vS5
+ ,s6 = vS6
+ ,k01 = vK1
+ ,k02 = vK2
+ ,k03 = vP1
+ ,k04 = vP2
+ ,auction = vAuction
+ ,package = vPackage
+ WHERE id = vEdi;
+ END IF;
+
+ -- Registra el lote
+
+ INSERT INTO batch SET
+ message_id = vMessage
+ ,type_id = vType
+ ,buy_edi_id = vEdi;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ediLoad` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ediLoad`(vEdi INT)
+BEGIN
+ DECLARE vRef INT;
+ DECLARE vBuy INT;
+ DECLARE vItem INT;
+ DECLARE vQty INT;
+ DECLARE vPackage INT;
+ DECLARE vIsLot BOOLEAN;
+
+ -- Carga los datos necesarios del EKT
+
+ SELECT ref, qty, package INTO vRef, vQty, vPackage
+ FROM vn2008.buy_edi e
+ LEFT JOIN item i ON e.ref = i.id
+ WHERE e.id = vEdi;
+
+ -- Inserta el cubo si no existe
+
+ IF vPackage = 800
+ THEN
+ SET vPackage = 800 + vQty;
+
+ INSERT IGNORE INTO vn2008.Cubos SET
+ Id_Cubo = vPackage,
+ x = 7200 / vQty,
+ y = 1;
+ ELSE
+ INSERT IGNORE INTO vn2008.Cubos (Id_Cubo, X, Y, Z)
+ SELECT bucket_id, ROUND(x_size/10), ROUND(y_size/10), ROUND(z_size/10)
+ FROM bucket WHERE bucket_id = vPackage;
+
+ IF ROW_COUNT() > 0
+ THEN
+ INSERT INTO vn2008.mail SET
+ `subject` = 'Cubo añadido',
+ `text` = CONCAT('Se ha añadido el cubo: ', vPackage),
+ `to` = 'ekt@verdnatura.es';
+ END IF;
+ END IF;
+
+ -- Intenta obtener el artículo en base a los atributos holandeses
+
+ INSERT IGNORE INTO item_track SET
+ item_id = vRef;
+
+ SELECT c.Id_Compra, c.Id_Article INTO vBuy, vItem
+ FROM vn2008.buy_edi e
+ JOIN item_track t ON t.item_id = e.ref
+ LEFT JOIN vn2008.buy_edi l ON l.ref = e.ref
+ LEFT JOIN vn2008.Compres c ON c.buy_edi_id = l.id
+ JOIN vn2008.config cfg
+ WHERE e.id = vEdi
+ AND l.id != vEdi
+ AND c.Id_Article != cfg.generic_item
+ AND IF(t.s1, l.s1 = e.s1, TRUE)
+ AND IF(t.s2, l.s2 = e.s2, TRUE)
+ AND IF(t.s3, l.s3 = e.s3, TRUE)
+ AND IF(t.s4, l.s4 = e.s4, TRUE)
+ AND IF(t.s5, l.s5 = e.s5, TRUE)
+ AND IF(t.s6, l.s6 = e.s6, TRUE)
+ AND IF(t.kop, l.kop = e.kop, TRUE)
+ AND IF(t.pac, l.pac = e.pac, TRUE)
+ AND IF(t.cat, l.cat = e.cat, TRUE)
+ AND IF(t.ori, l.ori = e.ori, TRUE)
+ AND IF(t.pro, l.pro = e.pro, TRUE)
+ AND IF(t.sub, l.sub = e.sub, TRUE)
+ AND IF(t.package, l.package = e.package, TRUE)
+ AND c.Id_Article < 170000
+ ORDER BY l.now DESC, c.Id_Compra ASC LIMIT 1;
+
+ -- Determina si el articulo se vende por lotes
+
+ IF vItem
+ THEN
+ SELECT COUNT(*) > 0 INTO vIsLot
+ FROM vn2008.Articles a
+ LEFT JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id
+ WHERE a.Id_Article = vItem
+ AND t.`transaction`;
+
+ -- Si el articulo se vende por lotes se inserta un nuevo artículo
+
+ IF vIsLot
+ THEN
+ INSERT INTO vn2008.Articles (
+ Article
+ ,Medida
+ ,Categoria
+ ,Id_Origen
+ ,iva_group_id
+ ,Foto
+ ,Color
+ ,Codintrastat
+ ,tipo_id
+ ,Tallos
+ )
+ SELECT
+ i.`name`
+ ,IFNULL(e.s1, e.pac)
+ ,e.cat
+ ,IFNULL(o.id, 17)
+ ,IFNULL(a.iva_group_id, 1)
+ ,a.Foto
+ ,a.Color
+ ,a.Codintrastat
+ ,IFNULL(a.tipo_id, 10)
+ ,IF(a.tipo_id = 15, 0, 1)
+ FROM vn2008.buy_edi e
+ LEFT JOIN item i ON i.id = e.ref
+ LEFT JOIN vn2008.Origen o ON o.Abreviatura = e.ori
+ LEFT JOIN vn2008.Articles a ON a.Id_Article = vItem
+ WHERE e.id = vEdi;
+
+ SET vItem = LAST_INSERT_ID();
+ END IF;
+ END IF;
+
+ -- Inserta la compra asociada al EKT
+
+ INSERT INTO vn2008.Compres
+ (
+ Id_Entrada
+ ,buy_edi_id
+ ,Costefijo
+ ,Id_Article
+ ,grouping
+ ,caja
+ ,Packing
+ ,Cantidad
+ ,Productor
+ ,Etiquetas
+ ,Id_Cubo
+ )
+ SELECT
+ cfg.edi_entry
+ ,vEdi
+ ,(@t := IF(a.Tallos, a.Tallos, 1)) * e.pri
+ ,IFNULL(vItem, cfg.generic_item)
+ ,IFNULL(c.grouping, e.pac)
+ ,IFNULL(c.caja, TRUE)
+ ,@pac := e.pac / @t
+ ,@pac * e.qty
+ ,s.company_name
+ ,e.qty
+ ,IFNULL(c.Id_Cubo, e.package)
+ FROM vn2008.buy_edi e
+ LEFT JOIN vn2008.Compres c ON c.Id_Compra = vBuy
+ LEFT JOIN vn2008.Articles a ON a.Id_Article = c.Id_Article
+ LEFT JOIN supplier s ON e.pro = s.supplier_id
+ JOIN vn2008.config cfg
+ WHERE e.id = vEdi
+ 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 `messageNew` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `messageNew`(
+ vMailId VARCHAR(100)
+ ,vSender VARCHAR(150)
+ ,OUT vMessageId INT
+)
+BEGIN
+/**
+ * Registra un correo electronico.
+ *
+ * @param vMailId Message-ID del correo electrónico
+ * @param vSender Id del correo electrónio del remitente
+ */
+ DECLARE vSenderId INT;
+
+ SELECT id INTO vSenderId FROM mail
+ WHERE mail = vSender;
+
+ INSERT IGNORE INTO message SET
+ sender_id = vSenderId
+ ,mail_id = vMailId;
+
+ SET vMessageId = 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 */ ;
+
+--
+-- Current Database: `bi`
+--
+
+CREATE DATABASE /*!32312 IF NOT EXISTS*/ `bi` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
+
+USE `bi`;
+
+--
+-- Table structure for table `Equalizator`
+--
+
+DROP TABLE IF EXISTS `Equalizator`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `Equalizator` (
+ `Vista` int(11) NOT NULL,
+ `Pedido` int(11) DEFAULT NULL,
+ `Impreso` int(11) DEFAULT NULL,
+ `Encajado` int(11) DEFAULT NULL,
+ PRIMARY KEY (`Vista`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `Greuge_Evolution`
+--
+
+DROP TABLE IF EXISTS `Greuge_Evolution`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `Greuge_Evolution` (
+ `Id_Cliente` int(11) NOT NULL,
+ `Fecha` date NOT NULL,
+ `Greuge` decimal(10,2) NOT NULL DEFAULT '0.00',
+ `Ventas` decimal(10,2) NOT NULL DEFAULT '0.00',
+ `Fosil` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'greuge fósil, correspondiente a los clientes muertos',
+ `Recobro` decimal(10,2) NOT NULL DEFAULT '0.00',
+ PRIMARY KEY (`Id_Cliente`,`Fecha`),
+ KEY `greuge_evolution_idx1` (`Fecha`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacenamos la evolucion del greuge de los ultimos dias ';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `Greuge_comercial_recobro`
+--
+
+DROP TABLE IF EXISTS `Greuge_comercial_recobro`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `Greuge_comercial_recobro` (
+ `Id_Trabajador` int(11) NOT NULL,
+ `recobro` decimal(10,2) NOT NULL DEFAULT '0.00',
+ `peso_cartera` decimal(10,2) NOT NULL DEFAULT '0.00',
+ PRIMARY KEY (`Id_Trabajador`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `Greuges_comercial_detail`
+--
+
+DROP TABLE IF EXISTS `Greuges_comercial_detail`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `Greuges_comercial_detail` (
+ `Id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `Id_Trabajador` int(10) unsigned NOT NULL,
+ `Comentario` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
+ `Importe` decimal(10,2) NOT NULL,
+ `Fecha` datetime DEFAULT NULL,
+ PRIMARY KEY (`Id`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=FIXED;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `Last_buy_id`
+--
+
+DROP TABLE IF EXISTS `Last_buy_id`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `Last_buy_id` (
+ `Id_Article` int(11) NOT NULL DEFAULT '90',
+ `Id_Compra` int(11) NOT NULL DEFAULT '0',
+ `warehouse_id` smallint(6) unsigned NOT NULL,
+ PRIMARY KEY (`warehouse_id`,`Id_Article`),
+ UNIQUE KEY `Id_Compra_UNIQUE` (`Id_Compra`),
+ CONSTRAINT `Id_CompraFK` FOREIGN KEY (`Id_Compra`) REFERENCES `vn2008`.`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 `Last_buy_idBackUp`
+--
+
+DROP TABLE IF EXISTS `Last_buy_idBackUp`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `Last_buy_idBackUp` (
+ `Id_Article` int(11) NOT NULL DEFAULT '90',
+ `Id_Compra` int(11) NOT NULL DEFAULT '0',
+ `warehouse_id` smallint(6) unsigned NOT NULL,
+ PRIMARY KEY (`Id_Article`,`warehouse_id`),
+ UNIQUE KEY `Id_Compra_UNIQUE` (`Id_Compra`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `Radar`
+--
+
+DROP TABLE IF EXISTS `Radar`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `Radar` (
+ `Propio` int(1) NOT NULL DEFAULT '0',
+ `Credito` double NOT NULL DEFAULT '0',
+ `Riesgo` double(19,2) DEFAULT NULL,
+ `Greuge` double DEFAULT NULL,
+ `Id_Ticket` int(11) NOT NULL DEFAULT '0',
+ `wh` smallint(6) unsigned NOT NULL DEFAULT '1',
+ `Fecha` datetime NOT NULL,
+ `Alias` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Vista` int(11) DEFAULT '0',
+ `Tipo` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'RECOGIDA',
+ `Id_Trabajador` int(11) DEFAULT '20',
+ `Solucion` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Localizacion` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Estado` varchar(15) CHARACTER SET utf8 DEFAULT NULL,
+ `Fecha_Simple` date DEFAULT NULL,
+ `Id_Comercial` int(11) DEFAULT '20',
+ `Risk` double NOT NULL DEFAULT '0',
+ `Rojo` bigint(21) DEFAULT '0',
+ `Naranja` bigint(21) DEFAULT '0',
+ `Amarillo` bigint(21) DEFAULT '0'
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `Ticket_Portes`
+--
+
+DROP TABLE IF EXISTS `Ticket_Portes`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `Ticket_Portes` (
+ `Id_Ticket` int(11) NOT NULL,
+ `rate` tinyint(4) NOT NULL COMMENT 'Tarifa',
+ `real_amount` double NOT NULL COMMENT 'Cantidad pactada con la agencia',
+ `payed_amount` double NOT NULL COMMENT 'Cantidad reflejada en el Ticket',
+ PRIMARY KEY (`Id_Ticket`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `VelocityKK`
+--
+
+DROP TABLE IF EXISTS `VelocityKK`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `VelocityKK` (
+ `tipo_id` int(11) NOT NULL,
+ `Fecha` datetime NOT NULL,
+ `Disponible` int(11) DEFAULT NULL,
+ `Visible` int(11) DEFAULT NULL,
+ `velocity_id` int(11) NOT NULL AUTO_INCREMENT,
+ PRIMARY KEY (`velocity_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 `XDiario_ALL`
+--
+
+DROP TABLE IF EXISTS `XDiario_ALL`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `XDiario_ALL` (
+ `empresa_id` int(5) NOT NULL,
+ `SUBCTA` varchar(11) COLLATE utf8_unicode_ci NOT NULL,
+ `Eurodebe` double DEFAULT NULL,
+ `Eurohaber` double DEFAULT NULL,
+ `Fecha` date DEFAULT NULL,
+ `FECHA_EX` date DEFAULT NULL,
+ KEY `Cuenta` (`SUBCTA`),
+ KEY `empresa` (`empresa_id`),
+ KEY `Fecha` (`Fecha`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `analisis_grafico_simple`
+--
+
+DROP TABLE IF EXISTS `analisis_grafico_simple`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `analisis_grafico_simple` (
+ `Año` smallint(5) unsigned NOT NULL,
+ `Semana` tinyint(3) unsigned NOT NULL,
+ `Importe` double DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `analisis_grafico_ventas`
+--
+
+DROP TABLE IF EXISTS `analisis_grafico_ventas`;
+/*!50001 DROP VIEW IF EXISTS `analisis_grafico_ventas`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `analisis_grafico_ventas` AS SELECT
+ 1 AS `Año`,
+ 1 AS `Semana`,
+ 1 AS `Importe`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `analisis_ventas`
+--
+
+DROP TABLE IF EXISTS `analisis_ventas`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `analisis_ventas` (
+ `Familia` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
+ `Reino` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
+ `Comercial` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ `Comprador` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ `Provincia` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
+ `almacen` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
+ `Año` smallint(5) unsigned NOT NULL,
+ `Mes` tinyint(3) unsigned NOT NULL,
+ `Semana` tinyint(3) unsigned NOT NULL,
+ `Vista` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `Importe` double NOT NULL,
+ KEY `Año` (`Año`,`Semana`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `analisis_ventas_almacen_evolution`
+--
+
+DROP TABLE IF EXISTS `analisis_ventas_almacen_evolution`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `analisis_ventas_almacen_evolution` (
+ `Semana` int(11) NOT NULL,
+ `Almacen` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
+ `Ventas` int(11) NOT NULL,
+ `Año` int(11) NOT NULL,
+ `Periodo` int(11) NOT NULL,
+ KEY `Almacen` (`Almacen`,`Periodo`),
+ KEY `Periodo` (`Periodo`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `analisis_ventas_comprador_evolution`
+--
+
+DROP TABLE IF EXISTS `analisis_ventas_comprador_evolution`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `analisis_ventas_comprador_evolution` (
+ `semana` int(11) NOT NULL,
+ `comprador` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ `ventas` int(11) NOT NULL,
+ `año` int(11) NOT NULL,
+ `periodo` int(11) NOT NULL,
+ UNIQUE KEY `comprador` (`comprador`,`periodo`),
+ KEY `periodo` (`periodo`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `analisis_ventas_familia_evolution`
+--
+
+DROP TABLE IF EXISTS `analisis_ventas_familia_evolution`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `analisis_ventas_familia_evolution` (
+ `semana` int(11) NOT NULL,
+ `familia` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `ventas` int(11) NOT NULL,
+ `año` int(11) NOT NULL,
+ `periodo` int(11) NOT NULL,
+ KEY `familia` (`familia`,`periodo`),
+ KEY `periodo` (`periodo`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `analisis_ventas_provincia_evolution`
+--
+
+DROP TABLE IF EXISTS `analisis_ventas_provincia_evolution`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `analisis_ventas_provincia_evolution` (
+ `semana` int(11) NOT NULL,
+ `provincia` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
+ `ventas` int(11) NOT NULL,
+ `año` int(11) NOT NULL,
+ `periodo` int(11) NOT NULL,
+ UNIQUE KEY `provincia` (`provincia`,`periodo`),
+ KEY `periodo` (`periodo`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `analisis_ventas_reino_evolution`
+--
+
+DROP TABLE IF EXISTS `analisis_ventas_reino_evolution`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `analisis_ventas_reino_evolution` (
+ `semana` int(11) NOT NULL,
+ `reino` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
+ `ventas` int(11) NOT NULL,
+ `año` int(11) NOT NULL,
+ `periodo` int(11) NOT NULL,
+ UNIQUE KEY `reino` (`reino`,`periodo`),
+ KEY `periodo` (`periodo`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `analisis_ventas_simple`
+--
+
+DROP TABLE IF EXISTS `analisis_ventas_simple`;
+/*!50001 DROP VIEW IF EXISTS `analisis_ventas_simple`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `analisis_ventas_simple` AS SELECT
+ 1 AS `Año`,
+ 1 AS `Semana`,
+ 1 AS `Importe`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `analisis_ventas_vendedor_evolution`
+--
+
+DROP TABLE IF EXISTS `analisis_ventas_vendedor_evolution`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `analisis_ventas_vendedor_evolution` (
+ `semana` int(11) NOT NULL,
+ `vendedor` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ `ventas` int(11) NOT NULL,
+ `año` int(11) NOT NULL,
+ `periodo` int(11) NOT NULL,
+ UNIQUE KEY `vendedor` (`vendedor`,`periodo`),
+ KEY `periodo` (`periodo`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `analisis_ventas_vista_evolution`
+--
+
+DROP TABLE IF EXISTS `analisis_ventas_vista_evolution`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `analisis_ventas_vista_evolution` (
+ `semana` int(11) NOT NULL,
+ `vista` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
+ `ventas` int(11) NOT NULL,
+ `año` int(11) NOT NULL,
+ `periodo` int(11) NOT NULL,
+ UNIQUE KEY `vista` (`vista`,`periodo`),
+ KEY `periodo` (`periodo`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `calidad_detalle`
+--
+
+DROP TABLE IF EXISTS `calidad_detalle`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `calidad_detalle` (
+ `Id_Cliente` int(11) NOT NULL,
+ `calidad_parametros_id` int(2) NOT NULL,
+ `valor` int(3) DEFAULT NULL,
+ PRIMARY KEY (`Id_Cliente`,`calidad_parametros_id`),
+ KEY `calidad_parametros_detalle_idx` (`calidad_parametros_id`),
+ CONSTRAINT `calidad_parametros_detalle` FOREIGN KEY (`calidad_parametros_id`) REFERENCES `calidad_parametros` (`calidad_parametros_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 `calidad_parametros`
+--
+
+DROP TABLE IF EXISTS `calidad_parametros`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `calidad_parametros` (
+ `calidad_parametros_id` int(2) NOT NULL,
+ `descripcion` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`calidad_parametros_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `claims_ratio`
+--
+
+DROP TABLE IF EXISTS `claims_ratio`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `claims_ratio` (
+ `Id_Cliente` int(11) NOT NULL DEFAULT '0',
+ `Consumo` decimal(10,2) DEFAULT NULL,
+ `Reclamaciones` decimal(10,2) DEFAULT NULL,
+ `Ratio` decimal(5,2) DEFAULT NULL,
+ `recobro` decimal(5,2) DEFAULT NULL,
+ `inflacion` decimal(5,2) NOT NULL DEFAULT '1.00',
+ PRIMARY KEY (`Id_Cliente`),
+ CONSTRAINT `claims_ratio_ibfk_1` FOREIGN KEY (`Id_Cliente`) REFERENCES `vn2008`.`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 `comparativa_clientes`
+--
+
+DROP TABLE IF EXISTS `comparativa_clientes`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `comparativa_clientes` (
+ `Fecha` date NOT NULL DEFAULT '0000-00-00',
+ `Id_Cliente` int(11) NOT NULL DEFAULT '0',
+ `Propietario` int(11) DEFAULT NULL,
+ `titular` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ `suplente` varchar(3) COLLATE utf8_unicode_ci NOT NULL,
+ `trabajador` int(11) DEFAULT NULL,
+ `actual` double DEFAULT NULL,
+ `pasado` double DEFAULT NULL,
+ `concepto` varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '',
+ KEY `cc_data_indez` (`Fecha`),
+ KEY `cc_Id_Cliente_index` (`Id_Cliente`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `customerDebtInventory`
+--
+
+DROP TABLE IF EXISTS `customerDebtInventory`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `customerDebtInventory` (
+ `Id_Cliente` int(11) NOT NULL,
+ `Debt` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'CREATE TABLE bi.customerDebtInventory\n\nSELECT Id_Cliente, sum(Euros) as Debt\n\nFROM \n(\nSELECT Id_Cliente, Entregado as Euros\n\nFROM Recibos \n\nWHERE Fechacobro < ''2017-01-01\n''\nUNION ALL\n\nSELECT Id_Cliente, - Importe \nFROM Facturas\nWHERE Fecha < ''2017-01-01''\n) sub \nGROUP BY Id_Cliente',
+ PRIMARY KEY (`Id_Cliente`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `customerRiskOverdue`
+--
+
+DROP TABLE IF EXISTS `customerRiskOverdue`;
+/*!50001 DROP VIEW IF EXISTS `customerRiskOverdue`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `customerRiskOverdue` AS SELECT
+ 1 AS `customer_id`,
+ 1 AS `amount`,
+ 1 AS `company_id`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `customer_risk`
+--
+
+DROP TABLE IF EXISTS `customer_risk`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `customer_risk` (
+ `customer_id` int(11) NOT NULL DEFAULT '0',
+ `company_id` smallint(6) unsigned NOT NULL DEFAULT '0',
+ `amount` decimal(10,2) DEFAULT NULL,
+ PRIMARY KEY (`customer_id`,`company_id`),
+ KEY `company_id` (`company_id`),
+ CONSTRAINT `customer_risk_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `customer_risk_ibfk_2` FOREIGN KEY (`company_id`) REFERENCES `vn2008`.`empresa` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Saldo de apertura < 2015-01-01';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `dailyTaskLog`
+--
+
+DROP TABLE IF EXISTS `dailyTaskLog`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `dailyTaskLog` (
+ `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL,
+ `created` 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 `defaulters`
+--
+
+DROP TABLE IF EXISTS `defaulters`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `defaulters` (
+ `client` int(11) NOT NULL,
+ `date` date NOT NULL,
+ `amount` double NOT NULL DEFAULT '0',
+ `defaulterSince` date DEFAULT NULL,
+ `hasChanged` tinyint(1) DEFAULT NULL,
+ PRIMARY KEY (`client`,`date`),
+ KEY `client` (`client`),
+ KEY `date` (`date`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `defaulting`
+--
+
+DROP TABLE IF EXISTS `defaulting`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `defaulting` (
+ `date` date NOT NULL,
+ `amount` double NOT NULL,
+ PRIMARY KEY (`date`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `f_tvc`
+--
+
+DROP TABLE IF EXISTS `f_tvc`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `f_tvc` (
+ `Id_Ticket` int(11) NOT NULL,
+ PRIMARY KEY (`Id_Ticket`),
+ CONSTRAINT `id_ticket_to_comisionantes` FOREIGN KEY (`Id_Ticket`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacenamos la lista de tickets para agilizar la consulta. Corresponde a los clientes REAL y en los almacenes COMISIONANTES';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `facturacion_media_anual`
+--
+
+DROP TABLE IF EXISTS `facturacion_media_anual`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `facturacion_media_anual` (
+ `Id_Cliente` int(11) NOT NULL,
+ `Consumo` double(17,0) DEFAULT NULL,
+ PRIMARY KEY (`Id_Cliente`),
+ CONSTRAINT `fmaId_Cliente` FOREIGN KEY (`Id_Cliente`) REFERENCES `vn2008`.`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 */;
+
+--
+-- Temporary view structure for view `last_Id_Cubo`
+--
+
+DROP TABLE IF EXISTS `last_Id_Cubo`;
+/*!50001 DROP VIEW IF EXISTS `last_Id_Cubo`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `last_Id_Cubo` AS SELECT
+ 1 AS `Id_Compra`,
+ 1 AS `Id_Article`,
+ 1 AS `warehouse_id`,
+ 1 AS `Id_Cubo`,
+ 1 AS `Packing`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `lastaction`
+--
+
+DROP TABLE IF EXISTS `lastaction`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `lastaction` (
+ `Id_Cliente` int(11) unsigned NOT NULL,
+ `Cliente` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `Ultima_accion` date DEFAULT NULL,
+ `Comercial` varchar(3) CHARACTER SET utf8 DEFAULT NULL,
+ 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 `live_counter`
+--
+
+DROP TABLE IF EXISTS `live_counter`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `live_counter` (
+ `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `amount` double NOT NULL,
+ PRIMARY KEY (`odbc_date`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `mana_inventory_kk`
+--
+
+DROP TABLE IF EXISTS `mana_inventory_kk`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `mana_inventory_kk` (
+ `Id_Trabajador` int(11) NOT NULL,
+ `mana` double NOT NULL DEFAULT '0',
+ `dated` date NOT NULL,
+ PRIMARY KEY (`Id_Trabajador`,`dated`),
+ CONSTRAINT `fk_trabajador_mana_inventory` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) 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_log`
+--
+
+DROP TABLE IF EXISTS `movimientos_log`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `movimientos_log` (
+ `idmovimientos_log` int(11) NOT NULL AUTO_INCREMENT,
+ `Id_Movimiento` int(11) NOT NULL,
+ `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `Id_Trabajador` int(11) NOT NULL,
+ `field_name` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `new_value` double DEFAULT NULL,
+ PRIMARY KEY (`idmovimientos_log`)
+) ENGINE=InnoDB AUTO_INCREMENT=13371133 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `partitioning_information`
+--
+
+DROP TABLE IF EXISTS `partitioning_information`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `partitioning_information` (
+ `schema_name` varchar(10) CHARACTER SET utf8 NOT NULL,
+ `table_name` varchar(20) CHARACTER SET utf8 NOT NULL,
+ `date_field` varchar(20) CHARACTER SET utf8 DEFAULT NULL,
+ `table_depending` varchar(15) CHARACTER SET utf8 DEFAULT NULL,
+ `execution_order` tinyint(3) unsigned NOT NULL,
+ PRIMARY KEY (`schema_name`,`table_name`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `primer_pedido`
+--
+
+DROP TABLE IF EXISTS `primer_pedido`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `primer_pedido` (
+ `Id_Cliente` int(11) NOT NULL,
+ `Id_Ticket` int(11) NOT NULL,
+ `month` tinyint(1) NOT NULL,
+ `year` smallint(2) NOT NULL,
+ `total` decimal(10,2) NOT NULL DEFAULT '0.00',
+ 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 `rotacion`
+--
+
+DROP TABLE IF EXISTS `rotacion`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `rotacion` (
+ `Id_Article` int(11) NOT NULL,
+ `warehouse_id` smallint(6) unsigned NOT NULL,
+ `total` int(10) NOT NULL DEFAULT '0',
+ `rotacion` decimal(10,4) NOT NULL DEFAULT '0.0000',
+ `cm3` int(11) NOT NULL DEFAULT '0',
+ `almacenaje` decimal(10,4) NOT NULL DEFAULT '0.0000',
+ `manipulacion` decimal(10,4) NOT NULL DEFAULT '0.0000',
+ `auxiliar` decimal(10,4) NOT NULL DEFAULT '0.0000',
+ `mermas` decimal(10,4) NOT NULL DEFAULT '0.0000',
+ PRIMARY KEY (`Id_Article`,`warehouse_id`),
+ KEY `id_article_rotacion_idx` (`Id_Article`),
+ KEY `warehouse_id_rotacion_idx` (`warehouse_id`),
+ CONSTRAINT `id_article_rotaci` FOREIGN KEY (`Id_Article`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `warehouse_id_rotaci` FOREIGN KEY (`warehouse_id`) REFERENCES `vn2008`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los valores de rotacion en los ultimos 365 dias';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `saldos_bancos`
+--
+
+DROP TABLE IF EXISTS `saldos_bancos`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `saldos_bancos` (
+ `Semana` int(2) NOT NULL,
+ `Mes` int(2) NOT NULL,
+ `Año` int(4) NOT NULL,
+ `Entrada` double DEFAULT NULL,
+ `Salida` decimal(32,2) DEFAULT NULL,
+ `Saldo` double DEFAULT NULL,
+ `Id_Banco` int(11) NOT NULL DEFAULT '0',
+ `empresa_id` int(5) unsigned NOT NULL DEFAULT '0',
+ `Empresa` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT ''
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `saldos_bancos_pordia`
+--
+
+DROP TABLE IF EXISTS `saldos_bancos_pordia`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `saldos_bancos_pordia` (
+ `Fecha` date NOT NULL,
+ `Entrada` double DEFAULT NULL,
+ `Salida` decimal(32,2) DEFAULT NULL,
+ `Saldo` double DEFAULT NULL,
+ `Id_Banco` int(11) NOT NULL DEFAULT '0',
+ `empresa_id` int(5) unsigned NOT NULL DEFAULT '0',
+ `Empresa` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT '',
+ `Año` int(4) NOT NULL,
+ `Mes` int(2) NOT NULL,
+ `Dia` int(2) NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `sales`
+--
+
+DROP TABLE IF EXISTS `sales`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `sales` (
+ `Id_Trabajador` int(10) unsigned NOT NULL,
+ `year` int(10) unsigned NOT NULL,
+ `month` int(10) unsigned NOT NULL,
+ `weight` int(11) NOT NULL DEFAULT '0',
+ `boss_aid` int(10) NOT NULL DEFAULT '0',
+ `boss_id` int(10) NOT NULL DEFAULT '0',
+ `comision` int(11) DEFAULT NULL,
+ PRIMARY KEY (`Id_Trabajador`,`year`,`month`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `tarifa_componentes`
+--
+
+DROP TABLE IF EXISTS `tarifa_componentes`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `tarifa_componentes` (
+ `Id_Componente` int(11) NOT NULL AUTO_INCREMENT,
+ `Componente` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
+ `tarifa_componentes_series_id` int(11) NOT NULL,
+ `tarifa_class` smallint(6) DEFAULT NULL,
+ `tax` double DEFAULT NULL,
+ `is_renewable` tinyint(2) NOT NULL DEFAULT '1',
+ PRIMARY KEY (`Id_Componente`),
+ KEY `series_componentes_idx` (`tarifa_componentes_series_id`),
+ KEY `comp` (`tarifa_class`),
+ CONSTRAINT `serie_componente` FOREIGN KEY (`tarifa_componentes_series_id`) REFERENCES `tarifa_componentes_series` (`tarifa_componentes_series_id`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=42 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `tarifa_componentes_series`
+--
+
+DROP TABLE IF EXISTS `tarifa_componentes_series`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `tarifa_componentes_series` (
+ `tarifa_componentes_series_id` int(11) NOT NULL AUTO_INCREMENT,
+ `Serie` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
+ `base` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Marca aquellas series que se utilizan para calcular el precio base de las ventas, a efectos estadisticos',
+ `margen` tinyint(4) NOT NULL DEFAULT '0',
+ PRIMARY KEY (`tarifa_componentes_series_id`),
+ UNIQUE KEY `Serie_UNIQUE` (`Serie`)
+) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Permite organizar de forma ordenada los distintos componentes';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `tarifa_premisas`
+--
+
+DROP TABLE IF EXISTS `tarifa_premisas`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `tarifa_premisas` (
+ `Id_Premisa` int(11) NOT NULL AUTO_INCREMENT,
+ `premisa` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`Id_Premisa`)
+) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `tarifa_warehouse`
+--
+
+DROP TABLE IF EXISTS `tarifa_warehouse`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `tarifa_warehouse` (
+ `Id_Tarifa_Warehouse` int(11) NOT NULL AUTO_INCREMENT,
+ `warehouse_id` int(11) NOT NULL,
+ `Id_Premisa` int(11) NOT NULL,
+ `Valor` double NOT NULL,
+ PRIMARY KEY (`Id_Tarifa_Warehouse`)
+) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los valores de gasto por almacen';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `v_clientes_jerarquia`
+--
+
+DROP TABLE IF EXISTS `v_clientes_jerarquia`;
+/*!50001 DROP VIEW IF EXISTS `v_clientes_jerarquia`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `v_clientes_jerarquia` AS SELECT
+ 1 AS `Id_Cliente`,
+ 1 AS `Cliente`,
+ 1 AS `Comercial`,
+ 1 AS `Jefe`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `v_ventas_contables`
+--
+
+DROP TABLE IF EXISTS `v_ventas_contables`;
+/*!50001 DROP VIEW IF EXISTS `v_ventas_contables`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `v_ventas_contables` AS SELECT
+ 1 AS `year`,
+ 1 AS `month`,
+ 1 AS `importe`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `variablesKK`
+--
+
+DROP TABLE IF EXISTS `variablesKK`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `variablesKK` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `variable` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `value` double DEFAULT NULL,
+ `date` datetime DEFAULT NULL,
+ `text` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping events for database 'bi'
+--
+
+--
+-- Dumping routines for database 'bi'
+--
+/*!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
+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 PROCEDURE IF EXISTS `analisis_ventas_evolution_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `analisis_ventas_evolution_add`()
+BEGIN
+ DECLARE vPreviousPeriod INT;
+ DECLARE vCurrentPeriod INT;
+ DECLARE vLastPeriod INT;
+ DECLARE vMinPeriod INT DEFAULT 201400;
+ DECLARE vMaxPeriod INT DEFAULT vn2008.vnperiod(CURDATE());
+
+ DECLARE vYear INT;
+ DECLARE vWeek INT;
+
+ -- Almacen
+
+ SET vCurrentPeriod = IFNULL(vLastPeriod, vMinPeriod);
+
+ WHILE vCurrentPeriod < vMaxPeriod
+ DO
+ SELECT MAX(Periodo) INTO vPreviousPeriod
+ FROM bi.analisis_ventas_almacen_evolution
+ WHERE Periodo < vMaxPeriod;
+
+ SELECT MIN(period) INTO vCurrentPeriod
+ FROM vn2008.time
+ WHERE period > vPreviousPeriod;
+
+ SET vYear = FLOOR(vCurrentPeriod / 100);
+ SET vWeek = vCurrentPeriod - (vYear * 100);
+
+ DELETE FROM bi.analisis_ventas_almacen_evolution
+ WHERE Periodo = vCurrentPeriod;
+
+ REPLACE bi.analisis_ventas_almacen_evolution(Almacen, Ventas, Semana,Año, Periodo)
+ SELECT Almacen, sum(Ventas) AS Ventas, vWeek, vYear, vCurrentPeriod
+ FROM (
+ SELECT almacen, sum(Importe) AS Ventas
+ FROM bi.analisis_ventas
+ WHERE vYear = Año
+ AND vWeek = Semana
+ GROUP BY almacen
+ UNION ALL
+ SELECT almacen, - sum(Importe) AS Ventas
+ FROM bi.analisis_ventas
+ WHERE vYear - 1 = Año
+ AND vWeek = Semana
+ GROUP BY almacen
+ UNION ALL
+ SELECT Almacen, Ventas
+ FROM bi.analisis_ventas_almacen_evolution
+ WHERE Periodo = vPreviousPeriod
+ ) sub
+ GROUP BY Almacen;
+ END WHILE;
+
+ -- Reino
+
+ SET vCurrentPeriod = vMinPeriod;
+
+ WHILE vCurrentPeriod < vMaxPeriod
+ DO
+ SELECT MAX(periodo) INTO vPreviousPeriod
+ FROM bi.analisis_ventas_reino_evolution
+ WHERE periodo < vMaxPeriod;
+
+ SELECT MIN(period) INTO vCurrentPeriod
+ FROM vn2008.time
+ WHERE period > vPreviousPeriod;
+
+ SET vYear = FLOOR(vCurrentPeriod / 100);
+ SET vWeek = vCurrentPeriod - (vYear * 100);
+
+ DELETE FROM bi.analisis_ventas_reino_evolution
+ WHERE Periodo = vCurrentPeriod;
+
+ REPLACE bi.analisis_ventas_reino_evolution(reino, ventas, semana,año, periodo)
+ SELECT reino, sum(ventas) AS ventas, vWeek, vYear, vCurrentPeriod
+ FROM (
+ SELECT Reino, sum(Importe) AS ventas
+ FROM bi.analisis_ventas
+ WHERE vYear = Año
+ AND vWeek = Semana
+ GROUP BY Reino
+ UNION ALL
+ SELECT Reino, - sum(Importe) AS ventas
+ FROM bi.analisis_ventas
+ WHERE vYear - 1 = Año
+ AND vWeek = Semana
+ GROUP BY Reino
+ UNION ALL
+ SELECT reino, ventas
+ FROM bi.analisis_ventas_reino_evolution
+ WHERE Periodo = vPreviousPeriod
+ ) sub
+ GROUP BY reino;
+ END WHILE;
+
+ -- Familia
+
+ SET vCurrentPeriod = vMinPeriod;
+
+ WHILE vCurrentPeriod < vMaxPeriod
+ DO
+ SELECT MAX(periodo) INTO vPreviousPeriod
+ FROM bi.analisis_ventas_familia_evolution
+ WHERE periodo < vMaxPeriod;
+
+ SELECT MIN(period) INTO vCurrentPeriod
+ FROM vn2008.time
+ WHERE period > vPreviousPeriod;
+
+ SET vYear = FLOOR(vCurrentPeriod / 100);
+ SET vWeek = vCurrentPeriod - (vYear * 100);
+
+ DELETE FROM bi.analisis_ventas_familia_evolution
+ WHERE Periodo = vCurrentPeriod;
+
+ REPLACE bi.analisis_ventas_familia_evolution(familia, ventas, semana,año, periodo)
+ SELECT Familia, sum(ventas) AS ventas, vWeek, vYear, vCurrentPeriod
+ FROM (
+ SELECT Familia, sum(Importe) AS ventas
+ FROM bi.analisis_ventas
+ WHERE vYear = Año
+ AND vWeek = Semana
+ GROUP BY familia
+ UNION ALL
+ SELECT Familia, - sum(Importe) AS ventas
+ FROM bi.analisis_ventas
+ WHERE vYear - 1 = Año
+ AND vWeek = Semana
+ GROUP BY familia
+ UNION ALL
+ SELECT familia, ventas
+ FROM bi.analisis_ventas_familia_evolution
+ WHERE Periodo = vPreviousPeriod
+ ) sub
+ GROUP BY Familia;
+ END WHILE;
+
+ -- Comprador
+ -- FIXME: Bucle infinito porque la tabla está vacía
+/*
+ SET vCurrentPeriod = vMinPeriod;
+
+ WHILE vCurrentPeriod < vMaxPeriod
+ DO
+ SELECT IFNULL(MAX(periodo),vMinPeriod) INTO vPreviousPeriod
+ FROM bi.analisis_ventas_comprador_evolution
+ WHERE periodo < vMaxPeriod;
+
+ SELECT MIN(period) INTO vCurrentPeriod
+ FROM vn2008.time
+ WHERE period > vPreviousPeriod;
+
+ SET vYear = FLOOR(vCurrentPeriod / 100);
+ SET vWeek = vCurrentPeriod - (vYear * 100);
+
+ DELETE FROM bi.analisis_ventas_comprador_evolution
+ WHERE Periodo = vCurrentPeriod;
+
+ REPLACE bi.analisis_ventas_comprador_evolution(comprador, ventas, semana,año, periodo)
+ SELECT Comprador, sum(ventas) AS ventas, vWeek, vYear, vCurrentPeriod
+ FROM (
+ SELECT Comprador, sum(Importe) AS ventas
+ FROM bi.analisis_ventas
+ WHERE vYear = Año
+ AND vWeek = Semana
+ GROUP BY Comprador
+ UNION ALL
+ SELECT Comprador, - sum(Importe) AS ventas
+ FROM bi.analisis_ventas
+ WHERE vYear - 1 = Año
+ AND vWeek = Semana
+ GROUP BY Comprador
+ UNION ALL
+ SELECT comprador, IFNULL(ventas,0)
+ FROM bi.analisis_ventas_comprador_evolution
+ WHERE Periodo = vPreviousPeriod
+ ) sub
+ GROUP BY Comprador;
+ END WHILE;
+*/
+ -- Provincia
+
+ SET vCurrentPeriod = vMinPeriod;
+
+ WHILE vCurrentPeriod < vMaxPeriod
+ DO
+ SELECT MAX(periodo) INTO vPreviousPeriod
+ FROM bi.analisis_ventas_provincia_evolution
+ WHERE periodo < vMaxPeriod;
+
+ SELECT MIN(period) INTO vCurrentPeriod
+ FROM vn2008.time
+ WHERE period > vPreviousPeriod;
+
+ SET vYear = FLOOR(vCurrentPeriod / 100);
+ SET vWeek = vCurrentPeriod - (vYear * 100);
+
+ DELETE FROM bi.analisis_ventas_provincia_evolution
+ WHERE Periodo = vCurrentPeriod;
+
+ REPLACE bi.analisis_ventas_provincia_evolution(provincia, ventas, semana,año, periodo)
+ SELECT Provincia, sum(ventas) AS ventas, vWeek, vYear, vCurrentPeriod
+ FROM (
+ SELECT Provincia, sum(Importe) AS ventas
+ FROM bi.analisis_ventas
+ WHERE vYear = Año
+ AND vWeek = Semana
+ GROUP BY Provincia
+ UNION ALL
+ SELECT Provincia, - sum(Importe) AS ventas
+ FROM bi.analisis_ventas
+ WHERE vYear - 1 = Año
+ AND vWeek = Semana
+ GROUP BY Provincia
+ UNION ALL
+ SELECT provincia, ventas
+ FROM bi.analisis_ventas_provincia_evolution
+ WHERE Periodo = vPreviousPeriod
+ ) sub
+ GROUP BY Provincia;
+ END WHILE;
+
+ -- Vista
+
+ SET vCurrentPeriod = vMinPeriod;
+
+ WHILE vCurrentPeriod < vMaxPeriod
+ DO
+ SELECT MAX(periodo) INTO vPreviousPeriod
+ FROM bi.analisis_ventas_vista_evolution
+ WHERE periodo < vMaxPeriod;
+
+ SELECT MIN(period) INTO vCurrentPeriod
+ FROM vn2008.time
+ WHERE period > vPreviousPeriod;
+
+ SET vYear = FLOOR(vCurrentPeriod / 100);
+ SET vWeek = vCurrentPeriod - (vYear * 100);
+
+ DELETE FROM bi.analisis_ventas_vista_evolution
+ WHERE Periodo = vCurrentPeriod;
+
+ REPLACE bi.analisis_ventas_vista_evolution(vista, ventas, semana,año, periodo)
+ SELECT vista, sum(ventas) AS ventas, vWeek, vYear, vCurrentPeriod
+ FROM (
+ SELECT Vista, sum(Importe) AS ventas
+ FROM bi.analisis_ventas
+ WHERE vYear = Año
+ AND vWeek = Semana
+ GROUP BY Vista
+ UNION ALL
+ SELECT Vista, - sum(Importe) AS ventas
+ FROM bi.analisis_ventas
+ WHERE vYear - 1 = Año
+ AND vWeek = Semana
+ GROUP BY Vista
+ UNION ALL
+ SELECT vista, ventas
+ FROM bi.analisis_ventas_vista_evolution
+ WHERE Periodo = vPreviousPeriod
+ ) sub
+ GROUP BY Vista;
+ END WHILE;
+
+ -- Vendedor
+
+ SET vCurrentPeriod = vMinPeriod;
+
+ WHILE vCurrentPeriod < vMaxPeriod
+ DO
+ SELECT MAX(periodo) INTO vPreviousPeriod
+ FROM bi.analisis_ventas_vendedor_evolution
+ WHERE periodo < vMaxPeriod;
+
+ SELECT MIN(period) INTO vCurrentPeriod
+ FROM vn2008.time
+ WHERE period > vPreviousPeriod;
+
+ SET vYear = FLOOR(vCurrentPeriod / 100);
+ SET vWeek = vCurrentPeriod - (vYear * 100);
+
+ DELETE FROM bi.analisis_ventas_vendedor_evolution
+ WHERE Periodo = vCurrentPeriod;
+
+ REPLACE bi.analisis_ventas_vendedor_evolution(vendedor, ventas, semana,año, periodo)
+ SELECT Comercial AS vendedor, sum(ventas) AS ventas, vWeek, vYear, vCurrentPeriod
+ FROM (
+ SELECT Comercial, sum(Importe) AS ventas
+ from bi.analisis_ventas
+ WHERE vYear = Año
+ AND vWeek = Semana
+ GROUP BY Comercial
+ UNION ALL
+ SELECT Comercial, - sum(Importe) AS ventas
+ from bi.analisis_ventas
+ WHERE vYear - 1 = Año
+ AND vWeek = Semana
+ GROUP BY Comercial
+ UNION ALL
+ SELECT vendedor, ventas
+ FROM bi.analisis_ventas_vendedor_evolution
+ WHERE Periodo = vPreviousPeriod
+ ) sub
+ GROUP BY vendedor;
+ 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 `analisis_ventas_simple` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `analisis_ventas_simple`()
+BEGIN
+
+TRUNCATE bi.analisis_grafico_simple;
+
+INSERT INTO bi.analisis_grafico_simple SELECT * FROM bi.analisis_grafico_ventas;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `analisis_ventas_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 `analisis_ventas_update`()
+BEGIN
+
+ DECLARE vLastMonth DATE;
+
+ SET vLastMonth = util.firstDayOfMonth(TIMESTAMPADD(MONTH, -1, CURDATE()));
+
+ DELETE FROM bi.analisis_ventas
+ WHERE Año > YEAR(vLastMonth)
+ OR (Año = YEAR(vLastMonth) AND Mes >= MONTH(vLastMonth));
+
+ INSERT INTO bi.analisis_ventas
+
+ SELECT
+ `tp`.`Tipo` AS `Familia`,
+ `r`.`reino` AS `Reino`,
+ `tr`.`CodigoTrabajador` AS `Comercial`,
+ `tr2`.`CodigoTrabajador` AS `Comprador`,
+ `p`.`name` AS `Provincia`,
+ `w`.`name` AS `almacen`,
+ `time`.`year` AS `Año`,
+ `time`.`month` AS `Mes`,
+ `time`.`week` AS `Semana`,
+ `v`.`vista` AS `Vista`,
+ `bt`.`importe` AS `Importe`
+ FROM
+ (((((((((`bs`.`ventas` `bt`
+ LEFT JOIN `vn2008`.`Tipos` `tp` ON ((`tp`.`tipo_id` = `bt`.`tipo_id`)))
+ LEFT JOIN `vn2008`.`reinos` `r` ON ((`r`.`id` = `tp`.`reino_id`)))
+ LEFT JOIN `vn2008`.`Clientes` c on c.Id_Cliente = bt.Id_Cliente
+ LEFT JOIN `vn2008`.`Trabajadores` `tr` ON ((`tr`.`Id_Trabajador` = `c`.`Id_Trabajador`)))
+ LEFT JOIN `vn2008`.`Trabajadores` `tr2` ON ((`tr2`.`Id_Trabajador` = `tp`.`Id_Trabajador`)))
+ JOIN vn2008.time on time.date = bt.fecha
+ JOIN vn2008.Movimientos m on m.Id_Movimiento = bt.Id_Movimiento
+ LEFT JOIN `vn2008`.`Tickets` `t` ON ((`t`.`Id_Ticket` = `m`.`Id_Ticket`)))
+ JOIN vn2008.Agencias a on a.Id_Agencia = t.Id_Agencia
+ LEFT JOIN `vn2008`.`Vistas` `v` ON ((`v`.`vista_id` = `a`.`Vista`)))
+ LEFT JOIN `vn2008`.`Consignatarios` `cs` ON ((`cs`.`Id_Consigna` = `t`.`Id_Consigna`)))
+ LEFT JOIN `vn2008`.`province` `p` ON ((`p`.`province_id` = `cs`.`province_id`)))
+ LEFT JOIN `vn2008`.`warehouse` `w` ON ((`w`.`id` = `t`.`warehouse_id`)))
+ WHERE bt.fecha >= vLastMonth AND r.mercancia;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `call_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `call_add`()
+BEGIN
+
+DECLARE datSTART DATETIME DEFAULT '2012-03-01'/*CURDATE()*/;
+-- control
+INSERT INTO vn2008.daily_task_log(consulta) VALUES('bi.call_add');
+
+-- Seleccionamos la ultima fecha introducida
+SELECT MAX(Fecha) INTO datSTART FROM `call`;
+
+
+-- Borramos todas las entradas del dia datSTART por si hubiese registros nuevos
+DELETE FROM `call` WHERE Fecha = datSTART;
+
+INSERT INTO bi.`call`(CodTrabajadorCartera,CodTrabajadorTelefono,dur_in,dur_out,Fecha,`year`,`month`,`week`,`hour`,phone)
+SELECT vn2008.Averiguar_ComercialCliente(pb.Id_Cliente,Fecha) CodTrabajadorCartera,ll.CodigoTrabajador, dur_in,
+ dur_out, ll.Fecha,YEAR(ll.Fecha) `year`, MONTH(ll.Fecha) `month`,WEEK(ll.Fecha,7) `week`, Hora,phone
+FROM
+(
+SELECT Id_Trabajador,CodigoTrabajador, IFNULL(billsec,0) dur_in, 0 dur_out, 1 as Recibidas, NULL as Emitidas, calldate as Fecha,
+ hour(calldate) as Hora,src as phone
+FROM vn2008.Trabajadores T
+INNER JOIN vn2008.cdr C ON C.dstchannel LIKE CONCAT('%', T.extension, '%')
+WHERE calldate >= datSTART AND LENGTH(C.src) >=9 AND disposition = 'ANSWERED' AND duration
+UNION ALL
+SELECT Id_Trabajador,CodigoTrabajador,0 dur_in, IFNULL(billsec,0) dur_out, NULL as Recibidas, 1 as Emitidas, date(calldate), hour(calldate),dst
+FROM vn2008.Trabajadores T
+INNER JOIN vn2008.cdr C ON C.src = T.extension
+WHERE calldate >= datSTART AND LENGTH(C.dst) >=9 AND disposition = 'ANSWERED' AND duration
+) ll
+INNER JOIN vn2008.Permisos USING(Id_Trabajador)
+LEFT JOIN vn2008.v_phonebook pb ON pb.Telefono = ll.phone
+WHERE 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 `claim_ratio_routine` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `claim_ratio_routine`()
+BEGIN
+
+DECLARE vMonthToRefund INT DEFAULT 4;
+
+-- control
+INSERT INTO vn2008.daily_task_log(consulta)
+ VALUES('bi.claim_ratio_routine START');
+
+/*
+* PAK 2015-11-20
+* Se trata de añadir a la tabla Greuges todos los
+* cargos que luego vamos a utilizar para calcular el recobro
+*/
+
+-- descuentos comerciales COD 11
+
+INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario, Importe, Id_Ticket)
+ SELECT Fecha, Id_Cliente, Concat('COD11 : ',Concepte), - round(Cantidad *
+ Preu * (100 - Descuento) / 100 ,2) AS Importe, t.Id_Ticket
+ FROM vn2008.Tickets t
+ JOIN vn2008.Movimientos m ON m.Id_Ticket = t.Id_Ticket
+ WHERE Id_Article = 11
+ AND Concepte NOT LIKE '$%'
+ AND Fecha > '2014-01-01'
+ HAVING nz(Importe) <> 0;
+
+DELETE mc.*
+ FROM vn2008.Movimientos_componentes mc
+ JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento
+ JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket
+ WHERE m.Id_Article = 11
+ AND m.Concepte NOT LIKE '$%'
+ AND t.Fecha > '2017-01-01';
+
+INSERT INTO vn2008.Movimientos_componentes(Id_Movimiento, Id_Componente, Valor)
+ SELECT m.Id_Movimiento, 34, round(m.Preu * (100 - m.Descuento)/100,4)
+ FROM vn2008.Movimientos m
+ JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket
+ WHERE m.Id_Article = 11
+ AND m.Concepte NOT LIKE '$%'
+ AND t.Fecha > '2017-01-01';
+
+UPDATE vn2008.Movimientos m
+ JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket
+ SET Concepte = CONCAT('$ ',Concepte)
+ WHERE Id_Article = 11
+ AND Concepte NOT LIKE '$%'
+ AND Fecha > '2014-01-01';
+
+-- Reclamaciones demasiado sensibles
+
+INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario,
+ Importe, Greuges_type_id,Id_Ticket)
+ SELECT cm.Fecha
+ , cm.Id_Cliente
+ , concat('Claim ',cm.id,' : ', m.Concepte)
+ ,round( -1 * ((sensib -1)/4) * Cantidad *
+ Preu * (100 - Descuento) / 100, 2) AS Reclamaciones
+ , 4
+ , m.Id_Ticket
+ FROM vn2008.Movimientos m
+ JOIN vn2008.cl_act ca USING(Id_Movimiento)
+ JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id
+ WHERE ca.cl_sol_id NOT IN (1,5)
+ AND ca.greuge = 0
+ AND cm.cl_est_id = 3;
+
+ -- Reclamaciones que pasan a Maná
+
+INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario,
+ Importe , Greuges_type_id,Id_Ticket)
+ SELECT cm.Fecha
+ , cm.Id_Cliente
+ , concat('Claim_mana ',cm.id,' : ', m.Concepte)
+ ,round( ((sensib -1)/4) * Cantidad * Preu * (100 - Descuento) / 100, 2)
+ AS Reclamaciones
+ ,3
+ ,m.Id_Ticket
+ FROM vn2008.Movimientos m
+ JOIN vn2008.cl_act ca USING(Id_Movimiento)
+ JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id
+ WHERE ca.cl_sol_id NOT IN (1,5)
+ AND ca.greuge = 0
+ AND cm.cl_est_id = 3
+ AND cm.mana;
+
+ -- Marcamos para no repetir
+UPDATE vn2008.cl_act ca
+ JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id
+ SET greuge = 1
+ WHERE ca.cl_sol_id NOT IN (1,5)
+ AND ca.greuge = 0
+ AND cm.cl_est_id = 3;
+
+
+
+-- Recobros
+
+DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list;
+CREATE TEMPORARY TABLE tmp.ticket_list
+(PRIMARY KEY (Id_Ticket))
+SELECT DISTINCT t.Id_Ticket
+ FROM vn2008.Movimientos_componentes mc
+ JOIN vn2008.Movimientos m ON mc.Id_Movimiento = m.Id_Movimiento
+ JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket
+ JOIN vn2008.Tickets_state ts ON ts.Id_Ticket = t.Id_Ticket
+ JOIN vncontrol.inter i ON i.inter_id = ts.inter_id
+ JOIN vn2008.state s ON s.id = i.state_id
+ WHERE mc.Id_Componente = 17
+ AND mc.greuge = 0
+ AND t.Fecha >= '2016-10-01'
+ AND t.Fecha < CURDATE()
+ AND t.warehouse_id <> 41
+ AND s.alert_level >= 3;
+
+DELETE g.*
+ FROM vn2008.Greuges g
+ JOIN tmp.ticket_list t ON g.Id_Ticket = t.Id_Ticket
+ WHERE Greuges_type_id = 2;
+
+INSERT INTO vn2008.Greuges (Id_Cliente,Comentario,Importe,Fecha,
+ Greuges_type_id, Id_Ticket)
+ SELECT Id_Cliente
+ ,concat('recobro ', m.Id_Ticket), - round(SUM(mc.Valor*Cantidad),2)
+ AS dif
+ ,date(t.Fecha)
+ , 2
+ ,tt.Id_Ticket
+ FROM vn2008.Movimientos m
+ JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket
+ JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.Id_Ticket
+ JOIN vn2008.Movimientos_componentes mc
+ ON mc.Id_Movimiento = m.Id_Movimiento AND mc.Id_Componente = 17
+ GROUP BY t.Id_Ticket
+ HAVING ABS(dif) > 1;
+
+UPDATE vn2008.Movimientos_componentes mc
+ JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento
+ JOIN tmp.ticket_list tt ON tt.Id_Ticket = m.Id_Ticket
+ SET greuge = 1
+ WHERE Id_Componente = 17;
+
+/*
+* Recalculamos la ratio de las reclamaciones, que luego
+* se va a utilizar en el recobro
+*/
+
+DELETE FROM bi.claims_ratio;
+
+REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro)
+ SELECT fm.Id_Cliente, 12 * fm.Consumo, Reclamaciones,
+ round(Reclamaciones / (12*fm.Consumo),4) AS Ratio, 0
+ FROM bi.facturacion_media_anual fm
+ LEFT JOIN(
+ SELECT cm.Id_Cliente, round(sum(-1 * ((sensib -1)/4) *
+ Cantidad * Preu * (100 - Descuento) / 100))
+ AS Reclamaciones
+ FROM vn2008.Movimientos m
+ JOIN vn2008.cl_act ca
+ ON ca.Id_Movimiento = m.Id_Movimiento
+ JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id
+ WHERE ca.cl_sol_id NOT IN (1,5)
+ AND cm.cl_est_id = 3
+ AND cm.Fecha >= TIMESTAMPADD(YEAR, -1, CURDATE())
+ GROUP BY cm.Id_Cliente
+ ) claims ON claims.Id_Cliente = fm.Id_Cliente;
+
+
+-- Calculamos el porcentaje del recobro para añadirlo al precio de venta
+UPDATE bi.claims_ratio cr
+ JOIN (
+ SELECT Id_Cliente, nz(SUM(Importe)) AS Greuge
+ FROM vn2008.Greuges
+ WHERE Fecha <= CURDATE()
+ GROUP BY Id_Cliente
+ ) g ON g.Id_Cliente = cr.Id_Cliente
+ SET recobro = GREATEST(0,round(nz(Greuge) /
+ (nz(Consumo) * vMonthToRefund / 12 ) ,3));
+
+-- control
+INSERT INTO vn2008.daily_task_log(consulta)
+ VALUES('bi.claim_ratio_routine 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` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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`()
+BEGIN
+DECLARE vDateShort DATETIME;
+DECLARE vDateLong DATETIME;
+
+SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE());
+SET vDateLong = TIMESTAMPADD(MONTH, -18,CURDATE());
+
+INSERT INTO bi.dailyTaskLog(state) VALUES('clean START');
+
+DELETE FROM bi.comparativa_clientes WHERE Fecha < vDateLong;
+DELETE FROM bi.Greuge_Evolution WHERE Fecha < vDateShort AND weekday(Fecha) != 1;
+
+INSERT INTO bi.dailyTaskLog(state) 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(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 `comparativa_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `comparativa_add`()
+BEGIN
+ DECLARE lastCOMP INT; # Se trata de una variable para almacenar el ultimo valor del Periodo
+
+ SELECT MAX(Periodo) INTO lastCOMP FROM vn2008.Comparativa;
+ -- Fijaremos las ventas con más de un mes de antiguedad en la tabla Comparativa
+
+ IF lastCOMP < vn2008.vnperiod(CURDATE())- 3 AND vn2008.vnweek(CURDATE()) > 3 THEN
+
+ REPLACE vn2008.Comparativa(Periodo, Id_Article, warehouse_id, Cantidad,price)
+ SELECT tm.period as Periodo, m.Id_Article, t.warehouse_id, sum(m.Cantidad), sum(v.importe)
+ FROM bs.ventas v
+ JOIN vn2008.time tm ON tm.date = v.fecha
+ JOIN vn2008.Movimientos m ON m.Id_Movimiento = v.Id_Movimiento
+ JOIN vn2008.Articles a ON a.Id_Article = m.Id_Article
+ JOIN vn2008.Tipos tp ON tp.tipo_id = a.tipo_id
+ JOIN vn2008.reinos r ON r.id = tp.reino_id
+ JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket
+ WHERE tm.period BETWEEN lastCOMP AND vn2008.vnperiod(CURDATE())- 3
+ AND t.Id_Cliente NOT IN(400,200)
+ AND r.display <> 0
+ AND t.warehouse_id NOT IN (0,13)
+ GROUP BY Id_Article, Periodo, warehouse_id;
+
+
+/*
+ REPLACE vn2008.Comparativa(Periodo, Id_Article, warehouse_id, Cantidad,price)
+ SELECT vn2008.vnperiod(T.Fecha) AS Periodo
+ , Id_Article
+ , warehouse_id
+ , SUM(Cantidad) AS Total
+ , SUM(Cantidad * Preu * (100 - Descuento) / 100) precio
+ FROM vn2008.Movimientos M
+ JOIN vn2008.Tickets T USING (Id_Ticket)
+ JOIN vn2008.Articles A USING (Id_Article)
+ LEFT JOIN vn2008.Tipos ti ON ti.tipo_id = A.tipo_id
+ LEFT JOIN vn2008.reinos r ON r.id = ti.reino_id
+ WHERE T.Fecha BETWEEN TIMESTAMPADD(DAY,-60,CURDATE()) AND TIMESTAMPADD(DAY,-30,CURDATE())
+ AND T.Id_Cliente NOT IN(400,200)
+ AND display <> 0 AND warehouse_id NOT IN (0,13)
+ GROUP BY Id_Article, Periodo, warehouse_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 DROP PROCEDURE IF EXISTS `comparativa_add_manual` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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_add_manual`(IN dat_START DATE, IN dat_END DATE)
+BEGIN
+
+ DECLARE datINI DATETIME;
+ DECLARE datFIN DATETIME;
+
+ -- Seleccionamos la fecha minima/maxima del periodo que vamos a consultar
+ SELECT MIN(`date`) INTO datINI FROM vn2008.`time` WHERE period = vn2008.vnperiod(dat_START);
+ SELECT TIMESTAMP(MAX(`date`),'23:59:59') INTO datFIN FROM vn2008.`time` WHERE period = vn2008.vnperiod(dat_END);
+
+ DELETE FROM vn2008.Comparativa WHERE Periodo BETWEEN vn2008.vnperiod(dat_START) and vn2008.vnperiod(dat_END);
+
+ REPLACE vn2008.Comparativa(Periodo, Id_Article, warehouse_id, Cantidad,price)
+ SELECT tm.period AS Periodo
+ , M.Id_Article
+ , t.warehouse_id
+ , SUM(Cantidad) AS Total
+ , sum(v.importe) AS precio
+ FROM vn2008.Movimientos M
+ JOIN vn2008.Tickets t on t.Id_Ticket = M.Id_Ticket
+ JOIN bs.ventas v on v.Id_Movimiento = M.Id_Movimiento
+ JOIN vn2008.time tm on tm.date = v.fecha
+ JOIN vn2008.Tipos tp on v.tipo_id = tp.tipo_id
+ LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id
+ WHERE v.fecha BETWEEN datINI and datFIN
+ AND r.display <> 0 AND t.warehouse_id NOT IN (0,13)
+ GROUP BY Id_Article, Periodo, t.warehouse_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 `customer_risk_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 `customer_risk_update`(v_customer INT, v_company INT, v_amount DECIMAL(10,2))
+BEGIN
+ IF v_amount IS NOT NULL
+ THEN
+ INSERT INTO bi.customer_risk
+ SET
+ customer_id = v_customer,
+ company_id = v_company,
+ amount = v_amount
+ ON DUPLICATE KEY UPDATE
+ amount = amount + VALUES(amount);
+ 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 `defaultersFromDate` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `defaultersFromDate`(IN vDate DATE)
+BEGIN
+
+SELECT t1.*, c.Cliente, w.workerCode, c.pay_met_id,c.Vencimiento
+FROM (
+-- Filtramos aquellos clientes cuyo saldo se ha incrementado de ayer a hoy
+ select * from(
+ select today.client, today.amount todayAmount, yesterday.amount yesterdayAmount, round(yesterday.amount - today.amount,2) as difference, defaulterSince
+ from
+ (select client, amount, defaulterSince
+ from defaulters
+ where date = vDate and hasChanged) today
+ join
+ (select client, amount
+ from defaulters
+ where date = TIMESTAMPADD(DAY,-1,vDate)) yesterday using(client)
+
+ having today.amount > 0 and difference <> 0
+ ) newDefaulters
+)t1 left join vn2008.Clientes c ON t1.client = c.Id_Cliente
+ left join vn.worker w ON w.id = c.Id_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 DROP PROCEDURE IF EXISTS `defaulting` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `defaulting`(IN vDate DATE)
+BEGIN
+ DECLARE vDone BOOLEAN;
+ DECLARE vClient INT;
+ DECLARE vAmount INT;
+ DECLARE vDateInvoice DATE;
+ DECLARE vAmountInvoice DECIMAL(10,2);
+ DECLARE vDueDay INT;
+ DECLARE vGraceDays INT;
+ DECLARE defaulters CURSOR FOR
+ SELECT client, amount, Vencimiento, graceDays FROM bi.defaulters d
+ JOIN vn2008.Clientes c ON c.Id_Cliente = d.client
+ JOIN vn2008.pay_met pm ON pm.id = c.pay_met_id
+ WHERE hasChanged AND date = vDate;
+
+ DECLARE invoices CURSOR FOR
+ SELECT Fecha, importe FROM vn2008.Facturas f
+ WHERE f.Fecha >= '2016-01-01' AND f.Id_Cliente = vClient ORDER BY f.Fecha DESC;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
+ -- Control
+
+ INSERT INTO vn2008.daily_task_log(consulta) VALUES('defaulting');
+
+ DELETE FROM bi.defaulters WHERE date = vDate;
+
+ INSERT INTO bi.defaulters(client, date, amount)
+ SELECT customer_id, vDate, FLOOR(SUM(amount)) AS amount
+ FROM bi.customerRiskOverdue
+ GROUP BY customer_id;
+
+ -- marcamos si ha cambiado y heredamos la fecha defaulterSince
+ UPDATE bi.defaulters d
+ JOIN (
+ SELECT * FROM(
+ SELECT client, amount , defaulterSince FROM bi.defaulters
+ WHERE date <= TIMESTAMPADD(DAY,-1, vDate)
+ ORDER BY date DESC) t GROUP BY client
+ ) yesterday using(client)
+ SET d.hasChanged = IF(d.amount <> yesterday.amount, 1, 0),
+ d.defaulterSince = yesterday.defaulterSince
+ WHERE d.date = vDate ;
+
+ OPEN defaulters;
+ defaulters: LOOP
+ SET vDone = FALSE;
+ SET vAmount = 0;
+ FETCH defaulters INTO vClient,vAmount, vDueDay, vGraceDays;
+ IF vDone THEN
+ LEAVE defaulters;
+ END IF;
+ OPEN invoices;
+ invoices:LOOP
+
+ FETCH invoices INTO vDateInvoice, vAmountInvoice;
+ IF vDone THEN
+ LEAVE invoices;
+ END IF;
+
+ IF TIMESTAMPADD(DAY, vGraceDays, vn2008.paymentday(vDateInvoice, vDueDay)) <= vDate THEN
+ SET vAmount = vAmount - vAmountInvoice;
+ IF vAmount <= 0 THEN
+ UPDATE defaulters SET defaulterSince = vn2008.paymentday(vDateInvoice, vDueDay)
+ WHERE client = vClient and date = vDate;
+
+ SET vAmount = 0;
+ LEAVE invoices;
+ END IF;
+ END IF;
+ END LOOP;
+ CLOSE invoices;
+ END LOOP;
+ CLOSE defaulters;
+ DELETE FROM bi.defaulting WHERE date = vDate;
+
+ INSERT INTO bi.defaulting(date, amount)
+ SELECT vDate, SUM(amount)
+ FROM bi.defaulters
+ WHERE date = vDate and amount > 0;
+
+ CALL vn.clientFreeze();
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `defaultingkk` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `defaultingkk`(IN vDate DATE)
+BEGIN
+ DECLARE done BIT DEFAULT 0;
+ DECLARE vClient INT;
+ DECLARE vAmount INT;
+ DECLARE vDateInvoice DATE;
+ DECLARE vAmountInvoice DECIMAL(10,2);
+ DECLARE vDueDay INT;
+ DECLARE vGraceDays INT;
+ DECLARE defaulters CURSOR FOR
+ SELECT client, amount, Vencimiento, graceDays FROM bi.defaulters d
+ JOIN vn2008.Clientes c ON c.Id_Cliente = d.client
+ JOIN vn2008.pay_met pm ON pm.id = c.pay_met_id
+ WHERE hasChanged AND date = vDate;
+
+ DECLARE invoices CURSOR FOR
+ SELECT Fecha, importe FROM vn2008.Facturas f
+ WHERE f.Fecha >= '2016-01-01' AND f.Id_Cliente = vClient ORDER BY f.Fecha DESC;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
+ -- Control
+
+ INSERT INTO vn2008.daily_task_log(consulta) VALUES('defaulting');
+
+ DELETE FROM bi.defaulters WHERE date = vDate;
+
+ INSERT INTO bi.defaulters(client, date, amount)
+ SELECT customer_id, vDate, FLOOR(SUM(amount)) AS amount
+ FROM bi.customerRiskOverdue
+ GROUP BY customer_id;
+
+ -- marcamos si ha cambiado y heredamos la fecha defaulterSince
+ UPDATE bi.defaulters d
+ JOIN (
+ SELECT client, amount , defaulterSince FROM bi.defaulters
+ WHERE date = TIMESTAMPADD(DAY,-1, vDate)
+ GROUP BY client
+ ) yesterday using(client)
+ SET d.hasChanged = IF(d.amount <> yesterday.amount, 1, 0),
+ d.defaulterSince = yesterday.defaulterSince
+ WHERE d.date = vDate ;
+
+ OPEN defaulters;
+ defaulters: BEGIN
+ REPEAT
+ FETCH defaulters INTO vClient,vAmount, vDueDay, vGraceDays;
+ OPEN invoices;
+ invoices:BEGIN
+ REPEAT
+
+ FETCH invoices INTO vDateInvoice, vAmountInvoice;
+ IF TIMESTAMPADD(DAY, vGraceDays, vn2008.paymentday(vDateInvoice, vDueDay)) <= vDate THEN
+ SET vAmount = vAmount - vAmountInvoice;
+ IF vAmount < 0 THEN
+ UPDATE defaulters SET defaulterSince = vn2008.paymentday(vDateInvoice, vDueDay)
+ WHERE client = vClient and date = vDate;
+ SET vAmount = 0;
+ LEAVE invoices;
+ END IF;
+ END IF;
+ UNTIL done END REPEAT;
+ END invoices;
+ CLOSE invoices;
+ UNTIL done OR vClient IS NULL END REPEAT;
+ END defaulters;
+ CLOSE defaulters;
+ DELETE FROM bi.defaulting WHERE date = vDate;
+
+ INSERT INTO bi.defaulting(date, amount)
+ SELECT vDate, SUM(amount)
+ FROM bi.defaulters
+ WHERE date = vDate and amount > 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 `defaulting_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 `defaulting_launcher`()
+BEGIN
+
+ CALL bi.defaulting(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 `equaliza` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `equaliza`(IN wh_id INT)
+BEGIN
+
+DECLARE datEQ DATETIME;
+/* JGF 2017-03-20 cuelga el sistema
+
+SELECT `date` INTO datEQ FROM bi.variables WHERE variable = IF(wh_id = 17,'eq_mcf','equalizator');
+
+
+IF TIMEDIFF(now(), datEQ) > '00:05:00' THEN
+
+ UPDATE bi.Equalizator e
+ JOIN
+ (
+ SELECT
+ Vista,
+ sum(1) as pedido,
+ sum(PedidoImpreso) as impreso,
+ sum(t.Factura IS NOT NULL
+ OR t.Etiquetasemitidas
+ OR nz(ticket_id) <> 0) as encajado
+ FROM
+ vn2008.Movimientos
+ JOIN
+ vn2008.Tickets t USING (Id_Ticket)
+ JOIN
+ vn2008.Agencias a ON t.Id_Agencia = a.Id_Agencia
+ JOIN
+ vn2008.Clientes C USING (Id_Cliente)
+ LEFT JOIN
+ (SELECT distinct
+ ticket_id
+ FROM
+ vn2008.expeditions e JOIN vn2008.Tickets t ON t.Id_Ticket = e.ticket_id WHERE Fecha >= curDate()) exp ON ticket_id = Id_Ticket
+ WHERE
+ invoice And Fecha >= curDate()
+ AND t.warehouse_id = wh_id
+ AND fecha < (TIMESTAMPADD(DAY, 1, CURDATE()))
+ GROUP BY Vista) sub using(Vista)
+ SET e.Pedido = sub.pedido, e.Impreso = sub.impreso, e.Encajado = sub.encajado;
+
+ UPDATE bi.variables SET `date`= now() WHERE variable = IF(wh_id = 17,'eq_mcf','equalizator');
+
+
+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 `facturacion_media_anual_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 `facturacion_media_anual_update`()
+BEGIN
+
+-- control
+INSERT INTO vn2008.daily_task_log(consulta) VALUES('bi.facturacion_media_anual_update');
+
+TRUNCATE TABLE bi.facturacion_media_anual;
+
+REPLACE bi.facturacion_media_anual(Id_Cliente, Consumo)
+select Id_Cliente, avg(Consumo)
+from (
+ Select Id_Cliente, YEAR(fecha) year, MONTH(fecha) month, sum(importe) as Consumo
+ from bs.ventas
+ where fecha >= TIMESTAMPADD(YEAR,-1,CURDATE())
+ group by Id_Cliente, year, month
+) vol
+group by 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 `greuge_dif_porte_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `greuge_dif_porte_add`()
+BEGIN
+
+DECLARE datSTART DATETIME DEFAULT TIMESTAMPADD(DAY,-10,CURDATE());
+DECLARE datEND DATETIME DEFAULT TIMESTAMPADD(DAY,-1,CURDATE());
+
+
+DROP TEMPORARY TABLE IF EXISTS tmp.dp;
+
+CREATE TEMPORARY TABLE tmp.dp
+ (PRIMARY KEY (Id_Ticket))
+ ENGINE = MEMORY
+ SELECT
+ t.Id_Ticket,
+ SUM(az.price * IF(
+ e.EsBulto = 71
+ AND ISNULL(e.Id_Article)
+ AND a.Vista = 2,
+ 0.75,
+ 1
+ )
+ ) AS teorico,
+ 00000.00 as practico,
+ 00000.00 as greuge
+ FROM
+ vn2008.Tickets t
+ JOIN vn2008.Clientes cli ON cli.Id_cliente = t.Id_Cliente
+ LEFT JOIN vn2008.expeditions e ON e.ticket_id = t.Id_Ticket
+ JOIN vn2008.Consignatarios c ON c.Id_Consigna = t.Id_Consigna
+ JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia
+ JOIN vn2008.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 vn2008.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 between datSTART AND datEND
+ AND cli.`real`
+ AND t.empresa_id IN (442 , 567)
+ GROUP BY t.Id_Ticket;
+
+DROP TEMPORARY TABLE IF EXISTS tmp.dp_aux;
+
+CREATE TEMPORARY TABLE tmp.dp_aux
+ (PRIMARY KEY (Id_Ticket))
+ ENGINE = MEMORY
+ SELECT t.Id_Ticket, sum(freight) as porte
+ FROM tmp.dp
+ JOIN vn2008.Tickets t ON t.Id_Ticket = dp.Id_Ticket
+ JOIN vn2008.Rutas r on r.Id_Ruta = t.Id_Ruta
+ JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia
+ JOIN (
+ SELECT
+ M.Id_Ticket,
+ (M.Cantidad * r.cm3 / cb.Volumen ) * az.price AS freight
+ FROM
+ vn2008.Movimientos M
+ JOIN vn2008.Tickets t ON t.Id_Ticket = M.Id_Ticket
+ JOIN vn2008.Consignatarios c ON c.Id_Consigna = t.Id_Consigna
+ JOIN bi.rotacion r ON M.Id_Article = r.Id_Article
+ AND t.warehouse_id = r.warehouse_id
+ JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia
+ JOIN vn2008.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 vn2008.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
+ JOIN vn2008.Cubos cb ON Id_Cubo = 94
+ WHERE t.Fecha between datSTART AND datEND
+ ) vmv ON vmv.Id_Ticket = t.Id_Ticket
+ WHERE a.is_volumetric
+ GROUP BY t.Id_Ticket;
+
+ UPDATE tmp.dp
+ JOIN tmp.dp_aux using(Id_Ticket)
+ SET teorico = porte;
+
+DROP TEMPORARY TABLE IF EXISTS tmp.dp_aux;
+
+CREATE TEMPORARY TABLE tmp.dp_aux
+ (PRIMARY KEY (Id_Ticket))
+ ENGINE = MEMORY
+ SELECT dp.Id_Ticket, sum(Cantidad * Valor) as valor
+ FROM tmp.dp
+ JOIN vn2008.Movimientos m using(Id_Ticket)
+ JOIN vn2008.Movimientos_componentes mc using(Id_Movimiento)
+ WHERE mc.Id_Componente = 15
+ GROUP BY m.Id_Ticket;
+
+UPDATE tmp.dp
+ JOIN tmp.dp_aux using(Id_Ticket)
+ SET practico = valor;
+
+DROP TEMPORARY TABLE tmp.dp_aux;
+
+CREATE TEMPORARY TABLE tmp.dp_aux
+ (PRIMARY KEY (Id_Ticket))
+ ENGINE = MEMORY
+ SELECT dp.Id_Ticket, sum(Importe) Importe
+ FROM tmp.dp
+ JOIN vn2008.Greuges g using(Id_Ticket)
+ WHERE Greuges_type_id = 1
+ GROUP BY Id_Ticket;
+
+UPDATE tmp.dp
+ JOIN tmp.dp_aux using(Id_Ticket)
+ SET greuge = Importe;
+
+
+INSERT INTO vn2008.Greuges (Id_Cliente,Comentario,Importe,Fecha, Greuges_type_id, Id_Ticket)
+SELECT t.Id_Cliente
+ , concat('dif_porte ', dp.Id_Ticket)
+ , round(teorico - practico - greuge,2) as Importe
+ , date(t.Fecha)
+ , 1
+ ,t.Id_Ticket
+ FROM tmp.dp
+ JOIN vn2008.Tickets t on dp.Id_Ticket = t.Id_Ticket
+ WHERE ABS(teorico - practico - greuge) > 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 `Greuge_Evolution_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `Greuge_Evolution_Add`()
+BEGIN
+
+ /*
+
+ Inserta en la tabla Greuge_Evolution el saldo acumulado de cada cliente, así como las ventas acumuladas en los ultimos 365 dias
+ , para poder controlar su evolucion
+
+ */
+
+ DECLARE datFEC DATE;
+ DECLARE datFEC_TOMORROW DATE;
+ DECLARE datFEC_LASTYEAR DATE;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN
+
+ GET DIAGNOSTICS CONDITION 2 @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+ SELECT CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'));
+ INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('jgallego@verdnatura.es', 'Greuge_Evolution_Add' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')));
+ INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('pako@verdnatura.es', 'Greuge_Evolution_Add' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')));
+
+ END;
+
+ SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
+
+ INSERT INTO vn2008.daily_task_log(consulta) VALUES('Greuge Evolution Add START');
+
+ SELECT TIMESTAMPADD(DAY,1,MAX(Fecha)),
+ TIMESTAMPADD(DAY,2,MAX(Fecha))
+ INTO datFEC,
+ datFEC_TOMORROW
+ FROM bi.Greuge_Evolution;
+
+ SET datFEC_LASTYEAR = TIMESTAMPADD(YEAR,-1,datFEC);
+
+ DELETE FROM bi.Greuge_Evolution WHERE Fecha >= datFEC;
+
+ DROP TEMPORARY TABLE IF EXISTS maxInvoice;
+
+ CREATE TEMPORARY TABLE maxInvoice
+ (PRIMARY KEY (Id_Cliente))
+ ENGINE = MEMORY
+ SELECT DISTINCT Id_Cliente, max(Fecha) as maxFecha
+ FROM vn2008.Facturas
+ GROUP BY Id_Cliente
+ HAVING maxFecha < timestampadd(month,-2,datFEC);
+
+ INSERT INTO vn2008.daily_task_log(consulta) VALUES('Greuge Evolution Add MIDDLE');
+
+ WHILE datFEC < CURDATE() DO
+
+ REPLACE bi.Greuge_Evolution(Id_Cliente, Fecha, Greuge, Ventas)
+
+ SELECT Id_Cliente, datFEC as Fecha, Greuge, Ventas
+
+ FROM
+
+ (
+ SELECT Id_Cliente, sum(Importe) as Greuge
+ FROM vn2008.Greuges
+ where Fecha <= datFEC
+ group by Id_Cliente
+
+ ) sub
+
+ RIGHT JOIN
+
+ (
+
+ SELECT Id_Cliente, sum(Ventas) as Ventas
+ FROM
+ (
+
+ SELECT Id_Cliente, IF (fecha != datFEC, -1,1) * (importe + recargo) as Ventas
+ FROM bs.ventas
+ WHERE fecha = datFEC or fecha = datFEC_LASTYEAR
+
+ UNION ALL
+
+ SELECT Id_Cliente, Ventas
+ FROM bi.Greuge_Evolution
+ WHERE Fecha = TIMESTAMPADD(DAY, -1, datFEC)
+
+ ) sub
+ group by Id_Cliente
+
+ ) v using(Id_Cliente)
+ ;
+
+
+ -- Ahora calcularemos el greuge muerto
+
+ --
+ UPDATE bi.Greuge_Evolution ge
+ JOIN maxInvoice m using(Id_Cliente)
+ SET FOSIL = GREUGE
+ WHERE m.maxFecha < TIMESTAMPADD(MONTH,-2,ge.Fecha);
+
+
+ -- Recobro
+
+ UPDATE bi.Greuge_Evolution ge
+ JOIN (
+ SELECT cs.Id_Cliente, sum(Valor * Cantidad) as Importe
+ FROM vn2008.Tickets t
+ JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna
+ JOIN vn2008.Movimientos m on m.Id_Ticket = t.Id_Ticket
+ JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento
+ WHERE t.Fecha >= datFEC
+ AND t.Fecha < datFEC_TOMORROW
+ AND mc.Id_Componente = 17 -- Recobro
+ GROUP BY cs.Id_Cliente
+ ) sub using(Id_Cliente)
+ SET Recobro = Importe
+ WHERE ge.Fecha = datFEC;
+
+ INSERT INTO vn2008.daily_task_log(consulta) VALUES(CONCAT('Greuge Evolution ',datFEC));
+
+ SET datFEC = datFEC_TOMORROW;
+ SET datFEC_TOMORROW = TIMESTAMPADD(DAY,1,datFEC_TOMORROW);
+ SET datFEC_LASTYEAR = TIMESTAMPADD(YEAR,-1,datFEC);
+
+
+ END WHILE;
+
+ DROP TEMPORARY TABLE IF EXISTS maxInvoice;
+
+ INSERT INTO vn2008.daily_task_log(consulta) VALUES('Greuge Evolution Add 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 `last_buy_id_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `last_buy_id_add`()
+BEGIN
+
+-- control
+-- INSERT INTO vn2008.daily_task_log(consulta) VALUES('bi.last_buy_id_add');
+
+-- DELETE FROM bi.Last_buy_id;
+TRUNCATE TABLE bi.Last_buy_id;
+
+
+-- Primero metemos las del futuro, por si no hay en el presente
+
+INSERT INTO bi.Last_buy_id SELECT * FROM
+ (SELECT
+ Id_Article, Id_Compra, warehouse_id
+ FROM
+ vn2008.Compres c
+ JOIN vn2008.Entradas e USING (Id_Entrada)
+ JOIN vn2008.travel tr ON tr.id = e.travel_id
+ WHERE
+ Novincular = FALSE AND tarifa2 > 0 AND NOT Redada
+ AND landing > curdate()
+ ORDER BY landing DESC) t1
+GROUP BY Id_Article , warehouse_id;
+
+-- Ahora el presente machaca al futuro
+
+REPLACE bi.Last_buy_id SELECT * FROM
+ (SELECT
+ Id_Article, Id_Compra, warehouse_id
+ FROM
+ vn2008.Compres c
+ JOIN vn2008.Entradas e USING (Id_Entrada)
+ JOIN vn2008.travel tr ON tr.id = e.travel_id
+ WHERE
+ Novincular = FALSE AND tarifa2 > 0 AND NOT Redada
+ AND landing BETWEEN vn2008.date_inv() AND curdate()
+ ORDER BY landing DESC) t1
+GROUP BY Id_Article , warehouse_id;
+
+ TRUNCATE TABLE bi.Last_buy_idBackUp;
+ INSERT INTO bi.Last_buy_idBackUp
+ SELECT * FROM Last_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 `margenes` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `margenes`()
+BEGIN
+
+TRUNCATE TABLE bi.margenes;
+
+INSERT INTO bi.margenes
+SELECT Id_Article, Cantidad as Unidades, Cantidad * round(nz(Costefijo) + nz(Embalajefijo) + nz(Comisionfija) + nz(Portefijo),3) as Coste , w.name as almacen, month(landing) as Mes, year(landing) as Year, 0 as Venta
+FROM vn2008.Compres C
+JOIN vn2008.Entradas E using(Id_Entrada)
+JOIN vn2008.travel tr on tr.id = travel_id
+JOIN vn2008.warehouse w on w.id = tr.warehouse_id
+LEFT JOIN vn2008.Articles A using(Id_Article)
+JOIN vn2008.Tipos TP using(tipo_id)
+WHERE landing between '2013-01-01' and ' 2013-12-31'
+AND E.Id_Proveedor <> 4
+AND not redada
+AND not inventario
+union all
+SELECT Id_Article, Cantidad as Unidades, 0 as Coste , w.name, month(Fecha) as Mes, year(Fecha) as Year, Cantidad * round(Preu * (100 - M.Descuento) / 100,2) as Venta
+FROM vn2008.Movimientos M
+JOIN vn2008.Articles A using(Id_Article)
+JOIN vn2008.Tipos TP using(tipo_id)
+JOIN vn2008.Tickets T using(Id_Ticket)
+JOIN vn2008.Clientes C using(Id_Cliente)
+JOIN vn2008.warehouse w on w.id = warehouse_id
+WHERE Fecha between '2013-01-01' and ' 2013-12-31'
+AND (Id_Cliente = 31 or invoice)
+AND Id_Cliente NOT IN (2066,2067,2068);
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `nightly_tasks` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `nightly_tasks`()
+BEGIN
+
+call bi.analisis_ventas_evolution_add;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `nigthlyAnalisisVentas` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `nigthlyAnalisisVentas`()
+BEGIN
+
+ INSERT INTO vn2008.daily_task_log(consulta) VALUES('analisis ventas START');
+
+ CALL bi.analisis_ventas_update;
+ CALL bi.analisis_ventas_simple;
+ CALL bi.analisis_ventas_evolution_add;
+
+ INSERT INTO vn2008.daily_task_log(consulta) VALUES('analisis ventas 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 `partitioning` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `partitioning`(IN intyear INT)
+BEGIN
+
+ DECLARE v_sql TEXT;
+ DECLARE strSquemaName VARCHAR(10);
+ DECLARE strTableName VARCHAR(20);
+ DECLARE strFieldName VARCHAR(20);
+ DECLARE strDateField VARCHAR(20);
+ DECLARE strTableDependingOn VARCHAR(20);
+ DECLARE strFieldDependingOn VARCHAR(20);
+ DECLARE done BIT DEFAULT 0;
+ DECLARE strCacheSchema VARCHAR(5);
+ DECLARE dat_start,dat_end DATE;
+ DECLARE cur1 CURSOR FOR
+ SELECT `schema_name`,`table_name` FROM `cache`.partitioning_information ORDER BY execution_order;
+ DECLARE cur2 CURSOR FOR
+ SELECT `schema_name`,`table_name`,`date_field` FROM `cache`.partitioning_information WHERE date_field > '' ORDER BY execution_order;
+ DECLARE cur3 CURSOR FOR
+ SELECT `schema_name`,`table_name`,`table_depending` FROM `cache`.partitioning_information WHERE table_depending > '' ORDER BY execution_order;
+ DECLARE cur4 CURSOR FOR
+ SELECT `schema_name`,`table_name`,`table_depending` FROM `cache`.partitioning_information WHERE table_depending > '' ORDER BY execution_order DESC;
+ DECLARE cur5 CURSOR FOR
+ SELECT `schema_name`,`table_name`,`date_field` FROM `cache`.partitioning_information WHERE date_field > '' ORDER BY execution_order DESC;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
+
+ SET FOREIGN_KEY_CHECKS=0;
+ IF LENGTH(intyear) <> 4 THEN
+ CALL el_año_debe_contener_4_caracteres_yyyy();
+ END IF;
+ SET dat_start = STR_TO_DATE(CONCAT('01,01,',intyear),'%d,%m,%Y');
+ SET dat_end = STR_TO_DATE(CONCAT('31,12,',intyear),'%d,%m,%Y');
+ SET strCacheSchema = CONCAT('vn_',right(intyear,2));
+ SET v_sql = sql_printf ('CREATE SCHEMA IF NOT EXISTS %t',strCacheSchema);
+ CALL util.exec (v_sql);
+
+ -- Insertamos en las tablas del cur1
+ OPEN cur1;
+ FETCH cur1 INTO strSquemaName,strTableName;
+ WHILE NOT done DO
+ SET v_sql = sql_printf ('CREATE TABLE IF NOT EXISTS %t.%t LIKE %t.%t',
+ strCacheSchema,
+ strTableName,
+ strSquemaName,
+ strTableName);
+
+ CALL util.exec (v_sql);
+
+ FETCH cur1 INTO strSquemaName,strTableName;
+
+ END WHILE;
+ CLOSE cur1;
+
+ -- Insertamos en las tablas del cur2
+ OPEN cur2;
+ FETCH cur2 INTO strSquemaName,strTableName,strDateField;
+ WHILE NOT done DO
+ SET v_sql = sql_printf ('REPLACE INTO %t.%t SELECT * FROM %t.%t WHERE %t BETWEEN %v AND %v',
+ strCacheSchema,
+ strTableName,
+ strSquemaName,
+ strTableName,
+ strDateField,
+ dat_start,
+ dat_end);
+
+ SELECT v_sql;
+ CALL util.exec (v_sql);
+
+ FETCH cur2 INTO strSquemaName,strTableName,strDateField;
+
+ END WHILE;
+ CLOSE cur2;
+
+ -- Insertamos en las tablas del cur3
+ OPEN cur3;
+ SET done = 0;
+ FETCH cur3 INTO strSquemaName,strTableName,strTableDependingOn;
+ WHILE NOT done DO
+
+
+ -- Torna la columna per la qual vincular amb el seu pare
+ SELECT kcu.column_name INTO strFieldName
+ FROM information_schema.key_column_usage kcu
+ WHERE table_schema = CONVERT(strSquemaName USING utf8) COLLATE utf8_general_ci
+ AND REFERENCED_TABLE_NAME = CONVERT(strTableDependingOn USING utf8) COLLATE utf8_general_ci
+ AND table_name = CONVERT(strTableName USING utf8) COLLATE utf8_general_ci;
+
+ -- Torna la columna per la qual vincular amb el seu fill
+ SELECT kcu.column_name INTO strFieldDependingOn
+ FROM information_schema.key_column_usage kcu
+ WHERE table_schema = CONVERT(strSquemaName USING utf8) COLLATE utf8_general_ci -- FIX mirar l'esquema del pare
+ AND constraint_name = 'PRIMARY'
+ AND table_name = CONVERT(strTableDependingOn USING utf8) COLLATE utf8_general_ci;
+
+ SET v_sql = sql_printf ('REPLACE INTO %t.%t SELECT a.* FROM %t.%t a JOIN %t.%t b ON a.%t = b.%t',
+ strCacheSchema,
+ strTableName,
+ strSquemaName,
+ strTableName,
+ strCacheSchema,
+ strTableDependingOn,
+ strFieldName,
+ strFieldDependingOn);
+ select v_sql;
+ CALL util.exec (v_sql);
+
+ FETCH cur3 INTO strSquemaName,strTableName,strTableDependingOn;
+ END WHILE;
+
+ CLOSE cur3;
+
+ -- Borramos en las tablas del cur4 que es igual que el dos pero en sentido descendente
+ -- para evitar errores con las foreign key
+ OPEN cur4;
+ SET done = 0;
+ FETCH cur4 INTO strSquemaName,strTableName,strTableDependingOn;
+ WHILE NOT done DO
+
+
+ -- Torna la columna per la qual vincular amb el seu pare
+ SELECT kcu.column_name INTO strFieldName
+ FROM information_schema.key_column_usage kcu
+ WHERE table_schema = CONVERT(strSquemaName USING utf8) COLLATE utf8_general_ci
+ AND REFERENCED_TABLE_NAME = CONVERT(strTableDependingOn USING utf8) COLLATE utf8_general_ci
+ AND table_name = CONVERT(strTableName USING utf8) COLLATE utf8_general_ci;
+
+ -- Torna la columna per la qual vincular amb el seu fill
+ SELECT kcu.column_name INTO strFieldDependingOn
+ FROM information_schema.key_column_usage kcu
+ WHERE table_schema = CONVERT(strSquemaName USING utf8) COLLATE utf8_general_ci
+ AND constraint_name = 'PRIMARY'
+ AND table_name = CONVERT(strTableDependingOn USING utf8) COLLATE utf8_general_ci;
+
+ SELECT v_sql;
+ SET v_sql = sql_printf ('DELETE a.* FROM %t.%t a JOIN %t.%t b ON a.%t = b.%t',
+ strSquemaName,
+ strTableName,
+ strCacheSchema,
+ strTableDependingOn,
+ strFieldName,
+ strFieldDependingOn);
+ CALL util.exec (v_sql);
+
+ FETCH cur4 INTO strSquemaName,strTableName,strTableDependingOn;
+ END WHILE;
+
+ CLOSE cur4;
+
+ -- Borramos en las tablas del cur5
+ OPEN cur5;
+ SET done = 0;
+ FETCH cur5 INTO strSquemaName,strTableName,strDateField;
+ WHILE NOT done DO
+
+ SET v_sql = sql_printf ('DELETE FROM %t WHERE %t BETWEEN %v AND %v',
+ strTableName,
+ strDateField,
+ dat_start,
+ dat_end);
+ CALL util.exec (v_sql);
+
+ FETCH cur5 INTO strSquemaName,strTableName,strDateField;
+
+ END WHILE;
+ CLOSE cur5;
+ SET FOREIGN_KEY_CHECKS=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 `primer_pedido_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `primer_pedido_add`()
+BEGIN
+ INSERT IGNORE INTO bi.primer_pedido(Id_Ticket, Id_Cliente, month, year, total)
+ SELECT *
+ FROM
+ (SELECT
+ `m`.`Id_Ticket` ,
+ `v`.`Id_Cliente` ,
+ `t`.`month`,
+ `t`.`year`,
+ v.importe + v.recargo as total
+ FROM
+ bs.ventas v
+ JOIN
+ vn2008.Movimientos m on m.Id_Movimiento = v.Id_Movimiento
+ JOIN
+ vn2008.time t on t.date = v.fecha
+ WHERE
+ fecha > CURDATE() + INTERVAL -(1) YEAR
+ ORDER BY fecha) `s`
+ GROUP BY `s`.`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 `regularidad` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `regularidad`()
+BEGIN
+
+select Id_Cliente, Meses, IF(Antiguedad = 13,12,Antiguedad) , Meses / IF(Antiguedad = 13,12,Antiguedad) as Regularidad from (
+SELECT Id_Cliente, count(*) as Meses, FLOOR(DATEDIFF('2012-07-31', IF(Created < '2011-08-01','2011-08-01', Created)) / 30) +1 as Antiguedad from
+(
+
+SELECT DISTINCT Id_Cliente, Periodo(Fecha) as periodo from Facturas
+where Fecha between '2011-08-01' AND '2012-07-31'
+
+) sub
+
+join Clientes using(Id_Cliente)
+where Created <= '2012-07-31'
+
+group by Id_Cliente
+having Antiguedad > 0
+
+) sub44
+order by Antiguedad ;
+
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `rotacion_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 `rotacion_update`()
+BEGIN
+
+-- control
+INSERT INTO vn2008.daily_task_log(consulta) VALUES('bi.rotation_update');
+
+-- Sólo hace la consulta gorda los sábados de madrugada. Necesita casi dos horas.
+
+ call rotacion_update_manual(1, 999999, TIMESTAMPADD(WEEK,-1,CURDATE()), 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 `rotacion_update_manual` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `rotacion_update_manual`(IN intART_DESDE INT, IN intART_HASTA INT, IN datSTART DATE, IN datEND DATE)
+BEGIN
+
+
+DECLARE intLAPSO INT DEFAULT DATEDIFF(datEND,datSTART );
+
+
+
+
+ REPLACE bi.rotacion(Id_Article,warehouse_id,total,rotacion)
+ SELECT Id_Article, warehouse_id, Total, round((sum(Saldo_Ponderado)/Total),2) as rotacion -- round(avg(Saldo_Ponderado) / (Total / intLAPSO),1) as Rotacion
+ FROM
+ (
+ SELECT Id_Article, warehouse_id,
+ @intervalo:= IF(warehouse_id = @wh AND Id_Article = @art , DATEDIFF(Fecha, @fec),1) as Dias,
+ IF(warehouse_id = @wh AND Id_Article = @art , IF(@sd < 0,0,@sd) * @intervalo, IF(Unidades<0,0,Unidades)) as Saldo_Ponderado,
+ IF(warehouse_id = @wh AND Id_Article = @art , @sd:= @sd + Unidades, @sd:= Unidades) as Saldo
+
+ , @fec:= Fecha, @art:= Id_Article, @wh:= warehouse_id
+ FROM
+ (
+ SELECT Id_Article, landing as Fecha, sum(Cantidad) as Unidades, warehouse_id, @fec:= datSTART, @art := 0, @d := 0, @sd:= 0, @wh := 0, @intervalo := 0
+ FROM
+ (
+ SELECT Id_Article, landing, Cantidad, warehouse_id
+ FROM vn2008.Compres C
+ JOIN vn2008.Entradas E using(Id_Entrada)
+ JOIN vn2008.Articles A using(Id_Article)
+ JOIN vn2008.Tipos tp ON tp.tipo_id = A.tipo_id
+ LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id
+ JOIN vn2008.travel tr on tr.id = travel_id
+ JOIN vn2008.warehouse w on w.id = tr.warehouse_id
+ WHERE landing between datSTART and datEND
+ AND Id_Article between intART_DESDE and intART_HASTA
+ AND Id_Proveedor <> 4
+ AND r.display <> 0
+ AND NOT E.Inventario
+ AND NOT fuente
+ AND NOT redada
+ UNION ALL
+ SELECT Id_Article, shipment, -Cantidad, warehouse_id_out
+ FROM vn2008.Compres C
+ JOIN vn2008.Entradas E using(Id_Entrada)
+ JOIN vn2008.Articles A using(Id_Article)
+ JOIN vn2008.Tipos tp ON tp.tipo_id = A.tipo_id
+ LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id
+ JOIN vn2008.travel tr on tr.id = travel_id
+ JOIN vn2008.warehouse w on w.id = tr.warehouse_id_out
+ WHERE shipment between datSTART and datEND
+ AND Id_Article between intART_DESDE and intART_HASTA
+ AND Id_Proveedor <> 4
+ AND r.display <> 0
+ AND NOT fuente
+ AND NOT E.Inventario
+ AND NOT redada
+ UNION ALL
+ SELECT Id_Article, date(Fecha), -Cantidad, warehouse_id
+ FROM vn2008.Movimientos M
+ JOIN vn2008.Articles A using(Id_Article)
+ JOIN vn2008.Tipos tp ON tp.tipo_id = A.tipo_id
+ LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id
+ JOIN vn2008.Tickets t using(Id_Ticket)
+ JOIN vn2008.warehouse w on w.id = t.warehouse_id
+ WHERE Fecha between datSTART and datEND
+ AND r.display <> 0
+ AND NOT fuente
+ AND Id_Article between intART_DESDE and intART_HASTA
+ AND Id_Cliente NOT IN (2066,2067,2068)
+ ) sub
+ GROUP BY Id_Article, warehouse_id, Fecha
+ ) sub2
+ ) sub4
+ JOIN
+ (
+ SELECT Id_Article, sum(Cantidad) as Total, warehouse_id
+ FROM vn2008.Compres C
+ JOIN vn2008.Entradas E using(Id_Entrada)
+ JOIN vn2008.Articles A using(Id_Article)
+ JOIN vn2008.Tipos tp ON tp.tipo_id = A.tipo_id
+ LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id
+ JOIN vn2008.travel tr on tr.id = travel_id
+ JOIN vn2008.warehouse w on w.id = tr.warehouse_id
+ WHERE landing between datSTART and datEND
+ AND Id_Article between intART_DESDE and intART_HASTA
+ AND Id_Proveedor <> 4
+ AND NOT E.Inventario
+ AND r.display <> 0
+ AND NOT redada
+ AND NOT fuente
+ GROUP BY Id_Article, warehouse_id
+ ) sub3 using(Id_Article, warehouse_id)
+
+ GROUP BY Id_Article, warehouse_id;
+
+
+
+ CALL vn2008.item_last_buy_(NULL,datSTART);
+
+ -- Añadimos el volumen por unidad de venta
+ update bi.rotacion r
+ JOIN vn2008.t_item_last_buy b ON r.Id_Article = b.item_id AND r.warehouse_id = b.warehouse_id
+ join vn2008.Compres ON Id_Compra = b.buy_id
+ set cm3 = vn2008.cm3_2(Id_Cubo, r.Id_Article) / Packing
+ where r.Id_Article between intART_DESDE and intART_HASTA;
+
+-- Añadimos el coste de almacenamiento y manipulacion
+UPDATE bi.rotacion
+JOIN (
+ SELECT warehouse_id, sum(total*rotacion*cm3) as Operacion
+ FROM bi.rotacion
+ WHERE Id_Article between intART_DESDE and intART_HASTA
+ GROUP BY warehouse_id
+ ) sub using(warehouse_id)
+
+JOIN (
+ SELECT warehouse_id, sum(Valor) as Coste_Auxiliar
+ FROM bi.tarifa_warehouse
+ WHERE Id_Premisa = 1
+ GROUP BY warehouse_id
+ ) sub2 using(warehouse_id)
+
+JOIN (
+ SELECT warehouse_id, sum(Valor) as Coste_Operativo
+ FROM bi.tarifa_warehouse
+ WHERE Id_Premisa IN (2,3)
+ GROUP BY warehouse_id
+ ) sub3 using(warehouse_id)
+
+JOIN (
+ SELECT warehouse_id, sum(Valor) as Coste_Manipulacion
+ FROM bi.tarifa_warehouse
+ WHERE Id_Premisa = 4
+ GROUP BY warehouse_id
+ ) sub4 using(warehouse_id)
+
+SET auxiliar = if(rotacion < 0,0,round(rotacion *cm3 * Coste_Auxiliar / Operacion,4))
+ ,almacenaje = if(rotacion < 0,0,round(rotacion *cm3 * Coste_Operativo / Operacion,4))
+ , manipulacion = if(rotacion < 0,0,round(rotacion *cm3 * Coste_Manipulacion / Operacion,4))
+ WHERE Id_Article between intART_DESDE and intART_HASTA;
+
+
+-- Añadimos todos los productos de los que no tenemos histórico, con la media de su familia como valor por defecto
+
+INSERT INTO bi.rotacion(Id_Article, warehouse_id, rotacion, cm3, almacenaje, manipulacion, auxiliar, mermas)
+SELECT a.Id_Article, warehouse_id, rotacion_m, cm3_m, alm_m, man_m, aux_m, merm_m
+FROM vn2008.Articles a
+JOIN (SELECT tipo_id, warehouse_id, Id_Tipo, avg(rotacion) rotacion_m, avg(cm3) cm3_m, avg(almacenaje) alm_m, avg(manipulacion) man_m
+ , avg(auxiliar) aux_m, avg(mermas) merm_m
+ from bi.rotacion
+ join vn2008.Articles a using(Id_Article)
+ join vn2008.Tipos tp using(tipo_id)
+ group by tipo_id, warehouse_id) sub using(tipo_id)
+
+WHERE a.Id_Article between intART_DESDE and intART_HASTA
+ON DUPLICATE KEY UPDATE rotacion = rotacion;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `rotacion_update_manual_PCA` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `rotacion_update_manual_PCA`(IN datSTART DATE, IN datEND DATE)
+BEGIN
+
+
+DECLARE intLAPSO INT DEFAULT DATEDIFF(datEND,datSTART );
+DECLARE intART_DESDE BIGINT DEFAULT 1;
+DECLARE intART_HASTA BIGINT DEFAULT 100;
+
+WHILE intART_HASTA < 999999 DO
+
+ IF intART_HASTA MOD 1000 = 0 THEN
+
+ SELECT intART_HASTA;
+
+ END IF;
+
+ REPLACE bi.rotacion(Id_Article,warehouse_id,total,rotacion)
+ SELECT Id_Article, warehouse_id, Total, round((sum(Saldo_Ponderado)/Total),2) as rotacion -- round(avg(Saldo_Ponderado) / (Total / intLAPSO),1) as Rotacion
+ FROM
+ (
+ SELECT Id_Article, warehouse_id,
+ @intervalo:= IF(warehouse_id = @wh AND Id_Article = @art , DATEDIFF(Fecha, @fec),1) as Dias,
+ IF(warehouse_id = @wh AND Id_Article = @art , IF(@sd < 0,0,@sd) * @intervalo, IF(Unidades<0,0,Unidades)) as Saldo_Ponderado,
+ IF(warehouse_id = @wh AND Id_Article = @art , @sd:= @sd + Unidades, @sd:= Unidades) as Saldo
+
+ , @fec:= Fecha, @art:= Id_Article, @wh:= warehouse_id
+ FROM
+ (
+ SELECT Id_Article, landing as Fecha, sum(Cantidad) as Unidades, warehouse_id, @fec:= datSTART, @art := 0, @d := 0, @sd:= 0, @wh := 0, @intervalo := 0
+ FROM
+ (
+ SELECT Id_Article, landing, Cantidad, warehouse_id
+ FROM vn2008.Compres C
+ JOIN vn2008.Entradas E using(Id_Entrada)
+ JOIN vn2008.Articles A using(Id_Article)
+ JOIN vn2008.Tipos using(tipo_id)
+ JOIN vn2008.travel tr on tr.id = travel_id
+ JOIN vn2008.warehouse w on w.id = tr.warehouse_id
+ WHERE landing between datSTART and datEND
+ AND warehouse_id = 44
+ AND Id_Article between intART_DESDE and intART_HASTA
+ AND Id_Proveedor <> 4
+ AND reino_id IN (3,4)
+ AND NOT E.Inventario
+ AND NOT fuente
+ AND NOT redada
+ UNION ALL
+ SELECT Id_Article, shipment, -Cantidad, warehouse_id_out
+ FROM vn2008.Compres C
+ JOIN vn2008.Entradas E using(Id_Entrada)
+ JOIN vn2008.Articles A using(Id_Article)
+ JOIN vn2008.Tipos using(tipo_id)
+ JOIN vn2008.travel tr on tr.id = travel_id
+ JOIN vn2008.warehouse w on w.id = tr.warehouse_id_out
+ WHERE shipment between datSTART and datEND
+ AND warehouse_id_out = 44
+ AND Id_Article between intART_DESDE and intART_HASTA
+ AND Id_Proveedor <> 4
+ AND reino_id IN (3,4)
+ AND NOT fuente
+ AND NOT E.Inventario
+ AND NOT redada
+ UNION ALL
+ SELECT Id_Article, date(Fecha), -Cantidad, warehouse_id
+ FROM vn2008.Movimientos M
+ JOIN vn2008.Articles A using(Id_Article)
+ JOIN vn2008.Tipos using(tipo_id)
+ JOIN vn2008.Tickets t using(Id_Ticket)
+ JOIN vn2008.warehouse w on w.id = t.warehouse_id
+ WHERE Fecha between datSTART and datEND
+ AND t.warehouse_id = 44
+ AND reino_id IN (3,4)
+ AND NOT fuente
+ AND Id_Article between intART_DESDE and intART_HASTA
+ AND Id_Cliente NOT IN (2066,2067,2068)
+ ) sub
+ GROUP BY Id_Article, warehouse_id, Fecha
+ ) sub2
+ ) sub4
+ JOIN
+ (
+ SELECT Id_Article, sum(Cantidad) as Total, warehouse_id
+ FROM vn2008.Compres C
+ JOIN vn2008.Entradas E using(Id_Entrada)
+ JOIN vn2008.Articles A using(Id_Article)
+ JOIN vn2008.Tipos using(tipo_id)
+ JOIN vn2008.travel tr on tr.id = travel_id
+ JOIN vn2008.warehouse w on w.id = tr.warehouse_id
+ WHERE landing between datSTART and datEND
+ AND warehouse_id = 44
+ AND Id_Article between intART_DESDE and intART_HASTA
+ AND Id_Proveedor <> 4
+ AND NOT E.Inventario
+ AND reino_id IN (3,4)
+ AND NOT redada
+ AND NOT fuente
+ GROUP BY Id_Article, warehouse_id
+ ) sub3 using(Id_Article, warehouse_id)
+ GROUP BY Id_Article, warehouse_id;
+
+SET intART_DESDE = intART_DESDE + 100;
+SET intART_DESDE = intART_HASTA + 100;
+
+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 `rotacion_volumen_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=`z-developer`@`%` PROCEDURE `rotacion_volumen_update`()
+BEGIN
+
+ CALL vn2008.item_last_buy_(NULL,curdate());
+
+ -- Añadimos el volumen por unidad de venta
+ update bi.rotacion r
+ JOIN vn2008.t_item_last_buy b ON r.Id_Article = b.item_id AND r.warehouse_id = b.warehouse_id
+ join vn2008.Compres ON Id_Compra = b.buy_id
+ set cm3 = vn2008.cm3_2(Id_Cubo, r.Id_Article) / Packing;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `rutas_m3_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `rutas_m3_add`()
+BEGIN
+
+ DECLARE datSTART DATE DEFAULT TIMESTAMPADD(DAY,-90,CURDATE());
+ DECLARE datEND DATE DEFAULT CURDATE();
+ DECLARE datFEC DATE;
+
+ IF hour(now()) between 5 and 24 then
+
+ SET datSTART = CURDATE();
+ SET datEND = TIMESTAMPADD(DAY,1,CURDATE());
+
+ end if;
+
+ SET datFEC = datSTART;
+
+ CALL vn2008.item_last_buy_(NULL,CURDATE());
+ WHILE datFEC <= datEND DO
+
+ UPDATE vn2008.Rutas R
+ JOIN (SELECT R.Id_Ruta, sum(Cantidad * vn2008.cm3_unidad(b.buy_id)) / 1000000 as m3
+ from vn2008.Rutas R
+ join vn2008.Tickets t using(Id_Ruta)
+ join vn2008.Movimientos m using(Id_Ticket)
+ join vn2008.t_item_last_buy b ON Id_Article = b.item_id AND b.warehouse_id = t.warehouse_id
+ where R.Fecha = datFEC AND R.m3 IS NULL
+ group by R.Id_Ruta
+ ) t using(Id_Ruta)
+ SET R.m3 = t.m3
+ WHERE R.m3 IS NULL;
+
+ SET datFEC = TIMESTAMPADD(DAY,1,datFEC);
+
+ 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 `ticket_add2kk` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticket_add2kk`(intNUMDAYS INTEGER)
+BEGIN
+
+DECLARE datSTART,datEND DATETIME;
+-- Seleccionamos los tickets a tratar añadiendolos a la tabla bi.ticket
+
+ SET @@session.max_sp_recursion_depth=250; -- Habilito la recursión en mysql hasta un límite de 250.
+ SET datSTART = TIMESTAMPADD(DAY, -intNUMDAYS, CURDATE());
+
+
+ SET datEND = vn2008.DAYEND(datSTART);
+
+
+
+
+ -- Actualiza el valor de costfixat en Movimientos a efectos estadisticos
+update vn2008.Movimientos m
+join
+(
+select Id_Movimiento, round(IFNULL(sum(Valor) , IFNULL( Preu * (100 - m.Descuento) /100,0 ) ),2) as Cost
+from vn2008.Tickets t
+join vn2008.Movimientos m using(Id_Ticket)
+left join vn2008.Movimientos_componentes mc using(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
+where t.Fecha between datSTART AND datEND
+group by Id_Movimiento
+) sub using(Id_Movimiento)
+set CostFixat = Cost;
+
+
+
+
+ REPLACE INTO bi.ticket(Id_Ticket,Id_Cliente,`date`, tipo_id, `year`,`week`,`month`,`day`,`view`,amount,Id_Trabajador,Id_propietario )
+ SELECT t.Id_Ticket,c.Id_Cliente,t.Fecha `date`,tipo_id, year(Fecha) as `year`, vn2008.vnweek(Fecha) as `week`,
+ month(Fecha) as `month`,vn2008.vnday(Fecha) as `day`, A.Vista `view`,
+ IFNULL( round( sum(cantidad * Preu * (100 - m.Descuento)/100) ,2) ,0) as amount,
+ c.Id_Trabajador, c.Id_Trabajador
+ FROM vn2008.Tickets t
+ JOIN vn2008.Consignatarios cs using(Id_Consigna)
+ JOIN vn2008.warehouse W ON W.id = t.warehouse_id
+ INNER JOIN vn2008.Clientes c on cs.Id_Cliente = c.Id_Cliente
+ INNER JOIN vn2008.Movimientos m USING(Id_Ticket)
+ INNER JOIN vn2008.Articles USING(Id_Article)
+ INNER JOIN vn2008.Agencias A on A.Id_Agencia = t.Id_Agencia
+ INNER JOIN vn2008.Tipos TP USING(tipo_id)
+ WHERE Fecha BETWEEN datSTART AND datEND
+ AND NOT W.fuente
+ AND c.`Real`
+ AND (reino_id <> 6 OR m.Id_Article IN (95,98))
+ GROUP BY t.Id_Ticket,tipo_id ;
+
+ /*
+ UPDATE bi.ticket
+ JOIN vn2008.Tickets using(Id_Ticket)
+ JOIN vn2008.Agencias using(Id_Agencia)
+ JOIN vn2008.agency_warehouse aw using(agency_id,warehouse_id)
+ SET `view` = aw.Vista
+ WHERE Tickets.Fecha BETWEEN datSTART AND datEND;
+ */
+
+
+
+ IF (intNUMDAYS>0) THEN
+ CALL `bi`.`ticket_add2` (intNUMDAYS-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 `ticket_addkk` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticket_addkk`(intNUMDAYS INTEGER)
+BEGIN
+
+DECLARE datSTART DATETIME;
+
+ IF (intNUMDAYS > 0) THEN
+ SET datSTART = TIMESTAMPADD(DAY, -intNUMDAYS, CURDATE());
+ DELETE FROM bi.ticket where `date` >= datSTART ;
+ CALL `bi`.`ticket_add2` (intNUMDAYS);
+ DELETE FROM bi.ticket where `date` < '2001-01-01';
+ END IF;
+
+UPDATE bi.ticket bt
+JOIN vn2008.Tickets USING(Id_Ticket)
+JOIN vn2008.Consignatarios C USING(Id_Consigna)
+SET bt.Id_Cliente = C.Id_Cliente
+, bt.Id_Trabajador = @idT := vn2008.Averiguar_ComercialCliente_Id(C.Id_Cliente,bt.date)
+, bt.Id_propietario = @idT
+WHERE Tickets.Id_Cliente = 31 AND bt.date >= datSTART;
+
+
+-- Almacena los tickets que comisionan, para consultas rapidas
+
+truncate table bi.f_tvc;
+
+insert into bi.f_tvc
+select Id_Ticket
+from vn2008.Tickets t
+join vn2008.Consignatarios cs using(Id_Consigna)
+join vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente
+join vn2008.warehouse w on w.id = t.warehouse_id
+where c.`Real` = TRUE
+and w.comisionantes = TRUE;
+
+
+
+
+-- Quita las horas de los tickets del mes anterior
+IF DAY(CURDATE()) = 15 THEN
+ update vn2008.Tickets
+ set Fecha = date(Fecha)
+ where Fecha between TIMESTAMPADD(DAY,-46,CURDATE()) and TIMESTAMPADD(DAY, -1 - DAY(CURDATE()), 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 `ticket_add_bydaykk` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticket_add_bydaykk`(datFEC DATE)
+BEGIN
+
+ DECLARE datSTART DATETIME;
+ DECLARE datEND DATETIME;
+
+-- Seleccionamos los tickets a tratar añadiendolos a la tabla bi.ticket
+
+ SET @@session.max_sp_recursion_depth=2500; -- Habilito la recursión en mysql hasta un límite de 2500.
+
+ SET datSTART = DATE(datFEC);
+ SET datEND = TIMESTAMPADD(DAY,30,datSTART);
+
+ DELETE FROM bi.ticket WHERE `date` between datSTART and datEND;
+
+ INSERT INTO bi.ticket(Id_Ticket,`date`, tipo_id, `year`,`week`,`month`,`view`,amount,Id_Trabajador, Id_Cliente, Id_Propietario )
+ SELECT t.Id_Ticket,t.Fecha `date`,tipo_id, vn2008.vnyear(Fecha) as `year`, vn2008.vnweek(Fecha) as `week`,
+ vn2008.vnmonth(Fecha) as `month`, A.Vista `view`, IFNULL(round(sum(cantidad * preu * (100 - m.Descuento)/100),2),0) as amount,
+ c.Id_Trabajador, c.Id_Cliente, ifnull(c.Id_Trabajador,20)
+ FROM vn2008.Tickets t
+ JOIN vn2008.Consignatarios cs using(Id_Consigna)
+ JOIN vn2008.warehouse W ON W.id = t.warehouse_id
+ INNER JOIN vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente
+ INNER JOIN vn2008.Movimientos m USING(Id_Ticket)
+ INNER JOIN vn2008.Articles USING(Id_Article)
+ INNER JOIN vn2008.Agencias A on A.Id_Agencia = t.Id_Agencia
+ INNER JOIN vn2008.Tipos TP USING(tipo_id)
+ LEFT JOIN vn2008.reinos r ON r.id = TP.reino_id
+ WHERE Fecha >= datSTART
+ AND Fecha < datEND
+ AND NOT W.fuente
+ AND (invoice or t.Id_Cliente in (5,31))
+ AND r.display <> 0
+ GROUP BY t.Id_Ticket,tipo_id
+ ON DUPLICATE KEY UPDATE amount = amount,
+ `view` = `view`,
+ `date` = `date`,
+ `week` = `week`,
+ `year` = `year`,
+ `month` = `month`,
+ tipo_id = tipo_id,
+ Id_Trabajador = Id_Trabajador,
+ Id_Cliente = Id_Cliente,
+ Id_Propietario = ifnull(Id_Trabajador,20);
+
+ UPDATE bi.ticket
+ JOIN vn2008.Tickets using(Id_Ticket)
+ JOIN vn2008.Agencias using(Id_Agencia)
+ JOIN vn2008.agency_warehouse aw using(agency_id,warehouse_id)
+ SET `view` = aw.Vista
+ WHERE Tickets.Fecha BETWEEN datSTART AND datEND;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `Ultima_Accion` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `Ultima_Accion`()
+BEGIN
+
+REPLACE INTO bi.lastaction(Id_Cliente, Cliente, Ultima_accion, Comercial)
+
+SELECT Id_Cliente, Cliente, Ultima_accion, Comercial
+FROM vn2008.Clientes
+JOIN
+(
+SELECT Id_Cliente, MAX(calldate) as Ultima_accion, vn2008.Averiguar_ComercialCliente(Id_Cliente, CURDATE()) as Comercial
+FROM
+(
+SELECT Id_Cliente, calldate
+FROM vn2008.cdr
+JOIN vn2008.Contactos CT on CT.Telefono = dst
+JOIN vn2008.Relaciones using(Id_Contacto)
+WHERE Id_Cliente IS NOT NULL
+AND duration > 30
+UNION ALL
+SELECT Id_Cliente, calldate
+FROM vn2008.cdr
+JOIN vn2008.Contactos CT on CT.Movil = dst
+JOIN vn2008.Relaciones using(Id_Contacto)
+WHERE Id_Cliente IS NOT NULL
+AND duration > 30
+UNION ALL
+SELECT Id_Cliente, calldate
+FROM vn2008.cdr
+JOIN vn2008.Clientes CT on CT.Telefono = dst
+WHERE duration > 30
+UNION ALL
+SELECT Id_Cliente, calldate
+FROM vn2008.cdr
+JOIN vn2008.Clientes CT on CT.Movil = dst
+WHERE duration > 30
+UNION ALL
+SELECT C.Id_Cliente, Fecha
+FROM vn2008.Tickets JOIN vn2008.Consignatarios C using(Id_Consigna)
+) sub
+GROUP BY Id_Cliente ) sub2 USING(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 `Velocity_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `Velocity_Add`()
+BEGIN
+
+DECLARE bol_EXISTS BOOL;
+DECLARE datMAX DATETIME;
+DECLARE v_buffer VARCHAR(11);
+DECLARE v_sql VARCHAR(255);
+
+
+
+SELECT MAX(Fecha) INTO datMAX FROM bi.Velocity;
+
+IF Date(datMAX) = CURDATE() AND hour(datMAX) > hour(now()) THEN
+
+
+ SET v_buffer = vn2008.buffer_name(CURDATE(),1);
+
+ SELECT count(*) INTO bol_EXISTS FROM information_schema.`TABLES`
+ WHERE TABLE_NAME = CONVERT(v_buffer using utf8) collate utf8_general_ci;
+
+ IF bol_EXISTS THEN
+
+ SET v_sql = sql_printf (
+ 'INSERT INTO bi.Velocity(tipo_id, Fecha, Disponible, Visible)
+ SELECT A.tipo_id, NOW(), sum(avalaible), sum(visible)
+ FROM vn2008.%t b
+ JOIN Articles A ON b.item_id = A.Id_Article GROUP BY tipo_id;
+ ',
+ v_buffer
+ );
+
+
+ CALL util.exec (v_sql);
+
+ 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 */ ;
+
+--
+-- Current Database: `pbx`
+--
+
+CREATE DATABASE /*!32312 IF NOT EXISTS*/ `pbx` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
+
+USE `pbx`;
+
+--
+-- Table structure for table `blacklist`
+--
+
+DROP TABLE IF EXISTS `blacklist`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `blacklist` (
+ `phone` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`phone`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Hangup input calls from this list';
+/*!40101 SET character_set_client = @saved_cs_client */;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `pbx`.`blacklistBeforeInsert`
+BEFORE INSERT ON `blacklist` FOR EACH ROW
+BEGIN
+ CALL phoneIsValid (NEW.phone);
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `pbx`.`blacklistBerforeUpdate`
+BEFORE UPDATE ON `blacklist` FOR EACH ROW
+BEGIN
+ CALL phoneIsValid (NEW.phone);
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+
+--
+-- Table structure for table `cdr`
+--
+
+DROP TABLE IF EXISTS `cdr`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `cdr` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `call_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `clid` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+ `src` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+ `dst` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+ `dcontext` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+ `channel` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+ `dst_channel` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+ `last_app` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+ `last_data` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+ `duration` int(11) NOT NULL DEFAULT '0',
+ `billsec` int(11) NOT NULL DEFAULT '0',
+ `disposition` varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+ `ama_flags` int(11) NOT NULL DEFAULT '0',
+ `account_code` varchar(20) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+ `unique_id` varchar(32) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+ `user_field` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
+ PRIMARY KEY (`id`),
+ KEY `calldate` (`call_date`),
+ KEY `dst` (`dst`),
+ KEY `accountcode` (`account_code`),
+ KEY `dstchannel` (`dst_channel`),
+ KEY `disposition` (`disposition`),
+ KEY `src` (`src`)
+) ENGINE=MyISAM AUTO_INCREMENT=172800 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `cdrConf`
+--
+
+DROP TABLE IF EXISTS `cdrConf`;
+/*!50001 DROP VIEW IF EXISTS `cdrConf`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `cdrConf` 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 `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(10) unsigned NOT NULL AUTO_INCREMENT,
+ `sundayFestive` tinyint(4) NOT NULL,
+ `countryPrefix` varchar(20) CHARACTER SET utf8 DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `followme`
+--
+
+DROP TABLE IF EXISTS `followme`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `followme` (
+ `extension` varchar(128) CHARACTER SET utf8 NOT NULL,
+ `phone` varchar(20) CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`extension`),
+ CONSTRAINT `followme_ibfk_1` FOREIGN KEY (`extension`) REFERENCES `sip` (`extension`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `pbx`.`followmeBeforeInsert`
+BEFORE INSERT ON `followme` FOR EACH ROW
+BEGIN
+ CALL pbx.phoneIsValid (NEW.phone);
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `pbx`.`followmeBeforeUpdate`
+BEFORE UPDATE ON `followme` FOR EACH ROW
+BEGIN
+ CALL pbx.phoneIsValid (NEW.phone);
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+
+--
+-- Temporary view structure for view `followmeConf`
+--
+
+DROP TABLE IF EXISTS `followmeConf`;
+/*!50001 DROP VIEW IF EXISTS `followmeConf`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `followmeConf` AS SELECT
+ 1 AS `name`,
+ 1 AS `music`,
+ 1 AS `context`,
+ 1 AS `takecall`,
+ 1 AS `declinecall`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `followmeConfig`
+--
+
+DROP TABLE IF EXISTS `followmeConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `followmeConfig` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `music` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
+ `context` varchar(50) CHARACTER SET utf8 NOT NULL,
+ `takeCall` char(1) CHARACTER SET utf8 NOT NULL,
+ `declineCall` char(1) CHARACTER SET utf8 NOT NULL,
+ `timeout` int(11) NOT NULL,
+ PRIMARY KEY (`id`)
+) 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 `followmeNumberConf`
+--
+
+DROP TABLE IF EXISTS `followmeNumberConf`;
+/*!50001 DROP VIEW IF EXISTS `followmeNumberConf`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `followmeNumberConf` AS SELECT
+ 1 AS `name`,
+ 1 AS `ordinal`,
+ 1 AS `phonenumber`,
+ 1 AS `timeout`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `queue`
+--
+
+DROP TABLE IF EXISTS `queue`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `queue` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `description` varchar(128) CHARACTER SET utf8 NOT NULL,
+ `name` varchar(128) CHARACTER SET utf8 NOT NULL,
+ `config` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `name` (`name`),
+ UNIQUE KEY `description` (`description`),
+ KEY `config` (`config`),
+ CONSTRAINT `queue_ibfk_1` FOREIGN KEY (`config`) REFERENCES `queueConfig` (`id`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queues';
+/*!40101 SET character_set_client = @saved_cs_client */;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `pbx`.`queueBeforeInsert`
+BEFORE INSERT ON `queue` FOR EACH ROW
+BEGIN
+ CALL queueIsValid (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 */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `pbx`.`queueBeforeUpdate`
+BEFORE UPDATE ON `queue` FOR EACH ROW
+BEGIN
+ CALL queueIsValid (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 */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+
+--
+-- Temporary view structure for view `queueConf`
+--
+
+DROP TABLE IF EXISTS `queueConf`;
+/*!50001 DROP VIEW IF EXISTS `queueConf`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `queueConf` AS SELECT
+ 1 AS `name`,
+ 1 AS `strategy`,
+ 1 AS `timeout`,
+ 1 AS `retry`,
+ 1 AS `weight`,
+ 1 AS `maxlen`,
+ 1 AS `ringinuse`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `queueConfig`
+--
+
+DROP TABLE IF EXISTS `queueConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `queueConfig` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `strategy` varchar(128) CHARACTER SET utf8 NOT NULL,
+ `timeout` int(10) unsigned NOT NULL,
+ `retry` int(10) unsigned NOT NULL,
+ `weight` int(10) unsigned NOT NULL,
+ `maxLen` int(10) unsigned NOT NULL,
+ `ringInUse` tinyint(4) NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Default values for queues configuration';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `queueMember`
+--
+
+DROP TABLE IF EXISTS `queueMember`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `queueMember` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `queue` varchar(128) CHARACTER SET utf8 NOT NULL,
+ `extension` varchar(128) CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `queue` (`queue`,`extension`),
+ KEY `extension` (`extension`),
+ CONSTRAINT `queueMember_ibfk_1` FOREIGN KEY (`queue`) REFERENCES `queue` (`name`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `queueMember_ibfk_2` FOREIGN KEY (`extension`) REFERENCES `sip` (`extension`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=723 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queue members';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `queueMemberConf`
+--
+
+DROP TABLE IF EXISTS `queueMemberConf`;
+/*!50001 DROP VIEW IF EXISTS `queueMemberConf`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `queueMemberConf` AS SELECT
+ 1 AS `uniqueid`,
+ 1 AS `queue_name`,
+ 1 AS `interface`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `queuePhone`
+--
+
+DROP TABLE IF EXISTS `queuePhone`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `queuePhone` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `queue` varchar(128) CHARACTER SET utf8 NOT NULL,
+ `phone` varchar(128) CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `queue` (`queue`,`phone`),
+ CONSTRAINT `queuePhone_ibfk_1` FOREIGN KEY (`queue`) REFERENCES `queue` (`name`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=1003 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `pbx`.`queuePhoneBeforeInsert`
+BEFORE INSERT ON `queuePhone` FOR EACH ROW
+BEGIN
+ CALL phoneIsValid (NEW.phone);
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `pbx`.`queuePhoneBeforeUpdate`
+BEFORE UPDATE ON `queuePhone` FOR EACH ROW
+BEGIN
+ CALL phoneIsValid (NEW.phone);
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+
+--
+-- Table structure for table `schedule`
+--
+
+DROP TABLE IF EXISTS `schedule`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `schedule` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `weekDay` tinyint(3) unsigned NOT NULL COMMENT '0 = Monday, 6 = Sunday',
+ `timeStart` time NOT NULL,
+ `timeEnd` time 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 `sip`
+--
+
+DROP TABLE IF EXISTS `sip`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `sip` (
+ `user_id` int(10) unsigned NOT NULL DEFAULT '0',
+ `extension` varchar(128) CHARACTER SET utf8 NOT NULL,
+ `secret` varchar(80) CHARACTER SET utf8 NOT NULL,
+ `caller_id` varchar(80) CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`user_id`),
+ UNIQUE KEY `extension` (`extension`),
+ CONSTRAINT `sip_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='SIP accounts';
+/*!40101 SET character_set_client = @saved_cs_client */;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `pbx`.`sipBeforeInsert`
+BEFORE INSERT ON `sip` FOR EACH ROW
+BEGIN
+ CALL extensionIsValid (NEW.extension);
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `sipAfterInsert`
+AFTER INSERT ON `sip` FOR EACH ROW
+BEGIN
+ INSERT INTO sipReg (userId) VALUES (NEW.user_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 */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `pbx`.`sipBeforeUpdate`
+BEFORE UPDATE ON `sip` FOR EACH ROW
+BEGIN
+ CALL extensionIsValid (NEW.extension);
+END */;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+
+--
+-- Temporary view structure for view `sipConf`
+--
+
+DROP TABLE IF EXISTS `sipConf`;
+/*!50001 DROP VIEW IF EXISTS `sipConf`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `sipConf` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `secret`,
+ 1 AS `callerid`,
+ 1 AS `host`,
+ 1 AS `deny`,
+ 1 AS `permit`,
+ 1 AS `type`,
+ 1 AS `context`,
+ 1 AS `incominglimit`,
+ 1 AS `pickupgroup`,
+ 1 AS `careinvite`,
+ 1 AS `ipaddr`,
+ 1 AS `regseconds`,
+ 1 AS `port`,
+ 1 AS `defaultuser`,
+ 1 AS `useragent`,
+ 1 AS `lastms`,
+ 1 AS `fullcontact`,
+ 1 AS `regserver`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `sipConfig`
+--
+
+DROP TABLE IF EXISTS `sipConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `sipConfig` (
+ `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
+ `host` varchar(40) CHARACTER SET utf8 DEFAULT NULL,
+ `deny` varchar(95) CHARACTER SET utf8 NOT NULL,
+ `permit` varchar(95) CHARACTER SET utf8 NOT NULL,
+ `type` enum('user','peer','friend') CHARACTER SET utf8 NOT NULL,
+ `context` varchar(80) CHARACTER SET utf8 NOT NULL,
+ `incomingLimit` varchar(10) CHARACTER SET utf8 NOT NULL,
+ `pickupGroup` varchar(10) CHARACTER SET utf8 NOT NULL,
+ `careInvite` varchar(10) CHARACTER SET utf8 NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Default values for SIP accounts';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `sipReg`
+--
+
+DROP TABLE IF EXISTS `sipReg`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `sipReg` (
+ `userId` int(10) unsigned NOT NULL,
+ `ipAddr` varchar(40) CHARACTER SET utf8 DEFAULT NULL,
+ `regSeconds` int(10) unsigned DEFAULT NULL,
+ `port` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
+ `defaultUser` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
+ `userAgent` varchar(80) CHARACTER SET utf8 DEFAULT NULL,
+ `lastMs` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
+ `fullContact` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
+ `regServer` varchar(20) CHARACTER SET utf8 DEFAULT NULL,
+ PRIMARY KEY (`userId`),
+ CONSTRAINT `sipReg_ibfk_1` FOREIGN KEY (`userId`) REFERENCES `sip` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='SIP registrations';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping events for database 'pbx'
+--
+
+--
+-- Dumping routines for database 'pbx'
+--
+/*!50003 DROP FUNCTION IF EXISTS `clientFromPhone` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `clientFromPhone`(vPhone VARCHAR(255)) RETURNS int(11)
+ DETERMINISTIC
+BEGIN
+ DECLARE vClient INT DEFAULT NULL;
+
+ -- SET vPhone = vPhone COLLATE 'utf8_unicode_ci';
+
+ -- Searchs a customer associated to the phone number
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.customer;
+ CREATE TEMPORARY TABLE tmp.customer
+ ENGINE = MEMORY
+ SELECT id_cliente customer
+ FROM vn2008.Clientes c
+ WHERE telefono = vPhone
+ OR movil = vPhone
+ UNION
+ SELECT id_cliente
+ FROM vn2008.Consignatarios
+ WHERE telefono = vPhone
+ OR movil = vPhone
+ UNION
+ SELECT r.id_cliente
+ FROM vn2008.Relaciones r
+ JOIN vn2008.Contactos c ON r.Id_Contacto = c.Id_Contacto
+ WHERE c.telefono = vPhone
+ OR c.movil = vPhone;
+
+ SELECT t.customer INTO vClient
+ FROM tmp.customer t
+ JOIN vn2008.Clientes c ON c.id_cliente = t.customer
+ WHERE c.activo
+ LIMIT 1;
+
+ DROP TEMPORARY TABLE tmp.customer;
+
+ RETURN 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 FUNCTION IF EXISTS `phoneFormat` */;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `phoneFormat`(vPhone VARCHAR(255)) RETURNS varchar(255) CHARSET utf8
+BEGIN
+ DECLARE vI INT DEFAULT 0;
+ DECLARE vChr VARCHAR(1);
+ DECLARE vLen INT DEFAULT LENGTH(vPhone);
+ DECLARE vNewPhone VARCHAR(255) DEFAULT '';
+
+ WHILE vI < vLen
+ DO
+ SET vChr = SUBSTR(vPhone, vI + 1, 1);
+
+ IF vChr REGEXP '^[0-9]$'
+ THEN
+ SET vNewPhone = CONCAT(vNewPhone, vChr);
+ ELSEIF vChr = '+' AND vI = 0
+ THEN
+ SET vNewPhone = CONCAT(vNewPhone, '00');
+ END IF;
+
+ SET vI = vI + 1;
+ END WHILE;
+
+ IF vNewPhone REGEXP '^0+$' OR vNewPhone = '' THEN
+ RETURN NULL;
+ END IF;
+
+ IF vNewPhone REGEXP '^0034' THEN
+ SET vNewPhone = SUBSTR(vNewPhone, 5);
+ END IF;
+
+ RETURN vNewPhone;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `extensionIsValid` */;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `extensionIsValid`(vExtension VARCHAR(255))
+ DETERMINISTIC
+BEGIN
+ DECLARE vIsValid BOOLEAN;
+
+ SET vIsValid = vExtension IS NULL
+ OR (vExtension REGEXP '^[0-9]{4}$'
+ AND MOD(vExtension, 100) != 0);
+
+ IF NOT vIsValid
+ THEN
+ SIGNAL SQLSTATE '45000'
+ SET MESSAGE_TEXT = 'EXTENSION_INVALID_FORMAT';
+ 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 */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `phoneIsValid` */;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `phoneIsValid`(vPhone VARCHAR(255))
+BEGIN
+ DECLARE vIsValid BOOLEAN;
+
+ SET vIsValid = vPhone IS NULL
+ OR (vPhone REGEXP '^[0-9]+$'
+ AND vPhone NOT REGEXP '^0+$'
+ AND vPhone NOT REGEXP '^0034');
+
+ IF NOT vIsValid
+ THEN
+ SIGNAL SQLSTATE '45000'
+ SET MESSAGE_TEXT = 'PHONE_INVALID_FORMAT';
+ 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 */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `queueIsValid` */;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `queueIsValid`(vQueue VARCHAR(255))
+ DETERMINISTIC
+BEGIN
+ DECLARE vIsValid BOOLEAN;
+
+ SET vIsValid = vQueue IS NULL
+ OR vQueue REGEXP '^[1-9][0-9]00$';
+
+ IF NOT vIsValid
+ THEN
+ SIGNAL SQLSTATE '45000'
+ SET MESSAGE_TEXT = 'QUEUE_INVALID_FORMAT';
+ 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 */ ;
+ALTER DATABASE `pbx` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+
+--
+-- Current Database: `salix`
+--
+
+CREATE DATABASE /*!32312 IF NOT EXISTS*/ `salix` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
+
+USE `salix`;
+
+--
+-- Table structure for table `ACL`
+--
+
+DROP TABLE IF EXISTS `ACL`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `ACL` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `model` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
+ `property` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
+ `accessType` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
+ `permission` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
+ `principalType` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
+ `principalId` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
+ PRIMARY KEY (`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 `AccessToken`
+--
+
+DROP TABLE IF EXISTS `AccessToken`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `AccessToken` (
+ `id` varchar(255) CHARACTER SET utf8 NOT NULL,
+ `ttl` int(11) DEFAULT NULL,
+ `scopes` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
+ `created` datetime DEFAULT NULL,
+ `userId` int(11) DEFAULT NULL,
+ 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 `Account`
+--
+
+DROP TABLE IF EXISTS `Account`;
+/*!50001 DROP VIEW IF EXISTS `Account`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Account` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `password`,
+ 1 AS `roleFk`,
+ 1 AS `active`,
+ 1 AS `email`,
+ 1 AS `created`,
+ 1 AS `updated`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Accounting`
+--
+
+DROP TABLE IF EXISTS `Accounting`;
+/*!50001 DROP VIEW IF EXISTS `Accounting`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Accounting` AS SELECT
+ 1 AS `id`,
+ 1 AS `bank`,
+ 1 AS `account`,
+ 1 AS `accountingTypeFk`,
+ 1 AS `entityFk`,
+ 1 AS `isActive`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Address`
+--
+
+DROP TABLE IF EXISTS `Address`;
+/*!50001 DROP VIEW IF EXISTS `Address`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Address` AS SELECT
+ 1 AS `id`,
+ 1 AS `consignee`,
+ 1 AS `street`,
+ 1 AS `city`,
+ 1 AS `postcode`,
+ 1 AS `provinceFk`,
+ 1 AS `phone`,
+ 1 AS `mobile`,
+ 1 AS `isEnabled`,
+ 1 AS `isDefaultAddress`,
+ 1 AS `clientFk`,
+ 1 AS `defaultAgencyFk`,
+ 1 AS `longitude`,
+ 1 AS `latitude`,
+ 1 AS `isEqualizated`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Agency`
+--
+
+DROP TABLE IF EXISTS `Agency`;
+/*!50001 DROP VIEW IF EXISTS `Agency`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Agency` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `warehouseFk`,
+ 1 AS `isVolumetric`,
+ 1 AS `bankFk`,
+ 1 AS `warehouseAliasFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `AgencyMode`
+--
+
+DROP TABLE IF EXISTS `AgencyMode`;
+/*!50001 DROP VIEW IF EXISTS `AgencyMode`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `AgencyMode` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `description`,
+ 1 AS `agencyTypeFk`,
+ 1 AS `m3`,
+ 1 AS `agencyFk`,
+ 1 AS `inflation`,
+ 1 AS `sendMailTo`,
+ 1 AS `isForTicket`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Bank`
+--
+
+DROP TABLE IF EXISTS `Bank`;
+/*!50001 DROP VIEW IF EXISTS `Bank`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Bank` AS SELECT
+ 1 AS `id`,
+ 1 AS `bank`,
+ 1 AS `account`,
+ 1 AS `cash`,
+ 1 AS `entityFk`,
+ 1 AS `isActive`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `City`
+--
+
+DROP TABLE IF EXISTS `City`;
+/*!50001 DROP VIEW IF EXISTS `City`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `City` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `provinceFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Client`
+--
+
+DROP TABLE IF EXISTS `Client`;
+/*!50001 DROP VIEW IF EXISTS `Client`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Client` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `fi`,
+ 1 AS `socialName`,
+ 1 AS `contact`,
+ 1 AS `street`,
+ 1 AS `city`,
+ 1 AS `postcode`,
+ 1 AS `provinceFk`,
+ 1 AS `countryFk`,
+ 1 AS `email`,
+ 1 AS `phone`,
+ 1 AS `mobile`,
+ 1 AS `fax`,
+ 1 AS `active`,
+ 1 AS `discount`,
+ 1 AS `credit`,
+ 1 AS `creditInsurance`,
+ 1 AS `iban`,
+ 1 AS `dueDay`,
+ 1 AS `equalizationTax`,
+ 1 AS `hasToInvoice`,
+ 1 AS `invoiceByEmail`,
+ 1 AS `payMethodFk`,
+ 1 AS `salesPersonFk`,
+ 1 AS `contactChannelFk`,
+ 1 AS `sepaVnl`,
+ 1 AS `coreVnl`,
+ 1 AS `coreVnh`,
+ 1 AS `eypbc`,
+ 1 AS `quality`,
+ 1 AS `vies`,
+ 1 AS `isRelevant`,
+ 1 AS `typeFk`,
+ 1 AS `accountingAccount`,
+ 1 AS `created`,
+ 1 AS `hasToInvoiceByAddress`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `ClientCredit`
+--
+
+DROP TABLE IF EXISTS `ClientCredit`;
+/*!50001 DROP VIEW IF EXISTS `ClientCredit`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ClientCredit` AS SELECT
+ 1 AS `id`,
+ 1 AS `clientFk`,
+ 1 AS `employeeFk`,
+ 1 AS `amount`,
+ 1 AS `created`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `ClientCreditLimit`
+--
+
+DROP TABLE IF EXISTS `ClientCreditLimit`;
+/*!50001 DROP VIEW IF EXISTS `ClientCreditLimit`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ClientCreditLimit` AS SELECT
+ 1 AS `id`,
+ 1 AS `maxAmount`,
+ 1 AS `roleFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `ClientObservation`
+--
+
+DROP TABLE IF EXISTS `ClientObservation`;
+/*!50001 DROP VIEW IF EXISTS `ClientObservation`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ClientObservation` AS SELECT
+ 1 AS `id`,
+ 1 AS `clientFk`,
+ 1 AS `employeeFk`,
+ 1 AS `text`,
+ 1 AS `created`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `ClientType`
+--
+
+DROP TABLE IF EXISTS `ClientType`;
+/*!50001 DROP VIEW IF EXISTS `ClientType`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ClientType` AS SELECT
+ 1 AS `id`,
+ 1 AS `code`,
+ 1 AS `type`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `ContactChannel`
+--
+
+DROP TABLE IF EXISTS `ContactChannel`;
+/*!50001 DROP VIEW IF EXISTS `ContactChannel`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ContactChannel` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Country`
+--
+
+DROP TABLE IF EXISTS `Country`;
+/*!50001 DROP VIEW IF EXISTS `Country`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Country` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `inCee`,
+ 1 AS `code`,
+ 1 AS `currencyFk`,
+ 1 AS `realCountryFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `CreditClassification`
+--
+
+DROP TABLE IF EXISTS `CreditClassification`;
+/*!50001 DROP VIEW IF EXISTS `CreditClassification`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `CreditClassification` AS SELECT
+ 1 AS `id`,
+ 1 AS `clientFk`,
+ 1 AS `started`,
+ 1 AS `ended`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Delivery`
+--
+
+DROP TABLE IF EXISTS `Delivery`;
+/*!50001 DROP VIEW IF EXISTS `Delivery`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Delivery` AS SELECT
+ 1 AS `id`,
+ 1 AS `date`,
+ 1 AS `m3`,
+ 1 AS `warehouseFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Employee`
+--
+
+DROP TABLE IF EXISTS `Employee`;
+/*!50001 DROP VIEW IF EXISTS `Employee`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Employee` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `surname`,
+ 1 AS `userFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `FakeProduction`
+--
+
+DROP TABLE IF EXISTS `FakeProduction`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `FakeProduction` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `ticketFk` int(11) NOT NULL DEFAULT '0',
+ `clientFk` int(11) NOT NULL DEFAULT '0',
+ `client` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `date` date DEFAULT NULL,
+ `hour` time DEFAULT NULL,
+ `city` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `province` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `provinceFk` smallint(6) unsigned NOT NULL DEFAULT '0',
+ `agency` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `agencyFk` smallint(6) NOT NULL,
+ `lines` int(1) NOT NULL DEFAULT '0',
+ `m3` decimal(5,2) NOT NULL DEFAULT '0.00',
+ `problems` int(1) NOT NULL DEFAULT '0',
+ `problem` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `stateFk` bigint(4) NOT NULL DEFAULT '0',
+ `workerfk` int(11) NOT NULL DEFAULT '0',
+ `worker` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `salesPersonFk` int(11) NOT NULL DEFAULT '0',
+ `salesPerson` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `state` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `boxes` double DEFAULT NULL,
+ `routeFk` int(10) unsigned DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=826 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `Message`
+--
+
+DROP TABLE IF EXISTS `Message`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `Message` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `uuid` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `sender` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `recipient` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `message` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `sendDate` datetime DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `MessageInbox`
+--
+
+DROP TABLE IF EXISTS `MessageInbox`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `MessageInbox` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `uuid` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `sender` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `recipient` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `finalRecipient` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `message` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `sendDate` datetime DEFAULT CURRENT_TIMESTAMP,
+ 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 `PayMethod`
+--
+
+DROP TABLE IF EXISTS `PayMethod`;
+/*!50001 DROP VIEW IF EXISTS `PayMethod`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `PayMethod` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `graceDays`,
+ 1 AS `outstandingDebt`,
+ 1 AS `ibanRequired`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Province`
+--
+
+DROP TABLE IF EXISTS `Province`;
+/*!50001 DROP VIEW IF EXISTS `Province`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Province` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `countryFk`,
+ 1 AS `warehouseFk`,
+ 1 AS `zoneFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Role`
+--
+
+DROP TABLE IF EXISTS `Role`;
+/*!50001 DROP VIEW IF EXISTS `Role`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Role` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `description`,
+ 1 AS `created`,
+ 1 AS `modified`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `RoleMapping`
+--
+
+DROP TABLE IF EXISTS `RoleMapping`;
+/*!50001 DROP VIEW IF EXISTS `RoleMapping`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `RoleMapping` AS SELECT
+ 1 AS `id`,
+ 1 AS `principalType`,
+ 1 AS `principalId`,
+ 1 AS `roleId`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Route`
+--
+
+DROP TABLE IF EXISTS `Route`;
+/*!50001 DROP VIEW IF EXISTS `Route`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Route` AS SELECT
+ 1 AS `id`,
+ 1 AS `date`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `State`
+--
+
+DROP TABLE IF EXISTS `State`;
+/*!50001 DROP VIEW IF EXISTS `State`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `State` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `order`,
+ 1 AS `alertLevel`,
+ 1 AS `code`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Ticket`
+--
+
+DROP TABLE IF EXISTS `Ticket`;
+/*!50001 DROP VIEW IF EXISTS `Ticket`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Ticket` AS SELECT
+ 1 AS `id`,
+ 1 AS `agencyFk`,
+ 1 AS `employeeFk`,
+ 1 AS `date`,
+ 1 AS `hour`,
+ 1 AS `clientFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `TicketState`
+--
+
+DROP TABLE IF EXISTS `TicketState`;
+/*!50001 DROP VIEW IF EXISTS `TicketState`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `TicketState` AS SELECT
+ 1 AS `id`,
+ 1 AS `ticketFk`,
+ 1 AS `stateFk`,
+ 1 AS `employeeFk`,
+ 1 AS `updated`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Vehicle`
+--
+
+DROP TABLE IF EXISTS `Vehicle`;
+/*!50001 DROP VIEW IF EXISTS `Vehicle`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Vehicle` AS SELECT
+ 1 AS `id`,
+ 1 AS `numberPlate`,
+ 1 AS `tradeMark`,
+ 1 AS `model`,
+ 1 AS `companyFk`,
+ 1 AS `warehouseFk`,
+ 1 AS `description`,
+ 1 AS `m3`,
+ 1 AS `isActive`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Warehouse`
+--
+
+DROP TABLE IF EXISTS `Warehouse`;
+/*!50001 DROP VIEW IF EXISTS `Warehouse`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Warehouse` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `tpv`,
+ 1 AS `inventory`,
+ 1 AS `isManaged`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `WarehouseAlias`
+--
+
+DROP TABLE IF EXISTS `WarehouseAlias`;
+/*!50001 DROP VIEW IF EXISTS `WarehouseAlias`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `WarehouseAlias` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Worker`
+--
+
+DROP TABLE IF EXISTS `Worker`;
+/*!50001 DROP VIEW IF EXISTS `Worker`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Worker` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `surname`,
+ 1 AS `userFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `Zone`
+--
+
+DROP TABLE IF EXISTS `Zone`;
+/*!50001 DROP VIEW IF EXISTS `Zone`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `Zone` AS SELECT
+ 1 AS `id`,
+ 1 AS `name`,
+ 1 AS `printingOrder`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `user`
+--
+
+DROP TABLE IF EXISTS `user`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `user` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `realm` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
+ `username` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
+ `password` varchar(512) CHARACTER SET utf8 NOT NULL,
+ `email` varchar(512) CHARACTER SET utf8 NOT NULL,
+ `emailVerified` tinyint(1) DEFAULT NULL,
+ `verificationToken` varchar(512) CHARACTER SET utf8 DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=50054 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping events for database 'salix'
+--
+
+--
+-- Dumping routines for database 'salix'
+--
+/*!50003 DROP PROCEDURE IF EXISTS `production_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 `production_control_source`(idWarehouse INT, scopeDays TINYINT)
+BEGIN
+ CALL vn2008.production_control_source(idWarehouse, scopeDays);
+
+ SET @id = 0;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.production;
+ CREATE TEMPORARY TABLE tmp.production
+ ENGINE = MEMORY
+ SELECT
+ @id := @id+1 id,
+ p.Id_Ticket ticketFk,
+ p.Id_Cliente clientFk,
+ p.Alias client,
+ p.Fecha `date`,
+ p.Hora hour,
+ p.POBLACION city,
+ p.PROVINCIA province,
+ p.province_id provinceFk,
+ p.Agencia agency,
+ p.agency_id agencyFk,
+ p.lines,
+ p.m3,
+ p.problems,
+ p.problem,
+ p.state stateFk,
+ t.Id_Trabajador workerfk,
+ CONCAT(t.Nombre, ' ', t.Apellidos) worker,
+ tt.Id_Trabajador salesPersonFk,
+ CONCAT(tt.Nombre, ' ', tt.Apellidos) salesPerson,
+ s.name state,
+ p.Cajas boxes,
+ p.Id_Ruta routeFk
+ FROM tmp.production_buffer p
+ JOIN vn2008.state s ON p.state = s.id
+ JOIN vn2008.Trabajadores t ON p.CodigoTrabajador = t.CodigoTrabajador COLLATE utf8_unicode_ci
+ JOIN vn2008.Trabajadores tt ON p.Comercial = tt.CodigoTrabajador COLLATE utf8_unicode_ci;
+
+ DROP TEMPORARY TABLE 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 */ ;
+
+--
+-- Current Database: `hedera`
+--
+
+CREATE DATABASE /*!32312 IF NOT EXISTS*/ `hedera` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
+
+USE `hedera`;
+
+--
+-- Temporary view structure for view `address_view`
+--
+
+DROP TABLE IF EXISTS `address_view`;
+/*!50001 DROP VIEW IF EXISTS `address_view`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `address_view` AS SELECT
+ 1 AS `id`,
+ 1 AS `customer_id`,
+ 1 AS `warehouse_id`,
+ 1 AS `name`,
+ 1 AS `city`,
+ 1 AS `province_id`,
+ 1 AS `zip_code`,
+ 1 AS `consignee`,
+ 1 AS `default`,
+ 1 AS `type_id`,
+ 1 AS `specs`,
+ 1 AS `insurance`,
+ 1 AS `postage`,
+ 1 AS `active`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `androidUser`
+--
+
+DROP TABLE IF EXISTS `androidUser`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `androidUser` (
+ `androidId` varchar(200) CHARACTER SET utf8 NOT NULL,
+ `userFk` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`userFk`,`androidId`),
+ CONSTRAINT `androidUser_ibfk_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `basket`
+--
+
+DROP TABLE IF EXISTS `basket`;
+/*!50001 DROP VIEW IF EXISTS `basket`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `basket` 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 `company_id`,
+ 1 AS `note`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `basketOrder`
+--
+
+DROP TABLE IF EXISTS `basketOrder`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `basketOrder` (
+ `customerFk` int(11) NOT NULL,
+ `orderFk` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`orderFk`,`customerFk`),
+ UNIQUE KEY `customer_id` (`customerFk`),
+ CONSTRAINT `basketOrder_ibfk_1` FOREIGN KEY (`orderFk`, `customerFk`) REFERENCES `order` (`id`, `customer_id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `basketOrder_ibfk_2` FOREIGN KEY (`orderFk`) REFERENCES `order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `basketOrder_ibfk_3` FOREIGN KEY (`customerFk`) REFERENCES `vn2008`.`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 */;
+
+--
+-- Temporary view structure for view `basket_defaults`
+--
+
+DROP TABLE IF EXISTS `basket_defaults`;
+/*!50001 DROP VIEW IF EXISTS `basket_defaults`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `basket_defaults` AS SELECT
+ 1 AS `address_id`,
+ 1 AS `agency_id`,
+ 1 AS `delivery_method`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `basket_item`
+--
+
+DROP TABLE IF EXISTS `basket_item`;
+/*!50001 DROP VIEW IF EXISTS `basket_item`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `basket_item` AS SELECT
+ 1 AS `id`,
+ 1 AS `order_id`,
+ 1 AS `warehouse_id`,
+ 1 AS `item_id`,
+ 1 AS `amount`,
+ 1 AS `price`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `browser`
+--
+
+DROP TABLE IF EXISTS `browser`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `browser` (
+ `name` varchar(30) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Browser name in browscap',
+ `version` float NOT NULL COMMENT 'Minimal version',
+ UNIQUE KEY `name` (`name`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='List of compatible web browsers and its version';
+/*!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` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
+ `defaultLang` char(2) CHARACTER SET utf8 NOT NULL COMMENT 'The default language if none is specified',
+ `https` tinyint(3) unsigned NOT NULL COMMENT 'Wether to force de use of HTTPS',
+ `cookieLife` smallint(5) unsigned NOT NULL COMMENT 'The cookies life, in days',
+ `jwtKey` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The key used to encode/decode JWT tokens',
+ `default_form` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Form loaded at web login',
+ `restUri` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `testRestUri` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `image_host` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `image_dir` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Directory where images are allocated',
+ `guest_user` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Guest user name',
+ `guest_pass` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Guest password, base64 encoded',
+ `test_domain` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The address for beta website',
+ `production_domain` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The address for production website',
+ `pdfs_dir` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Directory where pdfs are allocated',
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `contact`
+--
+
+DROP TABLE IF EXISTS `contact`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `contact` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `recipient` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`)
+) 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 `customer_view`
+--
+
+DROP TABLE IF EXISTS `customer_view`;
+/*!50001 DROP VIEW IF EXISTS `customer_view`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `customer_view` AS SELECT
+ 1 AS `user_id`,
+ 1 AS `name`,
+ 1 AS `email`,
+ 1 AS `mail`,
+ 1 AS `default_address`,
+ 1 AS `credit`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `imageCollection`
+--
+
+DROP TABLE IF EXISTS `imageCollection`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `imageCollection` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `desc` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `maxWidth` int(10) unsigned NOT NULL,
+ `maxHeight` int(10) unsigned NOT NULL,
+ `schema` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `table` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `column` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `name` (`name`)
+) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `imageCollectionSize`
+--
+
+DROP TABLE IF EXISTS `imageCollectionSize`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `imageCollectionSize` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `collectionFk` int(10) unsigned NOT NULL,
+ `width` int(10) unsigned NOT NULL,
+ `height` int(10) unsigned NOT NULL,
+ `crop` tinyint(3) unsigned NOT NULL DEFAULT '0',
+ PRIMARY KEY (`id`),
+ KEY `image_schema_id` (`collectionFk`),
+ CONSTRAINT `imageCollectionSize_ibfk_1` FOREIGN KEY (`collectionFk`) REFERENCES `imageCollection` (`id`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `imageConfig`
+--
+
+DROP TABLE IF EXISTS `imageConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `imageConfig` (
+ `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Identifier',
+ `maxSize` int(10) unsigned NOT NULL COMMENT 'Maximun size for uploaded images in MB',
+ `useXsendfile` tinyint(4) NOT NULL COMMENT 'Whether to use the apache module XSendfile',
+ `url` varchar(255) NOT NULL COMMENT 'Public URL where image are hosted',
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='Global image parameters';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `imageFile`
+--
+
+DROP TABLE IF EXISTS `imageFile`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `imageFile` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `schemaFk` int(10) unsigned NOT NULL,
+ `file` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `stamp` int(11) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `schema_id_file` (`schemaFk`,`file`),
+ CONSTRAINT `imageFile_ibfk_1` FOREIGN KEY (`schemaFk`) REFERENCES `imageCollection` (`id`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=32793 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `invoice_view`
+--
+
+DROP TABLE IF EXISTS `invoice_view`;
+/*!50001 DROP VIEW IF EXISTS `invoice_view`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `invoice_view` AS SELECT
+ 1 AS `invoice_id`,
+ 1 AS `serial_num`,
+ 1 AS `issued`,
+ 1 AS `amount`*/;
+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) CHARACTER SET utf8 NOT NULL,
+ `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
+ `orgName` varchar(255) 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` int(11) NOT NULL AUTO_INCREMENT,
+ `name` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
+ `description` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `link` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `image` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=36 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `location`
+--
+
+DROP TABLE IF EXISTS `location`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `location` (
+ `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
+ `lat` varchar(12) COLLATE utf8_unicode_ci NOT NULL,
+ `lng` varchar(12) COLLATE utf8_unicode_ci NOT NULL,
+ `title` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `address` varchar(75) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `postcode` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `city` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `province` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `phone` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `language` char(2) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `mailConfig`
+--
+
+DROP TABLE IF EXISTS `mailConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `mailConfig` (
+ `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Identifier',
+ `host` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'localhost' COMMENT 'SMTP host',
+ `port` smallint(6) NOT NULL DEFAULT '465' COMMENT 'SMTP port',
+ `secure` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Wether to use a secure connection',
+ `sender` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The sender mail address',
+ `senderName` varchar(75) CHARACTER SET utf8 NOT NULL COMMENT 'The sender name',
+ `user` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'SMTP user',
+ `password` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'SMTP password, base64 encoded',
+ PRIMARY KEY (`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 `menu`
+--
+
+DROP TABLE IF EXISTS `menu`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `menu` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `description` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
+ `path` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `roleFk` int(10) unsigned NOT NULL,
+ `parentFk` int(10) unsigned DEFAULT NULL,
+ `displayOrder` tinyint(4) unsigned NOT NULL DEFAULT '1',
+ PRIMARY KEY (`id`),
+ KEY `group_id` (`roleFk`),
+ KEY `parent` (`parentFk`),
+ CONSTRAINT `menu_ibfk_1` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role` (`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 `message`
+--
+
+DROP TABLE IF EXISTS `message`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `message` (
+ `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
+ `code` char(35) COLLATE utf8_unicode_ci NOT NULL,
+ `description` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `code` (`code`)
+) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `metatag`
+--
+
+DROP TABLE IF EXISTS `metatag`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `metatag` (
+ `id` int(11) NOT NULL,
+ `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `content` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `name` (`name`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `myAddress`
+--
+
+DROP TABLE IF EXISTS `myAddress`;
+/*!50001 DROP VIEW IF EXISTS `myAddress`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `myAddress` AS SELECT
+ 1 AS `id`,
+ 1 AS `clientFk`,
+ 1 AS `street`,
+ 1 AS `city`,
+ 1 AS `postalCode`,
+ 1 AS `provinceFk`,
+ 1 AS `nickname`,
+ 1 AS `isDefaultAddress`,
+ 1 AS `active`,
+ 1 AS `longitude`,
+ 1 AS `latitude`,
+ 1 AS `warehouseFk`,
+ 1 AS `agencyFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `myMenu`
+--
+
+DROP TABLE IF EXISTS `myMenu`;
+/*!50001 DROP VIEW IF EXISTS `myMenu`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `myMenu` AS SELECT
+ 1 AS `id`,
+ 1 AS `path`,
+ 1 AS `description`,
+ 1 AS `parentFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `myTicket`
+--
+
+DROP TABLE IF EXISTS `myTicket`;
+/*!50001 DROP VIEW IF EXISTS `myTicket`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `myTicket` AS SELECT
+ 1 AS `id`,
+ 1 AS `clientFk`,
+ 1 AS `warehouseFk`,
+ 1 AS `shipped`,
+ 1 AS `landed`,
+ 1 AS `nickname`,
+ 1 AS `agencyModeFk`,
+ 1 AS `refFk`,
+ 1 AS `addressFk`,
+ 1 AS `isSigned`,
+ 1 AS `package`,
+ 1 AS `location`,
+ 1 AS `companyFk`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `myTicketRow`
+--
+
+DROP TABLE IF EXISTS `myTicketRow`;
+/*!50001 DROP VIEW IF EXISTS `myTicketRow`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `myTicketRow` AS SELECT
+ 1 AS `id`,
+ 1 AS `itemFk`,
+ 1 AS `ticketFk`,
+ 1 AS `concept`,
+ 1 AS `quantity`,
+ 1 AS `price`,
+ 1 AS `discount`,
+ 1 AS `reserved`,
+ 1 AS `isPicked`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `myTpvTransaction`
+--
+
+DROP TABLE IF EXISTS `myTpvTransaction`;
+/*!50001 DROP VIEW IF EXISTS `myTpvTransaction`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `myTpvTransaction` AS SELECT
+ 1 AS `id`,
+ 1 AS `merchantFk`,
+ 1 AS `clientFk`,
+ 1 AS `receiptFk`,
+ 1 AS `amount`,
+ 1 AS `response`,
+ 1 AS `status`,
+ 1 AS `created`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `news`
+--
+
+DROP TABLE IF EXISTS `news`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `news` (
+ `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
+ `title` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
+ `text` text COLLATE utf8_unicode_ci NOT NULL,
+ `image` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `userFk` int(10) unsigned NOT NULL,
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `priority` tinyint(3) unsigned NOT NULL DEFAULT '3',
+ `tag` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'new',
+ `__date_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Deprecated',
+ `__user_id` int(10) NOT NULL COMMENT 'Deprecated',
+ PRIMARY KEY (`id`),
+ KEY `user` (`userFk`),
+ KEY `tag` (`tag`),
+ CONSTRAINT `news_ibfk_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`account` (`id`) ON UPDATE CASCADE,
+ CONSTRAINT `news_ibfk_2` FOREIGN KEY (`tag`) REFERENCES `newsTag` (`name`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=12987 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `newsTag`
+--
+
+DROP TABLE IF EXISTS `newsTag`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `newsTag` (
+ `name` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
+ `description` varchar(25) 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 */;
+
+--
+-- Table structure for table `order`
+--
+
+DROP TABLE IF EXISTS `order`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `order` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `date_send` date NOT NULL DEFAULT '0000-00-00',
+ `customer_id` int(11) NOT NULL,
+ `delivery_method_id` int(11) DEFAULT '3',
+ `agency_id` int(11) DEFAULT '2',
+ `address_id` int(11) DEFAULT NULL,
+ `company_id` smallint(5) unsigned NOT NULL DEFAULT '442',
+ `note` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `source_app` set('WEB','ANDROID','IOS','TPV','TABLET_VN','') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'TPV',
+ `is_bionic` tinyint(1) NOT NULL DEFAULT '1',
+ `confirmed` tinyint(1) NOT NULL DEFAULT '0',
+ `date_make` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `first_row_stamp` datetime DEFAULT NULL,
+ `confirm_date` datetime DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `address` (`address_id`),
+ KEY `delivery_method` (`delivery_method_id`),
+ KEY `agency` (`agency_id`),
+ KEY `customer_id` (`customer_id`),
+ KEY `company_id` (`company_id`),
+ KEY `id` (`id`,`customer_id`),
+ KEY `source_app` (`source_app`),
+ KEY `confirmed` (`confirmed`),
+ CONSTRAINT `order_ibfk_5` FOREIGN KEY (`address_id`) REFERENCES `vn2008`.`Consignatarios` (`id_consigna`) ON UPDATE CASCADE,
+ CONSTRAINT `order_ibfk_8` FOREIGN KEY (`delivery_method_id`) REFERENCES `vn2008`.`Vistas` (`vista_id`) ON UPDATE CASCADE,
+ CONSTRAINT `order_ibfk_9` FOREIGN KEY (`agency_id`) REFERENCES `vn2008`.`Agencias` (`Id_Agencia`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=1209359 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `orderCheck`
+--
+
+DROP TABLE IF EXISTS `orderCheck`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `orderCheck` (
+ `id` tinyint(1) unsigned NOT NULL AUTO_INCREMENT,
+ `maxTime` time NOT NULL,
+ `denySunday` tinyint(1) NOT NULL,
+ `denyDay` date DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Conditions to check when an order is confirmed';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `orderCheckFestive`
+--
+
+DROP TABLE IF EXISTS `orderCheckFestive`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `orderCheckFestive` (
+ `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
+ `date` date NOT NULL,
+ `acceptOrders` tinyint(1) NOT NULL DEFAULT '1',
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `date` (`date`)
+) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `orderCheckWday`
+--
+
+DROP TABLE IF EXISTS `orderCheckWday`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `orderCheckWday` (
+ `weekday` tinyint(3) unsigned NOT NULL COMMENT '0 = Monday, 6 = Sunday',
+ `maxTime` time NOT NULL,
+ PRIMARY KEY (`weekday`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `orderConfig`
+--
+
+DROP TABLE IF EXISTS `orderConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `orderConfig` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `employeeFk` int(11) NOT NULL,
+ `deliveryAgencyFk` int(11) NOT NULL,
+ `guestMethod` varchar(45) CHARACTER SET utf8 NOT NULL,
+ `guestAgencyFk` int(11) NOT NULL,
+ `reserveTime` time NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `employee_id` (`employeeFk`),
+ KEY `delivery_agency` (`deliveryAgencyFk`)
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `orderRow`
+--
+
+DROP TABLE IF EXISTS `orderRow`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `orderRow` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `orderFk` int(10) unsigned NOT NULL DEFAULT '0',
+ `itemFk` int(11) NOT NULL DEFAULT '0',
+ `warehouseFk` int(11) DEFAULT NULL,
+ `shipment` date DEFAULT NULL,
+ `amount` smallint(6) unsigned NOT NULL DEFAULT '0',
+ `price` decimal(10,2) DEFAULT NULL,
+ `rate` smallint(5) unsigned DEFAULT NULL,
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `saleFk` int(11) DEFAULT NULL COMMENT 'Deprecated',
+ PRIMARY KEY (`id`),
+ KEY `item` (`itemFk`),
+ KEY `order_id` (`orderFk`),
+ KEY `created` (`created`),
+ KEY `warehouse_shipment` (`warehouseFk`,`shipment`),
+ CONSTRAINT `orderRow_ibfk_2` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON UPDATE CASCADE,
+ CONSTRAINT `orderRow_ibfk_3` FOREIGN KEY (`orderFk`) REFERENCES `order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=7531286 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 `orderRowBeforeInsert`
+ BEFORE INSERT ON `orderRow`
+ FOR EACH ROW
+BEGIN
+ DECLARE vIsFirst BOOL;
+
+ SELECT (first_row_stamp IS NULL) INTO vIsFirst
+ FROM `order`
+ WHERE id = NEW.orderFk;
+
+ IF vIsFirst THEN
+ UPDATE `order` SET first_row_stamp = NOW()
+ WHERE id = NEW.orderFk;
+ 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 `orderRowComponent`
+--
+
+DROP TABLE IF EXISTS `orderRowComponent`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `orderRowComponent` (
+ `rowFk` int(10) unsigned NOT NULL,
+ `componentFk` int(11) NOT NULL,
+ `price` decimal(12,4) NOT NULL,
+ PRIMARY KEY (`rowFk`,`componentFk`),
+ KEY `component_id` (`componentFk`),
+ CONSTRAINT `orderRowComponent_ibfk_1` FOREIGN KEY (`rowFk`) REFERENCES `orderRow` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `order_basket`
+--
+
+DROP TABLE IF EXISTS `order_basket`;
+/*!50001 DROP VIEW IF EXISTS `order_basket`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `order_basket` AS SELECT
+ 1 AS `customer_id`,
+ 1 AS `order_id`*/;
+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_config`
+--
+
+DROP TABLE IF EXISTS `order_config`;
+/*!50001 DROP VIEW IF EXISTS `order_config`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `order_config` AS SELECT
+ 1 AS `id`,
+ 1 AS `employee_id`,
+ 1 AS `delivery_agency`,
+ 1 AS `guest_method`,
+ 1 AS `guest_agency`,
+ 1 AS `reserve_time`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `order_confirm_time`
+--
+
+DROP TABLE IF EXISTS `order_confirm_time`;
+/*!50001 DROP VIEW IF EXISTS `order_confirm_time`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `order_confirm_time` AS SELECT
+ 1 AS `date_make`,
+ 1 AS `source_app`,
+ 1 AS `customer_id`,
+ 1 AS `confirm_date`,
+ 1 AS `first_row_stamp`,
+ 1 AS `minutos`*/;
+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;
+
+--
+-- Temporary view structure for view `order_row_view`
+--
+
+DROP TABLE IF EXISTS `order_row_view`;
+/*!50001 DROP VIEW IF EXISTS `order_row_view`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `order_row_view` AS SELECT
+ 1 AS `id`,
+ 1 AS `order_id`,
+ 1 AS `warehouse_id`,
+ 1 AS `item_id`,
+ 1 AS `amount`,
+ 1 AS `price2`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `order_view`
+--
+
+DROP TABLE IF EXISTS `order_view`;
+/*!50001 DROP VIEW IF EXISTS `order_view`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `order_view` 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 `note`,
+ 1 AS `address_id`,
+ 1 AS `company_id`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `restPriv`
+--
+
+DROP TABLE IF EXISTS `restPriv`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `restPriv` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `methodPath` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `role` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `role` (`role`),
+ CONSTRAINT `restPriv_ibfk_1` FOREIGN KEY (`role`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `shelf`
+--
+
+DROP TABLE IF EXISTS `shelf`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `shelf` (
+ `id` int(10) unsigned NOT NULL,
+ `name` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
+ `nTrays` tinyint(3) unsigned NOT NULL,
+ `trayheight` mediumint(8) unsigned NOT NULL,
+ `topTrayHeight` mediumint(8) unsigned NOT NULL,
+ `width` mediumint(8) unsigned NOT NULL,
+ `depth` mediumint(8) unsigned NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Dimensiones de las estanterias';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `shelfConfig`
+--
+
+DROP TABLE IF EXISTS `shelfConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `shelfConfig` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `name` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
+ `namePrefix` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `warehouse` smallint(5) unsigned NOT NULL,
+ `family` smallint(5) unsigned NOT NULL,
+ `shelf` int(10) unsigned NOT NULL,
+ `maxAmount` smallint(5) unsigned DEFAULT NULL,
+ `showPacking` tinyint(4) NOT NULL,
+ `stack` tinyint(4) NOT NULL DEFAULT '0',
+ PRIMARY KEY (`id`),
+ KEY `shelf_id` (`shelf`),
+ KEY `family_id` (`family`),
+ KEY `warehouse_id` (`warehouse`),
+ CONSTRAINT `shelfConfig_ibfk_1` FOREIGN KEY (`family`) REFERENCES `vn2008`.`Tipos` (`tipo_id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `shelfConfig_ibfk_2` FOREIGN KEY (`shelf`) REFERENCES `shelf` (`id`) ON UPDATE CASCADE,
+ CONSTRAINT `shelfConfig_ibfk_3` FOREIGN KEY (`warehouse`) REFERENCES `vn2008`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `social`
+--
+
+DROP TABLE IF EXISTS `social`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `social` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `title` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `link` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `icon` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `priority` tinyint(3) unsigned NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `priority` (`priority`)
+) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `survey`
+--
+
+DROP TABLE IF EXISTS `survey`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `survey` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `question` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`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 `surveyAnswer`
+--
+
+DROP TABLE IF EXISTS `surveyAnswer`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `surveyAnswer` (
+ `id` int(10) unsigned NOT NULL,
+ `surveyFk` int(10) unsigned NOT NULL,
+ `answer` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
+ `votes` int(10) unsigned NOT NULL DEFAULT '0',
+ PRIMARY KEY (`id`),
+ KEY `survey` (`surveyFk`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `surveyVote`
+--
+
+DROP TABLE IF EXISTS `surveyVote`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `surveyVote` (
+ `surveyFk` int(10) unsigned NOT NULL,
+ `userFk` int(10) unsigned NOT NULL,
+ PRIMARY KEY (`surveyFk`,`userFk`),
+ KEY `surveyVote_ibfk_2` (`userFk`),
+ CONSTRAINT `surveyVote_ibfk_1` FOREIGN KEY (`surveyFk`) REFERENCES `survey` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `surveyVote_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `ticket_row_view`
+--
+
+DROP TABLE IF EXISTS `ticket_row_view`;
+/*!50001 DROP VIEW IF EXISTS `ticket_row_view`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ticket_row_view` AS SELECT
+ 1 AS `id`,
+ 1 AS `item_id`,
+ 1 AS `ticket_id`,
+ 1 AS `concept`,
+ 1 AS `amount`,
+ 1 AS `price`,
+ 1 AS `fixed`,
+ 1 AS `discount`,
+ 1 AS `cost`,
+ 1 AS `reserved`,
+ 1 AS `ok`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Temporary view structure for view `ticket_view`
+--
+
+DROP TABLE IF EXISTS `ticket_view`;
+/*!50001 DROP VIEW IF EXISTS `ticket_view`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `ticket_view` AS SELECT
+ 1 AS `id`,
+ 1 AS `customer_id`,
+ 1 AS `warehouse_id`,
+ 1 AS `date`,
+ 1 AS `delivery`,
+ 1 AS `alias`,
+ 1 AS `agency_id`,
+ 1 AS `note`,
+ 1 AS `invoice`,
+ 1 AS `address_id`,
+ 1 AS `employee_id`,
+ 1 AS `comments`,
+ 1 AS `signed`,
+ 1 AS `packages`,
+ 1 AS `location`,
+ 1 AS `hour`,
+ 1 AS `blocked`,
+ 1 AS `solution`,
+ 1 AS `company_id`,
+ 1 AS `type`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `tpvConfig`
+--
+
+DROP TABLE IF EXISTS `tpvConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `tpvConfig` (
+ `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
+ `currency` smallint(5) unsigned NOT NULL,
+ `terminal` tinyint(3) unsigned NOT NULL,
+ `transactionType` tinyint(3) unsigned NOT NULL,
+ `maxAmount` int(10) unsigned DEFAULT NULL,
+ `employeeFk` int(10) NOT NULL,
+ `url` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The bank web service URL for production environment',
+ `testMode` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'Whether test mode is enabled',
+ `testUrl` varchar(255) CHARACTER SET utf8 DEFAULT NULL COMMENT 'The bank web service URL for test environment',
+ `testKey` varchar(50) CHARACTER SET utf8 DEFAULT NULL COMMENT 'The bank secret key for test environment',
+ `merchantUrl` varchar(255) CHARACTER SET utf8 DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `employee_id` (`employeeFk`),
+ CONSTRAINT `employee_id` FOREIGN KEY (`employeeFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Virtual TPV parameters';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `tpvError`
+--
+
+DROP TABLE IF EXISTS `tpvError`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `tpvError` (
+ `code` char(7) COLLATE utf8_unicode_ci NOT NULL,
+ `message` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`code`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT=' List of possible TPV errors';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `tpvImapConfig`
+--
+
+DROP TABLE IF EXISTS `tpvImapConfig`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `tpvImapConfig` (
+ `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
+ `host` varchar(150) COLLATE utf8_unicode_ci NOT NULL,
+ `user` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `pass` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
+ `cleanPeriod` varchar(15) CHARACTER SET utf8 NOT NULL,
+ `successFolder` varchar(150) CHARACTER SET utf8 DEFAULT NULL,
+ `errorFolder` varchar(150) CHARACTER SET utf8 DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='IMAP configuration parameters for virtual TPV';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `tpvMerchant`
+--
+
+DROP TABLE IF EXISTS `tpvMerchant`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `tpvMerchant` (
+ `id` int(10) unsigned NOT NULL COMMENT 'Merchant identifier',
+ `description` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Small description',
+ `companyFk` smallint(6) unsigned DEFAULT NULL COMMENT 'Company associated with the merchant',
+ `bankFk` int(10) NOT NULL COMMENT 'The bank where merchant receipts are created',
+ `secretKey` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The merchant secret key to sign transactions',
+ PRIMARY KEY (`id`),
+ KEY `bank_id` (`bankFk`),
+ KEY `company_id` (`companyFk`),
+ KEY `id` (`id`,`companyFk`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Virtual TPV providers';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `tpvMerchantEnable`
+--
+
+DROP TABLE IF EXISTS `tpvMerchantEnable`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `tpvMerchantEnable` (
+ `merchantFk` int(10) unsigned NOT NULL DEFAULT '0',
+ `companyFk` smallint(6) unsigned NOT NULL,
+ PRIMARY KEY (`merchantFk`,`companyFk`),
+ UNIQUE KEY `company_id` (`companyFk`),
+ CONSTRAINT `tpvMerchantEnable_ibfk_1` FOREIGN KEY (`merchantFk`, `companyFk`) REFERENCES `tpvMerchant` (`id`, `companyFk`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Virtual TPV enabled providers';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `tpvResponse`
+--
+
+DROP TABLE IF EXISTS `tpvResponse`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `tpvResponse` (
+ `id` smallint(5) unsigned NOT NULL,
+ `message` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='List of possible TPV reponses';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `tpvTransaction`
+--
+
+DROP TABLE IF EXISTS `tpvTransaction`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `tpvTransaction` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `merchantFk` int(10) unsigned NOT NULL,
+ `clientFk` int(11) NOT NULL,
+ `receiptFk` int(11) DEFAULT NULL,
+ `amount` int(10) unsigned NOT NULL,
+ `response` smallint(5) unsigned DEFAULT NULL COMMENT 'Status notified by bank: NULL if no notification, 0 if success, error otherwise',
+ `errorCode` char(7) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `status` enum('started','ok','ko') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'started',
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`),
+ KEY `merchant_id` (`merchantFk`),
+ KEY `receipt_id` (`receiptFk`),
+ KEY `user_id` (`clientFk`),
+ KEY `response` (`response`),
+ KEY `error_code` (`errorCode`),
+ CONSTRAINT `receipt_id` FOREIGN KEY (`receiptFk`) REFERENCES `vn2008`.`Recibos` (`Id`) ON DELETE SET NULL ON UPDATE CASCADE,
+ CONSTRAINT `tpvTransaction_ibfk_1` FOREIGN KEY (`clientFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `tpvTransaction_ibfk_2` FOREIGN KEY (`merchantFk`) REFERENCES `tpvMerchant` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=181005 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Transactions realized through the virtual TPV';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `userSession`
+--
+
+DROP TABLE IF EXISTS `userSession`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `userSession` (
+ `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `lastUpdate` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `ssid` char(64) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `data` text COLLATE utf8_unicode_ci,
+ `userVisit` int(10) unsigned DEFAULT NULL,
+ UNIQUE KEY `ssid` (`ssid`),
+ KEY `userVisit` (`userVisit`),
+ KEY `lastUpdate` (`lastUpdate`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Temporary view structure for view `user_android`
+--
+
+DROP TABLE IF EXISTS `user_android`;
+/*!50001 DROP VIEW IF EXISTS `user_android`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `user_android` AS SELECT
+ 1 AS `android_id`,
+ 1 AS `user_id`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `visit`
+--
+
+DROP TABLE IF EXISTS `visit`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `visit` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `firstAgent` int(10) unsigned DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `firstAgent` (`firstAgent`),
+ CONSTRAINT `visit_ibfk_1` FOREIGN KEY (`firstAgent`) REFERENCES `visitAgent` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=1112123 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `visitAccess`
+--
+
+DROP TABLE IF EXISTS `visitAccess`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `visitAccess` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `agent` int(10) unsigned NOT NULL,
+ `stamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `ip` int(10) unsigned DEFAULT NULL,
+ `referer` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `visit_access_idx_agent` (`agent`),
+ KEY `stamp` (`stamp`),
+ CONSTRAINT `visitAccess_ibfk_1` FOREIGN KEY (`agent`) REFERENCES `visitAgent` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=2356472 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `visitAgent`
+--
+
+DROP TABLE IF EXISTS `visitAgent`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `visitAgent` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `visit` int(10) unsigned NOT NULL,
+ `firstAccess` int(10) unsigned DEFAULT NULL,
+ `platform` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `browser` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `version` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `javascript` tinyint(3) unsigned DEFAULT NULL,
+ `cookies` tinyint(3) unsigned DEFAULT NULL,
+ `agent` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `visit_id` (`visit`),
+ KEY `firstAccess` (`firstAccess`),
+ CONSTRAINT `visitAgent_ibfk_1` FOREIGN KEY (`visit`) REFERENCES `visit` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `visitAgent_ibfk_2` FOREIGN KEY (`firstAccess`) REFERENCES `visitAccess` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=1627507 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `visitUser`
+--
+
+DROP TABLE IF EXISTS `visitUser`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `visitUser` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `access` int(10) unsigned NOT NULL,
+ `user` int(10) unsigned DEFAULT NULL,
+ `stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`),
+ KEY `access_id` (`access`),
+ KEY `date_time` (`stamp`),
+ KEY `user_id` (`user`),
+ CONSTRAINT `visitUser_ibfk_1` FOREIGN KEY (`access`) REFERENCES `visitAccess` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB AUTO_INCREMENT=2309412 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping events for database 'hedera'
+--
+
+--
+-- Dumping routines for database 'hedera'
+--
+/*!50003 DROP FUNCTION IF EXISTS `basketGetId` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `basketGetId`() RETURNS int(11)
+ DETERMINISTIC
+BEGIN
+ DECLARE v_order INT;
+
+ SELECT order_id INTO v_order FROM order_basket
+ WHERE customer_id = account.userGetId();
+
+ RETURN v_order;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `clientGetDebt` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `clientGetDebt`(vDate DATE) RETURNS decimal(10,2)
+BEGIN
+/**
+ * Calcula el saldo del cliente actual.
+ *
+ * @return Saldo del cliente
+ */
+ RETURN vn.clientGetDebt(account.userGetId(), vDate);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `invoiceGetPath` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `invoiceGetPath`(vInvoice INT) RETURNS varchar(255) CHARSET utf8
+BEGIN
+ DECLARE vIssued DATE;
+ DECLARE vSerial VARCHAR(15);
+
+ SELECT issued, ref
+ INTO vIssued, vSerial
+ FROM vn.invoiceOut WHERE id = vInvoice;
+
+ RETURN CONCAT_WS('/'
+ ,'invoice'
+ ,YEAR(vIssued)
+ ,MONTH(vIssued)
+ ,DAY(vIssued)
+ ,CONCAT(YEAR(vIssued), vSerial, '.pdf')
+ );
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `orderGetTotal` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `orderGetTotal`(vOrder INT) RETURNS decimal(10,2)
+ READS SQL DATA
+ DETERMINISTIC
+BEGIN
+/**
+ * Obtiene el total de un pedido con el IVA y el recargo de
+ * equivalencia incluidos.
+ *
+ * @param vOrder El identificador del pedido
+ * @return El total del pedido
+ */
+ DECLARE vTotal DECIMAL(10,2);
+
+ CALL orderGetTax (vOrder);
+
+ SELECT SUM(taxBase) + SUM(tax) + SUM(equalizationTax) INTO vTotal
+ FROM tmp.orderTax;
+
+ DROP TEMPORARY TABLE tmp.orderTax;
+
+ RETURN vTotal;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `order_get_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 `order_get_total`(vOrder INT) RETURNS decimal(10,2)
+ READS SQL DATA
+ DETERMINISTIC
+BEGIN
+/**
+ * Obtiene el total de un pedido con el IVA y el recargo de
+ * equivalencia incluidos.
+ *
+ * @deprecated Use function orderGetTotal() instead
+ *
+ * @param vOrder El identificador del pedido
+ * @return El total del pedido
+ */
+ RETURN orderGetTotal (vOrder);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `userCheckRestPriv` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `userCheckRestPriv`(vMethodPath VARCHAR(255)) RETURNS tinyint(1)
+ DETERMINISTIC
+BEGIN
+/**
+ * Comprueba si el usuario actual tiene permiso para ejecutar
+ * un servicio REST.
+ *
+ * @param vMethodPath Ruta del servicio REST a ejecutar
+ * @return %TRUE si tiene permisos, %FALSE en caso contrario
+ **/
+ DECLARE vRole INT DEFAULT NULL;
+
+ SELECT role INTO vRole FROM restPriv
+ WHERE methodPath = vMethodPath;
+
+ RETURN vRole IS NULL
+ OR account.userHasRoleId (vRole);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `basketAddItem` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `basketAddItem`(
+ vWarehouse INT,
+ vItem INT,
+ vAmount INT)
+BEGIN
+ DECLARE vOrder INT;
+ DECLARE vRow INT;
+ DECLARE vAdd INT;
+ DECLARE vAvailable INT;
+ DECLARE vDone BOOL;
+ DECLARE vGrouping INT;
+ DECLARE vRate INT;
+ DECLARE vShipment DATE;
+ DECLARE vPrice DECIMAL(10,2);
+
+ DECLARE cur CURSOR FOR
+ SELECT grouping, price, rate
+ FROM tmp.bionic_price
+ WHERE warehouse_id = vWarehouse
+ AND item_id = vItem
+ ORDER BY grouping DESC;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND
+ SET vDone = TRUE;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ ROLLBACK;
+ RESIGNAL;
+ END;
+
+ CALL bionic_from_item (vItem);
+
+ START TRANSACTION;
+
+ SET vOrder = basketGetId();
+
+ SELECT Fecha_envio INTO vShipment
+ FROM tmp.travel_tree
+ WHERE warehouse_id = vWarehouse;
+
+ SELECT available INTO vAvailable
+ FROM tmp.bionic_lot
+ WHERE warehouse_id = vWarehouse
+ AND item_id = vItem;
+
+ IF vAmount > vAvailable
+ THEN
+ CALL util.throw ('ORDER_ROW_UNAVAILABLE');
+ END IF;
+
+ OPEN cur;
+
+ l: LOOP
+ SET vDone = FALSE;
+ FETCH cur INTO vGrouping, vPrice, vRate;
+
+ IF vDone THEN
+ LEAVE l;
+ END IF;
+
+ SET vAdd = vAmount - MOD(vAmount, vGrouping);
+ SET vAmount = vAmount - vAdd;
+
+ IF vAdd = 0 THEN
+ ITERATE l;
+ END IF;
+
+ INSERT INTO order_row SET
+ order_id = vOrder,
+ item_id = vItem,
+ warehouse_id = vWarehouse,
+ shipment = vShipment,
+ rate = vRate,
+ amount = vAdd,
+ price = vPrice;
+
+ SET vRow = LAST_INSERT_ID();
+
+ INSERT INTO order_component (order_row_id, component_id, price)
+ SELECT vRow, c.component_id, c.cost
+ FROM tmp.bionic_component c
+ JOIN bi.tarifa_componentes t
+ ON t.Id_Componente = c.component_id
+ AND (t.tarifa_class IS NULL OR t.tarifa_class = vRate)
+ WHERE c.warehouse_id = vWarehouse
+ AND c.item_id = vItem;
+ END LOOP;
+
+ CLOSE cur;
+ COMMIT;
+
+ CALL vn2008.bionic_free ();
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `basketCheck` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `basketCheck`()
+BEGIN
+/**
+ * Comprueba que la cesta esta creada y que su configuración es
+ * correcta. Si la configuración es correcta pero lleva mucho
+ * tiempo creada actualiza los precios y cantidades de los artículos.
+ *
+ * @select El id del pedido y el estado de la cesta
+ */
+ DECLARE vOrder INT;
+ DECLARE vCreated DATETIME;
+ DECLARE vStatus VARCHAR(15) DEFAULT 'OK';
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vStatus = 'NOT_EXISTS';
+ DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET vStatus = 'BAD_CONFIG';
+
+ SELECT id, date_make
+ INTO vOrder, vCreated
+ FROM basket;
+
+ IF vStatus = 'OK'
+ THEN
+ CALL orderCheckConfig (vOrder);
+
+ IF vStatus = 'OK' AND vCreated < TIMESTAMPADD(DAY, -1, NOW())
+ THEN
+ CALL orderUpdate (vOrder);
+ SET vStatus = 'UPDATED';
+ END IF;
+ END IF;
+
+ SELECT vStatus stat;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `basketConfigure` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `basketConfigure`(
+ vDelivery DATE,
+ vDeliveryMethod VARCHAR(45),
+ vAgency INT,
+ vAddress INT)
+BEGIN
+/**
+ * Configura la cesta de la compra utilizando los parámetros
+ * pasados. Si los parámetros no son válidos devuelve un error.
+ *
+ * @param vDelivery Fecha de recogida
+ * @param vAgency Id de la agencia
+ * @param vAddress Id de dirección de envío, @NULL si es recogida
+ */
+ DECLARE vOrder INT;
+ DECLARE vCompany INT;
+ DECLARE vDeliveryMethodId INT;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vOrder = NULL;
+ DECLARE EXIT HANDLER FOR SQLSTATE '45000'
+ BEGIN
+ ROLLBACK;
+ RESIGNAL;
+ END;
+
+ START TRANSACTION;
+
+ SELECT id INTO vDeliveryMethodId
+ FROM vn.deliveryMethod
+ WHERE code = vDeliveryMethod;
+
+ IF vDeliveryMethod = 'DELIVERY'
+ THEN
+ SELECT delivery_agency INTO vAgency
+ FROM order_config;
+ END IF;
+
+ IF vDeliveryMethod = 'PICKUP' AND vAddress IS NULL
+ THEN
+ SELECT default_address INTO vAddress
+ FROM customer_view;
+ END IF;
+
+ SET vOrder = basketGetId();
+
+ IF vOrder IS NULL
+ THEN
+ SELECT empresa_id INTO vCompany
+ FROM vn2008.Clientes_empresa
+ WHERE Id_Cliente = account.userGetId()
+ AND CURDATE() BETWEEN fecha_ini AND fecha_fin
+ LIMIT 1;
+
+ INSERT INTO `order`
+ SET
+ customer_id = account.userGetId(),
+ date_send = vDelivery,
+ delivery_method_id = vDeliveryMethodId,
+ agency_id = vAgency,
+ address_id = vAddress,
+ source_app = 'WEB',
+ company_id = IFNULL(vCompany, 442);
+
+ SET vOrder = LAST_INSERT_ID();
+
+ INSERT INTO order_basket SET
+ customer_id = account.userGetId(),
+ order_id = vOrder;
+ ELSE
+ UPDATE `order`
+ SET
+ date_send = vDelivery,
+ delivery_method_id = vDeliveryMethodId,
+ agency_id = vAgency,
+ address_id = vAddress
+ WHERE
+ id = vOrder;
+
+ CALL orderUpdate (vOrder);
+ END IF;
+
+ CALL orderCheckConfig (vOrder);
+
+ 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 `basketConfigureForGuest` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `basketConfigureForGuest`()
+BEGIN
+ DECLARE vMethod VARCHAR(45);
+ DECLARE vAgency INT;
+
+ SELECT guest_method, guest_agency
+ INTO vMethod, vAgency
+ FROM order_config
+ LIMIT 1;
+
+ CALL basketConfigure (CURDATE(), vMethod, vAgency, 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 `basketConfirm` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `basketConfirm`()
+BEGIN
+ DECLARE vOrder INT DEFAULT basketGetId ();
+
+ IF vOrder IS NOT NULL
+ THEN
+ CALL order_confirm_bionic (vOrder);
+
+ DELETE FROM order_basket
+ WHERE order_id = vOrder;
+ 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 `basketGetTax` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `basketGetTax`()
+ READS SQL DATA
+BEGIN
+/**
+ * Returns the taxes for the current client basket.
+ *
+ * @treturn tmp.orderTax
+ */
+ CALL orderGetTax (basketGetId());
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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`()
+BEGIN
+ DECLARE v_date DATE;
+ DECLARE v_address INT;
+ DECLARE v_agency INT;
+
+ SELECT date_send, address_id, agency_id
+ INTO v_date, v_address, v_agency
+ FROM basket;
+
+ CALL vn2008.bionic_calc (v_date, v_address, v_agency);
+
+ IF account.userGetName () = 'visitor'
+ THEN
+ DROP TEMPORARY TABLE tmp.bionic_component;
+ UPDATE tmp.bionic_item SET price = 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 DROP PROCEDURE IF EXISTS `bionic_from_basket` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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_basket`()
+BEGIN
+ DECLARE v_order INT;
+ DECLARE v_date DATE;
+ DECLARE v_address INT;
+ DECLARE v_agency INT;
+
+ SELECT id, date_send, address_id, agency_id
+ INTO v_order, v_date, v_address, v_agency
+ FROM basket;
+
+ CALL vn2008.bionic_from_order (v_date, v_address, v_agency, v_order);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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_item INT)
+BEGIN
+ DECLARE v_date DATE;
+ DECLARE v_address INT;
+ DECLARE v_agency INT;
+
+ SELECT date_send, address_id, agency_id
+ INTO v_date, v_address, v_agency
+ FROM basket;
+
+ CALL vn2008.bionic_from_item (v_date, v_address, v_agency, v_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 `catalogGetAvailable` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `catalogGetAvailable`()
+BEGIN
+/**
+ * Gets the available items list that meets the tag filter.
+ *
+ * @table tItems
+ */
+ CALL itemGetAvailable;
+
+ DELETE t FROM tItems t
+ JOIN tmp.itemAvailable a ON a.id = t.id
+ WHERE a.id IS NULL;
+
+ DROP TEMPORARY TABLE tmp.itemAvailable;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `catalogGetItems` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `catalogGetItems`()
+BEGIN
+/**
+ * Returns the list of items.
+ *
+ * @table tItems The list of items
+ * @select The list of items
+ */
+ DROP TEMPORARY TABLE IF EXISTS tmp.bionic_calc;
+ CREATE TEMPORARY TABLE tmp.bionic_calc
+ (INDEX (item_id))
+ ENGINE = MEMORY
+ SELECT id item_id FROM tItems;
+
+ CALL bionic_calc ();
+ DROP TEMPORARY TABLE tmp.bionic_calc;
+
+ SELECT i.id, i.name, i.description, i.category, i.size, i.image, i.inkFk,
+ IF(i.stems > 1, i.stems, NULL) stems, b.available, b.price, b.producer,
+ a.tag1, a.val1, a.tag2, a.val2, a.tag3, a.val3
+ FROM tmp.bionic_item b
+ JOIN vn.item i ON i.id = b.item_id
+ LEFT JOIN vn.itemTagArranged a ON a.itemFk = i.id
+ LEFT JOIN vn.producer p ON p.id = i.producerFk
+ WHERE b.available > 0
+ ORDER BY i.relevancy DESC, i.name, i.size
+ LIMIT 40;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `catalogGetTags` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `catalogGetTags`(vLimit INT)
+BEGIN
+/**
+ * Returns the main tags for a list of items.
+ *
+ * @table tItems The list of items
+ * @select The main tags for the passed items
+ */
+ CALL catalogGetAvailable;
+
+ DROP TEMPORARY TABLE IF EXISTS tTags;
+ CREATE TEMPORARY TABLE tTags
+ (INDEX (tagFk))
+ ENGINE = MEMORY
+ SELECT it.tagFk, SUM(it.priority) priority
+ FROM vn.itemTag it
+ JOIN tItems i ON i.id = it.itemFk
+ GROUP BY tagFk
+ LIMIT vLimit;
+
+ SELECT l.id, l.name
+ FROM tTags t
+ JOIN vn.tagL10n l ON l.id = t.tagFk
+ ORDER BY priority DESC;
+
+ DROP TEMPORARY TABLE tTags;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `catalogGetTagValues` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `catalogGetTagValues`(vTag INT)
+BEGIN
+/**
+ * Returns the list of available values for a tag and a list of items.
+ *
+ * @table tItems The list of items
+ * @param vTag The tag identifier
+ * @select The list of available tags
+ */
+ CALL catalogGetAvailable;
+
+ SELECT DISTINCT it.value
+ FROM vn.itemTag it
+ JOIN tItems i ON i.id = it.itemFk
+ WHERE it.tagFk = vTag
+ ORDER BY value
+ LIMIT 200;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `itemAllocator` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `itemAllocator`(
+ vWh TINYINT
+ ,vDate DATE
+ ,vType INT
+ ,vPrefix VARCHAR(255)
+ ,vUseIds BOOLEAN
+)
+BEGIN
+ DECLARE vPrefixLen SMALLINT;
+ DECLARE vFilter VARCHAR(255) DEFAULT NULL;
+ DECLARE vDateInv DATE DEFAULT vn2008.date_inv();
+
+ SET vPrefixLen = LENGTH(vPrefix);
+
+ IF vPrefix IS NOT NULL AND vPrefixLen > 0
+ THEN
+ SET vFilter = CONCAT(vPrefix, '%');
+ SET vPrefixLen = vPrefixLen + 1;
+ END IF;
+
+ DROP TEMPORARY TABLE IF EXISTS filter;
+ CREATE TEMPORARY TABLE filter
+ (INDEX (item_id))
+ ENGINE = MEMORY
+ SELECT Id_Article item_id FROM vn2008.Articles
+ WHERE tipo_id = vType
+ AND (vFilter IS NULL OR Article LIKE vFilter);
+
+ DROP TEMPORARY TABLE IF EXISTS current_stock;
+ CREATE TEMPORARY TABLE current_stock
+ (INDEX (item_id))
+ ENGINE = MEMORY
+ SELECT item_id, SUM(Cantidad) amount FROM
+ (
+ SELECT Id_Article item_id, Cantidad
+ FROM vn2008.Compres c
+ JOIN vn2008.Entradas e USING(Id_Entrada)
+ JOIN vn2008.travel t ON t.id = e.travel_id
+ WHERE landing BETWEEN vDateInv AND vDate
+ AND warehouse_id = vWh
+ AND NOT Redada
+ UNION ALL
+ SELECT Id_Article, -Cantidad
+ FROM vn2008.Compres c
+ JOIN vn2008.Entradas e USING(Id_Entrada)
+ JOIN vn2008.travel t ON t.id = e.travel_id
+ WHERE shipment BETWEEN vDateInv AND CURDATE()
+ AND warehouse_id_out = vWh
+ AND NOT Redada
+ AND delivered
+ UNION ALL
+ SELECT m.Id_Article, -m.Cantidad
+ FROM vn2008.Movimientos m
+ JOIN vn2008.Tickets t USING(Id_Ticket)
+ JOIN vn.ticketState s ON s.ticket = t.Id_Ticket
+ WHERE t.Fecha BETWEEN vDateInv AND CURDATE()
+ AND t.warehouse_id = vWh
+ AND (t.Etiquetasemitidas OR s.alertLevel = 3)
+ ) t
+ GROUP BY item_id
+ HAVING amount > 0;
+
+ DROP TEMPORARY TABLE IF EXISTS tmp;
+ CREATE TEMPORARY TABLE tmp
+ (INDEX (item_id))
+ ENGINE = MEMORY
+ SELECT * FROM
+ (
+ SELECT c.Id_Article item_id, c.Id_Compra id, c.Id_Cubo, c.packing
+ FROM vn2008.Compres c
+ JOIN vn2008.Entradas e USING(Id_Entrada)
+ JOIN vn2008.travel t ON t.id = e.travel_id
+ WHERE t.landing BETWEEN vDateInv AND vDate
+ AND c.Novincular = FALSE
+ AND c.Tarifa2 >= 0
+ AND Id_Cubo IS NOT NULL
+ ORDER BY t.warehouse_id = 1 DESC, t.landing DESC
+ ) t GROUP BY item_id;
+
+ DROP TEMPORARY TABLE IF EXISTS result;
+ CREATE TEMPORARY TABLE result
+ ENGINE = MEMORY
+ SELECT a.Id_Article, IF(vPrefixLen > 0, SUBSTRING(a.Article, vPrefixLen), a.Article) Article,
+ t.packing, CEIL(s.amount / t.packing) etiquetas, t.Id_Cubo, IF(c.z > 0, c.z, 0) z, c.x, c.y, a.Nicho
+ FROM vn2008.Articles a
+ JOIN filter f ON f.item_id = a.Id_Article
+ JOIN current_stock s ON s.item_id = a.Id_Article
+ LEFT JOIN tmp t ON t.item_id = a.Id_Article
+ LEFT JOIN vn2008.Cubos c ON c.Id_Cubo = t.Id_Cubo
+ WHERE CEIL(s.amount / t.packing) > 0
+ AND c.box;
+
+ IF vUseIds
+ THEN
+ SELECT * FROM result
+ ORDER BY Id_Article;
+ ELSE
+ SELECT * FROM result
+ ORDER BY Article, packing;
+ END IF;
+
+ DROP TEMPORARY TABLE
+ filter,
+ current_stock,
+ tmp,
+ result;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `itemGetAvailable` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `itemGetAvailable`()
+BEGIN
+/**
+ * Gets the available items list.
+ *
+ * @table tmp.itemAvailable
+ */
+ DECLARE vDelivery DATE;
+ DECLARE vAddress INT;
+ DECLARE vAgency INT;
+
+ SELECT date_send, address_id, agency_id
+ INTO vDelivery, vAddress, vAgency
+ FROM basket;
+
+ CALL vn2008.bionic_available_ (vDelivery, vAddress, vAgency);
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.itemAvailable;
+ CREATE TEMPORARY TABLE tmp.itemAvailable
+ (INDEX (id))
+ ENGINE = MEMORY
+ SELECT c.item_id id
+ FROM cache.available c
+ JOIN vn2008.t_bionic_available a ON c.calc_id = a.calc_id
+ WHERE c.available > 0
+ GROUP BY c.item_id;
+
+ DROP TEMPORARY TABLE vn2008.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 `item_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 = '' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `item_available`()
+BEGIN
+/**
+ * Genera una tabla con los ids de los articulos disponibles.
+ *
+ * @table tmp.item_available
+ **/
+ DECLARE v_delivery DATE;
+ DECLARE v_address INT;
+ DECLARE v_agency INT;
+
+ SELECT date_send, address_id, agency_id
+ INTO v_delivery, v_address, v_agency
+ FROM basket;
+
+ CALL vn2008.bionic_available_ (v_delivery, v_address, v_agency);
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.item_available;
+ CREATE TEMPORARY TABLE tmp.item_available
+ (INDEX (item_id))
+ ENGINE = MEMORY
+ SELECT c.item_id
+ FROM `cache`.available c
+ JOIN vn2008.t_bionic_available a ON c.calc_id = a.calc_id
+ WHERE c.available > 0
+ GROUP BY c.item_id;
+
+ DROP TEMPORARY TABLE vn2008.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 `item_list` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `item_list`(v_warehouse SMALLINT, v_shipping DATE, v_realm INT, v_rate TINYINT)
+BEGIN
+ DECLARE v_calc INT;
+
+ CALL cache.available_refresh (v_calc, TRUE, v_warehouse, v_shipping);
+ CALL vn2008.item_last_buy_ (v_warehouse, v_shipping);
+
+ SELECT a.Id_Article, a.Article, a.Categoria, a.Medida, a.Tallos,
+ c.available, a.Color, o.Abreviatura, t.Tipo, a.tipo_id, a.Foto,
+ CASE b.caja
+ WHEN 0 THEN 1
+ WHEN 2 THEN b.packing
+ ELSE b.grouping
+ END AS grouping,
+ CASE v_rate
+ WHEN 1 THEN b.Tarifa1
+ WHEN 2 THEN b.Tarifa2
+ WHEN 3 THEN b.Tarifa3
+ ELSE NULL
+ END AS price
+ FROM cache.available c
+ JOIN vn2008.Articles a ON a.Id_Article = c.item_id
+ JOIN vn2008.t_item_last_buy l ON l.item_id = c.item_id
+ JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id
+ JOIN vn2008.reinos r ON t.reino_id = r.id
+ JOIN vn2008.Compres b ON b.Id_Compra = l.buy_id
+ LEFT JOIN vn2008.Origen o ON a.id_origen = o.id
+ WHERE c.calc_id = v_calc
+ AND c.available > 0
+ AND c.item_id != 90
+ AND r.display
+ AND (v_realm IS NULL OR v_realm = r.id)
+ ORDER BY a.tipo_id, Article, Medida;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `myTicketGet` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `myTicketGet`(vTicket INT)
+BEGIN
+/**
+ * Returns a current user ticket header.
+ *
+ * @param vTicket The ticket identifier
+ */
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
+ CREATE TEMPORARY TABLE tmp.ticket
+ ENGINE = MEMORY
+ SELECT id ticketFk FROM myTicket
+ WHERE id = vTicket;
+
+ CALL vn.ticketGetTax (NULL);
+
+ SELECT t.id, t.landed, t.shipped, t.refFk, ag.description agency,
+ a.postalCode, a.city, a.nickname, p.name province,
+ v.taxBase taxBase, v.taxBase + v.tax + v.equalizationTax AS total
+ FROM tmp.ticketTax v
+ JOIN vn.ticket t ON t.id = v.ticketFk
+ JOIN vn.address a ON a.id = t.addressFk
+ JOIN vn.agencyMode ag ON ag.id = t.agencyModeFk
+ JOIN vn.province p ON p.id = a.provinceFk
+ WHERE t.id = vTicket;
+
+ DROP TEMPORARY TABLE
+ tmp.ticket,
+ tmp.ticketTax;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `myTicketGetRows` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `myTicketGetRows`(vTicket INT)
+BEGIN
+/**
+ * Returns a current user ticket lines.
+ *
+ * @param vTicket The ticket identifier
+ * @select The ticket lines
+ */
+ SELECT r.itemFk, r.quantity, r.concept, r.price, r.discount,
+ o.code origin, i.category, i.size, i.stems, i.inkFk, i.image
+ FROM myTicketRow r
+ JOIN vn.item i ON i.id = r.itemFk
+ LEFT JOIN vn.origin o ON o.id = i.originFk
+ WHERE r.ticketFk = vTicket
+ ORDER BY r.concept;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `myTicketList` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `myTicketList`(vFrom DATE, vTo DATE)
+BEGIN
+/**
+ * Returns the current user list of tickets between two dates reange.
+ * Also returns the total price with tax of every ticket.
+ *
+ * @param vFrom From date, if %NULL current date minus 25 days
+ * @param vTo To date, if %NULL current date
+ * @select The tickets list
+ */
+ SET vFrom = IFNULL(vFrom, DATE_FORMAT(TIMESTAMPADD(DAY, -25, CURDATE()), '%Y-%m-01'));
+ SET vTo = IFNULL(vTo, TIMESTAMPADD(YEAR, 1, CURDATE()));
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
+ CREATE TEMPORARY TABLE tmp.ticket
+ (KEY (ticketFk))
+ ENGINE = MEMORY
+ SELECT t.id ticketFk
+ FROM myTicket t
+ WHERE landed BETWEEN TIMESTAMP(vFrom) AND TIMESTAMP(vTo, '23:59:59');
+
+ CALL vn.ticketGetTotal;
+
+ SELECT v.id, IFNULL(v.landed, v.shipped) landed, v.shipped, v.companyFk,
+ a.city, a.nickname, ag.description agency, t.total
+ FROM tmp.ticket i
+ JOIN vn.ticket v ON v.id = i.ticketFk
+ JOIN vn.address a ON a.id = v.addressFk
+ JOIN vn.agencyMode ag ON ag.id = agencyModeFk
+ JOIN tmp.ticketTotal t ON t.ticketFk = i.ticketFk
+ ORDER BY IFNULL(v.landed, v.shipped) DESC, i.ticketFk DESC;
+
+ DROP TEMPORARY TABLE
+ tmp.ticket,
+ tmp.ticketTotal,
+ tMovementFixed;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `myTicketLogAccess` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `myTicketLogAccess`(vTicket INT)
+BEGIN
+/**
+ * Logs an access to a ticket.
+ *
+ * @param vTicket The ticket identifier
+ */
+ INSERT INTO vn.ticketLog
+ (originFk, userFk, `action`, description)
+ SELECT vTicket, account.userGetId(), 'select', 'Access'
+ FROM myTicket t
+ WHERE t.id = vTicket;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `orderCheckConfig` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `orderCheckConfig`(vOrder INT)
+proc: BEGIN
+/**
+ * Comprueba que la configuración del pedido es correcta.
+ *
+ * @param vOrder Identificador del pedido
+ */
+ DECLARE vDeliveryMethod VARCHAR(255);
+ DECLARE vDelivery DATE;
+ DECLARE vAgency INT;
+ DECLARE vAddress INT;
+
+ -- Obtiene los datos del pedido
+
+ SELECT d.code, o.date_send, o.agency_id, o.address_id
+ INTO vDeliveryMethod, vDelivery, vAgency, vAddress
+ FROM `order` o
+ JOIN vn.deliveryMethod d ON d.id = o.delivery_method_id
+ WHERE o.id = vOrder;
+
+ -- Comprueba que se ha seleccionado una dirección
+
+ IF vDeliveryMethod IN ('AGENCY', 'DELIVERY')
+ && vAddress IS NULL
+ THEN
+ CALL util.throw ('ORDER_EMPTY_ADDRESS');
+ END IF;
+
+ -- Comprueba que la agencia es correcta
+
+ IF !vn.AgencyIsAvailable (vAgency, vDelivery, vAddress) THEN
+ CALL util.throw ('ORDER_INVALID_AGENCY');
+ 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 `orderCheckDate` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `orderCheckDate`(vDate DATE)
+BEGIN
+ DECLARE vMaxTime TIME;
+ DECLARE vFestive BOOLEAN;
+ DECLARE vDenyDay DATE;
+ DECLARE vDenySunday BOOLEAN;
+
+ SELECT COUNT(*) INTO vFestive
+ FROM orderCheckFestive
+ WHERE TIMESTAMPADD(YEAR, -YEAR(vDate), vDate) = date
+ AND acceptOrders = FALSE;
+
+ IF vDate < CURDATE()
+ THEN
+ CALL util.throw ('ORDER_DATE_PAST');
+ ELSEIF vFestive > 0
+ THEN
+ CALL util.throw ('ORDER_DATE_HOLIDAY');
+ ELSE
+ SELECT c.denySunday, c.denyDay, IFNULL(w.maxTime, c.maxTime)
+ INTO vDenySunday, vDenyDay, vMaxTime
+ FROM orderCheck c
+ LEFT JOIN orderCheckWday w
+ ON w.weekday = WEEKDAY(CURDATE());
+
+ IF vDate = CURDATE() AND CURTIME() > vMaxTime
+ THEN
+ CALL util.throw ('ORDER_DATE_LAST');
+ ELSEIF WEEKDAY(vDate) = 6 AND vDenySunday
+ THEN
+ CALL util.throw ('ORDER_DATE_SUNDAY');
+ ELSEIF vDate = vDenyDay
+ THEN
+ CALL util.throw ('ORDER_DATE_SATURATED');
+ 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 `orderConfirm` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `orderConfirm`(vOrder INT)
+BEGIN
+/**
+ * Confirms an order, creating each of its tickets on
+ * the corresponding date and store.
+ *
+ * @deprecated Use orderConfirm() instead
+ *
+ * @param vOrder The order identifier
+ */
+ DECLARE vOk BOOL;
+ DECLARE vDone BOOL DEFAULT FALSE;
+ DECLARE vWarehouse INT;
+ DECLARE vShipment DATETIME;
+ DECLARE vTicket INT;
+ DECLARE vNotes VARCHAR(255);
+ DECLARE vItem INT;
+ DECLARE vConcept VARCHAR(30);
+ DECLARE vAmount INT;
+ DECLARE vPrice DECIMAL(10,2);
+ DECLARE vSale INT;
+ DECLARE vRate INT;
+ DECLARE vEmployee INT;
+ DECLARE vRowId INT;
+ DECLARE vDelivery DATE;
+ DECLARE vAddress INT;
+ DECLARE vAgency INT;
+ DECLARE vIsConfirmed BOOL;
+ DECLARE vClientId INT;
+ DECLARE vCompanyId INT;
+ DECLARE vAgencyModeId INT;
+
+ DECLARE TICKET_FREE INT DEFAULT 2;
+ DECLARE SYSTEM_WORKER INT DEFAULT 20;
+
+ DECLARE cDates CURSOR FOR
+ SELECT t.Fecha_envio, r.warehouse_id
+ FROM `order` o
+ JOIN order_row r ON r.order_id = o.id
+ LEFT JOIN vn2008.travel_tree t ON t.warehouse_id = r.warehouse_id
+ WHERE o.id = vOrder AND r.amount != 0
+ GROUP BY warehouse_id;
+
+ DECLARE cRows CURSOR FOR
+ SELECT r.id, r.item_id, a.Article, r.amount, r.price, r.rate
+ FROM order_row r
+ JOIN vn2008.Articles a ON a.Id_Article = r.item_id
+ WHERE r.amount != 0
+ AND r.warehouse_id = vWarehouse
+ AND r.order_id = vOrder
+ ORDER BY r.rate DESC;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND
+ SET vDone = TRUE;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ ROLLBACK;
+ RESIGNAL;
+ END;
+
+ -- Carga los datos del pedido
+
+ SELECT o.date_send, o.address_id, o.note, a.agency_id,
+ o.confirmed, cs.Id_Cliente, o.company_id, o.agency_id
+ INTO vDelivery, vAddress, vNotes, vAgency,
+ vIsConfirmed, vClientId, vCompanyId, vAgencyModeId
+ FROM hedera.`order` o
+ JOIN vn2008.Agencias a ON a.Id_Agencia = o.agency_id
+ JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = o.address_id
+ WHERE id = vOrder;
+
+ -- Comprueba que el pedido no está confirmado
+
+ IF vIsConfirmed THEN
+ CALL util.throw ('ORDER_ALREADY_CONFIRMED');
+ END IF;
+
+ -- Comprueba que el pedido no está vacío
+
+ SELECT COUNT(*) > 0 INTO vOk
+ FROM order_row WHERE order_id = vOrder AND amount > 0;
+
+ IF !vOk THEN
+ CALL util.throw ('ORDER_EMPTY');
+ END IF;
+
+ -- Carga las fechas de salida de cada almacén
+
+ CALL vn2008.travel_tree (vDelivery, vAddress, vAgency);
+
+ -- Trabajador que realiza la acción
+
+ SELECT Id_Trabajador INTO vEmployee
+ FROM vn2008.Trabajadores
+ WHERE user_id = account.userGetId();
+
+ IF vEmployee IS NULL THEN
+ SELECT employee_id INTO vEmployee FROM order_config;
+ END IF;
+
+ -- Crea los tickets del pedido
+
+ START TRANSACTION;
+
+ OPEN cDates;
+
+ lDates:
+ LOOP
+ SET vTicket = NULL;
+ SET vDone = FALSE;
+ FETCH cDates INTO vShipment, vWarehouse;
+
+ IF vDone THEN
+ LEAVE lDates;
+ END IF;
+
+ -- Busca un ticket existente que coincida con los parametros del nuevo pedido
+
+ SELECT Id_Ticket INTO vTicket
+ FROM vn2008.Tickets t
+ LEFT JOIN vn.ticketState tls on tls.ticket = t.Id_Ticket
+ JOIN `order` o
+ ON o.address_id = t.Id_Consigna
+ AND vWarehouse = t.warehouse_id
+ AND o.agency_id = t.Id_Agencia
+ AND t.landing = o.date_send
+ AND vShipment = DATE(t.Fecha)
+ WHERE o.id = vOrder
+ AND t.Factura IS NULL
+ AND IFNULL(tls.alertLevel,0) = 0
+ AND t.Id_Cliente <> 1118
+ LIMIT 1;
+
+ -- Crea el ticket en el caso de no existir uno adecuado
+
+ IF vTicket IS NULL
+ THEN
+ CALL vn.ticketCreate (
+ vClientId,
+ IFNULL(vShipment, CURDATE()),
+ vWarehouse,
+ vCompanyId,
+ vAddress,
+ vAgencyModeId,
+ NULL,
+ vDelivery,
+ vTicket
+ );
+ ELSE
+ INSERT INTO vncontrol.inter
+ SET Id_Ticket = vTicket,
+ Id_Trabajador = SYSTEM_WORKER,
+ state_id = TICKET_FREE;
+ END IF;
+
+ INSERT IGNORE INTO vn2008.order_Tickets
+ SET order_id = vOrder,
+ Id_Ticket = vTicket;
+
+ -- Añade las notas
+
+ IF vNotes IS NOT NULL AND vNotes != ''
+ THEN
+ INSERT INTO vn2008.ticket_observation (Id_Ticket, observation_type_id, text)
+ VALUES (vTicket, 4/*comercial*/, vNotes)
+ ON DUPLICATE KEY UPDATE text = CONCAT(VALUES(text),'. ', text);
+ END IF;
+
+ -- Añade los movimientos y sus componentes
+
+ OPEN cRows;
+
+ lRows:
+ LOOP
+ SET vDone = FALSE;
+ FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate;
+
+ IF vDone THEN
+ LEAVE lRows;
+ END IF;
+
+ INSERT INTO vn2008.Movimientos
+ SET
+ Id_Article = vItem,
+ Id_Ticket = vTicket,
+ Concepte = vConcept,
+ Cantidad = vAmount,
+ Preu = vPrice,
+ CostFixat = 0,
+ PrecioFijado = TRUE;
+
+ SET vSale = LAST_INSERT_ID();
+
+ INSERT INTO vn2008.Movimientos_componentes (Id_Movimiento, Id_Componente, Valor)
+ SELECT vSale, cm.component_id, cm.price
+ FROM order_component cm
+ JOIN bi.tarifa_componentes tc ON tc.Id_Componente = cm.component_id
+ WHERE cm.order_row_id = vRowId
+ GROUP BY vSale, cm.component_id;
+
+ UPDATE order_row SET Id_Movimiento = vSale
+ WHERE id = vRowId;
+
+ END LOOP;
+
+ CLOSE cRows;
+
+ -- Fija el Costfixat
+
+ UPDATE vn2008.Movimientos m
+ JOIN (SELECT SUM(mc.Valor) sum_valor,mc.Id_Movimiento
+ FROM vn2008.Movimientos_componentes mc
+ 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
+ JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento
+ WHERE m.Id_Ticket = vTicket
+ GROUP BY mc.Id_Movimiento) mc ON mc.Id_Movimiento = m.Id_Movimiento
+ SET m.CostFixat = sum_valor;
+ END LOOP;
+
+ CLOSE cDates;
+
+ DELETE FROM order_basket WHERE order_id = vOrder;
+ UPDATE `order` SET confirmed = TRUE, confirm_date = NOW()
+ WHERE id = vOrder;
+
+ 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 `orderGetTax` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `orderGetTax`(vOrder INT)
+ READS SQL DATA
+BEGIN
+/**
+ * Calcula el IVA, y el recargo de equivalencia de un pedido
+ * desglosados por tipos.
+ *
+ * @param vOrder El identificador del pedido
+ * @treturn tmp.orderTax Bases imponibles, IVA y recargo de equivalencia
+ */
+ CALL vn.taxGetRates (NULL);
+
+ -- Calcula el IVA y el recargo desglosado.
+
+ DROP TEMPORARY TABLE IF EXISTS tmp.orderTax;
+ CREATE TEMPORARY TABLE tmp.orderTax
+ (INDEX (orderFk))
+ ENGINE = MEMORY
+ SELECT id orderFk, t.type, t.taxBase,
+ CAST(IF(t.hasTax, t.taxBase * x.rate, 0) AS DECIMAL(10,2)) tax,
+ CAST(IF(t.hasEqualizationTax, t.taxBase * x.equalizationTax, 0) AS DECIMAL(10,2)) equalizationTax
+ FROM (
+ SELECT o.id, g.countryFk, g.type
+ ,SUM(CAST(m.amount * m.price AS DECIMAL(10,2))) taxBase
+ ,NOT(c.isVies AND p.countryFk <> c.countryFk) hasTax
+ ,c.isEqualizated != FALSE AS hasEqualizationTax
+ FROM `order` o
+ JOIN orderRow m ON m.orderFk = o.id
+ JOIN vn.item a ON a.id = m.itemFk
+ JOIN vn.client c ON c.id = o.customer_id
+ JOIN vn.supplier p ON p.id = o.company_id
+ JOIN tmp.taxClass g
+ ON g.countryFk = p.countryFk AND g.taxClassFk = a.taxClassFk
+ WHERE o.id = vOrder
+ GROUP BY o.id, g.type
+ ) t
+ JOIN tmp.taxType x
+ ON x.countryFk = t.countryFk AND x.type = t.type;
+
+ DROP TEMPORARY TABLE
+ tmp.taxClass,
+ tmp.taxType;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `orderNew` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `orderNew`()
+BEGIN
+
+ DECLARE vCount INT;
+
+ DECLARE vDeliveryMethod INT;
+
+ DECLARE vAgency INT;
+
+ DECLARE vAddress INT;
+
+ DECLARE vWarehouse INT DEFAULT NULL;
+
+
+
+ SELECT COUNT(*) INTO vCount FROM order_view;
+
+
+
+ IF vCount >= 3 THEN
+
+ CALL util.throw ('ORDER_MAX_EXCEEDED');
+
+ END IF;
+
+
+
+ SELECT co.Id_Consigna, co.Id_Agencia, a.Vista
+
+ INTO vAddress, vAgency, vDeliveryMethod
+
+ FROM vn2008.Clientes c
+
+ LEFT JOIN vn2008.Consignatarios co ON co.Id_Consigna = c.default_address
+
+ JOIN vn2008.Agencias a ON a.Id_Agencia = co.Id_Agencia
+
+ WHERE c.Id_cliente = user_id();
+
+
+
+ INSERT INTO `order`
+
+ SET
+
+ date_send = CURDATE(),
+
+ customer_id = user_id(),
+
+ delivery_method_id = IFNULL(vDeliveryMethod, DEFAULT(delivery_method_id)),
+
+ agency_id = IFNULL(vAgency, DEFAULT(agency_id)),
+
+ address_id = IFNULL(vAddress, DEFAULT(address_id)),
+
+ wh_id = IFNULL(vWarehouse, DEFAULT(wh_id)),
+
+ type_id = IFNULL(vAgency, DEFAULT(type_id)),
+ is_bionic = FALSE;
+
+
+
+ SELECT LAST_INSERT_ID() order_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 `orderUpdate` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `orderUpdate`(vOrder INT)
+proc: BEGIN
+/**
+ * Actualiza la líneas de un pedido.
+ *
+ * @param vOrder Id del pedido
+ */
+ DECLARE vDate DATE;
+ DECLARE vAddress INT;
+ DECLARE vAgency INT;
+ DECLARE vNRows INT;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ ROLLBACK;
+ RESIGNAL;
+ END;
+
+ START TRANSACTION;
+
+ SELECT COUNT(*) INTO vNRows
+ FROM order_row WHERE order_id = vOrder;
+
+ IF vNRows > 0
+ THEN
+ SELECT date_send, address_id, agency_id
+ INTO vDate, vAddress, vAgency
+ FROM `order`
+ WHERE id = vOrder;
+
+ CALL vn2008.bionic_from_order (vDate, vAddress, vAgency, vOrder);
+
+ DELETE c
+ FROM order_row r
+ JOIN order_component c ON c.order_row_id = r.id
+ WHERE r.order_id = vOrder;
+
+ UPDATE order_row r
+ LEFT JOIN tmp.bionic_price l
+ ON l.warehouse_id = r.warehouse_id
+ AND l.item_id = r.item_id
+ AND l.rate = r.rate
+ LEFT JOIN tmp.travel_tree t
+ ON t.warehouse_id = r.warehouse_id
+ SET
+ r.price = l.price,
+ r.amount = IF(l.item_id IS NOT NULL, r.amount + IF(@m := MOD(r.amount, l.grouping), l.grouping - @m, 0), 0),
+ r.shipment = t.Fecha_envio
+ WHERE r.order_id = vOrder;
+
+ INSERT INTO order_component (order_row_id, component_id, price)
+ SELECT r.id, c.component_id, c.cost
+ FROM order_row r
+ JOIN tmp.bionic_component c
+ ON c.warehouse_id = r.warehouse_id
+ AND c.item_id = r.item_id
+ JOIN bi.tarifa_componentes t
+ ON t.Id_Componente = c.component_id
+ AND (t.tarifa_class IS NULL OR t.tarifa_class = r.rate)
+ WHERE r.order_id = vOrder;
+ END IF;
+
+ UPDATE `order` SET date_make = NOW()
+ WHERE id = vOrder;
+
+ 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 `order_confirm_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`@`%` PROCEDURE `order_confirm_bionic`(vOrder INT)
+BEGIN
+/**
+ * Confirma un pedido, creando cada uno de sus tickets en la fecha
+ * y almacén correspondientes.
+ *
+ * @deprecated Use orderConfirm() instead
+ *
+ * @param vOrder Identificador del pedido
+ */
+ CALL orderConfirm (vOrder);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `order_get_vat` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `order_get_vat`(vOrder INT)
+ READS SQL DATA
+BEGIN
+/**
+ * Calcula el IVA, y el recargo de equivalencia de un pedido
+ * desglosados por tipos.
+ *
+ * @deprecated Use procedure orderGetTax() instead
+ *
+ * @param vOrder El identificador del pedido
+ * @table t_order_vat Bases imponibles, su IVA y su recargo de equivalencia.
+ */
+ CALL orderGetTax (vOrder);
+
+ DROP TEMPORARY TABLE IF EXISTS t_order_vat;
+ CREATE TEMPORARY TABLE t_order_vat
+ ENGINE = MEMORY
+ SELECT orderFk order_id, type rate, taxBase tax_base,
+ tax vat, equalizationTax surcharge
+ FROM tmp.orderTax;
+
+ DROP TEMPORARY TABLE tmp.orderTax;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `surveyVote` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `surveyVote`(vAnswer INT)
+BEGIN
+ DECLARE vSurvey INT;
+ DECLARE vCount TINYINT;
+ DECLARE EXIT HANDLER FOR 1062
+ CALL util.throw ('SURVEY_MAX_ONE_VOTE');
+
+ SELECT survey_id INTO vSurvey
+ FROM survey_answer WHERE id = vAnswer;
+
+ INSERT INTO survey_vote
+ VALUES (vSurvey, account.userGetId());
+
+ UPDATE survey_answer SET votes = votes + 1
+ WHERE id = vAnswer;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticketLog` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ticketLog`(vticket INT)
+BEGIN
+ INSERT INTO vn2008.Tickets_dits
+ (idaccion_dits, Id_Trabajador, Id_Ticket)
+ SELECT 146, 4, id
+ FROM ticket_view WHERE id = vTicket;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `ticket_list` */;
+/*!50003 SET @saved_cs_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' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `ticket_list`()
+BEGIN
+
+/**
+
+ * Devuelve los tickets del cliente del último mes, calculando
+
+ * el total de cada ticket.
+
+ *
+
+ * @select Listado de tickets
+
+ **/
+
+ DROP TEMPORARY TABLE IF EXISTS vn2008.ticket_tmp;
+
+ CREATE TEMPORARY TABLE vn2008.ticket_tmp
+
+ (KEY (ticket_id))
+
+ ENGINE = MEMORY
+
+ SELECT t.id ticket_id FROM ticket_view t
+
+ WHERE date > TIMESTAMP(DATE_FORMAT(TIMESTAMPADD(DAY, -25, CURDATE()), '%Y-%m-01'));
+
+
+
+ CALL vn2008.ticket_total ();
+
+
+
+ DROP TEMPORARY TABLE IF EXISTS t_movement_fixed;
+
+ CREATE TEMPORARY TABLE t_movement_fixed
+
+ (KEY (ticket_id))
+
+ ENGINE = MEMORY
+
+ SELECT ticket_id, BIT_AND(fixed != FALSE) all_fixed
+
+ FROM ticket_row_view
+
+ JOIN vn2008.ticket_tmp USING(ticket_id)
+
+ GROUP BY ticket_id;
+
+
+
+ SELECT i.ticket_id, IFNULL(v.delivery, v.`date`) `date`, city, consignee, type, company_id,
+
+ IF(all_fixed, t.total, NULL) total,
+
+ IF(v.date >= CURDATE() AND v.invoice IS NULL AND all_fixed
+
+ ,t.total
+
+ ,NULL
+
+ ) pending
+
+ FROM vn2008.ticket_tmp i
+
+ JOIN ticket_view v ON i.ticket_id = v.id
+
+ JOIN address_view c ON v.address_id = c.id
+
+ JOIN vn2008.ticket_total t USING(ticket_id)
+
+ LEFT JOIN t_movement_fixed m USING(ticket_id)
+
+ ORDER BY IFNULL(v.delivery, v.`date`) DESC, i.ticket_id DESC;
+
+
+
+ DROP TEMPORARY TABLE vn2008.ticket_tmp;
+
+ DROP TEMPORARY TABLE vn2008.ticket_total;
+
+ DROP TEMPORARY TABLE t_movement_fixed;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `tpvTransactionConfirm` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `tpvTransactionConfirm`(
+ vAmount INT
+ ,vOrder INT
+ ,vMerchant INT
+ ,vCurrency INT
+ ,vResponse INT
+ ,vErrorCode VARCHAR(10)
+)
+BEGIN
+/**
+ * Confirma una transacción previamente iniciada, reescribiendo
+ * sus datos por los confirmados por el banco (solo si estos difieren).
+ * Genera el recibo y su correspondiente entrada en caja.
+ *
+ * @param vAmount Cantidad confirmada
+ * @param vOrder Identificador de transacción
+ * @param vMerchant Identificador de comercio
+ * @param vCurrency Identificador de moneda
+ * @param vResponse Identificador de respuesta del banco
+ * @param vErrorCode Código de error del banco, si lo hubiera
+ */
+ DECLARE vReceipt INT;
+ DECLARE vStatus VARCHAR(10);
+ DECLARE vCustomer INT;
+ DECLARE vBank INT;
+ DECLARE vCompany INT;
+ DECLARE vEmployee INT;
+ DECLARE vIsDuplicated BOOLEAN;
+ DECLARE vDate DATE;
+ DECLARE vConcept VARCHAR(25) DEFAULT 'Cobro Web';
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ ROLLBACK;
+ RESIGNAL;
+ END;
+
+ START TRANSACTION;
+
+ SELECT COUNT(*) > 0 INTO vIsDuplicated
+ FROM tpvTransaction
+ WHERE id = vOrder AND response IS NOT NULL
+ FOR UPDATE;
+
+ IF vIsDuplicated
+ THEN
+ CALL util.throw ('TRANSACTION_DUPLICATED');
+ END IF;
+
+ IF vResponse BETWEEN 0 AND 99
+ THEN
+ SELECT
+ t.clientFk
+ ,m.bankFk
+ ,m.companyFk
+ ,c.employeeFk
+ ,DATE(t.created)
+ INTO
+ vCustomer
+ ,vBank
+ ,vCompany
+ ,vEmployee
+ ,vDate
+ FROM tpvMerchant m
+ JOIN tpvConfig c ON c.id = 1
+ LEFT JOIN tpvTransaction t ON t.id = vOrder
+ WHERE m.id = vMerchant;
+
+ INSERT INTO vn2008.Recibos
+ SET
+ Entregado = vAmount / 100
+ ,Fechacobro = vDate
+ ,Id_Trabajador = vEmployee
+ ,Id_Banco = vBank
+ ,Id_Cliente = vCustomer
+ ,empresa_id = vCompany
+ ,Id_Factura = vConcept
+ ,conciliado = TRUE;
+
+ SET vReceipt = LAST_INSERT_ID();
+ SET vStatus = 'ok';
+
+ -- Código redundante
+
+ DO vn2008.till_entry
+ (
+ vCustomer
+ ,vBank
+ ,vAmount / 100
+ ,vConcept
+ ,vDate
+ ,'A'
+ ,TRUE
+ ,vCustomer
+ ,vCompany
+ ,vEmployee
+ );
+ ELSE
+ SET vReceipt = NULL;
+ SET vStatus = 'ko';
+ END IF;
+
+ UPDATE tpvTransaction
+ SET
+ merchantFk = vMerchant
+ ,receiptFk = vReceipt
+ ,amount = vAmount
+ ,response = vResponse
+ ,errorCode = vErrorCode
+ ,status = vStatus
+ WHERE id = vOrder;
+
+ 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 `tpvTransactionConfirmAll` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `tpvTransactionConfirmAll`(vDate DATE)
+BEGIN
+/**
+ * Confirma todas las transacciones confirmadas por el cliente pero no
+ * por el banco para una fecha dada.
+ *
+ * @param vDate Fecha deseada
+ */
+ DECLARE vOrder INT;
+ DECLARE vDone BOOLEAN DEFAULT FALSE;
+ DECLARE vDateIni DATETIME DEFAULT TIMESTAMP(vDate, '00:00:00');
+ DECLARE vDateEnd DATETIME DEFAULT TIMESTAMP(vDate, '23:59:59');
+
+ DECLARE cTransactions CURSOR FOR
+ SELECT id
+ FROM tpvTransaction
+ WHERE created BETWEEN vDateIni AND vDateEnd
+ AND status = 'ok'
+ AND response IS NULL;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
+
+ OPEN cTransactions;
+
+ l: LOOP
+ FETCH cTransactions INTO vOrder;
+
+ IF vDone THEN
+ LEAVE l;
+ END IF;
+
+ CALL tpvTransactionConfirmById (vOrder);
+ END LOOP l;
+
+ CLOSE cTransactions;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `tpvTransactionConfirmById` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `tpvTransactionConfirmById`(vOrder INT)
+BEGIN
+/**
+ * Confirma manualmente una transacción espedificando su identificador.
+ *
+ * @param vOrder Identificador de la transacción
+ */
+ DECLARE vAmount INT;
+ DECLARE vMerchant INT;
+ DECLARE vCurrency INT;
+
+ SELECT amount, merchantFk, currency
+ INTO vAmount, vMerchant, vCurrency
+ FROM tpvTransaction t
+ JOIN tpvMerchant m ON m.id = t.merchantFk
+ JOIN tpvConfig c
+ WHERE t.id = vOrder;
+
+ CALL tpvTransactionConfirm (
+ vAmount
+ ,vOrder
+ ,vMerchant
+ ,vCurrency
+ ,0
+ ,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 `tpvTransactionEnd` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `tpvTransactionEnd`(vTransaction INT, vStatus VARCHAR(12))
+BEGIN
+/**
+ * Finaliza una transaccción estableciendo su estado a 'ok' o
+ * 'ko' en función de si esta se ha realizado correctamente.
+ * Este procedimiento debe ser llamado directamente por el cliente
+ * nada mas finalizar la transacción y solo tiene validez hasta que
+ * llega la notificacion definitiva desde el banco.
+ *
+ * @param vTransaction El identificador de la transacción
+ * @param vStatus El estado, 'ok' o 'ko'
+ */
+ IF vStatus IN ('ok', 'ko')
+ THEN
+ UPDATE myTpvTransaction SET status = vStatus
+ WHERE id = vTransaction AND response IS 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 DROP PROCEDURE IF EXISTS `tpvTransactionStart` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `tpvTransactionStart`(vAmount INT, vCompany INT)
+BEGIN
+/**
+ * Inicia una nueva transacción con el TPV virtual, generando
+ * un identificador de transacción y devolviendo con un SELECT
+ * los parámetros que deben enviarse a la URL del servicio web
+ * del banco.
+ *
+ * @param vAmount Cantidad a pagar en céntimos
+ * @param vCompany El identificador de la empresa
+ *
+ * @select Los parámetros que deben pasarse al banco
+ */
+ DECLARE vTransaction CHAR(12);
+ DECLARE vMerchant INT;
+ DECLARE vUrl VARCHAR(255);
+ DECLARE vKey VARCHAR(50);
+ DECLARE vTestMode BOOLEAN;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ ROLLBACK;
+ RESIGNAL;
+ END;
+
+ START TRANSACTION;
+
+ IF vCompany IS NULL
+ THEN
+ SELECT companyFk INTO vCompany
+ FROM tpvMerchantEnable LIMIT 1;
+ END IF;
+
+ SELECT merchantFk INTO vMerchant
+ FROM tpvMerchantEnable WHERE companyFk = vCompany;
+
+ SELECT testMode INTO vTestMode
+ FROM tpvConfig;
+
+ IF NOT vTestMode
+ THEN
+ SELECT c.url, m.secretKey INTO vUrl, vKey
+ FROM tpvMerchant m
+ JOIN tpvConfig c
+ WHERE m.id = vMerchant;
+ ELSE
+ SELECT testUrl, testKey INTO vUrl, vKey
+ FROM tpvConfig;
+ END IF;
+
+ INSERT INTO myTpvTransaction
+ SET
+ merchantFk = vMerchant
+ ,clientFk = account.userGetId()
+ ,amount = vAmount;
+
+ SET vTransaction = LAST_INSERT_ID();
+
+ SELECT
+ vAmount amount
+ ,vTransaction transactionId
+ ,vMerchant merchant
+ ,currency
+ ,transactionType
+ ,terminal
+ ,merchantUrl
+ ,vUrl url
+ ,vKey secretKey
+ FROM tpvConfig;
+
+ 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 `tpvTransactionUndo` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `tpvTransactionUndo`(
+ vOrder INT
+)
+BEGIN
+ DECLARE vCustomer INT;
+ DECLARE vAmount DOUBLE;
+ DECLARE vReceipt INT;
+ DECLARE vDate DATE;
+ DECLARE vBank INT;
+ DECLARE vAccount VARCHAR(12);
+ DECLARE vSubaccount VARCHAR(12);
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ ROLLBACK;
+ RESIGNAL;
+ END;
+
+ START TRANSACTION;
+
+ SELECT
+ t.clientFk
+ ,t.amount / 100
+ ,t.receiptFk
+ ,DATE(t.created)
+ ,m.bankFk
+ INTO
+ vCustomer
+ ,vAmount
+ ,vReceipt
+ ,vDate
+ ,vBank
+ FROM tpvTransaction t
+ JOIN tpvMerchant m ON m.id = t.merchantFk
+ JOIN tpvConfig c
+ WHERE t.id = vOrder
+ FOR UPDATE;
+
+ -- Elimina el recibo
+
+ DELETE FROM vn2008.Recibos
+ WHERE Id = vReceipt LIMIT 1;
+
+ -- Elimina la entrada de cajas
+
+ DELETE FROM vn2008.Cajas
+ WHERE Id_Banco = vBank
+ AND DATE(CajaFecha) = vDate
+ AND Entrada = vAmount
+ LIMIT 1;
+
+ -- Elimina los asientos contables
+
+ SELECT Cuenta INTO vSubaccount
+ FROM vn2008.Clientes WHERE Id_Cliente = vCustomer;
+
+ SELECT Cuenta INTO vAccount
+ FROM vn2008.Bancos WHERE Id_Banco = vBank;
+
+ DELETE FROM vn2008.XDiario
+ WHERE SUBCTA = vSubaccount
+ AND CONTRA = vAccount
+ AND DATE(FECHA) = vDate
+ AND EUROHABER = vAmount
+ LIMIT 1;
+
+ DELETE FROM vn2008.XDiario
+ WHERE CONTRA = vSubaccount
+ AND SUBCTA = vAccount
+ AND DATE(FECHA) = vDate
+ AND EURODEBE = vAmount
+ LIMIT 1;
+
+ -- Actualiza la transaccion
+
+ UPDATE tpvTransaction
+ SET response = NULL, status = 'started'
+ WHERE id = vOrder;
+
+ 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 `transactionEnd` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `transactionEnd`(vTransaction INT, vStatus VARCHAR(12))
+BEGIN
+/**
+ * @deprecated Use procedure tpvTransactionEnd() instead
+ */
+ CALL tpvTransactionEnd(vTransaction, vStatus);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `transactionStart` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `transactionStart`(vAmount INT, vCompany INT)
+BEGIN
+/**
+ * @deprecated Use procedure tpvtransactionStart() instead
+ */
+ CALL tpvtransactionStart(vAmount, vCompany);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `visitRegister` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `visitRegister`(
+ vVisit INT
+ ,vPlatform VARCHAR(30)
+ ,vBrowser VARCHAR(30)
+ ,vVersion VARCHAR(15)
+ ,vJavascript TINYINT
+ ,vCookies TINYINT
+ ,vAgent VARCHAR(255)
+ ,vIp INT
+ ,vReferer VARCHAR(255)
+)
+BEGIN
+ DECLARE vFirstVisit TINYINT DEFAULT FALSE;
+ DECLARE vFirstAgent TINYINT DEFAULT FALSE;
+ DECLARE vAgentId INT DEFAULT NULL;
+ DECLARE vAccessId INT DEFAULT NULL;
+
+ -- Registers the visit
+
+ IF vVisit IS NULL || (SELECT COUNT(*) FROM visit WHERE id = vVisit) = 0
+ THEN
+ INSERT INTO visit SET id = DEFAULT;
+ SET vVisit = LAST_INSERT_ID();
+ SET vFirstVisit = TRUE;
+ END IF;
+
+ SELECT id INTO vAgentId FROM visitAgent
+ WHERE visit = vVisit
+ AND (agent = vAgent OR (vAgent IS NULL AND agent IS NULL))
+ LIMIT 1;
+
+ -- Registers the user agent
+
+ IF vAgentId IS NULL
+ THEN
+ INSERT INTO visitAgent SET
+ visit = vVisit
+ ,platform = vPlatform
+ ,browser = vBrowser
+ ,version = vVersion
+ ,javascript = vJavascript
+ ,cookies = vCookies
+ ,agent = vAgent;
+
+ SET vAgentId = LAST_INSERT_ID();
+ SET vFirstAgent = TRUE;
+ END IF;
+
+ IF vFirstVisit
+ THEN
+ UPDATE visit SET firstAgent = vAgentId
+ WHERE id = vVisit;
+ END IF;
+
+ -- Registers the user access
+
+ INSERT INTO visitAccess SET
+ agent = vAgentId
+ ,ip = vIp
+ ,referer = vReferer;
+
+ SET vAccessId = LAST_INSERT_ID();
+
+ IF vFirstAgent
+ THEN
+ UPDATE visitAgent SET firstAccess = vAccessId
+ WHERE id = vAgentId;
+ END IF;
+
+ -- Returns the visit info
+
+ SELECT vVisit visit, vAccessId access;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `visitUserNew` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `visitUserNew`(
+ vAccess INT
+ ,vSsid VARCHAR(64)
+)
+BEGIN
+ DECLARE vUserVisit INT;
+
+ INSERT INTO visitUser SET
+ access = vAccess,
+ user = account.userGetId();
+
+ SET vUserVisit = LAST_INSERT_ID();
+
+ UPDATE userSession SET userVisit = vUserVisit
+ WHERE ssid = vSsid;
+
+ DELETE FROM userSession
+ WHERE lastUpdate < TIMESTAMPADD(HOUR, -1, NOW());
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `__order_confirm_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`@`%` PROCEDURE `__order_confirm_bionic`(v_order INT)
+BEGIN
+/**
+ * Confirma un pedido, creando cada uno de sus tickets en la fecha
+ * y almacén correspondientes.
+ *
+ * @param v_order Identificador del pedido
+ **/
+ DECLARE v_ok BOOLEAN;
+ DECLARE v_done BOOLEAN DEFAULT FALSE;
+ DECLARE v_wh INT;
+ DECLARE v_shipment DATETIME;
+ DECLARE v_ticket INT;
+ DECLARE v_note VARCHAR(255);
+ DECLARE i_article INT;
+ DECLARE v_concepte VARCHAR(30);
+ DECLARE i_amount INT;
+ DECLARE d_price DOUBLE;
+ DECLARE i_movimiento INT;
+ DECLARE i_rate INT;
+ DECLARE i_worker INT;
+ DECLARE i_order_row INT;
+ DECLARE d_delivery DATE;
+ DECLARE i_address INT;
+ DECLARE i_agency INT;
+ DECLARE b_confirmed BOOLEAN;
+ DECLARE TICKET_FREE INT DEFAULT 2;
+ DECLARE SYSTEM_WORKER INT DEFAULT 20;
+ DECLARE vClientId INT;
+ DECLARE vCompanyId INT;
+ DECLARE vAgencyModeId INT;
+
+ DECLARE cur_tick CURSOR FOR
+ SELECT t.Fecha_envio, r.warehouse_id
+ FROM `order` o
+ JOIN order_row r ON r.order_id = o.id
+ LEFT JOIN vn2008.travel_tree t ON t.warehouse_id = r.warehouse_id
+ WHERE o.id = v_order AND r.amount != 0
+ GROUP BY warehouse_id;
+
+ DECLARE cur_mov CURSOR FOR
+ SELECT r.id, r.item_id, a.Article, r.amount, r.price, r.rate
+ FROM order_row r
+ JOIN vn2008.Articles a ON a.Id_Article = r.item_id
+ WHERE r.amount != 0
+ AND r.warehouse_id = v_wh
+ AND r.order_id = v_order
+ ORDER BY r.rate DESC;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND
+ SET v_done = TRUE;
+
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+ ROLLBACK;
+ RESIGNAL;
+ END;
+
+ -- Carga los datos del pedido
+
+ SELECT o.date_send, o.address_id, o.note, a.agency_id, o.confirmed,cs.Id_Cliente,o.company_id,o.agency_id
+ INTO d_delivery,i_address, v_note, i_agency, b_confirmed,vClientId , vCompanyId,vAgencyModeId
+ FROM hedera.`order` o
+ JOIN vn2008.Agencias a ON a.Id_Agencia = o.agency_id
+ JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = o.address_id
+ WHERE id = v_order;
+
+ -- Comprueba que el pedido no está confirmado
+
+ IF b_confirmed THEN
+ CALL util.throw ('ORDER_ALREADY_CONFIRMED');
+ END IF;
+
+ -- Comprueba que el pedido no está vacío
+
+ SELECT COUNT(*) > 0 INTO v_ok
+ FROM order_row WHERE order_id = v_order AND amount > 0;
+
+ IF !v_ok THEN
+ CALL util.throw ('ORDER_EMPTY');
+ END IF;
+
+ -- Carga las fechas de salida de cada almacén
+
+ CALL vn2008.travel_tree (d_delivery, i_address, i_agency);
+
+ -- Trabajador que realiza la acción
+
+ SELECT Id_Trabajador INTO i_worker
+ FROM vn2008.Trabajadores
+ WHERE user_id = account.userGetId();
+
+ IF i_worker IS NULL THEN
+ SELECT employee_id INTO i_worker FROM order_config;
+ END IF;
+
+ -- Crea los tickets del pedido
+
+ START TRANSACTION;
+
+ OPEN cur_tick;
+
+ tick_loop:
+ LOOP
+ SET v_ticket = NULL;
+ SET v_done = FALSE;
+ FETCH cur_tick INTO v_shipment, v_wh;
+
+ IF v_done THEN
+ LEAVE tick_loop;
+ END IF;
+
+ -- Busca un ticket existente que coincida con los parametros del nuevo pedido
+ SELECT Id_Ticket INTO v_ticket
+ FROM vn2008.Tickets t
+ LEFT JOIN vn.ticketState tls on tls.ticket = t.Id_Ticket
+ JOIN `order` o
+ ON o.address_id = t.Id_Consigna
+ AND v_wh = t.warehouse_id
+ AND o.agency_id = t.Id_Agencia
+ AND t.landing = o.date_send
+ AND v_shipment = DATE(t.Fecha)
+ WHERE o.id = v_order
+ AND t.Factura IS NULL
+ AND IFNULL(tls.alertLevel,0) = 0
+ /* AND t.PedidoImpreso = 0
+ AND t.Etiquetasemitidas = 0
+ AND vn2008.is_bionic(t.Id_Ticket) */
+ AND t.Id_Cliente <> 1118
+ LIMIT 1;
+
+
+ -- Crea el ticket en el caso de no existir uno adecuado
+
+ IF v_ticket IS NULL
+ THEN
+ call vn.ticketCreate( vClientId, IFNULL(v_shipment,CURDATE()), v_wh, vCompanyId, i_address, vAgencyModeId, NULL, d_delivery, v_ticket);
+ ELSE
+ -- UPDATE vn2008.Tickets SET Localizacion = CONCAT(Localizacion,'B+') WHERE Id_Ticket = v_ticket;
+ INSERT INTO vncontrol.inter(Id_Ticket, Id_Trabajador, state_id)
+ VALUES(v_ticket, SYSTEM_WORKER, TICKET_FREE);
+
+ END IF;
+
+ INSERT IGNORE INTO vn2008.order_Tickets (order_id, Id_Ticket)
+ VALUES (v_order, v_ticket);
+
+ -- Añade las notas
+
+ IF v_note IS NOT NULL && v_note != ''
+ THEN
+ INSERT INTO vn2008.ticket_observation (Id_Ticket, observation_type_id, text)
+ VALUES (v_ticket, 4/*comercial*/, v_note)
+ ON DUPLICATE KEY UPDATE text = CONCAT(VALUES(text),'. ', text);
+ END IF;
+
+ -- Añade los movimientos y sus componentes
+
+ OPEN cur_mov;
+
+ mov_loop:
+ LOOP
+ SET v_done = FALSE;
+ FETCH cur_mov INTO i_order_row, i_article, v_concepte, i_amount, d_price, i_rate;
+
+ IF v_done THEN
+ LEAVE mov_loop;
+ END IF;
+
+ INSERT INTO vn2008.Movimientos
+ SET
+ Id_Article = i_article,
+ Id_Ticket = v_ticket,
+ Concepte = v_concepte,
+ Cantidad = i_amount,
+ Preu = d_price,
+ CostFixat = 0,
+ PrecioFijado = TRUE;
+
+ SET i_movimiento = LAST_INSERT_ID();
+
+ INSERT INTO vn2008.Movimientos_componentes (Id_Movimiento, Id_Componente, Valor)
+ SELECT i_movimiento, cm.component_id, cm.price
+ FROM order_component cm
+ JOIN bi.tarifa_componentes tc ON tc.Id_Componente = cm.component_id
+ WHERE cm.order_row_id = i_order_row
+ GROUP BY i_movimiento, cm.component_id;
+
+ UPDATE order_row SET Id_Movimiento = i_movimiento
+ WHERE id = i_order_row;
+
+ END LOOP;
+
+ CLOSE cur_mov;
+ -- Fija el Costfixat
+
+ UPDATE vn2008.Movimientos m
+ JOIN (SELECT SUM(mc.Valor) sum_valor,mc.Id_Movimiento
+ FROM vn2008.Movimientos_componentes mc
+ 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
+ JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento
+ where m.Id_Ticket = v_ticket
+ GROUP BY mc.Id_Movimiento) mc ON mc.Id_Movimiento = m.Id_Movimiento
+ SET m.CostFixat = sum_valor;
+ END LOOP;
+
+ CLOSE cur_tick;
+
+ DELETE FROM order_basket WHERE order_id = v_order;
+ UPDATE `order` SET confirmed = TRUE, confirm_date = NOW()
+ WHERE id = v_order;
+
+ 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 */ ;
+
+--
+-- Current Database: `bs`
+--
+
+CREATE DATABASE /*!32312 IF NOT EXISTS*/ `bs` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
+
+USE `bs`;
+
+--
+-- Temporary view structure for view `VentasPorCliente`
+--
+
+DROP TABLE IF EXISTS `VentasPorCliente`;
+/*!50001 DROP VIEW IF EXISTS `VentasPorCliente`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `VentasPorCliente` AS SELECT
+ 1 AS `Id_Cliente`,
+ 1 AS `VentaBasica`,
+ 1 AS `year`,
+ 1 AS `month`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `bancos_evolution`
+--
+
+DROP TABLE IF EXISTS `bancos_evolution`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `bancos_evolution` (
+ `Fecha` date NOT NULL,
+ `Id_Banco` int(11) NOT NULL,
+ `saldo` double NOT NULL DEFAULT '0',
+ `quilla` double NOT NULL DEFAULT '0',
+ `deuda` double NOT NULL DEFAULT '0',
+ `liquidez` double NOT NULL DEFAULT '0',
+ `disponibilidad ajena` double NOT NULL DEFAULT '0',
+ `saldo_aux` double NOT NULL DEFAULT '0' COMMENT 'Saldo auxiliar para el calculo de lo dispuesto en las polizas',
+ PRIMARY KEY (`Fecha`,`Id_Banco`),
+ KEY `fk_banco_evolution_idx` (`Id_Banco`),
+ CONSTRAINT `fk_banco_evolution` FOREIGN KEY (`Id_Banco`) REFERENCES `vn2008`.`Bancos` (`Id_Banco`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los saldos bancarios';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `carteras`
+--
+
+DROP TABLE IF EXISTS `carteras`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `carteras` (
+ `CodigoTrabajador` varchar(3) CHARACTER SET latin1 NOT NULL,
+ `Año` int(11) NOT NULL,
+ `Mes` int(11) NOT NULL,
+ `Peso` decimal(10,2) DEFAULT NULL,
+ PRIMARY KEY (`CodigoTrabajador`,`Año`,`Mes`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `compradores`
+--
+
+DROP TABLE IF EXISTS `compradores`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `compradores` (
+ `Id_Trabajador` int(11) NOT NULL,
+ `año` int(4) NOT NULL,
+ `semana` int(2) NOT NULL,
+ `importe` decimal(10,2) DEFAULT NULL,
+ `comision` decimal(10,2) DEFAULT NULL,
+ PRIMARY KEY (`Id_Trabajador`,`año`,`semana`),
+ CONSTRAINT `comprador_trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) 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 `compradores_evolution`
+--
+
+DROP TABLE IF EXISTS `compradores_evolution`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `compradores_evolution` (
+ `Id_Trabajador` int(11) NOT NULL,
+ `fecha` date NOT NULL,
+ `importe` decimal(10,2) DEFAULT NULL,
+ PRIMARY KEY (`Id_Trabajador`,`fecha`),
+ CONSTRAINT `evo_trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) 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 `experienceIberflora2016`
+--
+
+DROP TABLE IF EXISTS `experienceIberflora2016`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `experienceIberflora2016` (
+ `Id_Cliente` int(11) NOT NULL,
+ `isVisitor` tinyint(4) NOT NULL DEFAULT '0',
+ PRIMARY KEY (`Id_Cliente`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de clientes que participan en el estudio sobre la mejora del consumo tras la visita a las instalaciones de Silla';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `fondo_maniobra`
+--
+
+DROP TABLE IF EXISTS `fondo_maniobra`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `fondo_maniobra` (
+ `fecha` date NOT NULL,
+ `fondo` double DEFAULT NULL,
+ `clientes_facturas` double DEFAULT NULL,
+ `clientes_cobros` double DEFAULT NULL,
+ `proveedores_facturas` double DEFAULT NULL,
+ `proveedores_pagos` double DEFAULT NULL,
+ `fondo_medio` double DEFAULT NULL,
+ PRIMARY KEY (`fecha`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `manaCustomer`
+--
+
+DROP TABLE IF EXISTS `manaCustomer`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `manaCustomer` (
+ `Id_Cliente` int(11) NOT NULL,
+ `Mana` decimal(10,0) NOT NULL DEFAULT '0',
+ `dated` date NOT NULL,
+ PRIMARY KEY (`Id_Cliente`,`dated`),
+ KEY `manaCustomerIdx1` (`dated`),
+ CONSTRAINT `cliente_fk` FOREIGN KEY (`Id_Cliente`) REFERENCES `vn2008`.`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 `mana_spellers`
+--
+
+DROP TABLE IF EXISTS `mana_spellers`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `mana_spellers` (
+ `Id_Trabajador` int(11) NOT NULL,
+ `size` int(11) NOT NULL DEFAULT '300',
+ `used` int(11) NOT NULL DEFAULT '0',
+ `prices_modifier_rate` double NOT NULL DEFAULT '0',
+ `prices_modifier_activated` tinyint(1) NOT NULL DEFAULT '1',
+ PRIMARY KEY (`Id_Trabajador`),
+ KEY `fk_mana_spellers_Trabajadores_idx` (`Id_Trabajador`),
+ CONSTRAINT `fk_mana_spellers_Trabajadores` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `bs`.`mana_spellers_AFTER_INSERT` AFTER INSERT ON `mana_spellers` FOR EACH ROW
+BEGIN
+
+
+ REPLACE vn2008.Permisos(Id_Grupo, Id_Trabajador)
+ VALUES(6, NEW.Id_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 */ ;
+ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+
+--
+-- Table structure for table `nightTask`
+--
+
+DROP TABLE IF EXISTS `nightTask`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `nightTask` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `started` datetime DEFAULT NULL,
+ `finished` datetime DEFAULT NULL,
+ `order` int(11) DEFAULT NULL,
+ `schema` varchar(45) COLLATE utf8_unicode_ci NOT NULL,
+ `procedure` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB AUTO_INCREMENT=40 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 `bs`.`nightTaskBeforeInsert` BEFORE INSERT ON `nightTask` FOR EACH ROW
+BEGIN
+
+ IF NOT (NEW.`schema`REGEXP '^[0-9a-zA-Z_]+$') OR NOT (NEW.`procedure`REGEXP '^[0-9a-zA-Z_]+$') THEN
+
+ CALL util.throw('ONLY_ALPHANUMERICS_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 */ ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `bs`.`nightTaskBeforeUpdate` BEFORE UPDATE ON `nightTask` FOR EACH ROW
+BEGIN
+
+ IF NOT (NEW.`schema`REGEXP '^[0-9a-zA-Z_]+$') OR NOT (NEW.`procedure`REGEXP '^[0-9a-zA-Z_]+$') THEN
+
+ CALL util.throw('ONLY_ALPHANUMERICS_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 */ ;
+
+--
+-- Temporary view structure for view `v_ventas`
+--
+
+DROP TABLE IF EXISTS `v_ventas`;
+/*!50001 DROP VIEW IF EXISTS `v_ventas`*/;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+/*!50001 CREATE VIEW `v_ventas` AS SELECT
+ 1 AS `importe`,
+ 1 AS `recargo`,
+ 1 AS `year`,
+ 1 AS `month`,
+ 1 AS `week`,
+ 1 AS `day`*/;
+SET character_set_client = @saved_cs_client;
+
+--
+-- Table structure for table `vendedores`
+--
+
+DROP TABLE IF EXISTS `vendedores`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `vendedores` (
+ `Id_Trabajador` int(11) NOT NULL,
+ `año` int(4) NOT NULL,
+ `mes` int(2) NOT NULL,
+ `importe` decimal(10,2) DEFAULT NULL,
+ `comision` decimal(10,2) DEFAULT NULL,
+ `comisionArrendada` decimal(10,2) DEFAULT NULL COMMENT 'comision proveniente de clientes que han sido donados. Ver tabla Clientes_cedidos',
+ `comisionCedida` decimal(10,2) DEFAULT NULL COMMENT 'comision generada por los clientes que han sido donados. Ver tabla Clientes_cedidos',
+ PRIMARY KEY (`Id_Trabajador`,`año`,`mes`),
+ CONSTRAINT `trabajador_trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) 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 `vendedores_evolution`
+--
+
+DROP TABLE IF EXISTS `vendedores_evolution`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `vendedores_evolution` (
+ `Id_Trabajador` int(11) NOT NULL,
+ `fecha` date NOT NULL,
+ `importe` decimal(10,2) DEFAULT NULL,
+ PRIMARY KEY (`Id_Trabajador`,`fecha`),
+ CONSTRAINT `evo_vendedor_trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) 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 `ventas`
+--
+
+DROP TABLE IF EXISTS `ventas`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `ventas` (
+ `Id_Movimiento` int(11) NOT NULL,
+ `importe` decimal(10,3) NOT NULL DEFAULT '0.000',
+ `recargo` decimal(10,3) NOT NULL DEFAULT '0.000',
+ `fecha` date NOT NULL,
+ `tipo_id` smallint(5) unsigned NOT NULL,
+ `Id_Cliente` int(11) NOT NULL DEFAULT '1',
+ `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442',
+ PRIMARY KEY (`Id_Movimiento`),
+ KEY `tip_to_tip_idx` (`tipo_id`),
+ KEY `clientes_bs_ventas_idx` (`Id_Cliente`),
+ KEY `empresa_bs_ventas_idx` (`empresa_id`),
+ KEY `fecha_bs` (`fecha`),
+ CONSTRAINT `clientes_bs_ventas` FOREIGN KEY (`Id_Cliente`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `empresa_bs_ventas` FOREIGN KEY (`empresa_id`) REFERENCES `vn2008`.`empresa` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `mov_to_mov` FOREIGN KEY (`Id_Movimiento`) REFERENCES `vn2008`.`Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `tip_to_tip` FOREIGN KEY (`tipo_id`) REFERENCES `vn2008`.`Tipos` (`tipo_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 `ventasComponentes`
+--
+
+DROP TABLE IF EXISTS `ventasComponentes`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `ventasComponentes` (
+ `Fecha` varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '',
+ `Id_Componente` int(11) NOT NULL,
+ `Importe` decimal(10,2) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Table structure for table `ventas_contables`
+--
+
+DROP TABLE IF EXISTS `ventas_contables`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `ventas_contables` (
+ `year` int(4) NOT NULL,
+ `month` int(2) NOT NULL,
+ `venta` decimal(10,2) DEFAULT NULL,
+ `grupo` int(1) NOT NULL,
+ `reino_id` int(10) unsigned NOT NULL,
+ `tipo_id` smallint(5) unsigned NOT NULL,
+ `empresa_id` int(4) NOT NULL,
+ `gasto` varchar(10) CHARACTER SET latin1 NOT NULL,
+ PRIMARY KEY (`year`,`month`,`grupo`,`reino_id`,`tipo_id`,`empresa_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping events for database 'bs'
+--
+/*!50106 SET @save_time_zone= @@TIME_ZONE */ ;
+/*!50106 DROP EVENT IF EXISTS `nightly_tasks` */;
+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 = utf8 */ ;;
+/*!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' */ ;;
+/*!50003 SET @saved_time_zone = @@time_zone */ ;;
+/*!50003 SET time_zone = 'SYSTEM' */ ;;
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `nightly_tasks` ON SCHEDULE EVERY 1 DAY STARTS '2017-08-27 01:00:00' ON COMPLETION NOT PRESERVE ENABLE DO CALL bs.nightTaskLauncher() */ ;;
+/*!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 `nightly_tasks2` */;;
+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 = utf8 */ ;;
+/*!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' */ ;;
+/*!50003 SET @saved_time_zone = @@time_zone */ ;;
+/*!50003 SET time_zone = 'SYSTEM' */ ;;
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `nightly_tasks2` ON SCHEDULE EVERY 1 DAY STARTS '2017-03-24 02:00:00' ON COMPLETION NOT PRESERVE ENABLE DO call bs.nightTaskLauncher() */ ;;
+/*!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 `nightly_tasks3` */;;
+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 = utf8 */ ;;
+/*!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' */ ;;
+/*!50003 SET @saved_time_zone = @@time_zone */ ;;
+/*!50003 SET time_zone = 'SYSTEM' */ ;;
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `nightly_tasks3` ON SCHEDULE EVERY 1 DAY STARTS '2017-03-24 03:00:00' ON COMPLETION NOT PRESERVE ENABLE DO call bs.nightTaskLauncher() */ ;;
+/*!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 `nightly_tasks4` */;;
+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 = utf8 */ ;;
+/*!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' */ ;;
+/*!50003 SET @saved_time_zone = @@time_zone */ ;;
+/*!50003 SET time_zone = 'SYSTEM' */ ;;
+/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `nightly_tasks4` ON SCHEDULE EVERY 1 DAY STARTS '2017-03-24 04:00:00' ON COMPLETION NOT PRESERVE ENABLE DO call bs.nightTaskLauncher() */ ;;
+/*!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 'bs'
+--
+/*!50003 DROP PROCEDURE IF EXISTS `analisisComponentes` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `analisisComponentes`()
+BEGIN
+
+DECLARE vDateStart DATE DEFAULT '2017-01-01';
+DECLARE vDateEnd DATE DEFAULT '2017-11-30';
+DECLARE vDate DATE;
+
+SET vDate = vDateStart;
+
+DELETE FROM bs.ventasComponentes;
+
+WHILE vDate <= vDateEnd DO
+
+ INSERT INTO bs.ventasComponentes
+ SELECT vDate as Fecha, mc.Id_Componente, cast(sum(m.Cantidad * mc.Valor) AS DECIMAL(10,2)) as Importe
+ FROM vn2008.Movimientos_componentes mc
+ JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento
+ JOIN bs.ventas v ON v.Id_Movimiento = mc.Id_Movimiento
+ WHERE v.fecha = vDate
+ GROUP BY mc.Id_Componente;
+
+ SET vDate = TIMESTAMPADD(DAY,1,vDate);
+
+ IF DAY(vDate) MOD 10 = 0 THEN
+
+ SELECT vDate;
+
+ END IF;
+
+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 `bancos_evolution_add` */;
+ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `bancos_evolution_add`()
+BEGIN
+/*
+
+Inserta en la tabla bancos_evolution los saldos acumulados
+
+*/
+
+
+DECLARE vCurrentDate DATE;
+DECLARE vStartingDate DATE DEFAULT '2015-01-01';
+DECLARE vMaxDate DATE DEFAULT TIMESTAMPADD(MONTH, 2, CURDATE());
+
+SELECT max(Fecha)
+ INTO vStartingDate
+ FROM bs.bancos_evolution
+ WHERE Fecha > '2015-01-01';
+
+DELETE FROM bs.bancos_evolution
+WHERE Fecha > vStartingDate;
+
+SET vCurrentDate = vStartingDate;
+
+
+
+
+ WHILE vCurrentDate < vMaxDate DO
+
+ IF day(vCurrentDate) mod 28 = 0 then
+ SELECT vCurrentDate;
+ end if;
+
+
+ REPLACE bs.bancos_evolution( Fecha
+ ,Id_Banco
+ ,saldo)
+
+ SELECT vCurrentDate
+ , Id_Banco
+ , sum(saldo)
+
+ FROM
+ (
+
+ SELECT Id_Banco
+ ,saldo_aux as saldo
+ FROM bs.bancos_evolution
+
+ WHERE Fecha = TIMESTAMPADD(DAY,-1,vCurrentDate) -- los saldos acumulados del dia anterior
+
+ UNION ALL
+
+ SELECT c.Id_Banco, IFNULL(sum(Entrada),0) - ifnull(sum(Salida),0) as saldo
+ FROM vn2008.Cajas c
+ JOIN vn2008.Bancos b using(Id_Banco) -- saldos de las cajas
+ WHERE cash IN (0,3)
+ AND Cajafecha = vCurrentDate
+ AND (Serie = 'MB' OR cash = 3)
+ GROUP BY Id_Banco
+
+ UNION ALL
+
+ SELECT id_banco, - importe -- pagos futuros
+ FROM vn2008.pago
+ WHERE fecha = vCurrentDate
+ AND fecha >= CURDATE()
+ AND NOT conciliado
+
+ UNION ALL
+
+ SELECT Id_Banco, Entregado -- cobros futuros
+ FROM vn2008.Recibos
+ WHERE Fechacobro = vCurrentDate
+ AND Fechacobro > CURDATE()
+
+ UNION ALL
+
+ SELECT sp.Id_Banco, Importe -- saldos de la tabla prevision
+ FROM vn2008.Saldos_Prevision sp
+ JOIN vn2008.Bancos b using(Id_Banco)
+ WHERE cash IN (0,3)
+ AND Fecha = vCurrentDate
+
+
+
+ )sub
+ GROUP BY Id_Banco;
+
+ -- Utilizamos el saldo_auxiliar para calcular lo dispuesto en las polizas
+
+ UPDATE bs.bancos_evolution be
+ SET saldo_aux = saldo;
+
+ -- Ahora actualizamos la quilla
+ UPDATE bs.bancos_evolution be
+ LEFT JOIN
+ (
+ SELECT Id_Banco, - sum(importe) as quilla
+ FROM vn2008.Bancos_poliza
+ WHERE vCurrentDate between apertura AND IFNULL(cierre, vCurrentDate)
+ GROUP BY Id_Banco
+ ) sub using(Id_Banco)
+ SET be.quilla = sub.quilla
+ WHERE be.Fecha = vCurrentDate;
+
+
+ SET vCurrentDate = TIMESTAMPADD(DAY,1,vCurrentDate);
+
+ END WHILE;
+
+
+ -- Deuda
+ UPDATE bs.bancos_evolution be
+ JOIN vn2008.Bancos using(Id_Banco)
+ SET be.deuda = IF(cash = 3, be.saldo_aux, 0)
+ , be.saldo = IF(cash = 3, 0, be.saldo_aux)
+ WHERE Fecha >= vStartingDate;
+
+
+ -- Liquidez
+ update bs.bancos_evolution set liquidez = saldo - quilla + deuda WHERE Fecha >= vStartingDate;
+
+ -- Disponibilidad
+ update bs.bancos_evolution set `disponibilidad ajena` = - quilla + deuda WHERE Fecha >= vStartingDate;
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `campaignComparative` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `campaignComparative`(vDateFrom DATE, vDateTo DATE)
+BEGIN
+ SELECT
+ workerName,
+ id,
+ name,
+ CAST(SUM(previousAmmount) AS DECIMAL(10, 0)) AS previousAmmount,
+ CAST(SUM(currentAmmount) AS DECIMAL(10, 0)) AS currentAmmount
+ FROM (
+ (SELECT
+ CONCAT(w.firstname, ' ', w.name) AS workerName,
+ c.id,
+ c.name,
+ SUM(v.importe) AS previousAmmount,
+ 0 currentAmmount
+ FROM bs.ventas v
+ INNER JOIN vn.`client` c ON v.Id_Cliente = c.id
+ INNER JOIN vn.worker w ON c.salesPersonFk = w.id
+ WHERE v.fecha BETWEEN DATE_ADD(vDateFrom, INTERVAL - 1 YEAR)
+ AND DATE_ADD(vDateTo, INTERVAL - 1 YEAR)
+ GROUP BY w.id, v.Id_Cliente)
+ UNION ALL
+ (SELECT
+ CONCAT(w.firstname, ' ', w.name) AS workerName,
+ c.id,
+ c.name,
+ 0 AS previousAmmount,
+ SUM(s.quantity * s.price) AS currentAmmount
+ FROM vn.sale s
+ JOIN vn.ticket t ON t.id = s.ticketFk
+ JOIN vn.client c ON c.id = t.clientFk
+ JOIN vn.worker w ON c.salesPersonFk = w.id
+ WHERE t.shipped BETWEEN vDateFrom
+ AND vDateTo
+ GROUP BY w.id, c.id)
+ ) comparative
+ GROUP BY workerName, id
+ HAVING (previousAmmount <> 0 OR currentAmmount <> 0)
+ ORDER BY workerName, 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 `carteras_add` */;
+ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `carteras_add`()
+BEGIN
+
+DELETE FROM bs.carteras
+WHERE Año >= YEAR(CURDATE()) - 1;
+
+INSERT INTO bs.carteras(Año,Mes,CodigoTrabajador,Peso)
+SELECT year as Año, month as Mes, CodigoTrabajador, sum(importe) as Peso
+FROM vn2008.time t
+JOIN bs.ventas v on t.date = v.fecha
+JOIN vn2008.Clientes c on c.Id_Cliente = v.Id_Cliente
+JOIN vn2008.Trabajadores tr on tr.Id_Trabajador = c.Id_Trabajador
+WHERE t.year >= YEAR(CURDATE()) - 1
+GROUP BY CodigoTrabajador, Año, Mes;
+
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `comercialesCompleto` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `comercialesCompleto`(IN vWorker INT)
+BEGIN
+create TEMPORARY TABLE workerAndBelow ENGINE=MEMORY
+
+SELECT w.id
+ FROM vn.worker w
+ WHERE w.bossFk=vWorker OR w.id=vWorker;
+
+
+SELECT
+ c.Id_Cliente id_cliente,
+ c.calidad,
+ c.Cliente cliente,
+ cr.recobro * 100 tarifa,
+ c.Telefono telefono,
+ c.movil,
+ c.POBLACION poblacion,
+ p.`name` provincia,
+ vn2008.red(f.futur) futur,
+ c.Credito credito,
+ pm.`name` forma_pago,
+ vn2008.red(c365 / 12) consumo_medio365,
+ vn2008.red(c365) consumo365,
+ vn2008.red(CmLy.peso) peso_mes_año_pasado,
+ vn2008.red(CmLy.peso * 1.19) objetivo,
+ tr.CodigoTrabajador,
+ vn2008.red(mes_actual.consumo) consumoMes,
+ vn2008.red(IFNULL(mes_actual.consumo, 0) - IFNULL(CmLy.peso * 1.19, 0)) como_lo_llevo,
+ DATE(LastTicket) ultimo_ticket,
+ dead.muerto,
+ g.Greuge,
+ cr.recobro
+FROM
+ vn2008.Clientes c
+ LEFT JOIN
+ (SELECT Id_Cliente, Greuge
+ FROM bi.Greuge_Evolution
+ WHERE Fecha = (SELECT MAX(Fecha) FROM bi.Greuge_Evolution)
+ ) g ON g.Id_Cliente = c.Id_Cliente
+ LEFT JOIN
+ vn2008.province p ON p.province_id = c.province_id
+ JOIN
+ vn2008.pay_met pm ON pm.id = c.pay_met_id
+ LEFT JOIN
+ vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
+ LEFT JOIN
+ bi.claims_ratio cr on cr.Id_Cliente = c.Id_Cliente
+ LEFT JOIN
+ (SELECT v.Id_Cliente, SUM(importe) c365 -- optimizat de 6s /5.3s/ 4.7s a 0.3/0.4/0.3
+ FROM bs.ventas v
+ JOIN vn2008.Clientes c USING (Id_Cliente)
+ JOIN workerAndBelow w ON w.id = c.Id_Trabajador
+ WHERE v.fecha BETWEEN TIMESTAMPADD(YEAR, - 1, CURDATE()) AND CURDATE()
+ GROUP BY v.Id_Cliente) c365 ON c365.Id_Cliente = c.Id_Cliente
+ LEFT JOIN
+ (SELECT
+ Id_Cliente, SUM(importe) consumo
+ FROM
+ bs.ventas v
+ INNER JOIN vn2008.Clientes c USING (Id_Cliente)
+ LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
+ WHERE
+ (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
+ AND (v.fecha BETWEEN TIMESTAMPADD(DAY, - DAY(CURDATE()) + 1, CURDATE()) AND CURDATE() - 1)
+ GROUP BY Id_Cliente) mes_actual ON mes_actual.Id_Cliente = c.Id_Cliente
+ LEFT JOIN
+ (SELECT
+ t.Id_Cliente,
+ SUM(m.preu * m.Cantidad * (1 - m.Descuento / 100)) futur
+ FROM
+ vn2008.Tickets t
+ JOIN vn2008.Clientes c ON c.Id_Cliente = t.Id_Cliente
+ JOIN vn2008.Movimientos m ON m.Id_Ticket = t.Id_Ticket
+ LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
+ WHERE
+ (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
+ AND DATE(Fecha) BETWEEN CURDATE() AND LAST_DAY(CURDATE())
+ GROUP BY Id_Cliente) f ON c.Id_Cliente = f.Id_Cliente
+ LEFT JOIN
+ (SELECT
+ MAX(t.Fecha) LastTicket, c.Id_Cliente
+ FROM
+ vn2008.Tickets t
+ JOIN vn2008.Clientes c ON c.Id_cliente = t.Id_Cliente
+ LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
+
+ WHERE
+ (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
+ GROUP BY t.Id_Cliente) LastTicket ON LastTicket.Id_Cliente = c.Id_Cliente
+ LEFT JOIN
+ (SELECT
+ SUM(importe) peso, c.Id_Cliente
+ FROM
+ bs.ventas v
+ JOIN vn2008.Clientes c ON c.Id_Cliente = v.Id_Cliente
+ LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
+ WHERE
+ MONTH(fecha) = MONTH(CURDATE())
+ AND YEAR(fecha) = YEAR(CURDATE()) - 1
+ AND (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
+ GROUP BY c.Id_Cliente) CmLy ON CmLy.Id_Cliente = c.Id_Cliente
+ LEFT JOIN
+ (SELECT
+ c.Id_Cliente,
+ IF(MAX(Fecha) < DATE_FORMAT(TIMESTAMPADD(MONTH, - 1, CURDATE()), '%Y- %m-01'), TRUE, FALSE) muerto
+ FROM
+ vn2008.Facturas f
+ JOIN vn2008.Clientes c ON c.Id_cliente = f.Id_Cliente
+ LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador
+ WHERE
+ (c.Id_Trabajador = vWorker OR tr.boss = vWorker)
+ GROUP BY Id_Cliente) dead ON dead.Id_Cliente = c.Id_Cliente
+WHERE
+ (c.Id_Trabajador = vWorker OR tr.boss = vWorker);
+DROP TEMPORARY TABLE workerAndBelow;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `compradores_add` */;
+ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `compradores_add`(IN intYEAR INT, IN intWEEK_START INT, IN intWEEK_END INT)
+BEGIN
+
+REPLACE bs.compradores
+
+SELECT tp.Id_Trabajador
+ , intYEAR as año
+ , tm.week as semana
+ , sum(importe) as importe
+ , 0 as comision
+
+FROM bs.ventas v
+JOIN vn2008.time tm on tm.date = v.fecha
+JOIN vn2008.Tipos tp using(tipo_id)
+WHERE tm.year = intYEAR and tm.week between intWEEK_START and intWEEK_END
+AND reino_id != 6
+GROUP BY tp.Id_Trabajador, tm.week;
+
+
+
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `compradores_evolution_add` */;
+ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `compradores_evolution_add`()
+BEGIN
+/*
+
+Inserta en la tabla compradores_evolution las ventas acumuladas en los ultimos 365 dias
+
+*/
+
+DECLARE datFEC DATE;
+
+
+SELECT TIMESTAMPADD(DAY,1,MAX(fecha)) INTO datFEC FROM bs.compradores_evolution;
+
+ WHILE datFEC < CURDATE() DO
+
+ SELECT datFEC;
+
+ REPLACE bs.compradores_evolution( Id_Trabajador
+ , fecha
+ , importe)
+
+ SELECT Id_Trabajador
+ , datFEC as fecha
+ , sum(importe) as importe
+
+ FROM
+ (
+
+ SELECT Id_Trabajador
+ , importe
+ FROM bs.compradores_evolution
+ WHERE fecha = TIMESTAMPADD(DAY,-1,datFEC) -- las ventas acumuladas del dia anterior
+
+ UNION ALL
+
+ SELECT Id_Trabajador
+ , importe * IF(v.fecha < datFEC,-1,1) -- se restan las ventas del año anterior y se suman las del actual
+ FROM bs.ventas v
+ JOIN vn2008.Tipos tp using(tipo_id)
+ WHERE fecha IN (datFEC, TIMESTAMPADD(DAY,-365,datFEC))
+ AND reino_id != 6
+
+ )sub
+ GROUP BY Id_Trabajador;
+
+
+
+
+ SET datFEC = TIMESTAMPADD(DAY,1,datFEC);
+
+ 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 */ ;
+ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `fondo_evolution_add` */;
+ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `fondo_evolution_add`()
+BEGIN
+/*
+
+Inserta en la tabla fondo_maniobra los saldos acumulados en los ultimos 365 dias
+
+*/
+
+DECLARE datFEC DATE DEFAULT '2015-01-01';
+
+
+SELECT TIMESTAMPADD(DAY,1,MAX(fecha)) INTO datFEC FROM bs.fondo_maniobra;
+
+ WHILE datFEC < CURDATE() DO
+
+ -- esto solo sirve para no aburrirse mientras esperamos...
+
+ IF day(datFEC) mod 28 = 0 then
+ SELECT datFEC;
+ end if;
+
+
+ REPLACE bs.fondo_maniobra(Fecha, clientes_facturas, clientes_cobros,proveedores_facturas,proveedores_pagos, fondo)
+ SELECT datFEC as Fecha, Facturas, Cobros,Recibidas,Pagos, Facturas + Cobros + Recibidas + Pagos
+ FROM
+ (
+ SELECT Sum(Facturas.Importe) AS Facturas
+ FROM vn2008.Facturas
+ INNER JOIN vn2008.Clientes ON Facturas.Id_Cliente = Clientes.Id_cliente
+ WHERE Clientes.`real`
+ AND empresa_id <>1381
+ AND Fecha between '2011-01-01' and datFEC) fac
+ JOIN
+ (
+ SELECT - Sum(Entregado) AS Cobros
+ FROM vn2008.Recibos
+ INNER JOIN vn2008.Clientes ON Recibos.Id_Cliente = Clientes.Id_cliente
+ WHERE Clientes.`real`
+ AND empresa_id <> 1381
+ AND Fechacobro Between '2011-01-01' and datFEC) cob
+ JOIN
+ (
+ SELECT - Sum(cantidad) AS Recibidas
+ FROM vn2008.recibida
+ INNER JOIN vn2008.recibida_vencimiento ON recibida.id = recibida_vencimiento.recibida_id
+ WHERE empresa_id <> 1381
+ AND recibida.fecha Between '2015-01-01' and datFEC) rec
+ JOIN
+ (
+ SELECT Sum(importe) AS Pagos
+ FROM vn2008.pago
+ WHERE empresa_id <>1381 AND pago.fecha Between '2015-01-01' and datFEC) pag;
+
+
+
+ UPDATE bs.fondo_maniobra
+ JOIN
+ (SELECT avg(fondo) as media
+ FROM bs.fondo_maniobra
+ WHERE fecha <= datFEC) sub
+ SET fondo_medio = media
+ WHERE fecha = datFEC;
+
+
+ SET datFEC = TIMESTAMPADD(DAY,1,datFEC);
+
+ 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 */ ;
+ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `manaCustomerFill_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 `manaCustomerFill_kk`()
+BEGIN
+
+
+/* Rellena la tabla caché bs.manaCustomer desde 0
+*
+* Utilizar para reconstruirla en caso de que se corrompa.
+*
+*/
+
+DECLARE vFromDated DATE;
+DECLARE vToDated DATETIME DEFAULT '2015-12-31 23:59:59';
+DECLARE isDone BOOLEAN DEFAULT FALSE;
+
+DELETE FROM bs.manaCustomer;
+
+WHILE NOT isDone DO
+
+ SELECT TIMESTAMPADD(DAY,1,vToDated), TIMESTAMPADD(MONTH, 1, vToDated)
+ INTO vFromDated, vToDated;
+
+ IF vToDated >= CURDATE() THEN
+
+ SET vToDated = TIMESTAMPADD(SECOND,-1,CURDATE());
+ SET isDone = TRUE;
+
+ END IF;
+
+ INSERT INTO bs.manaCustomer(Id_Cliente, Mana)
+ SELECT Id_Cliente, newMana
+ FROM
+ (SELECT cs.Id_Cliente, - sum(Cantidad * Valor) as newMana
+ FROM vn2008.Tickets t
+ JOIN vn2008.Consignatarios cs using(Id_Consigna)
+ JOIN vn2008.Movimientos m using(Id_Ticket)
+ JOIN vn2008.Movimientos_componentes mc using(Id_Movimiento)
+ WHERE Id_Componente IN (39, 37) -- maná auto y maná
+ AND Fecha BETWEEN vFromDated AND vToDated
+ GROUP BY cs.Id_Cliente
+ ) t1
+ ON DUPLICATE KEY UPDATE Mana = Mana + newMana;
+
+ SELECT vFromDated, vToDated;
+
+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 `manaCustomerUpdate` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `manaCustomerUpdate`()
+BEGIN
+DECLARE vToDated DATE;
+ DECLARE vFromDated DATE;
+ DECLARE vForDeleteDated DATE;
+ DECLARE vManaId INT DEFAULT 37;
+ DECLARE vManaAutoId INT DEFAULT 39;
+ DECLARE vManaBankId INT DEFAULT 66;
+ DECLARE vManaGreugeTypeId INT DEFAULT 3;
+
+ SELECT IFNULL(max(dated), '2016-01-01')
+ INTO vFromDated
+ FROM bs.manaCustomer;
+
+ WHILE timestampadd(week,1,vFromDated) < CURDATE() DO
+
+ SELECT
+ timestampadd(week,1,vFromDated),
+ timestampadd(week,-4,vFromDated)
+ INTO
+ vToDated,
+ vForDeleteDated;
+
+ DELETE FROM bs.manaCustomer
+ WHERE dated <= vForDeleteDated;
+
+
+ INSERT INTO bs.manaCustomer(Id_Cliente, Mana, dated)
+
+ SELECT
+ Id_Cliente,
+ cast(sum(mana) as decimal(10,2)) as mana,
+ vToDated as dated
+ FROM
+
+ (
+ SELECT cs.Id_Cliente, Cantidad * Valor as mana
+ FROM vn2008.Tickets t
+ JOIN vn2008.Consignatarios cs using(Id_Consigna)
+ JOIN vn2008.Movimientos m on m.Id_Ticket = t.Id_Ticket
+ JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento
+ WHERE Id_Componente IN (vManaAutoId, vManaId)
+ AND Fecha > vFromDated
+ AND Fecha <= vToDated
+
+
+ UNION ALL
+
+ SELECT r.Id_Cliente, - Entregado
+ FROM vn2008.Recibos r
+ WHERE Id_Banco = vManaBankId
+ AND Fechacobro > vFromDated
+ AND Fechacobro <= vToDated
+
+ UNION ALL
+
+ SELECT g.Id_Cliente, g.Importe
+ FROM vn2008.Greuges g
+ WHERE Greuges_type_id = vManaGreugeTypeId
+ AND Fecha > vFromDated
+ AND Fecha <= vToDated
+
+ UNION ALL
+
+ SELECT Id_Cliente, mana
+ FROM bs.manaCustomer
+ WHERE dated = vFromDated
+ ) sub
+
+ GROUP BY Id_Cliente
+ HAVING Id_Cliente;
+
+ SET vFromDated = vToDated;
+
+ 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 `mana_price_modifier_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 `mana_price_modifier_update`()
+BEGIN
+
+INSERT INTO vn2008.daily_task_log(consulta)
+VALUES ('bs.mana_price_modifier_update');
+
+UPDATE mana_spellers
+JOIN
+ (SELECT Id_Trabajador, floor(sum(importe)/12) as pesoCarteraMensual
+ FROM bs.vendedores v
+ WHERE año * 100 + mes >= (year(curdate()) -1) * 100 + month(curdate())
+ GROUP BY Id_Trabajador
+ ) ultimo_año_de_ventas using(Id_Trabajador)
+SET prices_modifier_rate = GREATEST(-0.05,LEAST(0.05,round(- used/pesoCarteraMensual,3))) ;
+
+
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `nightly_tasks` */;
+ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `nightly_tasks`()
+BEGIN
+
+DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN
+ INSERT INTO vn2008.mail SET `to` = 'informatica@verdnatura.es', subject = 'bs.nightly_tasks', `text` = CONCAT('ERROR ', @errno, ' (', @sqlstate, '): ', @text);
+ INSERT INTO vn2008.mail SET `to` = 'pako@verdnatura.es', subject = 'bs.nightly_tasks', `text` = CONCAT('ERROR ', @errno, ' (', @sqlstate, '): ', @text);
+END;
+
+ insert into vn2008.daily_task_log(consulta) VALUES('arranca el event bs.nightly_tasks');
+
+ call bancos_evolution_add;
+
+ call fondo_evolution_add;
+
+ call ventas_add(timestampadd(month,-1,curdate()),curdate());
+
+ call ventas_contables_add(YEAR(TIMESTAMPADD(MONTH,-1,CURDATE())), MONTH(TIMESTAMPADD(MONTH,-1,CURDATE())));
+
+ call bs.vendedores_add(year(curdate()), month(curdate()));
+
+ call bs.vendedores_add(year(timestampadd(month,-1,curdate()))
+ , month(timestampadd(month,-1,curdate()))
+ );
+
+ call carteras_add;
+
+ call vn2008.mana_inventory_requery;
+
+ call bs.mana_price_modifier_update;
+
+ call bs.manaCustomerUpdate;
+
+ insert into vn2008.daily_task_log(consulta) VALUES('finalitza el event bs.nightly_tasks');
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `nightTaskLauncher` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `nightTaskLauncher`()
+BEGIN
+
+ DECLARE done BOOL DEFAULT FALSE;
+ DECLARE vSchema VARCHAR(255);
+ DECLARE vProcedure VARCHAR(255);
+ DECLARE vId INT;
+
+ DECLARE rs CURSOR FOR
+ SELECT id,`schema`, `procedure`
+ FROM bs.nightTask
+ WHERE IFNULL(finished,0) <= CURDATE()
+ ORDER BY `order`;
+
+ DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
+
+ OPEN rs;
+
+ FETCH rs INTO vId, vSchema, vProcedure;
+
+ WHILE NOT done DO
+
+ SELECT vId, vSchema, vProcedure;
+
+ UPDATE bs.nightTask
+ SET started = now()
+ WHERE id = vId;
+
+ CALL util.exec (sql_printf('CALL %s.%s',vSchema, vProcedure));
+
+ UPDATE bs.nightTask
+ SET finished = now()
+ WHERE id = vId;
+
+ FETCH rs INTO vId, vSchema, vProcedure;
+
+ 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 `nocturnEvent_Tickets_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 `nocturnEvent_Tickets_Bionizar`()
+BEGIN
+
+DECLARE MyDate DATE;
+/*
+ DECLARE EXIT HANDLER FOR SQLEXCEPTION
+ BEGIN
+
+ GET DIAGNOSTICS CONDITION 2 @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
+ SELECT CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'));
+ INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('jgallego@verdnatura.es', 'nocturnEvent_Tickets_Bionizar' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')));
+ INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('pako@verdnatura.es', 'nocturnEvent_Tickets_Bionizar' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')));
+
+END;
+*/
+
+
+SET MyDate = timestampadd(week,-1,curdate());
+
+ INSERT INTO vn2008.daily_task_log(consulta) VALUES('Comença la rebionització de tickets ');
+
+WHILE MyDate < CURDATE() DO
+
+ CALL `vn2008`.`bionic_tickets_range_bionizar`(MyDate, MyDate);
+
+ SET MyDate = timestampadd(DAY,1,MyDate);
+
+ SELECT MyDate;
+
+END WHILE;
+
+ INSERT INTO vn2008.daily_task_log(consulta) VALUES('finalitza la rebionització de tickets ');
+
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `vendedores_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `vendedores_add`(IN intYEAR INT, IN intMONTH INT)
+BEGIN
+
+REPLACE vendedores
+
+SELECT c.Id_Trabajador
+ , intYEAR
+ , intMONTH
+ , sum(importe) as importe
+ , sum(importe) * 0.029 as comision
+ , 0 as comisionCedida
+ , 0 as comisionArrendada
+
+FROM ventas v
+JOIN vn2008.Clientes c on v.Id_Cliente = c.Id_Cliente
+JOIN vn2008.time on time.date = v.fecha
+WHERE time.year = intYEAR and time.month = intMONTH
+AND c.Id_Trabajador is not null
+GROUP BY c.Id_Trabajador;
+
+-- Ventas cedidas
+
+UPDATE vendedores
+JOIN
+(
+SELECT cc.Id_Trabajador_old as Id_Trabajador
+ , sum(importe) * 0.029 * comision_old as cedido
+
+FROM ventas v
+JOIN vn2008.Clientes c on v.Id_Cliente = c.Id_Cliente
+JOIN vn2008.Clientes_cedidos cc on cc.Id_Cliente = c.Id_Cliente
+JOIN vn2008.time on time.date = v.fecha
+WHERE time.year = intYEAR and time.month = intMONTH
+AND c.Id_Trabajador is not null
+GROUP BY cc.Id_Trabajador_old
+) sub using(Id_Trabajador)
+SET comisionCedida = cedido, comision = comision - cedido
+WHERE año = intYEAR and mes = intMONTH;
+
+-- Ventas arrendadas
+
+UPDATE vendedores
+JOIN
+(
+SELECT cc.Id_Trabajador_new as Id_Trabajador
+ , sum(importe) * 0.029 * comision_new as arrendada
+
+FROM ventas v
+JOIN vn2008.Clientes c on v.Id_Cliente = c.Id_Cliente
+JOIN vn2008.Clientes_cedidos cc on cc.Id_Cliente = c.Id_Cliente AND v.fecha between datSTART and datEND
+JOIN vn2008.time on time.date = v.fecha
+WHERE time.year = intYEAR and time.month = intMONTH
+AND c.Id_Trabajador is not null
+GROUP BY cc.Id_Trabajador_new
+) sub using(Id_Trabajador)
+SET comisionArrendada = arrendada, comision = comision - arrendada
+WHERE año = intYEAR and mes = intMONTH;
+
+
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `vendedores_add_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 `vendedores_add_launcher`()
+BEGIN
+
+ call bs.vendedores_add(year(curdate()), month(curdate()));
+ call bs.vendedores_add(year(timestampadd(month,-1,curdate())), month(timestampadd(month,-1,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 `vendedores_evolution_add` */;
+ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `vendedores_evolution_add`()
+BEGIN
+/*
+
+Inserta en la tabla compradores_evolution las ventas acumuladas en los ultimos 365 dias
+
+*/
+
+DECLARE datFEC DATE;
+
+
+SELECT TIMESTAMPADD(DAY,1,MAX(fecha)) INTO datFEC FROM bs.vendedores_evolution;
+
+ WHILE datFEC < CURDATE() DO
+
+ SELECT datFEC;
+
+ REPLACE bs.vendedores_evolution( Id_Trabajador
+ , fecha
+ , importe)
+
+ SELECT Id_Trabajador
+ , datFEC as fecha
+ , sum(importe) as importe
+
+ FROM
+ (
+
+ SELECT Id_Trabajador
+ , importe
+ FROM bs.vendedores_evolution
+ WHERE fecha = TIMESTAMPADD(DAY,-1,datFEC) -- las ventas acumuladas del dia anterior
+
+ UNION ALL
+
+ SELECT c.Id_Trabajador
+ , importe * IF(v.fecha < datFEC,-1,1) -- se restan las ventas del año anterior y se suman las del actual
+ FROM bs.ventas v
+ JOIN vn2008.Movimientos m using(Id_Movimiento)
+ JOIN vn2008.Tickets t using(Id_Ticket)
+ JOIN vn2008.Consignatarios cs using(Id_Consigna)
+ JOIN vn2008.Clientes c on cs.Id_Cliente = c.Id_Cliente
+ JOIN vn2008.Tipos using(tipo_id)
+ WHERE v.fecha IN (datFEC, TIMESTAMPADD(DAY,-365,datFEC))
+ AND c.Id_Trabajador is not null
+ AND (Id_Article = 98 or Id_Article = 95 or reino_id != 6)
+ GROUP BY c.Id_Trabajador
+
+
+ )sub
+ GROUP BY Id_Trabajador;
+
+
+
+
+ SET datFEC = TIMESTAMPADD(DAY,1,datFEC);
+
+ 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 */ ;
+ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `ventas_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` PROCEDURE `ventas_add`(IN datSTART DATETIME, IN datEND DATETIME)
+BEGIN
+
+
+DECLARE vStartingPeriod INT;
+DECLARE vStartingDate DATETIME;
+DECLARE vEndingDate DATETIME;
+DECLARE TIPO_PATRIMONIAL INT DEFAULT 188;
+
+SET datEND = vn2008.dayend(datEND);
+SET vStartingDate = GREATEST('2015-10-01',datSTART);
+SET vEndingDate = vn2008.dayend(vStartingDate);
+
+DELETE FROM ventas
+WHERE fecha between vStartingDate and datEND;
+
+WHILE vEndingDate <= datEND DO
+
+
+-- Ventes bioniques
+ SELECT vStartingDate,vEndingDate, datEND;
+
+ REPLACE ventas(Id_Movimiento, importe, recargo, fecha, tipo_id, Id_Cliente, empresa_id)
+ SELECT Id_Movimiento
+ , sum( IF(base, Cantidad * Valor, 0) ) as importe
+ , sum( IF(base, 0, Cantidad * Valor) ) as recargo
+ , vStartingDate
+ , a.tipo_id
+ , cs.Id_Cliente
+ , t.empresa_id
+ FROM vn2008.Movimientos_componentes mc
+ JOIN bi.tarifa_componentes tc using(Id_Componente)
+ JOIN bi.tarifa_componentes_series tcs using(tarifa_componentes_series_id)
+ JOIN vn2008.Movimientos m using(Id_Movimiento)
+ JOIN vn2008.Articles a using(Id_Article)
+ JOIN vn2008.Tipos tp using(tipo_id)
+ JOIN vn2008.reinos r on r.id = tp.reino_id
+ 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.empresa e on e.id = empresa_id
+ WHERE t.Fecha between vStartingDate and vEndingDate
+ AND datEND >= '2015-10-01'
+ AND (
+ c.`Real` != 0
+ OR c.Razonsocial = 'MIRIAM FERRER TORIBIO'
+ OR c.Razonsocial = 'VERDNATURA COMPLEMENTOS'
+ )
+ AND Cantidad <> 0
+ AND a.tipo_id != TIPO_PATRIMONIAL
+ AND c.Id_Trabajador IS NOT NULL
+ AND m.Descuento <> 100
+ AND (m.Id_Article = 98 or m.Id_Article = 95 or r.mercancia != 0)
+ GROUP BY mc.Id_Movimiento
+ HAVING IFNULL(importe,0) <> 0 OR IFNULL(recargo,0) <> 0;
+
+/*
+UPDATE vn2008.Movimientos m
+JOIN bs.ventas v ON v.Id_Movimiento = m.Id_Movimiento
+SET m.Costfixat = IFNULL(round(v.importe/m.Cantidad,2),0)
+WHERE v.fecha between vStartingDate and vEndingDate;
+*/
+
+ SET vStartingDate = TIMESTAMPADD(DAY,1, vStartingDate);
+ SET vEndingDate = vn2008.dayend(vStartingDate);
+
+
+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 `ventas_add_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 `ventas_add_launcher`()
+BEGIN
+
+ call bs.ventas_add(timestampadd(week,-1,curdate()),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 `ventas_contables_add` */;
+ALTER DATABASE `bs` CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ventas_contables_add`(IN vYear INT, IN vMonth INT)
+BEGIN
+/**
+ * Reemplaza las ventas contables. Es el origen de datos para el balance de Entradas
+ *
+ * @param vYear Año a reemplazar
+ * @param vMonth Mes a reemplazar
+ *
+ *
+ **/
+DECLARE TIPO_PATRIMONIAL INT DEFAULT 188;
+
+DELETE FROM bs.ventas_contables
+ WHERE year = vYear
+ AND month = vMonth;
+
+DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list;
+
+CREATE TEMPORARY TABLE tmp.ticket_list
+ (PRIMARY KEY (Id_Ticket))
+ SELECT Id_Ticket
+ FROM vn2008.Tickets t
+ JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura
+ WHERE year(f.Fecha) = vYear
+ AND month(f.Fecha) = vMonth;
+
+
+INSERT INTO bs.ventas_contables(year
+ , month
+ , venta
+ , grupo
+ , reino_id
+ , tipo_id
+ , empresa_id
+ , gasto)
+
+ SELECT vYear
+ , vMonth
+ , round(sum(Cantidad * Preu * (100 - m.Descuento)/100))
+ , if(
+ e.empresa_grupo = e2.empresa_grupo
+ ,1
+ ,if(e2.empresa_grupo,2,0)
+ ) as grupo
+ , tp.reino_id
+ , a.tipo_id
+ , t.empresa_id
+ , 7000000000
+ + if(e.empresa_grupo = e2.empresa_grupo
+ ,1
+ ,if(e2.empresa_grupo,2,0)
+ ) * 1000000
+ + IF(tp.Id_Trabajador = 24 , 7,tp.reino_id) * 10000 as Gasto
+ FROM vn2008.Movimientos m
+ JOIN vn2008.Tickets t on t.Id_Ticket = m.Id_Ticket
+ JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna
+ JOIN vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente
+ JOIN tmp.ticket_list tt on tt.Id_Ticket = t.Id_Ticket
+ JOIN vn2008.Articles a on m.Id_Article = a.Id_Article
+ JOIN vn2008.empresa e on e.id = t.empresa_id
+ LEFT JOIN vn2008.empresa e2 on e2.Id_Cliente = c.Id_Cliente
+ JOIN vn2008.Tipos tp on tp.tipo_id = a.tipo_id
+ WHERE Cantidad <> 0
+ AND Preu <> 0
+ AND m.Descuento <> 100
+ AND a.tipo_id != TIPO_PATRIMONIAL
+ GROUP BY grupo, reino_id, tipo_id, empresa_id, Gasto;
+
+
+DROP TEMPORARY TABLE tmp.ticket_list;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `ventas_contables_add_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 `ventas_contables_add_launcher`()
+BEGIN
+
+ call bs.ventas_contables_add(YEAR(TIMESTAMPADD(MONTH,-1,CURDATE())), MONTH(TIMESTAMPADD(MONTH,-1,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 `ventas_contables_por_cliente` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `ventas_contables_por_cliente`(IN vYear INT, IN vMonth INT)
+BEGIN
+
+
+DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list;
+
+CREATE TEMPORARY TABLE tmp.ticket_list
+ (PRIMARY KEY (Id_Ticket))
+ SELECT Id_Ticket
+ FROM vn2008.Tickets t
+ JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura
+ WHERE year(f.Fecha) = vYear
+ AND month(f.Fecha) = vMonth;
+
+
+
+ SELECT vYear Año
+ , vMonth Mes
+ , t.Id_Cliente
+ , round(sum(Cantidad * Preu * (100 - m.Descuento)/100)) Venta
+ , if(
+ e.empresa_grupo = e2.empresa_grupo
+ ,1
+ ,if(e2.empresa_grupo,2,0)
+ ) as grupo
+ , t.empresa_id empresa
+ FROM vn2008.Movimientos m
+ JOIN vn2008.Tickets t on t.Id_Ticket = m.Id_Ticket
+ JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna
+ JOIN vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente
+ JOIN tmp.ticket_list tt on tt.Id_Ticket = t.Id_Ticket
+ JOIN vn2008.Articles a on m.Id_Article = a.Id_Article
+ JOIN vn2008.empresa e on e.id = t.empresa_id
+ LEFT JOIN vn2008.empresa e2 on e2.Id_Cliente = c.Id_Cliente
+ JOIN vn2008.Tipos tp on tp.tipo_id = a.tipo_id
+ WHERE Cantidad <> 0
+ AND Preu <> 0
+ AND m.Descuento <> 100
+ AND a.tipo_id != 188
+ GROUP BY t.Id_Cliente, grupo,t.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 */ ;
+
+
+
+
+
+
+
+
+
+
+
+-- Dump completed on 2017-12-27 7:52:59
diff --git a/services/db/localDB05StructureUtil.sql b/services/db/localDB05StructureUtil.sql
new file mode 100644
index 000000000..3d338fdb3
--- /dev/null
+++ b/services/db/localDB05StructureUtil.sql
@@ -0,0 +1,616 @@
+CREATE DATABASE IF NOT EXISTS `util` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
+USE `util`;
+-- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64)
+--
+-- Host: db.verdnatura.es Database: util
+-- ------------------------------------------------------
+-- 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 `debug`
+--
+
+DROP TABLE IF EXISTS `debug`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `debug` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ `connectionId` int(10) unsigned DEFAULT NULL,
+ `user` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `host` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `variable` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `value` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Log de depuración';
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping events for database 'util'
+--
+
+--
+-- Dumping routines for database 'util'
+--
+/*!50003 DROP FUNCTION IF EXISTS `capitalizeFirst` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `capitalizeFirst`(vString VARCHAR(255)) RETURNS varchar(255) CHARSET utf8
+ NO SQL
+ DETERMINISTIC
+BEGIN
+/**
+ * Pass the first letter of every word in a string to uppercase.
+ *
+ * @param vString String to tranform
+ * @return Transformed string
+ */
+ DECLARE vNewString VARCHAR(255) DEFAULT '';
+ DECLARE vI INT DEFAULT 1;
+ DECLARE vSpaceIni, vWordIni INT;
+ DECLARE vLen INT DEFAULT CHAR_LENGTH(vString);
+
+ WHILE vI < vLen
+ DO
+ SET vSpaceIni = vI;
+
+ WHILE MID(vString, vI, 1) REGEXP '[[:space:]]' DO
+ SET vI = vI + 1;
+ END WHILE;
+
+ SET vWordIni = vI;
+ SET vI = vWordIni + 1;
+
+ WHILE vI <= vLen AND MID(vString, vI, 1) NOT REGEXP '[[:space:]]' DO
+ SET vI = vI + 1;
+ END WHILE;
+
+ SET vNewString = CONCAT(vNewString
+ ,MID(vString, vSpaceIni, vWordIni - vSpaceIni)
+ ,UPPER(MID(vString, vWordIni, 1))
+ ,MID(vString, vWordIni + 1, vI - vWordIni - 1)
+ );
+ END WHILE;
+
+ RETURN vNewString;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 = 'NO_ENGINE_SUBSTITUTION' */ ;
+DELIMITER ;;
+CREATE DEFINER=`root`@`%` FUNCTION `dayEnd`(vDated DATE) RETURNS datetime
+ NO SQL
+ DETERMINISTIC
+BEGIN
+/**
+ * Formats a date to the end of the day.
+ *
+ * @param vDated The date to format
+ * @return The formatted date
+ */
+ RETURN TIMESTAMP(vDated, '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 `firstDayOfMonth` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `firstDayOfMonth`(vDate DATE) RETURNS date
+ NO SQL
+ DETERMINISTIC
+BEGIN
+/**
+ * Returns the date formatted to the first day of month.
+ *
+ * @param vDate The date to format
+ * @return The formatted date
+ */
+ RETURN DATE_FORMAT(vDate, '%Y-%m-01');
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `hmacSha2` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `hmacSha2`(`vAlg` SMALLINT, `vMsg` MEDIUMBLOB, `vKey` MEDIUMBLOB) RETURNS varchar(128) CHARSET utf8
+ NO SQL
+ DETERMINISTIC
+BEGIN
+/**
+ * HMAC function based on SHA2 vAlgorythms.
+ */
+ DECLARE vHashlen INT UNSIGNED;
+ DECLARE vOpad, vIpad TINYBLOB;
+
+ CASE vAlg
+ WHEN 224 THEN SET vHashlen = 64;
+ WHEN 256 THEN SET vHashlen = 64;
+ WHEN 384 THEN SET vHashlen = 128;
+ WHEN 512 THEN SET vHashlen = 128;
+ ELSE CALL throw ('WRONG_vALGORYTHM_IDENTIFICATOR_USED');
+ END CASE;
+
+ IF LENGTH(vKey) > vHashlen THEN
+ SET vKey = UNHEX(SHA2(vKey, vAlg));
+ END IF;
+
+ SET vKey = RPAD(vKey, vHashlen, 0x00);
+
+ SET vIpad = stringXor(vKey, 0x36);
+ SET vOpad = stringXor(vKey, 0x5C);
+
+ RETURN SHA2(CONCAT(vOpad, UNHEX(SHA2(CONCAT(vIpad, vMsg), vAlg))), vAlg);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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
+ NO SQL
+ DETERMINISTIC
+BEGIN
+/**
+ * Returns the current language code.
+ *
+ * @return The language code
+ */
+ RETURN IFNULL(@lang, SUBSTR(@@lc_messages, 1, 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 `nextWeek` */;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `nextWeek`(vYearWeek INT) RETURNS int(11)
+ DETERMINISTIC
+BEGIN
+/**
+ * A partir de un perido año/semana en formato AAAASS devuelve el siguiente
+ * periodo. Esta función trabaja de la misma forma que la función WEEK() en
+ * modo 3.
+ */
+ DECLARE vYear INT DEFAULT FLOOR(vYearWeek / 100);
+
+ IF vYearWeek < YEARWEEK(CONCAT(vYear, '-12-31'), 3) THEN
+ RETURN vYearWeek + 1;
+ ELSE
+ RETURN ((vYear + 1) * 100) + 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 */ ;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `stringXor` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `stringXor`(vString MEDIUMBLOB, vConst TINYINT UNSIGNED) RETURNS mediumblob
+ NO SQL
+ DETERMINISTIC
+BEGIN
+/**
+ * Returns XOR of binary string and an 8-bit constant.
+ */
+ DECLARE vLen, vPos INT UNSIGNED;
+ DECLARE vResult MEDIUMBLOB;
+
+ SET vLen = LENGTH(vString);
+ SET vPos = 1;
+ SET vResult = '';
+
+ WHILE vPos <= vLen DO
+ SET vResult = CONCAT(vResult, LPAD(HEX( ORD(SUBSTR(vString, vPos, 1)) ^ vConst), 2, '0'));
+ SET vPos = vPos + 1;
+ END WHILE;
+
+ RETURN UNHEX(vResult);
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_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 `today` */;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `today`() RETURNS date
+ DETERMINISTIC
+BEGIN
+/**
+ * Devuelve la fecha actual. Usar en lugar de la función nativa
+ * CURDATE() en aquellos que se necesite rendimiento ya que la
+ * la última no es determinista.
+ *
+ * @return La fecha actual
+ */
+ RETURN 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 */ ;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `twoDaysAgo` */;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `twoDaysAgo`() RETURNS date
+ DETERMINISTIC
+BEGIN
+/**
+ * Devuelve la fecha de antes de ayer.
+ *
+ * @return La fecha de antes de ayer
+ */
+ RETURN TIMESTAMPADD(DAY, -2, 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 */ ;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `yearRelativePosition` */;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `yearRelativePosition`(vYear INT) RETURNS varchar(20) CHARSET utf8
+ DETERMINISTIC
+BEGIN
+/**
+ * Devuelve la posicion del año relativa al año actual.
+ * Se utiliza como cabecera en informes de balances.
+ *
+ * @param vYear Año a evaluar
+ * @return La posicion relativa del año
+ */
+ DECLARE vCurYear INT DEFAULT YEAR(CURDATE());
+
+ IF vYear = vCurYear THEN
+ RETURN 'curYear';
+ END IF;
+
+ IF vYear = vCurYear - 1 THEN
+ RETURN 'lastYear';
+ END IF;
+
+ IF vYear = vCurYear - 2 THEN
+ RETURN 'twoYearsAgo';
+ END IF;
+
+ RETURN 'other';
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP FUNCTION IF EXISTS `yesterday` */;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `yesterday`() RETURNS date
+ DETERMINISTIC
+BEGIN
+/**
+ * Devuelve la fecha de ayer.
+ *
+ * @return La fecha de ayer
+ */
+ RETURN TIMESTAMPADD(DAY, -1, 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 */ ;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `debugAdd` */;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `debugAdd`(vVariable VARCHAR(255), vValue VARCHAR(255))
+ MODIFIES SQL DATA
+BEGIN
+/**
+ * Añade una entrada de depuración en la tabla @debug.
+ *
+ * @param vVariable Nombre de variable
+ * @param vValue Valor de la variable
+ */
+ DECLARE vIndex INT DEFAULT INSTR(USER(), '@');
+
+ INSERT INTO debug SET
+ `connectionId` = CONNECTION_ID(),
+ `user` = LEFT(USER(), vIndex - 1),
+ `host` = RIGHT(USER(), CHAR_LENGTH(USER()) - vIndex),
+ `variable` = vVariable,
+ `value` = 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 */ ;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `exec` */;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `exec`(vSqlQuery TEXT)
+BEGIN
+/**
+ * Executes a string with an SQL query.
+ *
+ * @param vSqlQuery The SQL string
+ */
+ SET @sqlQuery = vSqlQuery;
+
+ PREPARE stmt FROM @sqlQuery;
+ EXECUTE stmt;
+ DEALLOCATE PREPARE stmt;
+
+ SET @sqlQuery = 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 `findObject` */;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `findObject`(vChain VARCHAR(45))
+ READS SQL DATA
+BEGIN
+/**
+ * Devuelve un listado de todos los procedimientos, funciones
+ * eventos, disparadores y vistas que inluyen una cadena dada.
+ *
+ * @param vChain Cadena a buscar
+ * @select Listado de objetos
+ */
+ SET vChain = CONCAT('%', vChain, '%');
+
+ SELECT * FROM
+ (
+ SELECT
+ `db`,
+ `name`,
+ `type`,
+ `body`,
+ `created`,
+ `modified`
+ FROM `mysql`.`proc`
+ WHERE `body` LIKE vChain COLLATE utf8_general_ci
+ UNION ALL
+ SELECT
+ `db`,
+ `name`,
+ 'EVENT',
+ `body_utf8`,
+ `created`,
+ `modified`
+ FROM `mysql`.`event`
+ WHERE `body_utf8` LIKE vChain COLLATE utf8_general_ci
+ UNION ALL
+ SELECT
+ `EVENT_OBJECT_SCHEMA`,
+ `TRIGGER_NAME`,
+ 'TRIGGER',
+ `ACTION_STATEMENT`,
+ NULL,
+ NULL
+ FROM `information_schema`.`TRIGGERS`
+ WHERE `ACTION_STATEMENT` LIKE vChain COLLATE utf8_general_ci
+ UNION ALL
+ SELECT
+ `TABLE_SCHEMA`,
+ `TABLE_NAME`,
+ 'VIEW',
+ `VIEW_DEFINITION`,
+ NULL,
+ NULL
+ FROM `information_schema`.`VIEWS`
+ WHERE `VIEW_DEFINITION` LIKE vChain COLLATE utf8_general_ci
+ ) t
+ ORDER BY `db`, `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 */ ;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `throw` */;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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 `throw`(vCode CHAR(35))
+BEGIN
+/**
+ * Lanza una error de usuario.
+ *
+ * @param vCode Código de error
+ */
+ SIGNAL SQLSTATE '45000'
+ SET MESSAGE_TEXT = vCode;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!50003 DROP PROCEDURE IF EXISTS `warn` */;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_general_ci ;
+/*!50003 SET @saved_cs_client = @@character_set_client */ ;
+/*!50003 SET @saved_cs_results = @@character_set_results */ ;
+/*!50003 SET @saved_col_connection = @@collation_connection */ ;
+/*!50003 SET character_set_client = utf8 */ ;
+/*!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=`z-developer`@`%` PROCEDURE `warn`(vCode CHAR(35))
+BEGIN
+ DECLARE w VARCHAR(1) DEFAULT '__';
+ SET @warn = vCode;
+END ;;
+DELIMITER ;
+/*!50003 SET sql_mode = @saved_sql_mode */ ;
+/*!50003 SET character_set_client = @saved_cs_client */ ;
+/*!50003 SET character_set_results = @saved_cs_results */ ;
+/*!50003 SET collation_connection = @saved_col_connection */ ;
+ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
+
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
+
+-- Dump completed on 2017-12-29 7:39:15
diff --git a/services/db/localDB06Views2008.sql b/services/db/localDB06Views2008.sql
new file mode 100644
index 000000000..aaa0013f4
--- /dev/null
+++ b/services/db/localDB06Views2008.sql
@@ -0,0 +1,1613 @@
+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 */;
+
+--
+-- Final view structure for view `V_edi_item_track`
+--
+
+/*!50001 DROP VIEW IF EXISTS `V_edi_item_track`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `V_edi_item_track` AS select `edi`.`item_track`.`item_id` AS `item_id`,`edi`.`item_track`.`s1` AS `s1`,`edi`.`item_track`.`s2` AS `s2`,`edi`.`item_track`.`s3` AS `s3`,`edi`.`item_track`.`s4` AS `s4`,`edi`.`item_track`.`s5` AS `s5`,`edi`.`item_track`.`s6` AS `s6`,`edi`.`item_track`.`kop` AS `kop`,`edi`.`item_track`.`pac` AS `pac`,`edi`.`item_track`.`cat` AS `cat`,`edi`.`item_track`.`ori` AS `ori`,`edi`.`item_track`.`pro` AS `pro`,`edi`.`item_track`.`sub` AS `sub`,`edi`.`item_track`.`package` AS `package` from `edi`.`item_track` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `cdr`
+--
+
+/*!50001 DROP VIEW IF EXISTS `cdr`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `cdr` AS select `c`.`call_date` AS `calldate`,`c`.`clid` AS `clid`,`c`.`src` AS `src`,`c`.`dst` AS `dst`,`c`.`dcontext` AS `dcontext`,`c`.`channel` AS `channel`,`c`.`dst_channel` AS `dstchannel`,`c`.`last_app` AS `lastapp`,`c`.`last_data` AS `lastdata`,`c`.`duration` AS `duration`,`c`.`billsec` AS `billsec`,`c`.`disposition` AS `disposition`,`c`.`ama_flags` AS `amaflags`,`c`.`account_code` AS `accountcode`,`c`.`unique_id` AS `uniqueid`,`c`.`user_field` AS `userfield` from `pbx`.`cdr` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+--
+-- Final view structure for view `VerEspionaje`
+--
+
+/*!50001 DROP VIEW IF EXISTS `VerEspionaje`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `VerEspionaje` AS select `Trabajadores`.`CodigoTrabajador` AS `CodigoTrabajador`,`Espionajes`.`Fecha` AS `Fecha`,`Espionajes`.`HoraEntrada` AS `HoraEntrada`,`Espionajes`.`HoraSalida` AS `HoraSalida`,`Espionajes`.`Id_Equipo` AS `Id_Equipo`,`Trabajadores`.`Id_Trabajador` AS `Id_Trabajador` from (`Espionajes` join `Trabajadores` on((`Espionajes`.`Id_Trabajador` = `Trabajadores`.`Id_Trabajador`))) order by `Trabajadores`.`CodigoTrabajador`,`Espionajes`.`Fecha` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `account_customer`
+--
+
+/*!50001 DROP VIEW IF EXISTS `account_customer`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `account_customer` AS select `e`.`description` AS `description`,`vn2008`.`cc_to_iban`(concat(`a`.`entity_id`,`a`.`office`,`a`.`DC`,`a`.`number`)) AS `iban`,`a`.`entity_id` AS `entity_id`,`a`.`office` AS `office`,`a`.`DC` AS `dc`,`a`.`number` AS `number` from ((`provider_account_customer` `c` join `Proveedores_account` `a` on((`a`.`Id_Proveedores_account` = `c`.`account_id`))) join `entity` `e` on((`a`.`entity_id` = `e`.`entity_id`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `awb_volume`
+--
+
+/*!50001 DROP VIEW IF EXISTS `awb_volume`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `awb_volume` AS select `ar`.`awb_id` AS `awb_id`,(((`c`.`Etiquetas` * `a`.`density`) * if((`cu`.`Volumen` > 0),`cu`.`Volumen`,((`cu`.`X` * `cu`.`Y`) * if((`cu`.`Z` = 0),(`a`.`Medida` + 10),`cu`.`Z`)))) / 167000) AS `volume` from (((((((`Compres` `c` join `Articles` `a` on((`c`.`Id_Article` = `a`.`Id_Article`))) join `Tipos` `t` on((`a`.`tipo_id` = `t`.`tipo_id`))) join `Cubos` `cu` on((`cu`.`Id_Cubo` = `c`.`Id_Cubo`))) join `Entradas` `e` on((`c`.`Id_Entrada` = `e`.`Id_Entrada`))) join `travel` `tr` on((`tr`.`id` = `e`.`travel_id`))) join `recibida_entrada` `re` on((`c`.`Id_Entrada` = `re`.`Id_Entrada`))) join `awb_recibida` `ar` on((`re`.`awb_recibida` = `ar`.`recibida_id`))) where (`tr`.`shipment` > makedate((year(curdate()) - 1),1)) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+
+
+--
+-- Final view structure for view `clientMana`
+--
+
+/*!50001 DROP VIEW IF EXISTS `clientMana`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `clientMana` AS select `t`.`Id_Cliente` AS `Id_Cliente`,`mc`.`Valor` AS `ManaUnitario`,(`mc`.`Valor` * `m`.`Cantidad`) AS `ManaTotal`,`t`.`Id_Ticket` AS `Id_Ticket`,`m`.`Id_Article` AS `Id_Article`,`m`.`Concepte` AS `Concepte`,`m`.`Cantidad` AS `Cantidad`,`m`.`Preu` AS `Preu`,`t`.`Fecha` AS `Fecha`,`m`.`Id_Movimiento` AS `Id_Movimiento` from ((((`vn2008`.`Tickets` `t` join `vn2008`.`Movimientos` `m` on((`m`.`Id_Ticket` = `t`.`Id_Ticket`))) join `vn2008`.`Movimientos_componentes` `mc` on((`mc`.`Id_Movimiento` = `m`.`Id_Movimiento`))) join `vn2008`.`tarifa_componentes` `tc` on((`tc`.`Id_Componente` = `mc`.`Id_Componente`))) join `vn2008`.`tarifa_componentes_series` `tcs` on((`tc`.`tarifa_componentes_series_id` = `tcs`.`tarifa_componentes_series_id`))) where ((`t`.`Fecha` >= '2016-01-01') and (`tcs`.`Serie` = 'cartera_comercial') and (`mc`.`Valor` <> 0)) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `edi_article`
+--
+
+/*!50001 DROP VIEW IF EXISTS `edi_article`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `edi_article` AS select `edi`.`item`.`id` AS `id`,`edi`.`item`.`product_name` AS `product_name`,`edi`.`item`.`name` AS `name`,`edi`.`item`.`plant_id` AS `plant_id`,`edi`.`item`.`group_id` AS `group_id`,`edi`.`item`.`entry_date` AS `entry_date`,`edi`.`item`.`expiry_date` AS `expiry_date`,`edi`.`item`.`change_date_time` AS `change_date_time` from `edi`.`item` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `edi_bucket`
+--
+
+/*!50001 DROP VIEW IF EXISTS `edi_bucket`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `edi_bucket` AS select (cast(`edi`.`bucket`.`bucket_id` as char charset utf8) collate utf8_general_ci) AS `bucket_id`,`edi`.`bucket`.`bucket_type_id` AS `bucket_type_id`,`edi`.`bucket`.`description` AS `description`,`edi`.`bucket`.`x_size` AS `x_size`,`edi`.`bucket`.`y_size` AS `y_size`,`edi`.`bucket`.`z_size` AS `z_size`,`edi`.`bucket`.`entry_date` AS `entry_date`,`edi`.`bucket`.`expiry_date` AS `expiry_date`,`edi`.`bucket`.`change_date_time` AS `change_date_time` from `edi`.`bucket` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `edi_bucket_type`
+--
+
+/*!50001 DROP VIEW IF EXISTS `edi_bucket_type`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `edi_bucket_type` AS select `edi`.`bucket_type`.`bucket_type_id` AS `bucket_type_id`,`edi`.`bucket_type`.`description` AS `description`,`edi`.`bucket_type`.`entry_date` AS `entry_date`,`edi`.`bucket_type`.`expiry_date` AS `expiry_date`,`edi`.`bucket_type`.`change_date_time` AS `change_date_time` from `edi`.`bucket_type` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `edi_feature`
+--
+
+/*!50001 DROP VIEW IF EXISTS `edi_feature`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `edi_feature` AS select `edi`.`feature`.`item_id` AS `item_id`,`edi`.`feature`.`feature_type_id` AS `feature_type_id`,`edi`.`feature`.`feature_value` AS `feature_value`,`edi`.`feature`.`entry_date` AS `entry_date`,`edi`.`feature`.`expiry_date` AS `expiry_date`,`edi`.`feature`.`change_date_time` AS `change_date_time` from `edi`.`feature` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `edi_genus`
+--
+
+/*!50001 DROP VIEW IF EXISTS `edi_genus`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `edi_genus` AS select `edi`.`genus`.`genus_id` AS `genus_id`,`edi`.`genus`.`latin_genus_name` AS `latin_genus_name`,`edi`.`genus`.`entry_date` AS `entry_date`,`edi`.`genus`.`expiry_date` AS `expiry_date`,`edi`.`genus`.`change_date_time` AS `change_date_time` from `edi`.`genus` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `edi_item_feature`
+--
+
+/*!50001 DROP VIEW IF EXISTS `edi_item_feature`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `edi_item_feature` AS select `edi`.`item_feature`.`item_id` AS `item_id`,`edi`.`item_feature`.`presentation_order` AS `presentation_order`,`edi`.`item_feature`.`feature` AS `feature`,`edi`.`item_feature`.`regulation_type` AS `regulation_type`,`edi`.`item_feature`.`entry_date` AS `entry_date`,`edi`.`item_feature`.`expiry_date` AS `expiry_date`,`edi`.`item_feature`.`change_date_time` AS `change_date_time` from `edi`.`item_feature` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `edi_plant`
+--
+
+/*!50001 DROP VIEW IF EXISTS `edi_plant`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `edi_plant` AS select `edi`.`plant`.`plant_id` AS `plant_id`,`edi`.`plant`.`genus_id` AS `genus_id`,`edi`.`plant`.`specie_id` AS `specie_id`,`edi`.`plant`.`entry_date` AS `entry_date`,`edi`.`plant`.`expiry_date` AS `expiry_date`,`edi`.`plant`.`change_date_time` AS `change_date_time` from `edi`.`plant` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `edi_specie`
+--
+
+/*!50001 DROP VIEW IF EXISTS `edi_specie`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `edi_specie` AS select `edi`.`specie`.`specie_id` AS `specie_id`,`edi`.`specie`.`genus_id` AS `genus_id`,`edi`.`specie`.`latin_species_name` AS `latin_species_name`,`edi`.`specie`.`entry_date` AS `entry_date`,`edi`.`specie`.`expiry_date` AS `expiry_date`,`edi`.`specie`.`change_date_time` AS `change_date_time` from `edi`.`specie` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `edi_supplier`
+--
+
+/*!50001 DROP VIEW IF EXISTS `edi_supplier`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `edi_supplier` AS select `edi`.`supplier`.`supplier_id` AS `supplier_id`,`edi`.`supplier`.`company_name` AS `company_name` from `edi`.`supplier` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `edi_type`
+--
+
+/*!50001 DROP VIEW IF EXISTS `edi_type`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `edi_type` AS select `edi`.`type`.`type_id` AS `type_id`,`edi`.`type`.`type_group_id` AS `type_group_id`,`edi`.`type`.`description` AS `description`,`edi`.`type`.`entry_date` AS `entry_date`,`edi`.`type`.`expiry_date` AS `expiry_date`,`edi`.`type`.`change_date_time` AS `change_date_time` from `edi`.`type` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `edi_value`
+--
+
+/*!50001 DROP VIEW IF EXISTS `edi_value`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `edi_value` AS select `edi`.`value`.`type_id` AS `type_id`,`edi`.`value`.`type_value` AS `type_value`,`edi`.`value`.`type_description` AS `type_description`,`edi`.`value`.`entry_date` AS `entry_date`,`edi`.`value`.`expiry_date` AS `expiry_date`,`edi`.`value`.`change_date_time` AS `change_date_time` from `edi`.`value` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `itemTag`
+--
+
+/*!50001 DROP VIEW IF EXISTS `itemTag`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `itemTag` AS select `i`.`id` AS `id`,`i`.`itemFk` AS `itemFk`,`i`.`tagFk` AS `tagFk`,`i`.`value` AS `value`,`i`.`priority` AS `priority` from `vn`.`itemTag` `i` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `itemTagArranged`
+--
+
+/*!50001 DROP VIEW IF EXISTS `itemTagArranged`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `itemTagArranged` AS select `i`.`itemFk` AS `itemFk`,`i`.`tag1` AS `tag1`,`i`.`val1` AS `val1`,`i`.`tag2` AS `tag2`,`i`.`val2` AS `val2`,`i`.`tag3` AS `tag3`,`i`.`val3` AS `val3`,`i`.`tag4` AS `tag4`,`i`.`val4` AS `val4`,`i`.`tag5` AS `tag5`,`i`.`val5` AS `val5`,`i`.`tag6` AS `tag6`,`i`.`val6` AS `val6`,`i`.`description` AS `description` from `vn`.`itemTagArranged` `i` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `item_entry_in`
+--
+
+/*!50001 DROP VIEW IF EXISTS `item_entry_in`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `item_entry_in` AS select `t`.`warehouse_id` AS `warehouse_id`,`t`.`landing` AS `dat`,`m`.`Id_Article` AS `item_id`,`m`.`Cantidad` AS `amount`,`t`.`received` AS `received` from ((`Compres` `m` join `Entradas` `e` on((`m`.`Id_Entrada` = `e`.`Id_Entrada`))) join `travel` `t` on((`e`.`travel_id` = `t`.`id`))) where ((`e`.`Inventario` = 0) and (`m`.`Cantidad` <> 0)) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `item_entry_out`
+--
+
+/*!50001 DROP VIEW IF EXISTS `item_entry_out`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `item_entry_out` AS select `t`.`warehouse_id_out` AS `warehouse_id`,`t`.`shipment` AS `dat`,`m`.`Id_Article` AS `item_id`,-(`m`.`Cantidad`) AS `amount`,(`t`.`delivered` or ifnull(`co`.`valor`,0)) AS `delivered` from (((`Compres` `m` join `Entradas` `e` on((`m`.`Id_Entrada` = `e`.`Id_Entrada`))) join `travel` `t` on((`e`.`travel_id` = `t`.`id`))) left join `Compres_ok` `co` on(((`co`.`Id_Compra` = `m`.`Id_Compra`) and (`co`.`Id_Accion` = 3)))) where ((`e`.`Inventario` = 0) and (`e`.`Redada` = 0) and (`m`.`Cantidad` <> 0)) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `item_entry_outkk`
+--
+
+/*!50001 DROP VIEW IF EXISTS `item_entry_outkk`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `item_entry_outkk` AS select `t`.`warehouse_id_out` AS `warehouse_id`,`t`.`shipment` AS `dat`,`m`.`Id_Article` AS `item_id`,-(`m`.`Cantidad`) AS `amount`,`t`.`delivered` AS `delivered` from ((`Compres` `m` join `Entradas` `e` on((`m`.`Id_Entrada` = `e`.`Id_Entrada`))) join `travel` `t` on((`e`.`travel_id` = `t`.`id`))) where ((`e`.`Inventario` = 0) and (`e`.`Redada` = 0) and (`m`.`Cantidad` <> 0)) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `item_out`
+--
+
+/*!50001 DROP VIEW IF EXISTS `item_out`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `item_out` AS select `t`.`warehouse_id` AS `warehouse_id`,`t`.`Fecha` AS `dat`,`m`.`Id_Article` AS `item_id`,-(`m`.`Cantidad`) AS `amount`,`m`.`OK` AS `ok`,`m`.`Reservado` AS `Reservado`,(`ts`.`alertLevel` = 3) AS `ready`,`t`.`Factura` AS `invoice`,ifnull(`ts`.`alertLevel`,0) AS `alertLevel` from ((`vn2008`.`Movimientos` `m` join `vn2008`.`Tickets` `t` on((`m`.`Id_Ticket` = `t`.`Id_Ticket`))) left join `vn`.`ticketState` `ts` on((`t`.`Id_Ticket` = `ts`.`ticket`))) where (`m`.`Cantidad` <> 0) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `new_viewkk`
+--
+
+/*!50001 DROP VIEW IF EXISTS `new_viewkk`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `new_viewkk` AS select `vn`.`workerDocument`.`id` AS `id`,`vn`.`workerDocument`.`worker` AS `worker`,`vn`.`workerDocument`.`document` AS `document` from `vn`.`workerDocument` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `order`
+--
+
+/*!50001 DROP VIEW IF EXISTS `order`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `order` AS select `hedera`.`order`.`id` AS `id`,`hedera`.`order`.`date_make` AS `date_make`,`hedera`.`order`.`date_send` AS `date_send`,`hedera`.`order`.`customer_id` AS `customer_id`,`hedera`.`order`.`delivery_method_id` AS `delivery_method_id`,`hedera`.`order`.`agency_id` AS `agency_id`,`hedera`.`order`.`address_id` AS `address_id`,`hedera`.`order`.`note` AS `note`,`hedera`.`order`.`confirmed` AS `confirmed`,`hedera`.`order`.`is_bionic` AS `is_bionic`,`hedera`.`order`.`source_app` AS `source_app` from `hedera`.`order` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `order_component`
+--
+
+/*!50001 DROP VIEW IF EXISTS `order_component`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `order_component` AS select `c`.`order_row_id` AS `order_row_id`,`c`.`component_id` AS `component_id`,`c`.`price` AS `price` from `hedera`.`order_component` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `order_row`
+--
+
+/*!50001 DROP VIEW IF EXISTS `order_row`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `order_row` AS select `order_row`.`id` AS `id`,`order_row`.`order_id` AS `order_id`,`order_row`.`item_id` AS `item_id`,`order_row`.`warehouse_id` AS `warehouse_id`,`order_row`.`shipment` AS `shipment`,`order_row`.`amount` AS `amount`,`order_row`.`price` AS `price`,`order_row`.`rate` AS `rate`,`order_row`.`created` AS `created`,`order_row`.`Id_Movimiento` AS `Id_Movimiento` from `hedera`.`order_row` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `person_user`
+--
+
+/*!50001 DROP VIEW IF EXISTS `person_user`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `person_user` AS select `u`.`id` AS `id`,`u`.`role` AS `mysql_user_id`,`u`.`name` AS `name`,`u`.`password` AS `password`,`u`.`active` AS `active`,`u`.`lastPassChange` AS `last_pass_change` from `account`.`user` `u` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `person_user_idtrabajador`
+--
+
+/*!50001 DROP VIEW IF EXISTS `person_user_idtrabajador`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `person_user_idtrabajador` AS select `t`.`Id_Trabajador` AS `Id_Trabajador` from (`vn2008`.`person_user` `p` join `vn2008`.`Trabajadores` `t` on((`p`.`id` = `t`.`user_id`))) where (`t`.`user_id` = `account`.`userGetId`()) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `proveedores_clientes`
+--
+
+/*!50001 DROP VIEW IF EXISTS `proveedores_clientes`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `proveedores_clientes` AS select `Proveedores`.`Id_Proveedor` AS `Id_Proveedor`,`Proveedores`.`Proveedor` AS `Proveedor`,`Clientes`.`id_cliente` AS `Id_Cliente`,`Clientes`.`cliente` AS `Cliente` from (`Proveedores` join `Clientes` on((`Proveedores`.`NIF` = `Clientes`.`if`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `sms`
+--
+
+/*!50001 DROP VIEW IF EXISTS `sms`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `sms` AS select `t`.`id` AS `id`,`t`.`senderFk` AS `Id_trabajador`,`t`.`destinationFk` AS `Id_Cliente`,`t`.`sender` AS `from`,`t`.`destination` AS `to`,`t`.`message` AS `text`,`t`.`statusCode` AS `sent`,`t`.`status` AS `response`,`t`.`created` AS `DATE_ODBC` from `vn`.`sms` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `tag`
+--
+
+/*!50001 DROP VIEW IF EXISTS `tag`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `tag` AS select `t`.`id` AS `id`,`t`.`name` AS `name`,`t`.`free` AS `free`,`t`.`isQuantitatif` AS `isQuantitatif`,`t`.`sourceTable` AS `sourceTable`,`t`.`unit` AS `unit` from `vn`.`tag` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `tarifa_componentes`
+--
+
+/*!50001 DROP VIEW IF EXISTS `tarifa_componentes`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `tarifa_componentes` AS select `bi`.`tarifa_componentes`.`Id_Componente` AS `Id_Componente`,`bi`.`tarifa_componentes`.`Componente` AS `Componente`,`bi`.`tarifa_componentes`.`tarifa_componentes_series_id` AS `tarifa_componentes_series_id`,`bi`.`tarifa_componentes`.`tarifa_class` AS `tarifa_class`,`bi`.`tarifa_componentes`.`tax` AS `tax`,`bi`.`tarifa_componentes`.`is_renewable` AS `is_renewable` from `bi`.`tarifa_componentes` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `tarifa_componentes_series`
+--
+
+/*!50001 DROP VIEW IF EXISTS `tarifa_componentes_series`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `tarifa_componentes_series` AS select `bi`.`tarifa_componentes_series`.`tarifa_componentes_series_id` AS `tarifa_componentes_series_id`,`bi`.`tarifa_componentes_series`.`Serie` AS `Serie`,`bi`.`tarifa_componentes_series`.`base` AS `base` from `bi`.`tarifa_componentes_series` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ticketCreationData`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ticketCreationData`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ticketCreationData` AS select dayname(`h`.`confirm_date`) AS `DiadelaSemana`,hour(`h`.`confirm_date`) AS `Hora`,cast(`h`.`confirm_date` as date) AS `Fecha`,`h`.`source_app` AS `Dispositivo` from `hedera`.`order` `h` where `h`.`confirm_date` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_Agenda`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_Agenda`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_Agenda` AS select 'P' AS `Tipo`,`Proveedores`.`Id_Proveedor` AS `Id`,`Proveedores`.`Proveedor` AS `Nombre`,`Proveedores`.`Telefono` AS `Telephone` from `Proveedores` where (`Proveedores`.`Telefono` is not null) union select 'C' AS `Tipo`,`Clientes`.`id_cliente` AS `Id`,`Clientes`.`cliente` AS `Cliente`,`Clientes`.`telefono` AS `Telefono` from `Clientes` where (`Clientes`.`telefono` is not null) union select 'C' AS `Tipo`,`Clientes`.`id_cliente` AS `Id`,`Clientes`.`cliente` AS `Cliente`,`Clientes`.`movil` AS `Movil` from `Clientes` where (`Clientes`.`movil` is not null) union select if(isnull(`Relaciones`.`Id_Proveedor`),'C','P') AS `Tipo`,if(isnull(`Relaciones`.`Id_Proveedor`),`Relaciones`.`Id_Cliente`,`Relaciones`.`Id_Proveedor`) AS `Id`,`Contactos`.`Nombre` AS `Nombre`,`Contactos`.`Telefono` AS `Telefono` from (`Contactos` join `Relaciones` on((`Contactos`.`Id_Contacto` = `Relaciones`.`Id_Contacto`))) where (`Contactos`.`Telefono` is not null) union select if(isnull(`Relaciones`.`Id_Proveedor`),'C','P') AS `Tipo`,if(isnull(`Relaciones`.`Id_Proveedor`),`Relaciones`.`Id_Cliente`,`Relaciones`.`Id_Proveedor`) AS `Id`,`Contactos`.`Nombre` AS `Nombre`,`Contactos`.`Movil` AS `Movil` from (`Contactos` join `Relaciones` on((`Contactos`.`Id_Contacto` = `Relaciones`.`Id_Contacto`))) where (`Contactos`.`Movil` is not null) union select 'T' AS `Tipo`,`Trabajadores`.`Id_Trabajador` AS `Id_Trabajador`,`Trabajadores`.`CodigoTrabajador` AS `CodigoTrabajador`,`Trabajadores`.`extension` AS `extension` from `Trabajadores` where (`Trabajadores`.`extension` is not null) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_Agenda2`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_Agenda2`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_Agenda2` AS select `v_Agenda`.`Tipo` AS `Tipo`,`v_Agenda`.`Id` AS `Id`,`v_Agenda`.`Nombre` AS `Nombre`,replace(`v_Agenda`.`Telephone`,' ','') AS `Telefono` from `v_Agenda` where `v_Agenda`.`Telephone` group by replace(`v_Agenda`.`Telephone`,' ','') */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_Articles_botanical`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_Articles_botanical`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_Articles_botanical` AS select `ab`.`Id_Article` AS `Id_Article`,ifnull(`ab`.`botanical`,concat(`g`.`latin_genus_name`,' ',ifnull(`s`.`latin_species_name`,''))) AS `edi_botanic` from ((`vn2008`.`Articles_botanical` `ab` left join `edi`.`genus` `g` on((`ab`.`genus_id` = `g`.`genus_id`))) left join `edi`.`specie` `s` on((`s`.`specie_id` = `ab`.`specie_id`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_Movimientos_Volumen_shipping_charge`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_Movimientos_Volumen_shipping_charge`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_Movimientos_Volumen_shipping_charge` AS select `M`.`Id_Ticket` AS `Id_Ticket`,`M`.`Id_Movimiento` AS `Id_Movimiento`,`t`.`Fecha` AS `Fecha`,`az`.`price` AS `price`,(((`M`.`Cantidad` * `r`.`cm3`) / `cb`.`Volumen`) * `az`.`price`) AS `freight` from (((((((`vn2008`.`Movimientos` `M` join `vn2008`.`Tickets` `t` on((`t`.`Id_Ticket` = `M`.`Id_Ticket`))) join `vn2008`.`Consignatarios` `c` on((`c`.`id_consigna` = `t`.`Id_Consigna`))) join `bi`.`rotacion` `r` on(((`r`.`Id_Article` = `M`.`Id_Article`) and (`r`.`warehouse_id` = `t`.`warehouse_id`)))) join `vn2008`.`Cubos` `cb` on((`cb`.`Id_Cubo` = 94))) join `vn2008`.`Agencias` `a` on((`a`.`Id_Agencia` = `t`.`Id_Agencia`))) join `vn2008`.`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 `vn2008`.`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)))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_Ordenes`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_Ordenes`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_Ordenes` AS select `Ordenes`.`Id_ORDEN` AS `Id_ORDEN`,`Ordenes`.`ORDEN` AS `ORDEN`,`Ordenes`.`datORDEN` AS `datORDEN`,`Ordenes`.`datTICKET` AS `datTICKET`,`Ordenes`.`CodVENDEDOR` AS `CodVENDEDOR`,`Ordenes`.`CodCOMPRADOR` AS `CodCOMPRADOR`,`Ordenes`.`CANTIDAD` AS `CANTIDAD`,`Ordenes`.`PRECIOMAX` AS `PRECIOMAX`,`Ordenes`.`PREU` AS `PREU`,`Ordenes`.`Id_ARTICLE` AS `Id_ARTICLE`,`Ordenes`.`Id_CLIENTE` AS `Id_CLIENTE`,`Ordenes`.`COMENTARIO` AS `COMENTARIO`,`Ordenes`.`OK` AS `OK`,`Ordenes`.`TOTAL` AS `TOTAL`,`Ordenes`.`datCOMPRA` AS `datCOMPRA`,`Ordenes`.`KO` AS `KO`,`Ordenes`.`Id_Movimiento` AS `Id_Movimiento`,`Ordenes`.`odbc_date` AS `odbc_date` from `Ordenes` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_XDiario_ALL`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_XDiario_ALL`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_XDiario_ALL` AS select `bi`.`XDiario_ALL`.`empresa_id` AS `empresa_id`,`bi`.`XDiario_ALL`.`SUBCTA` AS `SUBCTA`,`bi`.`XDiario_ALL`.`Eurodebe` AS `Eurodebe`,`bi`.`XDiario_ALL`.`Eurohaber` AS `Eurohaber`,`bi`.`XDiario_ALL`.`Fecha` AS `Fecha`,`bi`.`XDiario_ALL`.`FECHA_EX` AS `FECHA_EX` from `bi`.`XDiario_ALL` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_accion`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_accion`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_accion` AS select `vncontrol`.`accion`.`accion_id` AS `accion_id`,`vncontrol`.`accion`.`accion` AS `accion` from `vncontrol`.`accion` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_account`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_account`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_account` AS select `a`.`id` AS `user_id` from `account`.`account` `a` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_analisis_ventas`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_analisis_ventas`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_analisis_ventas` AS select `bi`.`analisis_ventas`.`Familia` AS `Familia`,`bi`.`analisis_ventas`.`Reino` AS `Reino`,`bi`.`analisis_ventas`.`Comercial` AS `Comercial`,`bi`.`analisis_ventas`.`Comprador` AS `Comprador`,`bi`.`analisis_ventas`.`Provincia` AS `Provincia`,`bi`.`analisis_ventas`.`almacen` AS `almacen`,`bi`.`analisis_ventas`.`Año` AS `Año`,`bi`.`analisis_ventas`.`Mes` AS `Mes`,`bi`.`analisis_ventas`.`Semana` AS `Semana`,`bi`.`analisis_ventas`.`Vista` AS `Vista`,`bi`.`analisis_ventas`.`Importe` AS `Importe` from `bi`.`analisis_ventas` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_awb_volumen`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_awb_volumen`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_awb_volumen` AS select `a`.`id` AS `awb_id`,`a`.`codigo` AS `codigo`,`a`.`importe` AS `importe`,cast(sum(`v`.`volume`) as signed) AS `Vol_Total` from (`awb` `a` join `awb_volume` `v` on((`v`.`awb_id` = `a`.`id`))) group by `a`.`id` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_barcodes`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_barcodes`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_barcodes` AS select `Articles`.`Id_Article` AS `code`,`Articles`.`Id_Article` AS `Id_Article` from `Articles` union all select `barcodes`.`code` AS `code`,`barcodes`.`Id_Article` AS `Id_Article` from `barcodes` union all select `c`.`Id_Compra` AS `Id_Compra`,`c`.`Id_Article` AS `Id_Article` from ((`Compres` `c` join `Entradas` `e` on((`c`.`Id_Entrada` = `e`.`Id_Entrada`))) join `travel` `tr` on((`tr`.`id` = `e`.`travel_id`))) where (`tr`.`landing` >= (curdate() + interval -(15) day)) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_barcodes_plus`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_barcodes_plus`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_barcodes_plus` AS select `cache`.`barcodes`.`code` AS `code`,`cache`.`barcodes`.`Id_Article` AS `Id_Article`,`cache`.`barcodes`.`Article` AS `Article`,`cache`.`barcodes`.`Medida` AS `Medida`,`cache`.`barcodes`.`Color` AS `Color`,`cache`.`barcodes`.`Categoria` AS `Categoria`,`cache`.`barcodes`.`Producer` AS `Producer` from `cache`.`barcodes` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_botanic_export`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_botanic_export`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_botanic_export` AS select concat(ifnull(concat(`eg`.`latin_genus_name`,' '),''),ifnull(`es`.`latin_species_name`,'')) AS `Nom_botanic`,`be`.`Id_Paises` AS `Id_Paises`,`be`.`restriction` AS `restriction`,`be`.`description` AS `description` from ((`vn2008`.`botanic_export` `be` left join `vn2008`.`edi_genus` `eg` on((`be`.`edi_genus_id` = `eg`.`genus_id`))) left join `vn2008`.`edi_specie` `es` on((`be`.`edi_specie_id` = `es`.`specie_id`))) order by concat(`eg`.`latin_genus_name`,' ',`es`.`latin_species_name`) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_compres`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_compres`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_compres` AS select `TP`.`Id_Tipo` AS `Familia`,`RN`.`id` AS `reino_id`,`C`.`Id_Compra` AS `Id_Compra`,`C`.`Id_Entrada` AS `Id_Entrada`,`C`.`Id_Article` AS `Id_Article`,`C`.`Cantidad` AS `Cantidad`,`C`.`Costefijo` AS `Costefijo`,`C`.`Portefijo` AS `Portefijo`,`C`.`Novincular` AS `Novincular`,`C`.`Etiquetas` AS `Etiquetas`,`C`.`Packing` AS `Packing`,`C`.`grouping` AS `grouping`,`C`.`Comisionfija` AS `Comisionfija`,`C`.`Embalajefijo` AS `Embalajefijo`,`an`.`nicho` AS `Nicho`,`C`.`Id_Cubo` AS `Id_Cubo`,`C`.`Tarifa1` AS `Tarifa1`,`C`.`Tarifa2` AS `Tarifa2`,`C`.`Tarifa3` AS `Tarifa3`,`C`.`PVP` AS `PVP`,`C`.`Vida` AS `Vida`,`C`.`Id_Trabajador` AS `Id_Trabajador`,`C`.`punteo` AS `punteo`,`C`.`odbc_date` AS `odbc_date`,`E`.`Inventario` AS `Inventario`,`E`.`Id_Proveedor` AS `Id_Proveedor`,`E`.`Fecha` AS `Fecha`,`E`.`Confirmada` AS `Confirmada`,`E`.`Redada` AS `Redada`,`E`.`empresa_id` AS `empresa_id`,`E`.`travel_id` AS `travel_id`,`E`.`Pedida` AS `Pedida`,`E`.`recibida_id` AS `recibida_id`,`TR`.`id` AS `id`,`TR`.`shipment` AS `shipment`,`TR`.`landing` AS `landing`,`TR`.`warehouse_id` AS `warehouse_id`,`TR`.`warehouse_id_out` AS `warehouse_id_out`,`TR`.`agency_id` AS `agency_id`,`TR`.`ref` AS `ref`,`TR`.`delivered` AS `delivered`,`TR`.`received` AS `received`,`A`.`Article` AS `Article`,`A`.`Medida` AS `Medida`,`A`.`Tallos` AS `Tallos`,`C`.`caja` AS `caja`,`A`.`Categoria` AS `Categoria`,`A`.`id_origen` AS `id_origen`,`TP`.`Id_Tipo` AS `Tipo`,`A`.`tipo_id` AS `tipo_id`,`A`.`Color` AS `Color`,`A`.`Min` AS `Min`,(((`C`.`Costefijo` + `C`.`Embalajefijo`) + `C`.`Comisionfija`) + `C`.`Portefijo`) AS `Coste`,`W_OUT`.`fuente` AS `fuente`,`A`.`iva_group_id` AS `iva_group_id`,(if((`cb`.`Volumen` > 0),`cb`.`Volumen`,((`cb`.`X` * `cb`.`Y`) * if((`cb`.`Z` = 0),(`A`.`Medida` + 10),`cb`.`Z`))) * `C`.`Etiquetas`) AS `cm3`,`A`.`producer_id` AS `producer_id` from (((((((((`Compres` `C` join `Entradas` `E` on((`C`.`Id_Entrada` = `E`.`Id_Entrada`))) join `travel` `TR` on((`TR`.`id` = `E`.`travel_id`))) join `warehouse` `W_IN` on((`W_IN`.`id` = `TR`.`warehouse_id`))) join `warehouse` `W_OUT` on((`W_OUT`.`id` = `TR`.`warehouse_id_out`))) join `Articles` `A` on((`C`.`Id_Article` = `A`.`Id_Article`))) join `Tipos` `TP` on((`A`.`tipo_id` = `TP`.`tipo_id`))) join `reinos` `RN` on((`RN`.`id` = `TP`.`reino_id`))) join `Cubos` `cb` on((`cb`.`Id_Cubo` = `C`.`Id_Cubo`))) left join `Articles_nicho` `an` on(((`A`.`Id_Article` = `an`.`Id_Article`) and (`an`.`warehouse_id` = `W_IN`.`id`)))) where ((not(`W_IN`.`fuente`)) and (not(`E`.`Inventario`)) and (not(`E`.`Redada`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_departure_limit`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_departure_limit`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_departure_limit` AS select `cache`.`departure_limit`.`warehouse_id` AS `warehouse_id`,`cache`.`departure_limit`.`fecha` AS `fecha`,`cache`.`departure_limit`.`hora` AS `hora`,`cache`.`departure_limit`.`minSpeed` AS `minSpeed` from `cache`.`departure_limit` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_descuadre_bionic`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_descuadre_bionic`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_descuadre_bionic` AS select `t`.`Id_Ticket` AS `Id_Ticket`,`t`.`Alias` AS `Alias`,`m`.`Concepte` AS `Concepte`,sum(`mc`.`Valor`) AS `suma_componente`,`m`.`Preu` AS `Preu`,`m`.`Descuento` AS `Descuento`,(((`m`.`Preu` * (100 - `m`.`Descuento`)) / 100) - sum(`mc`.`Valor`)) AS `diferencia`,`t`.`Fecha` AS `Fecha`,((`m`.`Preu` > 0) and (`tp`.`reino_id` <> 6) and (`a`.`tipo_id` not in (7,115)) and (`t`.`warehouse_id` <> 41)) AS `benvenut` from ((((((`Movimientos` `m` join `Tickets` `t` on((`m`.`Id_Ticket` = `t`.`Id_Ticket`))) join `Clientes` `c` on((`t`.`Id_Cliente` = `c`.`id_cliente`))) join `warehouse` `w` on((`w`.`id` = `t`.`warehouse_id`))) join `Articles` `a` on((`m`.`Id_Article` = `a`.`Id_Article`))) join `Tipos` `tp` on((`a`.`tipo_id` = `tp`.`tipo_id`))) left join `Movimientos_componentes` `mc` on((`m`.`Id_Movimiento` = `mc`.`Id_Movimiento`))) where ((`t`.`Fecha` >= '2015-09-01') and (`t`.`empresa_id` in (442,791,567)) and `w`.`reserve` and `c`.`real` and (`tp`.`reino_id` <> 6)) group by `m`.`Id_Movimiento` having ((abs(`diferencia`) > 0.01) or isnull(`diferencia`)) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_descuadre_porte`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_descuadre_porte`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_descuadre_porte` AS select `t`.`Id_Ticket` AS `Id_Ticket`,round(sum((`mc`.`Valor` * `m`.`Cantidad`)),2) AS `suma_componente`,round(`es`.`shipping_charge`,2) AS `teorico_agencia`,round((sum((`mc`.`Valor` * `m`.`Cantidad`)) - `es`.`shipping_charge`),2) AS `diferencia`,`t`.`Fecha` AS `Fecha` from ((((`vn2008`.`Movimientos` `m` left join `vn2008`.`Movimientos_componentes` `mc` on((`m`.`Id_Movimiento` = `mc`.`Id_Movimiento`))) join `vn2008`.`tarifa_componentes` `tc` on(((`tc`.`Id_Componente` = `mc`.`Id_Componente`) and (`tc`.`tarifa_componentes_series_id` = 6)))) join `vn2008`.`Tickets` `t` on((`t`.`Id_Ticket` = `m`.`Id_Ticket`))) left join `vn2008`.`v_expeditions_shipping_charge` `es` on((`es`.`Id_Ticket` = `t`.`Id_Ticket`))) where ((`t`.`Fecha` >= '2015-09-01') and (`t`.`empresa_id` in (442,791,567))) group by `t`.`Id_Ticket` having ((abs(`diferencia`) > 0.01) or isnull(`diferencia`)) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_descuadre_porte2`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_descuadre_porte2`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_descuadre_porte2` AS select `t`.`Id_Ticket` AS `Id_Ticket`,(`mc`.`Valor` * `m`.`Cantidad`) AS `suma_componente`,`t`.`Fecha` AS `Fecha` from (((`vn2008`.`Movimientos` `m` left join `vn2008`.`Movimientos_componentes` `mc` on((`m`.`Id_Movimiento` = `mc`.`Id_Movimiento`))) join `vn2008`.`tarifa_componentes` `tc` on(((`tc`.`Id_Componente` = `mc`.`Id_Componente`) and (`tc`.`tarifa_componentes_series_id` = 6)))) join `vn2008`.`Tickets` `t` on((`t`.`Id_Ticket` = `m`.`Id_Ticket`))) where ((`t`.`Fecha` >= '2015-09-01') and (`t`.`empresa_id` in (442,791,567))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_empresa`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_empresa`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_empresa` AS select `e`.`logo` AS `logo`,`e`.`id` AS `id`,`e`.`registro` AS `registro`,`e`.`gerente_id` AS `gerente_id`,`e`.`alta` AS `alta`,`t`.`Nombre` AS `Nombre`,`t`.`Apellidos` AS `Apellidos`,`p`.`Proveedor` AS `Proveedor`,`p`.`Domicilio` AS `Domicilio`,`p`.`CP` AS `CP`,`p`.`Localidad` AS `Localidad`,`p`.`NIF` AS `NIF`,`p`.`Telefono` AS `Telefono`,`p`.`Alias` AS `Alias`,`e`.`abbreviation` AS `abbreviation` from ((`empresa` `e` join `Trabajadores` `t` on((`t`.`Id_Trabajador` = `e`.`gerente_id`))) join `Proveedores` `p` on((`p`.`Id_Proveedor` = `e`.`id`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_encajado`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_encajado`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_encajado` AS select hour(`e`.`odbc_date`) AS `hora`,minute(`e`.`odbc_date`) AS `minuto`,ifnull(`c`.`Volumen`,94500) AS `cm3`,`t`.`warehouse_id` AS `warehouse_id` from ((`expeditions` `e` left join `Cubos` `c` on((`c`.`item_id` = `e`.`EsBulto`))) join `Tickets` `t` on((`t`.`Id_Ticket` = `e`.`ticket_id`))) where (`e`.`odbc_date` between curdate() and `DAYEND`(curdate())) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_encajado_ultima_hora`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_encajado_ultima_hora`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_encajado_ultima_hora` AS select sum((ifnull(`c`.`Volumen`,94500) / 1000000)) AS `m3`,`t`.`warehouse_id` AS `warehouse_id` from ((`expeditions` `e` left join `Cubos` `c` on((`c`.`item_id` = `e`.`EsBulto`))) join `Tickets` `t` on((`t`.`Id_Ticket` = `e`.`ticket_id`))) where ((`e`.`odbc_date` > (now() + interval -(1) hour)) and (`t`.`warehouse_id` in (1,44))) group by `t`.`warehouse_id` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_expeditions_shipping_charge`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_expeditions_shipping_charge`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_expeditions_shipping_charge` AS select `t`.`Id_Ticket` AS `Id_Ticket`,sum((`az`.`price` * if(((`e`.`EsBulto` = 71) and isnull(`e`.`Id_Article`) and (`a`.`Vista` = 2)),0.75,1))) AS `shipping_charge`,`t`.`Fecha` AS `Fecha` from ((((((`Tickets` `t` join `Clientes` `cli` on((`cli`.`id_cliente` = `t`.`Id_Cliente`))) left join `expeditions` `e` 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 (`cli`.`real` <> 0) and (`t`.`empresa_id` in (442,791,567))) group by `t`.`Id_Ticket` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_expeditions_shipping_charge2`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_expeditions_shipping_charge2`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_expeditions_shipping_charge2` AS select `t`.`Id_Ticket` AS `Id_Ticket`,(`az`.`price` * if(((`e`.`EsBulto` = 71) and isnull(`e`.`Id_Article`) and (`a`.`Vista` = 2)),0.75,1)) AS `shipping_charge`,`t`.`Fecha` AS `Fecha`,`t`.`warehouse_id` AS `warehouse_id` from (((((`Tickets` `t` left join `expeditions` `e` 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` >= '2016-01-01') and (`t`.`empresa_id` in (442,567))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_fallo`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_fallo`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_fallo` AS select `vncontrol`.`fallo`.`queja_id` AS `queja_id`,`vncontrol`.`fallo`.`accion_id` AS `accion_id` from `vncontrol`.`fallo` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_inter`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_inter`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_inter` AS select `vncontrol`.`inter`.`inter_id` AS `inter_id`,`vncontrol`.`inter`.`state_id` AS `state_id`,`vncontrol`.`inter`.`nota` AS `nota`,`vncontrol`.`inter`.`odbc_date` AS `odbc_date`,`vncontrol`.`inter`.`Id_Ticket` AS `Id_Ticket`,`vncontrol`.`inter`.`Id_Trabajador` AS `Id_Trabajador`,`vncontrol`.`inter`.`Id_Supervisor` AS `Id_supervisor` from `vncontrol`.`inter` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_jerarquia`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_jerarquia`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_jerarquia` AS select `jerarquia`.`worker_id` AS `Id_Trabajador`,`jerarquia`.`boss_id` AS `boss_id` from `jerarquia` union all select distinct `jerarquia`.`boss_id` AS `Id_Trabajador`,`jerarquia`.`boss_id` AS `boss_id` from `jerarquia` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_location`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_location`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_location` AS select `tl`.`longitude` AS `longitude`,`tl`.`latitude` AS `latitude`,`t`.`Id_Consigna` AS `Id_Consigna` from (`ticket_location` `tl` join `Tickets` `t` on((`t`.`Id_Ticket` = `tl`.`Id_Ticket`))) where (`t`.`Fecha` >= (curdate() + interval -(3) month)) group by `t`.`Id_Consigna` order by `t`.`Id_Ticket` desc */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_mana_spellers`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_mana_spellers`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_mana_spellers` AS select `bs`.`mana_spellers`.`Id_Trabajador` AS `Id_Trabajador`,`bs`.`mana_spellers`.`size` AS `size`,`bs`.`mana_spellers`.`used` AS `used` from `bs`.`mana_spellers` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_miriam`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_miriam`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_miriam` AS select `M`.`Id_Article` AS `Id_Article`,`M`.`Concepte` AS `Concepte`,`M`.`Cantidad` AS `Cantidad`,`M`.`Preu` AS `Preu`,`M`.`Descuento` AS `Descuento`,`T`.`Fecha` AS `Fecha`,`T`.`Id_Cliente` AS `Id_Cliente`,(((`M`.`Cantidad` * `M`.`Preu`) * (100 - `M`.`Descuento`)) / 100) AS `Importe` from (((`Tickets` `T` join `Movimientos` `M` on((`T`.`Id_Ticket` = `M`.`Id_Ticket`))) join `Articles` `A` on((`M`.`Id_Article` = `A`.`Id_Article`))) join `Tipos` `TP` on((`A`.`tipo_id` = `TP`.`tipo_id`))) where ((`T`.`Fecha` >= '2011-01-01') and (`A`.`tipo_id` = 7)) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_movimientos_log`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_movimientos_log`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_movimientos_log` AS select `bi`.`movimientos_log`.`idmovimientos_log` AS `idmovimientos_log`,`bi`.`movimientos_log`.`Id_Movimiento` AS `Id_Movimiento`,`bi`.`movimientos_log`.`odbc_date` AS `odbc_date`,`bi`.`movimientos_log`.`Id_Trabajador` AS `Id_Trabajador`,`bi`.`movimientos_log`.`field_name` AS `field_name`,`bi`.`movimientos_log`.`new_value` AS `new_value` from `bi`.`movimientos_log` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_movimientos_mark`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_movimientos_mark`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_movimientos_mark` AS select `Movimientos_mark`.`Id_Movimiento` AS `Id_Movimiento`,max(`Movimientos_mark`.`Id_Accion`) AS `Accion` from `Movimientos_mark` group by `Movimientos_mark`.`Id_Movimiento` having ((max(`Movimientos_mark`.`Id_Accion`) = '6') or (max(`Movimientos_mark`.`Id_Accion`) = '7')) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_pedidos_auto_preparados`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_pedidos_auto_preparados`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_pedidos_auto_preparados` AS select `t`.`CodigoTrabajador` AS `CodigoTrabajador`,`i`.`Id_Ticket` AS `Id_Ticket`,`i`.`odbc_date` AS `Momento` from ((`vn2008`.`v_jerarquia` `j` left join `vn2008`.`v_inter` `i` on((`j`.`Id_Trabajador` = `i`.`Id_Trabajador`))) join `vn2008`.`Trabajadores` `t` on((`t`.`Id_Trabajador` = `j`.`Id_Trabajador`))) where (`i`.`state_id` = 20) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_pedidos_auto_preparadoskk`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_pedidos_auto_preparadoskk`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_pedidos_auto_preparadoskk` AS select `t`.`CodigoTrabajador` AS `CodigoTrabajador`,`TK`.`Fecha` AS `Fecha`,`TK`.`Id_Ticket` AS `Id_Ticket`,`i`.`odbc_date` AS `Momento` from (((`vn2008`.`v_jerarquia` `j` left join `vn2008`.`v_inter` `i` on((`j`.`Id_Trabajador` = `i`.`Id_Trabajador`))) join `vn2008`.`Trabajadores` `t` on((`t`.`Id_Trabajador` = `j`.`Id_Trabajador`))) left join `vn2008`.`Tickets` `TK` on((`TK`.`Id_Ticket` = `i`.`Id_Ticket`))) where (`i`.`state_id` = 5) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_phonebook`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_phonebook`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_phonebook` AS select `Clientes`.`id_cliente` AS `Id_Cliente`,replace(`Clientes`.`telefono`,' ','') AS `Telefono` from `Clientes` where (`Clientes`.`telefono` and `Clientes`.`activo`) union select `Clientes`.`id_cliente` AS `Id_Cliente`,replace(`Clientes`.`movil`,' ','') AS `Movil` from `Clientes` where (`Clientes`.`movil` and `Clientes`.`activo`) union select `Consignatarios`.`Id_cliente` AS `Id_Cliente`,replace(`Consignatarios`.`telefono`,' ','') AS `TRIM(telefono)` from (`Consignatarios` join `Clientes` `c` on((`Consignatarios`.`Id_cliente` = `c`.`id_cliente`))) where (`Consignatarios`.`telefono` and `c`.`activo`) union select `Consignatarios`.`Id_cliente` AS `Id_Cliente`,replace(`Consignatarios`.`movil`,' ','') AS `TRIM(movil)` from (`Consignatarios` join `Clientes` `c` on((`Consignatarios`.`Id_cliente` = `c`.`id_cliente`))) where (`Consignatarios`.`movil` and `c`.`activo`) union select `r`.`Id_Cliente` AS `Id_Cliente`,replace(`c`.`Telefono`,' ','') AS `REPLACE(c.telefono,' ','')` from ((`Clientes` `cl` join `Relaciones` `r` on((`cl`.`id_cliente` = `r`.`Id_Cliente`))) join `Contactos` `c` on((`r`.`Id_Contacto` = `c`.`Id_Contacto`))) where (`cl`.`telefono` and `cl`.`activo`) union select `r`.`Id_Cliente` AS `Id_Cliente`,replace(`c`.`Movil`,' ','') AS `REPLACE(c.Movil,' ','')` from ((`Clientes` `cl` join `Relaciones` `r` on((`cl`.`id_cliente` = `r`.`Id_Cliente`))) join `Contactos` `c` on((`r`.`Id_Contacto` = `c`.`Id_Contacto`))) where (`cl`.`movil` and `cl`.`activo`) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_price_fixed`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_price_fixed`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_price_fixed` AS select `pf`.`warehouse_id` AS `warehouse_id`,`pf`.`item_id` AS `item_id`,`pf`.`rate_0` AS `rate_0`,`pf`.`rate_1` AS `rate_1`,`pf`.`rate_2` AS `rate_2`,`pf`.`rate_3` AS `rate_3`,`pf`.`date_start` AS `date_start`,`pf`.`date_end` AS `date_end`,`pf`.`bonus` AS `bonus`,`pf`.`grouping` AS `grouping`,`pf`.`Packing` AS `Packing`,`pf`.`caja` AS `caja` from `price_fixed` `pf` where (`pf`.`warehouse_id` < 1000) union all select `wg`.`warehouse_id` AS `warehouse_id`,`pf`.`item_id` AS `item_id`,`pf`.`rate_0` AS `rate_0`,`pf`.`rate_1` AS `rate_1`,`pf`.`rate_2` AS `rate_2`,`pf`.`rate_3` AS `rate_3`,`pf`.`date_start` AS `date_start`,`pf`.`date_end` AS `date_end`,`pf`.`bonus` AS `bonus`,`pf`.`grouping` AS `grouping`,`pf`.`Packing` AS `Packing`,`pf`.`caja` AS `caja` from (`price_fixed` `pf` join `warehouse_group` `wg`) where ((`wg`.`warehouse_alias_id` + 1000) = `pf`.`warehouse_id`) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_price_fixed_group`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_price_fixed_group`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_price_fixed_group` AS select `pf`.`warehouse_id` AS `warehouse_id`,`pf`.`item_id` AS `item_id`,`pf`.`rate_0` AS `rate_0`,`pf`.`rate_1` AS `rate_1`,`pf`.`rate_2` AS `rate_2`,`pf`.`rate_3` AS `rate_3`,`pf`.`date_start` AS `date_start`,`pf`.`date_end` AS `date_end`,`pf`.`bonus` AS `bonus`,`pf`.`grouping` AS `grouping`,`pf`.`Packing` AS `Packing`,`pf`.`caja` AS `caja` from `v_price_fixed` `pf` group by `pf`.`warehouse_id`,`pf`.`item_id`,`pf`.`date_start`,`pf`.`date_end` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_session`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_session`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_session` AS select 1 AS `id`,`t`.`CodigoTrabajador` AS `CodigoTrabajador`,if(isnull(`sc`.`Id_Suplente`),`c`.`Id_Trabajador`,`sc`.`Id_Suplente`) AS `Id_Trabajador`,`c`.`id_cliente` AS `Id_Cliente`,`c`.`cliente` AS `Cliente`,`s`.`lastUpdate` AS `Fecha` from ((((`hedera`.`userSession` `s` join `hedera`.`visitUser` `v` on((`v`.`id` = `s`.`userVisit`))) join `vn2008`.`Clientes` `c` on((`c`.`id_cliente` = `v`.`user`))) left join `vn2008`.`Trabajadores` `t` on((`c`.`Id_Trabajador` = `t`.`Id_Trabajador`))) left join `vn2008`.`sharingcart` `sc` on(((`sc`.`Id_Trabajador` = `c`.`Id_Trabajador`) and (curdate() between `sc`.`datSTART` and `sc`.`datEND`)))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_ticket_amount`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_ticket_amount`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_ticket_amount` AS select `Movimientos`.`Id_Ticket` AS `Id_Ticket`,sum((((`Movimientos`.`Cantidad` * `Movimientos`.`Preu`) * (100 - `Movimientos`.`Descuento`)) / 100)) AS `amount` from (`Movimientos` join `Tickets` on((`Movimientos`.`Id_Ticket` = `Tickets`.`Id_Ticket`))) where (`Tickets`.`Fecha` >= (curdate() + interval -(6) month)) group by `Movimientos`.`Id_Ticket` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_trabajadores`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_trabajadores`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_trabajadores` AS select `t`.`CodigoTrabajador` AS `CodigoTrabajador`,`t`.`Nombre` AS `Nombre`,`t`.`Fecha_Inicio` AS `Fecha_Inicio`,`t`.`Password` AS `Password`,`t`.`user` AS `user`,`t`.`Apellidos` AS `Apellidos`,`t`.`Id_Trabajador` AS `Id_Trabajador`,`t`.`Foto` AS `Foto` from `vn2008`.`Trabajadores` `t` where (`t`.`Id_Cliente_Interno` = `account`.`userGetId`()) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_user`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_user`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_user` AS select `u`.`id` AS `id`,`u`.`role` AS `mysql_user_id`,`u`.`name` AS `name`,`u`.`password` AS `password`,`u`.`active` AS `active` from `account`.`user` `u` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_ventes`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_ventes`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_ventes` AS select `Agencias`.`Agencia` AS `Agencia`,`A`.`Categoria` AS `Categoria`,`A`.`tipo_id` AS `tipo_id`,`A`.`Medida` AS `Medida`,`A`.`Article` AS `Article`,`A`.`Color` AS `Color`,`CS`.`Id_cliente` AS `Id_Cliente`,`TP`.`Id_Tipo` AS `Tipo`,`T`.`Factura` AS `Factura`,`T`.`warehouse_id` AS `warehouse_id`,`M`.`Id_Movimiento` AS `Id_Movimiento`,`M`.`Id_Article` AS `Id_Article`,`TP`.`Id_Tipo` AS `Familia`,`M`.`Id_Ticket` AS `Id_Ticket`,`M`.`Concepte` AS `Concepte`,`M`.`Cantidad` AS `Cantidad`,`M`.`quantity` AS `quantity`,`M`.`Preu` AS `Preu`,`M`.`Descuento` AS `Descuento`,if((`T`.`Fecha` >= '2015-10-01'),`M`.`CostFixat`,((`M`.`Preu` * (100 - `M`.`Descuento`)) / 100)) AS `CostFixat`,`M`.`Reservado` AS `Reservado`,`M`.`OK` AS `OK`,`M`.`PrecioFijado` AS `PrecioFijado`,`M`.`odbc_date` AS `odbc_date`,cast(`T`.`Fecha` as date) AS `Fecha`,`T`.`Fecha` AS `FechaCompleta`,`CS`.`consignatario` AS `Alias`,`T`.`Id_Consigna` AS `Id_Consigna`,(((`M`.`Cantidad` * `M`.`Preu`) * (100 - `M`.`Descuento`)) / 100) AS `Importe`,`O`.`Origen` AS `Origen`,`TP`.`reino_id` AS `reino_id`,`C`.`invoice` AS `invoice`,`A`.`producer_id` AS `producer_id` from ((((((((`Movimientos` `M` join `Tickets` `T` on((`M`.`Id_Ticket` = `T`.`Id_Ticket`))) join `Consignatarios` `CS` on((`CS`.`id_consigna` = `T`.`Id_Consigna`))) join `Clientes` `C` on((`CS`.`Id_cliente` = `C`.`id_cliente`))) join `Articles` `A` on((`M`.`Id_Article` = `A`.`Id_Article`))) join `Origen` `O` on((`O`.`id` = `A`.`id_origen`))) join `Tipos` `TP` on((`A`.`tipo_id` = `TP`.`tipo_id`))) join `reinos` `r` on((`TP`.`reino_id` = `r`.`id`))) join `Agencias` on((`Agencias`.`Id_Agencia` = `T`.`Id_Agencia`))) where ((`T`.`Fecha` >= '2013-01-01') and (`C`.`real` > 0) and (`r`.`id` <> 6)) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_venteskk`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_venteskk`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_venteskk` AS select `Agencias`.`Agencia` AS `Agencia`,`A`.`Categoria` AS `Categoria`,`A`.`tipo_id` AS `tipo_id`,`A`.`Medida` AS `Medida`,`A`.`Article` AS `Article`,`A`.`Color` AS `Color`,`CS`.`Id_cliente` AS `Id_Cliente`,`TP`.`Id_Tipo` AS `Tipo`,`T`.`Factura` AS `Factura`,`T`.`warehouse_id` AS `warehouse_id`,`M`.`Id_Movimiento` AS `Id_Movimiento`,`M`.`Id_Article` AS `Id_Article`,`TP`.`Id_Tipo` AS `Familia`,`M`.`Id_Ticket` AS `Id_Ticket`,`M`.`Concepte` AS `Concepte`,`M`.`Cantidad` AS `Cantidad`,`M`.`quantity` AS `quantity`,`M`.`Preu` AS `Preu`,`M`.`Descuento` AS `Descuento`,if((`T`.`Fecha` >= '2015-10-01'),`M`.`CostFixat`,((`M`.`Preu` * (100 - `M`.`Descuento`)) / 100)) AS `CostFixat`,`M`.`Reservado` AS `Reservado`,`M`.`OK` AS `OK`,`M`.`PrecioFijado` AS `PrecioFijado`,`M`.`odbc_date` AS `odbc_date`,cast(`T`.`Fecha` as date) AS `Fecha`,`T`.`Fecha` AS `FechaCompleta`,`CS`.`consignatario` AS `Alias`,`T`.`Id_Consigna` AS `Id_Consigna`,(((`M`.`Cantidad` * `M`.`Preu`) * (100 - `M`.`Descuento`)) / 100) AS `Importe`,`O`.`Origen` AS `Origen`,`TP`.`reino_id` AS `reino_id`,`C`.`invoice` AS `invoice`,`A`.`producer_id` AS `producer_id` from ((((((((`Movimientos` `M` join `Tickets` `T` on((`M`.`Id_Ticket` = `T`.`Id_Ticket`))) join `Consignatarios` `CS` on((`CS`.`id_consigna` = `T`.`Id_Consigna`))) join `Clientes` `C` on((`CS`.`Id_cliente` = `C`.`id_cliente`))) join `Articles` `A` on((`M`.`Id_Article` = `A`.`Id_Article`))) join `Origen` `O` on((`O`.`id` = `A`.`id_origen`))) join `Tipos` `TP` on((`A`.`tipo_id` = `TP`.`tipo_id`))) join `reinos` `r` on((`TP`.`reino_id` = `r`.`id`))) join `Agencias` on((`Agencias`.`Id_Agencia` = `T`.`Id_Agencia`))) where ((`T`.`Fecha` >= '2013-01-01') and (`C`.`real` > 0) and (`r`.`id` <> 6)) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_warehouse`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_warehouse`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_warehouse` AS select `warehouse`.`id` AS `id`,`warehouse`.`name` AS `almacen` from `warehouse` union all select (1000 + `warehouse_alias`.`warehouse_alias_id`) AS `warehouse_alias_id`,concat(`warehouse_alias`.`alias`,'(G)') AS `concat(alias, '(G)')` from `warehouse_alias` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_xsubclien`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_xsubclien`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_xsubclien` AS select distinct `Facturas`.`Id_Cliente` AS `Id_Cliente`,`Facturas`.`empresa_id` AS `empresa_id` from `Facturas` where (`Facturas`.`Fecha` > (curdate() + interval -(2) month)) union select `Recibos`.`Id_Cliente` AS `Id_Cliente`,`Recibos`.`empresa_id` AS `empresa_id` from `Recibos` where (`Recibos`.`Fechacobro` > (curdate() + interval -(2) month)) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_xsubcuentas`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_xsubcuentas`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_xsubcuentas` AS select `Clientes`.`Cuenta` AS `COD`,`Clientes`.`razonSocial` AS `TITULO`,concat(if((`p`.`CEE` = 1),`p`.`Codigo`,''),`Clientes`.`if`) AS `NIF`,`Clientes`.`domicilio` AS `DOMICILIO`,`Clientes`.`poblacion` AS `POBLACION`,`province`.`name` AS `PROVINCIA`,`Clientes`.`codPostal` AS `CODPOSTAL`,`p`.`Codigo` AS `country_code`,`v_xsubclien`.`empresa_id` AS `empresa_id`,substr(`Clientes`.`e-mail`,1,(coalesce(nullif(locate(',',`Clientes`.`e-mail`),0),99) - 1)) AS `EMAIL`,`Clientes`.`cplusTerIdNifFk` AS `IDNIF` from (((`Clientes` join `v_xsubclien` on((`Clientes`.`id_cliente` = `v_xsubclien`.`Id_Cliente`))) left join `Paises` `p` on((`p`.`Id` = `Clientes`.`Id_Pais`))) join `province` on((`Clientes`.`province_id` = `province`.`province_id`))) where (`Clientes`.`oficial` <> 0) group by `Clientes`.`id_cliente`,`v_xsubclien`.`empresa_id` union all select `Proveedores`.`cuenta` AS `Cuenta`,`Proveedores`.`Proveedor` AS `Proveedor`,concat(if((`p`.`CEE` = 1),`p`.`Codigo`,''),`Proveedores`.`NIF`) AS `NIF`,`Proveedores`.`Domicilio` AS `Domicilio`,`Proveedores`.`Localidad` AS `Localidad`,`prov`.`name` AS `Provincia`,`Proveedores`.`CP` AS `CP`,`p`.`Codigo` AS `country_code`,`v_xsubprov`.`empresa_id` AS `empresa_id`,substr(`c`.`email`,1,(coalesce(nullif(locate(',',`c`.`email`),0),99) - 1)) AS `EMAIL`,if((`p`.`CEE` = 0),1,if((`p`.`CEE` = 1),2,4)) AS `IDNIF` from (((((`Proveedores` join `v_xsubprov` on((`Proveedores`.`Id_Proveedor` = `v_xsubprov`.`proveedor_id`))) left join `Paises` `p` on((`p`.`Id` = `Proveedores`.`pais_id`))) left join `province` `prov` on((`prov`.`province_id` = `Proveedores`.`province_id`))) left join `Relaciones` `r` on((`r`.`Id_Proveedor` = `Proveedores`.`Id_Proveedor`))) left join `Contactos` `c` on((`c`.`Id_Contacto` = `r`.`Id_Contacto`))) where (`Proveedores`.`oficial` <> 0) group by `v_xsubprov`.`proveedor_id`,`v_xsubprov`.`empresa_id` union all select `Gastos`.`Id_Gasto` AS `Id_Gasto`,`Gastos`.`Gasto` AS `Gasto`,NULL AS `NULL`,NULL AS `My_exp_NULL`,NULL AS `My_exp_1_NULL`,NULL AS `My_exp_2_NULL`,NULL AS `My_exp_3_NULL`,NULL AS `country_code`,`e`.`id` AS `id`,NULL AS `EMAIL`,1 AS `IDNIF` from (`Gastos` join `empresa` `e` on((`e`.`id` = 442))) union all select `Bancos`.`Cuenta` AS `Cuenta`,`Bancos`.`Banco` AS `Banco`,NULL AS `NULL`,NULL AS `My_exp_NULL`,NULL AS `My_exp_1_NULL`,NULL AS `My_exp_2_NULL`,NULL AS `My_exp_3_NULL`,NULL AS `country_code`,`e`.`id` AS `id`,NULL AS `EMAIL`,1 AS `IDNIF` from (`Bancos` join `empresa` `e` on((`e`.`id` = 442))) union all select lpad(right(`Proveedores`.`cuenta`,5),10,'47510000') AS `Cuenta`,`Proveedores`.`Proveedor` AS `Proveedor`,`Proveedores`.`NIF` AS `NIF`,`Proveedores`.`Domicilio` AS `Domicilio`,`Proveedores`.`Localidad` AS `Localidad`,`prov`.`name` AS `Provincia`,`Proveedores`.`CP` AS `CP`,`p`.`Codigo` AS `country_code`,`v_xsubprov`.`empresa_id` AS `empresa_id`,substr(`c`.`email`,1,(coalesce(nullif(locate(',',`c`.`email`),0),99) - 1)) AS `EMAIL`,if((`p`.`CEE` = 0),1,if((`p`.`CEE` = 1),2,4)) AS `IDNIF` from (((((`Proveedores` join `v_xsubprov` on((`Proveedores`.`Id_Proveedor` = `v_xsubprov`.`proveedor_id`))) left join `Paises` `p` on((`p`.`Id` = `Proveedores`.`pais_id`))) left join `province` `prov` on((`prov`.`province_id` = `Proveedores`.`province_id`))) left join `Relaciones` `r` on((`r`.`Id_Proveedor` = `Proveedores`.`Id_Proveedor`))) left join `Contactos` `c` on((`c`.`Id_Contacto` = `r`.`Id_Contacto`))) where (((`Proveedores`.`cuenta` like '_____3____') or (`Proveedores`.`cuenta` like '_____2____')) and (`Proveedores`.`oficial` = 1)) group by `v_xsubprov`.`proveedor_id`,`v_xsubprov`.`empresa_id` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_xsubprov`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_xsubprov`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_xsubprov` AS select `recibida`.`proveedor_id` AS `proveedor_id`,`recibida`.`empresa_id` AS `empresa_id` from `recibida` where (`recibida`.`fecha` > (curdate() + interval -(3) month)) group by `recibida`.`proveedor_id`,`recibida`.`empresa_id` union all select `pago`.`id_proveedor` AS `id_proveedor`,`pago`.`empresa_id` AS `empresa_id` from `pago` where (`pago`.`fecha` > (curdate() + interval -(3) month)) group by `pago`.`id_proveedor`,`pago`.`empresa_id` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `vnCreditClassification`
+--
+
+/*!50001 DROP VIEW IF EXISTS `vnCreditClassification`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `vnCreditClassification` AS select `vn`.`creditClassification`.`id` AS `id`,`vn`.`creditClassification`.`client` AS `client`,`vn`.`creditClassification`.`dateStart` AS `dateStart`,`vn`.`creditClassification`.`dateEnd` AS `dateEnd` from `vn`.`creditClassification` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `vnCreditInsurance`
+--
+
+/*!50001 DROP VIEW IF EXISTS `vnCreditInsurance`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `vnCreditInsurance` AS select `vn`.`creditInsurance`.`id` AS `id`,`vn`.`creditInsurance`.`creditClassification` AS `creditClassification`,`vn`.`creditInsurance`.`credit` AS `credit`,`vn`.`creditInsurance`.`creationDate` AS `creationDate`,`vn`.`creditInsurance`.`grade` AS `grade` from `vn`.`creditInsurance` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `vnSolunionCAP`
+--
+
+/*!50001 DROP VIEW IF EXISTS `vnSolunionCAP`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `vnSolunionCAP` AS select `vn`.`solunionCAP`.`creditInsurance` AS `creditInsurance`,`vn`.`solunionCAP`.`dateStart` AS `dateStart`,`vn`.`solunionCAP`.`dateEnd` AS `dateEnd`,`vn`.`solunionCAP`.`dateLeaving` AS `dateLeaving` from `vn`.`solunionCAP` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `workerDocument`
+--
+
+/*!50001 DROP VIEW IF EXISTS `workerDocument`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `workerDocument` AS select `vn`.`workerDocument`.`id` AS `id`,`vn`.`workerDocument`.`worker` AS `worker`,`vn`.`workerDocument`.`document` AS `document` from `vn`.`workerDocument` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `workerTeamCollegues`
+--
+
+/*!50001 DROP VIEW IF EXISTS `workerTeamCollegues`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `workerTeamCollegues` AS select distinct `w`.`Id_Trabajador` AS `workerId`,`t`.`Id_Trabajador` AS `collegueId` from (`vn`.`workerTeam` `w` join `vn`.`workerTeam` `t` on((`w`.`team` = `t`.`team`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `workerTeam_kk`
+--
+
+/*!50001 DROP VIEW IF EXISTS `workerTeam_kk`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `workerTeam_kk` AS select `w`.`team` AS `team`,`w`.`user` AS `user`,`w`.`id` AS `id`,`t`.`Id_Trabajador` AS `Id_Trabajador` from (`vn`.`workerTeam` `w` left join `vn2008`.`Trabajadores` `t` on((`t`.`user_id` = `w`.`user`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `zoneNickname`
+--
+
+/*!50001 DROP VIEW IF EXISTS `zoneNickname`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `zoneNickname` AS select `ap`.`warehouse_id` AS `warehouse_id`,`ap`.`agency_id` AS `agency_id`,`ap`.`zona` AS `zona`,concat('ZONA ',`ap`.`zona`,' ',if((`ap`.`zona` = 20),'Madrid',`p`.`name`)) AS `alias` from (`Agencias_province` `ap` join `province` `p` on((`p`.`province_id` = `ap`.`province_id`))) group by `ap`.`zona`,`ap`.`warehouse_id`,`ap`.`agency_id` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
+
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
+
+-- Dump completed on 2017-12-27 7:50:53
\ No newline at end of file
diff --git a/services/db/localDB07ViewsVn.sql b/services/db/localDB07ViewsVn.sql
new file mode 100644
index 000000000..bf231170b
--- /dev/null
+++ b/services/db/localDB07ViewsVn.sql
@@ -0,0 +1,2024 @@
+USE `vn`;
+-- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64)
+--
+-- Host: db.verdnatura.es Database: vn
+-- ------------------------------------------------------
+-- 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 */;
+
+--
+-- Final view structure for view `accounting`
+--
+
+/*!50001 DROP VIEW IF EXISTS `accounting`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `accounting` AS select `b`.`Id_Banco` AS `id`,`b`.`Banco` AS `bank`,`b`.`Cuenta` AS `account`,`b`.`cash` AS `accountingTypeFk`,`b`.`entity_id` AS `entityFk`,`b`.`activo` AS `isActive` from `vn2008`.`Bancos` `b` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `address`
+--
+
+/*!50001 DROP VIEW IF EXISTS `address`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `address` AS select `t`.`id_consigna` AS `id`,`t`.`Id_cliente` AS `clientFk`,`t`.`domicilio` AS `street`,`t`.`poblacion` AS `city`,`t`.`codPostal` AS `postalCode`,`t`.`province_id` AS `provinceFk`,`t`.`telefono` AS `phone`,`t`.`movil` AS `celular`,`t`.`consignatario` AS `nickname`,`t`.`predeterminada` AS `isDefaultAddress`,`t`.`active` AS `active`,`t`.`longitude` AS `longitude`,`t`.`latitude` AS `latitude`,`t`.`warehouse_id` AS `warehouseFk`,`t`.`movil` AS `mobile`,`t`.`Id_Agencia` AS `agencyFk`,`t`.`isEqualizated` AS `isEqualizated`,`t`.`predeterminada` AS `defaultAddress`,`t`.`Id_cliente` AS `customer`,`t`.`Id_Agencia` AS `agency`,`t`.`province_id` AS `province`,`t`.`warehouse_id` AS `warehouse` from `vn2008`.`Consignatarios` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `addressObservation`
+--
+
+/*!50001 DROP VIEW IF EXISTS `addressObservation`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `addressObservation` AS select `co`.`consignatarios_observation_id` AS `id`,`co`.`Id_Consigna` AS `addressFk`,`co`.`observation_type_id` AS `observationTypeFk`,`co`.`text` AS `description` from `vn2008`.`consignatarios_observation` `co` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `agency`
+--
+
+/*!50001 DROP VIEW IF EXISTS `agency`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `agency` AS select `a`.`agency_id` AS `id`,`a`.`name` AS `name`,`a`.`warehouse_id` AS `warehouse`,`a`.`warehouse_id` AS `warehouseFk`,`a`.`por_volumen` AS `isVolumetric`,`a`.`Id_Banco` AS `bank`,`a`.`Id_Banco` AS `bankFk`,`a`.`warehouse_alias_id` AS `warehouseNickname`,`a`.`warehouse_alias_id` AS `warehouseAliasFk`,`a`.`propios` AS `own`,`a`.`zone_label` AS `labelZone` from `vn2008`.`agency` `a` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `agencyHour`
+--
+
+/*!50001 DROP VIEW IF EXISTS `agencyHour`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `agencyHour` AS select `h`.`agency_hour_id` AS `id`,`h`.`agency_id` AS `agency`,`h`.`week_day` AS `weekDay`,`h`.`warehouse_id` AS `warehouse`,`h`.`province_id` AS `province`,`h`.`subtract_day` AS `substractDay`,`h`.`max_hour` AS `maxHour` from `vn2008`.`agency_hour` `h` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `agencyMode`
+--
+
+/*!50001 DROP VIEW IF EXISTS `agencyMode`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `agencyMode` AS select `a`.`Id_Agencia` AS `id`,`a`.`Agencia` AS `name`,`a`.`description` AS `description`,`a`.`Vista` AS `view`,`a`.`Vista` AS `deliveryMethod`,`a`.`m3` AS `m3`,`a`.`cod71` AS `cod71`,`a`.`web` AS `web`,`a`.`agency_id` AS `agency`,`a`.`agency_id` AS `agencyFk`,`a`.`agency_service_id` AS `agencyService`,`a`.`agency_service_id` AS `agencyServiceFk`,`a`.`inflacion` AS `inflacion`,`a`.`is_volumetric` AS `isVolumetric`,`a`.`send_mail` AS `reportMail` from `vn2008`.`Agencias` `a` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `agencyWarehouse`
+--
+
+/*!50001 DROP VIEW IF EXISTS `agencyWarehouse`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `agencyWarehouse` AS select `a`.`agency_id` AS `agencyFk`,`a`.`warehouse_id` AS `warehouseFk`,`a`.`Vista` AS `agencyType` from `vn2008`.`agency_warehouse` `a` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `awb`
+--
+
+/*!50001 DROP VIEW IF EXISTS `awb`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `awb` AS select `a`.`id` AS `id`,`a`.`codigo` AS `code`,`a`.`bultos` AS `package`,`a`.`peso` AS `weight`,`a`.`MYSQL_TIME` AS `created`,`a`.`transitario_id` AS `transitoryFk`,`a`.`iva_id` AS `taxFk`,`a`.`gestdoc_id` AS `docFk`,`a`.`importe` AS `amount`,`a`.`carguera_id` AS `freightFk`,`a`.`m3` AS `m3`,`a`.`stems` AS `stems`,`a`.`flight_id` AS `flightFk`,`a`.`volume_weight` AS `volumeWeight`,`a`.`hb` AS `hb`,`a`.`rate` AS `rate`,`a`.`booked` AS `booked`,`a`.`issued` AS `issued`,`a`.`operated` AS `operated`,`a`.`bookEntried` AS `bookEntried` from `vn2008`.`awb` `a` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `bank`
+--
+
+/*!50001 DROP VIEW IF EXISTS `bank`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `bank` AS select `b`.`Id_Banco` AS `id`,`b`.`Banco` AS `bank`,`b`.`Cuenta` AS `account`,`b`.`cash` AS `cash`,`b`.`entity_id` AS `entityFk`,`b`.`activo` AS `isActive` from `vn2008`.`Bancos` `b` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `bankEntity`
+--
+
+/*!50001 DROP VIEW IF EXISTS `bankEntity`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `bankEntity` AS select `e`.`entity_id` AS `id`,`e`.`pais_id` AS `countryFk`,`e`.`description` AS `name`,`e`.`bic` AS `bic` from `vn2008`.`entity` `e` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `botanicExport`
+--
+
+/*!50001 DROP VIEW IF EXISTS `botanicExport`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `botanicExport` AS select `be`.`botanic_export_id` AS `id`,`be`.`edi_genus_id` AS `ediGenusFk`,`be`.`edi_specie_id` AS `ediSpecieFk`,`be`.`Id_Paises` AS `countryFk`,`be`.`restriction` AS `restriction`,`be`.`description` AS `description` from `vn2008`.`botanic_export` `be` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `buy`
+--
+
+/*!50001 DROP VIEW IF EXISTS `buy`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `buy` AS select `c`.`Id_Compra` AS `id`,`c`.`Id_Entrada` AS `entryFk`,`c`.`Id_Article` AS `itemFk`,`c`.`Cantidad` AS `amount`,`c`.`Costefijo` AS `buyingValue`,`c`.`Cantidad` AS `quantity`,`c`.`Id_Cubo` AS `packageFk`,`c`.`Etiquetas` AS `stickers`,`c`.`Portefijo` AS `freightValue`,`c`.`Embalajefijo` AS `packageValue`,`c`.`Comisionfija` AS `comissionValue`,`c`.`Packing` AS `packing`,`c`.`grouping` AS `grouping`,`c`.`caja` AS `groupingMode`,`c`.`Nicho` AS `location`,`c`.`Tarifa1` AS `price1`,`c`.`Tarifa2` AS `price2`,`c`.`Tarifa3` AS `price3`,`c`.`PVP` AS `minPrice`,`c`.`Productor` AS `producer`,`c`.`Vida` AS `printedStickers`,`c`.`punteo` AS `isChecked` from `vn2008`.`Compres` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `city`
+--
+
+/*!50001 DROP VIEW IF EXISTS `city`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `city` AS select `c`.`city_id` AS `id`,`c`.`name` AS `name`,`c`.`province_id` AS `provinceFk` from `vn2008`.`city` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `client`
+--
+
+/*!50001 DROP VIEW IF EXISTS `client`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `client` AS select `c`.`id_cliente` AS `id`,`c`.`cliente` AS `name`,`c`.`if` AS `fi`,`c`.`razonSocial` AS `socialName`,`c`.`contacto` AS `contact`,`c`.`domicilio` AS `street`,`c`.`poblacion` AS `city`,`c`.`codPostal` AS `postcode`,`c`.`telefono` AS `phone`,`c`.`movil` AS `mobile`,`c`.`fax` AS `fax`,`c`.`real` AS `isRelevant`,`c`.`e-mail` AS `email`,`c`.`iban` AS `iban`,`c`.`vencimiento` AS `dueDay`,`c`.`Cuenta` AS `accountingAccount`,`c`.`RE` AS `isEqualizated`,`c`.`province_id` AS `provinceFk`,`c`.`invoice` AS `hasToInvoice`,`c`.`credito` AS `credit`,`c`.`Id_Pais` AS `countryFk`,`c`.`activo` AS `isActive`,`c`.`gestdoc_id` AS `gestdocFk`,`c`.`calidad` AS `quality`,`c`.`pay_met_id` AS `payMethodFk`,`c`.`created` AS `created`,`c`.`mail` AS `isToBeMailed`,`c`.`chanel_id` AS `contactChannelFk`,`c`.`sepaVnl` AS `hasSepaVnl`,`c`.`coreVnl` AS `hasCoreVnl`,`c`.`coreVnh` AS `hasCoreVnh`,`c`.`risk_calculated` AS `riskCalculated`,`c`.`clientes_tipo_id` AS `clientTypeFk`,`c`.`mail_address` AS `mailAddress`,`c`.`cplusTerIdNifFk` AS `cplusTerIdNifFk`,`c`.`invoiceByAddress` AS `hasToInvoiceByAddress`,`c`.`contabilizado` AS `isTaxDataChecked`,`c`.`congelado` AS `isFreezed`,`c`.`creditInsurance` AS `creditInsurance`,`c`.`isCreatedAsServed` AS `isCreatedAsServed`,`c`.`hasInvoiceSimplified` AS `hasInvoiceSimplified`,`c`.`Id_Trabajador` AS `salesPersonFk`,`c`.`vies` AS `isVies`,`c`.`EYPBC` AS `eypbc` from `vn2008`.`Clientes` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `clientCredit`
+--
+
+/*!50001 DROP VIEW IF EXISTS `clientCredit`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `clientCredit` AS select `c`.`id` AS `id`,`c`.`Id_Cliente` AS `clientFk`,`c`.`Id_Trabajador` AS `employeeFk`,`c`.`amount` AS `amount`,`c`.`odbc_date` AS `created` from `vn2008`.`credit` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `clientDefaultCompany`
+--
+
+/*!50001 DROP VIEW IF EXISTS `clientDefaultCompany`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `clientDefaultCompany` AS select `ce`.`Id_Clientes_empresa` AS `id`,`ce`.`Id_Cliente` AS `ClientFk`,`ce`.`empresa_id` AS `CompanyFk`,`ce`.`fecha_ini` AS `started`,`ce`.`fecha_fin` AS `finished` from `vn2008`.`Clientes_empresa` `ce` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `clientManaCache`
+--
+
+/*!50001 DROP VIEW IF EXISTS `clientManaCache`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `clientManaCache` AS select `mc`.`Id_Cliente` AS `clientFk`,`mc`.`Mana` AS `mana`,`mc`.`dated` AS `dated` from `bs`.`manaCustomer` `mc` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `clientNew`
+--
+
+/*!50001 DROP VIEW IF EXISTS `clientNew`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `clientNew` AS select `c`.`id_cliente` AS `id`,`c`.`cliente` AS `name`,`c`.`if` AS `fi`,`c`.`razonSocial` AS `socialName`,`c`.`contacto` AS `contact`,`c`.`domicilio` AS `street`,`c`.`poblacion` AS `city`,`c`.`codPostal` AS `postcode`,`c`.`telefono` AS `phone`,`c`.`movil` AS `mobile`,`c`.`fax` AS `fax`,`c`.`real` AS `isRelevant`,`c`.`e-mail` AS `email`,`c`.`iban` AS `iban`,`c`.`vencimiento` AS `dueDay`,`c`.`Cuenta` AS `accountingAccount`,`c`.`RE` AS `isEqualizated`,`c`.`province_id` AS `provinceFk`,`c`.`invoice` AS `hasToInvoice`,`c`.`credito` AS `credit`,`c`.`Id_Pais` AS `countryFk`,`c`.`activo` AS `isActive`,`c`.`gestdoc_id` AS `gestdocFk`,`c`.`calidad` AS `quality`,`c`.`pay_met_id` AS `payMethodFk`,`c`.`created` AS `created`,`c`.`mail` AS `isToBeMailed`,`c`.`chanel_id` AS `contactChannelFk`,`c`.`sepaVnl` AS `hasSepaVnl`,`c`.`coreVnl` AS `hasCoreVnl`,`c`.`coreVnh` AS `hasCoreVnh`,`c`.`risk_calculated` AS `riskCalculated`,`c`.`clientes_tipo_id` AS `clientTypeFk`,`c`.`mail_address` AS `mailAddress`,`c`.`cplusTerIdNifFk` AS `cplusTerIdNifFk`,`c`.`invoiceByAddress` AS `hasToInvoiceByAddress`,`c`.`contabilizado` AS `isTaxDataChecked`,`c`.`congelado` AS `isFreezed`,`c`.`creditInsurance` AS `creditInsurance`,`c`.`isCreatedAsServed` AS `isCreatedAsServed`,`c`.`hasInvoiceSimplified` AS `hasInvoiceSimplified`,`c`.`Id_Trabajador` AS `salesPersonFk`,`c`.`vies` AS `isVies`,`c`.`EYPBC` AS `eypbc` from `vn2008`.`Clientes` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `clientNotification`
+--
+
+/*!50001 DROP VIEW IF EXISTS `clientNotification`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `clientNotification` AS select `e`.`id` AS `id`,`e`.`Id_Cliente` AS `clientFk`,`e`.`escritos_id` AS `clientNotificationTypeFk`,`e`.`fecha` AS `created`,`e`.`Id_Trabajador` AS `workerFk`,`e`.`userFk` AS `userFk` from `vn2008`.`escritos_det` `e` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `clientNotificationType`
+--
+
+/*!50001 DROP VIEW IF EXISTS `clientNotificationType`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `clientNotificationType` AS select `e`.`id` AS `id`,`e`.`abrev` AS `code`,`e`.`descripcion` AS `description`,`e`.`visible` AS `isVisible` from `vn2008`.`escritos` `e` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `clientObservation`
+--
+
+/*!50001 DROP VIEW IF EXISTS `clientObservation`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `clientObservation` AS select `vn2008`.`client_observation`.`client_observation_id` AS `id`,`vn2008`.`client_observation`.`Id_Cliente` AS `clientFk`,`vn2008`.`client_observation`.`Id_Trabajador` AS `workerFk`,`vn2008`.`client_observation`.`text` AS `text`,`vn2008`.`client_observation`.`odbc_date` AS `creationDate` from `vn2008`.`client_observation` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `clientTransicion`
+--
+
+/*!50001 DROP VIEW IF EXISTS `clientTransicion`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `clientTransicion` AS select `c`.`id_cliente` AS `id`,`c`.`cliente` AS `name`,`c`.`if` AS `fi`,`c`.`razonSocial` AS `socialName`,`c`.`contacto` AS `contact`,`c`.`domicilio` AS `street`,`c`.`poblacion` AS `city`,`c`.`codPostal` AS `postcode`,`c`.`telefono` AS `phone`,`c`.`movil` AS `mobile`,`c`.`fax` AS `fax`,`c`.`real` AS `isRelevant`,`c`.`e-mail` AS `email`,`c`.`cc` AS `iban`,`c`.`vencimiento` AS `dueDay`,`c`.`Cuenta` AS `accountingAccount`,`c`.`RE` AS `isEqualizated`,`c`.`province_id` AS `provinceFk`,`c`.`invoice` AS `hasToInvoice`,`c`.`credito` AS `credit`,`c`.`Id_Pais` AS `countryFk`,`c`.`activo` AS `isActive`,`c`.`gestdoc_id` AS `gestdocFk`,`c`.`calidad` AS `quality`,`c`.`pay_met_id` AS `paymentMethodFk`,`c`.`mail` AS `isToBeMailed`,`c`.`chanel_id` AS `contactChannelFk`,`c`.`sepaVnl` AS `hasSepaVnl`,`c`.`coreVnl` AS `hasCoreVnl`,`c`.`coreVnh` AS `hasCoreVnh`,`c`.`risk_calculated` AS `riskCalculated`,`c`.`clientes_tipo_id` AS `clientTypeFk`,`c`.`mail_address` AS `mail_address`,`c`.`cplusTerIdNifFk` AS `cplusTerIdNifFk`,`c`.`contabilizado` AS `isTaxDataChecked`,`c`.`congelado` AS `isFreezed`,`c`.`creditInsurance` AS `creditInsurance`,`c`.`isCreatedAsServed` AS `isCreatedAsServed`,`c`.`hasInvoiceSimplified` AS `hasInvoiceSimplified`,`c`.`Id_Trabajador` AS `salesPersonFk`,`c`.`vies` AS `isVies`,`c`.`EYPBC` AS `eypbc`,`c`.`activo` AS `active`,`c`.`RE` AS `equalizationTax`,`c`.`mail` AS `invoiceByEmail`,`c`.`pay_met_id` AS `payMethodFk`,`c`.`vies` AS `vies`,`c`.`invoiceByAddress` AS `hasToInvoiceByAddress`,`c`.`clientes_tipo_id` AS `typeFk`,`c`.`created` AS `created`,`c`.`province_id` AS `province`,`c`.`congelado` AS `Congelado`,`c`.`Id_Trabajador` AS `Id_Trabajador`,`c`.`Id_Trabajador` AS `workerFk`,`c`.`cyc` AS `cyc`,`c`.`Id_Pais` AS `Id_Pais`,`c`.`activo` AS `activo`,`c`.`gestdoc_id` AS `gestdoc`,`c`.`calidad` AS `calidad`,`c`.`pay_met_id` AS `paymentMethod`,`c`.`chanel_id` AS `channel`,`c`.`chanel_id` AS `channelFk`,`c`.`clientes_tipo_id` AS `clientes_tipo_id`,`c`.`postcode_id` AS `postcode_id`,`c`.`codpos` AS `codpos`,`c`.`domicilio` AS `postalAddress`,`c`.`sepaVnl` AS `sepavnl`,`c`.`coreVnl` AS `corevnl`,`c`.`coreVnh` AS `corevnh` from `vn2008`.`Clientes` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `clientType`
+--
+
+/*!50001 DROP VIEW IF EXISTS `clientType`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `clientType` AS select `ct`.`clientes_tipo_id` AS `id`,`ct`.`code` AS `code`,`ct`.`tipo` AS `type` from `vn2008`.`clientes_tipo` `ct` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `clientkk`
+--
+
+/*!50001 DROP VIEW IF EXISTS `clientkk`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `clientkk` AS select `c`.`id_cliente` AS `id`,`c`.`cliente` AS `name`,`c`.`if` AS `fi`,`c`.`telefono` AS `phone`,`c`.`fax` AS `fax`,`c`.`e-mail` AS `email`,`c`.`cc` AS `iban`,`c`.`vencimiento` AS `dueDay`,`c`.`Cuenta` AS `accountingAccount`,`c`.`RE` AS `isEqualizated`,`c`.`poblacion` AS `city`,`c`.`province_id` AS `province`,`c`.`province_id` AS `provinceFk`,`c`.`codPostal` AS `postcode`,`c`.`razonSocial` AS `socialName`,`c`.`contacto` AS `contact`,`c`.`invoice` AS `hasToInvoice`,`c`.`congelado` AS `Congelado`,`c`.`Id_Trabajador` AS `Id_Trabajador`,`c`.`Id_Trabajador` AS `workerFk`,`c`.`credito` AS `credit`,`c`.`cyc` AS `cyc`,`c`.`Id_Pais` AS `Id_Pais`,`c`.`Id_Pais` AS `countryFk`,`c`.`activo` AS `activo`,`c`.`activo` AS `active`,`c`.`gestdoc_id` AS `gestdoc`,`c`.`gestdoc_id` AS `gestdocFk`,`c`.`calidad` AS `calidad`,`c`.`pay_met_id` AS `paymentMethod`,`c`.`pay_met_id` AS `paymentMethodFk`,`c`.`created` AS `registerDate`,`c`.`mail` AS `invoiceByEmail`,`c`.`mail` AS `isToBeMailed`,`c`.`chanel_id` AS `channel`,`c`.`chanel_id` AS `channelFk`,`c`.`vies` AS `VIES`,`c`.`sepaVnl` AS `sepavnl`,`c`.`coreVnl` AS `corevnl`,`c`.`risk_calculated` AS `riskCalculated`,`c`.`coreVnh` AS `corevnh`,`c`.`clientes_tipo_id` AS `clientes_tipo_id`,`c`.`clientes_tipo_id` AS `clientTypeFk`,`c`.`postcode_id` AS `postcode_id`,`c`.`postcode_id` AS `postcodeFk`,`c`.`mail_address` AS `mail_address`,`c`.`codpos` AS `codpos`,`c`.`cplusTerIdNifFk` AS `cplusTerIdNifFk`,`c`.`domicilio` AS `postalAddress`,`c`.`invoiceByAddress` AS `invoiceByAddress`,`c`.`contabilizado` AS `isTaxDataChecked`,`c`.`congelado` AS `isFreezed`,`c`.`creditInsurance` AS `creditInsurance`,`c`.`isCreatedAsServed` AS `isCreatedAsServed`,`c`.`hasInvoiceSimplified` AS `hasInvoiceSimplified` from `vn2008`.`Clientes` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `color`
+--
+
+/*!50001 DROP VIEW IF EXISTS `color`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `color` AS select `c`.`Id_Color` AS `id`,`c`.`Color` AS `name` from `vn2008`.`Colores` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `company`
+--
+
+/*!50001 DROP VIEW IF EXISTS `company`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `company` AS select `e`.`id` AS `id`,`e`.`abbreviation` AS `code`,`e`.`Id_Proveedores_account` AS `supplierAccountFk` from `vn2008`.`empresa` `e` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `comparative`
+--
+
+/*!50001 DROP VIEW IF EXISTS `comparative`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `comparative` AS select `c`.`Periodo` AS `timePeriod`,`c`.`Id_Article` AS `itemFk`,`c`.`warehouse_id` AS `warehouseFk`,`c`.`Cantidad` AS `quantity`,`c`.`price` AS `price` from `vn2008`.`Comparativa` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `comparativeFilter`
+--
+
+/*!50001 DROP VIEW IF EXISTS `comparativeFilter`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `comparativeFilter` AS select `f`.`id` AS `id`,`f`.`name` AS `name`,`f`.`sql` AS `whereSql` from `vn2008`.`filtros` `f` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `country`
+--
+
+/*!50001 DROP VIEW IF EXISTS `country`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `country` AS select `p`.`Id` AS `id`,`p`.`Pais` AS `country`,`p`.`CEE` AS `CEE`,if((`p`.`CEE` < 2),1,0) AS `isUeeMember`,`p`.`Codigo` AS `Code`,`p`.`Id_Moneda` AS `currencyFk`,`p`.`Id_Paisreal` AS `politicalCountryFk`,`p`.`geoFk` AS `geoFk` from `vn2008`.`Paises` `p` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `deliveryMethod`
+--
+
+/*!50001 DROP VIEW IF EXISTS `deliveryMethod`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `deliveryMethod` AS select `d`.`vista_id` AS `id`,`d`.`code` AS `code`,`d`.`vista` AS `description` from `vn2008`.`Vistas` `d` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ediGenus`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ediGenus`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ediGenus` AS select `g`.`genus_id` AS `id`,`g`.`latin_genus_name` AS `latinGenusName`,`g`.`entry_date` AS `entried`,`g`.`expiry_date` AS `dued`,`g`.`change_date_time` AS `modified` from `edi`.`genus` `g` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ediSpecie`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ediSpecie`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ediSpecie` AS select `s`.`specie_id` AS `id`,`s`.`genus_id` AS `genusFk`,`s`.`latin_species_name` AS `latinSpeciesName`,`s`.`entry_date` AS `entried`,`s`.`expiry_date` AS `dued`,`s`.`change_date_time` AS `modified` from `edi`.`specie` `s` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `entry`
+--
+
+/*!50001 DROP VIEW IF EXISTS `entry`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `entry` AS select `e`.`Id_Entrada` AS `id`,`e`.`Id_Proveedor` AS `supplierFk`,`e`.`Referencia` AS `ref`,`e`.`Inventario` AS `isInventory`,`e`.`Confirmada` AS `isConfirmed`,`e`.`Pedida` AS `isOrdered`,`e`.`Redada` AS `isRaid`,`e`.`comision` AS `commission`,`e`.`odbc_date` AS `created`,`e`.`Notas_Eva` AS `evaNotes`,`e`.`travel_id` AS `travelFk`,`e`.`Id_Moneda` AS `currencyFk`,`e`.`empresa_id` AS `companyFk`,`e`.`gestdoc_id` AS `gestDocFk`,`e`.`recibida_id` AS `invoiceReceivedFk` from `vn2008`.`Entradas` `e` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `especialPrice`
+--
+
+/*!50001 DROP VIEW IF EXISTS `especialPrice`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `especialPrice` AS select `p`.`Id_PrecioEspecial` AS `id`,`p`.`Id_Cliente` AS `clientFk`,`p`.`Id_Article` AS `itemFk`,`p`.`PrecioEspecial` AS `value` from `vn2008`.`PreciosEspeciales` `p` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `expedition`
+--
+
+/*!50001 DROP VIEW IF EXISTS `expedition`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `expedition` AS select `e`.`expeditions_id` AS `id`,`e`.`agency_id` AS `agency`,`e`.`agency_id` AS `agencyFk`,`e`.`ticket_id` AS `ticket`,`e`.`ticket_id` AS `ticketFk`,`e`.`EsBulto` AS `isBox`,`e`.`odbc_date` AS `printingTime`,`e`.`Id_Article` AS `item`,`e`.`Id_Article` AS `itemFk`,`e`.`counter` AS `counter`,`e`.`checked` AS `checked`,`e`.`workerFk` AS `workerFk` from `vn2008`.`expeditions` `e` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `expence`
+--
+
+/*!50001 DROP VIEW IF EXISTS `expence`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `expence` AS select `g`.`Id_Gasto` AS `id`,`g`.`iva_tipo_id` AS `taxTypeFk`,`g`.`Gasto` AS `name`,`g`.`isWithheld` AS `isWithheld` from `vn2008`.`Gastos` `g` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `grant`
+--
+
+/*!50001 DROP VIEW IF EXISTS `grant`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `grant` AS select `vn2008`.`Permisos`.`Id_Grupo` AS `group`,`vn2008`.`Permisos`.`Id_Trabajador` AS `worker`,`vn2008`.`Permisos`.`empresa_id` AS `company` from `vn2008`.`Permisos` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `grantGroup`
+--
+
+/*!50001 DROP VIEW IF EXISTS `grantGroup`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `grantGroup` AS select `vn2008`.`Grupos`.`id` AS `id`,`vn2008`.`Grupos`.`Grupo` AS `description`,`vn2008`.`Grupos`.`observation_type_id` AS `observationType` from `vn2008`.`Grupos` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `greuge`
+--
+
+/*!50001 DROP VIEW IF EXISTS `greuge`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `greuge` AS select `g`.`Id` AS `id`,`g`.`Id_Cliente` AS `clientFk`,`g`.`Comentario` AS `description`,`g`.`Importe` AS `amount`,`g`.`Fecha` AS `shipped`,`g`.`odbc_date` AS `created`,`g`.`Greuges_type_id` AS `greugeTypeFk`,`g`.`Id_Ticket` AS `ticketFk` from `vn2008`.`Greuges` `g` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `greugeType`
+--
+
+/*!50001 DROP VIEW IF EXISTS `greugeType`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `greugeType` AS select `gt`.`Greuges_type_id` AS `id`,`gt`.`name` AS `name` from `vn2008`.`Greuges_type` `gt` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ink`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ink`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ink` AS select `c`.`Id_Tinta` AS `id`,`c`.`name` AS `name`,`c`.`Tinta` AS `picture`,`c`.`Orden` AS `showOrder` from `vn2008`.`Tintas` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `inkL10n`
+--
+
+/*!50001 DROP VIEW IF EXISTS `inkL10n`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `inkL10n` AS select `k`.`id` AS `id`,ifnull(`i`.`name`,`k`.`name`) AS `name` from (`vn`.`ink` `k` left join `vn`.`inkI18n` `i` on(((`i`.`inkFk` = `k`.`id`) and (`i`.`lang` = `util`.`lang`())))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `intrastat`
+--
+
+/*!50001 DROP VIEW IF EXISTS `intrastat`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `intrastat` AS select `i`.`Codintrastat` AS `id`,`i`.`Definicion` AS `description`,`i`.`iva_group_id` AS `taxGroupFk`,`i`.`iva_codigo_id` AS `taxCodeFk` from `vn2008`.`Intrastat` `i` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `invoiceCorrection`
+--
+
+/*!50001 DROP VIEW IF EXISTS `invoiceCorrection`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `invoiceCorrection` AS select `ic`.`correctingFk` AS `correctingFk`,`ic`.`correctedFk` AS `correctedFk`,`ic`.`cplusRectificationTypeFk` AS `cplusRectificationTypeFk`,`ic`.`cplusInvoiceType477Fk` AS `cplusInvoiceType477Fk`,`ic`.`invoiceCorrectionTypeFk` AS `invoiceCorrectionTypeFk` from `vn2008`.`invoiceCorrection` `ic` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `invoiceCorrectionDataSource`
+--
+
+/*!50001 DROP VIEW IF EXISTS `invoiceCorrectionDataSource`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `invoiceCorrectionDataSource` AS select `s`.`itemFk` AS `itemFk`,`s`.`quantity` AS `quantity`,`s`.`concept` AS `concept`,`s`.`price` AS `price`,`s`.`discount` AS `discount`,`t`.`refFk` AS `refFk`,`s`.`id` AS `saleFk`,`t`.`shipped` AS `shipped` from (`vn`.`sale` `s` join `vn`.`ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `invoiceIn`
+--
+
+/*!50001 DROP VIEW IF EXISTS `invoiceIn`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `invoiceIn` AS select `r`.`id` AS `id`,`r`.`num_recibida` AS `serialNumber`,`r`.`serie` AS `serial`,`r`.`proveedor_id` AS `supplierFk`,`r`.`fecha` AS `issued`,`r`.`sref` AS `supplierRef`,`r`.`contabilizada` AS `isBooked`,`r`.`moneda_id` AS `currencyFk`,`r`.`MYSQL_TIME` AS `created`,`r`.`empresa_id` AS `companyFk`,`r`.`gestdoc_id` AS `docFk`,`r`.`dateBooking` AS `booked`,`r`.`dateOperation` AS `operated`,`r`.`cplusInvoiceType472Fk` AS `cplusInvoiceType472Fk`,`r`.`cplusRectificationTypeFk` AS `cplusRectificationTypeFk`,`r`.`cplusSubjectOpFk` AS `cplusSubjectOpFk`,`r`.`cplusTaxBreakFk` AS `cplusTaxBreakFk`,`r`.`cplusTrascendency472Fk` AS `cplusTrascendency472Fk`,`r`.`bookEntried` AS `bookEntried` from `vn2008`.`recibida` `r` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `invoiceInAwb`
+--
+
+/*!50001 DROP VIEW IF EXISTS `invoiceInAwb`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `invoiceInAwb` AS select `a`.`recibida_id` AS `invoiceInFk`,`a`.`awb_id` AS `awbFk`,`a`.`dua` AS `dua` from `vn2008`.`awb_recibida` `a` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `invoiceInEntry`
+--
+
+/*!50001 DROP VIEW IF EXISTS `invoiceInEntry`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `invoiceInEntry` AS select `i`.`recibida_entrada_id` AS `id`,`i`.`recibida_id` AS `invoiceInFk`,`i`.`Id_Entrada` AS `entryFk`,`i`.`percentage` AS `percentage`,`i`.`awb_recibida` AS `invoiceInAwbFk`,`i`.`Contabilizado` AS `isBooked` from `vn2008`.`recibida_entrada` `i` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `invoiceInIntrastat`
+--
+
+/*!50001 DROP VIEW IF EXISTS `invoiceInIntrastat`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `invoiceInIntrastat` AS select `r`.`recibida_id` AS `invoiceInFk`,`r`.`Codintrastat` AS `intrastatFk`,`r`.`importe` AS `amount` from `vn2008`.`recibida_intrastat` `r` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `invoiceInTax`
+--
+
+/*!50001 DROP VIEW IF EXISTS `invoiceInTax`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `invoiceInTax` AS select `r`.`id` AS `id`,`r`.`recibida_id` AS `invoiceInFk`,`r`.`iva_id` AS `taxCodeFk`,`r`.`bi` AS `taxableBase`,`r`.`gastos_id` AS `expenceFk`,`r`.`divisa` AS `foreignValue`,`r`.`MYSQL_TIME` AS `created` from `vn2008`.`recibida_iva` `r` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `invoiceOut`
+--
+
+/*!50001 DROP VIEW IF EXISTS `invoiceOut`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `invoiceOut` AS select `f`.`factura_id` AS `id`,`f`.`Id_Factura` AS `ref`,`f`.`Serie` AS `serial`,`f`.`Fecha` AS `issued`,`f`.`Importe` AS `amount`,`f`.`Id_Cliente` AS `clientFk`,`f`.`odbc_date` AS `created`,`f`.`empresa_id` AS `companyFk`,`f`.`Vencimiento` AS `dued`,`f`.`booked` AS `booked`,`f`.`cplusInvoiceType477Fk` AS `cplusInvoiceType477Fk`,`f`.`cplusTaxBreakFk` AS `cplusTaxBreakFk`,`f`.`cplusSubjectOpFk` AS `cplusSubjectOpFk`,`f`.`cplusTrascendency477Fk` AS `cplusTrascendency477Fk`,`f`.`pdf` AS `pdf` from `vn2008`.`Facturas` `f` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `item`
+--
+
+/*!50001 DROP VIEW IF EXISTS `item`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `item` AS select `t`.`Id_Article` AS `id`,`t`.`Article` AS `name`,`t`.`tipo_id` AS `typeFk`,`t`.`Medida` AS `size`,`t`.`Color` AS `inkFk`,`t`.`Categoria` AS `category`,`t`.`Tallos` AS `stems`,`t`.`id_origen` AS `originFk`,`t`.`description` AS `description`,`t`.`producer_id` AS `producerFk`,`t`.`Codintrastat` AS `intrastatFk`,`t`.`offer` AS `isOnOffer`,`t`.`expenceFk` AS `expenceFk`,`t`.`bargain` AS `isBargain`,`t`.`comments` AS `comment`,`t`.`relevancy` AS `relevancy`,`t`.`Foto` AS `image`,`t`.`iva_group_id` AS `taxClassFk` from `vn2008`.`Articles` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `itemBarcode`
+--
+
+/*!50001 DROP VIEW IF EXISTS `itemBarcode`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `itemBarcode` AS select `vn2008`.`barcodes`.`id` AS `id`,`vn2008`.`barcodes`.`Id_Article` AS `itemFk`,`vn2008`.`barcodes`.`code` AS `code` from `vn2008`.`barcodes` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `itemBotanical`
+--
+
+/*!50001 DROP VIEW IF EXISTS `itemBotanical`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `itemBotanical` AS select `ab`.`Id_Article` AS `itemFk`,`ab`.`botanical` AS `botanical`,`ab`.`genus_id` AS `genusFk`,`ab`.`specie_id` AS `specieFk` from `vn2008`.`Articles_botanical` `ab` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `itemBotanicalWithGenus`
+--
+
+/*!50001 DROP VIEW IF EXISTS `itemBotanicalWithGenus`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `itemBotanicalWithGenus` AS select `ib`.`itemFk` AS `itemFk`,ifnull(`ib`.`botanical`,concat(`g`.`latinGenusName`,' ',ifnull(`s`.`latinSpeciesName`,''))) AS `ediBotanic` from ((`vn`.`itemBotanical` `ib` left join `vn`.`ediGenus` `g` on((`g`.`id` = `ib`.`genusFk`))) left join `vn`.`ediSpecie` `s` on((`s`.`id` = `ib`.`specieFk`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `itemCategory`
+--
+
+/*!50001 DROP VIEW IF EXISTS `itemCategory`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `itemCategory` AS select `r`.`id` AS `id`,`r`.`reino` AS `name`,`r`.`display` AS `display`,`r`.`color` AS `color` from `vn2008`.`reinos` `r` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `itemCategoryL10n`
+--
+
+/*!50001 DROP VIEW IF EXISTS `itemCategoryL10n`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `itemCategoryL10n` AS select `c`.`id` AS `id`,ifnull(`i`.`name`,`c`.`name`) AS `name` from (`vn`.`itemCategory` `c` left join `vn`.`itemCategoryI18n` `i` on(((`i`.`categoryFk` = `c`.`id`) and (`i`.`lang` = `util`.`lang`())))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `itemPlacement`
+--
+
+/*!50001 DROP VIEW IF EXISTS `itemPlacement`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `itemPlacement` AS select `an`.`Id_Article` AS `itemFk`,`an`.`warehouse_id` AS `warehouseFk`,`an`.`nicho` AS `code` from `vn2008`.`Articles_nicho` `an` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `itemTagged`
+--
+
+/*!50001 DROP VIEW IF EXISTS `itemTagged`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `itemTagged` AS select distinct `itemTag`.`itemFk` AS `itemFk` from `itemTag` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `itemType`
+--
+
+/*!50001 DROP VIEW IF EXISTS `itemType`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `itemType` AS select `t`.`tipo_id` AS `id`,`t`.`Tipo` AS `name`,`t`.`reino_id` AS `categoryFk`,`t`.`life` AS `life`,`t`.`Id_Trabajador` AS `workerFk` from `vn2008`.`Tipos` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `itemTypeL10n`
+--
+
+/*!50001 DROP VIEW IF EXISTS `itemTypeL10n`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `itemTypeL10n` AS select `t`.`id` AS `id`,ifnull(`i`.`name`,`t`.`name`) AS `name` from (`vn`.`itemType` `t` left join `vn`.`itemTypeI18n` `i` on(((`i`.`typeFk` = `t`.`id`) and (`i`.`lang` = `util`.`LANG`())))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `mail`
+--
+
+/*!50001 DROP VIEW IF EXISTS `mail`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `mail` AS select `vn2008`.`mail`.`id` AS `id`,`vn2008`.`mail`.`senderFk` AS `senderFk`,`vn2008`.`mail`.`recipientFk` AS `recipientFk`,`vn2008`.`mail`.`to` AS `sender`,`vn2008`.`mail`.`reply_to` AS `replyTo`,`vn2008`.`mail`.`subject` AS `subject`,`vn2008`.`mail`.`text` AS `body`,`vn2008`.`mail`.`plainTextBody` AS `plainTextBody`,`vn2008`.`mail`.`path` AS `attachment`,`vn2008`.`mail`.`DATE_ODBC` AS `creationDate`,`vn2008`.`mail`.`sent` AS `sent`,`vn2008`.`mail`.`error` AS `status` from `vn2008`.`mail` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `manaSpellers`
+--
+
+/*!50001 DROP VIEW IF EXISTS `manaSpellers`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `manaSpellers` AS select `bs`.`mana_spellers`.`Id_Trabajador` AS `worker`,`bs`.`mana_spellers`.`size` AS `size`,`bs`.`mana_spellers`.`used` AS `used`,`bs`.`mana_spellers`.`prices_modifier_rate` AS `pricesModifierRate`,`bs`.`mana_spellers`.`prices_modifier_activated` AS `pricesModifierActivated`,`vn2008`.`Trabajadores`.`CodigoTrabajador` AS `workerCode`,`vn2008`.`Trabajadores`.`Nombre` AS `firstname`,`vn2008`.`Trabajadores`.`Apellidos` AS `name` from (`bs`.`mana_spellers` join `vn2008`.`Trabajadores` on((`bs`.`mana_spellers`.`Id_Trabajador` = `vn2008`.`Trabajadores`.`Id_Trabajador`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `mandate`
+--
+
+/*!50001 DROP VIEW IF EXISTS `mandate`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `mandate` AS select `m`.`id` AS `id`,`m`.`Id_Cliente` AS `clientFk`,`m`.`empresa_id` AS `companyFk`,`m`.`Id_mandato` AS `code`,`m`.`FAlta` AS `created`,`m`.`Fbaja` AS `finished`,`m`.`idmandato_tipo` AS `mandateTypeFk` from `vn2008`.`mandato` `m` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `mandateType`
+--
+
+/*!50001 DROP VIEW IF EXISTS `mandateType`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `mandateType` AS select `m`.`idmandato_tipo` AS `id`,`m`.`Nombre` AS `name` from `vn2008`.`mandato_tipo` `m` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `movement`
+--
+
+/*!50001 DROP VIEW IF EXISTS `movement`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `movement` AS select `m`.`Id_Movimiento` AS `id`,`m`.`Id_Article` AS `item`,`m`.`Id_Ticket` AS `ticket`,`m`.`Concepte` AS `concept`,`m`.`Cantidad` AS `amount`,`m`.`quantity` AS `quantity`,`m`.`Preu` AS `price`,`m`.`Descuento` AS `discount`,`m`.`CostFixat` AS `cost`,`m`.`Reservado` AS `reservado`,`m`.`OK` AS `od`,`m`.`PrecioFijado` AS `priceFixed`,`m`.`odbc_date` AS `lastUpdate` from `vn2008`.`Movimientos` `m` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `observationType`
+--
+
+/*!50001 DROP VIEW IF EXISTS `observationType`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `observationType` AS select `ot`.`observation_type_id` AS `id`,`ot`.`description` AS `description` from `vn2008`.`observation_type` `ot` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `origin`
+--
+
+/*!50001 DROP VIEW IF EXISTS `origin`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `origin` AS select `o`.`id` AS `id`,`o`.`Abreviatura` AS `code`,`o`.`Origen` AS `name` from `vn2008`.`Origen` `o` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `originL10n`
+--
+
+/*!50001 DROP VIEW IF EXISTS `originL10n`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `originL10n` AS select `o`.`id` AS `id`,ifnull(`i`.`name`,`o`.`name`) AS `name` from (`vn`.`origin` `o` left join `vn`.`originI18n` `i` on(((`i`.`originFk` = `o`.`id`) and (`i`.`lang` = `util`.`lang`())))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `outgoingInvoice`
+--
+
+/*!50001 DROP VIEW IF EXISTS `outgoingInvoice`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `outgoingInvoice` AS select `vn2008`.`Facturas`.`Id_Factura` AS `id`,`vn2008`.`Facturas`.`Serie` AS `serie`,`vn2008`.`Facturas`.`Fecha` AS `dateInvoice`,`vn2008`.`Facturas`.`Importe` AS `total`,`vn2008`.`Facturas`.`Vencimiento` AS `dueDate`,`vn2008`.`Facturas`.`Id_Banco` AS `bank`,`vn2008`.`Facturas`.`Id_Cliente` AS `client`,`vn2008`.`Facturas`.`Id_Remesa` AS `remittance`,`vn2008`.`Facturas`.`Remesar` AS `remit`,`vn2008`.`Facturas`.`Id_Trabajador` AS `worker`,`vn2008`.`Facturas`.`odbc_date` AS `creationDate`,`vn2008`.`Facturas`.`empresa_id` AS `company`,`vn2008`.`Facturas`.`liquidacion` AS `liquidacion?`,`vn2008`.`Facturas`.`pdf` AS `isPdf` from `vn2008`.`Facturas` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `package`
+--
+
+/*!50001 DROP VIEW IF EXISTS `package`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `package` AS select `c`.`Id_Cubo` AS `id`,`c`.`Volumen` AS `volume`,`c`.`X` AS `width`,`c`.`Y` AS `height`,`c`.`Z` AS `depth`,`c`.`Retornable` AS `isPackageReturnable`,`c`.`odbc_date` AS `created`,`c`.`item_id` AS `itemFk` from `vn2008`.`Cubos` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `payMethod`
+--
+
+/*!50001 DROP VIEW IF EXISTS `payMethod`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `payMethod` AS select `pm`.`id` AS `id`,`pm`.`name` AS `name` from `vn2008`.`pay_met` `pm` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `plantpassport`
+--
+
+/*!50001 DROP VIEW IF EXISTS `plantpassport`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `plantpassport` AS select `pp`.`producer_id` AS `producerFk`,`pp`.`plantpassport_authority_id` AS `plantpassportAuthorityFk`,`pp`.`number` AS `number` from `vn2008`.`plantpassport` `pp` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `plantpassportAuthority`
+--
+
+/*!50001 DROP VIEW IF EXISTS `plantpassportAuthority`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `plantpassportAuthority` AS select `ppa`.`plantpassport_authority_id` AS `id`,`ppa`.`denomination` AS `denomination`,`ppa`.`Paises_Id` AS `countryFk` from `vn2008`.`plantpassport_authority` `ppa` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `priceFixed`
+--
+
+/*!50001 DROP VIEW IF EXISTS `priceFixed`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `priceFixed` AS select `p`.`item_id` AS `itemFk`,`p`.`rate_0` AS `rate0`,`p`.`rate_1` AS `rate1`,`p`.`rate_2` AS `rate2`,`p`.`rate_3` AS `rate3`,`p`.`date_start` AS `started`,`p`.`date_end` AS `ended`,`p`.`bonus` AS `bonus`,`p`.`warehouse_id` AS `warehouseFk`,`p`.`odbc_date` AS `created`,`p`.`price_fixed_id` AS `id`,`p`.`grouping` AS `grouping`,`p`.`Packing` AS `packing`,`p`.`caja` AS `box` from `vn2008`.`price_fixed` `p` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `printServerQueue`
+--
+
+/*!50001 DROP VIEW IF EXISTS `printServerQueue`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `printServerQueue` AS select `c`.`Id_Cola` AS `id`,`c`.`Id_Impresora` AS `printerFk`,`c`.`Id_Prioridad` AS `priorityFk`,`c`.`Id_Informe` AS `reportFk`,`c`.`Id_Estado` AS `statusFk`,`c`.`Hora_Inicio` AS `started`,`c`.`Hora_Fin` AS `finished`,`c`.`Cola` AS `param1`,`c`.`Id_Trabajador` AS `workerFk`,`c`.`Cola2` AS `param2`,`c`.`Cola3` AS `param3`,`c`.`error` AS `error` from `vn2008`.`Colas` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `printingQueue`
+--
+
+/*!50001 DROP VIEW IF EXISTS `printingQueue`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `printingQueue` AS select `c`.`Id_Cola` AS `id`,`c`.`Id_Impresora` AS `printer`,`c`.`Id_Prioridad` AS `priority`,`c`.`Id_Informe` AS `report`,`c`.`Id_Estado` AS `state`,`c`.`Hora_Inicio` AS `startingTime`,`c`.`Hora_Fin` AS `endingTime`,`c`.`Cola` AS `text`,`c`.`Id_Trabajador` AS `worker`,`c`.`Cola2` AS `text2`,`c`.`Cola3` AS `text3` from `vn2008`.`Colas` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `producer`
+--
+
+/*!50001 DROP VIEW IF EXISTS `producer`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `producer` AS select `p`.`producer_id` AS `id`,`p`.`name` AS `name` from `vn2008`.`producer` `p` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `province`
+--
+
+/*!50001 DROP VIEW IF EXISTS `province`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `province` AS select `t`.`province_id` AS `id`,`t`.`name` AS `name`,`t`.`Paises_Id` AS `countryFk`,`t`.`geoFk` AS `geoFk` from `vn2008`.`province` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `receipt`
+--
+
+/*!50001 DROP VIEW IF EXISTS `receipt`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `receipt` AS select `t`.`Id` AS `Id`,`t`.`Id_Factura` AS `invoiceFk`,`t`.`Entregado` AS `amountPaid`,`t`.`Pendiente` AS `amountUnpaid`,`t`.`Fechacobro` AS `payed`,`t`.`Id_Trabajador` AS `workerFk`,`t`.`Id_Banco` AS `bankFk`,`t`.`Id_Cliente` AS `clientFk`,`t`.`odbc_date` AS `created`,`t`.`empresa_id` AS `companyFk`,`t`.`conciliado` AS `isConciliate` from `vn2008`.`Recibos` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `referenceRate`
+--
+
+/*!50001 DROP VIEW IF EXISTS `referenceRate`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `referenceRate` AS select `r`.`moneda_id` AS `currencyFk`,`r`.`date` AS `dated`,`r`.`rate` AS `value` from `vn2008`.`reference_rate` `r` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `role`
+--
+
+/*!50001 DROP VIEW IF EXISTS `role`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `role` AS select `account`.`role`.`id` AS `id`,`account`.`role`.`name` AS `name`,`account`.`role`.`description` AS `description`,`account`.`role`.`hasLogin` AS `hasLogin` from `account`.`role` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `route`
+--
+
+/*!50001 DROP VIEW IF EXISTS `route`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `route` AS select `a`.`Id_Ruta` AS `id`,`a`.`Id_Trabajador` AS `workerFk`,`a`.`Fecha` AS `created`,`a`.`Id_Vehiculo` AS `vehicleFk`,`a`.`Id_Agencia` AS `agencyFk`,`a`.`Id_Agencia` AS `agencyModeFk`,`a`.`Hora` AS `time`,`a`.`ok` AS `isOk`,`a`.`km_start` AS `kmStart`,`a`.`km_end` AS `kmEnd`,`a`.`date_start` AS `started`,`a`.`date_end` AS `finished`,`a`.`gestdoc_id` AS `gestdocFk`,`a`.`cost` AS `cost`,`a`.`m3` AS `m3` from `vn2008`.`Rutas` `a` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `sale`
+--
+
+/*!50001 DROP VIEW IF EXISTS `sale`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `sale` AS select `m`.`Id_Movimiento` AS `id`,`m`.`Id_Article` AS `itemFk`,`m`.`Id_Ticket` AS `ticketFk`,`m`.`Concepte` AS `concept`,`m`.`Cantidad` AS `quantity`,`m`.`Preu` AS `price`,`m`.`Descuento` AS `discount`,`m`.`Reservado` AS `reserved`,`m`.`OK` AS `isPicked`,`m`.`odbc_date` AS `created` from `vn2008`.`Movimientos` `m` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `saleComponent`
+--
+
+/*!50001 DROP VIEW IF EXISTS `saleComponent`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `saleComponent` AS select `mc`.`Id_Movimiento` AS `saleFk`,`mc`.`Id_Componente` AS `componentFk`,`mc`.`Valor` AS `value` from `vn2008`.`Movimientos_componentes` `mc` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `state`
+--
+
+/*!50001 DROP VIEW IF EXISTS `state`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `state` AS select `s`.`id` AS `id`,`s`.`name` AS `name`,`s`.`order` AS `order`,`s`.`alert_level` AS `alertLevel`,`s`.`code` AS `code` from `vn2008`.`state` `s` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `supplier`
+--
+
+/*!50001 DROP VIEW IF EXISTS `supplier`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `supplier` AS select `p`.`Id_Proveedor` AS `id`,`p`.`Proveedor` AS `name`,`p`.`cuenta` AS `account`,`p`.`pais_id` AS `countryFk`,`p`.`NIF` AS `nif`,`p`.`Agricola` AS `isFarmer`,`p`.`cuentaret` AS `retAccount`,`p`.`ComisionProveedor` AS `commission`,`p`.`odbc_time` AS `created`,`p`.`postcode_id` AS `postcodeFk`,`p`.`active` AS `isActive`,`p`.`Domicilio` AS `street`,`p`.`Localidad` AS `city`,`p`.`province_id` AS `provinceFk`,`p`.`codpos` AS `postCode` from `vn2008`.`Proveedores` `p` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `supplierAccount`
+--
+
+/*!50001 DROP VIEW IF EXISTS `supplierAccount`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `supplierAccount` AS select `pa`.`Id_Proveedores_account` AS `id`,`pa`.`IBAN` AS `iban`,`pa`.`entity_id` AS `bankEntityFk` from `vn2008`.`Proveedores_account` `pa` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `tagL10n`
+--
+
+/*!50001 DROP VIEW IF EXISTS `tagL10n`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `tagL10n` AS select `t`.`id` AS `id`,ifnull(`i`.`name`,`t`.`name`) AS `name` from (`tag` `t` left join `tagI18n` `i` on(((`i`.`tagFk` = `t`.`id`) and (`i`.`lang` = `util`.`LANG`())))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `taxClass`
+--
+
+/*!50001 DROP VIEW IF EXISTS `taxClass`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `taxClass` AS select `c`.`iva_group_id` AS `id`,`c`.`description` AS `description`,`c`.`code` AS `code` from `vn2008`.`iva_group` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `taxClassCode`
+--
+
+/*!50001 DROP VIEW IF EXISTS `taxClassCode`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `taxClassCode` AS select `c`.`iva_group_id` AS `taxClassFk`,`c`.`date` AS `effectived`,`c`.`iva_codigo_id` AS `taxCodeFk` from `vn2008`.`iva_group_codigo` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `taxCode`
+--
+
+/*!50001 DROP VIEW IF EXISTS `taxCode`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `taxCode` AS select `ic`.`id` AS `id`,`ic`.`fecha` AS `dated`,`ic`.`codigo` AS `code`,`ic`.`iva_tipo_id` AS `taxTypeFk`,`ic`.`iva` AS `rate`,`ic`.`recargo` AS `equalizationTax`,`ic`.`tipo` AS `type`,`ic`.`link` AS `linkFk`,`ic`.`isActive` AS `isActive` from `vn2008`.`iva_codigo` `ic` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `taxType`
+--
+
+/*!50001 DROP VIEW IF EXISTS `taxType`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `taxType` AS select `t`.`id` AS `id`,`t`.`alias` AS `nickname`,`t`.`serie_id` AS `serial`,`t`.`TIPOOPE` AS `TIPOOPE`,`t`.`descripcion` AS `description`,`t`.`Id_Pais` AS `countryFk` from `vn2008`.`iva_tipo` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ticket`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ticket`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ticket` AS select `t`.`Id_Ticket` AS `id`,`t`.`Id_Cliente` AS `clientFk`,`t`.`warehouse_id` AS `warehouseFk`,`t`.`Fecha` AS `shipped`,`t`.`landing` AS `landed`,`t`.`Alias` AS `nickname`,`t`.`Factura` AS `refFk`,`t`.`Id_Consigna` AS `addressFk`,`t`.`Firmado` AS `isSigned`,`t`.`Localizacion` AS `location`,`t`.`blocked` AS `blocked`,`t`.`Solucion` AS `solution`,`t`.`Id_Ruta` AS `path`,`t`.`Id_Ruta` AS `routeFk`,`t`.`empresa_id` AS `company`,`t`.`empresa_id` AS `companyFk`,`t`.`Id_Agencia` AS `agencyModeFk`,`t`.`Prioridad` AS `loadingOrder`,`t`.`odbc_date` AS `created`,`t`.`Fecha` AS `shipment`,`t`.`landing` AS `landing`,`t`.`Id_Cliente` AS `customer`,`t`.`warehouse_id` AS `warehouse`,`t`.`Id_Cliente` AS `client`,`t`.`Id_Consigna` AS `address`,`t`.`Id_Agencia` AS `agencyMode`,`t`.`Firmado` AS `signed`,`t`.`Bultos` AS `package`,`t`.`odbc_date` AS `creationDate` from `vn2008`.`Tickets` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ticketObservation`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ticketObservation`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ticketObservation` AS select `to`.`ticket_observation_id` AS `id`,`to`.`Id_Ticket` AS `ticketFk`,`to`.`observation_type_id` AS `observationTypeFk`,`to`.`text` AS `description` from `vn2008`.`ticket_observation` `to` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ticketState`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ticketState`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ticketState` AS select `ts`.`Id_Ticket` AS `ticketFk`,`ts`.`Id_Ticket` AS `ticket`,`s`.`id` AS `state`,`s`.`order` AS `productionOrder`,`s`.`alert_level` AS `alertLevel`,`s`.`code` AS `code`,`i`.`Id_Trabajador` AS `worker`,`i`.`Id_Trabajador` AS `workerFk` from ((`vn2008`.`Tickets_state` `ts` join `vncontrol`.`inter` `i` on((`i`.`inter_id` = `ts`.`inter_id`))) join `vn2008`.`state` `s` on((`s`.`id` = `i`.`state_id`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ticketStateToday`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ticketStateToday`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ticketStateToday` AS select `ts`.`ticket` AS `ticket`,`ts`.`state` AS `state`,`ts`.`productionOrder` AS `productionOrder`,`ts`.`alertLevel` AS `alertLevel`,`ts`.`worker` AS `worker`,`ts`.`code` AS `code` from (`vn`.`ticketState` `ts` join `vn`.`ticket` `t` on((`t`.`id` = `ts`.`ticket`))) where (`t`.`shipment` between curdate() and `midnight`(curdate())) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ticketTracking`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ticketTracking`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ticketTracking` AS select `i`.`inter_id` AS `id`,`i`.`state_id` AS `stateFk`,`i`.`odbc_date` AS `created`,`i`.`Id_Ticket` AS `ticketFk`,`i`.`Id_Trabajador` AS `workerFk` from `vncontrol`.`inter` `i` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `time`
+--
+
+/*!50001 DROP VIEW IF EXISTS `time`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `time` AS select `t`.`date` AS `dated`,`t`.`period` AS `period`,`t`.`month` AS `month`,`t`.`year` AS `year`,`t`.`day` AS `day`,`t`.`week` AS `week` from `vn2008`.`time` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `travel`
+--
+
+/*!50001 DROP VIEW IF EXISTS `travel`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `travel` AS select `t`.`id` AS `id`,`t`.`shipment` AS `shipped`,`t`.`shipment_hour` AS `shipmentHour`,`t`.`landing` AS `landed`,`t`.`landing_hour` AS `landingHour`,`t`.`warehouse_id` AS `warehouseInFk`,`t`.`warehouse_id_out` AS `warehouseOutFk`,`t`.`agency_id` AS `agencyFk`,`t`.`ref` AS `ref`,`t`.`delivered` AS `isDelivered`,`t`.`received` AS `isReceived`,`t`.`m3` AS `m3` from `vn2008`.`travel` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `unary`
+--
+
+/*!50001 DROP VIEW IF EXISTS `unary`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `unary` AS select `a`.`id` AS `id`,`a`.`parent` AS `parent` from `vn2008`.`unary` `a` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `unaryScan`
+--
+
+/*!50001 DROP VIEW IF EXISTS `unaryScan`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `unaryScan` AS select `u`.`unary_id` AS `unaryFk`,`u`.`name` AS `name`,`u`.`odbc_date` AS `created`,`u`.`type` AS `type` from `vn2008`.`unary_scan` `u` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `unaryScanLine`
+--
+
+/*!50001 DROP VIEW IF EXISTS `unaryScanLine`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `unaryScanLine` AS select `u`.`id` AS `id`,`u`.`code` AS `code`,`u`.`odbc_date` AS `created`,`u`.`unary_id` AS `unaryScanFk` from `vn2008`.`unary_scan_line` `u` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `unaryScanLineBuy`
+--
+
+/*!50001 DROP VIEW IF EXISTS `unaryScanLineBuy`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `unaryScanLineBuy` AS select `u`.`scan_line_id` AS `unaryScanLineFk`,`u`.`Id_Article` AS `itemFk` from `vn2008`.`unary_scan_line_buy` `u` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `unaryScanLineExpedition`
+--
+
+/*!50001 DROP VIEW IF EXISTS `unaryScanLineExpedition`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `unaryScanLineExpedition` AS select `u`.`scan_line_id` AS `unaryScanLineFk`,`u`.`expedition_id` AS `expeditionFk` from `vn2008`.`unary_scan_line_expedition` `u` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `user`
+--
+
+/*!50001 DROP VIEW IF EXISTS `user`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `user` AS select `account`.`user`.`id` AS `id`,`account`.`user`.`name` AS `name`,`account`.`user`.`password` AS `password`,`account`.`user`.`role` AS `role`,`account`.`user`.`active` AS `active`,`account`.`user`.`recoverPass` AS `recoverPass`,`account`.`user`.`lastPassChange` AS `lastPassChange` from `account`.`user` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `vehicle`
+--
+
+/*!50001 DROP VIEW IF EXISTS `vehicle`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `vehicle` AS select `v`.`Id_Vehiculo` AS `id`,`v`.`Matricula` AS `numberPlate`,`v`.`Marca` AS `tradeMark`,`v`.`Modelo` AS `model`,`v`.`empresa_id` AS `companyFk`,`v`.`warehouseFk` AS `warehouseFk`,`v`.`description` AS `description`,`v`.`m3` AS `m3`,`v`.`active` AS `isActive` from `vn2008`.`Vehiculos` `v` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `warehouse`
+--
+
+/*!50001 DROP VIEW IF EXISTS `warehouse`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `warehouse` AS select `t`.`id` AS `id`,`t`.`name` AS `name`,`t`.`inventario` AS `isInventory`,`t`.`is_comparative` AS `isComparative`,`t`.`comisionantes` AS `hasComission` from `vn2008`.`warehouse` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `warehouseAlias`
+--
+
+/*!50001 DROP VIEW IF EXISTS `warehouseAlias`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `warehouseAlias` AS select `wa`.`warehouse_alias_id` AS `id`,`wa`.`alias` AS `name` from `vn2008`.`warehouse_alias` `wa` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `worker`
+--
+
+/*!50001 DROP VIEW IF EXISTS `worker`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `worker` AS select `t`.`Id_Trabajador` AS `id`,`t`.`CodigoTrabajador` AS `workerCode`,`t`.`Nombre` AS `firstName`,`t`.`Apellidos` AS `name`,`t`.`user_id` AS `userFk`,`t`.`phone` AS `phone`,`t`.`boss` AS `bossFk` from `vn2008`.`Trabajadores` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `workerTeam`
+--
+
+/*!50001 DROP VIEW IF EXISTS `workerTeam`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `workerTeam` AS select `w`.`team` AS `team`,`w`.`user` AS `user`,`w`.`id` AS `id`,`t`.`Id_Trabajador` AS `Id_Trabajador` from (`vn2008`.`workerTeam` `w` left join `vn2008`.`Trabajadores` `t` on((`t`.`user_id` = `w`.`user`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
+
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
diff --git a/services/db/localDB08OthersViews.sql b/services/db/localDB08OthersViews.sql
new file mode 100644
index 000000000..ba95345a0
--- /dev/null
+++ b/services/db/localDB08OthersViews.sql
@@ -0,0 +1,1236 @@
+-- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64)
+--
+-- Host: db.verdnatura.es Database: cache
+-- ------------------------------------------------------
+-- 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 */;
+
+--
+-- Current Database: `cache`
+--
+
+USE `cache`;
+
+--
+-- Current Database: `vncontrol`
+--
+
+USE `vncontrol`;
+
+--
+-- Current Database: `edi`
+--
+
+USE `edi`;
+
+--
+-- Current Database: `bi`
+--
+
+USE `bi`;
+
+--
+-- Final view structure for view `analisis_grafico_ventas`
+--
+
+/*!50001 DROP VIEW IF EXISTS `analisis_grafico_ventas`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `analisis_grafico_ventas` AS select `analisis_ventas`.`Año` AS `Año`,`analisis_ventas`.`Semana` AS `Semana`,sum(`analisis_ventas`.`Importe`) AS `Importe` from `analisis_ventas` group by `analisis_ventas`.`Año`,`analisis_ventas`.`Semana` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `analisis_ventas_simple`
+--
+
+/*!50001 DROP VIEW IF EXISTS `analisis_ventas_simple`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `analisis_ventas_simple` AS select `analisis_ventas`.`Año` AS `Año`,`analisis_ventas`.`Semana` AS `Semana`,sum(`analisis_ventas`.`Importe`) AS `Importe` from `analisis_ventas` group by `analisis_ventas`.`Año`,`analisis_ventas`.`Semana` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `customerRiskOverdue`
+--
+
+/*!50001 DROP VIEW IF EXISTS `customerRiskOverdue`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `customerRiskOverdue` AS select `cr`.`customer_id` AS `customer_id`,`cr`.`amount` AS `amount`,`cr`.`company_id` AS `company_id` from (((`bi`.`customer_risk` `cr` join `vn2008`.`empresa` `e` on((`e`.`id` = `cr`.`company_id`))) join `vn2008`.`Clientes` `c` on((`cr`.`customer_id` = `c`.`id_cliente`))) join `vn2008`.`pay_met` `pm` on((`pm`.`id` = `c`.`pay_met_id`))) where (`cr`.`amount` and `e`.`morosidad` and `pm`.`deudaviva`) union all select `f`.`Id_Cliente` AS `Id_Cliente`,-(round(`f`.`Importe`,2)) AS `importe`,`f`.`empresa_id` AS `empresa_id` from (((`vn2008`.`Facturas` `f` join `vn2008`.`Clientes` `c` on((`f`.`Id_Cliente` = `c`.`id_cliente`))) join `vn2008`.`empresa` `e` on((`e`.`id` = `f`.`empresa_id`))) join `vn2008`.`pay_met` `pm` on((`pm`.`id` = `c`.`pay_met_id`))) where ((`f`.`Fecha` > (curdate() + interval -(101) day)) and ((`vn2008`.`paymentday`(`f`.`Fecha`,`c`.`vencimiento`) + interval `pm`.`graceDays` day) > curdate()) and (`f`.`Importe` > 0) and `e`.`morosidad` and `pm`.`deudaviva`) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `last_Id_Cubo`
+--
+
+/*!50001 DROP VIEW IF EXISTS `last_Id_Cubo`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `last_Id_Cubo` AS select `C`.`Id_Compra` AS `Id_Compra`,`C`.`Id_Article` AS `Id_Article`,`tr`.`warehouse_id` AS `warehouse_id`,`C`.`Id_Cubo` AS `Id_Cubo`,`C`.`Packing` AS `Packing` from ((`vn2008`.`Compres` `C` join `vn2008`.`Entradas` `E` on((`C`.`Id_Entrada` = `E`.`Id_Entrada`))) join `vn2008`.`travel` `tr` on((`E`.`travel_id` = `tr`.`id`))) where ((`C`.`Id_Cubo` is not null) and (`C`.`Id_Cubo` <> '--') and (`tr`.`landing` > (curdate() - interval 18 month))) order by `C`.`Id_Compra` desc */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_clientes_jerarquia`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_clientes_jerarquia`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_clientes_jerarquia` AS select `c`.`id_cliente` AS `Id_Cliente`,`c`.`cliente` AS `Cliente`,`t`.`CodigoTrabajador` AS `Comercial`,`tj`.`CodigoTrabajador` AS `Jefe` from (((`vn2008`.`Clientes` `c` join `vn2008`.`Trabajadores` `t` on((`t`.`Id_Trabajador` = `c`.`Id_Trabajador`))) join `vn2008`.`jerarquia` on((`vn2008`.`jerarquia`.`worker_id` = `c`.`Id_Trabajador`))) join `vn2008`.`Trabajadores` `tj` on((`tj`.`Id_Trabajador` = `vn2008`.`jerarquia`.`boss_id`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_ventas_contables`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_ventas_contables`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_ventas_contables` AS select `vn2008`.`time`.`year` AS `year`,`vn2008`.`time`.`month` AS `month`,cast(sum((((`m`.`Cantidad` * `m`.`Preu`) * (100 - `m`.`Descuento`)) / 100)) as decimal(10,0)) AS `importe` from (((`vn2008`.`Tickets` `t` join `bi`.`f_tvc` on((`t`.`Id_Ticket` = `bi`.`f_tvc`.`Id_Ticket`))) join `vn2008`.`Movimientos` `m` on((`t`.`Id_Ticket` = `m`.`Id_Ticket`))) join `vn2008`.`time` on((`vn2008`.`time`.`date` = cast(`t`.`Fecha` as date)))) where (`t`.`Fecha` >= '2014-01-01') group by `vn2008`.`time`.`year`,`vn2008`.`time`.`month` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Current Database: `pbx`
+--
+
+USE `pbx`;
+
+--
+-- Final view structure for view `cdrConf`
+--
+
+/*!50001 DROP VIEW IF EXISTS `cdrConf`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `cdrConf` AS select `c`.`call_date` AS `calldate`,`c`.`clid` AS `clid`,`c`.`src` AS `src`,`c`.`dst` AS `dst`,`c`.`dcontext` AS `dcontext`,`c`.`channel` AS `channel`,`c`.`dst_channel` AS `dstchannel`,`c`.`last_app` AS `lastapp`,`c`.`last_data` AS `lastdata`,`c`.`duration` AS `duration`,`c`.`billsec` AS `billsec`,`c`.`disposition` AS `disposition`,`c`.`ama_flags` AS `amaflags`,`c`.`account_code` AS `accountcode`,`c`.`unique_id` AS `uniqueid`,`c`.`user_field` AS `userfield` from `cdr` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `followmeConf`
+--
+
+/*!50001 DROP VIEW IF EXISTS `followmeConf`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `followmeConf` AS select `f`.`extension` AS `name`,`c`.`music` AS `music`,`c`.`context` AS `context`,`c`.`takeCall` AS `takecall`,`c`.`declineCall` AS `declinecall` from (`followme` `f` join `followmeConfig` `c`) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `followmeNumberConf`
+--
+
+/*!50001 DROP VIEW IF EXISTS `followmeNumberConf`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `followmeNumberConf` AS select `f`.`extension` AS `name`,1 AS `ordinal`,`f`.`phone` AS `phonenumber`,`c`.`timeout` AS `timeout` from (`followme` `f` join `followmeConfig` `c`) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `queueConf`
+--
+
+/*!50001 DROP VIEW IF EXISTS `queueConf`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `queueConf` AS select `q`.`name` AS `name`,`c`.`strategy` AS `strategy`,`c`.`timeout` AS `timeout`,`c`.`retry` AS `retry`,`c`.`weight` AS `weight`,`c`.`maxLen` AS `maxlen`,`c`.`ringInUse` AS `ringinuse` from (`queue` `q` join `queueConfig` `c` on((`q`.`config` = `c`.`id`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `queueMemberConf`
+--
+
+/*!50001 DROP VIEW IF EXISTS `queueMemberConf`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `queueMemberConf` AS select `m`.`id` AS `uniqueid`,`m`.`queue` AS `queue_name`,concat('SIP/',`m`.`extension`) AS `interface` from `queueMember` `m` union all select `p`.`id` AS `id`,`p`.`queue` AS `queue`,concat('Local/',`p`.`phone`,'@outgoing') AS `phone` from `queuePhone` `p` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `sipConf`
+--
+
+/*!50001 DROP VIEW IF EXISTS `sipConf`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `sipConf` AS select `s`.`user_id` AS `id`,`s`.`extension` AS `name`,`s`.`secret` AS `secret`,`s`.`caller_id` AS `callerid`,`c`.`host` AS `host`,`c`.`deny` AS `deny`,`c`.`permit` AS `permit`,`c`.`type` AS `type`,`c`.`context` AS `context`,`c`.`incomingLimit` AS `incominglimit`,`c`.`pickupGroup` AS `pickupgroup`,`c`.`careInvite` AS `careinvite`,`r`.`ipAddr` AS `ipaddr`,`r`.`regSeconds` AS `regseconds`,`r`.`port` AS `port`,`r`.`defaultUser` AS `defaultuser`,`r`.`userAgent` AS `useragent`,`r`.`lastMs` AS `lastms`,`r`.`fullContact` AS `fullcontact`,`r`.`regServer` AS `regserver` from ((`sip` `s` left join `sipReg` `r` on((`s`.`user_id` = `r`.`userId`))) join `sipConfig` `c`) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Current Database: `salix`
+--
+
+USE `salix`;
+
+--
+-- Final view structure for view `Account`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Account`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Account` AS select `u`.`id` AS `id`,`u`.`name` AS `name`,`u`.`password` AS `password`,`u`.`role` AS `roleFk`,`u`.`active` AS `active`,`u`.`email` AS `email`,`u`.`created` AS `created`,`u`.`updated` AS `updated` from `account`.`user` `u` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Accounting`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Accounting`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Accounting` AS select `b`.`Id_Banco` AS `id`,`b`.`Banco` AS `bank`,`b`.`Cuenta` AS `account`,`b`.`cash` AS `accountingTypeFk`,`b`.`entity_id` AS `entityFk`,`b`.`activo` AS `isActive` from `vn2008`.`Bancos` `b` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Address`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Address`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Address` AS select `a`.`id_consigna` AS `id`,`a`.`consignatario` AS `consignee`,`a`.`domicilio` AS `street`,`a`.`poblacion` AS `city`,`a`.`codPostal` AS `postcode`,`a`.`province_id` AS `provinceFk`,`a`.`telefono` AS `phone`,`a`.`movil` AS `mobile`,`a`.`active` AS `isEnabled`,`a`.`predeterminada` AS `isDefaultAddress`,`a`.`Id_cliente` AS `clientFk`,`a`.`Id_Agencia` AS `defaultAgencyFk`,`a`.`longitude` AS `longitude`,`a`.`latitude` AS `latitude`,`a`.`isEqualizated` AS `isEqualizated` from `vn2008`.`Consignatarios` `a` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Agency`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Agency`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Agency` AS select `a`.`agency_id` AS `id`,`a`.`name` AS `name`,`a`.`warehouse_id` AS `warehouseFk`,`a`.`por_volumen` AS `isVolumetric`,`a`.`Id_Banco` AS `bankFk`,`a`.`warehouse_alias_id` AS `warehouseAliasFk` from `vn2008`.`agency` `a` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `AgencyMode`
+--
+
+/*!50001 DROP VIEW IF EXISTS `AgencyMode`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `AgencyMode` AS select `a`.`Id_Agencia` AS `id`,`a`.`Agencia` AS `name`,`a`.`description` AS `description`,`a`.`Vista` AS `agencyTypeFk`,`a`.`m3` AS `m3`,`a`.`agency_id` AS `agencyFk`,`a`.`inflacion` AS `inflation`,`a`.`send_mail` AS `sendMailTo`,`a`.`tpv` AS `isForTicket` from `vn2008`.`Agencias` `a` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Bank`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Bank`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Bank` AS select `b`.`Id_Banco` AS `id`,`b`.`Banco` AS `bank`,`b`.`Cuenta` AS `account`,`b`.`cash` AS `cash`,`b`.`entity_id` AS `entityFk`,`b`.`activo` AS `isActive` from `vn2008`.`Bancos` `b` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `City`
+--
+
+/*!50001 DROP VIEW IF EXISTS `City`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `City` AS select `c`.`city_id` AS `id`,`c`.`name` AS `name`,`c`.`province_id` AS `provinceFk` from `vn2008`.`city` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Client`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Client`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Client` AS select `c`.`id_cliente` AS `id`,`c`.`cliente` AS `name`,`c`.`if` AS `fi`,`c`.`razonSocial` AS `socialName`,`c`.`contacto` AS `contact`,`c`.`domicilio` AS `street`,`c`.`poblacion` AS `city`,`c`.`codPostal` AS `postcode`,`c`.`province_id` AS `provinceFk`,`c`.`Id_Pais` AS `countryFk`,`c`.`e-mail` AS `email`,`c`.`telefono` AS `phone`,`c`.`movil` AS `mobile`,`c`.`fax` AS `fax`,`c`.`activo` AS `active`,`c`.`descuento` AS `discount`,`c`.`credito` AS `credit`,`c`.`creditInsurance` AS `creditInsurance`,`c`.`iban` AS `iban`,`c`.`vencimiento` AS `dueDay`,`c`.`RE` AS `equalizationTax`,`c`.`invoice` AS `hasToInvoice`,`c`.`mail` AS `invoiceByEmail`,`c`.`pay_met_id` AS `payMethodFk`,`c`.`Id_Trabajador` AS `salesPersonFk`,`c`.`chanel_id` AS `contactChannelFk`,`c`.`sepaVnl` AS `sepaVnl`,`c`.`coreVnl` AS `coreVnl`,`c`.`coreVnh` AS `coreVnh`,`c`.`EYPBC` AS `eypbc`,`c`.`calidad` AS `quality`,`c`.`vies` AS `vies`,`c`.`real` AS `isRelevant`,`c`.`clientes_tipo_id` AS `typeFk`,`c`.`Cuenta` AS `accountingAccount`,`c`.`created` AS `created`,`c`.`invoiceByAddress` AS `hasToInvoiceByAddress` from `vn2008`.`Clientes` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ClientCredit`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ClientCredit`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ClientCredit` AS select `c`.`id` AS `id`,`c`.`Id_Cliente` AS `clientFk`,`c`.`Id_Trabajador` AS `employeeFk`,`c`.`amount` AS `amount`,`c`.`odbc_date` AS `created` from `vn2008`.`credit` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ClientCreditLimit`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ClientCreditLimit`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ClientCreditLimit` AS select `l`.`id` AS `id`,`l`.`maxAmount` AS `maxAmount`,`l`.`roleFk` AS `roleFk` from `vn`.`clientCreditLimit` `l` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ClientObservation`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ClientObservation`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ClientObservation` AS select `o`.`client_observation_id` AS `id`,`o`.`Id_Cliente` AS `clientFk`,`o`.`Id_Trabajador` AS `employeeFk`,`o`.`text` AS `text`,`o`.`odbc_date` AS `created` from `vn2008`.`client_observation` `o` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ClientType`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ClientType`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ClientType` AS select `ct`.`clientes_tipo_id` AS `id`,`ct`.`code` AS `code`,`ct`.`tipo` AS `type` from `vn2008`.`clientes_tipo` `ct` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ContactChannel`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ContactChannel`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ContactChannel` AS select `c`.`chanel_id` AS `id`,`c`.`name` AS `name` from `vn2008`.`chanel` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Country`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Country`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Country` AS select `c`.`Id` AS `id`,`c`.`Pais` AS `name`,`c`.`CEE` AS `inCee`,`c`.`Codigo` AS `code`,`c`.`Id_Moneda` AS `currencyFk`,`c`.`Id_Paisreal` AS `realCountryFk` from `vn2008`.`Paises` `c` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `CreditClassification`
+--
+
+/*!50001 DROP VIEW IF EXISTS `CreditClassification`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `CreditClassification` AS select `vn`.`creditClassification`.`id` AS `id`,`vn`.`creditClassification`.`client` AS `clientFk`,`vn`.`creditClassification`.`dateStart` AS `started`,`vn`.`creditClassification`.`dateEnd` AS `ended` from `vn`.`creditClassification` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Delivery`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Delivery`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Delivery` AS select `r`.`Id_Ruta` AS `id`,`r`.`Fecha` AS `date`,`r`.`m3` AS `m3`,`t`.`warehouse_id` AS `warehouseFk` from (`vn2008`.`Rutas` `r` join `vn2008`.`Tickets` `t` on((`r`.`Id_Ruta` = `t`.`Id_Ruta`))) where (`r`.`Fecha` = curdate()) group by `r`.`Id_Ruta` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Employee`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Employee`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Employee` AS select `e`.`Id_Trabajador` AS `id`,`e`.`Nombre` AS `name`,`e`.`Apellidos` AS `surname`,`e`.`user_id` AS `userFk` from `vn2008`.`Trabajadores` `e` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `PayMethod`
+--
+
+/*!50001 DROP VIEW IF EXISTS `PayMethod`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `PayMethod` AS select `m`.`id` AS `id`,`m`.`name` AS `name`,`m`.`graceDays` AS `graceDays`,`m`.`deudaviva` AS `outstandingDebt`,`m`.`ibanRequired` AS `ibanRequired` from `vn2008`.`pay_met` `m` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Province`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Province`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Province` AS select `p`.`province_id` AS `id`,`p`.`name` AS `name`,`p`.`Paises_Id` AS `countryFk`,`p`.`warehouse_id` AS `warehouseFk`,`p`.`zone` AS `zoneFk` from `vn2008`.`province` `p` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Role`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Role`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Role` AS select `r`.`id` AS `id`,`r`.`name` AS `name`,`r`.`description` AS `description`,`r`.`created` AS `created`,`r`.`modified` AS `modified` from `account`.`role` `r` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `RoleMapping`
+--
+
+/*!50001 DROP VIEW IF EXISTS `RoleMapping`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `RoleMapping` AS select ((`u`.`id` * 1000) + `r`.`inheritsFrom`) AS `id`,'USER' AS `principalType`,`u`.`id` AS `principalId`,`r`.`inheritsFrom` AS `roleId` from (`account`.`user` `u` join `account`.`roleRole` `r` on((`r`.`role` = `u`.`role`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Route`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Route`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Route` AS select `r`.`Id_Ruta` AS `id`,`r`.`Fecha` AS `date` from `vn2008`.`Rutas` `r` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `State`
+--
+
+/*!50001 DROP VIEW IF EXISTS `State`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `State` AS select `s`.`id` AS `id`,`s`.`name` AS `name`,`s`.`order` AS `order`,`s`.`alert_level` AS `alertLevel`,`s`.`code` AS `code` from `vn2008`.`state` `s` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Ticket`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Ticket`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Ticket` AS select `t`.`Id_Ticket` AS `id`,`t`.`Id_Agencia` AS `agencyFk`,`t`.`Id_Trabajador` AS `employeeFk`,`t`.`Fecha` AS `date`,`t`.`Id_Consigna` AS `addressFk`,`t`.`Hora` AS `hour`,`t`.`Id_Cliente` AS `clientFk` from `vn2008`.`Tickets` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `TicketState`
+--
+
+/*!50001 DROP VIEW IF EXISTS `TicketState`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `TicketState` AS select `i`.`inter_id` AS `id`,`i`.`Id_Ticket` AS `ticketFk`,`i`.`state_id` AS `stateFk`,`i`.`Id_Trabajador` AS `employeeFk`,`i`.`odbc_date` AS `updated` from `vncontrol`.`inter` `i` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Vehicle`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Vehicle`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Vehicle` AS select `v`.`Id_Vehiculo` AS `id`,`v`.`Matricula` AS `numberPlate`,`v`.`Marca` AS `tradeMark`,`v`.`Modelo` AS `model`,`v`.`empresa_id` AS `companyFk`,`v`.`warehouseFk` AS `warehouseFk`,`v`.`description` AS `description`,`v`.`m3` AS `m3`,`v`.`active` AS `isActive` from `vn2008`.`Vehiculos` `v` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Warehouse`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Warehouse`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Warehouse` AS select `w`.`id` AS `id`,`w`.`name` AS `name`,`w`.`tpv` AS `tpv`,`w`.`inventario` AS `inventory`,`w`.`isManaged` AS `isManaged` from `vn2008`.`warehouse` `w` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `WarehouseAlias`
+--
+
+/*!50001 DROP VIEW IF EXISTS `WarehouseAlias`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `WarehouseAlias` AS select `wa`.`warehouse_alias_id` AS `id`,`wa`.`alias` AS `name` from `vn2008`.`warehouse_alias` `wa` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Worker`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Worker`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Worker` AS select `e`.`Id_Trabajador` AS `id`,`e`.`Nombre` AS `name`,`e`.`Apellidos` AS `surname`,`e`.`user_id` AS `userFk` from `vn2008`.`Trabajadores` `e` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `Zone`
+--
+
+/*!50001 DROP VIEW IF EXISTS `Zone`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `Zone` AS select `z`.`zone_id` AS `id`,`z`.`name` AS `name`,`z`.`printingOrder` AS `printingOrder` from `vn2008`.`zones` `z` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Current Database: `hedera`
+--
+
+USE `hedera`;
+
+--
+-- Final view structure for view `address_view`
+--
+
+/*!50001 DROP VIEW IF EXISTS `address_view`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `address_view` AS select `a`.`id_consigna` AS `id`,`a`.`Id_cliente` AS `customer_id`,`a`.`warehouse_id` AS `warehouse_id`,`a`.`domicilio` AS `name`,`a`.`poblacion` AS `city`,`a`.`province_id` AS `province_id`,`a`.`codPostal` AS `zip_code`,`a`.`consignatario` AS `consignee`,`a`.`predeterminada` AS `default`,`a`.`Id_Agencia` AS `type_id`,`a`.`especificaciones` AS `specs`,`a`.`seguro` AS `insurance`,`a`.`porte` AS `postage`,`a`.`active` AS `active` from `vn2008`.`Consignatarios` `a` where (`a`.`Id_cliente` = `account`.`userGetId`()) */
+/*!50002 WITH CASCADED CHECK OPTION */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `basket`
+--
+
+/*!50001 DROP VIEW IF EXISTS `basket`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `basket` AS select `o`.`id` AS `id`,`o`.`date_make` AS `date_make`,`o`.`date_send` AS `date_send`,`o`.`customer_id` AS `customer_id`,`o`.`delivery_method_id` AS `delivery_method_id`,`o`.`agency_id` AS `agency_id`,`o`.`address_id` AS `address_id`,`o`.`company_id` AS `company_id`,`o`.`note` AS `note` from `hedera`.`order` `o` where (`o`.`id` = `basketGetId`()) */
+/*!50002 WITH CASCADED CHECK OPTION */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `basket_defaults`
+--
+
+/*!50001 DROP VIEW IF EXISTS `basket_defaults`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `basket_defaults` AS select `ad`.`id_consigna` AS `address_id`,`ad`.`Id_Agencia` AS `agency_id`,`v`.`code` AS `delivery_method` from (((`vn2008`.`Clientes` `c` left join `vn2008`.`Consignatarios` `ad` on((`ad`.`id_consigna` = `c`.`default_address`))) join `vn2008`.`Agencias` `a` on((`a`.`Id_Agencia` = `ad`.`Id_Agencia`))) join `vn2008`.`Vistas` `v` on((`v`.`vista_id` = `a`.`Vista`))) where (`c`.`id_cliente` = `account`.`userGetId`()) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+
+
+--
+-- Final view structure for view `customer_view`
+--
+
+/*!50001 DROP VIEW IF EXISTS `customer_view`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `customer_view` AS select `c`.`id_cliente` AS `user_id`,`c`.`cliente` AS `name`,`c`.`e-mail` AS `email`,`c`.`mail` AS `mail`,`c`.`default_address` AS `default_address`,`c`.`credito` AS `credit` from `vn2008`.`Clientes` `c` where (`c`.`id_cliente` = `account`.`userGetId`()) */
+/*!50002 WITH CASCADED CHECK OPTION */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `invoice_view`
+--
+
+/*!50001 DROP VIEW IF EXISTS `invoice_view`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `invoice_view` AS select `i`.`factura_id` AS `invoice_id`,`i`.`Id_Factura` AS `serial_num`,`i`.`Fecha` AS `issued`,`i`.`Importe` AS `amount` from `vn2008`.`Facturas` `i` where ((`i`.`Id_Cliente` = `account`.`userGetId`()) and `i`.`pdf`) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `myAddress`
+--
+
+/*!50001 DROP VIEW IF EXISTS `myAddress`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `myAddress` AS select `t`.`id` AS `id`,`t`.`clientFk` AS `clientFk`,`t`.`street` AS `street`,`t`.`city` AS `city`,`t`.`postalCode` AS `postalCode`,`t`.`provinceFk` AS `provinceFk`,`t`.`nickname` AS `nickname`,`t`.`isDefaultAddress` AS `isDefaultAddress`,`t`.`active` AS `active`,`t`.`longitude` AS `longitude`,`t`.`latitude` AS `latitude`,`t`.`warehouseFk` AS `warehouseFk`,`t`.`agencyFk` AS `agencyFk` from `vn`.`address` `t` where (`t`.`clientFk` = `account`.`userGetId`()) */
+/*!50002 WITH CASCADED CHECK OPTION */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `myMenu`
+--
+
+/*!50001 DROP VIEW IF EXISTS `myMenu`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `myMenu` AS select `t`.`id` AS `id`,`t`.`path` AS `path`,`t`.`description` AS `description`,`t`.`parentFk` AS `parentFk` from (`hedera`.`menu` `t` join `account`.`userRole` `r` on((`r`.`id` = `t`.`roleFk`))) order by `t`.`parentFk`,`t`.`displayOrder`,`t`.`id` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `myTicket`
+--
+
+/*!50001 DROP VIEW IF EXISTS `myTicket`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `myTicket` AS select `t`.`id` AS `id`,`t`.`clientFk` AS `clientFk`,`t`.`warehouseFk` AS `warehouseFk`,`t`.`shipped` AS `shipped`,`t`.`landed` AS `landed`,`t`.`nickname` AS `nickname`,`t`.`agencyModeFk` AS `agencyModeFk`,`t`.`refFk` AS `refFk`,`t`.`addressFk` AS `addressFk`,`t`.`isSigned` AS `isSigned`,`t`.`package` AS `package`,`t`.`location` AS `location`,`t`.`companyFk` AS `companyFk` from `vn`.`ticket` `t` where (`t`.`clientFk` = `account`.`userGetId`()) */
+/*!50002 WITH CASCADED CHECK OPTION */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `myTicketRow`
+--
+
+/*!50001 DROP VIEW IF EXISTS `myTicketRow`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `myTicketRow` AS select `s`.`id` AS `id`,`s`.`itemFk` AS `itemFk`,`s`.`ticketFk` AS `ticketFk`,`s`.`concept` AS `concept`,`s`.`quantity` AS `quantity`,`s`.`price` AS `price`,`s`.`discount` AS `discount`,`s`.`reserved` AS `reserved`,`s`.`isPicked` AS `isPicked` from (`vn`.`sale` `s` join `hedera`.`myTicket` `t` on((`s`.`ticketFk` = `t`.`id`))) */
+/*!50002 WITH CASCADED CHECK OPTION */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `myTpvTransaction`
+--
+
+/*!50001 DROP VIEW IF EXISTS `myTpvTransaction`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `myTpvTransaction` AS select `t`.`id` AS `id`,`t`.`merchantFk` AS `merchantFk`,`t`.`clientFk` AS `clientFk`,`t`.`receiptFk` AS `receiptFk`,`t`.`amount` AS `amount`,`t`.`response` AS `response`,`t`.`status` AS `status`,`t`.`created` AS `created` from `hedera`.`tpvTransaction` `t` where (`t`.`clientFk` = `account`.`userGetId`()) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `order_basket`
+--
+
+/*!50001 DROP VIEW IF EXISTS `order_basket`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `order_basket` AS select `t`.`customerFk` AS `customer_id`,`t`.`orderFk` AS `order_id` from `basketOrder` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `order_component`
+--
+
+/*!50001 DROP VIEW IF EXISTS `order_component`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `order_component` AS select `t`.`rowFk` AS `order_row_id`,`t`.`componentFk` AS `component_id`,`t`.`price` AS `price` from `orderRowComponent` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `order_config`
+--
+
+/*!50001 DROP VIEW IF EXISTS `order_config`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `order_config` AS select `t`.`id` AS `id`,`t`.`employeeFk` AS `employee_id`,`t`.`deliveryAgencyFk` AS `delivery_agency`,`t`.`guestMethod` AS `guest_method`,`t`.`guestAgencyFk` AS `guest_agency`,`t`.`reserveTime` AS `reserve_time` from `orderConfig` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `order_confirm_time`
+--
+
+/*!50001 DROP VIEW IF EXISTS `order_confirm_time`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `order_confirm_time` AS select `o`.`date_make` AS `date_make`,`o`.`source_app` AS `source_app`,`o`.`customer_id` AS `customer_id`,`o`.`confirm_date` AS `confirm_date`,`o`.`first_row_stamp` AS `first_row_stamp`,(ceiling((((unix_timestamp(`o`.`confirm_date`) - unix_timestamp(`o`.`first_row_stamp`)) / 60) / 5)) * 5) AS `minutos` from `order` `o` where ((`o`.`confirm_date` is not null) and (`o`.`first_row_stamp` is not null)) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `order_row`
+--
+
+/*!50001 DROP VIEW IF EXISTS `order_row`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `order_row` AS select `t`.`id` AS `id`,`t`.`orderFk` AS `order_id`,`t`.`itemFk` AS `item_id`,`t`.`warehouseFk` AS `warehouse_id`,`t`.`shipment` AS `shipment`,`t`.`amount` AS `amount`,`t`.`price` AS `price`,`t`.`rate` AS `rate`,`t`.`created` AS `created`,`t`.`saleFk` AS `Id_Movimiento` from `orderRow` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `order_row_view`
+--
+
+/*!50001 DROP VIEW IF EXISTS `order_row_view`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `order_row_view` AS select `r`.`id` AS `id`,`r`.`order_id` AS `order_id`,`r`.`warehouse_id` AS `warehouse_id`,`r`.`item_id` AS `item_id`,`r`.`amount` AS `amount`,`r`.`price` AS `price2` from `hedera`.`order_row` `r` where `r`.`order_id` in (select `order_view`.`id` AS `id` from `hedera`.`order_view`) */
+/*!50002 WITH CASCADED CHECK OPTION */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `order_view`
+--
+
+/*!50001 DROP VIEW IF EXISTS `order_view`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `order_view` AS select `o`.`id` AS `id`,`o`.`date_make` AS `date_make`,`o`.`date_send` AS `date_send`,`o`.`customer_id` AS `customer_id`,`o`.`delivery_method_id` AS `delivery_method_id`,`o`.`agency_id` AS `agency_id`,`o`.`note` AS `note`,`o`.`address_id` AS `address_id`,`o`.`company_id` AS `company_id` from `hedera`.`order` `o` where ((`o`.`customer_id` = `account`.`userGetId`()) and (`o`.`is_bionic` = 0)) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ticket_row_view`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ticket_row_view`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ticket_row_view` AS select `m`.`Id_Movimiento` AS `id`,`m`.`Id_Article` AS `item_id`,`m`.`Id_Ticket` AS `ticket_id`,`m`.`Concepte` AS `concept`,`m`.`Cantidad` AS `amount`,`m`.`Preu` AS `price`,`m`.`PrecioFijado` AS `fixed`,`m`.`Descuento` AS `discount`,`m`.`CostFixat` AS `cost`,`m`.`Reservado` AS `reserved`,`m`.`OK` AS `ok` from (`vn2008`.`Movimientos` `m` join `hedera`.`ticket_view` `t` on((`m`.`Id_Ticket` = `t`.`id`))) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `ticket_view`
+--
+
+/*!50001 DROP VIEW IF EXISTS `ticket_view`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `ticket_view` AS select `t`.`Id_Ticket` AS `id`,`t`.`Id_Cliente` AS `customer_id`,`t`.`warehouse_id` AS `warehouse_id`,`t`.`Fecha` AS `date`,`t`.`landing` AS `delivery`,`t`.`Alias` AS `alias`,`t`.`Id_Agencia` AS `agency_id`,`t`.`Notas` AS `note`,`t`.`Factura` AS `invoice`,`t`.`Id_Consigna` AS `address_id`,`t`.`Id_Trabajador` AS `employee_id`,`t`.`Observaciones` AS `comments`,`t`.`Firmado` AS `signed`,`t`.`Bultos` AS `packages`,`t`.`Localizacion` AS `location`,`t`.`Hora` AS `hour`,`t`.`blocked` AS `blocked`,`t`.`Solucion` AS `solution`,`t`.`empresa_id` AS `company_id`,`a`.`Agencia` AS `type` from (`vn2008`.`Tickets` `t` join `vn2008`.`Agencias` `a` on((`t`.`Id_Agencia` = `a`.`Id_Agencia`))) where (`t`.`Id_Cliente` = `account`.`userGetId`()) */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `user_android`
+--
+
+/*!50001 DROP VIEW IF EXISTS `user_android`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `user_android` AS select `t`.`androidId` AS `android_id`,`t`.`userFk` AS `user_id` from `androidUser` `t` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Current Database: `bs`
+--
+
+USE `bs`;
+
+--
+-- Final view structure for view `VentasPorCliente`
+--
+
+/*!50001 DROP VIEW IF EXISTS `VentasPorCliente`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `VentasPorCliente` AS select `v`.`Id_Cliente` AS `Id_Cliente`,round(sum(`v`.`importe`),0) AS `VentaBasica`,`t`.`year` AS `year`,`t`.`month` AS `month` from (`vn2008`.`time` `t` join `bs`.`ventas` `v` on((`v`.`fecha` = `t`.`date`))) group by `v`.`Id_Cliente`,`t`.`year`,`t`.`month` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+
+--
+-- Final view structure for view `v_ventas`
+--
+
+/*!50001 DROP VIEW IF EXISTS `v_ventas`*/;
+/*!50001 SET @saved_cs_client = @@character_set_client */;
+/*!50001 SET @saved_cs_results = @@character_set_results */;
+/*!50001 SET @saved_col_connection = @@collation_connection */;
+/*!50001 SET character_set_client = utf8 */;
+/*!50001 SET character_set_results = utf8 */;
+/*!50001 SET collation_connection = utf8_general_ci */;
+/*!50001 CREATE ALGORITHM=UNDEFINED */
+/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */
+/*!50001 VIEW `v_ventas` AS select (`bs`.`ventas`.`importe` * `vn2008`.`Movimientos`.`Cantidad`) AS `importe`,`bs`.`ventas`.`recargo` AS `recargo`,`vn2008`.`time`.`year` AS `year`,`vn2008`.`time`.`month` AS `month`,`vn2008`.`time`.`week` AS `week`,`vn2008`.`time`.`day` AS `day` from ((`bs`.`ventas` join `vn2008`.`time` on((`vn2008`.`time`.`date` = `bs`.`ventas`.`fecha`))) join `vn2008`.`Movimientos` on((`bs`.`ventas`.`Id_Movimiento` = `vn2008`.`Movimientos`.`Id_Movimiento`))) group by `vn2008`.`time`.`date` */;
+/*!50001 SET character_set_client = @saved_cs_client */;
+/*!50001 SET character_set_results = @saved_cs_results */;
+/*!50001 SET collation_connection = @saved_col_connection */;
+/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
+
+/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
+/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
+/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
+/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
+
+
diff --git a/services/db/localDB02Inserts.sql b/services/db/localDB09Inserts.sql
similarity index 85%
rename from services/db/localDB02Inserts.sql
rename to services/db/localDB09Inserts.sql
index 9e6ed61c6..18cb94721 100644
--- a/services/db/localDB02Inserts.sql
+++ b/services/db/localDB09Inserts.sql
@@ -269,7 +269,8 @@ INSERT INTO `salix`.`Account`(`id`,`name`,`password`,`roleFk`,`active`,`email`)
(7, 'HankPym', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'HankPym@verdnatura.es'),
(8, 'CharlesXavier', 'ac754a330530832ba1bf7687f577da91', 18, 1, 'CharlesXavier@verdnatura.es'),
(9, 'BruceBanner', 'ac754a330530832ba1bf7687f577da91', 18, 1, 'BruceBanner@verdnatura.es'),
- (10, 'JessicaJones', 'ac754a330530832ba1bf7687f577da91', 9, 1, 'JessicaJones@verdnatura.es');
+ (10, 'JessicaJones', 'ac754a330530832ba1bf7687f577da91', 9, 1, 'JessicaJones@verdnatura.es'),
+ (11, 'Cyborg', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'cyborg@verdnatura.es');
INSERT INTO `salix`.`Country`(`id`, `name`, `inCee`, `code`, `currencyFk`, `realCountryFk`)
VALUES
@@ -363,7 +364,8 @@ INSERT INTO `vn2008`.`Trabajadores`(`CodigoTrabajador`, `Id_Trabajador`, `Nombre
('ANT', 2, 'Hank', 'Pym', 7),
('DCX', 3, 'Charles', 'Xavier', 8),
('HLK', 4, 'Bruce', 'Banner', 9),
- ('JJJ', 5, 'Jessica', 'Jones', 10);
+ ('JJJ', 5, 'Jessica', 'Jones', 10),
+ ('VSC', 20, 'Victor ', 'Stone', 11);
INSERT INTO `salix`.`ContactChannel`(`id`, `name`)
VALUES
@@ -373,18 +375,19 @@ INSERT INTO `salix`.`ContactChannel`(`id`, `name`)
(4, 'GCN Channel'),
(5, 'The Newspaper');
-INSERT INTO `salix`.`Client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `provinceFk`, `countryFk`, `email`, `phone`, `mobile`, `fax`, `active`, `discount`, `credit`, `creditInsurance`, `iban`, `dueDay`, `equalizationTax`, `hasToInvoice`, `isToBeMailed`, `payMethodFk`, `salesPersonFk`, `contactChannelFk`, `sepaVnl`, `coreVnl`, `coreVnh`, `eypbc`, `quality`, `vies`, `isRelevant`, `typeFk`, `accountingAccount`, `created`)
+INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`fax`,`isRelevant`,`email`,`iban`,`dueDay`,`accountingAccount`,`isEqualizated`,`provinceFk`,`hasToInvoice`,`credit`,`countryFk`,`isActive`,`gestdocFk`,`quality`,`payMethodFk`,`created`,`isToBeMailed`,`contactChannelFk`,`hasSepaVnl`,`hasCoreVnl`,`hasCoreVnh`,`riskCalculated`,`clientTypeFk`,`mailAddress`,`cplusTerIdNifFk`,`hasToInvoiceByAddress`,`isTaxDataChecked`,`isFreezed`,`creditInsurance`,`isCreatedAsServed`,`hasInvoiceSimplified`,`salesPersonFk`,`isVies`,`eypbc`)
VALUES
- (1, 'Bruce Wayne', '74451390E', 'Batman', 'Alfred', '1007 Mountain Drive, Gotham', 'Silla', 46460, 1, 1, 'BruceWayne@verdnatura.es', 1111111111, 222222222, 333333333, 1, 1, 300, NULL, NULL, 0, 1, 1, 1, 5, 1, 5, 1, 1, 1, 1, 10, 0, 1, 1, 1234567890, CURDATE()),
- (2, 'Petter Parker', '87945234L', 'Spider-Man', 'Aunt May', '20 Ingram Street', 'Silla', 46460, 1, 1, 'PetterParker@verdnatura.es', 1111111111, 222222222, 333333333, 1, 1, 300, NULL, NULL, 0, 1, 1, 1, 5, 1, 5, 1, 1, 1, 1, 10, 0, 1, 1, 1234567890, CURDATE()),
- (3, 'Clark Kent', '06815934E', 'Super-Man', 'lois lane', '344 Clinton Street', 'Silla', 46460, 1, 1, 'ClarkKent@verdnatura.es', 1111111111, 222222222, 333333333, 1, 1, 300, NULL, NULL, 0, 1, 1, 1, 5, 1, 5, 1, 1, 1, 1, 10, 0, 1, 1, 1234567890, CURDATE()),
- (4, 'Tony Stark', '06089160W', 'Iron-Man', 'Pepper Potts', '10880 Malibu Point', 'Silla', 46460, 1, 1, 'TonyStark@verdnatura.es', 1111111111, 222222222, 333333333, 1, 1, 300, NULL, NULL, 0, 1, 1, 1, 5, 1, 5, 1, 1, 1, 1, 10, 0, 1, 1, 1234567890, CURDATE()),
- (5, 'Max Eisenhardt', '39182496H', 'Magneto', 'Rogue', 'Unknown Whereabouts', 'Silla', 46460, 1, 1, 'MaxEisenhardt@verdnatura.es', 1111111111, 222222222, 333333333, 1, 1, 300, NULL, NULL, 0, 1, 1, 1, 5, 3, 5, 1, 1, 1, 1, 10, 0, 1, 1, 1234567890, CURDATE()),
- (6, 'DavidCharlesHaller', '53136686Q', 'Legion', 'Charles Xavier', 'Evil hideout', 'Silla', 46460, 1, 1, 'DavidCharlesHaller@verdnatura.es', 1111111111, 222222222, 333333333, 1, 1, 300, NULL, NULL, 0, 1, 1, 1, 5, 3, 5, 1, 1, 1, 1, 10, 0, 1, 1, 1234567890, CURDATE()),
- (7, 'Hank Pym', '09854837G', 'Ant-Man', 'Hawk', 'Anthill', 'Silla', 46460, 1, 1, 'HankPym@verdnatura.es', 1111111111, 222222222, 333333333, 1, 1, 300, NULL, NULL, 0, 1, 1, 1, 5, 3, 5, 1, 1, 1, 1, 10, 0, 1, 1, 1234567890, CURDATE()),
- (8, 'Charles Xavier', '22641921P', 'Professor X', 'Beast', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Silla', 46460, 1, 1, 'CharlesXavier@verdnatura.es', 1111111111, 222222222, 333333333, 1, 1, 300, NULL, NULL, 0, 1, 1, 1, 5, 4, 5, 1, 1, 1, 1, 10, 0, 1, 1, 1234567890, CURDATE()),
- (9, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 1, 1, 'BruceBanner@verdnatura.es', 1111111111, 222222222, 333333333, 1, 1, 300, NULL, NULL, 0, 1, 1, 1, 5, 4, 5, 1, 1, 1, 1, 10, 0, 1, 1, 1234567890, CURDATE()),
- (10, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 1, 1, 'JessicaJones@verdnatura.es', 1111111111, 222222222, 333333333, 1, 1, 300, NULL, NULL, 0, 1, 1, 1, 5, 4, 5, 1, 1, 1, 1, 10, 0, 1, 1, 1234567890, CURDATE());
+ (1, 'Bruce Wayne', '74451390E', 'Batman', 'Alfred', '1007 Mountain Drive, Gotham', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceWayne@verdnatura.es', NULL, 0, 1234567890, 1, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 1, 0, 1 ),
+ (2, 'Petter Parker', '87945234L', 'Spider-Man', 'Aunt May', '20 Ingram Street', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'PetterParker@verdnatura.es', NULL, 0, 1234567890, 1, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 1, 0, 1 ),
+ (3, 'Clark Kent', '06815934E', 'Super-Man', 'lois lane', '344 Clinton Street', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'ClarkKent@verdnatura.es', NULL, 0, 1234567890, 1, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 1, 0, 1 ),
+ (4, 'Tony Stark', '06089160W', 'Iron-Man', 'Pepper Potts', '10880 Malibu Point', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'TonyStark@verdnatura.es', NULL, 0, 1234567890, 1, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 1, 0, 1 ),
+ (5, 'Max Eisenhardt', '39182496H', 'Magneto', 'Rogue', 'Unknown Whereabouts', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'MaxEisenhardt@verdnatura.es', NULL, 0, 1234567890, 1, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 3, 0, 1 ),
+ (6, 'DavidCharlesHaller', '53136686Q', 'Legion', 'Charles Xavier', 'Evil hideout', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'DavidCharlesHaller@verdnatura.es', NULL, 0, 1234567890, 1, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 3, 0, 1 ),
+ (7, 'Hank Pym', '09854837G', 'Ant-Man', 'Hawk', 'Anthill', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'HankPym@verdnatura.es', NULL, 0, 1234567890, 1, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 3, 0, 1 ),
+ (8, 'Charles Xavier', '22641921P', 'Professor X', 'Beast', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'CharlesXavier@verdnatura.es', NULL, 0, 1234567890, 1, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 4, 0, 1 ),
+ (9, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceBanner@verdnatura.es', NULL, 0, 1234567890, 1, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 4, 0, 1 ),
+ (10, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'JessicaJones@verdnatura.es', NULL, 0, 1234567890, 1, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 4, 0, 1 );
+
INSERT INTO `salix`.`Address`(`id`, `consignee`, `street`, `city`, `postcode`, `provinceFk`, `phone`, `mobile`, `isEnabled`, `isDefaultAddress`, `clientFk`, `defaultAgencyFk`, `longitude`, `latitude`, `isEqualizated`)
VALUES
@@ -473,14 +476,14 @@ INSERT INTO `vn2008`.`empresa`(`id`, `abbreviation`, `registro`, `gerente_id`, `
INSERT INTO `salix`.`TicketState`(`id`, `ticketFk`, `stateFk`, `employeeFk`, `updated`)
VALUES
- (1, 1, 1, 1, CURDATE()),
- (2, 2, 2, 1, CURDATE()),
- (3, 3, 3, 2, CURDATE()),
- (4, 4, 1, 2, CURDATE()),
- (5, 5, 2, 3, CURDATE()),
- (6, 6, 3, 3, CURDATE()),
- (7, 7, 1, 4, CURDATE()),
- (8, 8, 2, 4, CURDATE()),
+ (1, 1, 1, 5, CURDATE()),
+ (2, 2, 2, 5, CURDATE()),
+ (3, 3, 3, 5, CURDATE()),
+ (4, 4, 1, 5, CURDATE()),
+ (5, 5, 2, 5, CURDATE()),
+ (6, 6, 3, 5, CURDATE()),
+ (7, 7, 1, 5, CURDATE()),
+ (8, 8, 2, 5, CURDATE()),
(9, 9, 3, 5, CURDATE()),
(10, 10, 1, 5, CURDATE());