From c59221229079eca0d1ec245a04bfcd66bafc3920 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 31 Aug 2021 15:15:51 +0200 Subject: [PATCH] fix(structure): Dumped production database Dumped database and fixed structure issues Refs: #3079 --- db/dump/dumpedFixtures.sql | 46 +- db/dump/fixtures.sql | 46 +- db/dump/structure.sql | 11848 +++++++++++++++++++---------------- 3 files changed, 6611 insertions(+), 5329 deletions(-) diff --git a/db/dump/dumpedFixtures.sql b/db/dump/dumpedFixtures.sql index 871c8e933..9cb7e9a0c 100644 --- a/db/dump/dumpedFixtures.sql +++ b/db/dump/dumpedFixtures.sql @@ -1,6 +1,6 @@ USE `util`; --- MariaDB dump 10.19 Distrib 10.5.10-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64) -- -- Host: db.verdnatura.es Database: util -- ------------------------------------------------------ @@ -22,7 +22,7 @@ USE `util`; LOCK TABLES `config` WRITE; /*!40000 ALTER TABLE `config` DISABLE KEYS */; -INSERT INTO `config` VALUES (1,'10320',0,'production',NULL); +INSERT INTO `config` VALUES (1,'10330',0,'production',NULL); /*!40000 ALTER TABLE `config` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -34,9 +34,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-06-22 14:40:02 +-- Dump completed on 2021-08-31 14:42:28 USE `account`; --- MariaDB dump 10.19 Distrib 10.5.10-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64) -- -- Host: db.verdnatura.es Database: account -- ------------------------------------------------------ @@ -58,7 +58,7 @@ USE `account`; LOCK TABLES `role` WRITE; /*!40000 ALTER TABLE `role` DISABLE KEYS */; -INSERT INTO `role` VALUES (1,'employee','Empleado básico',1,'2017-05-19 07:04:58','2017-11-29 10:06:31'),(2,'customer','Privilegios básicos de un cliente',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(3,'agency','Consultar tablas de predicciones de bultos',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(5,'administrative','Tareas relacionadas con la contabilidad',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(6,'guest','Privilegios para usuarios sin cuenta',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(9,'developer','Desarrolladores del sistema',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(11,'account','Privilegios relacionados con el login',0,'2017-05-19 07:04:58','2017-09-20 17:06:35'),(13,'teamBoss','Jefe de departamento',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(15,'logistic','Departamento de compras, responsables de la logistica',1,'2017-05-19 07:04:58','2018-02-12 10:50:10'),(16,'logisticBoss','Jefe del departamento de logística',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(17,'adminBoss','Jefe del departamento de administración',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(18,'salesPerson','Departamento de ventas',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(19,'salesBoss','Jefe del departamento de ventas',1,'2017-05-19 07:04:58','2017-08-16 12:38:27'),(20,'manager','Departamento de gerencia',1,'2017-06-01 14:57:02','2017-06-01 14:57:51'),(21,'salesAssistant','Jefe auxiliar de ventas',1,'2017-08-16 12:40:52','2017-08-16 12:40:52'),(22,'teamManager','Jefe de departamento con privilegios de auxiliar de venta.',1,'2017-09-07 09:08:12','2017-09-07 09:08:12'),(30,'financialBoss','Director finaciero',1,'2017-09-21 11:05:36','2017-09-21 11:05:36'),(31,'freelancer','Trabajadores por cuenta ajena',1,'2017-10-10 12:57:26','2017-10-10 12:59:27'),(32,'ett','Trabajadores de empresa temporal',1,'2017-10-10 12:58:58','2017-10-10 12:59:20'),(33,'invoicing','Personal con acceso a facturación',0,'2018-01-29 16:43:34','2018-01-29 16:43:34'),(34,'agencyBoss','Jefe/a del departamento de agencias',1,'2018-01-29 16:44:39','2018-02-23 07:58:53'),(35,'buyer','Departamento de compras',1,'2018-02-12 10:35:42','2018-02-12 10:35:42'),(36,'replenisher','Trabajadores de camara',1,'2018-02-16 14:07:10','2019-04-12 05:38:08'),(37,'hr','Gestor/a de recursos humanos',1,'2018-02-22 17:34:53','2018-02-22 17:34:53'),(38,'hrBoss','Jefe/a de recursos humanos',1,'2018-02-22 17:35:09','2018-02-22 17:35:09'),(39,'adminAssistant','Jefe auxiliar administrativo',1,'2018-02-23 10:37:36','2018-02-23 10:38:41'),(40,'handmade','Departamento de confección',1,'2018-02-23 11:14:53','2018-02-23 11:39:12'),(41,'handmadeBoss','Jefe de departamento de confección',1,'2018-02-23 11:15:09','2018-02-23 11:39:26'),(42,'artificial','Departamento de artificial',1,'2018-02-23 11:39:59','2018-02-23 11:39:59'),(43,'artificialBoss','Jefe del departamento de artificial',1,'2018-02-23 11:40:16','2018-02-23 11:40:16'),(44,'accessory','Departamento de complementos',1,'2018-02-23 11:41:12','2018-02-23 11:41:12'),(45,'accessoryBoss','Jefe del departamento de complementos',1,'2018-02-23 11:41:23','2018-02-23 11:41:23'),(47,'cooler','Empleados de cámara',1,'2018-02-23 13:08:18','2018-02-23 13:08:18'),(48,'coolerBoss','Jefe del departamento de cámara',1,'2018-02-23 13:12:01','2018-02-23 13:12:01'),(49,'production','Empleado de producción',1,'2018-02-26 15:28:23','2021-02-12 09:42:35'),(50,'productionBoss','Jefe de producción',1,'2018-02-26 15:34:12','2018-02-26 15:34:12'),(51,'marketing','Departamento de marketing',1,'2018-03-01 07:28:39','2018-03-01 07:28:39'),(52,'marketingBoss','Jefe del departamento de marketing',1,'2018-03-01 07:28:57','2018-03-01 07:28:57'),(53,'insurance','Gestor de seguros de cambio',0,'2018-03-05 07:44:35','2019-02-01 13:47:57'),(54,'itemPicker','Sacador en cámara',1,'2018-03-05 12:08:17','2018-03-05 12:08:17'),(55,'itemPickerBoss','Jefe de sacadores',1,'2018-03-05 12:08:31','2018-03-05 12:08:31'),(56,'delivery','Personal de reparto',1,'2018-05-30 06:07:02','2018-05-30 06:07:02'),(57,'deliveryBoss','Jefe de personal de reparto',1,'2018-05-30 06:07:19','2018-05-30 06:07:19'),(58,'packager','Departamento encajadores',1,'2019-01-21 12:43:45','2019-01-21 12:43:45'),(59,'packagerBoss','Jefe departamento encajadores',1,'2019-01-21 12:44:10','2019-01-21 12:44:10'),(60,'productionAssi','Tareas relacionadas con producción y administración',1,'2019-01-29 13:29:01','2019-01-29 13:29:01'),(61,'replenisherBos','Jefe de Complementos/Camara',1,'2019-07-01 06:44:07','2019-07-01 06:44:07'),(62,'noLogin','Role without login access to MySQL',0,'2019-07-01 06:50:19','2019-07-02 13:42:05'),(64,'balanceSheet','Consulta de Balance',0,'2019-07-16 12:12:08','2019-07-16 12:12:08'),(65,'officeBoss','Jefe de filial',1,'2019-08-02 06:54:26','2019-08-02 06:54:26'),(66,'sysadmin','Administrador de sistema',1,'2019-08-08 06:58:56','2019-08-08 06:58:56'),(67,'adminOfficer','categoria profesional oficial de administración',1,'2020-01-03 08:09:23','2020-01-03 08:09:23'),(69,'coolerAssist','Empleado cámara con permiso compras',1,'2020-02-05 12:36:09','2020-02-05 12:36:09'),(70,'trainee','Alumno de prácticas',1,'2020-03-04 11:00:25','2020-03-04 11:00:25'),(71,'checker','Rol de revisor con privilegios de itemPicker',1,'2020-10-02 10:50:07','2020-10-02 10:50:07'),(72,'claimManager','Personal de reclamaciones',1,'2020-10-13 10:01:32','2020-10-26 07:29:46'),(73,'financial','Departamento de finanzas',1,'2020-11-16 09:30:27','2020-11-16 09:30:27'),(74,'userPhotos','Privilegios para subir fotos de usuario',1,'2021-02-03 10:24:27','2021-02-03 10:24:27'),(75,'catalogPhotos','Privilegios para subir fotos del catálogo',1,'2021-02-03 10:24:27','2021-02-03 10:24:27'),(76,'chat','Rol para utilizar el rocket chat',1,'2020-11-27 13:06:50','2020-12-17 07:49:41'),(100,'root','Rol con todos los privilegios',0,'2018-04-23 14:33:36','2020-11-12 06:50:07'),(101,'buyerBoss','Jefe del departamento de compras',1,'2021-06-16 09:53:17','2021-06-16 09:53:17'); +INSERT INTO `role` VALUES (1,'employee','Empleado básico',1,'2017-05-19 07:04:58','2017-11-29 10:06:31'),(2,'customer','Privilegios básicos de un cliente',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(3,'agency','Consultar tablas de predicciones de bultos',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(5,'administrative','Tareas relacionadas con la contabilidad',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(6,'guest','Privilegios para usuarios sin cuenta',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(9,'developer','Desarrolladores del sistema',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(11,'account','Privilegios relacionados con el login',0,'2017-05-19 07:04:58','2017-09-20 17:06:35'),(13,'teamBoss','Jefe de equipo/departamento',1,'2017-05-19 07:04:58','2021-06-30 13:29:30'),(15,'logistic','Departamento de compras, responsables de la logistica',1,'2017-05-19 07:04:58','2018-02-12 10:50:10'),(16,'logisticBoss','Jefe del departamento de logística',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(17,'adminBoss','Jefe del departamento de administración',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(18,'salesPerson','Departamento de ventas',1,'2017-05-19 07:04:58','2017-05-19 07:04:58'),(19,'salesBoss','Jefe del departamento de ventas',1,'2017-05-19 07:04:58','2017-08-16 12:38:27'),(20,'manager','Departamento de gerencia',1,'2017-06-01 14:57:02','2017-06-01 14:57:51'),(21,'salesAssistant','Jefe auxiliar de ventas',1,'2017-08-16 12:40:52','2017-08-16 12:40:52'),(22,'teamManager','Jefe de departamento con privilegios de auxiliar de venta.',1,'2017-09-07 09:08:12','2017-09-07 09:08:12'),(30,'financialBoss','Director finaciero',1,'2017-09-21 11:05:36','2017-09-21 11:05:36'),(31,'freelancer','Trabajadores por cuenta ajena',1,'2017-10-10 12:57:26','2017-10-10 12:59:27'),(32,'ett','Trabajadores de empresa temporal',1,'2017-10-10 12:58:58','2017-10-10 12:59:20'),(33,'invoicing','Personal con acceso a facturación',0,'2018-01-29 16:43:34','2018-01-29 16:43:34'),(34,'agencyBoss','Jefe/a del departamento de agencias',1,'2018-01-29 16:44:39','2018-02-23 07:58:53'),(35,'buyer','Departamento de compras',1,'2018-02-12 10:35:42','2018-02-12 10:35:42'),(36,'replenisher','Trabajadores de camara',1,'2018-02-16 14:07:10','2019-04-12 05:38:08'),(37,'hr','Gestor/a de recursos humanos',1,'2018-02-22 17:34:53','2018-02-22 17:34:53'),(38,'hrBoss','Jefe/a de recursos humanos',1,'2018-02-22 17:35:09','2018-02-22 17:35:09'),(39,'adminAssistant','Jefe auxiliar administrativo',1,'2018-02-23 10:37:36','2018-02-23 10:38:41'),(40,'handmade','Departamento de confección',1,'2018-02-23 11:14:53','2018-02-23 11:39:12'),(41,'handmadeBoss','Jefe de departamento de confección',1,'2018-02-23 11:15:09','2018-02-23 11:39:26'),(42,'artificial','Departamento de artificial',1,'2018-02-23 11:39:59','2018-02-23 11:39:59'),(43,'artificialBoss','Jefe del departamento de artificial',1,'2018-02-23 11:40:16','2018-02-23 11:40:16'),(44,'accessory','Departamento de complementos',1,'2018-02-23 11:41:12','2018-02-23 11:41:12'),(45,'accessoryBoss','Jefe del departamento de complementos',1,'2018-02-23 11:41:23','2018-02-23 11:41:23'),(47,'cooler','Empleados de cámara',1,'2018-02-23 13:08:18','2018-02-23 13:08:18'),(48,'coolerBoss','Jefe del departamento de cámara',1,'2018-02-23 13:12:01','2018-02-23 13:12:01'),(49,'production','Empleado de producción',1,'2018-02-26 15:28:23','2021-02-12 09:42:35'),(50,'productionBoss','Jefe de producción',1,'2018-02-26 15:34:12','2018-02-26 15:34:12'),(51,'marketing','Departamento de marketing',1,'2018-03-01 07:28:39','2018-03-01 07:28:39'),(52,'marketingBoss','Jefe del departamento de marketing',1,'2018-03-01 07:28:57','2018-03-01 07:28:57'),(53,'insurance','Gestor de seguros de cambio',0,'2018-03-05 07:44:35','2019-02-01 13:47:57'),(54,'itemPicker','Sacador en cámara',1,'2018-03-05 12:08:17','2018-03-05 12:08:17'),(55,'itemPickerBoss','Jefe de sacadores',1,'2018-03-05 12:08:31','2018-03-05 12:08:31'),(56,'delivery','Personal de reparto',1,'2018-05-30 06:07:02','2018-05-30 06:07:02'),(57,'deliveryBoss','Jefe de personal de reparto',1,'2018-05-30 06:07:19','2018-05-30 06:07:19'),(58,'packager','Departamento encajadores',1,'2019-01-21 12:43:45','2019-01-21 12:43:45'),(59,'packagerBoss','Jefe departamento encajadores',1,'2019-01-21 12:44:10','2019-01-21 12:44:10'),(60,'productionAssi','Tareas relacionadas con producción y administración',1,'2019-01-29 13:29:01','2019-01-29 13:29:01'),(61,'replenisherBos','Jefe de Complementos/Camara',1,'2019-07-01 06:44:07','2019-07-01 06:44:07'),(62,'noLogin','Role without login access to MySQL',0,'2019-07-01 06:50:19','2019-07-02 13:42:05'),(64,'balanceSheet','Consulta de Balance',0,'2019-07-16 12:12:08','2019-07-16 12:12:08'),(65,'officeBoss','Jefe de filial',1,'2019-08-02 06:54:26','2019-08-02 06:54:26'),(66,'sysadmin','Administrador de sistema',1,'2019-08-08 06:58:56','2019-08-08 06:58:56'),(67,'adminOfficer','categoria profesional oficial de administración',1,'2020-01-03 08:09:23','2020-01-03 08:09:23'),(69,'coolerAssist','Empleado cámara con permiso compras',1,'2020-02-05 12:36:09','2020-02-05 12:36:09'),(70,'trainee','Alumno de prácticas',1,'2020-03-04 11:00:25','2020-03-04 11:00:25'),(71,'checker','Rol de revisor con privilegios de itemPicker',1,'2020-10-02 10:50:07','2020-10-02 10:50:07'),(72,'claimManager','Personal de reclamaciones',1,'2020-10-13 10:01:32','2020-10-26 07:29:46'),(73,'financial','Departamento de finanzas',1,'2020-11-16 09:30:27','2020-11-16 09:30:27'),(74,'userPhotos','Privilegios para subir fotos de usuario',1,'2021-02-03 10:24:27','2021-02-03 10:24:27'),(75,'catalogPhotos','Privilegios para subir fotos del catálogo',1,'2021-02-03 10:24:27','2021-02-03 10:24:27'),(76,'chat','Rol para utilizar el rocket chat',1,'2020-11-27 13:06:50','2020-12-17 07:49:41'),(100,'root','Rol con todos los privilegios',0,'2018-04-23 14:33:36','2020-11-12 06:50:07'),(101,'buyerBoss','Jefe del departamento de compras',1,'2021-06-16 09:53:17','2021-06-16 09:53:17'); /*!40000 ALTER TABLE `role` ENABLE KEYS */; UNLOCK TABLES; @@ -68,7 +68,7 @@ UNLOCK TABLES; LOCK TABLES `roleInherit` WRITE; /*!40000 ALTER TABLE `roleInherit` DISABLE KEYS */; -INSERT INTO `roleInherit` VALUES (1,1,2),(2,1,3),(3,1,70),(4,2,11),(5,3,11),(6,5,1),(7,5,21),(8,5,33),(124,5,76),(123,9,76),(9,9,100),(10,11,6),(11,13,1),(12,15,35),(143,15,49),(13,15,57),(114,15,76),(14,16,13),(15,16,15),(127,16,76),(16,17,20),(17,17,37),(18,17,39),(19,17,64),(145,17,67),(136,17,76),(20,18,1),(132,18,76),(21,19,21),(22,20,13),(23,20,16),(24,20,65),(134,20,76),(25,21,13),(26,21,18),(27,21,53),(131,21,76),(28,22,13),(29,22,21),(30,30,5),(31,30,20),(32,30,22),(33,30,53),(34,30,64),(118,30,76),(35,31,1),(36,32,1),(37,34,1),(38,34,13),(39,34,33),(40,35,1),(142,35,75),(129,35,76),(41,36,44),(42,36,47),(43,37,1),(139,37,74),(125,37,76),(146,38,13),(44,38,37),(45,38,64),(126,38,76),(46,39,5),(47,39,21),(48,39,57),(115,39,76),(49,40,1),(50,40,49),(51,41,13),(52,41,35),(53,41,40),(135,41,76),(54,42,35),(55,42,49),(128,42,76),(56,43,13),(57,43,42),(58,44,1),(59,45,13),(60,45,44),(61,47,1),(62,48,13),(63,48,47),(64,49,36),(65,49,58),(66,50,13),(67,50,21),(68,50,35),(69,50,49),(70,50,57),(71,50,59),(133,50,76),(72,51,1),(140,51,74),(141,51,75),(73,52,13),(74,52,19),(75,52,35),(76,52,51),(137,52,76),(77,53,1),(78,54,1),(79,55,13),(80,55,54),(81,56,1),(82,57,13),(83,57,56),(138,57,76),(84,58,1),(85,59,13),(109,59,50),(87,60,5),(88,60,37),(89,60,50),(90,60,57),(130,60,76),(91,61,13),(92,61,36),(93,65,19),(94,65,35),(95,65,50),(117,65,76),(122,66,76),(96,66,100),(97,67,5),(98,67,37),(99,69,35),(100,69,47),(101,70,11),(144,70,76),(102,71,1),(103,71,58),(104,72,13),(105,72,18),(106,73,5),(108,73,19),(107,73,64),(148,101,13),(147,101,35); +INSERT INTO `roleInherit` VALUES (1,1,2),(2,1,3),(3,1,70),(4,2,11),(5,3,11),(6,5,1),(7,5,21),(8,5,33),(124,5,76),(123,9,76),(9,9,100),(10,11,6),(11,13,1),(12,15,35),(143,15,49),(150,15,56),(114,15,76),(14,16,13),(15,16,15),(127,16,76),(16,17,20),(17,17,37),(18,17,39),(19,17,64),(145,17,67),(136,17,76),(20,18,1),(132,18,76),(21,19,21),(22,20,13),(23,20,16),(24,20,65),(134,20,76),(25,21,13),(26,21,18),(27,21,53),(131,21,76),(28,22,13),(29,22,21),(30,30,5),(31,30,20),(32,30,22),(33,30,53),(34,30,64),(118,30,76),(35,31,1),(36,32,1),(37,34,1),(38,34,13),(39,34,33),(40,35,1),(142,35,75),(129,35,76),(41,36,44),(42,36,47),(43,37,1),(139,37,74),(125,37,76),(146,38,13),(44,38,37),(45,38,64),(126,38,76),(46,39,5),(47,39,21),(48,39,57),(115,39,76),(49,40,1),(50,40,49),(51,41,13),(52,41,35),(53,41,40),(135,41,76),(54,42,35),(55,42,49),(128,42,76),(56,43,13),(57,43,42),(58,44,1),(59,45,13),(60,45,44),(61,47,1),(62,48,13),(153,48,35),(63,48,47),(64,49,36),(65,49,58),(66,50,13),(67,50,21),(68,50,35),(69,50,49),(70,50,57),(71,50,59),(133,50,76),(72,51,1),(140,51,74),(141,51,75),(73,52,13),(74,52,19),(75,52,35),(76,52,51),(137,52,76),(77,53,1),(78,54,1),(79,55,13),(80,55,54),(81,56,1),(82,57,13),(83,57,56),(138,57,76),(84,58,1),(85,59,13),(109,59,50),(87,60,5),(88,60,37),(89,60,50),(90,60,57),(130,60,76),(91,61,13),(92,61,36),(93,65,19),(94,65,35),(95,65,50),(117,65,76),(122,66,76),(96,66,100),(97,67,5),(98,67,37),(99,69,35),(152,69,47),(101,70,11),(144,70,76),(102,71,1),(103,71,58),(104,72,13),(105,72,18),(106,73,5),(108,73,19),(107,73,64),(148,101,13),(147,101,35); /*!40000 ALTER TABLE `roleInherit` ENABLE KEYS */; UNLOCK TABLES; @@ -78,7 +78,7 @@ UNLOCK TABLES; LOCK TABLES `roleRole` WRITE; /*!40000 ALTER TABLE `roleRole` DISABLE KEYS */; -INSERT INTO `roleRole` VALUES (39114,1,1),(39115,1,2),(39116,1,3),(39120,1,6),(39119,1,11),(39117,1,70),(39118,1,76),(39031,2,2),(39033,2,6),(39032,2,11),(38916,3,3),(38918,3,6),(38917,3,11),(38888,5,1),(38895,5,2),(38894,5,3),(38887,5,5),(38899,5,6),(38898,5,11),(38892,5,13),(38896,5,18),(38889,5,21),(38890,5,33),(38897,5,53),(38893,5,70),(38891,5,76),(39185,6,6),(39078,9,1),(39075,9,2),(39062,9,3),(39060,9,5),(39083,9,6),(39052,9,9),(39057,9,11),(39110,9,13),(39092,9,15),(39093,9,16),(39059,9,17),(39108,9,18),(39107,9,19),(39094,9,20),(39106,9,21),(39111,9,22),(39081,9,30),(39082,9,31),(39079,9,32),(39089,9,33),(39063,9,34),(39067,9,35),(39104,9,36),(39086,9,37),(39087,9,38),(39058,9,39),(39084,9,40),(39085,9,41),(39064,9,42),(39065,9,43),(39055,9,44),(39056,9,45),(39072,9,47),(39074,9,48),(39101,9,49),(39103,9,50),(39095,9,51),(39096,9,52),(39088,9,53),(39090,9,54),(39091,9,55),(39076,9,56),(39077,9,57),(39099,9,58),(39100,9,59),(39102,9,60),(39105,9,61),(39097,9,62),(39066,9,64),(39098,9,65),(39109,9,66),(39061,9,67),(39073,9,69),(39112,9,70),(39070,9,71),(39071,9,72),(39080,9,73),(39113,9,74),(39069,9,75),(39053,9,76),(39054,9,100),(39068,9,101),(38835,11,6),(38834,11,11),(39649,13,1),(39650,13,2),(39651,13,3),(39655,13,6),(39654,13,11),(39648,13,13),(39652,13,70),(39653,13,76),(39272,15,1),(39279,15,2),(39278,15,3),(39281,15,6),(39280,15,11),(39273,15,13),(39264,15,15),(39265,15,35),(39270,15,36),(39276,15,44),(39275,15,47),(39266,15,49),(39274,15,56),(39267,15,57),(39269,15,58),(39277,15,70),(39271,15,75),(39268,15,76),(39288,16,1),(39293,16,2),(39292,16,3),(39300,16,6),(39299,16,11),(39283,16,13),(39284,16,15),(39282,16,16),(39287,16,35),(39294,16,36),(39298,16,44),(39297,16,47),(39286,16,49),(39296,16,56),(39289,16,57),(39295,16,58),(39291,16,70),(39290,16,75),(39285,16,76),(38861,17,1),(38870,17,2),(38869,17,3),(38859,17,5),(38882,17,6),(38878,17,11),(38864,17,13),(38874,17,15),(38863,17,16),(38852,17,17),(38875,17,18),(38873,17,19),(38853,17,20),(38865,17,21),(38867,17,33),(38872,17,35),(38884,17,36),(38854,17,37),(38855,17,39),(38886,17,44),(38885,17,47),(38881,17,49),(38871,17,50),(38876,17,53),(38877,17,56),(38866,17,57),(38883,17,58),(38879,17,59),(38856,17,64),(38862,17,65),(38857,17,67),(38868,17,70),(38860,17,74),(38880,17,75),(38858,17,76),(39579,18,1),(39582,18,2),(39581,18,3),(39585,18,6),(39584,18,11),(39578,18,18),(39583,18,70),(39580,18,76),(39572,19,1),(39575,19,2),(39574,19,3),(39577,19,6),(39576,19,11),(39568,19,13),(39569,19,18),(39566,19,19),(39567,19,21),(39570,19,53),(39573,19,70),(39571,19,76),(39309,20,1),(39315,20,2),(39314,20,3),(39327,20,6),(39324,20,11),(39302,20,13),(39308,20,15),(39303,20,16),(39320,20,18),(39307,20,19),(39301,20,20),(39316,20,21),(39306,20,35),(39323,20,36),(39326,20,44),(39325,20,47),(39312,20,49),(39310,20,50),(39319,20,53),(39321,20,56),(39311,20,57),(39322,20,58),(39318,20,59),(39304,20,65),(39313,20,70),(39317,20,75),(39305,20,76),(39560,21,1),(39563,21,2),(39562,21,3),(39565,21,6),(39564,21,11),(39556,21,13),(39557,21,18),(39555,21,21),(39558,21,53),(39561,21,70),(39559,21,76),(39660,22,1),(39665,22,2),(39664,22,3),(39667,22,6),(39666,22,11),(39657,22,13),(39659,22,18),(39658,22,21),(39656,22,22),(39661,22,53),(39663,22,70),(39662,22,76),(39157,30,1),(39163,30,2),(39162,30,3),(39146,30,5),(39174,30,6),(39170,30,11),(39154,30,13),(39159,30,15),(39153,30,16),(39160,30,18),(39158,30,19),(39147,30,20),(39156,30,21),(39148,30,22),(39145,30,30),(39155,30,33),(39164,30,35),(39173,30,36),(39176,30,44),(39175,30,47),(39169,30,49),(39165,30,50),(39149,30,53),(39171,30,56),(39168,30,57),(39172,30,58),(39166,30,59),(39150,30,64),(39152,30,65),(39161,30,70),(39167,30,75),(39151,30,76),(39178,31,1),(39179,31,2),(39180,31,3),(39184,31,6),(39183,31,11),(39177,31,31),(39181,31,70),(39182,31,76),(39122,32,1),(39123,32,2),(39124,32,3),(39128,32,6),(39127,32,11),(39121,32,32),(39125,32,70),(39126,32,76),(39245,33,33),(38920,34,1),(38925,34,2),(38924,34,3),(38928,34,6),(38927,34,11),(38921,34,13),(38922,34,33),(38919,34,34),(38923,34,70),(38926,34,76),(38963,35,1),(38968,35,2),(38967,35,3),(38970,35,6),(38969,35,11),(38962,35,35),(38966,35,70),(38964,35,75),(38965,35,76),(39474,36,1),(39476,36,2),(39475,36,3),(39480,36,6),(39479,36,11),(39471,36,36),(39472,36,44),(39473,36,47),(39477,36,70),(39478,36,76),(39217,37,1),(39222,37,2),(39221,37,3),(39224,37,6),(39223,37,11),(39216,37,37),(39220,37,70),(39218,37,74),(39219,37,76),(39231,38,1),(39234,38,2),(39233,38,3),(39236,38,6),(39235,38,11),(39226,38,13),(39227,38,37),(39225,38,38),(39228,38,64),(39232,38,70),(39230,38,74),(39229,38,76),(38844,39,1),(38849,39,2),(38848,39,3),(38837,39,5),(38851,39,6),(38850,39,11),(38842,39,13),(38841,39,18),(38838,39,21),(38843,39,33),(38836,39,39),(38845,39,53),(38846,39,56),(38839,39,57),(38847,39,70),(38840,39,76),(39187,40,1),(39190,40,2),(39189,40,3),(39198,40,6),(39197,40,11),(39192,40,36),(39186,40,40),(39195,40,44),(39194,40,47),(39188,40,49),(39193,40,58),(39191,40,70),(39196,40,76),(39206,41,1),(39210,41,2),(39209,41,3),(39215,41,6),(39214,41,11),(39200,41,13),(39201,41,35),(39207,41,36),(39202,41,40),(39199,41,41),(39213,41,44),(39212,41,47),(39204,41,49),(39211,41,58),(39208,41,70),(39205,41,75),(39203,41,76),(38935,42,1),(38940,42,2),(38939,42,3),(38943,42,6),(38942,42,11),(38930,42,35),(38933,42,36),(38929,42,42),(38937,42,44),(38941,42,47),(38931,42,49),(38936,42,58),(38938,42,70),(38934,42,75),(38932,42,76),(38948,43,1),(38954,43,2),(38953,43,3),(38960,43,6),(38959,43,11),(38945,43,13),(38947,43,35),(38955,43,36),(38946,43,42),(38944,43,43),(38958,43,44),(38957,43,47),(38949,43,49),(38956,43,58),(38952,43,70),(38951,43,75),(38950,43,76),(38817,44,1),(38818,44,2),(38819,44,3),(38823,44,6),(38822,44,11),(38816,44,44),(38820,44,70),(38821,44,76),(38827,45,1),(38829,45,2),(38828,45,3),(38833,45,6),(38832,45,11),(38825,45,13),(38826,45,44),(38824,45,45),(38830,45,70),(38831,45,76),(39003,47,1),(39004,47,2),(39005,47,3),(39009,47,6),(39008,47,11),(39002,47,47),(39006,47,70),(39007,47,76),(39024,48,1),(39026,48,2),(39025,48,3),(39030,48,6),(39029,48,11),(39022,48,13),(39023,48,47),(39021,48,48),(39027,48,70),(39028,48,76),(39415,49,1),(39418,49,2),(39417,49,3),(39421,49,6),(39420,49,11),(39411,49,36),(39414,49,44),(39413,49,47),(39410,49,49),(39412,49,58),(39416,49,70),(39419,49,76),(39463,50,1),(39468,50,2),(39467,50,3),(39470,50,6),(39469,50,11),(39450,50,13),(39462,50,18),(39451,50,21),(39452,50,35),(39459,50,36),(39465,50,44),(39464,50,47),(39453,50,49),(39449,50,50),(39461,50,53),(39457,50,56),(39454,50,57),(39458,50,58),(39455,50,59),(39466,50,70),(39460,50,75),(39456,50,76),(39329,51,1),(39334,51,2),(39333,51,3),(39337,51,6),(39336,51,11),(39328,51,51),(39332,51,70),(39330,51,74),(39331,51,75),(39335,51,76),(39347,52,1),(39352,52,2),(39351,52,3),(39354,52,6),(39353,52,11),(39339,52,13),(39349,52,18),(39340,52,19),(39346,52,21),(39341,52,35),(39342,52,51),(39338,52,52),(39348,52,53),(39350,52,70),(39344,52,74),(39345,52,75),(39343,52,76),(39238,53,1),(39239,53,2),(39240,53,3),(39244,53,6),(39243,53,11),(39237,53,53),(39241,53,70),(39242,53,76),(39247,54,1),(39248,54,2),(39249,54,3),(39253,54,6),(39252,54,11),(39246,54,54),(39250,54,70),(39251,54,76),(39257,55,1),(39259,55,2),(39258,55,3),(39263,55,6),(39262,55,11),(39255,55,13),(39256,55,54),(39254,55,55),(39260,55,70),(39261,55,76),(39035,56,1),(39036,56,2),(39037,56,3),(39041,56,6),(39040,56,11),(39034,56,56),(39038,56,70),(39039,56,76),(39046,57,1),(39049,57,2),(39048,57,3),(39051,57,6),(39050,57,11),(39043,57,13),(39044,57,56),(39042,57,57),(39047,57,70),(39045,57,76),(39381,58,1),(39382,58,2),(39383,58,3),(39387,58,6),(39386,58,11),(39380,58,58),(39384,58,70),(39385,58,76),(39392,59,1),(39402,59,2),(39401,59,3),(39409,59,6),(39408,59,11),(39389,59,13),(39399,59,18),(39391,59,21),(39393,59,35),(39403,59,36),(39407,59,44),(39406,59,47),(39394,59,49),(39390,59,50),(39398,59,53),(39405,59,56),(39395,59,57),(39404,59,58),(39388,59,59),(39400,59,70),(39397,59,75),(39396,59,76),(39432,60,1),(39444,60,2),(39443,60,3),(39423,60,5),(39448,60,6),(39447,60,11),(39428,60,13),(39441,60,18),(39431,60,21),(39430,60,33),(39433,60,35),(39438,60,36),(39424,60,37),(39446,60,44),(39445,60,47),(39434,60,49),(39425,60,50),(39440,60,53),(39436,60,56),(39426,60,57),(39437,60,58),(39435,60,59),(39422,60,60),(39442,60,70),(39429,60,74),(39439,60,75),(39427,60,76),(39485,61,1),(39489,61,2),(39488,61,3),(39492,61,6),(39491,61,11),(39482,61,13),(39483,61,36),(39484,61,44),(39486,61,47),(39481,61,61),(39487,61,70),(39490,61,76),(39355,62,62),(38961,64,64),(39363,65,1),(39372,65,2),(39371,65,3),(39379,65,6),(39378,65,11),(39361,65,13),(39374,65,18),(39357,65,19),(39364,65,21),(39358,65,35),(39369,65,36),(39377,65,44),(39376,65,47),(39365,65,49),(39359,65,50),(39373,65,53),(39375,65,56),(39366,65,57),(39368,65,58),(39367,65,59),(39356,65,65),(39370,65,70),(39362,65,75),(39360,65,76),(39613,66,1),(39609,66,2),(39596,66,3),(39594,66,5),(39618,66,6),(39612,66,9),(39591,66,11),(39644,66,13),(39627,66,15),(39628,66,16),(39593,66,17),(39643,66,18),(39642,66,19),(39629,66,20),(39641,66,21),(39645,66,22),(39616,66,30),(39617,66,31),(39614,66,32),(39624,66,33),(39597,66,34),(39601,66,35),(39639,66,36),(39621,66,37),(39622,66,38),(39592,66,39),(39619,66,40),(39620,66,41),(39598,66,42),(39599,66,43),(39589,66,44),(39590,66,45),(39606,66,47),(39608,66,48),(39636,66,49),(39638,66,50),(39630,66,51),(39631,66,52),(39623,66,53),(39625,66,54),(39626,66,55),(39610,66,56),(39611,66,57),(39634,66,58),(39635,66,59),(39637,66,60),(39640,66,61),(39632,66,62),(39600,66,64),(39633,66,65),(39586,66,66),(39595,66,67),(39607,66,69),(39646,66,70),(39604,66,71),(39605,66,72),(39615,66,73),(39647,66,74),(39603,66,75),(39587,66,76),(39588,66,100),(39602,66,101),(38904,67,1),(38912,67,2),(38911,67,3),(38901,67,5),(38915,67,6),(38914,67,11),(38909,67,13),(38908,67,18),(38903,67,21),(38905,67,33),(38902,67,37),(38913,67,53),(38900,67,67),(38910,67,70),(38907,67,74),(38906,67,76),(39014,69,1),(39018,69,2),(39017,69,3),(39020,69,6),(39019,69,11),(39011,69,35),(39012,69,47),(39010,69,69),(39016,69,70),(39013,69,75),(39015,69,76),(39671,70,6),(39669,70,11),(39668,70,70),(39670,70,76),(38984,71,1),(38987,71,2),(38986,71,3),(38991,71,6),(38990,71,11),(38985,71,58),(38988,71,70),(38983,71,71),(38989,71,76),(38996,72,1),(38998,72,2),(38997,72,3),(39001,72,6),(39000,72,11),(38993,72,13),(38994,72,18),(38999,72,70),(38992,72,72),(38995,72,76),(39135,73,1),(39140,73,2),(39139,73,3),(39130,73,5),(39144,73,6),(39143,73,11),(39137,73,13),(39141,73,18),(39131,73,19),(39134,73,21),(39133,73,33),(39142,73,53),(39132,73,64),(39138,73,70),(39129,73,73),(39136,73,76),(39672,74,74),(38981,75,75),(38982,76,76),(39519,100,1),(39515,100,2),(39501,100,3),(39499,100,5),(39524,100,6),(39518,100,9),(39496,100,11),(39551,100,13),(39533,100,15),(39534,100,16),(39498,100,17),(39549,100,18),(39548,100,19),(39535,100,20),(39547,100,21),(39552,100,22),(39522,100,30),(39523,100,31),(39520,100,32),(39530,100,33),(39502,100,34),(39506,100,35),(39545,100,36),(39527,100,37),(39528,100,38),(39497,100,39),(39525,100,40),(39526,100,41),(39503,100,42),(39504,100,43),(39494,100,44),(39495,100,45),(39512,100,47),(39514,100,48),(39542,100,49),(39544,100,50),(39536,100,51),(39537,100,52),(39529,100,53),(39531,100,54),(39532,100,55),(39516,100,56),(39517,100,57),(39540,100,58),(39541,100,59),(39543,100,60),(39546,100,61),(39538,100,62),(39505,100,64),(39539,100,65),(39550,100,66),(39500,100,67),(39513,100,69),(39553,100,70),(39510,100,71),(39511,100,72),(39521,100,73),(39554,100,74),(39508,100,75),(39509,100,76),(39493,100,100),(39507,100,101),(38973,101,1),(38978,101,2),(38977,101,3),(38980,101,6),(38979,101,11),(38972,101,35),(38976,101,70),(38974,101,75),(38975,101,76),(38971,101,101); +INSERT INTO `roleRole` VALUES (44924,1,1),(44925,1,2),(44926,1,3),(44930,1,6),(44929,1,11),(44927,1,70),(44928,1,76),(44841,2,2),(44843,2,6),(44842,2,11),(44723,3,3),(44725,3,6),(44724,3,11),(44695,5,1),(44702,5,2),(44701,5,3),(44694,5,5),(44706,5,6),(44705,5,11),(44699,5,13),(44703,5,18),(44696,5,21),(44697,5,33),(44704,5,53),(44700,5,70),(44698,5,76),(44995,6,6),(44888,9,1),(44885,9,2),(44872,9,3),(44870,9,5),(44893,9,6),(44862,9,9),(44867,9,11),(44920,9,13),(44902,9,15),(44903,9,16),(44869,9,17),(44918,9,18),(44917,9,19),(44904,9,20),(44916,9,21),(44921,9,22),(44891,9,30),(44892,9,31),(44889,9,32),(44899,9,33),(44873,9,34),(44877,9,35),(44914,9,36),(44896,9,37),(44897,9,38),(44868,9,39),(44894,9,40),(44895,9,41),(44874,9,42),(44875,9,43),(44865,9,44),(44866,9,45),(44882,9,47),(44884,9,48),(44911,9,49),(44913,9,50),(44905,9,51),(44906,9,52),(44898,9,53),(44900,9,54),(44901,9,55),(44886,9,56),(44887,9,57),(44909,9,58),(44910,9,59),(44912,9,60),(44915,9,61),(44907,9,62),(44876,9,64),(44908,9,65),(44919,9,66),(44871,9,67),(44883,9,69),(44922,9,70),(44880,9,71),(44881,9,72),(44890,9,73),(44923,9,74),(44879,9,75),(44863,9,76),(44864,9,100),(44878,9,101),(44642,11,6),(44641,11,11),(45456,13,1),(45457,13,2),(45458,13,3),(45462,13,6),(45461,13,11),(45455,13,13),(45459,13,70),(45460,13,76),(45082,15,1),(45086,15,2),(45085,15,3),(45089,15,6),(45088,15,11),(45074,15,15),(45075,15,35),(45080,15,36),(45083,15,44),(45087,15,47),(45076,15,49),(45077,15,56),(45079,15,58),(45084,15,70),(45081,15,75),(45078,15,76),(45096,16,1),(45101,16,2),(45100,16,3),(45107,16,6),(45106,16,11),(45091,16,13),(45092,16,15),(45090,16,16),(45095,16,35),(45102,16,36),(45105,16,44),(45104,16,47),(45094,16,49),(45097,16,56),(45103,16,58),(45099,16,70),(45098,16,75),(45093,16,76),(44668,17,1),(44677,17,2),(44676,17,3),(44666,17,5),(44689,17,6),(44685,17,11),(44671,17,13),(44681,17,15),(44670,17,16),(44659,17,17),(44682,17,18),(44680,17,19),(44660,17,20),(44672,17,21),(44674,17,33),(44679,17,35),(44691,17,36),(44661,17,37),(44662,17,39),(44693,17,44),(44692,17,47),(44688,17,49),(44678,17,50),(44683,17,53),(44684,17,56),(44673,17,57),(44690,17,58),(44686,17,59),(44663,17,64),(44669,17,65),(44664,17,67),(44675,17,70),(44667,17,74),(44687,17,75),(44665,17,76),(45386,18,1),(45389,18,2),(45388,18,3),(45392,18,6),(45391,18,11),(45385,18,18),(45390,18,70),(45387,18,76),(45379,19,1),(45382,19,2),(45381,19,3),(45384,19,6),(45383,19,11),(45375,19,13),(45376,19,18),(45373,19,19),(45374,19,21),(45377,19,53),(45380,19,70),(45378,19,76),(45116,20,1),(45122,20,2),(45121,20,3),(45134,20,6),(45131,20,11),(45109,20,13),(45115,20,15),(45110,20,16),(45128,20,18),(45114,20,19),(45108,20,20),(45123,20,21),(45113,20,35),(45130,20,36),(45133,20,44),(45132,20,47),(45119,20,49),(45117,20,50),(45127,20,53),(45118,20,56),(45125,20,57),(45129,20,58),(45126,20,59),(45111,20,65),(45120,20,70),(45124,20,75),(45112,20,76),(45367,21,1),(45370,21,2),(45369,21,3),(45372,21,6),(45371,21,11),(45363,21,13),(45364,21,18),(45362,21,21),(45365,21,53),(45368,21,70),(45366,21,76),(45467,22,1),(45472,22,2),(45471,22,3),(45474,22,6),(45473,22,11),(45464,22,13),(45466,22,18),(45465,22,21),(45463,22,22),(45468,22,53),(45470,22,70),(45469,22,76),(44967,30,1),(44973,30,2),(44972,30,3),(44956,30,5),(44984,30,6),(44981,30,11),(44964,30,13),(44969,30,15),(44963,30,16),(44970,30,18),(44968,30,19),(44957,30,20),(44966,30,21),(44958,30,22),(44955,30,30),(44965,30,33),(44974,30,35),(44983,30,36),(44986,30,44),(44985,30,47),(44980,30,49),(44975,30,50),(44959,30,53),(44979,30,56),(44977,30,57),(44982,30,58),(44976,30,59),(44960,30,64),(44962,30,65),(44971,30,70),(44978,30,75),(44961,30,76),(44988,31,1),(44989,31,2),(44990,31,3),(44994,31,6),(44993,31,11),(44987,31,31),(44991,31,70),(44992,31,76),(44932,32,1),(44933,32,2),(44934,32,3),(44938,32,6),(44937,32,11),(44931,32,32),(44935,32,70),(44936,32,76),(45055,33,33),(44727,34,1),(44732,34,2),(44731,34,3),(44735,34,6),(44734,34,11),(44728,34,13),(44729,34,33),(44726,34,34),(44730,34,70),(44733,34,76),(44770,35,1),(44775,35,2),(44774,35,3),(44777,35,6),(44776,35,11),(44769,35,35),(44773,35,70),(44771,35,75),(44772,35,76),(45281,36,1),(45283,36,2),(45282,36,3),(45287,36,6),(45286,36,11),(45278,36,36),(45279,36,44),(45280,36,47),(45284,36,70),(45285,36,76),(45027,37,1),(45032,37,2),(45031,37,3),(45034,37,6),(45033,37,11),(45026,37,37),(45030,37,70),(45028,37,74),(45029,37,76),(45041,38,1),(45044,38,2),(45043,38,3),(45046,38,6),(45045,38,11),(45036,38,13),(45037,38,37),(45035,38,38),(45038,38,64),(45042,38,70),(45040,38,74),(45039,38,76),(44651,39,1),(44656,39,2),(44655,39,3),(44644,39,5),(44658,39,6),(44657,39,11),(44649,39,13),(44648,39,18),(44645,39,21),(44650,39,33),(44643,39,39),(44652,39,53),(44653,39,56),(44646,39,57),(44654,39,70),(44647,39,76),(44997,40,1),(45000,40,2),(44999,40,3),(45008,40,6),(45007,40,11),(45002,40,36),(44996,40,40),(45005,40,44),(45004,40,47),(44998,40,49),(45003,40,58),(45001,40,70),(45006,40,76),(45016,41,1),(45020,41,2),(45019,41,3),(45025,41,6),(45024,41,11),(45010,41,13),(45011,41,35),(45017,41,36),(45012,41,40),(45009,41,41),(45023,41,44),(45022,41,47),(45014,41,49),(45021,41,58),(45018,41,70),(45015,41,75),(45013,41,76),(44742,42,1),(44747,42,2),(44746,42,3),(44750,42,6),(44749,42,11),(44737,42,35),(44740,42,36),(44736,42,42),(44744,42,44),(44748,42,47),(44738,42,49),(44743,42,58),(44745,42,70),(44741,42,75),(44739,42,76),(44755,43,1),(44761,43,2),(44760,43,3),(44767,43,6),(44766,43,11),(44752,43,13),(44754,43,35),(44762,43,36),(44753,43,42),(44751,43,43),(44765,43,44),(44764,43,47),(44756,43,49),(44763,43,58),(44759,43,70),(44758,43,75),(44757,43,76),(44624,44,1),(44625,44,2),(44626,44,3),(44630,44,6),(44629,44,11),(44623,44,44),(44627,44,70),(44628,44,76),(44634,45,1),(44636,45,2),(44635,45,3),(44640,45,6),(44639,45,11),(44632,45,13),(44633,45,44),(44631,45,45),(44637,45,70),(44638,45,76),(44811,47,1),(44812,47,2),(44813,47,3),(44817,47,6),(44816,47,11),(44810,47,47),(44814,47,70),(44815,47,76),(44835,48,1),(44838,48,2),(44837,48,3),(44840,48,6),(44839,48,11),(44830,48,13),(44831,48,35),(44832,48,47),(44829,48,48),(44836,48,70),(44834,48,75),(44833,48,76),(45222,49,1),(45225,49,2),(45224,49,3),(45228,49,6),(45227,49,11),(45218,49,36),(45221,49,44),(45220,49,47),(45217,49,49),(45219,49,58),(45223,49,70),(45226,49,76),(45270,50,1),(45275,50,2),(45274,50,3),(45277,50,6),(45276,50,11),(45257,50,13),(45269,50,18),(45258,50,21),(45259,50,35),(45266,50,36),(45272,50,44),(45271,50,47),(45260,50,49),(45256,50,50),(45268,50,53),(45264,50,56),(45261,50,57),(45265,50,58),(45262,50,59),(45273,50,70),(45267,50,75),(45263,50,76),(45136,51,1),(45141,51,2),(45140,51,3),(45144,51,6),(45143,51,11),(45135,51,51),(45139,51,70),(45137,51,74),(45138,51,75),(45142,51,76),(45154,52,1),(45159,52,2),(45158,52,3),(45161,52,6),(45160,52,11),(45146,52,13),(45156,52,18),(45147,52,19),(45153,52,21),(45148,52,35),(45149,52,51),(45145,52,52),(45155,52,53),(45157,52,70),(45151,52,74),(45152,52,75),(45150,52,76),(45048,53,1),(45049,53,2),(45050,53,3),(45054,53,6),(45053,53,11),(45047,53,53),(45051,53,70),(45052,53,76),(45057,54,1),(45058,54,2),(45059,54,3),(45063,54,6),(45062,54,11),(45056,54,54),(45060,54,70),(45061,54,76),(45067,55,1),(45069,55,2),(45068,55,3),(45073,55,6),(45072,55,11),(45065,55,13),(45066,55,54),(45064,55,55),(45070,55,70),(45071,55,76),(44845,56,1),(44846,56,2),(44847,56,3),(44851,56,6),(44850,56,11),(44844,56,56),(44848,56,70),(44849,56,76),(44856,57,1),(44859,57,2),(44858,57,3),(44861,57,6),(44860,57,11),(44853,57,13),(44854,57,56),(44852,57,57),(44857,57,70),(44855,57,76),(45188,58,1),(45189,58,2),(45190,58,3),(45194,58,6),(45193,58,11),(45187,58,58),(45191,58,70),(45192,58,76),(45199,59,1),(45209,59,2),(45208,59,3),(45216,59,6),(45215,59,11),(45196,59,13),(45206,59,18),(45198,59,21),(45200,59,35),(45210,59,36),(45214,59,44),(45213,59,47),(45201,59,49),(45197,59,50),(45205,59,53),(45212,59,56),(45202,59,57),(45211,59,58),(45195,59,59),(45207,59,70),(45204,59,75),(45203,59,76),(45239,60,1),(45251,60,2),(45250,60,3),(45230,60,5),(45255,60,6),(45254,60,11),(45235,60,13),(45248,60,18),(45238,60,21),(45237,60,33),(45240,60,35),(45245,60,36),(45231,60,37),(45253,60,44),(45252,60,47),(45241,60,49),(45232,60,50),(45247,60,53),(45243,60,56),(45233,60,57),(45244,60,58),(45242,60,59),(45229,60,60),(45249,60,70),(45236,60,74),(45246,60,75),(45234,60,76),(45292,61,1),(45296,61,2),(45295,61,3),(45299,61,6),(45298,61,11),(45289,61,13),(45290,61,36),(45291,61,44),(45293,61,47),(45288,61,61),(45294,61,70),(45297,61,76),(45162,62,62),(44768,64,64),(45170,65,1),(45179,65,2),(45178,65,3),(45186,65,6),(45185,65,11),(45168,65,13),(45181,65,18),(45164,65,19),(45171,65,21),(45165,65,35),(45176,65,36),(45184,65,44),(45183,65,47),(45172,65,49),(45166,65,50),(45180,65,53),(45182,65,56),(45173,65,57),(45175,65,58),(45174,65,59),(45163,65,65),(45177,65,70),(45169,65,75),(45167,65,76),(45420,66,1),(45416,66,2),(45403,66,3),(45401,66,5),(45425,66,6),(45419,66,9),(45398,66,11),(45451,66,13),(45434,66,15),(45435,66,16),(45400,66,17),(45450,66,18),(45449,66,19),(45436,66,20),(45448,66,21),(45452,66,22),(45423,66,30),(45424,66,31),(45421,66,32),(45431,66,33),(45404,66,34),(45408,66,35),(45446,66,36),(45428,66,37),(45429,66,38),(45399,66,39),(45426,66,40),(45427,66,41),(45405,66,42),(45406,66,43),(45396,66,44),(45397,66,45),(45413,66,47),(45415,66,48),(45443,66,49),(45445,66,50),(45437,66,51),(45438,66,52),(45430,66,53),(45432,66,54),(45433,66,55),(45417,66,56),(45418,66,57),(45441,66,58),(45442,66,59),(45444,66,60),(45447,66,61),(45439,66,62),(45407,66,64),(45440,66,65),(45393,66,66),(45402,66,67),(45414,66,69),(45453,66,70),(45411,66,71),(45412,66,72),(45422,66,73),(45454,66,74),(45410,66,75),(45394,66,76),(45395,66,100),(45409,66,101),(44711,67,1),(44719,67,2),(44718,67,3),(44708,67,5),(44722,67,6),(44721,67,11),(44716,67,13),(44715,67,18),(44710,67,21),(44712,67,33),(44709,67,37),(44720,67,53),(44707,67,67),(44717,67,70),(44714,67,74),(44713,67,76),(44822,69,1),(44826,69,2),(44825,69,3),(44828,69,6),(44827,69,11),(44819,69,35),(44820,69,47),(44818,69,69),(44824,69,70),(44821,69,75),(44823,69,76),(45478,70,6),(45476,70,11),(45475,70,70),(45477,70,76),(44792,71,1),(44795,71,2),(44794,71,3),(44799,71,6),(44798,71,11),(44793,71,58),(44796,71,70),(44791,71,71),(44797,71,76),(44804,72,1),(44806,72,2),(44805,72,3),(44809,72,6),(44808,72,11),(44801,72,13),(44802,72,18),(44807,72,70),(44800,72,72),(44803,72,76),(44945,73,1),(44950,73,2),(44949,73,3),(44940,73,5),(44954,73,6),(44953,73,11),(44947,73,13),(44951,73,18),(44941,73,19),(44944,73,21),(44943,73,33),(44952,73,53),(44942,73,64),(44948,73,70),(44939,73,73),(44946,73,76),(45479,74,74),(44789,75,75),(44790,76,76),(45326,100,1),(45322,100,2),(45308,100,3),(45306,100,5),(45331,100,6),(45325,100,9),(45303,100,11),(45358,100,13),(45340,100,15),(45341,100,16),(45305,100,17),(45356,100,18),(45355,100,19),(45342,100,20),(45354,100,21),(45359,100,22),(45329,100,30),(45330,100,31),(45327,100,32),(45337,100,33),(45309,100,34),(45313,100,35),(45352,100,36),(45334,100,37),(45335,100,38),(45304,100,39),(45332,100,40),(45333,100,41),(45310,100,42),(45311,100,43),(45301,100,44),(45302,100,45),(45319,100,47),(45321,100,48),(45349,100,49),(45351,100,50),(45343,100,51),(45344,100,52),(45336,100,53),(45338,100,54),(45339,100,55),(45323,100,56),(45324,100,57),(45347,100,58),(45348,100,59),(45350,100,60),(45353,100,61),(45345,100,62),(45312,100,64),(45346,100,65),(45357,100,66),(45307,100,67),(45320,100,69),(45360,100,70),(45317,100,71),(45318,100,72),(45328,100,73),(45361,100,74),(45315,100,75),(45316,100,76),(45300,100,100),(45314,100,101),(44782,101,1),(44786,101,2),(44785,101,3),(44788,101,6),(44787,101,11),(44779,101,13),(44780,101,35),(44784,101,70),(44781,101,75),(44783,101,76),(44778,101,101); /*!40000 ALTER TABLE `roleRole` ENABLE KEYS */; UNLOCK TABLES; @@ -120,9 +120,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-06-22 14:40:03 +-- Dump completed on 2021-08-31 14:42:28 USE `salix`; --- MariaDB dump 10.19 Distrib 10.5.10-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64) -- -- Host: db.verdnatura.es Database: salix -- ------------------------------------------------------ @@ -144,7 +144,7 @@ USE `salix`; LOCK TABLES `ACL` WRITE; /*!40000 ALTER TABLE `ACL` DISABLE KEYS */; -INSERT INTO `ACL` VALUES (1,'Account','*','*','ALLOW','ROLE','employee'),(3,'Address','*','*','ALLOW','ROLE','employee'),(5,'AgencyService','*','READ','ALLOW','ROLE','employee'),(7,'Client','*','*','ALLOW','ROLE','employee'),(9,'ClientObservation','*','*','ALLOW','ROLE','employee'),(11,'ContactChannel','*','READ','ALLOW','ROLE','trainee'),(13,'Employee','*','READ','ALLOW','ROLE','employee'),(14,'PayMethod','*','READ','ALLOW','ROLE','trainee'),(16,'FakeProduction','*','READ','ALLOW','ROLE','employee'),(17,'Warehouse','* ','READ','ALLOW','ROLE','trainee'),(18,'State','*','READ','ALLOW','ROLE','employee'),(20,'TicketState','*','*','ALLOW','ROLE','employee'),(24,'Delivery','*','READ','ALLOW','ROLE','employee'),(25,'Zone','*','READ','ALLOW','ROLE','employee'),(26,'ClientCredit','*','*','ALLOW','ROLE','employee'),(27,'ClientCreditLimit','*','READ','ALLOW','ROLE','trainee'),(30,'GreugeType','*','READ','ALLOW','ROLE','trainee'),(31,'Mandate','*','READ','ALLOW','ROLE','trainee'),(32,'MandateType','*','READ','ALLOW','ROLE','trainee'),(33,'Company','*','READ','ALLOW','ROLE','trainee'),(34,'Greuge','*','READ','ALLOW','ROLE','trainee'),(35,'AddressObservation','*','*','ALLOW','ROLE','employee'),(36,'ObservationType','*','*','ALLOW','ROLE','employee'),(37,'Greuge','*','WRITE','ALLOW','ROLE','employee'),(38,'AgencyMode','*','READ','ALLOW','ROLE','employee'),(39,'ItemTag','*','WRITE','ALLOW','ROLE','buyer'),(40,'ItemBotanical','*','WRITE','ALLOW','ROLE','buyer'),(41,'ItemBotanical','*','READ','ALLOW','ROLE','employee'),(42,'ItemPlacement','*','WRITE','ALLOW','ROLE','buyer'),(43,'ItemPlacement','*','WRITE','ALLOW','ROLE','replenisher'),(44,'ItemPlacement','*','READ','ALLOW','ROLE','employee'),(45,'ItemBarcode','*','READ','ALLOW','ROLE','employee'),(46,'ItemBarcode','*','WRITE','ALLOW','ROLE','buyer'),(47,'ItemBarcode','*','WRITE','ALLOW','ROLE','replenisher'),(48,'ItemNiche','*','READ','ALLOW','ROLE','employee'),(49,'ItemNiche','*','WRITE','ALLOW','ROLE','buyer'),(50,'ItemNiche','*','WRITE','ALLOW','ROLE','replenisher'),(51,'ItemTag','*','READ','ALLOW','ROLE','employee'),(53,'Item','*','READ','ALLOW','ROLE','employee'),(54,'Item','*','WRITE','ALLOW','ROLE','buyer'),(55,'Recovery','*','READ','ALLOW','ROLE','trainee'),(56,'Recovery','*','WRITE','ALLOW','ROLE','administrative'),(58,'CreditClassification','*','*','ALLOW','ROLE','insurance'),(60,'CreditInsurance','*','*','ALLOW','ROLE','insurance'),(61,'InvoiceOut','*','READ','ALLOW','ROLE','employee'),(62,'Ticket','*','*','ALLOW','ROLE','employee'),(63,'TicketObservation','*','*','ALLOW','ROLE','employee'),(64,'Route','*','READ','ALLOW','ROLE','employee'),(65,'Sale','*','READ','ALLOW','ROLE','employee'),(66,'TicketTracking','*','READ','ALLOW','ROLE','employee'),(68,'TicketPackaging','*','*','ALLOW','ROLE','employee'),(69,'Packaging','*','READ','ALLOW','ROLE','employee'),(70,'Packaging','*','WRITE','ALLOW','ROLE','logistic'),(71,'SaleChecked','*','READ','ALLOW','ROLE','employee'),(72,'SaleComponent','*','READ','ALLOW','ROLE','employee'),(73,'Expedition','*','READ','ALLOW','ROLE','employee'),(74,'Expedition','*','WRITE','ALLOW','ROLE','deliveryBoss'),(75,'Expedition','*','WRITE','ALLOW','ROLE','production'),(76,'AnnualAverageInvoiced','*','READ','ALLOW','ROLE','employee'),(77,'WorkerMana','*','READ','ALLOW','ROLE','employee'),(78,'TicketTracking','*','WRITE','ALLOW','ROLE','production'),(79,'TicketTracking','changeState','*','ALLOW','ROLE','employee'),(80,'Sale','deleteSales','*','ALLOW','ROLE','employee'),(81,'Sale','moveToTicket','*','ALLOW','ROLE','employee'),(82,'Sale','updateQuantity','*','ALLOW','ROLE','employee'),(83,'Sale','updatePrice','*','ALLOW','ROLE','employee'),(84,'Sale','updateDiscount','*','ALLOW','ROLE','employee'),(85,'SaleTracking','*','READ','ALLOW','ROLE','employee'),(86,'Order','*','*','ALLOW','ROLE','employee'),(87,'OrderRow','*','*','ALLOW','ROLE','employee'),(88,'ClientContact','*','*','ALLOW','ROLE','employee'),(89,'Sale','moveToNewTicket','*','ALLOW','ROLE','employee'),(90,'Sale','reserve','*','ALLOW','ROLE','employee'),(91,'TicketWeekly','*','READ','ALLOW','ROLE','employee'),(94,'Agency','landsThatDay','*','ALLOW','ROLE','employee'),(96,'ClaimEnd','*','READ','ALLOW','ROLE','employee'),(97,'ClaimEnd','*','WRITE','ALLOW','ROLE','claimManager'),(98,'ClaimBeginning','*','*','ALLOW','ROLE','employee'),(99,'ClaimDevelopment','*','READ','ALLOW','ROLE','employee'),(100,'ClaimDevelopment','*','WRITE','ALLOW','ROLE','claimManager'),(101,'Claim','*','*','ALLOW','ROLE','employee'),(102,'Claim','createFromSales','*','ALLOW','ROLE','employee'),(103,'ClaimEnd','importTicketSales','WRITE','ALLOW','ROLE','claimManager'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','WRITE','ALLOW','ROLE','marketingBoss'),(107,'ItemNiche','*','WRITE','ALLOW','ROLE','marketingBoss'),(108,'ItemPlacement','*','WRITE','ALLOW','ROLE','marketingBoss'),(109,'UserConfig','*','*','ALLOW','ROLE','employee'),(110,'Bank','*','READ','ALLOW','ROLE','trainee'),(111,'ClientLog','*','READ','ALLOW','ROLE','trainee'),(112,'Defaulter','*','READ','ALLOW','ROLE','employee'),(113,'ClientRisk','*','READ','ALLOW','ROLE','trainee'),(114,'Receipt','*','READ','ALLOW','ROLE','trainee'),(115,'Receipt','*','WRITE','ALLOW','ROLE','administrative'),(116,'BankEntity','*','*','ALLOW','ROLE','employee'),(117,'ClientSample','*','*','ALLOW','ROLE','employee'),(118,'WorkerTeam','*','*','ALLOW','ROLE','salesPerson'),(119,'Travel','*','READ','ALLOW','ROLE','employee'),(120,'Travel','*','WRITE','ALLOW','ROLE','buyer'),(121,'Item','regularize','*','ALLOW','ROLE','employee'),(122,'TicketRequest','*','*','ALLOW','ROLE','employee'),(123,'Worker','*','*','ALLOW','ROLE','employee'),(124,'Client','confirmTransaction','WRITE','ALLOW','ROLE','administrative'),(125,'Agency','getAgenciesWithWarehouse','*','ALLOW','ROLE','employee'),(126,'Client','activeWorkersWithRole','*','ALLOW','ROLE','employee'),(127,'TicketLog','*','READ','ALLOW','ROLE','employee'),(129,'TicketService','*','*','ALLOW','ROLE','employee'),(130,'Expedition','*','WRITE','ALLOW','ROLE','packager'),(131,'CreditInsurance','*','READ','ALLOW','ROLE','trainee'),(132,'CreditClassification','*','READ','ALLOW','ROLE','trainee'),(133,'ItemTag','*','WRITE','ALLOW','ROLE','marketingBoss'),(135,'ZoneGeo','*','READ','ALLOW','ROLE','employee'),(136,'ZoneCalendar','*','READ','ALLOW','ROLE','employee'),(137,'ZoneIncluded','*','READ','ALLOW','ROLE','employee'),(138,'LabourHoliday','*','READ','ALLOW','ROLE','employee'),(139,'LabourHolidayLegend','*','READ','ALLOW','ROLE','employee'),(140,'LabourHolidayType','*','READ','ALLOW','ROLE','employee'),(141,'Zone','*','*','ALLOW','ROLE','deliveryBoss'),(142,'ZoneCalendar','*','WRITE','ALLOW','ROLE','deliveryBoss'),(143,'ZoneIncluded','*','*','ALLOW','ROLE','deliveryBoss'),(144,'Stowaway','*','*','ALLOW','ROLE','employee'),(145,'Ticket','getPossibleStowaways','READ','ALLOW','ROLE','employee'),(147,'UserConfigView','*','*','ALLOW','ROLE','employee'),(148,'UserConfigView','*','*','ALLOW','ROLE','employee'),(149,'Sip','*','READ','ALLOW','ROLE','employee'),(150,'Sip','*','WRITE','ALLOW','ROLE','hr'),(151,'Department','*','READ','ALLOW','ROLE','employee'),(152,'Department','*','WRITE','ALLOW','ROLE','hr'),(153,'Route','*','READ','ALLOW','ROLE','employee'),(154,'Route','*','WRITE','ALLOW','ROLE','delivery'),(155,'Calendar','*','READ','ALLOW','ROLE','hr'),(156,'WorkerLabour','*','READ','ALLOW','ROLE','hr'),(157,'Calendar','absences','READ','ALLOW','ROLE','employee'),(158,'ItemTag','*','WRITE','ALLOW','ROLE','accessory'),(160,'TicketServiceType','*','READ','ALLOW','ROLE','employee'),(161,'TicketConfig','*','READ','ALLOW','ROLE','employee'),(162,'InvoiceOut','delete','WRITE','ALLOW','ROLE','invoicing'),(163,'InvoiceOut','book','WRITE','ALLOW','ROLE','invoicing'),(164,'InvoiceOut','regenerate','WRITE','ALLOW','ROLE','invoicing'),(165,'TicketDms','*','READ','ALLOW','ROLE','employee'),(167,'Worker','isSubordinate','READ','ALLOW','ROLE','employee'),(168,'Worker','mySubordinates','READ','ALLOW','ROLE','employee'),(169,'WorkerTimeControl','filter','READ','ALLOW','ROLE','employee'),(170,'WorkerTimeControl','addTime','WRITE','ALLOW','ROLE','employee'),(171,'TicketServiceType','*','WRITE','ALLOW','ROLE','administrative'),(172,'Sms','*','READ','ALLOW','ROLE','employee'),(173,'Sms','send','WRITE','ALLOW','ROLE','employee'),(174,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(175,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(176,'Device','*','*','ALLOW','ROLE','employee'),(177,'Device','*','*','ALLOW','ROLE','employee'),(178,'WorkerTimeControl','*','*','ALLOW','ROLE','employee'),(179,'ItemLog','*','READ','ALLOW','ROLE','employee'),(180,'RouteLog','*','READ','ALLOW','ROLE','employee'),(181,'Dms','removeFile','WRITE','ALLOW','ROLE','employee'),(182,'Dms','uploadFile','WRITE','ALLOW','ROLE','employee'),(183,'Dms','downloadFile','READ','ALLOW','ROLE','employee'),(184,'Client','uploadFile','WRITE','ALLOW','ROLE','employee'),(185,'ClientDms','removeFile','WRITE','ALLOW','ROLE','employee'),(186,'ClientDms','*','READ','ALLOW','ROLE','trainee'),(187,'Ticket','uploadFile','WRITE','ALLOW','ROLE','employee'),(188,'TicketDms','removeFile','WRITE','ALLOW','ROLE','employee'),(189,'TicketDms','*','READ','ALLOW','ROLE','employee'),(190,'Route','updateVolume','WRITE','ALLOW','ROLE','deliveryBoss'),(191,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(192,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(194,'Postcode','*','WRITE','ALLOW','ROLE','deliveryBoss'),(195,'Ticket','addSale','WRITE','ALLOW','ROLE','employee'),(196,'Dms','updateFile','WRITE','ALLOW','ROLE','employee'),(197,'Dms','*','READ','ALLOW','ROLE','trainee'),(198,'ClaimDms','removeFile','WRITE','ALLOW','ROLE','employee'),(199,'ClaimDms','*','READ','ALLOW','ROLE','employee'),(200,'Claim','uploadFile','WRITE','ALLOW','ROLE','employee'),(201,'Sale','updateConcept','WRITE','ALLOW','ROLE','employee'),(202,'Claim','updateClaimAction','WRITE','ALLOW','ROLE','claimManager'),(203,'UserPhone','*','*','ALLOW','ROLE','employee'),(204,'WorkerDms','removeFile','WRITE','ALLOW','ROLE','hr'),(205,'WorkerDms','*','READ','ALLOW','ROLE','hr'),(206,'Chat','*','*','ALLOW','ROLE','employee'),(207,'Chat','sendMessage','*','ALLOW','ROLE','employee'),(208,'Sale','recalculatePrice','WRITE','ALLOW','ROLE','employee'),(209,'Ticket','recalculateComponents','WRITE','ALLOW','ROLE','employee'),(211,'TravelLog','*','READ','ALLOW','ROLE','buyer'),(212,'Thermograph','*','*','ALLOW','ROLE','buyer'),(213,'TravelThermograph','*','WRITE','ALLOW','ROLE','buyer'),(214,'Entry','*','*','ALLOW','ROLE','buyer'),(215,'TicketWeekly','*','WRITE','ALLOW','ROLE','buyer'),(216,'TravelThermograph','*','READ','ALLOW','ROLE','employee'),(218,'Intrastat','*','*','ALLOW','ROLE','buyer'),(219,'Account','acl','READ','ALLOW','ROLE','account'),(220,'Account','getCurrentUserData','READ','ALLOW','ROLE','account'),(221,'UserConfig','getUserConfig','READ','ALLOW','ROLE','account'),(222,'Client','*','READ','ALLOW','ROLE','trainee'),(226,'ClientObservation','*','READ','ALLOW','ROLE','trainee'),(227,'Address','*','READ','ALLOW','ROLE','trainee'),(228,'AddressObservation','*','READ','ALLOW','ROLE','trainee'),(230,'ClientCredit','*','READ','ALLOW','ROLE','trainee'),(231,'ClientContact','*','READ','ALLOW','ROLE','trainee'),(232,'ClientSample','*','READ','ALLOW','ROLE','trainee'),(233,'EntryLog','*','READ','ALLOW','ROLE','buyer'),(234,'WorkerLog','*','READ','ALLOW','ROLE','salesAssistant'),(235,'CustomsAgent','*','*','ALLOW','ROLE','employee'),(236,'Buy','*','*','ALLOW','ROLE','buyer'),(237,'WorkerDms','filter','*','ALLOW','ROLE','employee'),(238,'Town','*','WRITE','ALLOW','ROLE','deliveryBoss'),(239,'Province','*','WRITE','ALLOW','ROLE','deliveryBoss'),(240,'supplier','*','WRITE','ALLOW','ROLE','administrative'),(241,'SupplierContact','*','WRITE','ALLOW','ROLE','administrative'),(242,'supplier','*','WRITE','ALLOW','ROLE','administrative'),(243,'SupplierContact','*','WRITE','ALLOW','ROLE','administrative'),(244,'supplier','*','WRITE','ALLOW','ROLE','administrative'),(245,'SupplierContact','*','WRITE','ALLOW','ROLE','administrative'),(246,'Account','changePassword','*','ALLOW','ROLE','account'),(247,'UserAccount','exists','*','ALLOW','ROLE','account'),(248,'RoleMapping','*','READ','ALLOW','ROLE','account'),(249,'UserPassword','*','READ','ALLOW','ROLE','account'),(250,'Town','*','WRITE','ALLOW','ROLE','deliveryBoss'),(251,'Province','*','WRITE','ALLOW','ROLE','deliveryBoss'),(252,'Supplier','*','READ','ALLOW','ROLE','employee'),(253,'Supplier','*','WRITE','ALLOW','ROLE','administrative'),(254,'SupplierLog','*','READ','ALLOW','ROLE','employee'),(255,'SupplierContact','*','WRITE','ALLOW','ROLE','administrative'),(256,'Image','*','WRITE','ALLOW','ROLE','employee'),(257,'FixedPrice','*','*','ALLOW','ROLE','buyer'),(258,'PayDem','*','READ','ALLOW','ROLE','employee'),(259,'Client','createReceipt','*','ALLOW','ROLE','salesAssistant'),(260,'PrintServerQueue','*','WRITE','ALLOW','ROLE','employee'),(261,'SupplierAccount','*','*','ALLOW','ROLE','administrative'),(262,'Entry','*','*','ALLOW','ROLE','administrative'),(263,'InvoiceIn','*','*','ALLOW','ROLE','administrative'),(264,'StarredModule','*','*','ALLOW','ROLE','employee'),(265,'ItemBotanical','*','WRITE','ALLOW','ROLE','logisticBoss'),(266,'ZoneLog','*','READ','ALLOW','ROLE','employee'),(267,'Genus','*','WRITE','ALLOW','ROLE','logisticBoss'),(268,'Specie','*','WRITE','ALLOW','ROLE','logisticBoss'),(269,'InvoiceOut','createPdf','WRITE','ALLOW','ROLE','invoicing'),(270,'SupplierAddress','*','*','ALLOW','ROLE','employee'),(271,'SalesMonitor','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (1,'Account','*','*','ALLOW','ROLE','employee'),(3,'Address','*','*','ALLOW','ROLE','employee'),(5,'AgencyService','*','READ','ALLOW','ROLE','employee'),(7,'Client','*','*','ALLOW','ROLE','employee'),(9,'ClientObservation','*','*','ALLOW','ROLE','employee'),(11,'ContactChannel','*','READ','ALLOW','ROLE','trainee'),(13,'Employee','*','READ','ALLOW','ROLE','employee'),(14,'PayMethod','*','READ','ALLOW','ROLE','trainee'),(16,'FakeProduction','*','READ','ALLOW','ROLE','employee'),(17,'Warehouse','* ','READ','ALLOW','ROLE','trainee'),(18,'State','*','READ','ALLOW','ROLE','employee'),(20,'TicketState','*','*','ALLOW','ROLE','employee'),(24,'Delivery','*','READ','ALLOW','ROLE','employee'),(25,'Zone','*','READ','ALLOW','ROLE','employee'),(26,'ClientCredit','*','*','ALLOW','ROLE','employee'),(27,'ClientCreditLimit','*','READ','ALLOW','ROLE','trainee'),(30,'GreugeType','*','READ','ALLOW','ROLE','trainee'),(31,'Mandate','*','READ','ALLOW','ROLE','trainee'),(32,'MandateType','*','READ','ALLOW','ROLE','trainee'),(33,'Company','*','READ','ALLOW','ROLE','trainee'),(34,'Greuge','*','READ','ALLOW','ROLE','trainee'),(35,'AddressObservation','*','*','ALLOW','ROLE','employee'),(36,'ObservationType','*','*','ALLOW','ROLE','employee'),(37,'Greuge','*','WRITE','ALLOW','ROLE','employee'),(38,'AgencyMode','*','READ','ALLOW','ROLE','employee'),(39,'ItemTag','*','WRITE','ALLOW','ROLE','buyer'),(40,'ItemBotanical','*','WRITE','ALLOW','ROLE','buyer'),(41,'ItemBotanical','*','READ','ALLOW','ROLE','employee'),(42,'ItemPlacement','*','WRITE','ALLOW','ROLE','buyer'),(43,'ItemPlacement','*','WRITE','ALLOW','ROLE','replenisher'),(44,'ItemPlacement','*','READ','ALLOW','ROLE','employee'),(45,'ItemBarcode','*','READ','ALLOW','ROLE','employee'),(46,'ItemBarcode','*','WRITE','ALLOW','ROLE','buyer'),(47,'ItemBarcode','*','WRITE','ALLOW','ROLE','replenisher'),(48,'ItemNiche','*','READ','ALLOW','ROLE','employee'),(49,'ItemNiche','*','WRITE','ALLOW','ROLE','buyer'),(50,'ItemNiche','*','WRITE','ALLOW','ROLE','replenisher'),(51,'ItemTag','*','READ','ALLOW','ROLE','employee'),(53,'Item','*','READ','ALLOW','ROLE','employee'),(54,'Item','*','WRITE','ALLOW','ROLE','buyer'),(55,'Recovery','*','READ','ALLOW','ROLE','trainee'),(56,'Recovery','*','WRITE','ALLOW','ROLE','administrative'),(58,'CreditClassification','*','*','ALLOW','ROLE','insurance'),(60,'CreditInsurance','*','*','ALLOW','ROLE','insurance'),(61,'InvoiceOut','*','READ','ALLOW','ROLE','employee'),(62,'Ticket','*','*','ALLOW','ROLE','employee'),(63,'TicketObservation','*','*','ALLOW','ROLE','employee'),(64,'Route','*','READ','ALLOW','ROLE','employee'),(65,'Sale','*','READ','ALLOW','ROLE','employee'),(66,'TicketTracking','*','READ','ALLOW','ROLE','employee'),(68,'TicketPackaging','*','*','ALLOW','ROLE','employee'),(69,'Packaging','*','READ','ALLOW','ROLE','employee'),(70,'Packaging','*','WRITE','ALLOW','ROLE','logistic'),(71,'SaleChecked','*','READ','ALLOW','ROLE','employee'),(72,'SaleComponent','*','READ','ALLOW','ROLE','employee'),(73,'Expedition','*','READ','ALLOW','ROLE','employee'),(74,'Expedition','*','WRITE','ALLOW','ROLE','deliveryBoss'),(75,'Expedition','*','WRITE','ALLOW','ROLE','production'),(76,'AnnualAverageInvoiced','*','READ','ALLOW','ROLE','employee'),(77,'WorkerMana','*','READ','ALLOW','ROLE','employee'),(78,'TicketTracking','*','WRITE','ALLOW','ROLE','production'),(79,'TicketTracking','changeState','*','ALLOW','ROLE','employee'),(80,'Sale','deleteSales','*','ALLOW','ROLE','employee'),(81,'Sale','moveToTicket','*','ALLOW','ROLE','employee'),(82,'Sale','updateQuantity','*','ALLOW','ROLE','employee'),(83,'Sale','updatePrice','*','ALLOW','ROLE','employee'),(84,'Sale','updateDiscount','*','ALLOW','ROLE','employee'),(85,'SaleTracking','*','READ','ALLOW','ROLE','employee'),(86,'Order','*','*','ALLOW','ROLE','employee'),(87,'OrderRow','*','*','ALLOW','ROLE','employee'),(88,'ClientContact','*','*','ALLOW','ROLE','employee'),(89,'Sale','moveToNewTicket','*','ALLOW','ROLE','employee'),(90,'Sale','reserve','*','ALLOW','ROLE','employee'),(91,'TicketWeekly','*','READ','ALLOW','ROLE','employee'),(94,'Agency','landsThatDay','*','ALLOW','ROLE','employee'),(96,'ClaimEnd','*','READ','ALLOW','ROLE','employee'),(97,'ClaimEnd','*','WRITE','ALLOW','ROLE','claimManager'),(98,'ClaimBeginning','*','*','ALLOW','ROLE','employee'),(99,'ClaimDevelopment','*','READ','ALLOW','ROLE','employee'),(100,'ClaimDevelopment','*','WRITE','ALLOW','ROLE','claimManager'),(101,'Claim','*','*','ALLOW','ROLE','employee'),(102,'Claim','createFromSales','*','ALLOW','ROLE','employee'),(103,'ClaimEnd','importTicketSales','WRITE','ALLOW','ROLE','claimManager'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','WRITE','ALLOW','ROLE','marketingBoss'),(107,'ItemNiche','*','WRITE','ALLOW','ROLE','marketingBoss'),(108,'ItemPlacement','*','WRITE','ALLOW','ROLE','marketingBoss'),(109,'UserConfig','*','*','ALLOW','ROLE','employee'),(110,'Bank','*','READ','ALLOW','ROLE','trainee'),(111,'ClientLog','*','READ','ALLOW','ROLE','trainee'),(112,'Defaulter','*','READ','ALLOW','ROLE','employee'),(113,'ClientRisk','*','READ','ALLOW','ROLE','trainee'),(114,'Receipt','*','READ','ALLOW','ROLE','trainee'),(115,'Receipt','*','WRITE','ALLOW','ROLE','administrative'),(116,'BankEntity','*','*','ALLOW','ROLE','employee'),(117,'ClientSample','*','*','ALLOW','ROLE','employee'),(118,'WorkerTeam','*','*','ALLOW','ROLE','salesPerson'),(119,'Travel','*','READ','ALLOW','ROLE','employee'),(120,'Travel','*','WRITE','ALLOW','ROLE','buyer'),(121,'Item','regularize','*','ALLOW','ROLE','employee'),(122,'TicketRequest','*','*','ALLOW','ROLE','employee'),(123,'Worker','*','*','ALLOW','ROLE','employee'),(124,'Client','confirmTransaction','WRITE','ALLOW','ROLE','administrative'),(125,'Agency','getAgenciesWithWarehouse','*','ALLOW','ROLE','employee'),(126,'Client','activeWorkersWithRole','*','ALLOW','ROLE','employee'),(127,'TicketLog','*','READ','ALLOW','ROLE','employee'),(129,'TicketService','*','*','ALLOW','ROLE','employee'),(130,'Expedition','*','WRITE','ALLOW','ROLE','packager'),(131,'CreditInsurance','*','READ','ALLOW','ROLE','trainee'),(132,'CreditClassification','*','READ','ALLOW','ROLE','trainee'),(133,'ItemTag','*','WRITE','ALLOW','ROLE','marketingBoss'),(135,'ZoneGeo','*','READ','ALLOW','ROLE','employee'),(136,'ZoneCalendar','*','READ','ALLOW','ROLE','employee'),(137,'ZoneIncluded','*','READ','ALLOW','ROLE','employee'),(138,'LabourHoliday','*','READ','ALLOW','ROLE','employee'),(139,'LabourHolidayLegend','*','READ','ALLOW','ROLE','employee'),(140,'LabourHolidayType','*','READ','ALLOW','ROLE','employee'),(141,'Zone','*','*','ALLOW','ROLE','deliveryBoss'),(142,'ZoneCalendar','*','WRITE','ALLOW','ROLE','deliveryBoss'),(143,'ZoneIncluded','*','*','ALLOW','ROLE','deliveryBoss'),(144,'Stowaway','*','*','ALLOW','ROLE','employee'),(145,'Ticket','getPossibleStowaways','READ','ALLOW','ROLE','employee'),(147,'UserConfigView','*','*','ALLOW','ROLE','employee'),(148,'UserConfigView','*','*','ALLOW','ROLE','employee'),(149,'Sip','*','READ','ALLOW','ROLE','employee'),(150,'Sip','*','WRITE','ALLOW','ROLE','hr'),(151,'Department','*','READ','ALLOW','ROLE','employee'),(152,'Department','*','WRITE','ALLOW','ROLE','hr'),(153,'Route','*','READ','ALLOW','ROLE','employee'),(154,'Route','*','WRITE','ALLOW','ROLE','delivery'),(155,'Calendar','*','READ','ALLOW','ROLE','hr'),(156,'WorkerLabour','*','READ','ALLOW','ROLE','hr'),(157,'Calendar','absences','READ','ALLOW','ROLE','employee'),(158,'ItemTag','*','WRITE','ALLOW','ROLE','accessory'),(160,'TicketServiceType','*','READ','ALLOW','ROLE','employee'),(161,'TicketConfig','*','READ','ALLOW','ROLE','employee'),(162,'InvoiceOut','delete','WRITE','ALLOW','ROLE','invoicing'),(163,'InvoiceOut','book','WRITE','ALLOW','ROLE','invoicing'),(164,'InvoiceOut','regenerate','WRITE','ALLOW','ROLE','invoicing'),(165,'TicketDms','*','READ','ALLOW','ROLE','employee'),(167,'Worker','isSubordinate','READ','ALLOW','ROLE','employee'),(168,'Worker','mySubordinates','READ','ALLOW','ROLE','employee'),(169,'WorkerTimeControl','filter','READ','ALLOW','ROLE','employee'),(170,'WorkerTimeControl','addTime','WRITE','ALLOW','ROLE','employee'),(171,'TicketServiceType','*','WRITE','ALLOW','ROLE','administrative'),(172,'Sms','*','READ','ALLOW','ROLE','employee'),(173,'Sms','send','WRITE','ALLOW','ROLE','employee'),(174,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(175,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(176,'Device','*','*','ALLOW','ROLE','employee'),(177,'Device','*','*','ALLOW','ROLE','employee'),(178,'WorkerTimeControl','*','*','ALLOW','ROLE','employee'),(179,'ItemLog','*','READ','ALLOW','ROLE','employee'),(180,'RouteLog','*','READ','ALLOW','ROLE','employee'),(181,'Dms','removeFile','WRITE','ALLOW','ROLE','employee'),(182,'Dms','uploadFile','WRITE','ALLOW','ROLE','employee'),(183,'Dms','downloadFile','READ','ALLOW','ROLE','employee'),(184,'Client','uploadFile','WRITE','ALLOW','ROLE','employee'),(185,'ClientDms','removeFile','WRITE','ALLOW','ROLE','employee'),(186,'ClientDms','*','READ','ALLOW','ROLE','trainee'),(187,'Ticket','uploadFile','WRITE','ALLOW','ROLE','employee'),(188,'TicketDms','removeFile','WRITE','ALLOW','ROLE','employee'),(189,'TicketDms','*','READ','ALLOW','ROLE','employee'),(190,'Route','updateVolume','WRITE','ALLOW','ROLE','deliveryBoss'),(191,'Agency','getLanded','READ','ALLOW','ROLE','employee'),(192,'Agency','getShipped','READ','ALLOW','ROLE','employee'),(194,'Postcode','*','WRITE','ALLOW','ROLE','deliveryBoss'),(195,'Ticket','addSale','WRITE','ALLOW','ROLE','employee'),(196,'Dms','updateFile','WRITE','ALLOW','ROLE','employee'),(197,'Dms','*','READ','ALLOW','ROLE','trainee'),(198,'ClaimDms','removeFile','WRITE','ALLOW','ROLE','employee'),(199,'ClaimDms','*','READ','ALLOW','ROLE','employee'),(200,'Claim','uploadFile','WRITE','ALLOW','ROLE','employee'),(201,'Sale','updateConcept','WRITE','ALLOW','ROLE','employee'),(202,'Claim','updateClaimAction','WRITE','ALLOW','ROLE','claimManager'),(203,'UserPhone','*','*','ALLOW','ROLE','employee'),(204,'WorkerDms','removeFile','WRITE','ALLOW','ROLE','hr'),(205,'WorkerDms','*','READ','ALLOW','ROLE','hr'),(206,'Chat','*','*','ALLOW','ROLE','employee'),(207,'Chat','sendMessage','*','ALLOW','ROLE','employee'),(208,'Sale','recalculatePrice','WRITE','ALLOW','ROLE','employee'),(209,'Ticket','recalculateComponents','WRITE','ALLOW','ROLE','employee'),(211,'TravelLog','*','READ','ALLOW','ROLE','buyer'),(212,'Thermograph','*','*','ALLOW','ROLE','buyer'),(213,'TravelThermograph','*','WRITE','ALLOW','ROLE','buyer'),(214,'Entry','*','*','ALLOW','ROLE','buyer'),(215,'TicketWeekly','*','WRITE','ALLOW','ROLE','buyer'),(216,'TravelThermograph','*','READ','ALLOW','ROLE','employee'),(218,'Intrastat','*','*','ALLOW','ROLE','buyer'),(219,'Account','acl','READ','ALLOW','ROLE','account'),(220,'Account','getCurrentUserData','READ','ALLOW','ROLE','account'),(221,'UserConfig','getUserConfig','READ','ALLOW','ROLE','account'),(222,'Client','*','READ','ALLOW','ROLE','trainee'),(226,'ClientObservation','*','READ','ALLOW','ROLE','trainee'),(227,'Address','*','READ','ALLOW','ROLE','trainee'),(228,'AddressObservation','*','READ','ALLOW','ROLE','trainee'),(230,'ClientCredit','*','READ','ALLOW','ROLE','trainee'),(231,'ClientContact','*','READ','ALLOW','ROLE','trainee'),(232,'ClientSample','*','READ','ALLOW','ROLE','trainee'),(233,'EntryLog','*','READ','ALLOW','ROLE','buyer'),(234,'WorkerLog','*','READ','ALLOW','ROLE','salesAssistant'),(235,'CustomsAgent','*','*','ALLOW','ROLE','employee'),(236,'Buy','*','*','ALLOW','ROLE','buyer'),(237,'WorkerDms','filter','*','ALLOW','ROLE','employee'),(238,'Town','*','WRITE','ALLOW','ROLE','deliveryBoss'),(239,'Province','*','WRITE','ALLOW','ROLE','deliveryBoss'),(240,'supplier','*','WRITE','ALLOW','ROLE','administrative'),(241,'SupplierContact','*','WRITE','ALLOW','ROLE','administrative'),(242,'supplier','*','WRITE','ALLOW','ROLE','administrative'),(244,'supplier','*','WRITE','ALLOW','ROLE','administrative'),(246,'Account','changePassword','*','ALLOW','ROLE','account'),(247,'UserAccount','exists','*','ALLOW','ROLE','account'),(248,'RoleMapping','*','READ','ALLOW','ROLE','account'),(249,'UserPassword','*','READ','ALLOW','ROLE','account'),(250,'Town','*','WRITE','ALLOW','ROLE','deliveryBoss'),(251,'Province','*','WRITE','ALLOW','ROLE','deliveryBoss'),(252,'Supplier','*','READ','ALLOW','ROLE','employee'),(253,'Supplier','*','WRITE','ALLOW','ROLE','administrative'),(254,'SupplierLog','*','READ','ALLOW','ROLE','employee'),(256,'Image','*','WRITE','ALLOW','ROLE','employee'),(257,'FixedPrice','*','*','ALLOW','ROLE','buyer'),(258,'PayDem','*','READ','ALLOW','ROLE','employee'),(259,'Client','createReceipt','*','ALLOW','ROLE','salesAssistant'),(260,'PrintServerQueue','*','WRITE','ALLOW','ROLE','employee'),(261,'SupplierAccount','*','*','ALLOW','ROLE','administrative'),(262,'Entry','*','*','ALLOW','ROLE','administrative'),(263,'InvoiceIn','*','*','ALLOW','ROLE','administrative'),(264,'StarredModule','*','*','ALLOW','ROLE','employee'),(265,'ItemBotanical','*','WRITE','ALLOW','ROLE','logisticBoss'),(266,'ZoneLog','*','READ','ALLOW','ROLE','employee'),(267,'Genus','*','WRITE','ALLOW','ROLE','logisticBoss'),(268,'Specie','*','WRITE','ALLOW','ROLE','logisticBoss'),(269,'InvoiceOut','createPdf','WRITE','ALLOW','ROLE','invoicing'),(270,'SupplierAddress','*','*','ALLOW','ROLE','employee'),(271,'SalesMonitor','*','*','ALLOW','ROLE','employee'),(272,'InvoiceInLog','*','*','ALLOW','ROLE','employee'); /*!40000 ALTER TABLE `ACL` ENABLE KEYS */; UNLOCK TABLES; @@ -176,9 +176,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-06-22 14:40:03 +-- Dump completed on 2021-08-31 14:42:29 USE `vn`; --- MariaDB dump 10.19 Distrib 10.5.10-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64) -- -- Host: db.verdnatura.es Database: vn -- ------------------------------------------------------ @@ -380,7 +380,7 @@ UNLOCK TABLES; LOCK TABLES `department` WRITE; /*!40000 ALTER TABLE `department` DISABLE KEYS */; -INSERT INTO `department` VALUES (1,NULL,'VERDNATURA',1,2,763,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,0,NULL,0),(22,NULL,'COMPRAS',3,4,NULL,72,596,2,5,0,0,0,0,NULL,'/',NULL,1,NULL,1),(23,NULL,'CAMARA',14,19,NULL,72,604,2,6,1,0,1,2,37,'/37/',NULL,0,NULL,0),(31,'IT','INFORMATICA',5,6,NULL,72,127,3,9,0,0,0,0,NULL,'/','informatica-cau',1,NULL,1),(34,NULL,'CONTABILIDAD',7,8,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL,1),(35,NULL,'FINANZAS',9,10,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL,1),(36,NULL,'LABORAL',11,12,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL,1),(37,NULL,'PRODUCCION',13,52,NULL,72,230,3,11,1,0,0,17,NULL,'/',NULL,0,NULL,0),(38,NULL,'SACADO',20,21,NULL,72,230,4,14,1,0,1,0,37,'/37/',NULL,0,NULL,0),(39,NULL,'ENCAJADO',22,23,NULL,72,230,4,12,1,0,1,0,37,'/37/',NULL,0,NULL,0),(41,NULL,'ADMINISTRACION',53,54,NULL,72,599,3,8,0,0,0,0,NULL,'/',NULL,1,NULL,1),(43,NULL,'VENTAS',55,78,NULL,0,NULL,NULL,NULL,0,0,0,11,NULL,'/',NULL,1,'direccioncomercial@verdnatura.es',1),(44,NULL,'GERENCIA',79,80,NULL,72,300,2,7,0,0,0,0,NULL,'/',NULL,0,NULL,0),(45,NULL,'LOGISTICA',81,82,NULL,72,596,3,19,0,0,0,0,NULL,'/',NULL,1,NULL,1),(46,NULL,'REPARTO',83,86,NULL,72,659,3,10,0,0,0,1,NULL,'/',NULL,1,NULL,1),(48,NULL,'ALMACENAJE',87,88,NULL,0,NULL,NULL,NULL,1,0,0,0,NULL,'/',NULL,0,NULL,0),(49,NULL,'PROPIEDAD',89,90,NULL,72,1008,1,1,0,0,0,0,NULL,'/',NULL,0,NULL,0),(52,NULL,'CARGA AEREA',91,92,NULL,72,163,4,28,0,0,0,0,NULL,'/',NULL,0,NULL,0),(53,NULL,'MARKETING Y COMUNICACIÓN',93,94,NULL,72,1238,0,0,0,0,0,0,NULL,'/',NULL,1,NULL,1),(54,NULL,'ORNAMENTALES',95,96,NULL,72,433,3,21,0,0,0,0,NULL,'/',NULL,0,NULL,0),(55,NULL,'TALLER NATURAL',97,98,NULL,72,695,2,23,0,0,0,0,NULL,'/',NULL,0,NULL,0),(56,NULL,'TALLER ARTIFICIAL',99,100,NULL,72,1780,2,24,0,0,0,0,NULL,'/',NULL,0,NULL,0),(58,NULL,'CAMPOS',101,102,NULL,72,225,2,2,0,0,0,0,NULL,'/',NULL,0,NULL,1),(59,NULL,'MANTENIMIENTO',103,104,NULL,72,1907,4,16,0,0,0,0,NULL,'/',NULL,0,NULL,0),(60,NULL,'RECLAMACIONES',105,106,NULL,72,563,3,20,0,0,0,0,NULL,'/',NULL,1,NULL,1),(61,NULL,'VNH',107,108,NULL,73,1297,3,17,0,0,0,0,NULL,'/',NULL,0,NULL,0),(63,NULL,'VENTAS FRANCIA',56,57,NULL,72,277,2,27,0,0,1,0,43,'/43/',NULL,0,NULL,0),(66,NULL,'VERDNAMADRID',109,110,NULL,72,163,3,18,0,0,0,0,NULL,'/',NULL,0,NULL,0),(68,NULL,'COMPLEMENTOS',24,25,NULL,72,617,3,26,1,0,1,0,37,'/37/',NULL,0,NULL,0),(69,NULL,'VERDNABARNA',111,112,NULL,74,432,3,22,0,0,0,0,NULL,'/',NULL,0,NULL,0),(77,NULL,'PALETIZADO',84,85,NULL,72,230,4,15,1,0,1,0,46,'/46/',NULL,0,NULL,0),(80,NULL,'EQUIPO J VALLES',58,59,NULL,72,693,3,4,0,0,1,0,43,'/43/','jvp_equipo',1,NULL,1),(86,NULL,'LIMPIEZA',113,114,NULL,72,599,0,0,0,0,0,0,NULL,'/',NULL,0,NULL,0),(89,NULL,'COORDINACION',115,116,NULL,0,NULL,NULL,NULL,1,0,0,0,NULL,'/',NULL,0,NULL,0),(90,NULL,'TRAILER',117,118,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,0,NULL,0),(91,NULL,'ARTIFICIAL',26,27,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(92,NULL,'EQUIPO SILVERIO',60,61,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','sdc_equipo',1,NULL,1),(93,NULL,'CONFECCION',119,120,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,0,NULL,0),(94,NULL,'EQUIPO J BROCAL',62,63,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','jes_equipo',1,NULL,1),(95,NULL,'EQUIPO C ZAMBRANO',64,65,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','czg_equipo',1,NULL,1),(96,NULL,'EQUIPO C LOPEZ',66,67,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','cla_equipo',1,NULL,1),(98,NULL,'EQUIPO RODRIGO',68,69,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','rhr_equipo',1,NULL,1),(101,NULL,'EQUIPO J IBAÑEZ',70,71,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','jmi_equipo',1,NULL,1),(102,NULL,'EQ ROJO FV RUBEN C',28,29,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(103,NULL,'EQ AZUL FV A FOLQUES',30,31,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(104,NULL,'EQ AMARILLO FV NORMAN G',32,33,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(105,NULL,'EQ MORADO FV MATOU',34,35,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(106,NULL,'EQ VERDE PCA KEVIN GIMENEZ',36,37,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(107,NULL,'EQ NARANJA PCA RUBEN ZANON',38,39,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(110,NULL,'EQ ROSA PCA J BONDIA',40,41,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(111,NULL,'EQ REPONEDOR CAJAS',42,43,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(112,NULL,'CAMARA EQ EDGAR LLEO',15,16,NULL,0,NULL,NULL,NULL,1,0,2,0,23,'/37/23/',NULL,0,NULL,0),(113,NULL,'CAMARA EQ MARC ROCA',17,18,NULL,0,NULL,NULL,NULL,1,0,2,0,23,'/37/23/',NULL,0,NULL,0),(114,NULL,'EQ MARRON PCA JL NUEVO',44,45,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(115,NULL,'EQUIPO CLAUDI',72,73,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','csr_equipo',1,NULL,1),(120,NULL,'PCA PRODUCCION',46,47,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(121,NULL,'FV PRODUCCION',48,49,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(122,NULL,'PCA ALMACEN',50,51,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(123,NULL,'EQUIPO ELENA BASCUÑANA',74,75,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','ebt_equipo',1,NULL,1),(124,NULL,'CONTROL INTERNO',121,122,NULL,72,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL,1),(125,NULL,'EQUIPO MIRIAM MAR',76,77,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','mir_equipo',0,NULL,0); +INSERT INTO `department` VALUES (1,NULL,'VERDNATURA',1,2,763,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,0,NULL,0),(22,NULL,'COMPRAS',3,4,NULL,72,596,2,5,0,0,0,0,NULL,'/',NULL,1,NULL,1),(23,NULL,'CAMARA',14,19,NULL,72,604,2,6,1,0,1,2,37,'/37/',NULL,0,NULL,0),(31,'IT','INFORMATICA',5,6,NULL,72,127,3,9,0,0,0,0,NULL,'/','informatica-cau',1,NULL,1),(34,NULL,'CONTABILIDAD',7,8,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL,1),(35,NULL,'FINANZAS',9,10,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL,1),(36,NULL,'LABORAL',11,12,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL,1),(37,NULL,'PRODUCCION',13,52,NULL,72,230,3,11,1,0,0,17,NULL,'/',NULL,0,NULL,0),(38,NULL,'SACADO',20,21,NULL,72,230,4,14,1,0,1,0,37,'/37/',NULL,0,NULL,0),(39,NULL,'ENCAJADO',22,23,NULL,72,230,4,12,1,0,1,0,37,'/37/',NULL,0,NULL,0),(41,NULL,'ADMINISTRACION',53,54,NULL,72,599,3,8,0,0,0,0,NULL,'/',NULL,1,NULL,1),(43,NULL,'VENTAS',55,78,NULL,0,NULL,NULL,NULL,0,0,0,11,NULL,'/',NULL,1,'direccioncomercial@verdnatura.es',1),(44,NULL,'GERENCIA',79,80,NULL,72,300,2,7,0,0,0,0,NULL,'/',NULL,0,NULL,0),(45,NULL,'LOGISTICA',81,82,NULL,72,596,3,19,0,0,0,0,NULL,'/',NULL,1,NULL,1),(46,NULL,'REPARTO',83,86,NULL,72,659,3,10,0,0,0,1,NULL,'/',NULL,0,NULL,0),(48,NULL,'ALMACENAJE',87,88,NULL,0,NULL,NULL,NULL,1,0,0,0,NULL,'/',NULL,0,NULL,0),(49,NULL,'PROPIEDAD',89,90,NULL,72,1008,1,1,0,0,0,0,NULL,'/',NULL,0,NULL,0),(52,NULL,'CARGA AEREA',91,92,NULL,72,163,4,28,0,0,0,0,NULL,'/',NULL,0,NULL,0),(53,NULL,'MARKETING Y COMUNICACIÓN',93,94,NULL,72,1238,0,0,0,0,0,0,NULL,'/',NULL,1,NULL,1),(54,NULL,'ORNAMENTALES',95,96,NULL,72,433,3,21,0,0,0,0,NULL,'/',NULL,0,NULL,0),(55,NULL,'TALLER NATURAL',97,98,NULL,72,695,2,23,0,0,0,0,NULL,'/',NULL,0,NULL,0),(56,NULL,'TALLER ARTIFICIAL',99,100,NULL,72,1780,2,24,0,0,0,0,NULL,'/',NULL,0,NULL,0),(58,NULL,'CAMPOS',101,102,NULL,72,225,2,2,0,0,0,0,NULL,'/',NULL,0,NULL,1),(59,NULL,'MANTENIMIENTO',103,104,NULL,72,1907,4,16,0,0,0,0,NULL,'/',NULL,0,NULL,0),(60,NULL,'RECLAMACIONES',105,106,NULL,72,563,3,20,0,0,0,0,NULL,'/',NULL,1,NULL,1),(61,NULL,'VNH',107,108,NULL,73,1297,3,17,0,0,0,0,NULL,'/',NULL,0,NULL,0),(63,NULL,'VENTAS FRANCIA',56,57,NULL,72,277,2,27,0,0,1,0,43,'/43/',NULL,0,NULL,0),(66,NULL,'VERDNAMADRID',109,110,NULL,72,163,3,18,0,0,0,0,NULL,'/',NULL,0,NULL,0),(68,NULL,'COMPLEMENTOS',24,25,NULL,72,617,3,26,1,0,1,0,37,'/37/',NULL,0,NULL,0),(69,NULL,'VERDNABARNA',111,112,NULL,74,432,3,22,0,0,0,0,NULL,'/',NULL,0,NULL,0),(77,NULL,'PALETIZADO',84,85,NULL,72,230,4,15,1,0,1,0,46,'/46/',NULL,0,NULL,0),(80,NULL,'EQUIPO J VALLES',58,59,NULL,72,693,3,4,0,0,1,0,43,'/43/','jvp_equipo',1,NULL,1),(86,NULL,'LIMPIEZA',113,114,NULL,72,599,0,0,0,0,0,0,NULL,'/',NULL,0,NULL,0),(89,NULL,'COORDINACION',115,116,NULL,0,NULL,NULL,NULL,1,0,0,0,NULL,'/',NULL,0,NULL,0),(90,NULL,'TRAILER',117,118,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,0,NULL,0),(91,NULL,'ARTIFICIAL',26,27,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(92,NULL,'EQUIPO SILVERIO',60,61,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','sdc_equipo',1,NULL,1),(93,NULL,'CONFECCION',119,120,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,0,NULL,0),(94,NULL,'EQUIPO J BROCAL',62,63,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','jes_equipo',1,NULL,1),(95,NULL,'EQUIPO C ZAMBRANO',64,65,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','czg_equipo',1,NULL,1),(96,NULL,'EQUIPO C LOPEZ',66,67,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','cla_equipo',1,NULL,1),(98,NULL,'EQUIPO RODRIGO',68,69,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','rhr_equipo',1,NULL,1),(101,NULL,'EQUIPO J IBAÑEZ',70,71,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','jmi_equipo',1,NULL,1),(102,NULL,'EQ ROJO FV RUBEN C',28,29,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(103,NULL,'EQ AZUL FV A FOLQUES',30,31,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(104,NULL,'EQ AMARILLO FV NORMAN G',32,33,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(105,NULL,'EQ MORADO FV MATOU',34,35,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(106,NULL,'EQ VERDE PCA KEVIN GIMENEZ',36,37,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(107,NULL,'EQ NARANJA PCA RUBEN ZANON',38,39,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(110,NULL,'EQ ROSA PCA J BONDIA',40,41,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(111,NULL,'EQ REPONEDOR CAJAS',42,43,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(112,NULL,'CAMARA EQ EDGAR LLEO',15,16,NULL,0,NULL,NULL,NULL,1,0,2,0,23,'/37/23/',NULL,0,NULL,0),(113,NULL,'CAMARA EQ MARC ROCA',17,18,NULL,0,NULL,NULL,NULL,1,0,2,0,23,'/37/23/',NULL,0,NULL,0),(114,NULL,'EQ MARRON PCA JL NUEVO',44,45,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(115,NULL,'EQUIPO CLAUDI',72,73,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','csr_equipo',1,NULL,1),(120,NULL,'PCA PRODUCCION',46,47,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(121,NULL,'FV PRODUCCION',48,49,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(122,NULL,'PCA ALMACEN',50,51,NULL,0,NULL,NULL,NULL,1,0,1,0,37,'/37/',NULL,0,NULL,0),(123,NULL,'EQUIPO ELENA BASCUÑANA',74,75,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','ebt_equipo',1,NULL,1),(124,NULL,'CONTROL INTERNO',121,122,NULL,72,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,1,NULL,1),(125,NULL,'EQUIPO MIRIAM MAR',76,77,NULL,0,NULL,NULL,NULL,0,0,1,0,43,'/43/','mir_equipo',0,NULL,0),(126,NULL,'TALLER PRESERVADO',123,124,NULL,0,NULL,NULL,NULL,0,0,0,0,NULL,'/',NULL,0,NULL,0); /*!40000 ALTER TABLE `department` ENABLE KEYS */; UNLOCK TABLES; @@ -432,9 +432,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-06-22 14:40:05 +-- Dump completed on 2021-08-31 14:42:30 USE `cache`; --- MariaDB dump 10.19 Distrib 10.5.10-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64) -- -- Host: db.verdnatura.es Database: cache -- ------------------------------------------------------ @@ -468,9 +468,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-06-22 14:40:05 +-- Dump completed on 2021-08-31 14:42:31 USE `hedera`; --- MariaDB dump 10.19 Distrib 10.5.10-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64) -- -- Host: db.verdnatura.es Database: hedera -- ------------------------------------------------------ @@ -534,9 +534,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-06-22 14:40:06 +-- Dump completed on 2021-08-31 14:42:31 USE `postgresql`; --- MariaDB dump 10.19 Distrib 10.5.10-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64) -- -- Host: db.verdnatura.es Database: postgresql -- ------------------------------------------------------ @@ -608,7 +608,7 @@ UNLOCK TABLES; LOCK TABLES `workcenter` WRITE; /*!40000 ALTER TABLE `workcenter` DISABLE KEYS */; -INSERT INTO `workcenter` VALUES (1,'Silla',20,1208,1,'Av espioca 100',552703),(2,'Mercaflor',19,NULL,NULL,NULL,NULL),(3,'Marjales',26,20008,NULL,NULL,NULL),(4,'VNH',NULL,NULL,3,NULL,NULL),(5,'Madrid',28,2865,5,'Av constitución 3',554145),(6,'Vilassar',88,88036,2,'Cami del Crist, 33',556412),(7,'Tenerife',NULL,NULL,10,NULL,NULL),(8,NULL,NULL,NULL,NULL,NULL,NULL),(9,'Algemesi',20,NULL,60,'Fenollars, 20',523549),(10,NULL,NULL,NULL,NULL,NULL,NULL); +INSERT INTO `workcenter` VALUES (1,'Silla',20,NULL,1,'Av espioca 100',552703),(2,'Mercaflor',19,NULL,NULL,NULL,NULL),(3,'Marjales',26,20008,NULL,NULL,NULL),(4,'VNH',NULL,NULL,3,NULL,NULL),(5,'Madrid',28,2865,5,'Av constitución 3',554145),(6,'Vilassar',88,88036,2,'Cami del Crist, 33',556412),(7,'Tenerife',NULL,NULL,10,NULL,NULL),(8,NULL,NULL,NULL,NULL,NULL,NULL),(9,'Algemesi',20,1266,60,'Fenollars, 2',523549),(10,NULL,NULL,NULL,NULL,NULL,NULL); /*!40000 ALTER TABLE `workcenter` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -620,9 +620,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-06-22 14:40:06 +-- Dump completed on 2021-08-31 14:42:32 USE `sage`; --- MariaDB dump 10.19 Distrib 10.5.10-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64) -- -- Host: db.verdnatura.es Database: sage -- ------------------------------------------------------ @@ -676,4 +676,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-06-22 14:40:07 +-- Dump completed on 2021-08-31 14:42:32 diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 867a830df..8a7ec5574 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -225,13 +225,21 @@ INSERT INTO `vn`.`payDem`(`id`, `payDem`) (1, 10), (2, 20); -INSERT INTO `vn`.`province`(`id`, `name`, `countryFk`, `warehouseFk`) +INSERT INTO `vn`.`autonomy`(`id`, `name`, `countryFk`) VALUES - (1, 'Province one', 1, NULL), - (2, 'Province two', 1, NULL), - (3, 'Province three', 1, NULL), - (4, 'Province four', 2, NULL), - (5, 'Province five', 13, NULL); + (1, 'Autonomy one', 1), + (2, 'Autonomy two', 1), + (3, 'Autonomy three', 2), + (4, 'Autonomy four', 13); + + +INSERT INTO `vn`.`province`(`id`, `name`, `countryFk`, `autonomyFk`, `warehouseFk`) + VALUES + (1, 'Province one', 1, 1, NULL), + (2, 'Province two', 1, 1, NULL), + (3, 'Province three', 1, 2, NULL), + (4, 'Province four', 2, 3, NULL), + (5, 'Province five', 13, 4, NULL); INSERT INTO `vn`.`town`(`id`, `name`, `provinceFk`) VALUES @@ -268,20 +276,20 @@ INSERT INTO `vn`.`contactChannel`(`id`, `name`) (4, 'GCN Channel'), (5, 'The Newspaper'); -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`) +INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city`,`postcode`,`phone`,`mobile`,`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 - (1101, 'Bruce Wayne', '84612325V', 'Batman', 'Alfred', '1007 Mountain Drive, Gotham', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), - (1102, 'Petter Parker', '87945234L', 'Spider man', 'Aunt May', '20 Ingram Street, Queens, USA', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), - (1103, 'Clark Kent', '06815934E', 'Super man', 'lois lane', '344 Clinton Street, Apartament 3-D', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 0, 19, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), - (1104, 'Tony Stark', '06089160W', 'Iron man', 'Pepper Potts', '10880 Malibu Point, 90265', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), - (1105, 'Max Eisenhardt', '251628698', 'Magneto', 'Rogue', 'Unknown Whereabouts', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 8, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1), - (1106, 'DavidCharlesHaller', '53136686Q', 'Legion', 'Charles Xavier', 'City of New York, New York, USA', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 19, 0, 1), - (1107, 'Hank Pym', '09854837G', 'Ant man', 'Hawk', 'Anthill, San Francisco, California', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1), - (1108, 'Charles Xavier', '22641921P', 'Professor X', 'Beast', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 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, 19, 0, 1), - (1109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 9, 0, 1), - (1110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1), - (1111, 'Missing', NULL, 'Missing man', 'Anton', 'The space, Universe far away', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1), - (1112, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city, Underground', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1); + (1101, 'Bruce Wayne', '84612325V', 'Batman', 'Alfred', '1007 Mountain Drive, Gotham', 'Silla', 46460, 1111111111, 222222222, 1, 'BruceWayne@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), + (1102, 'Petter Parker', '87945234L', 'Spider man', 'Aunt May', '20 Ingram Street, Queens, USA', 'Silla', 46460, 1111111111, 222222222, 1, 'PetterParker@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), + (1103, 'Clark Kent', '06815934E', 'Super man', 'lois lane', '344 Clinton Street, Apartament 3-D', 'Silla', 46460, 1111111111, 222222222, 1, 'ClarkKent@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 0, 19, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), + (1104, 'Tony Stark', '06089160W', 'Iron man', 'Pepper Potts', '10880 Malibu Point, 90265', 'Silla', 46460, 1111111111, 222222222, 1, 'TonyStark@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 18, 0, 1), + (1105, 'Max Eisenhardt', '251628698', 'Magneto', 'Rogue', 'Unknown Whereabouts', 'Silla', 46460, 1111111111, 222222222, 1, 'MaxEisenhardt@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 8, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1), + (1106, 'DavidCharlesHaller', '53136686Q', 'Legion', 'Charles Xavier', 'City of New York, New York, USA', 'Silla', 46460, 1111111111, 222222222, 1, 'DavidCharlesHaller@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 1, 0, NULL, 0, 0, 19, 0, 1), + (1107, 'Hank Pym', '09854837G', 'Ant man', 'Hawk', 'Anthill, San Francisco, California', 'Silla', 46460, 1111111111, 222222222, 1, 'HankPym@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 19, 0, 1), + (1108, 'Charles Xavier', '22641921P', 'Professor X', 'Beast', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Silla', 46460, 1111111111, 222222222, 1, 'CharlesXavier@mydomain.com', NULL, 0, 1234567890, 0, 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, 19, 0, 1), + (1109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, 9, 0, 1), + (1110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, NULL, 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1), + (1111, 'Missing', NULL, 'Missing man', 'Anton', 'The space, Universe far away', 'Silla', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1), + (1112, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city, Underground', 'Silla', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, NULL, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1); INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'SILLA', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, CURDATE(), 1 diff --git a/db/dump/structure.sql b/db/dump/structure.sql index b415e1d99..1565e029f 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -1,4 +1,4 @@ --- MariaDB dump 10.19 Distrib 10.5.10-MariaDB, for Linux (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.4-MariaDB, for Linux (x86_64) -- -- Host: db.verdnatura.es Database: account -- ------------------------------------------------------ @@ -3606,7 +3606,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 `analisisComponentes` */; +/*!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 */ ; @@ -3616,7 +3616,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `analisisComponentes`() +CREATE DEFINER=`root`@`%` PROCEDURE `analisisComponentes__`() BEGIN DECLARE vDateStart DATE DEFAULT '2016-01-01'; @@ -3701,9 +3701,10 @@ BEGIN 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) + JOIN vn.accountingType at2 ON at2.id = b.cash + WHERE at2.code IN ('wireTransfer','fundingLine') AND Cajafecha = vCurrentDate - AND (Serie = 'MB' OR cash = 3) + AND (Serie = 'MB' OR at2.code = 'fundingLine') GROUP BY Id_Banco )sub GROUP BY Id_Banco @@ -3751,7 +3752,8 @@ BEGIN FROM vn.time t JOIN vn2008.Saldos_Prevision sp ON sp.Fecha <= t.dated JOIN vn2008.Bancos b ON sp.Id_Banco = b.Id_Banco - WHERE b.cash IN (0,3) + JOIN vn.accountingType at2 ON at2.id = b.cash + WHERE at2.code IN ('wireTransfer','fundingLine') AND t.dated BETWEEN vStartingDate AND vMaxDate GROUP BY t.dated, sp.Id_Banco ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo); @@ -3763,10 +3765,11 @@ BEGIN -- 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; + JOIN vn2008.Bancos b using(Id_Banco) + JOIN vn.accountingType at2 ON at2.id = b.cash + SET be.deuda = IF(at2.code = 'fundingLine', be.saldo_aux, 0) + , be.saldo = IF(at2.code = 'fundingLine', 0, be.saldo_aux) + WHERE Fecha >= vStartingDate; -- Liquidez update bs.bancos_evolution set liquidez = saldo - quilla + deuda WHERE Fecha >= vStartingDate; @@ -3983,7 +3986,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 */ ; -ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `bs` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `clean` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4019,7 +4022,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 `clientDied` */; +/*!50003 DROP PROCEDURE IF EXISTS `clientDied_recalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -4029,11 +4032,8 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `clientDied`() +CREATE DEFINER=`root`@`%` PROCEDURE `clientDied_recalc`() BEGIN - - IF DAY(CURDATE()) = 3 THEN - SET @primerAviso := TIMESTAMPADD(MONTH,-1,CURDATE()); SET @segundoAviso := TIMESTAMPADD(MONTH,-2,CURDATE()); SET @tercerAviso := TIMESTAMPADD(MONTH,-3,CURDATE()); @@ -4063,8 +4063,6 @@ BEGIN DELETE cd.* FROM bs.clientDied cd JOIN vn.ticket t ON t.clientFk = cd.id WHERE t.refFk IS NULL AND t.shipped >=TIMESTAMPADD(MONTH,-1,CURDATE()); - END IF; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -4450,7 +4448,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 */ ; -ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `bs` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `compradores_add_launcher` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4680,7 +4678,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 */ ; -ALTER DATABASE `bs` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `bs` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `fruitsEvolution` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6137,21 +6135,31 @@ 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 `ventas_add`(IN datSTART DATETIME, IN datEND DATETIME) BEGIN + /** + * Añade las ventas que se realizaron de hace + * una semana hasta hoy + * + * @param datSTART Fecha de inicio + * @param datEND Fecha de finalizacion + * + **/ + DECLARE vStartingDate DATETIME; DECLARE vEndingDate DATETIME; DECLARE TIPO_PATRIMONIAL INT DEFAULT 188; - IF datSTART < '2015-10-01' OR datEND < '2015-10-01' THEN - CALL util.throw('fechaDemasiadoAntigua'); + IF datSTART < TIMESTAMPADD(YEAR,-5,CURDATE()) + OR datEND < TIMESTAMPADD(YEAR,-5,CURDATE()) THEN + CALL util.throw('fechaDemasiadoAntigua'); END IF; SET datEND = util.dayEnd(datEND); @@ -6160,54 +6168,52 @@ BEGIN DELETE FROM ventas - WHERE fecha between vStartingDate and datEND; - + WHERE fecha BETWEEN vStartingDate AND datEND; + WHILE vEndingDate <= datEND DO - + 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, + 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 - WHERE t.Fecha between vStartingDate and vEndingDate + 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 + WHERE t.Fecha BETWEEN vStartingDate AND vEndingDate AND c.typeFk IN ('Normal','handMaking','internalUse') AND m.Cantidad <> 0 AND a.tipo_id != TIPO_PATRIMONIAL AND m.Descuento <> 100 - AND (m.Id_Article = 98 or m.Id_Article = 95 or r.mercancia != 0) + 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 bs.ventas v JOIN ( SELECT s.id, sum(s.quantity * sc.value ) AS margen, s.quantity * s.price * (100 - s.discount ) / 100 AS pvp FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.saleComponent sc ON sc.saleFk = s.id - JOIN vn.component c ON c.id = sc.componentFk - JOIN vn.componentType ct ON ct.id = c.typeFk + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.saleComponent sc ON sc.saleFk = s.id + JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk WHERE t.shipped BETWEEN vStartingDate AND vEndingDate AND ct.isMargin = TRUE GROUP BY s.id) sub ON sub.id = v.Id_Movimiento - SET v.margen = sub.margen + v.importe + v.recargo - sub.pvp; - + + SET v.margen = sub.margen + v.importe + v.recargo - sub.pvp; SET vStartingDate = TIMESTAMPADD(DAY,1, vStartingDate); SET vEndingDate = util.dayEnd(vStartingDate); - END WHILE; @@ -6221,16 +6227,22 @@ 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 `ventas_add_launcher`() BEGIN + + /** + * Añade las ventas que se realizaron de hace + * una semana hasta hoy + * + **/ - call bs.ventas_add(timestampadd(week,-1,curdate()),curdate()); + CALL bs.ventas_add(timestampadd(week,-1,curdate()),curdate()); END ;; DELIMITER ; @@ -6242,13 +6254,155 @@ 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' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `ventas_contables_add`(IN vYear INT, IN vMonth INT) +BEGIN + + /** + * Reemplaza las ventas contables del último año. + * 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)) + ENGINE = MEMORY + 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 + + 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; + + INSERT INTO bs.ventas_contables(year + , month + , venta + , grupo + , reino_id + , tipo_id + , empresa_id + , gasto) + SELECT vYear + , vMonth + , sum(ts.quantity * ts.price) + , IF( + c.companyGroupFk = c2.companyGroupFk + ,1 + ,IF(c2.companyGroupFk, 2, 0) + ) as grupo + , NULL + , NULL + , t.companyFk + , 7050000000 + FROM vn.ticketService ts + JOIN vn.ticket t ON ts.ticketFk = t.id + JOIN vn.address a on a.id = t.addressFk + JOIN vn.client cl on cl.id = a.clientFk + JOIN tmp.ticket_list tt on tt.Id_Ticket = t.id + JOIN vn.company c on c.id = t.companyFk + LEFT JOIN vn.company c2 on c2.clientFk = cl.id + GROUP BY grupo, t.companyFk ; + + 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 */ ; +/*!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 = 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 `ventas_contables_add_launcher`() +BEGIN + + /** + * Reemplaza las ventas contables del último año. + * Es el origen de datos para el balance de Entradas + * + **/ + + 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_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_contables_add`(IN vYear INT, IN vMonth INT) +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 @@ -6318,27 +6472,6 @@ INSERT INTO bs.ventas_contables(year 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 */ ; -/*!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 */ ; @@ -6349,52 +6482,55 @@ 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 `ventas_contables_por_cliente`(IN vYear INT, IN vMonth INT) BEGIN + + /** + * Muestra las ventas (€) de cada cliente + * dependiendo del año + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; - -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 + 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 + 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; + + DROP TEMPORARY TABLE tmp.ticket_list; END ;; DELIMITER ; @@ -6406,52 +6542,71 @@ 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 `vivosMuertos`() BEGIN + + /** + * Devuelve el número de clientes nuevos y muertos, + * dependiendo de la fecha actual. + * + * @param @datSTART Fecha de inicio a buscar + * @param @datEND Fecha de finalización a buscar + */ -SET @datSTART = TIMESTAMPADD(YEAR,-2,CURDATE()); -SET @datEND = TIMESTAMPADD(DAY,-DAY(CURDATE()),CURDATE()); + SET @datSTART = TIMESTAMPADD(YEAR,-2,CURDATE()); + SET @datEND = TIMESTAMPADD(DAY,-DAY(CURDATE()),CURDATE()); + + DROP TEMPORARY TABLE IF EXISTS tmp.VivosMuertos; + + CREATE TEMPORARY TABLE tmp.VivosMuertos + SELECT c.Id_Cliente, tm.yearMonth, f.Compra, 0 as Nuevo, 0 as Muerto + FROM vn2008.Clientes c + JOIN + (SELECT DISTINCT yearMonth + FROM vn2008.time + WHERE date BETWEEN @datSTART + AND @datEND ) tm + LEFT JOIN + (SELECT DISTINCT tm.yearMonth, f.Id_Cliente , 1 as Compra + FROM vn2008.Facturas f + JOIN vn2008.time tm ON tm.date = f.Fecha + WHERE Fecha BETWEEN @datSTART + AND @datEND) f ON f.yearMonth = tm.yearMonth + AND f.Id_Cliente = c.Id_Cliente; + + UPDATE tmp.VivosMuertos vm + JOIN + (SELECT MIN(tm.yearMonth) firstMonth, f.Id_Cliente + FROM vn2008.Facturas f + JOIN vn2008.time tm ON tm.date = f.Fecha + WHERE Fecha BETWEEN @datSTART AND @datEND + GROUP BY f.Id_Cliente ) fm ON fm.firstMonth = vm.yearMonth + AND fm.Id_Cliente = vm.Id_Cliente -DROP TEMPORARY TABLE IF EXISTS tmp.VivosMuertos; + SET Nuevo = 1; + + SELECT max(yearMonth) INTO @lastYearMonth FROM tmp.VivosMuertos; + + UPDATE tmp.VivosMuertos vm + JOIN ( + SELECT MAX(tm.yearMonth) firstMonth, f.Id_Cliente + FROM vn2008.Facturas f + JOIN vn2008.time tm ON tm.date = f.Fecha + WHERE Fecha BETWEEN @datSTART AND @datEND + GROUP BY f.Id_Cliente ) fm ON fm.firstMonth = vm.yearMonth + AND fm.Id_Cliente = vm.Id_Cliente -CREATE TEMPORARY TABLE tmp.VivosMuertos -SELECT c.Id_Cliente, tm.yearMonth, f.Compra, 0 as Nuevo, 0 as Muerto -FROM vn2008.Clientes c -JOIN (SELECT DISTINCT yearMonth FROM vn2008.time WHERE date BETWEEN @datSTART AND @datEND ) tm -LEFT JOIN - (SELECT DISTINCT tm.yearMonth, f.Id_Cliente , 1 as Compra - FROM vn2008.Facturas f - JOIN vn2008.time tm ON tm.date = f.Fecha - WHERE Fecha BETWEEN @datSTART AND @datEND) f ON f.yearMonth = tm.yearMonth AND f.Id_Cliente = c.Id_Cliente; - -UPDATE tmp.VivosMuertos vm -JOIN ( - SELECT MIN(tm.yearMonth) firstMonth, f.Id_Cliente - FROM vn2008.Facturas f - JOIN vn2008.time tm ON tm.date = f.Fecha - WHERE Fecha BETWEEN @datSTART AND @datEND - GROUP BY f.Id_Cliente ) fm ON fm.firstMonth = vm.yearMonth AND fm.Id_Cliente = vm.Id_Cliente -SET Nuevo = 1; - -SELECT max(yearMonth) INTO @lastYearMonth FROM tmp.VivosMuertos; - -UPDATE tmp.VivosMuertos vm -JOIN ( - SELECT MAX(tm.yearMonth) firstMonth, f.Id_Cliente - FROM vn2008.Facturas f - JOIN vn2008.time tm ON tm.date = f.Fecha - WHERE Fecha BETWEEN @datSTART AND @datEND - GROUP BY f.Id_Cliente ) fm ON fm.firstMonth = vm.yearMonth AND fm.Id_Cliente = vm.Id_Cliente -SET Muerto = 1 -WHERE yearMonth < @lastYearMonth; - - SELECT * FROM tmp.VivosMuertos; + SET Muerto = 1 + + WHERE yearMonth < @lastYearMonth; + + SELECT * FROM tmp.VivosMuertos; END ;; DELIMITER ; @@ -6590,10 +6745,9 @@ BEGIN LEFT JOIN vn.workerDepartment wd ON wd.workerFk = st.workerFk LEFT JOIN vn.department d ON d.id = wd.departmentFk JOIN workerProductivityConfig w ON TRUE - WHERE t.shipped >= vDateFrom AND - ISNULL(sp.saleFk)AND - NOT IFNULL(d.name,'') LIKE 'EQUIPO%' AND - a.accion='SACAR' + WHERE t.shipped >= vDateFrom + AND ISNULL(sp.saleFk) + AND a.accion='SACAR' GROUP BY t.id, t.warehouseFk, st.workerFk ) sub JOIN account.role r ON r.name='itemPicker' @@ -6681,2585 +6835,6 @@ DELIMITER ; /*!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=InnoDB 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=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=COMPACT; -/*!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 `vn`.`buy` (`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 `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 `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` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `empresa_id` int(5) NOT NULL, - `SUBCTA` varchar(11) CHARACTER SET utf8 NOT NULL, - `Eurodebe` double DEFAULT NULL, - `Eurohaber` double DEFAULT NULL, - `Fecha` date DEFAULT NULL, - `FECHA_EX` date DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `Cuenta` (`SUBCTA`), - KEY `empresa` (`empresa_id`), - KEY `Fecha` (`Fecha`) -) ENGINE=InnoDBDEFAULT 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, - UNIQUE KEY `Año` (`Año`,`Semana`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Temporary table 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 TABLE `analisis_grafico_ventas` ( - `Año` tinyint NOT NULL, - `Semana` tinyint NOT NULL, - `Importe` tinyint NOT NULL -) ENGINE=MyISAM */; -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` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `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, - PRIMARY KEY (`id`), - KEY `Año` (`Año`,`Semana`) -) ENGINE=InnoDBDEFAULT 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, - UNIQUE 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, - UNIQUE 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, - `countryCode` varchar(2) COLLATE utf8_unicode_ci 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 table 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 TABLE `analisis_ventas_simple` ( - `Año` tinyint NOT NULL, - `Semana` tinyint NOT NULL, - `Importe` tinyint NOT NULL -) ENGINE=MyISAM */; -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 */; - --- --- Temporary table structure for view `claims_ratio` --- - -DROP TABLE IF EXISTS `claims_ratio`; -/*!50001 DROP VIEW IF EXISTS `claims_ratio`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `claims_ratio` ( - `Id_Cliente` tinyint NOT NULL, - `Consumo` tinyint NOT NULL, - `Reclamaciones` tinyint NOT NULL, - `Ratio` tinyint NOT NULL, - `recobro` tinyint NOT NULL, - `inflacion` tinyint NOT NULL -) ENGINE=MyISAM */; -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 table 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 TABLE `customerRiskOverdue` ( - `customer_id` tinyint NOT NULL, - `amount` tinyint NOT NULL, - `company_id` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `customer_risk` --- - -DROP TABLE IF EXISTS `customer_risk`; -/*!50001 DROP VIEW IF EXISTS `customer_risk`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `customer_risk` ( - `customer_id` tinyint NOT NULL, - `company_id` tinyint NOT NULL, - `amount` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `defaulters` --- - -DROP TABLE IF EXISTS `defaulters`; -/*!50001 DROP VIEW IF EXISTS `defaulters`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `defaulters` ( - `client` tinyint NOT NULL, - `date` tinyint NOT NULL, - `amount` tinyint NOT NULL, - `defaulterSince` tinyint NOT NULL, - `hasChanged` tinyint NOT NULL, - `frozened` tinyint NOT NULL -) ENGINE=MyISAM */; -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=InnoDB 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 `vn`.`ticket` (`id`) 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 */; - --- --- Temporary table structure for view `facturacion_media_anual` --- - -DROP TABLE IF EXISTS `facturacion_media_anual`; -/*!50001 DROP VIEW IF EXISTS `facturacion_media_anual`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `facturacion_media_anual` ( - `Id_Cliente` tinyint NOT NULL, - `Consumo` tinyint NOT NULL -) ENGINE=MyISAM */; -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 `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 */; - --- --- Temporary table structure for view `rotacion` --- - -DROP TABLE IF EXISTS `rotacion`; -/*!50001 DROP VIEW IF EXISTS `rotacion`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `rotacion` ( - `Id_Article` tinyint NOT NULL, - `warehouse_id` tinyint NOT NULL, - `total` tinyint NOT NULL, - `rotacion` tinyint NOT NULL, - `cm3` tinyint NOT NULL, - `almacenaje` tinyint NOT NULL, - `manipulacion` tinyint NOT NULL, - `auxiliar` tinyint NOT NULL, - `mermas` tinyint NOT NULL, - `cm3reparto` tinyint NOT NULL, - `grams` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - --- --- Table structure for table `rutasBoard` --- - -DROP TABLE IF EXISTS `rutasBoard`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `rutasBoard` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `Id_Ruta` int(10) unsigned NOT NULL DEFAULT '0', - `Id_Agencia` int(11) NOT NULL DEFAULT '0', - `km` bigint(10) NOT NULL DEFAULT '0', - `Dia` varchar(9) CHARACTER SET utf8 DEFAULT NULL, - `Fecha` date NOT NULL, - `Terceros` int(11) NOT NULL DEFAULT '0', - `Bultos` int(11) NOT NULL DEFAULT '0', - `Matricula` varchar(10) COLLATE utf8_unicode_ci, - `Tipo` varchar(1) CHARACTER SET utf8 NOT NULL DEFAULT '', - `year` int(4) NOT NULL, - `month` int(2) NOT NULL, - `warehouse_id` smallint(5) unsigned NOT NULL COMMENT 'A nulo si se puede enrutar desde todos los almacenes', - `coste_bulto` decimal(10,2) unsigned NOT NULL DEFAULT '0.00', - `teorico` decimal(10,2) NOT NULL DEFAULT '0.00', - `practico` decimal(10,2) NOT NULL DEFAULT '0.00', - `greuge` decimal(10,2) NOT NULL DEFAULT '0.00', - PRIMARY KEY (`id`), - UNIQUE KEY `rutasBoard_Ruta` (`Id_Ruta`), - KEY `rutasBoard_ix1` (`year`), - KEY `rutasBoard_ix2` (`month`), - KEY `rutasBoard_ix3` (`warehouse_id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Temporary table structure for view `saleVolume__` --- - -DROP TABLE IF EXISTS `saleVolume__`; -/*!50001 DROP VIEW IF EXISTS `saleVolume__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `saleVolume__` ( - `saleFk` tinyint NOT NULL, - `m3` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `tarifa_componentes` --- - -DROP TABLE IF EXISTS `tarifa_componentes`; -/*!50001 DROP VIEW IF EXISTS `tarifa_componentes`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `tarifa_componentes` ( - `Id_Componente` tinyint NOT NULL, - `Componente` tinyint NOT NULL, - `tarifa_componentes_series_id` tinyint NOT NULL, - `tarifa_class` tinyint NOT NULL, - `tax` tinyint NOT NULL, - `is_renewable` tinyint NOT NULL, - `code` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `tarifa_componentes_series` --- - -DROP TABLE IF EXISTS `tarifa_componentes_series`; -/*!50001 DROP VIEW IF EXISTS `tarifa_componentes_series`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `tarifa_componentes_series` ( - `tarifa_componentes_series_id` tinyint NOT NULL, - `Serie` tinyint NOT NULL, - `base` tinyint NOT NULL, - `margen` tinyint NOT NULL -) ENGINE=MyISAM */; -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=InnoDBDEFAULT 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=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los valores de gasto por almacen'; -/*!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 = 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 `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, countryCode, ventas, semana,año, periodo) - SELECT Provincia, code, SUM(ventas) AS ventas, vWeek, vYear, vCurrentPeriod - FROM ( - SELECT a.Provincia, c.code, SUM(a.Importe) AS ventas - FROM bi.analisis_ventas a - JOIN vn.province p ON p.name= a.provincia - JOIN vn.country c ON c.id = p.countryFk - WHERE vYear = a.Año - AND vWeek = a.Semana - GROUP BY a.Provincia - UNION ALL - SELECT a.Provincia, c.code, - sum(a.Importe) AS ventas - FROM bi.analisis_ventas a - JOIN vn.province p ON p.name= a.provincia - JOIN vn.country c ON c.id = p.countryFk - WHERE vYear - 1 = a.Año - AND vWeek = a.Semana - GROUP BY a.Provincia - UNION ALL - SELECT a.provincia,a.countryCode, a.ventas - FROM bi.analisis_ventas_provincia_evolution a - WHERE a.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 = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_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 analisis_ventas - WHERE Año > YEAR(vLastMonth) - OR (Año = YEAR(vLastMonth) AND Mes >= MONTH(vLastMonth)); - - INSERT INTO analisis_ventas ( - Familia, - Reino, - Comercial, - Comprador, - Provincia, - almacen, - Año, - Mes, - Semana, - Vista, - Importe - ) - 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, - tm.year AS Año, - tm.month AS Mes, - tm.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 tm ON tm.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 = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_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()*/ ; - - -- 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 - 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 - JOIN vn2008.cdr C ON C.src = T.extension - WHERE calldate >= datSTART AND LENGTH(C.dst) >=9 AND disposition = 'ANSWERED' AND duration - ) ll - 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; - - /* - * 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 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 - */ - - REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro) - SELECT Id_Cliente, 0,0,0,0 - FROM vn2008.Clientes; - - 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)); - - -- Protección neonatos - UPDATE bi.claims_ratio cr - JOIN vn.firstTicketShipped fts ON fts.clientFk = cr.Id_Cliente - SET recobro = 0, Ratio = 0 - WHERE fts.shipped > TIMESTAMPADD(MONTH,-1,CURDATE()); - - -- CLIENTE 7983, JULIAN SUAU - UPDATE bi.claims_ratio SET recobro = LEAST(0.05, recobro) WHERE Id_Cliente = 7983; - - -- CLIENTE 4358 - UPDATE bi.claims_ratio SET recobro = GREATEST(0.05, recobro) WHERE Id_Cliente = 4358; - - -- CLIENTE 5523, VERDECORA - UPDATE bi.claims_ratio SET recobro = GREATEST(0.12, recobro) WHERE Id_Cliente = 5523; - - -- CLIENTE 15979, SERVEIS VETERINARIS - UPDATE bi.claims_ratio SET recobro = GREATEST(0.05, recobro) WHERE Id_Cliente = 15979; - - -- CLIENTE 5189 i 8942, son de CSR i son el mateix client - UPDATE bi.claims_ratio cr - JOIN (SELECT sum(Consumo * recobro)/sum(Consumo) as recobro - FROM bi.claims_ratio - WHERE Id_Cliente IN ( 5189,8942) - ) sub - SET cr.recobro = sub.recobro - WHERE Id_Cliente IN ( 5189,8942); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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; - DECLARE vOneYearAgo DATETIME; - - SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE()); - SET vDateLong = TIMESTAMPADD(MONTH, -18,CURDATE()); - SET vOneYearAgo = TIMESTAMPADD(YEAR, -1,CURDATE()); - - DELETE FROM bi.Greuge_Evolution - WHERE (Fecha < vDateShort AND weekday(Fecha) != 1) - OR Fecha < vOneYearAgo; - - DELETE FROM bi.defaulters WHERE `date` < vDateLong; - DELETE FROM bi.defaulting WHERE `date` < vDateLong; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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.Tipos tp ON tp.tipo_id = v.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 m.Id_Article, Periodo, t.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 = 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 `comparativa_add_manual`(IN vStarted DATE, IN vEnded DATE) -BEGIN -/** - * Recalcula la tabla Comparativa para dos valores dados - * - * @param vStarted fecha desde - * @param vEnded fecha hasta - */ - - DECLARE periodStart INT; - DECLARE periodEnd INT; - - -- Seleccionamos la fecha minima/maxima del periodo que vamos a consultar - SET periodStart = vn2008.vnperiod(vStarted); - SET periodEnd = vn2008.vnperiod(vEnded); - - DELETE FROM vn2008.Comparativa - WHERE Periodo BETWEEN periodStart AND periodEnd; - - INSERT INTO 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.Tipos tp ON tp.tipo_id = v.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 periodStart AND periodEnd - AND t.Id_Cliente NOT IN(400,200) - AND r.display <> 0 - AND t.warehouse_id NOT IN (0,13) - GROUP BY m.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 - CALL vn.clientRisk_update(v_customer, v_company, v_amount); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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.code AS 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 = 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 `defaulting`(IN `vDate` DATE) -BEGIN - DECLARE vDone BOOLEAN; - DECLARE vClient INT; - DECLARE vAmount INT; - DECLARE vDued DATE; - DECLARE vAmountInvoice DECIMAL(10,2); - DECLARE vGraceDays INT; - DECLARE defaulters CURSOR FOR - SELECT client, amount, 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 Vencimiento, 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; - - DELETE FROM bi.defaulters WHERE date = vDate; - - INSERT INTO bi.defaulters(client, date, amount) - SELECT c.id, vDate, IFNULL(FLOOR(SUM(cro.amount)),0) AS amount - FROM vn.`client` c - LEFT JOIN bi.customerRiskOverdue cro ON c.id = cro.customer_id - GROUP BY c.id; - - -- marcamos si ha cambiado y heredamos la fecha defaulterSince - UPDATE bi.defaulters d - LEFT JOIN ( - SELECT * FROM( - SELECT client, amount , defaulterSince, frozened FROM bi.defaulters - WHERE date <= TIMESTAMPADD(DAY,-1, vDate) - ORDER BY date DESC) t GROUP BY client - ) yesterday using(client) - SET d.hasChanged = (IFNULL(d.amount,0) <> IFNULL(yesterday.amount,0)), - d.defaulterSince = yesterday.defaulterSince, - d.frozened = yesterday.frozened - WHERE d.date = vDate ; - - OPEN defaulters; - defaulters: LOOP - SET vDone = FALSE; - SET vAmount = 0; - FETCH defaulters INTO vClient,vAmount, vGraceDays; - IF vDone THEN - LEAVE defaulters; - END IF; - OPEN invoices; - invoices:LOOP - - FETCH invoices INTO vDued, vAmountInvoice; - IF vDone THEN - LEAVE invoices; - END IF; - - IF TIMESTAMPADD(DAY, vGraceDays, vDued) <= vDate THEN - SET vAmount = vAmount - vAmountInvoice; - IF vAmount <= 0 THEN - - UPDATE defaulters SET defaulterSince = vDued - 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 defaulters - WHERE amount = 0 - AND hasChanged = FALSE - AND `date` = vDate; - - UPDATE defaulters d - JOIN vn.config ON TRUE - SET d.frozened = NULL - WHERE `date` = vDate - AND d.amount <= config.defaultersMaxAmount; - - CALL vn.clientFreeze(); - - -- actualizamos defaulting - 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 `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 - TRUNCATE TABLE bs.clientAnnualConsumption; - - REPLACE bi.facturacion_media_anual(Id_Cliente, Consumo) - SELECT clientFk, avg(Facturacion) - FROM ( - SELECT clientFk, YEAR(issued) year, MONTH(issued) month, sum(amount) as Facturacion - FROM vn.invoiceOut - WHERE issued BETWEEN TIMESTAMPADD(YEAR,-1,CURDATE()) AND TIMESTAMPADD(DAY, - DAY(CURDATE()),CURDATE()) - GROUP BY clientFk, year, month - ) vol - GROUP BY clientFk; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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,-60,CURDATE()); -- '2019-07-01' - DECLARE datEND DATETIME DEFAULT TIMESTAMPADD(DAY,-1,CURDATE()); - - DROP TEMPORARY TABLE IF EXISTS tmp.dp; - - -- Agencias que no cobran por volumen - CREATE TEMPORARY TABLE tmp.dp - (PRIMARY KEY (ticketFk)) - ENGINE = MEMORY - SELECT t.id ticketFk, - SUM((t.zonePrice - t.zoneBonus) * ebv.ratio) AS teorico, - 00000.00 as practico, - 00000.00 as greuge, - t.clientFk, - t.shipped - FROM - vn.ticket t - JOIN vn2008.Clientes cli ON cli.Id_cliente = t.clientFk - LEFT JOIN vn2008.expeditions e ON e.ticket_id = t.id - JOIN vn.expeditionBoxVol ebv ON ebv.boxFk = e.EsBulto - JOIN vn.zone z ON t.zoneFk = z.id - WHERE - t.shipped between datSTART AND datEND - AND cli.`real` - AND t.companyFk IN (442 , 567) - AND z.isVolumetric = FALSE - GROUP BY t.id; - - -- Agencias que cobran por volumen - INSERT INTO tmp.dp - SELECT sv.ticketFk, - SUM(IFNULL(sv.freight,0)) AS teorico, - 00000.00 as practico, - 00000.00 as greuge, - sv.clientFk, - sv.shipped - FROM vn.saleVolume sv - JOIN vn.zone z ON z.id = sv.zoneFk - AND sv.shipped BETWEEN datSTART AND datEND - AND z.isVolumetric != FALSE - GROUP BY sv.ticketFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.dp_aux; - - CREATE TEMPORARY TABLE tmp.dp_aux - (PRIMARY KEY (ticketFk)) - ENGINE = MEMORY - SELECT dp.ticketFk, sum(Cantidad * Valor) as valor - FROM tmp.dp - JOIN vn2008.Movimientos m ON m.Id_Ticket = dp.ticketFk - JOIN vn2008.Movimientos_componentes mc using(Id_Movimiento) - WHERE mc.Id_Componente = 15 - GROUP BY dp.ticketFk; - - UPDATE tmp.dp - JOIN tmp.dp_aux USING(ticketFk) - SET practico = IFNULL(valor,0); - - DROP TEMPORARY TABLE tmp.dp_aux; - - CREATE TEMPORARY TABLE tmp.dp_aux - (PRIMARY KEY (ticketFk)) - ENGINE = MEMORY - SELECT dp.ticketFk, sum(Importe) Importe - FROM tmp.dp - JOIN vn2008.Greuges g ON g.Id_Ticket = dp.ticketFk - WHERE Greuges_type_id = 1 -- dif_porte - GROUP BY dp.ticketFk; - - UPDATE tmp.dp - JOIN tmp.dp_aux USING(ticketFk) - SET greuge = IFNULL(Importe,0); - - - INSERT INTO vn2008.Greuges (Id_Cliente,Comentario,Importe,Fecha, Greuges_type_id, Id_Ticket) - SELECT dp.clientFk - , concat('dif_porte ', dp.ticketFk) - , round(IFNULL(dp.teorico,0) - IFNULL(dp.practico,0) - IFNULL(dp.greuge,0),2) as Importe - , date(dp.shipped) - , 1 - ,dp.ticketFk - FROM tmp.dp - JOIN vn.client c ON c.id = dp.clientFk - WHERE ABS(IFNULL(dp.teorico,0) - IFNULL(dp.practico,0) - IFNULL(dp.greuge,0)) > 1 - AND c.isRelevant; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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 = 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 `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; - - DELETE FROM bi.Greuge_Evolution WHERE Fecha >= TIMESTAMPADD(MONTH,-1,CURDATE()); - - 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); - - WHILE datFEC < CURDATE() DO - - REPLACE bi.Greuge_Evolution(Id_Cliente, Fecha, Greuge, Ventas, Fosil) - - SELECT Id_Cliente, datFEC as Fecha, Greuge, Ventas, 0 - 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; - - 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; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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 = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `nigthlyAnalisisVentas`() -BEGIN - CALL analisis_ventas_update; - CALL analisis_ventas_simple; - CALL 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 `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 = 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 `rotacion_update`() -BEGIN -/** - * Llama a la función rotacion_update_manual para todos los articulos, desde hace una semana hasta hoy. - */ - DECLARE vMinItemFk INT; - DECLARE vMaxItemFk INT; - - - SELECT MIN(id), MAX(id) - INTO vMinItemFk, vMaxItemFk - FROM vn.item i; - CALL rotacion_update_manual(vMinItemFk, vMaxItemFk, 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`( - vItemFrom INT, - vItemTo INT, - vStartDate DATE, - vEndDate DATE -) -BEGIN - DECLARE vInventoryProvider INT DEFAULT 4; - DECLARE vLastEventFinished DATETIME; - - DROP TEMPORARY TABLE IF EXISTS timing; - CREATE TEMPORARY TABLE timing ( - `event` VARCHAR(255), - finished DATETIME, - seconds INT - ); - - INSERT INTO timing VALUES ('start', NOW(), 0); - - DROP TEMPORARY TABLE IF EXISTS tItems; - CREATE TEMPORARY TABLE tItems - (INDEX (id)) - ENGINE = MEMORY - SELECT i.id - FROM vn.item i - JOIN vn.itemType t ON t.id = i.typeFk - JOIN vn.itemCategory c ON c.id = t.categoryFk - WHERE i.id BETWEEN vItemFrom AND vItemTo - AND c.merchandise - AND c.display; - - DROP TEMPORARY TABLE IF EXISTS tTemp; - CREATE TEMPORARY TABLE tTemp - ENGINE = MEMORY - SELECT b.itemFk, t.landed dated, b.quantity, t.warehouseInFk warehouseFk - FROM vn.entry e - JOIN vn.buy b ON b.entryFk = e.id - STRAIGHT_JOIN tItems i ON i.id = b.itemFk - JOIN vn.travel t ON t.id = e.travelFk - JOIN vn.warehouse w ON w.id = t.warehouseInFk - WHERE t.landed BETWEEN vStartDate AND vEndDate - AND e.supplierFk <> vInventoryProvider - AND NOT e.isInventory - AND NOT e.isRaid - AND NOT w.isFeedStock; - - INSERT INTO tTemp - SELECT b.itemFk, t.shipped, -b.quantity, t.warehouseOutFk - FROM vn.entry e - JOIN vn.buy b ON b.entryFk = e.id - STRAIGHT_JOIN tItems i ON i.id = b.itemFk - JOIN vn.travel t ON t.id = e.travelFk - JOIN vn.warehouse w ON w.id = t.warehouseOutFk - WHERE t.shipped BETWEEN vStartDate AND vEndDate - AND e.supplierFk <> vInventoryProvider - AND NOT e.isInventory - AND NOT e.isRaid - AND NOT w.isFeedStock; - - INSERT INTO tTemp - SELECT s.itemFk, DATE(t.shipped), -s.quantity, t.warehouseFk - FROM vn.ticket t - JOIN vn.sale s ON s.ticketFk = t.id - STRAIGHT_JOIN tItems i ON i.id = s.itemFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - WHERE t.shipped BETWEEN vStartDate AND vEndDate - AND t.clientFk NOT IN (2066, 2067, 2068) - AND NOT w.isFeedStock; - - REPLACE bi.rotacion(Id_Article, warehouse_id, total, rotacion) - SELECT b.itemFk, b.warehouseFk, t.total, IF(t.total = 0, 0, ROUND((SUM(b.weightedBalance) / t.total), 2)) - FROM ( - SELECT itemFk, - warehouseFk, - @ival := IF(warehouseFk = @warehouse AND itemFk = @item, - DATEDIFF(dated, @dated), - 1 - ), - IF(warehouseFk = @warehouse AND itemFk = @item, - IF(@sd < 0, 0, @sd) * @ival, - IF(units < 0, 0, units) - ) weightedBalance, - IF(warehouseFk = @warehouse AND itemFk = @item, - @sd := @sd + units, - @sd:= units - ), - @dated := dated, - @item := itemFk, - @warehouse := warehouseFk - FROM ( - SELECT itemFk, dated, SUM(quantity) units, - warehouseFk, @dated := vStartDate, @item := 0, - @sd:= 0, @warehouse := 0, @ival := 0 - FROM tTemp - GROUP BY itemFk, warehouseFk, dated - ) t - ) b - JOIN ( - SELECT b.itemFk, t.warehouseInFk warehouseFk, SUM(b.quantity) total - FROM vn.entry e - JOIN vn.buy b ON b.entryFk = e.id - STRAIGHT_JOIN tItems i ON i.id = b.itemFk - JOIN vn.travel t ON t.id = e.travelFk - JOIN vn.warehouse w ON w.id = t.warehouseInFk - WHERE t.landed BETWEEN vStartDate AND vEndDate - AND e.supplierFk <> vInventoryProvider - AND NOT e.isInventory - AND NOT e.isRaid - AND NOT w.isFeedStock - GROUP BY itemFk, warehouseFk - ) t USING(itemFk, warehouseFk) - GROUP BY itemFk, warehouseFk; - - DROP TEMPORARY TABLE tItems, tTemp; - - SELECT MAX(finished) INTO vLastEventFinished FROM timing; - INSERT INTO timing VALUES ('replace', NOW(), TIMEDIFF(NOW(), vLastEventFinished)); - - -- Añadimos el volumen por unidad de venta - - CALL `cache`.last_buy_refresh(FALSE); - - UPDATE bi.rotacion r - JOIN `cache`.last_buy b ON r.Id_Article = b.item_id AND r.warehouse_id = b.warehouse_id - JOIN vn2008.Compres c ON c.Id_Compra = b.buy_id - JOIN vn.packaging p ON p.id = c.Id_Cubo - JOIN vn2008.Articles a ON a.Id_Article = c.Id_Article - JOIN vn2008.Tipos tp ON tp.tipo_id = a.tipo_id - JOIN vn2008.reinos re ON re.id = tp.reino_id - SET cm3 = IF(p.volume > 0, p.volume, p.width * p.depth * IF(p.height, p.height, a.medida + 10)) / IF(c.packing, c.packing, 1), - cm3reparto = a.compression * IF(p.volume > 0, p.volume, p.width * p.depth * IF(p.height, p.height, a.medida + 10)) / IF(c.packing, c.packing, 1), - grams = IF(IFNULL(c.weight,0), - (1000 * c.weight / c.Packing) / GREATEST(1,IFNULL(a.Tallos,0)), - (a.density / 1000000) * a.`compression` * IF(p.volume > 0, p.volume, p.width * p.depth * IF(p.height, p.height, a.medida + 10)) / IF(c.packing, c.packing, 1)/ GREATEST(1,IFNULL(a.Tallos,0))) - WHERE re.mercancia = TRUE - AND r.Id_Article BETWEEN vItemFrom AND vItemTo; - - SELECT MAX(finished) INTO vLastEventFinished FROM timing; - INSERT INTO timing VALUES ('volume', NOW(), TIMEDIFF(NOW(), vLastEventFinished)); - - -- Añadimos el coste de almacenamiento y manipulacion - - UPDATE bi.rotacion - JOIN ( - SELECT warehouse_id, SUM(total * rotacion * cm3) AS operatingCost - FROM bi.rotacion - WHERE Id_Article BETWEEN vItemFrom AND vItemTo - 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 OR operatingCost = 0, 0, ROUND(rotacion * cm3 * Coste_Auxiliar / operatingCost, 4)), - almacenaje = IF(rotacion < 0 OR operatingCost = 0, 0, ROUND(rotacion * cm3 * Coste_Operativo / operatingCost, 4)), - manipulacion = IF(rotacion < 0 OR operatingCost = 0, 0, ROUND(rotacion * cm3 * Coste_Manipulacion / operatingCost, 4)) - WHERE Id_Article BETWEEN vItemFrom AND vItemTo; - - SELECT MAX(finished) INTO vLastEventFinished FROM timing; - INSERT INTO timing VALUES ('almacenamiento', NOW(), TIMEDIFF(NOW(), vLastEventFinished)); - - SELECT * FROM timing; - DROP TEMPORARY TABLE timing; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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 = 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 `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 c ON c.Id_Compra = b.buy_id - join vn.item i ON i.id = c.Id_Article - join vn.itemType tp ON tp.id = i.typeFk - join vn.itemCategory ic ON ic.id = tp.categoryFk - set cm3 = vn.item_getVolume(r.Id_Article, Id_Cubo) / Packing - where ic.merchandise = 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 `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: `cache` -- @@ -10267,7 +7842,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 `departure_timing_beta` */; +/*!50003 DROP PROCEDURE IF EXISTS `departure_timing_beta__` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -10277,7 +7852,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `departure_timing_beta`(vWarehouseId INT) +CREATE DEFINER=`root`@`%` PROCEDURE `departure_timing_beta__`(vWarehouseId INT) BEGIN DECLARE done BOOL DEFAULT FALSE; @@ -10414,65 +7989,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 `last_buy_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 = 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 `last_buy_refresh__`(vRefresh BOOL) -proc: BEGIN -/** - * BERNAT: WORKING IN THIS FILE - * 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 vRefresh %TRUE para forzar el recálculo de la cache - **/ - DECLARE vCalc INT; - DECLARE started DATE; - DECLARE ended DATE; - DECLARE vLastRefresh DATE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - CALL cache_calc_unlock (vCalc); - RESIGNAL; - END; - - CALL cache_calc_start (vCalc, vRefresh, 'last_buy', NULL); - - IF !vRefresh - THEN - LEAVE proc; - END IF; - - -- TODO: ¿Se puede usar la fecha del ultimo inventario? - SET started = vn2008.date_inv();-- TIMESTAMPADD(DAY, -90, CURDATE()); - SET ended = CURDATE(); -- TIMESTAMPADD(DAY, -1, CURDATE()); - - CALL vn.buyUltimateFromInterval(NULL, started, ended); - - DELETE FROM last_buy; - - INSERT INTO last_buy (item_id, warehouse_id, buy_id, landing) - SELECT itemFk, warehouseFk, buyFk, landed - FROM tmp.buyUltimateFromInterval; - - DROP TEMPORARY TABLE tmp.buyUltimateFromInterval; - - CALL cache_calc_end (vCalc); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `prod_graphic_refresh` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14049,6 +11565,34 @@ CREATE TABLE `order` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER order_afterInsert +AFTER INSERT +ON `order` FOR EACH ROW +BEGIN + IF NEW.address_id = 2850 THEN + -- Fallo que se insertan no se sabe como tickets en este cliente + INSERT INTO vn.mail SET + `sender` = 'jgallego@verdnatura.es', + `replyTo` = 'jgallego@verdnatura.es', + `subject` = 'Creada order al address 2850', + `body` = CONCAT(account.myUserGetName(), ' ha creado la order ', + NEW.id); + END IF; +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = 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 ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `hedera`.`order_afterUpdate` AFTER UPDATE ON `order` FOR EACH ROW @@ -15149,6 +12693,142 @@ CREATE DEFINER=`root`@`%` PROCEDURE `item_getVisible`( vType INT, vPrefix VARCHAR(255)) BEGIN + +/** + * Gets visible items of the specified type at specified date. + * + * @param vWarehouse The warehouse id + * @param vDate The visible date + * @param vType The type id + * @param vPrefix The article prefix to filter or %NULL for all + * @return tmp.itemVisible Visible items + */ + DECLARE vPrefixLen SMALLINT; + DECLARE vFilter VARCHAR(255) DEFAULT NULL; + DECLARE vDateInv DATE DEFAULT vn2008.date_inv(); + DECLARE EXIT HANDLER FOR 1114 + BEGIN + GET DIAGNOSTICS CONDITION 1 + @message = MESSAGE_TEXT; + CALL vn.mail_insert( + 'cau@verdnatura.es', + NULL, + CONCAT('hedera.item_getVisible error: ', @message), + CONCAT( + 'warehouse: ', IFNULL(vWarehouse, ''), + ', Fecha:', IFNULL(vDate, ''), + ', tipo: ', IFNULL(vType,''), + ', prefijo: ', IFNULL(vPrefix,''))); + RESIGNAL; + END; + SET vPrefixLen = IFNULL(LENGTH(vPrefix), 0) + 1; + + IF vPrefixLen > 1 THEN + SET vFilter = CONCAT(vPrefix, '%'); + END IF; + + DROP TEMPORARY TABLE IF EXISTS `filter`; + CREATE TEMPORARY TABLE `filter` + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT id itemFk FROM vn.item + WHERE typeFk = vType + AND (vFilter IS NULL OR `name` LIKE vFilter); + + DROP TEMPORARY TABLE IF EXISTS currentStock; + CREATE TEMPORARY TABLE currentStock + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT itemFk, SUM(quantity) quantity + FROM ( + SELECT b.itemFk, b.quantity + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vDateInv AND vDate + AND t.warehouseInFk = vWarehouse + AND NOT e.isRaid + UNION ALL + SELECT b.itemFk, -b.quantity + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel t ON t.id = e.travelFk + WHERE t.shipped BETWEEN vDateInv AND CURDATE() + AND t.warehouseOutFk = vWarehouse + AND NOT e.isRaid + AND t.isDelivered + UNION ALL + SELECT m.itemFk, -m.quantity + FROM vn.sale m + JOIN vn.ticket t ON t.id = m.ticketFk + JOIN vn.ticketState s ON s.ticket = t.id + WHERE t.shipped BETWEEN vDateInv AND CURDATE() + AND t.warehouseFk = vWarehouse + AND s.alertLevel = 3 + ) t + GROUP BY itemFk + HAVING quantity > 0; + + DROP TEMPORARY TABLE IF EXISTS tmp; + CREATE TEMPORARY TABLE tmp + (INDEX (itemFk)) + ENGINE = MEMORY + SELECT * + FROM ( + SELECT b.itemFk, b.packageFk, b.packing + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vDateInv AND vDate + AND NOT b.isIgnored + AND b.price2 >= 0 + AND b.packageFk IS NOT NULL + ORDER BY t.warehouseInFk = vWarehouse DESC, t.landed DESC + ) t GROUP BY itemFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.itemVisible; + CREATE TEMPORARY TABLE tmp.itemVisible + ENGINE = MEMORY + SELECT i.id Id_Article, + SUBSTRING(i.`name`, vPrefixLen) Article, + t.packing, p.id Id_Cubo, + IF(p.depth > 0, p.depth, 0) depth, p.width, p.height, + CEIL(s.quantity / t.packing) etiquetas + FROM vn.item i + JOIN `filter` f ON f.itemFk = i.id + JOIN currentStock s ON s.itemFk = i.id + LEFT JOIN tmp t ON t.itemFk = i.id + LEFT JOIN vn.packaging p ON p.id = t.packageFk + WHERE CEIL(s.quantity / t.packing) > 0 + -- FIXME: Column Cubos.box not included in view vn.packaging + /* AND p.box */; + + DROP TEMPORARY TABLE + `filter`, + currentStock, + tmp; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_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_getVisible__` */; +/*!50003 SET @saved_cs_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 `item_getVisible__`( + vWarehouse TINYINT, + vDate DATE, + vType INT, + vPrefix VARCHAR(255)) +BEGIN /** * Gets visible items of the specified type at specified date. * @@ -17764,7 +15444,7 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `tpvTransaction_undo` */; -ALTER DATABASE `hedera` CHARACTER SET utf8 COLLATE utf8_general_ci ; +ALTER DATABASE `hedera` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -17858,7 +15538,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 */ ; -ALTER DATABASE `hedera` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `hedera` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `visitUser_new` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -19433,7 +17113,7 @@ DROP TABLE IF EXISTS `business_labour`; CREATE TABLE `business_labour` ( `business_id` int(11) NOT NULL, `notes` longtext, - `department_id` int(11) DEFAULT '2', + `department_id` int(11) NOT NULL, `professional_category_id` int(11) DEFAULT '0', `incentivo` double DEFAULT '0', `calendar_labour_type_id` int(11) DEFAULT '1', @@ -19447,7 +17127,7 @@ CREATE TABLE `business_labour` ( KEY `business_labour_department_idx` (`department_id`), CONSTRAINT `bus_restriction` FOREIGN KEY (`business_id`) REFERENCES `business` (`business_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `business_labour_agreement` FOREIGN KEY (`labour_agreement_id`) REFERENCES `labour_agreement` (`labour_agreement_id`) ON UPDATE CASCADE, - CONSTRAINT `business_labour_department` FOREIGN KEY (`department_id`) REFERENCES `vn`.`department` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `business_labour_department_id` FOREIGN KEY (`department_id`) REFERENCES `vn`.`department` (`id`) ON UPDATE CASCADE, CONSTRAINT `horario_tipo` FOREIGN KEY (`calendar_labour_type_id`) REFERENCES `calendar_labour_type` (`calendar_labour_type_id`) ON UPDATE CASCADE, CONSTRAINT `workcenter_labour` FOREIGN KEY (`workcenter_id`) REFERENCES `workcenter` (`workcenter_id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -19952,13 +17632,13 @@ CREATE TABLE `workcenter` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `workerTimeControlConfig` +-- Table structure for table `workerTimeControlConfig__` -- -DROP TABLE IF EXISTS `workerTimeControlConfig`; +DROP TABLE IF EXISTS `workerTimeControlConfig__`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `workerTimeControlConfig` ( +CREATE TABLE `workerTimeControlConfig__` ( `id` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `warehouseFk` smallint(6) unsigned NOT NULL, PRIMARY KEY (`id`), @@ -20488,8 +18168,7 @@ TRUNCATE TABLE clientesProveedores; IF (sn.SiglaNacion = "XB",IF(sp.CodigoProvincia IN (51,52), 22, IF (sp.CodigoProvincia IN (35,38), 21, sn.CodigoNacion)), sn.CodigoNacion) CodigoNacion, IF (sn.SiglaNacion = "XB",IF(sp.CodigoProvincia IN (51,52), "XC",IF (sp.CodigoProvincia IN (35,38), "XB", sn.SiglaNacion)), sn.SiglaNacion) SiglaNacion, IF((cl.fi REGEXP '^([[:blank:]]|[[:digit:]])'), 'J','F') PersonaFisicaJuridica, - IF((co.id = 1 OR co.id = 30) OR (co.isUeeMember = 1 AND NOT cl.isVies) , 1, - IF((co.isUeeMember = 1 AND cl.isVies), 2, 4)) TipoDocumentoPersona, + IF((co.id = 1 OR co.id = 30), 1, IF((co.isUeeMember = 1 AND cl.isVies), 2, 4)) TipoDocumentoPersona, -- IF(cl.isEqualizated, 'R', IF ((cl.isVies AND cl.countryFk <> 1) OR (NOT co.isUeeMember),'E','I'))AS CodigoIva, cl.taxTypeSageFk CodigoIva, IF(sn.SiglaNacion = "XB", IF(sp.CodigoProvincia IN (51,52), "CEUTA Y MELILLA", IF (sp.CodigoProvincia IN (35,38), "ISLAS CANARIAS",sn.Nacion)) , sn.Nacion) Nacion, @@ -22238,7 +19917,8 @@ BEGIN JOIN TiposIva t ON t.CodigoIva = it.taxTypeSageFk JOIN TiposTransacciones tt ON tt.CodigoTransaccion = it.transactionTypeSageFk LEFT JOIN tmp.invoiceDua id ON id.id = vXDiarioId - WHERE i.id = vInvoiceInFk AND i.id> 70000; -- los DUAS no son vInvoiceInFk, pero se pasan en el mismo parametro comparten id en tablas distintas de InvoiceIN (100000) dua(20000) + WHERE i.id = vInvoiceInFk + AND i.id> 70000; -- los DUAS no son vInvoiceInFk, pero se pasan en el mismo parametro comparten id en tablas distintas de InvoiceIN (100000) dua(20000) DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -22311,7 +19991,7 @@ BEGIN CodigoIva4 = vTaxCode WHERE id = vXDiarioId; ELSE - SELECT vXDiarioId; + SELECT vXDiarioId INTO vXDiarioId; END CASE; IF vIsIntracommunity THEN @@ -22358,42 +20038,31 @@ BEGIN xmi.FechaOperacion = ii.issued, xmi.MantenerAsiento = TRUE, xmi.SuFacturaNo = ii.supplierRef, - xmi.IvaDeducible1 = IF(id.id,FALSE,IF(IFNULL(xmi.BaseIva1,FALSE),FALSE,ii.isVatDeductible)), - xmi.IvaDeducible1 = IF(id.id,FALSE,IF(IFNULL(xmi.BaseIva2,FALSE),FALSE,ii.isVatDeductible)), - xmi.IvaDeducible1 = IF(id.id,FALSE,IF(IFNULL(xmi.BaseIva3,FALSE),FALSE,ii.isVatDeductible)), - xmi.IvaDeducible1 = IF(id.id,FALSE,IF(IFNULL(xmi.BaseIva4,FALSE),FALSE,ii.isVatDeductible)), + xmi.IvaDeducible1 = IF(id.id, FALSE, IF(IFNULL(xmi.BaseIva1, FALSE) = FALSE, FALSE, ii.isVatDeductible)), + xmi.IvaDeducible2 = IF(id.id, FALSE, IF(IFNULL(xmi.BaseIva2, FALSE) = FALSE, FALSE, ii.isVatDeductible)), + xmi.IvaDeducible3 = IF(id.id, FALSE, IF(IFNULL(xmi.BaseIva3, FALSE) = FALSE, FALSE, ii.isVatDeductible)), + xmi.IvaDeducible4 = IF(id.id, FALSE, IF(IFNULL(xmi.BaseIva4, FALSE) = FALSE, FALSE, ii.isVatDeductible)), xmi.FechaFacturaOriginal = x.FECHA_EX WHERE xmi.id = vXDiarioId; -- RETENCIONES - /* UPDATE XDiario_movConta_IVA xmi - JOIN vn.invoiceIn ii ON ii.id = vInvoiceInFk - JOIN vn2008.XDiario x ON x.id = xmi.id - JOIN vn.supplier s ON s.id = supplierFk - JOIN vn.invoiceInTax iit ON iit.invoiceInFk = ii.id - JOIN TiposRetencion t ON t.CodigoRetencion = ii.withholdingSageFk - SET xmi.CodigoRetencion = t.CodigoRetencion, - xmi.BaseRetencion = iit.taxableBase, - xmi.PorRetencion = t.PorcentajeRetencion, - xmi.ImporteRetencion = iit.taxableBase * (t.PorcentajeRetencion / 100) - WHERE xmi.id = vXDiarioId AND iit.taxableBase < 0 ;*/ UPDATE XDiario_movConta_IVA xmi - JOIN vn.invoiceIn ii ON ii.id = vInvoiceInFk - JOIN vn2008.XDiario x ON x.id = xmi.id - JOIN vn.supplier s ON s.id = supplierFk - JOIN vn.invoiceInTax iit ON iit.invoiceInFk = ii.id - JOIN TiposRetencion t ON t.CodigoRetencion = ii.withholdingSageFk - JOIN (SELECT SUM(BASEEURO) taxableBase, SUM(EURODEBE) taxBase - FROM vn.XDiario - WHERE BASEEURO <> 0 AND ASIEN = (SELECT ASIEN FROM vn.XDiario WHERE id = vXDiarioId) - )sub - SET xmi.CodigoRetencion = t.CodigoRetencion, - xmi.ClaveOperacionFactura = IF( t.Retencion = 'ARRENDAMIENTO Y SUBARRENDAMIENTO', 'R', xmi.ClaveOperacionFactura), - xmi.BaseRetencion = IF (t.CodigoRetencion = 2, sub.taxableBase + sub.taxBase, sub.taxableBase), - xmi.PorRetencion = t.PorcentajeRetencion, - xmi.ImporteRetencion = iit.taxableBase * - 1 - WHERE xmi.id = vXDiarioId AND iit.expenceFk= 4751000000 ; + JOIN vn.invoiceIn ii ON ii.id = vInvoiceInFk + JOIN vn2008.XDiario x ON x.id = xmi.id + JOIN vn.supplier s ON s.id = supplierFk + JOIN vn.invoiceInTax iit ON iit.invoiceInFk = ii.id + JOIN TiposRetencion t ON t.CodigoRetencion = ii.withholdingSageFk + JOIN (SELECT SUM(BASEEURO) taxableBase, SUM(EURODEBE) taxBase + FROM vn.XDiario + WHERE BASEEURO <> 0 AND ASIEN = (SELECT ASIEN FROM vn.XDiario WHERE id = vXDiarioId) + )sub + SET xmi.CodigoRetencion = t.CodigoRetencion, + xmi.ClaveOperacionFactura = IF( t.Retencion = 'ARRENDAMIENTO Y SUBARRENDAMIENTO', 'R', xmi.ClaveOperacionFactura), + xmi.BaseRetencion = IF (t.CodigoRetencion = 2, sub.taxableBase + sub.taxBase, sub.taxableBase), + xmi.PorRetencion = t.PorcentajeRetencion, + xmi.ImporteRetencion = iit.taxableBase * - 1 + WHERE xmi.id = vXDiarioId AND iit.expenceFk = 4751000000; END ;; DELIMITER ; @@ -22808,7 +20477,7 @@ BEGIN i.serial serial, i.supplierFk supplierFk, i.issued issued, - i.isVatDeductible isVatDeductible, + IF(expenceFkDeductible, FALSE, i.isVatDeductible) isVatDeductible, i.serialNumber serialNumber, IF(c.code = "EUR", '',c.code) currencyFk FROM vn.invoiceIn i @@ -24250,7 +21919,7 @@ CREATE TABLE `inbound` ( KEY `isSync` (`isSync`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -ALTER DATABASE `stock` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `stock` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -24278,7 +21947,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 */ ; -ALTER DATABASE `stock` CHARACTER SET utf8 COLLATE utf8_general_ci ; +ALTER DATABASE `stock` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -24375,7 +22044,7 @@ CREATE TABLE `outbound` ( KEY `isSync` (`isSync`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -ALTER DATABASE `stock` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `stock` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -24404,7 +22073,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 */ ; -ALTER DATABASE `stock` CHARACTER SET utf8 COLLATE utf8_general_ci ; +ALTER DATABASE `stock` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -25492,7 +23161,7 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `visible_log` */; -ALTER DATABASE `stock` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `stock` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -25525,7 +23194,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 */ ; -ALTER DATABASE `stock` CHARACTER SET utf8 COLLATE utf8_general_ci ; +ALTER DATABASE `stock` CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci ; -- -- Current Database: `util` @@ -25912,7 +23581,7 @@ DELIMITER ; /*!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 ; +ALTER DATABASE `util` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -25943,7 +23612,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 */ ; -ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `util` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP FUNCTION IF EXISTS `quarterFirstDay` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -26001,7 +23670,7 @@ DELIMITER ; /*!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 ; +ALTER DATABASE `util` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -26028,7 +23697,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 */ ; -ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `util` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP FUNCTION IF EXISTS `tomorrow` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -26055,7 +23724,7 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `twoDaysAgo` */; -ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_general_ci ; +ALTER DATABASE `util` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -26080,9 +23749,9 @@ DELIMITER ; /*!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 ; +ALTER DATABASE `util` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP FUNCTION IF EXISTS `yearRelativePosition` */; -ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_general_ci ; +ALTER DATABASE `util` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -26123,9 +23792,9 @@ DELIMITER ; /*!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 ; +ALTER DATABASE `util` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP FUNCTION IF EXISTS `yesterday` */; -ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_general_ci ; +ALTER DATABASE `util` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -26150,7 +23819,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 */ ; -ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `util` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `compareObjects` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -26268,7 +23937,7 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `debugAdd` */; -ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_general_ci ; +ALTER DATABASE `util` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -26301,7 +23970,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 */ ; -ALTER DATABASE `util` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `util` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `exec` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -26871,7 +24540,8 @@ CREATE TABLE `accountingType` ( `receiptDescription` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Descripción por defecto al crear nuevo recibo', `code` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `isAutoConciliated` tinyint(1) DEFAULT '1' COMMENT 'Si hay que marcar como conciliado el recibo al usar este tipo', - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + KEY `accountingType_code_IDX` (`code`) USING BTREE ) 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 */; @@ -26971,8 +24641,13 @@ DELIMITER ;; BEGIN DECLARE vIsEqualizated BOOL; - CALL pbx.phone_isValid(NEW.phone); - CALL pbx.phone_isValid(NEW.mobile); + IF (NEW.phone <> '') THEN + CALL pbx.phone_isValid(NEW.phone); + END IF; + + IF (NEW.mobile <> '') THEN + CALL pbx.phone_isValid(NEW.mobile); + END IF; IF NEW.isEqualizated IS NULL THEN SELECT isEqualizated @@ -27000,8 +24675,15 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`address_beforeUpdate` BEFORE UPDATE ON `vn`.`address` FOR EACH ROW BEGIN - CALL pbx.phone_isValid(NEW.phone); - CALL pbx.phone_isValid(NEW.mobile); + + IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN + CALL pbx.phone_isValid(NEW.phone); + END IF; + + IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN + CALL pbx.phone_isValid(NEW.mobile); + END IF; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -27223,7 +24905,7 @@ CREATE TABLE `agencyTerm` ( `packagePrice` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'precio extra por bulto', `routePrice` decimal(10,2) DEFAULT NULL COMMENT 'precio fijo por ruta', `minimumKm` int(11) NOT NULL DEFAULT '0', - `minimumM3` decimal(10,0) NOT NULL DEFAULT '0', + `minimumM3` decimal(10,2) NOT NULL DEFAULT '0.00', `m3Price` decimal(10,0) NOT NULL DEFAULT '0', PRIMARY KEY (`agencyFk`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -27238,8 +24920,8 @@ DROP TABLE IF EXISTS `alertLevel`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `alertLevel` ( `code` varchar(45) CHARACTER SET utf8 NOT NULL, - `alertLevel` int(11) NOT NULL, `id` int(11) NOT NULL, + `alertLevel` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -27328,13 +25010,13 @@ CREATE TABLE `autoRadioLogCall` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `autonomousRegion` +-- Table structure for table `autonomousRegion__` -- -DROP TABLE IF EXISTS `autonomousRegion`; +DROP TABLE IF EXISTS `autonomousRegion__`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `autonomousRegion` ( +CREATE TABLE `autonomousRegion__` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) CHARACTER SET utf8 NOT NULL, `geoFk` int(11) DEFAULT NULL, @@ -27345,6 +25027,96 @@ CREATE TABLE `autonomousRegion` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `autonomy` +-- + +DROP TABLE IF EXISTS `autonomy`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `autonomy` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL, + `countryFk` mediumint(8) unsigned NOT NULL, + `geoFk` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `autonomy_FK` (`countryFk`), + KEY `autonomy_FK_1` (`geoFk`), + CONSTRAINT `autonomy_FK` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `autonomy_FK_1` FOREIGN KEY (`geoFk`) REFERENCES `zoneGeo` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Comunidades autónomas o su equivalente en otros paises. Agrupación de provincias, en una categoria inferior a country.'; +/*!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 autonomy_BI +BEFORE INSERT +ON autonomy FOR EACH ROW +BEGIN + + SET NEW.geoFk = zoneGeo_new('autonomy', NEW.`name`, (SELECT geoFk FROM country WHERE id = NEW.countryFk)); + +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!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 autonomy_BU +BEFORE UPDATE +ON autonomy FOR EACH ROW +BEGIN + IF !(OLD.countryFk <=> NEW.countryFk) THEN + CALL zoneGeo_setParent(NEW.geoFk, + (SELECT geoFk FROM country WHERE id = NEW.countryFk)); + END IF; + + IF !(OLD.`name` <=> NEW.`name`) THEN + UPDATE zoneGeo SET `name` = NEW.`name` + WHERE id = NEW.geoFk; + 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 autonomy_AD +AFTER DELETE +ON autonomy FOR EACH ROW +BEGIN + CALL zoneGeo_delete(OLD.geoFk); +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; + -- -- Table structure for table `awb` -- @@ -27517,6 +25289,37 @@ CREATE TABLE `bankEntity` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Entidades bancarias '; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `bankPolicy` +-- + +DROP TABLE IF EXISTS `bankPolicy`; +/*!50001 DROP VIEW IF EXISTS `bankPolicy`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `bankPolicy` ( + `id` tinyint NOT NULL, + `ref` tinyint NOT NULL, + `amount` tinyint NOT NULL, + `balanceInterestDrawn` tinyint NOT NULL, + `commissionAvailableBalances` tinyint NOT NULL, + `openingCommission` tinyint NOT NULL, + `started` tinyint NOT NULL, + `ended` tinyint NOT NULL, + `bankFk` tinyint NOT NULL, + `companyFk` tinyint NOT NULL, + `supplierFk` tinyint NOT NULL, + `description` tinyint NOT NULL, + `hasGuarantee` tinyint NOT NULL, + `dmsFk` tinyint NOT NULL, + `notaryFk` tinyint NOT NULL, + `currencyFk` tinyint NOT NULL, + `amortizationTypeFk` tinyint NOT NULL, + `periodicityTypeFk` tinyint NOT NULL, + `insuranceExpired` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `beach` -- @@ -28002,6 +25805,7 @@ CREATE TABLE `calendar` ( KEY `calendar_employee_business_labour_id_idx` (`businessFk`), KEY `calendar_employee_calendar_state_calendar_state_id_idx` (`dayOffTypeFk`), KEY `id_index` (`id`), + CONSTRAINT `calendar_businessFk` FOREIGN KEY (`businessFk`) REFERENCES `postgresql`.`business` (`business_id`) ON UPDATE CASCADE, CONSTRAINT `calendar_employee_state_id` FOREIGN KEY (`dayOffTypeFk`) REFERENCES `postgresql`.`calendar_state` (`calendar_state_id`) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; @@ -28474,7 +26278,7 @@ CREATE TABLE `client` ( `street` longtext COLLATE utf8_unicode_ci, `fi` varchar(14) COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, - `fax` varchar(11) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'obsoleta (comprobar)', + `fax__` varchar(11) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'obsoleta (comprobar)', `email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `cc` varchar(23) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'obsoleta (comprobar)', `dueDay` smallint(6) NOT NULL DEFAULT '5', @@ -28524,7 +26328,7 @@ CREATE TABLE `client` ( `creditInsurance` int(11) DEFAULT NULL, `eypbc` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Email\\nYesterday\\nPurchases\\nBy\\nConsigna', `hasToInvoiceByAddress` tinyint(1) DEFAULT '0', - `cplusTerIdNifFk` int(11) NOT NULL DEFAULT '1' COMMENT 'OBSOLETO', + `cplusTerIdNifFk__` int(11) NOT NULL DEFAULT '1' COMMENT 'OBSOLETO', `isCreatedAsServed` tinyint(1) DEFAULT '0', `hasInvoiceSimplified` tinyint(1) NOT NULL DEFAULT '0', `iban` varchar(45) CHARACTER SET utf8 DEFAULT NULL, @@ -28581,9 +26385,13 @@ DELIMITER ;; FOR EACH ROW BEGIN - CALL pbx.phone_isValid(NEW.phone); - CALL pbx.phone_isValid(NEW.mobile); - CALL pbx.phone_isValid(NEW.fax); + IF (NEW.phone <> '') THEN + CALL pbx.phone_isValid(NEW.phone); + END IF; + + IF (NEW.mobile <> '') THEN + CALL pbx.phone_isValid(NEW.mobile); + END IF; SET NEW.accountingAccount = 4300000000 + NEW.id; @@ -28608,21 +26416,22 @@ DELIMITER ;; FOR EACH ROW BEGIN DECLARE vText VARCHAR(255) DEFAULT NULL; + DECLARE vPayMethodFk INT; -- Comprueba que el formato de los teléfonos es válido - IF !(NEW.phone <=> OLD.phone) THEN + IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN CALL pbx.phone_isValid(NEW.phone); END IF; - IF !(NEW.mobile <=> OLD.mobile) THEN + IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN CALL pbx.phone_isValid(NEW.mobile); END IF; - IF !(NEW.fax <=> OLD.fax) THEN - CALL pbx.phone_isValid(NEW.fax); - END IF; - - IF NEW.payMethodFk = 4 AND NEW.dueDay = 0 THEN + SELECT id INTO vPayMethodFk + FROM vn.payMethod + WHERE code = 'bankDraft'; + + IF NEW.payMethodFk = vPayMethodFk AND NEW.dueDay = 0 THEN SET NEW.dueDay = 5; END IF; @@ -29059,6 +26868,8 @@ CREATE TABLE `cmr` ( `addressFromFk` int(11) DEFAULT NULL, `supplierFk` int(11) DEFAULT NULL, `packagesList` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `merchandiseDetail` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `state` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `cmr_fk1_idx` (`ticketFk`), KEY `cmr_fk2_idx` (`companyFk`), @@ -29111,6 +26922,18 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +-- +-- Table structure for table `cmrConfig` +-- + +DROP TABLE IF EXISTS `cmrConfig`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `cmrConfig` ( + `dayOfMonth` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `cmr_expeditionPallet` -- @@ -29171,7 +26994,9 @@ SET character_set_client = utf8; `carrierCountry` tinyint NOT NULL, `phone` tinyint NOT NULL, `mobile` tinyint NOT NULL, - `addressFk` tinyint NOT NULL + `addressFk` tinyint NOT NULL, + `stamp` tinyint NOT NULL, + `merchandiseDetail` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; @@ -29303,6 +27128,29 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `collectionSmartTag2` +-- + +DROP TABLE IF EXISTS `collectionSmartTag2`; +/*!50001 DROP VIEW IF EXISTS `collectionSmartTag2`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `collectionSmartTag2` ( + `code` tinyint NOT NULL, + `ticketFk` tinyint NOT NULL, + `level` tinyint NOT NULL, + `wagon` tinyint NOT NULL, + `shelvingFk` tinyint NOT NULL, + `collectionFk` tinyint NOT NULL, + `agencyFk` tinyint NOT NULL, + `clientFk` tinyint NOT NULL, + `worker` tinyint NOT NULL, + `shipped` tinyint NOT NULL, + `landed` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `collectionVolumetry` -- @@ -29592,6 +27440,8 @@ CREATE TABLE `config` ( `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', `ASIEN` bigint(20) DEFAULT NULL, + `deviceHuntingMode` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Habilita el modo cazador para usuarios sin device registrado', + `tractorHuntingMode` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Habilita el modo cazador para usuarios que no se han logeado un tractor para sacar', PRIMARY KEY (`id`), KEY `fechainv_idx` (`inventoried`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -29670,6 +27520,8 @@ CREATE TABLE `conveyor` ( `y` int(11) DEFAULT NULL, `freeSpace` int(11) NOT NULL DEFAULT '0', `isBusy` tinyint(1) NOT NULL DEFAULT '0', + `tandem` int(11) DEFAULT NULL COMMENT 'agrupa conveyors para dividir las cajas por tipo en una misma ruta', + `conveyorBuildingClassFk` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `conveyor_fk1_idx` (`typeFk`), CONSTRAINT `conveyor_fk1` FOREIGN KEY (`typeFk`) REFERENCES `conveyorType` (`id`) ON UPDATE CASCADE @@ -29687,6 +27539,7 @@ CREATE TABLE `conveyorBuildingClass` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `priority` int(11) NOT NULL DEFAULT '0', + `weightThreshold` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tipo de caja para el montaje de pallets'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -29730,6 +27583,9 @@ CREATE TABLE `conveyorExpedition` ( `isIn` tinyint(4) NOT NULL DEFAULT '0', `productionMinute` int(11) DEFAULT NULL, `isOut` tinyint(4) NOT NULL DEFAULT '0', + `truck` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, + `criterion` int(11) DEFAULT NULL, + `isHeavy` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`expeditionFk`), KEY `conveyorExpedition_fk1_idx` (`conveyorFk`), KEY `conveyorExpedition_fk2_idx` (`conveyorBuildingClassFk`), @@ -29755,13 +27611,13 @@ CREATE TABLE `conveyorMode` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `conveyorMove` +-- Table structure for table `conveyorMove_kk` -- -DROP TABLE IF EXISTS `conveyorMove`; +DROP TABLE IF EXISTS `conveyorMove_kk`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `conveyorMove` ( +CREATE TABLE `conveyorMove_kk` ( `id` int(11) NOT NULL AUTO_INCREMENT, `fromConveyorFk` int(11) NOT NULL, `toConveyorFk` int(11) NOT NULL, @@ -29858,6 +27714,36 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`country_AFTER_INSERT` AFTER INSERT ON `country` FOR EACH ROW +BEGIN + + UPDATE sage.Naciones + SET countryFk = NEW.id + WHERE Nacion = NEW.country; + + IF ROW_COUNT() = 0 THEN + INSERT INTO vn.mail (sender, subject, body) + VALUES ('cau@verdnatura.es', + 'Actualizar tabla sage.Naciones', + CONCAT('Se ha insertado un nuevo país en la tabla vn.conuntry. Para el correcto funcionamiento del sistema de contabilidad es necesario actualizar la columna sage.Naciones.countryFk con el valor del nuevo país. + Hay que buscar el nuevo país: ', NEW.country, ' en la tabla sage.Naciones y actualizar el campo sage.Naciones.countryFk con el valor ', NEW.id)); + END IF; + +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = 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 ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`country_beforeUpdate` BEFORE UPDATE ON `country` FOR EACH ROW BEGIN @@ -30414,6 +28300,22 @@ CREATE TABLE `device` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `deviceLog` +-- + +DROP TABLE IF EXISTS `deviceLog`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `deviceLog` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `android_id` varchar(100) COLLATE utf8_unicode_ci NOT NULL, + `userFk` int(11) DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`) +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `deviceProduction` -- @@ -30429,9 +28331,11 @@ CREATE TABLE `deviceProduction` ( `serialNumber` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `departmentFk` int(11) DEFAULT NULL, `isOutOfService` tinyint(1) NOT NULL DEFAULT '0', + `android_id` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `device_id_UNIQUE` (`id`), UNIQUE KEY `sn_UNIQUE` (`imei`), + UNIQUE KEY `serial_number_UN` (`serialNumber`), KEY `deviceProductionModelsFgn` (`modelFk`), KEY `departmentFgn` (`departmentFk`), CONSTRAINT `departmentFgn` FOREIGN KEY (`departmentFk`) REFERENCES `department` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, @@ -30505,6 +28409,7 @@ CREATE TABLE `dms` ( `warehouseFk` smallint(5) unsigned NOT NULL DEFAULT '60', PRIMARY KEY (`id`), UNIQUE KEY `emp_id` (`companyFk`,`hardCopyNumber`,`warehouseFk`), + UNIQUE KEY `dms_hardCopyNumber_IDX` (`hardCopyNumber`,`warehouseFk`,`companyFk`) USING BTREE, KEY `trabajador_id` (`workerFk`), KEY `warehouse_id` (`warehouseFk`), KEY `dms_dmsTypeFk_idx` (`dmsTypeFk`), @@ -30517,9 +28422,9 @@ CREATE TABLE `dms` ( /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_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 ;; @@ -30535,10 +28440,9 @@ BEGIN IF NEW.hasFile THEN SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber FROM dms - WHERE companyFk = NEW.companyFk - AND warehouseFk = NEW.warehouseFk ; + WHERE warehouseFk = NEW.warehouseFk; - SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1) ; + SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1); END IF; SELECT code INTO vDmsTypeCode @@ -30573,8 +28477,7 @@ BEGIN SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber FROM dms - WHERE companyFk = NEW.companyFk - AND warehouseFk = NEW.warehouseFk; + WHERE warehouseFk = NEW.warehouseFk; SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1); END IF; @@ -30649,6 +28552,7 @@ CREATE TABLE `dua` ( `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', `ASIEN` double DEFAULT NULL, PRIMARY KEY (`id`), + UNIQUE KEY `code_UNIQUE` (`code`), KEY `fk_awb_dua_awb_idx` (`awbFk`), KEY `fk_dua_gestdoc1_idx` (`gestdocFk`), KEY `dua_fk4_idx` (`companyFk`), @@ -31251,6 +29155,24 @@ CREATE TABLE `envialiaAgency` ( UNIQUE KEY `id_UNIQUE` (`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 = 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 ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`envialiaAgency_bd` BEFORE DELETE ON `envialiaAgency` FOR EACH ROW +BEGIN + CALL util.debugAdd("envialiaAgency", OLD.id); +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `envialiaCity` @@ -31269,6 +29191,24 @@ CREATE TABLE `envialiaCity` ( KEY `postalCode` (`postalCode`) ) ENGINE=InnoDBDEFAULT 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 = 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 ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`envialiaCity_bd` BEFORE DELETE ON `envialiaCity` FOR EACH ROW +BEGIN + CALL util.debugAdd("envialiaCity", OLD.id); +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `envialiaConfig` @@ -31427,10 +29367,11 @@ CREATE TABLE `expedition` ( `itemFk` int(11) DEFAULT NULL COMMENT 'Este campo hace referencia al artículo que habria que facturar si las cajas no fueran incluidos.\\nSe debería llamar packageItemFk', `counter` smallint(5) unsigned NOT NULL, `checked` tinyint(4) NOT NULL DEFAULT '0', - `workerFk` int(11) DEFAULT NULL, + `workerFk` int(10) unsigned DEFAULT NULL, `externalId` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `packagingFk` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, + `hostFk` varchar(6) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), KEY `index1` (`agencyModeFk`), KEY `index2` (`isBox`), @@ -31438,9 +29379,11 @@ CREATE TABLE `expedition` ( KEY `index4` (`ticketFk`), KEY `expedition_fk3_idx` (`packagingFk`), KEY `expedition_itemPackingTypeFk` (`itemPackingTypeFk`), + KEY `workerFk` (`workerFk`), CONSTRAINT `expedition_fk1` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON UPDATE CASCADE, CONSTRAINT `expedition_fk2` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `expedition_fk3` FOREIGN KEY (`packagingFk`) REFERENCES `packaging` (`id`) ON UPDATE CASCADE, + CONSTRAINT `expedition_ibfk_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`), CONSTRAINT `expedition_itemPackingTypeFk` FOREIGN KEY (`itemPackingTypeFk`) REFERENCES `itemPackingType` (`code`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -31766,6 +29709,31 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `expeditionSticker__` +-- + +DROP TABLE IF EXISTS `expeditionSticker__`; +/*!50001 DROP VIEW IF EXISTS `expeditionSticker__`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `expeditionSticker__` ( + `expeditionFk` tinyint NOT NULL, + `ticketFk` tinyint NOT NULL, + `addressFk` tinyint NOT NULL, + `clientFk` tinyint NOT NULL, + `street` tinyint NOT NULL, + `postalCode` tinyint NOT NULL, + `city` tinyint NOT NULL, + `nickname` tinyint NOT NULL, + `routeFk` tinyint NOT NULL, + `beachFk` tinyint NOT NULL, + `zona` tinyint NOT NULL, + `province` tinyint NOT NULL, + `phone` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Temporary table structure for view `expeditionTimeExpended` -- @@ -32431,9 +30399,9 @@ CREATE TABLE `invoiceIn` ( /*!50003 SET @saved_cs_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 character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -32466,7 +30434,7 @@ DELIMITER ;; WHERE supplierRef = NEW.supplierRef AND supplierFk = NEW.supplierFk AND YEAR(issued) = YEAR(NEW.issued) - AND id = NEW.id + AND id <> NEW.id ) THEN CALL util.throw('reference duplicated'); END IF; @@ -32755,6 +30723,33 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `invoiceInLog` +-- + +DROP TABLE IF EXISTS `invoiceInLog`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `invoiceInLog` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `originFk` mediumint(8) unsigned NOT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL, + `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `description` text CHARACTER SET utf8, + `changedModel` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + `oldInstance` text COLLATE utf8_unicode_ci, + `newInstance` text COLLATE utf8_unicode_ci, + `changedModelId` int(11) DEFAULT NULL, + `changedModelValue` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `originFk` (`originFk`), + KEY `userFk` (`userFk`), + CONSTRAINT `invoiceInLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `invoiceInLog_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 `invoiceInSage` -- @@ -32913,18 +30908,15 @@ CREATE TABLE `invoiceOut` ( `dued` datetime DEFAULT NULL, `bankFk` int(11) DEFAULT NULL, `clientFk` int(11) DEFAULT '0', - `Id_Remesa__` int(11) DEFAULT NULL, - `Remesar__` tinyint(1) NOT NULL DEFAULT '0', - `taxableBase7` decimal(12,2) DEFAULT '0.00', - `taxableBase16` decimal(12,2) DEFAULT '0.00', - `equ1` decimal(12,2) DEFAULT '0.00', - `equ4` decimal(12,2) DEFAULT '0.00', - `vat7` decimal(12,2) DEFAULT '0.00', - `vat16` decimal(12,2) DEFAULT '0.00', - `workerFk` int(11) DEFAULT '0', + `taxableBase7__` decimal(12,2) DEFAULT '0.00', + `taxableBase16__` decimal(12,2) DEFAULT '0.00', + `equ1__` decimal(12,2) DEFAULT '0.00', + `equ4__` decimal(12,2) DEFAULT '0.00', + `vat7__` decimal(12,2) DEFAULT '0.00', + `vat16__` decimal(12,2) DEFAULT '0.00', + `workerFk__` int(11) DEFAULT '0', `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', - `liquidacion__` smallint(6) DEFAULT '0', `hasPdf` tinyint(3) unsigned NOT NULL DEFAULT '0', `booked` date DEFAULT NULL, `cplusInvoiceType477Fk` int(10) unsigned NOT NULL DEFAULT '1', @@ -32935,8 +30927,7 @@ CREATE TABLE `invoiceOut` ( UNIQUE KEY `Id_Factura` (`ref`), KEY `Id_Banco` (`bankFk`), KEY `Id_Cliente` (`clientFk`), - KEY `Id_Remesa` (`Id_Remesa__`), - KEY `Id_Trabajador` (`workerFk`), + KEY `Id_Trabajador` (`workerFk__`), KEY `empresa_id` (`companyFk`), KEY `Fecha` (`issued`), KEY `Facturas_ibfk_2_idx` (`cplusInvoiceType477Fk`), @@ -33545,6 +31536,19 @@ BEGIN IF NEW.itemFk IN (95, 98) THEN SET NEW.cm3 = 0; END IF; + + IF !(NEW.cm3delivery <=> OLD.cm3delivery) THEN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.itemCost ic + JOIN vn.sale s ON s.itemFk = ic.itemFk + JOIN vn.ticket t ON t.id = s.ticketFk AND t.warehouseFk = ic.warehouseFk + JOIN vn.route r ON r.id = t.routeFk + WHERE r.isOk = FALSE + AND ic.itemFk = NEW.itemFk + AND r.created >= CURDATE() + GROUP BY r.id; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -33864,6 +31868,23 @@ CREATE TABLE `itemRepo` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `itemSearch` +-- + +DROP TABLE IF EXISTS `itemSearch`; +/*!50001 DROP VIEW IF EXISTS `itemSearch`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `itemSearch` ( + `itemFk` tinyint NOT NULL, + `concept` tinyint NOT NULL, + `quantity` tinyint NOT NULL, + `nickname` tinyint NOT NULL, + `shipped` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `itemShelving` -- @@ -34619,6 +32640,7 @@ CREATE TABLE `itemType` ( `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT '60', `compression` decimal(5,2) DEFAULT '1.00', `itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'H', + `temperatureFk` varchar(10) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`code`), UNIQUE KEY `tipo_id_UNIQUE` (`id`), UNIQUE KEY `Tipo_UNIQUE` (`name`,`categoryFk`), @@ -34627,10 +32649,12 @@ CREATE TABLE `itemType` ( KEY `Tipos_fk3_idx` (`making`), KEY `tipos_fk4_idx` (`roleCodeFk__`), KEY `warehouseFk5_idx` (`warehouseFk`), + KEY `temperatureFk` (`temperatureFk`), CONSTRAINT `Tipos_fk3` FOREIGN KEY (`making`) REFERENCES `confectionType` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `Trabajador` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `itemType_ibfk_1` FOREIGN KEY (`categoryFk`) REFERENCES `itemCategory` (`id`) ON UPDATE CASCADE, CONSTRAINT `itemType_ibfk_2` FOREIGN KEY (`roleCodeFk__`) REFERENCES `account`.`role` (`name`) ON UPDATE CASCADE, + CONSTRAINT `temperatureFk` FOREIGN KEY (`temperatureFk`) REFERENCES `temperature` (`code`), CONSTRAINT `warehouseFk5` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT 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 */; @@ -34813,6 +32837,28 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `lastPurchases` +-- + +DROP TABLE IF EXISTS `lastPurchases`; +/*!50001 DROP VIEW IF EXISTS `lastPurchases`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `lastPurchases` ( + `landed` tinyint NOT NULL, + `warehouseFk` tinyint NOT NULL, + `warehouse` tinyint NOT NULL, + `longName` tinyint NOT NULL, + `subName` tinyint NOT NULL, + `entryFk` tinyint NOT NULL, + `stickers` tinyint NOT NULL, + `packing` tinyint NOT NULL, + `ref` tinyint NOT NULL, + `itemFk` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Temporary table structure for view `lastTopClaims` -- @@ -34961,6 +33007,27 @@ CREATE TABLE `machineDms` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `machineWorker` +-- + +DROP TABLE IF EXISTS `machineWorker`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `machineWorker` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `workerFk` int(10) unsigned NOT NULL, + `machineFk` int(11) NOT NULL, + `inTimed` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `outTimed` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `machineWorker_FK_1` (`machineFk`), + KEY `machineWorker_FK` (`workerFk`), + CONSTRAINT `machineWorker_FK` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, + CONSTRAINT `machineWorker_FK_1` FOREIGN KEY (`machineFk`) REFERENCES `machine` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Registros horarios de vehículos de almacén por empleado'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `mail` -- @@ -34970,6 +33037,7 @@ DROP TABLE IF EXISTS `mail`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `mail` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `receiver` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `sender` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `replyTo` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `subject` varchar(100) COLLATE utf8_unicode_ci NOT NULL, @@ -34986,6 +33054,31 @@ CREATE TABLE `mail` ( KEY `creation_idx` (`creationDate`) ) ENGINE=InnoDBDEFAULT 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 = 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 ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`mail_beforeInsert` +BEFORE INSERT ON `mail` FOR EACH ROW +BEGIN + + IF NEW.sender IS NOT NULL THEN + + SET NEW.receiver = NEW.sender; + + 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 `mailTemplates` @@ -35459,11 +33552,11 @@ DROP TABLE IF EXISTS `packageEquivalent`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `packageEquivalent` ( - `packageFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL, + `packagingFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `equivalentFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL, - PRIMARY KEY (`packageFk`,`equivalentFk`), + PRIMARY KEY (`packagingFk`,`equivalentFk`), KEY `packageEquivalent_fk2_idx` (`equivalentFk`), - CONSTRAINT `packageEquivalent_fk1` FOREIGN KEY (`packageFk`) REFERENCES `packaging` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `packageEquivalent_fk1` FOREIGN KEY (`packagingFk`) REFERENCES `packaging` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `packageEquivalent_fk2` FOREIGN KEY (`equivalentFk`) REFERENCES `packaging` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='recoge los modelos de cubos que se han de sustituir a efectos de presentar informes resumidos'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -35510,9 +33603,12 @@ CREATE TABLE `packaging` ( `cmrName` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `freightItemFk` int(11) DEFAULT NULL, `hasCompressionVariations` tinyint(1) DEFAULT '0' COMMENT 'Floramondo puede servirlos no llenos del todo', + `conveyorBuildingClassFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `packaging_fk1` (`itemFk`), KEY `packaging_fk2_idx` (`freightItemFk`), + KEY `packaging_FK` (`conveyorBuildingClassFk`), + CONSTRAINT `packaging_FK` FOREIGN KEY (`conveyorBuildingClassFk`) REFERENCES `conveyorBuildingClass` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `packaging_fk1` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON UPDATE CASCADE, CONSTRAINT `packaging_fk2` FOREIGN KEY (`freightItemFk`) REFERENCES `item` (`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -35529,10 +33625,30 @@ CREATE TABLE `packagingConfig` ( `id` int(11) NOT NULL AUTO_INCREMENT, `upperGap` int(11) NOT NULL, `previousPreparationMinimumSize` int(11) NOT NULL, + `defaultConveyorBuildingClass` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Altura mínima para preparar pedidos en preparacion previa'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `packingSite` +-- + +DROP TABLE IF EXISTS `packingSite`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `packingSite` ( + `code` varchar(10) COLLATE utf8_unicode_ci NOT NULL, + `hostFk` varchar(15) COLLATE utf8_unicode_ci NOT NULL, + `printerFk` tinyint(3) unsigned DEFAULT NULL, + PRIMARY KEY (`code`), + KEY `packingSite_FK` (`hostFk`), + KEY `packingSite_FK_1` (`printerFk`), + CONSTRAINT `packingSite_FK` FOREIGN KEY (`hostFk`) REFERENCES `vn2008`.`config_host` (`config_host_id`), + CONSTRAINT `packingSite_FK_1` FOREIGN KEY (`printerFk`) REFERENCES `vn2008`.`Impresoras` (`Id_Impresora`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `parking` -- @@ -35681,9 +33797,10 @@ BEGIN DECLARE cuenta_banco,cuenta_proveedor DOUBLE; DECLARE vNewBookEntry INT; DECLARE bolCASH BOOLEAN; + DECLARE isSupplierActive BOOLEAN; -- PAK 10/02/15 No se asientan los pagos directamente, salvo en el caso de las cajas de CASH - SELECT (cash = 1) INTO bolCASH FROM bank WHERE bank.id = NEW.bankFk ; + SELECT (at2.code = 'cash') INTO bolCASH FROM vn.bank b JOIN vn.accountingType at2 ON at2.id = b.cash WHERE b.id = NEW.bankFk ; IF bolCASH THEN @@ -35715,6 +33832,15 @@ BEGIN END IF; SET NEW.dueDated = IFNULL(NEW.dueDated, NEW.received); + + SELECT isActive INTO isSupplierActive + FROM supplier + WHERE id = NEW.supplierFk; + + IF isSupplierActive = FALSE THEN + CALL util.throw('SUPPLIER_INACTIVE'); + END IF; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -36310,40 +34436,6 @@ CREATE TABLE `printServerQueue2` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `printServerQueue3` --- - -DROP TABLE IF EXISTS `printServerQueue3`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `printServerQueue3` ( - `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `printerFk` tinyint(3) unsigned DEFAULT NULL, - `priorityFk` tinyint(3) unsigned DEFAULT NULL, - `labelReportFk` tinyint(3) unsigned DEFAULT NULL, - `statusFk` tinyint(3) unsigned DEFAULT '1', - `started` datetime DEFAULT NULL, - `finished` datetime DEFAULT NULL, - `param1` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `workerFk` int(11) DEFAULT NULL, - `param2` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `param3` text COLLATE utf8_unicode_ci, - `error` text COLLATE utf8_unicode_ci, - `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `reportFk__` tinyint(3) unsigned DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `Id_Impresora_2` (`printerFk`,`priorityFk`,`labelReportFk`,`statusFk`,`param1`,`workerFk`,`param2`), - KEY `Id_estado` (`statusFk`), - KEY `Id_Impresora` (`printerFk`), - KEY `Id_Prioridad` (`priorityFk`), - KEY `Id_Trabajador` (`workerFk`), - KEY `printServerQueue_FK` (`labelReportFk`), - CONSTRAINT `printServerQueue3_ibfk_3` FOREIGN KEY (`priorityFk`) REFERENCES `queuePriority` (`id`) ON UPDATE CASCADE, - CONSTRAINT `printServerQueue3_ibfk_4` FOREIGN KEY (`printerFk`) REFERENCES `vn2008`.`Impresoras` (`Id_Impresora`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `printingQueueCheck` -- @@ -36470,10 +34562,13 @@ CREATE TABLE `province` ( `warehouseFk` smallint(6) unsigned DEFAULT NULL COMMENT 'warehouse responsable de las rutas', `zoneFk` tinyint(4) DEFAULT NULL, `geoFk` int(11) DEFAULT NULL, + `autonomyFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `Paises_Id` (`countryFk`), KEY `warehouse_Id` (`warehouseFk`), KEY `provicne_zone_fk_idx` (`zoneFk`), + KEY `province_FK` (`autonomyFk`), + CONSTRAINT `province_FK` FOREIGN KEY (`autonomyFk`) REFERENCES `autonomy` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `province_ibfk_1` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE, CONSTRAINT `province_zone_fk` FOREIGN KEY (`zoneFk`) REFERENCES `vn2008`.`zones` (`zone_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `warehouse_Id` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE SET NULL ON UPDATE CASCADE @@ -36482,17 +34577,21 @@ CREATE TABLE `province` ( /*!50003 SET @saved_cs_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 character_set_client = utf8 */ ; +/*!50003 SET character_set_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`.`province_beforeInsert` BEFORE INSERT ON `province` FOR EACH ROW BEGIN + SET NEW.geoFk = zoneGeo_new('province', NEW.`name`, - (SELECT geoFk FROM country WHERE id = NEW.countryFk)); + (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk)); + + SET NEW.countryFk = (SELECT a.countryFk FROM vn.autonomy a WHERE a.id = NEW.autonomyFk); + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -36502,18 +34601,23 @@ 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 character_set_client = utf8 */ ; +/*!50003 SET character_set_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`.`province_beforeUpdate` - BEFORE UPDATE ON `province` FOR EACH ROW -BEGIN - -- IF !(OLD.geoFk <=> NEW.geoFk) THEN - -- CALL zoneGeo_throwNotEditable; - -- END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER province_beforeUpdate +BEFORE UPDATE +ON province FOR EACH ROW +BEGIN + + IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN + + SET NEW.countryFk = (SELECT a.countryFk FROM vn.autonomy a WHERE a.id = NEW.autonomyFk); + + END IF; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -36523,18 +34627,18 @@ 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 character_set_client = utf8 */ ; +/*!50003 SET character_set_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`.`province_afterUpdate` AFTER UPDATE ON `province` FOR EACH ROW BEGIN - IF !(OLD.countryFk <=> NEW.countryFk) THEN + IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN CALL zoneGeo_setParent(NEW.geoFk, - (SELECT geoFk FROM country WHERE id = NEW.countryFk)); + (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk)); END IF; IF !(OLD.`name` <=> NEW.`name`) THEN @@ -36980,6 +35084,7 @@ CREATE TABLE `route` ( KEY `route_ibfk_2_idx` (`workerFk`), KEY `fk_route_1_idx` (`zoneFk`), KEY `asdfasdf_idx` (`invoiceInFk`), + KEY `route_idxIsOk` (`isOk`), CONSTRAINT `fk_route_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `route_fk5` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `route_ibfk_1` FOREIGN KEY (`gestdocFk`) REFERENCES `dms` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, @@ -37113,6 +35218,7 @@ DROP TABLE IF EXISTS `routeConfig`; CREATE TABLE `routeConfig` ( `id` int(10) unsigned NOT NULL, `kmRate` decimal(10,4) DEFAULT NULL, + `kmTruckRate` decimal(10,4) DEFAULT NULL, `m3Distribution` decimal(10,4) DEFAULT NULL, `m3Management` decimal(10,2) DEFAULT NULL, `m3Palletization` decimal(10,2) DEFAULT NULL, @@ -37242,6 +35348,19 @@ CREATE TABLE `routeLog` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `routeRecalc` +-- + +DROP TABLE IF EXISTS `routeRecalc`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `routeRecalc` ( + `routeFk` int(11) NOT NULL, + PRIMARY KEY (`routeFk`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Queue of changed volume to recalc route volumen'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `routeUserPercentage` -- @@ -37319,9 +35438,9 @@ CREATE TABLE `sale` ( /*!50003 SET @saved_cs_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 character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -37346,7 +35465,16 @@ BEGIN AND (c.itemPackingTypeFk = i.itemPackingTypeFk OR ISNULL(c.itemPackingTypeFk)) SET c.saleTotalCount = c.saleTotalCount + 1; - + + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.route r ON r.id = t.routeFk + WHERE r.isOk = FALSE + AND s.id = NEW.id + AND r.created >= CURDATE() + GROUP BY r.id; END IF; END */;; @@ -37392,9 +35520,9 @@ 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 character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -37477,6 +35605,45 @@ BEGIN END IF; + IF !(NEW.quantity <=> OLD.quantity) THEN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.route r ON r.id = t.routeFk + WHERE r.isOk = FALSE + AND s.id = NEW.id + AND r.created >= CURDATE() + GROUP BY r.id; + END IF; +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`sale_BEFORE_DELETE` BEFORE DELETE ON `sale` FOR EACH ROW +BEGIN + IF OLD.quantity > 0 THEN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.route r ON r.id = t.routeFk + WHERE r.isOk = FALSE + AND s.id = OLD.id + AND r.created >= CURDATE() + GROUP BY r.id; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -37699,6 +35866,27 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `saleGoal` +-- + +DROP TABLE IF EXISTS `saleGoal`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `saleGoal` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `rank` smallint(6) NOT NULL, + `walletWeightFrom` int(11) NOT NULL, + `walletWeightTo` int(11) DEFAULT NULL, + `goal` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, + `goalType` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, + `amount` int(11) DEFAULT NULL, + `month` int(11) DEFAULT NULL, + `year` int(11) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `saleItemShelving__` -- @@ -38284,9 +36472,34 @@ CREATE TABLE `shelving` ( /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_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 ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER shelving_beforeInsert BEFORE INSERT ON shelving FOR EACH ROW + +BEGIN + + IF NEW.code = "" THEN + + CALL util.throw('NOT_EMPTY_CODE_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 = 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 ;; @@ -38303,6 +36516,12 @@ BEGIN WHERE sh.`code` = OLD.`code`; END IF; + + IF NEW.code = "" THEN + + CALL util.throw('NOT_EMPTY_CODE_ALLOWED'); + + END IF; END */;; DELIMITER ; @@ -38377,11 +36596,8 @@ CREATE TABLE `smartTag` ( `code` varchar(12) CHARACTER SET utf8 NOT NULL, `shelvingFk` varchar(10) CHARACTER SET utf8 DEFAULT NULL, `level` int(11) DEFAULT NULL, - `ticketFk` int(11) DEFAULT NULL, - KEY `ticket_fk` (`ticketFk`), KEY `smartTag_shelving_fk` (`shelvingFk`), - CONSTRAINT `smartTag_shelving_fk` FOREIGN KEY (`shelvingFk`) REFERENCES `shelving` (`code`) ON UPDATE CASCADE, - CONSTRAINT `smartTag_ticket_fk` FOREIGN KEY (`ticketFk`) REFERENCES `ticketCollection` (`ticketFk`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `smartTag_shelving_fk` FOREIGN KEY (`shelvingFk`) REFERENCES `shelving` (`code`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -38440,7 +36656,7 @@ CREATE TABLE `solunionCAP` ( 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 ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -38462,8 +36678,8 @@ DELIMITER ; /*!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 ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -38492,8 +36708,8 @@ DELIMITER ; /*!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 ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -38515,7 +36731,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 */ ; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; -- -- Table structure for table `sorter` @@ -38618,6 +36834,29 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +-- +-- Table structure for table `specieGeoInvasive` +-- + +DROP TABLE IF EXISTS `specieGeoInvasive`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `specieGeoInvasive` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `genusFk` int(11) NOT NULL, + `specieFk` int(11) NOT NULL, + `zoneGeofk` int(11) NOT NULL, + `isForbidden` tinyint(1) NOT NULL DEFAULT '1', + PRIMARY KEY (`id`), + KEY `specieGeoInvasive_FK` (`genusFk`), + KEY `specieGeoInvasive_FK_1` (`specieFk`), + KEY `specieGeoInvasive_FK_2` (`zoneGeofk`), + CONSTRAINT `specieGeoInvasive_FK` FOREIGN KEY (`genusFk`) REFERENCES `genus` (`id`) ON UPDATE CASCADE, + CONSTRAINT `specieGeoInvasive_FK_1` FOREIGN KEY (`specieFk`) REFERENCES `specie` (`id`) ON UPDATE CASCADE, + CONSTRAINT `specieGeoInvasive_FK_2` FOREIGN KEY (`zoneGeofk`) REFERENCES `zoneGeo` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Esta tabla recoge las prohibiciones de comerciar con especies invasoras de acuerdo con el Catálogo de Especies Exóticas Invasoras publicado por el Estado Español'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `starredModule` -- @@ -38958,7 +37197,8 @@ SET character_set_client = utf8; `landed` tinyint NOT NULL, `out` tinyint NOT NULL, `in` tinyint NOT NULL, - `almacen` tinyint NOT NULL + `almacen` tinyint NOT NULL, + `cost` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; @@ -39184,6 +37424,21 @@ CREATE TABLE `taxType` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `temperature` +-- + +DROP TABLE IF EXISTS `temperature`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `temperature` ( + `code` varchar(10) CHARACTER SET utf8 NOT NULL, + `description` text COLLATE utf8_unicode_ci, + `name` varchar(10) 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 */; + -- -- Table structure for table `thermograph` -- @@ -39308,16 +37563,7 @@ BEGIN VALUES(NEW.clientFk, IFNULL(vTransferorFirstShipped, CURDATE()), CURDATE()) ON DUPLICATE KEY UPDATE lastShipped = CURDATE(); END IF; - - IF NEW.clientFk = 2067 THEN - -- Fallo que se insertan no se sabe como tickets en este cliente - INSERT INTO vn.mail SET - `sender` = 'jgallego@verdnatura.es', - `replyTo` = 'jgallego@verdnatura.es', - `subject` = 'Creado ticket al cliente 2067', - `body` = CONCAT(account.myUserGetName(), ' ha creado el ticket ', - NEW.id); - END IF; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -39338,6 +37584,17 @@ DELIMITER ;; FOR EACH ROW BEGIN DECLARE vNewTime TIME; + + IF !(NEW.routeFk <=> OLD.routeFk) THEN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.route r + WHERE r.isOk = FALSE + AND r.id IN (OLD.routeFk,NEW.routeFk) + AND r.created >= CURDATE() + GROUP BY r.id; + END IF; + IF !(NEW.shipped <=> OLD.shipped) THEN IF YEAR(NEW.shipped) < 2000 THEN SIGNAL SQLSTATE '46000' @@ -39350,6 +37607,14 @@ BEGIN END IF; IF !(NEW.isDeleted <=> OLD.isDeleted) AND NEW.isDeleted THEN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.ticket t + JOIN vn.route r ON r.id = t.routeFk + WHERE r.isOk = FALSE + AND t.id = NEW.id + AND r.created >= CURDATE() + GROUP BY r.id; SET NEW.shipped = DATE_FORMAT(NEW.shipped, '2000-%m-%d %T'); SET NEW.landed = DATE_FORMAT(NEW.landed, '2000-%m-%d %T'); SET NEW.routeFk = NULL; @@ -39380,6 +37645,8 @@ BEGIN INSERT IGNORE INTO zoneAgencyMode (agencyModeFk,zoneFk) SELECT r.agencyModeFk, NEW.zoneFk FROM route r WHERE r.id = NEW.routeFk; + + CALL vn.routeUpdateM3(NEW.routeFk); END IF; END */;; DELIMITER ; @@ -39400,6 +37667,10 @@ DELIMITER ;; AFTER UPDATE ON `ticket` FOR EACH ROW BEGIN + /** + * Hay una versión en salix que machacará toda esta función/procedimiento avisa + * a jgallego de los cambios que quieres hacer. + */ IF !(NEW.id <=> OLD.id) OR !(NEW.warehouseFk <=> OLD.warehouseFk) OR !(NEW.shipped <=> OLD.shipped) THEN @@ -39440,9 +37711,9 @@ 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 character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -39450,6 +37721,14 @@ DELIMITER ;; BEFORE DELETE ON `ticket` FOR EACH ROW BEGIN + INSERT IGNORE INTO `vn`.`routeRecalc` (`routeFk`) + SELECT r.id + FROM vn.route r + WHERE r.isOk = FALSE + AND r.id = OLD.routeFk + AND r.created >= CURDATE() + GROUP BY r.id; + DELETE FROM sale WHERE ticketFk = OLD.id; DELETE FROM ticketDms WHERE ticketFk = OLD.id; @@ -39643,6 +37922,28 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `ticketLabel_Source` +-- + +DROP TABLE IF EXISTS `ticketLabel_Source`; +/*!50001 DROP VIEW IF EXISTS `ticketLabel_Source`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `ticketLabel_Source` ( + `level` tinyint NOT NULL, + `Id_Ticket` tinyint NOT NULL, + `Agencia` tinyint NOT NULL, + `Id_Cliente` tinyint NOT NULL, + `Notas` tinyint NOT NULL, + `Sacador` tinyint NOT NULL, + `ncarro` tinyint NOT NULL, + `horaagencia` tinyint NOT NULL, + `fecha` tinyint NOT NULL, + `urgente` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `ticketLastState` -- @@ -40855,12 +39156,15 @@ CREATE TABLE `travelThermograph` ( `temperature` enum('COOL','WARM') COLLATE utf8_unicode_ci NOT NULL, `result` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `dmsFk` int(11) DEFAULT NULL, + `temperatureFk` varchar(10) CHARACTER SET utf8 DEFAULT NULL COMMENT 'En la versión de Agosto de Salix se empezará a usar este campo y se actualizaran los anteriores mirando temperature.', PRIMARY KEY (`id`), KEY `thermograph_fk_idx` (`thermographFk`), KEY `gestdoc_fk_idx` (`dmsFk`), KEY `travel_id` (`travelFk`), KEY `warehouse_id` (`warehouseFk`), + KEY `travelThermographTemperatureFgn` (`temperatureFk`), CONSTRAINT `travelThermographDmsFgn` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON UPDATE CASCADE, + CONSTRAINT `travelThermographTemperatureFgn` FOREIGN KEY (`temperatureFk`) REFERENCES `temperature` (`code`), CONSTRAINT `travelThermographThermographFgn` FOREIGN KEY (`thermographFk`) REFERENCES `thermograph` (`id`) ON UPDATE CASCADE, CONSTRAINT `travelThermographTravelFgn` FOREIGN KEY (`travelFk`) REFERENCES `travel` (`id`), CONSTRAINT `travelThermographWarehouseFgn` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE @@ -40999,6 +39303,7 @@ CREATE TABLE `vehicle` ( `warehouseFk` smallint(6) unsigned DEFAULT NULL, `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `deliveryPointFk` int(11) DEFAULT NULL, + `isKmTruckRate` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Computar km como camión en el cálculo de salario de reparto', PRIMARY KEY (`id`), KEY `empresa_id` (`companyFk`), KEY `provinceFk_idx` (`warehouseFk`), @@ -41009,6 +39314,45 @@ CREATE TABLE `vehicle` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `vehicleWarehouse` +-- + +DROP TABLE IF EXISTS `vehicleWarehouse`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `vehicleWarehouse` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `numberPlate` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, + `model` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, + `tradeMark` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, + `numberSerial` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `vehicleWarehouse_UN` (`numberPlate`) +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Registros de vehículos utilizados en almacén'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `vehicleWarehouseTimeControl` +-- + +DROP TABLE IF EXISTS `vehicleWarehouseTimeControl`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `vehicleWarehouseTimeControl` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `workerFk` int(10) unsigned NOT NULL, + `vehicleWarehouseFk` int(10) unsigned DEFAULT NULL, + `timed` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `direction` enum('in','out') COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `vehicleWarehouseTimeControl_worker_idx` (`workerFk`), + KEY `vehicleWarehouseTimeControl_FK` (`vehicleWarehouseFk`), + CONSTRAINT `vehicleWarehouseTimeControl_FK` FOREIGN KEY (`vehicleWarehouseFk`) REFERENCES `vehicleWarehouse` (`id`) ON UPDATE CASCADE, + CONSTRAINT `vehicleWarehouseTimeControl_worker` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Registros horarios de vehículos de almacén por empleado'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `volumeConfig` -- @@ -41017,8 +39361,8 @@ DROP TABLE IF EXISTS `volumeConfig`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `volumeConfig` ( - `espai` decimal(10,2) DEFAULT NULL COMMENT 'metros cúbicos', - `carro` decimal(10,2) DEFAULT NULL COMMENT 'metros cúbicos', + `palletM3` decimal(10,2) DEFAULT NULL COMMENT 'metros cúbicos', + `trolleyM3` decimal(10,2) DEFAULT NULL COMMENT 'metros cúbicos', `dutchCompressionRate` double NOT NULL DEFAULT '1', `standardFlowerBox` int(11) NOT NULL COMMENT 'en litros', `minCompressionRate` decimal(10,2) DEFAULT '0.30' COMMENT 'minimo permitido por la empresa', @@ -41493,7 +39837,10 @@ CREATE TABLE `workerJourney` ( PRIMARY KEY (`id`), UNIQUE KEY `userFk_UNIQUE` (`userFk`,`dated`), KEY `fk_workerJourney_user_idx` (`userFk`), - CONSTRAINT `fk_workerJourney_user` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE + KEY `workerJourney_businessFk_idx` (`businessFk`), + KEY `workerJourney_dated_idx` (`dated`), + CONSTRAINT `fk_workerJourney_user` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE, + CONSTRAINT `workerJourney_businessFk` FOREIGN KEY (`businessFk`) REFERENCES `postgresql`.`business` (`business_id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -41652,10 +39999,10 @@ CREATE TABLE `workerShelving` ( KEY `workerShelving_shelving_fk` (`shelvingFk`), KEY `workerShelving_FK` (`workerFk`), KEY `workerShelving_FK_1` (`collectionFk`), - CONSTRAINT `workerShelving_collection_fk` FOREIGN KEY (`collectionFk`) REFERENCES `collection` (`id`), + CONSTRAINT `workerShelving_FK` FOREIGN KEY (`collectionFk`) REFERENCES `collection` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `workerShelving_shelving_fk` FOREIGN KEY (`shelvingFk`) REFERENCES `shelving` (`code`) ON UPDATE CASCADE, CONSTRAINT `workerShelving_worker_fk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='utilizaremos el id para establecer la prioridad de los carros a asignar'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='utilizaremos el id para establecer la prioridad de los carros a asignar'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41755,13 +40102,13 @@ CREATE TABLE `workerTimeControl` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `workerTimeControlConfig` +-- Table structure for table `workerTimeControlConfig_` -- -DROP TABLE IF EXISTS `workerTimeControlConfig`; +DROP TABLE IF EXISTS `workerTimeControlConfig_`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `workerTimeControlConfig` ( +CREATE TABLE `workerTimeControlConfig_` ( `id` int(11) NOT NULL AUTO_INCREMENT, `warehouseFk` smallint(6) unsigned NOT NULL, `host` varchar(45) COLLATE utf8_unicode_ci NOT NULL, @@ -41943,6 +40290,37 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `workerWithoutDevice` +-- + +DROP TABLE IF EXISTS `workerWithoutDevice`; +/*!50001 DROP VIEW IF EXISTS `workerWithoutDevice`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `workerWithoutDevice` ( + `workerFk` tinyint NOT NULL, + `Trabajador` tinyint NOT NULL, + `Colecciones` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + +-- +-- Temporary table structure for view `workerWithoutTractor` +-- + +DROP TABLE IF EXISTS `workerWithoutTractor`; +/*!50001 DROP VIEW IF EXISTS `workerWithoutTractor`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `workerWithoutTractor` ( + `workerFk` tinyint NOT NULL, + `Trabajador` tinyint NOT NULL, + `Colecciones` tinyint NOT NULL, + `created` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `workers20190711` -- @@ -42117,7 +40495,7 @@ CREATE TABLE `workingHours` ( CONSTRAINT `user_working_hour` FOREIGN KEY (`userId`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT 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 ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -42138,7 +40516,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 */ ; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; -- -- Table structure for table `zone` @@ -42356,7 +40734,7 @@ DROP TABLE IF EXISTS `zoneGeo`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `zoneGeo` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `type` set('country','province','town','postCode') CHARACTER SET utf8 NOT NULL, + `type` set('country','province','town','postCode','autonomy') CHARACTER SET utf8 NOT NULL, `name` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `parentFk` int(10) unsigned DEFAULT NULL, `path` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, @@ -42504,6 +40882,7 @@ CREATE TABLE `zoneWarehouse` ( PRIMARY KEY (`id`), UNIQUE KEY `zoneFk` (`zoneFk`,`warehouseFk`), KEY `warehouseFk` (`warehouseFk`), + CONSTRAINT `zoneWarehouse_fk_warehouse` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `zoneWarehouse_ibfk_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; @@ -42599,14 +40978,14 @@ 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 character_set_client = utf8 */ ;; +/*!50003 SET character_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 `printQueue_check` ON SCHEDULE EVERY 10 MINUTE STARTS '2019-11-08 01:00:00' ON COMPLETION PRESERVE ENABLE COMMENT 'Notifica en caso de que el servidor de impresión este parado' DO BEGIN +/*!50106 CREATE*/ /*!50117 DEFINER=`z-sysadmin`@`%`*/ /*!50106 EVENT `printQueue_check` ON SCHEDULE EVERY 10 MINUTE STARTS '2019-11-08 01:00:00' ON COMPLETION PRESERVE ENABLE COMMENT 'Notifica en caso de que el servidor de impresión este parado' DO BEGIN DECLARE vCurrentCount INT; DECLARE vCheckSum INT; @@ -42618,7 +40997,7 @@ DELIMITER ;; SELECT CONCAT(' ', IFNULL(pq.id, ''), ' ', IFNULL(p.path, ''),' - ', IFNULL(ls.name, ''),' + ', IFNULL(lr.name, ''),' ', IFNULL(e.Estado, ''),' ', IFNULL(w.firstname, ''), " ", IFNULL(w.lastName, ''),' ', IFNULL(pq.`error`, ''),' @@ -42673,7 +41052,7 @@ DELIMITER ;; CLOSE vCur; INSERT INTO vn2008.mail (`to`, subject, text) - VALUES ('cau@verdnatura.es, sysadmin@verdnatura.es', + VALUES ('cau@verdnatura.es', 'servidor de impresion parado', CONCAT('Hay ', vCurrentCount, ' lineas bloqueadas', vTableQueue, '')); @@ -42696,6 +41075,24 @@ END */ ;; /*!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 `route_doRecalc` */;; +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 `route_doRecalc` ON SCHEDULE EVERY 10 SECOND STARTS '2021-07-08 07:32:23' ON COMPLETION PRESERVE ENABLE DO CALL route_doRecalc */ ;; +/*!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 `sale_checkWithoutComponents` */;; DELIMITER ;; /*!50003 SET @saved_cs_client = @@character_set_client */ ;; @@ -43872,9 +42269,9 @@ 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 ;; @@ -43933,6 +42330,47 @@ BEGIN RETURN curRate; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 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 `deviceProductionUser_accessGranted` */; +/*!50003 SET @saved_cs_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 `deviceProductionUser_accessGranted`(vUserFK INT(10) , android_id VARCHAR(50)) RETURNS tinyint(1) + DETERMINISTIC +BEGIN + /* + * Comprueba si el usuario puede entrar en la aplicacion de almacen con ese movil + * + * */ + + DECLARE vIsGranted BOOLEAN; + DECLARE vDeviceProductionFk INT(11) DEFAULT NULL; + + SELECT dp.id INTO vDeviceProductionFk + FROM vn.deviceProduction dp + WHERE dp.android_id = android_id; + + IF vDeviceProductionFk THEN + + SELECT COUNT(*) INTO vIsGranted + FROM vn.deviceProductionUser dpu + WHERE dpu.userFk = vUserFK + AND dpu.deviceProductionFk = vDeviceProductionFk; + + RETURN vIsGranted; + END IF; + RETURN TRUE; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -44770,7 +43208,7 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `getInventoryDate` */; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -44790,7 +43228,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 */ ; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP FUNCTION IF EXISTS `getNewItemId` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45086,7 +43524,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 */ ; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP FUNCTION IF EXISTS `getUser` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45111,7 +43549,7 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `getUserId` */; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -45136,7 +43574,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 */ ; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP FUNCTION IF EXISTS `getWorkerCode` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45364,45 +43802,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 FUNCTION IF EXISTS `hasZone__` */; -/*!50003 SET @saved_cs_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 `hasZone__`(vLanded DATE, vAddress INT, vAgencyModeFk INT) RETURNS tinyint(1) - DETERMINISTIC -BEGIN - DECLARE vHasZone BOOLEAN DEFAULT FALSE; - - SELECT COUNT(*), id zoneFk, isIncluded INTO vHasZone, @trash, @trash FROM ( - SELECT z.id, - TIMESTAMPADD(DAY,-z.travelingDays, vLanded) shipped, - vLanded landed, - zi.isIncluded - FROM zoneGeo zgSon - JOIN zoneGeo zgFather ON zgSon.lft BETWEEN zgFather.lft AND zgFather.rgt - JOIN zoneIncluded zi ON zi.geoFk = zgFather.id - JOIN zone z ON z.id = zi.zoneFk - JOIN zoneCalendar zc ON zc.zoneFk = z.id - AND zc.delivered = vLanded - AND z.agencyModeFk = vAgencyModeFk - AND IF(TIMESTAMPADD(DAY,-z.travelingDays, vLanded) = CURDATE(), hour(now()) < hour(z.`hour`),TRUE) - WHERE zi.isIncluded - ORDER BY z.id, landed ASC, zgFather.depth DESC) t - GROUP BY id - HAVING isIncluded > 0 LIMIT 1; - RETURN vHasZone; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 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 */ ; @@ -45972,6 +44371,76 @@ 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 `machineWorker_Worker` */; +/*!50003 SET @saved_cs_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 `machineWorker_Worker`(vWorkerFk VARCHAR(10)) RETURNS varchar(20) CHARSET utf8 COLLATE utf8_unicode_ci + READS SQL DATA +BEGIN +/** + * Comprueba si existen registros en las últimas 12 horas del trabajador vWorkerFk y si tiene a nulo la hora outTimed (indica la hora que deja el vehículo) + * + * @param vWorkerFk id del trabajador + * @return Devuelve REGISTERED/UNREGISTERED en caso de que haya registros + */ + + IF (SELECT COUNT(*) + FROM machineWorker m + WHERE m.workerFk = vWorkerFk + AND m.inTimed >= TIMESTAMPADD(HOUR , -12,NOW()) AND ISNULL(m.outTimed)) + THEN + RETURN "REGISTERED"; + ELSE + RETURN "UNREGISTERED"; + END IF; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP FUNCTION IF EXISTS `machine_checkPlate` */; +/*!50003 SET @saved_cs_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 `machine_checkPlate`(vPlate VARCHAR(10)) RETURNS tinyint(1) + READS SQL DATA +BEGIN +/** + * Comprueba si existe matrícula + * + * @param vPlate matrícula del vehículo + * @return Devuelve TRUE en caso de que exista + * + */ + + IF (SELECT COUNT(*) + FROM machine m + WHERE m.plate = vPlate + ) THEN + RETURN TRUE; + ELSE + RETURN 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 DROP FUNCTION IF EXISTS `messageSend` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46083,7 +44552,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 */ ; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP FUNCTION IF EXISTS `myWorker_getId__` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46436,6 +44905,266 @@ 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 `smartTag_nextLevel` */; +/*!50003 SET @saved_cs_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 `smartTag_nextLevel`(vShelvingFk VARCHAR(10)) RETURNS int(2) + DETERMINISTIC +BEGIN + + DECLARE vLevel INT; + + SELECT count(*) + 1 INTO vLevel + FROM smartTag st + WHERE st.shelvingFk = vShelvingFk COLLATE utf8_general_ci; + + RETURN vLevel; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 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 `specie_IsForbidden` */; +/*!50003 SET @saved_cs_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 `specie_IsForbidden`(vItemFk INT, vAddressFk INT) RETURNS tinyint(1) + READS SQL DATA +BEGIN + + DECLARE vIsForbbiden BOOL; + DECLARE vLeft INT; + + SELECT zg.lft INTO vLeft + FROM vn.address a + JOIN vn.zoneGeo zg ON zg.name = a.postalCode + WHERE a.id = vAddressFk; + + SELECT sgi.isForbidden INTO vIsForbbiden + FROM vn.specieGeoInvasive sgi + JOIN vn.zoneGeo zg ON zg.id = sgi.zoneGeofk + JOIN vn.itemBotanical ib ON ib.genusFk = sgi.genusFk AND sgi.specieFk IN ('sp.',ib.specieFk) + WHERE vLeft BETWEEN zg.lft AND zg.rgt + AND ib.itemFk = vItemFk + ORDER BY zg.`depth` DESC + LIMIT 1; + + RETURN IFNULL(vIsForbbiden, 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 `testCIF` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 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 `testCIF`(vCIF VARCHAR(9)) RETURNS varchar(10) CHARSET utf8 COLLATE utf8_unicode_ci + DETERMINISTIC +BEGIN + + DECLARE vLetraInicial VARCHAR(1); + DECLARE vLetraFinal VARCHAR(1); + DECLARE vParteNumerica VARCHAR(7); + DECLARE vSuma INT DEFAULT 0; + DECLARE vNumero INT DEFAULT 0; + DECLARE i INT DEFAULT 0; + DECLARE vResult BOOL DEFAULT FALSE; + + SET vLetraInicial = SUBSTR(vCIF, 1, 1); + SET vLetraFinal = SUBSTR(vCIF, 9, 1); + SET vParteNumerica = SUBSTR(vCIF, 2, 7); + + WHILE i < 7 DO + + SET i = i + 1; + + SET vNumero = CAST(SUBSTR(vParteNumerica, i, 1) AS DECIMAL(1,0)); + + IF i MOD 2 THEN + + SET vNumero = vNumero * 2; + SET vNumero = vNumero MOD 10 + FLOOR(vNumero/10); + + END IF; + + SET vSuma = vSuma + vNumero; + + END WHILE; + + SET vSuma = vSuma MOD 10; + + IF vSuma > 0 THEN + + SET vSuma = 10 - vSuma; + + END IF; + + -- Comprobación de dígito de control + IF CAST(vLetraFinal AS DECIMAL(1,0)) = vSuma THEN + + SET vResult = TRUE; + + END IF; + + IF vSuma = 0 THEN + + SET vSuma = 10; + + END IF; + + IF CHAR(64 + vSuma) = vLetraFinal THEN + + SET vResult = TRUE; + + END IF; + + -- Sólo se aceptan letras como caracter inicial + IF ASCII(vLetraInicial) < 65 OR ASCII(vLetraInicial) > 87 THEN -- Ha de ser entre la A y la W + + SET vResult = FALSE; + + END IF; + + RETURN 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 `testNIE` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 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 `testNIE`(vNIE VARCHAR(9)) RETURNS tinyint(1) + DETERMINISTIC +BEGIN + + DECLARE vIndice INT; + DECLARE vNumero VARCHAR(7); + DECLARE vOperador VARCHAR(9); + DECLARE vParteNumerica DECIMAL(8,0); + DECLARE vLetraInicial VARCHAR(1); + DECLARE vLetraFinal VARCHAR(1); + DECLARE vLetrasFinalesPosibles VARCHAR(24) DEFAULT "TRWAGMYFPDXBNJZSQVHLCKE"; + DECLARE vLetraInicialEsIncorrecta BOOL DEFAULT FALSE; + + SET vLetraInicial = SUBSTR(vNIE, 1, 1); + SET vLetraFinal = SUBSTR(vNIE, 9, 1); + SET vNumero = SUBSTR(vNIE, 2, 7); + + CASE vLetraInicial + + WHEN 'X' THEN + + SET vOperador = "0"; + + WHEN 'Y' THEN + + SET vOperador = "1"; + + WHEN 'Z' THEN + + SET vOperador = "2"; + + ELSE + + SET vLetraInicialEsIncorrecta = TRUE; + + END CASE; + + SET vOperador = CONCAT(vOperador, vNumero); + SET vParteNumerica = CAST(vOperador AS DECIMAL(8,0)); + SET vIndice = Round(vParteNumerica Mod 23, 0) + 1; + + IF SUBSTR(vLetrasFinalesPosibles, vIndice, 1) = vLetraFinal AND vLetraInicialEsIncorrecta = FALSE THEN + + RETURN TRUE; + + ELSE + + RETURN 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 DROP FUNCTION IF EXISTS `testNIF` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 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 `testNIF`(vNIF VARCHAR(9)) RETURNS tinyint(1) + DETERMINISTIC +BEGIN + + DECLARE vIndice INT; + DECLARE vParteNumerica DECIMAL(8,0); + DECLARE vLetra VARCHAR(1); + DECLARE vLetrasPosibles VARCHAR(24) DEFAULT "TRWAGMYFPDXBNJZSQVHLCKE"; + + SET vLetra = SUBSTRING(vNIF, 9, 1); + + SET vParteNumerica = CAST(SUBSTRING(vNIF, 1, 8) AS DECIMAL(8,0)); + + SET vIndice = Round(vParteNumerica MOD 23, 0) + 1; + + If SUBSTRING(vLetrasPosibles, vIndice, 1) = vLetra Then + + RETURN TRUE; + + ELSE + + RETURN 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 DROP FUNCTION IF EXISTS `ticketGetTotal` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46483,15 +45212,16 @@ 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`@`%` FUNCTION `ticketPositionInPath`(vTicketId INT) RETURNS varchar(10) CHARSET utf8 + DETERMINISTIC BEGIN - + DECLARE vRestTicketsMaxOrder INT; DECLARE vRestTicketsMinOrder INT; DECLARE vRestTicketsPacking INT; @@ -47138,6 +45868,71 @@ 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 `vehicleWarehouseTimeControl_checkRegister` */; +/*!50003 SET @saved_cs_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 `vehicleWarehouseTimeControl_checkRegister`(vWorkerFk VARCHAR(10)) RETURNS tinyint(1) + READS SQL DATA +BEGIN +/** + * Comprueba si existen registros + * @return Devuelve TRUE en caso de que haya registros + */ + + IF (SELECT COUNT(*) + FROM vn.vehicleWarehouseTimeControl vwt + WHERE vwt.workerFk = vWorkerFk + AND vwt.timed >= TIMESTAMPADD(HOUR , -12,NOW())) + THEN + RETURN TRUE; + ELSE + RETURN 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 DROP FUNCTION IF EXISTS `vehicleWarehouse_checkNumberPlate` */; +/*!50003 SET @saved_cs_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 `vehicleWarehouse_checkNumberPlate`(vNumberPlate VARCHAR(10)) RETURNS tinyint(1) + READS SQL DATA +BEGIN +/** + * Comprueba si existe matrícula + * @return Devuelve TRUE en caso de que exista + */ + + IF (SELECT COUNT(*) + FROM vn.vehicleWarehouse + WHERE numberPlate = vNumberPlate + ) THEN + RETURN TRUE; + ELSE + RETURN 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 DROP FUNCTION IF EXISTS `workerIsBoss` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47759,17 +46554,17 @@ 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 `agencyVolume` */; +/*!50003 DROP PROCEDURE IF EXISTS `agencyVolume__` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_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 `agencyVolume`(vDated DATE, vAgency INT) +CREATE DEFINER=`root`@`%` PROCEDURE `agencyVolume__`(vDated DATE, vAgency INT) BEGIN SELECT ELT(it.temperature + 1,'Calientes','Frios','Secos') AS Temp, @@ -48062,7 +46857,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 `buyUltimate` */; +/*!50003 DROP PROCEDURE IF EXISTS `bankPolicy_notifyExpired` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -48072,13 +46867,61 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `buyUltimate`(vWarehouseFk SMALLINT, vDate DATE) +CREATE DEFINER=`root`@`%` PROCEDURE `bankPolicy_notifyExpired`() BEGIN /** - * Calcula las últimas compras realizadas hasta una fecha +* +* Manda correo cuando caduca un seguro +* de los leasing +* +*/ + INSERT INTO mail (sender,replyTo,subject,body) + SELECT 'administracion@verdnatura.es' sender, + 'noreply@verdnatura.es' replyTo, + CONCAT( + 'El seguro de la poliza ', + b.id, + ' ', + b.bank, + ' ha finalizado.' + ) subject, + CONCAT( + 'El seguro de la poliza ', + b.id, + ' ', + b.bank, + ' ha finalizado.' + ) body + FROM vn.bankPolicy bp + LEFT JOIN vn.supplier s + ON s.id = bp.supplierFk + LEFT JOIN vn.bank b + ON b.id = bp.bankFk + WHERE bp.insuranceExpired = 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 `buyUltimate` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `buyUltimate`(vWarehouseFk SMALLINT, vDated DATE) +BEGIN +/** + * Calcula las �ltimas compras realizadas hasta una fecha * - * @param vWarehouseFk Id del almacén - * @param vDate Compras hasta fecha + * @param vWarehouseFk Id del almacén + * @param vDated Compras hasta fecha * @return tmp.buyUltimate */ CALL cache.last_buy_refresh (FALSE); @@ -48092,12 +46935,19 @@ BEGIN FROM cache.last_buy WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL; - CALL vn.buyUltimateFromInterval(vWarehouseFk, CURDATE(), vDate); --- INSERT IGNORE INTO + CALL buyUltimateFromInterval(vWarehouseFk, CURDATE(), vDated); + REPLACE INTO tmp.buyUltimate SELECT itemFk, buyFk, warehouseFk FROM tmp.buyUltimateFromInterval - WHERE warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL; + WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) + AND landed <= vDated; + + INSERT IGNORE INTO tmp.buyUltimate + SELECT itemFk, buyFk, warehouseFk + FROM tmp.buyUltimateFromInterval + WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) + AND landed > vDated; DROP TEMPORARY TABLE tmp.buyUltimateFromInterval; END ;; @@ -48110,19 +46960,19 @@ 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 `buyUltimateFromInterval`(vWarehouseFk SMALLINT, vStarted DATE, vEnded DATE) BEGIN /** - * Calcula las últimas compras realizadas + * Calcula las últimas compras realizadas * desde un rango de fechas. * - * @param vWarehouseFk Id del almacén si es NULL se actualizan todos + * @param vWarehouseFk Id del almacén si es NULL se actualizan todos * @param vStarted Fecha inicial * @param vEnded Fecha fin * @return tmp.buyUltimateFromInterval @@ -48137,7 +46987,8 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval; CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval - (UNIQUE (itemFk, warehouseFk), INDEX(buyFk), INDEX(itemFk)) ENGINE = MEMORY + (PRIMARY KEY (itemFk, warehouseFk), INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk)) + ENGINE = MEMORY SELECT b.itemFk, t.warehouseInFk warehouseFk, @@ -48396,6 +47247,103 @@ 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 `buy_getVolume` */; +/*!50003 SET @saved_cs_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 `buy_getVolume`() +BEGIN +/** + * Cálculo de volumen en líneas de compra + * @table tmp.buy(buyFk) + */ + SELECT ELT(it.temperature + 1,'Calientes','Frios','Secos') Temp, + CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * + item_getVolume(b.itemFk, b.packageFk)) / vc.trolleyM3 / 1000000 ,1) AS DECIMAL(10,2)) carros , + CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * + item_getVolume(b.itemFk, b.packageFk)) / vc.palletM3 / 1000000,1) AS DECIMAL(10,2)) espais + FROM buy b + JOIN tmp.buy tb ON tb.buyFk = b.id + JOIN volumeConfig vc + JOIN item i ON i.id = b.itemFk + JOIN itemType it ON it.id = i.typeFk + GROUP BY Temp; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_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_getVolumeByAgency` */; +/*!50003 SET @saved_cs_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 `buy_getVolumeByAgency`(vDated DATE, vAgencyFk INT) +BEGIN + + DROP TEMPORARY TABLE IF EXISTS tmp.buy; + CREATE TEMPORARY TABLE tmp.buy (buyFk INT NOT NULL, PRIMARY KEY (buyFk)) ENGINE = MEMORY; + + INSERT INTO tmp.buy + SELECT b.id + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed = vDated + AND t.agencyFk IN (0, vAgencyFk); + + CALL buy_getVolume(); + DROP TEMPORARY TABLE tmp.buy; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buy_getVolumeByEntry` */; +/*!50003 SET @saved_cs_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 `buy_getVolumeByEntry`(vEntryFk INT) +BEGIN + + DROP TEMPORARY TABLE IF EXISTS tmp.buy; + CREATE TEMPORARY TABLE tmp.buy (buyFk INT NOT NULL, PRIMARY KEY (buyFk)) ENGINE = MEMORY; + + INSERT INTO tmp.buy + SELECT b.id + FROM buy b + JOIN entry e ON e.id = b.entryFk + WHERE e.id = vEntryFk; + + CALL buy_getVolume(); + DROP TEMPORARY TABLE tmp.buy; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_notifyPassport` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49054,9 +48002,9 @@ 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 character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -49122,7 +48070,7 @@ proc: BEGIN origin VARCHAR(3), price DECIMAL(10,2), priceKg DECIMAL(10,2), - KEY `itemFk` (`itemFk`) + PRIMARY KEY `itemFk` (`itemFk`) ) ENGINE = MEMORY DEFAULT CHARSET=utf8; OPEN cTravelTree; @@ -49186,14 +48134,16 @@ proc: BEGIN LEFT JOIN producer p ON p.id = i.producerFk AND p.isVisible JOIN origin o ON o.id = i.originFk JOIN ( - SELECT MAX(price) price, itemFk, priceKg - FROM tmp.ticketComponentPrice - WHERE warehouseFk = vWarehouseFk - GROUP BY itemFk + SELECT * + FROM (SELECT price, itemFk, priceKg + FROM tmp.ticketComponentPrice + WHERE warehouseFk = vWarehouseFk + ORDER BY (rate = 2) DESC) sub + GROUP BY itemFk ) bl ON bl.itemFk = tl.itemFk WHERE tl.zoneFk = vZoneFk AND tl.warehouseFk = vWarehouseFk - GROUP BY tl.itemFk; - -- on duplicatekey update + GROUP BY tl.itemFk + ON DUPLICATE KEY UPDATE available = available + VALUES(available); END LOOP; @@ -49209,9 +48159,9 @@ 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 character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -49254,6 +48204,7 @@ proc: BEGIN DECLARE vVisibleCache INT; DECLARE vRappelComponent INT DEFAULT 44; DECLARE vIsZonePremium BOOL; + DECLARE vFrenchDiscount DECIMAL(3,2) DEFAULT 0.12; SELECT (COUNT(*) > 0) INTO vIsZonePremium FROM vn.zoneFilter zf @@ -49400,20 +48351,21 @@ proc: BEGIN tcc.rate3 - b.buyingValue - b.freightValue - b.packageValue - b.comissionValue FROM tmp.ticketComponentCalculate tcc JOIN buy b ON b.id = tcc.buyFk; - /* - -- French Offer: revisar a partir de Mayo 2021 + + -- Promo Francia IF vIsFrenchVNHBuyer THEN - - INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) - SELECT tcc.warehouseFk, - tcc.itemFk, - vFrenchOffer, - - tcc.rate3 + b.buyingValue + b.freightValue + b.packageValue + b.comissionValue + ((b.buyingValue + b.freightValue + b.packageValue + b.comissionValue) * 0.18) - FROM tmp.ticketComponentCalculate tcc - JOIN buy b ON b.id = tcc.buyFk; - + + INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) + SELECT + tcc.warehouseFk, + tcc.itemFk, + vFrenchOffer, + - vFrenchDiscount * (b.buyingValue + b.freightValue + b.packageValue + b.comissionValue) / ( 1 - vFrenchDiscount) + FROM tmp.ticketComponentCalculate tcc + JOIN buy b ON b.id = tcc.buyFk; + END IF; -*/ + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentBase; CREATE TEMPORARY TABLE tmp.ticketComponentBase ENGINE = MEMORY SELECT tc.itemFk, ROUND(SUM(tc.cost), 4) AS base, tc.warehouseFk @@ -49992,6 +48944,7 @@ CREATE DEFINER=`root`@`%` PROCEDURE `clientCreate`( vProvinceFk SMALLINT(5), vCompanyFk SMALLINT(5), vPhone VARCHAR(11), + vEmail VARCHAR(255), vUserFk INT) BEGIN /** @@ -50011,6 +48964,7 @@ BEGIN street, fi, phone, + email, provinceFk, city, postcode, @@ -50027,6 +48981,7 @@ BEGIN vAddress, TRIM(vFi), vPhone, + vEmail, vProvinceFk, vCity, vPostcode, @@ -51012,7 +49967,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 `clonTravelComplete` */; +/*!50003 DROP PROCEDURE IF EXISTS `clonTravelComplete__` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -51022,8 +49977,9 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `clonTravelComplete`(IN `vTravelFk` INT, IN `vDateStart` DATE, IN `vDateEnd` DATE, IN `vRef` VARCHAR(255)) +CREATE DEFINER=`root`@`%` PROCEDURE `clonTravelComplete__`(IN `vTravelFk` INT, IN `vDateStart` DATE, IN `vDateEnd` DATE, IN `vRef` VARCHAR(255)) BEGIN +-- DEPRECATED usar travel_cloneWithEntries. jgallego /* * Clona un travel, junto con sus entradas y compras * @param vTravelFk travel a clonar @@ -51247,6 +50203,77 @@ BEGIN 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 `cmr_sendOverview` */; +/*!50003 SET @saved_cs_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 `cmr_sendOverview`() +BEGIN +/** + * Insert the monthly CMR summary in vn.mail on the 5th of each month. + */ + + SET SESSION group_concat_max_len = 1000000; +-- IF (DAY(CURDATE()) = 5) THEN + INSERT INTO + vn.mail (sender, + replyTo, + subject, + body) + SELECT + c2.email, + 'cmr@verdnatura.es', + 'Resumen CMR', + CONCAT('
+

Resumen Mensual CMR

+ + + + + + + + + ', GROUP_CONCAT('' ORDER BY c.id SEPARATOR '' ), ' +
+ Estimado cliente,
+ A continuación le enviamos el resumen menual de CMR ',UPPER(MONTHNAME(CURDATE() - INTERVAL 1 MONTH)),' ', YEAR(CURDATE() - INTERVAL 1 MONTH), '.

+ Le rogamos que nos devuelva el resumen firmado a cmr@verdnatura.es
+

+
CMRTicket
', c.id, ' ', c.ticketFk, '
+ +

+ Saludos cordiales, Dpto administración. +

') + FROM vn.cmr c + JOIN vn.address a ON c.addressToFk = a.id + JOIN vn.client c2 ON a.clientFk = c2.id + WHERE c.state = 'Pending' + AND MONTH(c.created) = MONTH(CURDATE() - INTERVAL 1 MONTH) + AND YEAR(c.created) = YEAR(CURDATE() - INTERVAL 1 MONTH) + AND c2.email IS NOT NULL -- No cogemos los CMRs dirigidos a 'Verdnatura' + GROUP BY c2.id; + + -- Actualizamos el estado a 'Enviado' + UPDATE vn.cmr c + SET c.state = 'Sent' + WHERE c.state = 'Pending' + AND MONTH(c.created) = MONTH(CURDATE() - INTERVAL 1 MONTH) + AND YEAR(c.created) = YEAR(CURDATE() - INTERVAL 1 MONTH); +-- END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -51446,9 +50473,9 @@ 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 ;; @@ -51475,7 +50502,7 @@ BEGIN LIMIT 1; IF IFNULL(vCollectionFk,0) = 0 THEN - +CALL util.debugAdd("vCollectionFk",vn.getUser()); INSERT INTO vn.collection(workerFk, itemPackingTypeFk) VALUES(vn.getUser(), vItemPackingTypeFk); @@ -51882,20 +50909,64 @@ 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 `collection_get`(vWorkerFk INT) BEGIN - SELECT c.id AS collectionFk, date(c.created) AS created - FROM vn.collection c - LEFT JOIN vn.state s ON c.stateFk = s.id - WHERE c.workerFk = vWorkerFk AND s.code = 'ON_PREPARATION'; + SELECT c.id AS collectionFk, date(c.created) AS created + FROM vn.collection c + LEFT JOIN vn.state s ON c.stateFk = s.id + WHERE c.workerFk = vWorkerFk AND s.code = 'ON_PREPARATION' + AND created >= TIMESTAMPADD(HOUR , -6,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 `collection_getTickets` */; +/*!50003 SET @saved_cs_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 `collection_getTickets`(vParamFk INT) +BEGIN + + DECLARE vAlertLevel INT; + DECLARE vItemPackingTypeFk VARCHAR(1); + + -- Si los sacadores son los de pruebas, pinta los colores + SELECT itemPackingTypeFk INTO vItemPackingTypeFk + FROM vn.collection + WHERE id = vParamFk; + + SELECT t.id ticketFk, + IF (!(vItemPackingTypeFk <=> 'V'), cc.code,CONCAT(SUBSTRING('ABCDEFGH',tc.wagon, 1),'-',tc.`level` )) `level`, + am.name as agencyName, + t.warehouseFk , + w.id as salesPersonFk, + IFNULL(tob.description,'')as observaciones + FROM vn.ticket t + LEFT JOIN vn.ticketCollection tc ON t.id = tc.ticketFk + LEFT JOIN vn.collectionColors cc ON cc.wagon = tc.wagon AND cc.shelve = tc.`level` + LEFT JOIN vn.zone z ON z.id = t.zoneFk + LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN vn.client c ON c.id = t.clientFk + LEFT JOIN vn.worker w ON w.id = c.salesPersonFk + LEFT JOIN vn.ticketObservation tob ON tob.ticketFk = t.id AND tob.observationTypeFk = 1 + WHERE tc.collectionFk = vParamFk OR (t.id = vParamFk AND t.id>2000000); + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -51999,7 +51070,1059 @@ 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 `collection_new` */; +/*!50003 DROP PROCEDURE IF EXISTS `collection_newSmartTag` */; +/*!50003 SET @saved_cs_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 `collection_newSmartTag`(vSectorFk INT) +proc:BEGIN + + DECLARE vIsPreviousPrepared BOOLEAN; + DECLARE vCollectionFk INT; + DECLARE vWarehouseFk INT; + DECLARE vMaxTickets INT; + DECLARE vStateFk INT; + DECLARE vFirstTicketFk INT; + DECLARE vHour INT; + DECLARE vMinute INT; + DECLARE vWorker INT; + DECLARE vWorkerCode VARCHAR(3); + DECLARE vWagon INT; + DECLARE vWagonCounter INT; + DECLARE vShelve INT; + DECLARE vTicket INT; + DECLARE vTicketToSplit INT; + DECLARE myUserIsSalesPersonRole BOOLEAN; + DECLARE vPrintedTickets INT; + DECLARE vMaxTicketPrinted INT; + DECLARE vItemPackingTypeFk VARCHAR(1); + DECLARE hasAssignedTickets BOOLEAN; + DECLARE vMaxNotReadyCollections INT DEFAULT 0; + DECLARE vNotReadyCollections INT; + DECLARE vSectorCode VARCHAR(20); + DECLARE vWagons INT; + + SELECT w.code, w.id INTO vWorkerCode, vWorker + FROM vn.worker w + WHERE w.id = vn.getUser(); + +-- Si hay colecciones sin terminar, sale del proceso + SELECT count(*) INTO vNotReadyCollections + FROM vn.collection c + WHERE c.workerFk = vn.getUser() + AND c.saleTotalCount > c.salePickedCount + 1 + AND c.created > TIMESTAMPADD(HOUR , -5,NOW()); + + IF vMaxNotReadyCollections < vNotReadyCollections THEN + + LEAVE proc; + + END IF; + + -- Establecemos el almacén y si es un sector de preparación previa, así como el estado para los tickets que se vayan preparando + SELECT isPreviousPrepared, warehouseFk, itemPackingTypeFk, code + INTO vIsPreviousPrepared, vWarehouseFk, vItemPackingTypeFk, vSectorCode + FROM vn.sector + WHERE id = vSectorFk; + + -- Cogemos el numero de wagons del trabajador + SELECT COUNT(ws.id) + FROM workerShelving ws + WHERE ws.workerFk = vWorker + AND ws.collectionFk IS NULL + INTO vWagons; + + SET vMaxTicketPrinted = 8 * vWagons; + SET vMaxTickets = 3 * vWagons; + + + IF vIsPreviousPrepared THEN + + LEAVE proc; -- Hasta que tengamos el altillo, vamos a cancelar esta opcion + + SELECT id INTO vStateFk + FROM vn.state + WHERE `code` = 'PREVIOUS_PREPARATION'; + ELSE + + SELECT id INTO vStateFk + FROM vn.state + WHERE `code` = 'ON_PREPARATION'; + + END IF; + + -- Averiguamos si es comercial el usuario + SELECT FALSE -- (r.name = 'salesPerson') + INTO myUserIsSalesPersonRole + FROM account.user u + JOIN account.role r ON r.id = u.role + WHERE u.id = vn.getUser(); + + -- Se obtiene nº de colección y el buffer con los pedidos preparables + INSERT INTO vn.collection + SET workerFk = account.myUser_getId(), + itemPackingTypeFk = vItemPackingTypeFk; + + SELECT LAST_INSERT_ID() INTO vCollectionFk; + + UPDATE workerShelving + SET collectionFk = vCollectionFk + WHERE workerFk = vWorker + AND collectionFk IS NULL; + + CALL vn.productionControl(vWarehouseFk, 0); + + -- Comprobamos si hay tickets asignados. En ese caso, nos centramos exclusivamente en esos tickets + -- y los sacamos independientemente de problemas o tamaños + SELECT COUNT(*) INTO hasAssignedTickets + FROM tmp.productionBuffer pb + JOIN vn.state s ON s.id = pb.state + WHERE s.code = 'PICKER_DESIGNED' + AND pb.workerCode = vWorkerCode + AND LENGTH(pb.problem) = 0; + + IF hasAssignedTickets THEN + + UPDATE vn.collection + SET itemPackingTypeFk = NULL + WHERE id = vCollectionFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketToSplit; + CREATE TEMPORARY TABLE tmp.ticketToSplit + SELECT pb.ticketFk + FROM tmp.productionBuffer pb + JOIN vn.state s ON s.id = pb.state + WHERE s.code = 'PICKER_DESIGNED' + AND pb.workerCode = vWorkerCode + AND LENGTH(pb.problem) = 0 + ORDER BY HH, + mm, + s.`order` DESC, + pb.m3 DESC; + + WHILE (SELECT COUNT(*) FROM tmp.ticketToSplit) DO + + SELECT MIN(ticketFk) INTO vTicketToSplit + FROM tmp.ticketToSplit; + + CALL vn.ticket_splitItemPackingType(vTicketToSplit); + + INSERT INTO vn.ticketCollection(ticketFk, collectionFk) + SELECT ticketFk, vCollectionFk + FROM tmp.ticketIPT; + + DELETE FROM tmp.ticketToSplit + WHERE ticketFk = vTicketToSplit; + + DROP TEMPORARY TABLE tmp.ticketIPT; + + END WHILE; + + CALL vn.productionControl(vWarehouseFk, 0); + + ELSE + + SELECT COUNT(*) INTO vPrintedTickets + FROM tmp.productionBuffer pb + JOIN vn.state s ON s.id = pb.state + JOIN vn.agencyMode am ON am.id = pb.agencyModeFk + JOIN vn.agency a ON a.id = am.agencyFk + WHERE pb.shipped = CURDATE() + AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) + AND s.isPreparable + AND (pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH) + OR pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV) + OR pb.F > 0 AND vItemPackingTypeFk = 'F' AND ISNULL(pb.collectionF) + OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)); + + SET vMaxTicketPrinted = vMaxTicketPrinted - vPrintedTickets; + -- AutoPRINT + + IF vMaxTicketPrinted > 0 THEN + + INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) + SELECT s2.id, pb.ticketFk, vn.getUser() + FROM tmp.productionBuffer pb + JOIN vn.agencyMode am ON am.id = pb.agencyModeFk + JOIN vn.agency a ON a.id = am.agencyFk + JOIN vn.state s ON s.id = pb.state + JOIN vn.state s2 ON s2.code = 'PRINTED_AUTO' + JOIN vn.ticket t ON t.id = pb.ticketFk + WHERE pb.shipped = CURDATE() + AND LENGTH(pb.problem) = 0 + AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) + AND s.isPrintable + AND (pb.m3 > 0.05 OR s.isOK) + AND (pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH) + OR pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV) + OR pb.F > 0 AND vItemPackingTypeFk = 'F' AND ISNULL(pb.collectionF) + OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)) + AND t.created < TIMESTAMPADD(MINUTE, -10, NOW()) + ORDER BY HH, + mm, + s.`order` DESC, + pb.m3 DESC + LIMIT vMaxTicketPrinted; + + END IF; + + -- Se seleccionan los primeros tickets, asignando colección para dejarlos bloqueados a otros sacadores. + -- Se splitan los tickets preparables, para que solo tengan un tipo de empaquetado + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketToSplit; + CREATE TEMPORARY TABLE tmp.ticketToSplit + SELECT pb.ticketFk + FROM tmp.productionBuffer pb + JOIN vn.agencyMode am ON am.id = pb.agencyModeFk + JOIN vn.agency a ON a.id = am.agencyFk + JOIN vn.ticketStateToday tst ON tst.ticket = pb.ticketFk + JOIN vn.state s ON s.id = tst.state + WHERE ( pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH) + OR pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV) + OR pb.F > 0 AND vItemPackingTypeFk = 'F' AND ISNULL(pb.collectionF) + OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)) + AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) + AND LENGTH(pb.problem) = 0 + AND s.isPreparable + AND NOT myUserIsSalesPersonRole + ORDER BY pb.HH, pb.mm, s.`order` DESC + LIMIT vMaxTickets; + + WHILE (SELECT COUNT(*) FROM tmp.ticketToSplit) DO + + SELECT MIN(ticketFk) INTO vTicketToSplit + FROM tmp.ticketToSplit; + + CALL vn.ticket_splitItemPackingType(vTicketToSplit); + + INSERT INTO vn.ticketCollection(ticketFk, collectionFk) + SELECT ticketFk, vCollectionFk + FROM tmp.ticketIPT + WHERE itemPackingTypeFk = vItemPackingTypeFk; + + DELETE FROM tmp.ticketToSplit + WHERE ticketFk = vTicketToSplit; + + DROP TEMPORARY TABLE tmp.ticketIPT; + + END WHILE; + + END IF; + + -- Creamos una tabla temporal con los datos que necesitamos para depurar la colección + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + SELECT pb.ticketFk, + pb.`lines`, + pb.m3 * 1000 liters, + 0 as height, + 0 as shelve, + 0 as wagon, + pb.productionOrder, + pb.HH, + pb.mm + FROM tmp.productionBuffer pb + JOIN vn.ticketCollection tc ON tc.ticketFk = pb.ticketFk + WHERE tc.collectionFk = vCollectionFk + LIMIT vMaxTickets; + + -- Es importante que el primer ticket se coja en todos los casos + SET vFirstTicketFk = 0; + + SELECT ticketFk, HH, mm + INTO vFirstTicketFk, vHour, vMinute + FROM tmp.ticket + ORDER BY productionOrder DESC, HH, mm + LIMIT 1; + + -- Hay que excluir aquellos que no tengan la misma hora de preparación + DELETE + FROM tmp.ticket + WHERE HH != vHour + OR mm != vMinute; + + -- En el caso de pedidos de más volumen de un carro, la colección será monoticket. Pero si el primer pedido + -- no es monoticket, excluimos a los de más de un carro + IF (SELECT (t.liters > vc.trolleyM3 * 1000) + FROM tmp.ticket t + JOIN vn.volumeConfig vc + WHERE t.ticketFk = vFirstTicketFk) THEN + + DELETE + FROM tmp.ticket + WHERE ticketFk != vFirstTicketFk; + + ELSE + + DELETE t.* + FROM tmp.ticket t + JOIN vn.volumeConfig vc + WHERE t.liters > vc.trolleyM3 * 1000; + + END IF; + + -- Elimina los tickets bloqueados que no se van a preparar + DELETE tc.* + FROM vn.ticketCollection tc + LEFT JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND t.ticketFk IS NULL; + + /* + * + * Construccion del tren + * + */ + + -- Establece altura máxima por pedido, porque las plantas no se pueden recostar. + UPDATE tmp.ticket t + JOIN + ( SELECT MAX(i.size) maxHeigth, + tc.ticketFk + FROM vn.ticketCollection tc + JOIN vn.sale s ON s.ticketFk = tc.ticketFk + JOIN vn.item i ON i.id = s.itemFk + WHERE i.itemPackingTypeFk = 'V' + AND tc.collectionFk = vCollectionFk + GROUP BY tc.ticketFk) sub ON sub.ticketFk = t.ticketFk + SET t.height = IFNULL(sub.maxHeigth,0); + + -- Vamos a generar una tabla con todas las posibilidades de asignacion de pedido + DROP TEMPORARY TABLE IF EXISTS tmp.wagonsVolumetry; + CREATE TEMPORARY TABLE tmp.wagonsVolumetry + SELECT cv.`level` as shelve, + 1 as wagon, + cv.`lines`, + cv.liters, + cv.height + FROM vn.collectionVolumetry cv; + + SET vWagonCounter = 1; + + WHILE vWagonCounter < vWagons DO + + SET vWagonCounter = vWagonCounter + 1; + + INSERT INTO tmp.wagonsVolumetry(shelve, wagon, `lines`, liters, height) + SELECT cv.`level` as shelve, + vWagonCounter as wagon, + cv.`lines`, + cv.liters, + cv.height + FROM vn.collectionVolumetry cv + WHERE cv.itemPackingTypeFk = IFNULL(vItemPackingTypeFk, 'H'); + + END WHILE; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketShelve; + CREATE TEMPORARY TABLE tmp.ticketShelve + SELECT ticketFk, shelve, wagon, linesDif, LitersDif, heightDif + FROM ( + SELECT t.ticketFk, + wv.shelve, + wv.wagon, + t.productionOrder, + CAST(wv.`lines` AS SIGNED) - t.`lines` as linesDif, + CAST(wv.liters AS SIGNED) - t.liters as litersDif, + CAST(wv.height AS SIGNED) - t.height as heightDif + FROM tmp.wagonsVolumetry wv + JOIN tmp.ticket t + ) sub + WHERE linesDif >= 0 + AND litersDif >= 0 + AND heightDif >= 0 + ORDER BY productionOrder DESC, linesDif, LitersDif, heightDif ; + + -- Insertamos una opcion virtual para carro completo. Todo ticket tiene que poder entrar en un carro completo.... + INSERT INTO tmp.ticketShelve(ticketFk, shelve, wagon, linesDif, LitersDif, heightDif) + SELECT t.ticketFk, 0, wv.wagon, 999, 999,999 + FROM tmp.ticket t + JOIN tmp.wagonsVolumetry wv + GROUP BY t.ticketFk, wv.wagon; + + SET vWagonCounter = 0; + + WHILE vWagonCounter < vWagons DO + + SET vWagonCounter = vWagonCounter + 1; + + -- Asignamos la primera balda util al primer pedido + IF vWagonCounter = 1 THEN + + SELECT shelve INTO vShelve + FROM tmp.ticketShelve + WHERE ticketFk = vFirstTicketFk + AND wagon = vWagonCounter + ORDER BY heightDif, litersDif, linesDif + LIMIT 1; + + ELSE + + SELECT shelve, ticketFk INTO vShelve, vFirstTicketFk + FROM tmp.ticketShelve + WHERE wagon = vWagonCounter + ORDER BY heightDif, litersDif, linesDif + LIMIT 1; + + END IF; + + IF vShelve > 0 THEN + + UPDATE tmp.ticket + SET shelve = vShelve, + wagon = vWagonCounter + WHERE ticketFk = vFirstTicketFk; + + DELETE FROM tmp.ticketShelve + WHERE ticketFk = vFirstTicketFk + OR (shelve = vShelve AND wagon = vWagonCounter); + + WHILE (SELECT COUNT(*) FROM tmp.ticketShelve WHERE wagon = vWagonCounter) DO + + SELECT ticketFk, shelve + INTO vTicket, vShelve + FROM tmp.ticketShelve + WHERE wagon = vWagonCounter + LIMIT 1; + + UPDATE tmp.ticket + SET shelve = vShelve, + wagon = vWagonCounter + WHERE ticketFk = vTicket; + + DELETE FROM tmp.ticketShelve + WHERE ticketFk = vTicket + OR (shelve = vShelve AND wagon = vWagonCounter); + + END WHILE; + + ELSE + + UPDATE tmp.ticket + SET shelve = 1, wagon = vWagonCounter + WHERE ticketFk = vFirstTicketFk; + + DELETE FROM tmp.ticketShelve + WHERE ticketFk = vFirstTicketFk + AND wagon != vWagonCounter; + + END IF; + + END WHILE; + + -- Eliminamos los que se han quedado sin balda + DELETE FROM tmp.ticket WHERE shelve = 0; + + -- Elimina los tickets bloqueados que no se van a preparar + DELETE tc.* + FROM vn.ticketCollection tc + LEFT JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND t.ticketFk IS NULL; + + -- Elimina los tickets que ya estan en otra coleccion + DELETE tc.* + FROM vn.ticketCollection tc + JOIN vn.ticketCollection tc2 ON tc2.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND tc2.collectionFk != vCollectionFk; + + -- Actualiza el estado de la colección + UPDATE vn.collection c + JOIN vn.state st ON st.code = 'ON_PREPARATION' + SET c.stateFk = st.id + WHERE c.id = vCollectionFk; + + -- Asigna las bandejas y las smartTags + SET @wagon := 0; + UPDATE vn.ticketCollection tc + JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk + JOIN (SELECT @wagon:=@wagon+1 as wagon, ws.shelvingFk + FROM workerShelving ws + WHERE ws.collectionFk = vCollectionFk) sub ON sub.wagon = t.wagon + JOIN smartTag s ON s.shelvingFk = sub.shelvingFk AND s.`level` = t.shelve + SET tc.`level` = t.shelve, tc.wagon = t.wagon, tc.smartTagFk = s.code; + + -- Actualiza el estado de los tickets + INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) + SELECT vStateFk, ticketFk, account.myUser_getId() + FROM vn.ticketCollection tc + WHERE tc.collectionFk = vCollectionFk; + + -- Aviso para la preparacion previa + INSERT INTO vn.ticketDown(ticketFk, collectionFk) + SELECT tc.ticketFk, tc.collectionFk + FROM vn.ticketCollection tc + WHERE tc.collectionFk = vCollectionFk; + + IF (SELECT count(*) FROM vn.ticketCollection WHERE collectionFk = vCollectionFk) THEN + + CALL vn.salesMerge_byCollection(vCollectionFk); + + UPDATE vn.collection c + JOIN (SELECT count(*) saleTotalCount , + sum(s.isPicked != 0) salePickedCount + FROM vn.ticketCollection tc + JOIN vn.sale s ON s.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND s.quantity > 0 + ) sub + SET c.saleTotalCount = sub.saleTotalCount, + c.salePickedCount = sub.salePickedCount + WHERE c.id = vCollectionFk; + + SELECT vCollectionFk; + + ELSE + + DELETE FROM vn.collection WHERE id = vCollectionFk; + -- SELECT NULL; + + END IF; + + DROP TEMPORARY TABLE tmp.ticketToSplit; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `collection_newSmartTag2` */; +/*!50003 SET @saved_cs_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 `collection_newSmartTag2`(vSectorFk INT) +proc:BEGIN + + DECLARE vIsPreviousPrepared BOOLEAN; + DECLARE vCollectionFk INT; + DECLARE vWarehouseFk INT; + DECLARE vMaxTickets INT; + DECLARE vStateFk INT; + DECLARE vFirstTicketFk INT; + DECLARE vHour INT; + DECLARE vMinute INT; + DECLARE vWorker INT; + DECLARE vWorkerCode VARCHAR(3); + DECLARE vWagon INT; + DECLARE vWagonCounter INT; + DECLARE vShelve INT; + DECLARE vTicket INT; + DECLARE vTicketToSplit INT; + DECLARE myUserIsSalesPersonRole BOOLEAN; + DECLARE vPrintedTickets INT; + DECLARE vMaxTicketPrinted INT; + DECLARE vItemPackingTypeFk VARCHAR(1); + DECLARE hasAssignedTickets BOOLEAN; + DECLARE vMaxNotReadyCollections INT DEFAULT 0; + DECLARE vNotReadyCollections INT; + DECLARE vSectorCode VARCHAR(20); + DECLARE vWagons INT; + + /* SELECT w.code, w.id INTO vWorkerCode, vWorker + FROM vn.worker w + WHERE w.id = vn.getUser(); + */ + + SELECT 'VLC', 19263 INTO vWorkerCode, vWorker; + +-- Si hay colecciones sin terminar, sale del proceso + SELECT count(*) INTO vNotReadyCollections + FROM vn.collection c + WHERE c.workerFk = 19263 + AND c.saleTotalCount > c.salePickedCount + 1 + AND c.created > TIMESTAMPADD(HOUR , -5,NOW()); + + IF vMaxNotReadyCollections < vNotReadyCollections THEN + + LEAVE proc; + + END IF; + + -- Establecemos el almacén y si es un sector de preparación previa, así como el estado para los tickets que se vayan preparando + SELECT isPreviousPrepared, warehouseFk, itemPackingTypeFk, code + INTO vIsPreviousPrepared, vWarehouseFk, vItemPackingTypeFk, vSectorCode + FROM vn.sector + WHERE id = vSectorFk; + + -- Cogemos el numero de wagons del trabajador + SELECT COUNT(ws.id) + FROM vn.workerShelving ws + WHERE ws.workerFk = vWorker + AND ws.collectionFk IS NULL + INTO vWagons; + + SET vMaxTicketPrinted = 6 * vWagons; + SET vMaxTickets = 3 * vWagons; + + + IF vIsPreviousPrepared THEN + + LEAVE proc; -- Hasta que tengamos el altillo, vamos a cancelar esta opcion + + SELECT id INTO vStateFk + FROM vn.state + WHERE `code` = 'PREVIOUS_PREPARATION'; + ELSE + + SELECT id INTO vStateFk + FROM vn.state + WHERE `code` = 'ON_PREPARATION'; + + END IF; + + -- Averiguamos si es comercial el usuario + SELECT FALSE -- (r.name = 'salesPerson') + INTO myUserIsSalesPersonRole + FROM account.user u + JOIN account.role r ON r.id = u.role + WHERE u.id = 19263; + + -- Se obtiene nº de colección y el buffer con los pedidos preparables + INSERT INTO vn.collection + SET workerFk = 19263, + itemPackingTypeFk = vItemPackingTypeFk; + + SELECT LAST_INSERT_ID() INTO vCollectionFk; + + + UPDATE workerShelving + SET collectionFk = vCollectionFk + WHERE workerFk = vWorker + AND collectionFk IS NULL; + + CALL vn.productionControl(vWarehouseFk, 0); + + -- Comprobamos si hay tickets asignados. En ese caso, nos centramos exclusivamente en esos tickets + -- y los sacamos independientemente de problemas o tamaños + SELECT COUNT(*) INTO hasAssignedTickets + FROM tmp.productionBuffer pb + JOIN vn.state s ON s.id = pb.state + WHERE s.code = 'PICKER_DESIGNED' + AND pb.workerCode = vWorkerCode + AND LENGTH(pb.problem) = 0; + + IF hasAssignedTickets THEN + + UPDATE vn.collection + SET itemPackingTypeFk = NULL + WHERE id = vCollectionFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketToSplit; + CREATE TEMPORARY TABLE tmp.ticketToSplit + SELECT pb.ticketFk + FROM tmp.productionBuffer pb + JOIN vn.state s ON s.id = pb.state + WHERE s.code = 'PICKER_DESIGNED' + AND pb.workerCode = vWorkerCode + AND LENGTH(pb.problem) = 0 + ORDER BY HH, + mm, + s.`order` DESC, + pb.m3 DESC; + + WHILE (SELECT COUNT(*) FROM tmp.ticketToSplit) DO + + SELECT MIN(ticketFk) INTO vTicketToSplit + FROM tmp.ticketToSplit; + + CALL vn.ticket_splitItemPackingType(vTicketToSplit); + + INSERT INTO vn.ticketCollection(ticketFk, collectionFk) + SELECT ticketFk, vCollectionFk + FROM tmp.ticketIPT; + + DELETE FROM tmp.ticketToSplit + WHERE ticketFk = vTicketToSplit; + + DROP TEMPORARY TABLE tmp.ticketIPT; + + END WHILE; + + CALL vn.productionControl(vWarehouseFk, 0); + + ELSE + + SELECT COUNT(*) INTO vPrintedTickets + FROM tmp.productionBuffer pb + JOIN vn.state s ON s.id = pb.state + JOIN vn.agencyMode am ON am.id = pb.agencyModeFk + JOIN vn.agency a ON a.id = am.agencyFk + WHERE pb.shipped = CURDATE() + AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) + AND s.isPreparable + AND (pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH) + OR pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV) + OR pb.F > 0 AND vItemPackingTypeFk = 'F' AND ISNULL(pb.collectionF) + OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)); + + SET vMaxTicketPrinted = vMaxTicketPrinted - vPrintedTickets; + -- AutoPRINT + + IF vMaxTicketPrinted > 0 THEN + + INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) + SELECT s2.id, pb.ticketFk, 19263 + FROM tmp.productionBuffer pb + JOIN vn.agencyMode am ON am.id = pb.agencyModeFk + JOIN vn.agency a ON a.id = am.agencyFk + JOIN vn.state s ON s.id = pb.state + JOIN vn.state s2 ON s2.code = 'PRINTED_AUTO' + JOIN vn.ticket t ON t.id = pb.ticketFk + WHERE pb.shipped = CURDATE() + AND LENGTH(pb.problem) = 0 + AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) + AND s.isPrintable + AND (pb.m3 > 0.05 OR s.isOK) + AND (pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH) + OR pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV) + OR pb.F > 0 AND vItemPackingTypeFk = 'F' AND ISNULL(pb.collectionF) + OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)) + AND t.created < TIMESTAMPADD(MINUTE, -10, NOW()) + ORDER BY HH, + mm, + s.`order` DESC, + pb.m3 DESC + LIMIT vMaxTicketPrinted; + + END IF; + + -- Se seleccionan los primeros tickets, asignando colección para dejarlos bloqueados a otros sacadores. + -- Se splitan los tickets preparables, para que solo tengan un tipo de empaquetado + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketToSplit; + CREATE TEMPORARY TABLE tmp.ticketToSplit + SELECT pb.ticketFk + FROM tmp.productionBuffer pb + JOIN vn.agencyMode am ON am.id = pb.agencyModeFk + JOIN vn.agency a ON a.id = am.agencyFk + JOIN vn.ticketStateToday tst ON tst.ticket = pb.ticketFk + JOIN vn.state s ON s.id = tst.state + WHERE ( pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH) + OR pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV) + OR pb.F > 0 AND vItemPackingTypeFk = 'F' AND ISNULL(pb.collectionF) + OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)) + AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) + AND LENGTH(pb.problem) = 0 + AND s.isPreparable + AND NOT myUserIsSalesPersonRole + ORDER BY pb.HH, pb.mm, s.`order` DESC + LIMIT vMaxTickets; + + WHILE (SELECT COUNT(*) FROM tmp.ticketToSplit) DO + + SELECT MIN(ticketFk) INTO vTicketToSplit + FROM tmp.ticketToSplit; + + CALL vn.ticket_splitItemPackingType(vTicketToSplit); + + INSERT INTO vn.ticketCollection(ticketFk, collectionFk) + SELECT ticketFk, vCollectionFk + FROM tmp.ticketIPT + WHERE itemPackingTypeFk = vItemPackingTypeFk; + + DELETE FROM tmp.ticketToSplit + WHERE ticketFk = vTicketToSplit; + + DROP TEMPORARY TABLE tmp.ticketIPT; + + END WHILE; + + END IF; + + -- Creamos una tabla temporal con los datos que necesitamos para depurar la colección + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + SELECT pb.ticketFk, + pb.`lines`, + pb.m3 * 1000 liters, + 0 as height, + 0 as shelve, + 0 as wagon, + pb.productionOrder, + pb.HH, + pb.mm + FROM tmp.productionBuffer pb + JOIN vn.ticketCollection tc ON tc.ticketFk = pb.ticketFk + WHERE tc.collectionFk = vCollectionFk + LIMIT vMaxTickets; + + -- Es importante que el primer ticket se coja en todos los casos + SET vFirstTicketFk = 0; + + SELECT ticketFk, HH, mm + INTO vFirstTicketFk, vHour, vMinute + FROM tmp.ticket + ORDER BY productionOrder DESC, HH, mm + LIMIT 1; + + -- Hay que excluir aquellos que no tengan la misma hora de preparación + DELETE + FROM tmp.ticket + WHERE HH != vHour + OR mm != vMinute; + + -- En el caso de pedidos de más volumen de un carro, la colección será monoticket. Pero si el primer pedido + -- no es monoticket, excluimos a los de más de un carro + IF (SELECT (t.liters > vc.trolleyM3 * 1000) + FROM tmp.ticket t + JOIN vn.volumeConfig vc + WHERE t.ticketFk = vFirstTicketFk) THEN + + DELETE + FROM tmp.ticket + WHERE ticketFk != vFirstTicketFk; + + ELSE + + DELETE t.* + FROM tmp.ticket t + JOIN vn.volumeConfig vc + WHERE t.liters > vc.trolleyM3 * 1000; + + END IF; + + -- Elimina los tickets bloqueados que no se van a preparar + DELETE tc.* + FROM vn.ticketCollection tc + LEFT JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND t.ticketFk IS NULL; + + /* + * + * Construccion del tren + * + */ + + -- Establece altura máxima por pedido, porque las plantas no se pueden recostar. + UPDATE tmp.ticket t + JOIN + ( SELECT MAX(i.size) maxHeigth, + tc.ticketFk + FROM vn.ticketCollection tc + JOIN vn.sale s ON s.ticketFk = tc.ticketFk + JOIN vn.item i ON i.id = s.itemFk + WHERE i.itemPackingTypeFk = 'V' + AND tc.collectionFk = vCollectionFk + GROUP BY tc.ticketFk) sub ON sub.ticketFk = t.ticketFk + SET t.height = IFNULL(sub.maxHeigth,0); + + -- Vamos a generar una tabla con todas las posibilidades de asignacion de pedido + DROP TEMPORARY TABLE IF EXISTS tmp.wagonsVolumetry; + CREATE TEMPORARY TABLE tmp.wagonsVolumetry + SELECT cv.`level` as shelve, + 1 as wagon, + cv.`lines`, + cv.liters, + cv.height + FROM vn.collectionVolumetry cv; + + SET vWagonCounter = 1; + + WHILE vWagonCounter < vWagons DO + + SET vWagonCounter = vWagonCounter + 1; + + INSERT INTO tmp.wagonsVolumetry(shelve, wagon, `lines`, liters, height) + SELECT cv.`level` as shelve, + vWagonCounter as wagon, + cv.`lines`, + cv.liters, + cv.height + FROM vn.collectionVolumetry cv + WHERE cv.itemPackingTypeFk = IFNULL(vItemPackingTypeFk, 'H'); + + END WHILE; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketShelve; + CREATE TEMPORARY TABLE tmp.ticketShelve + SELECT ticketFk, shelve, wagon, linesDif, LitersDif, heightDif + FROM ( + SELECT t.ticketFk, + wv.shelve, + wv.wagon, + t.productionOrder, + CAST(wv.`lines` AS SIGNED) - t.`lines` as linesDif, + CAST(wv.liters AS SIGNED) - t.liters as litersDif, + CAST(wv.height AS SIGNED) - t.height as heightDif + FROM tmp.wagonsVolumetry wv + JOIN tmp.ticket t + ) sub + WHERE linesDif >= 0 + AND litersDif >= 0 + AND heightDif >= 0 + ORDER BY productionOrder DESC, linesDif, LitersDif, heightDif ; + + -- Insertamos una opcion virtual para carro completo. Todo ticket tiene que poder entrar en un carro completo.... + INSERT INTO tmp.ticketShelve(ticketFk, shelve, wagon, linesDif, LitersDif, heightDif) + SELECT t.ticketFk, 0, wv.wagon, 999, 999,999 + FROM tmp.ticket t + JOIN tmp.wagonsVolumetry wv + GROUP BY t.ticketFk, wv.wagon; + + SET vWagonCounter = 0; + + WHILE vWagonCounter < vWagons DO + + SET vWagonCounter = vWagonCounter + 1; + + -- Asignamos la primera balda util al primer pedido + IF vWagonCounter = 1 THEN + + SELECT shelve INTO vShelve + FROM tmp.ticketShelve + WHERE ticketFk = vFirstTicketFk + AND wagon = vWagonCounter + ORDER BY heightDif, litersDif, linesDif + LIMIT 1; + + ELSE + + SELECT shelve, ticketFk INTO vShelve, vFirstTicketFk + FROM tmp.ticketShelve + WHERE wagon = vWagonCounter + ORDER BY heightDif, litersDif, linesDif + LIMIT 1; + + END IF; + + IF vShelve > 0 THEN + + UPDATE tmp.ticket + SET shelve = vShelve, + wagon = vWagonCounter + WHERE ticketFk = vFirstTicketFk; + + DELETE FROM tmp.ticketShelve + WHERE ticketFk = vFirstTicketFk + OR (shelve = vShelve AND wagon = vWagonCounter); + + WHILE (SELECT COUNT(*) FROM tmp.ticketShelve WHERE wagon = vWagonCounter) DO + + SELECT ticketFk, shelve + INTO vTicket, vShelve + FROM tmp.ticketShelve + WHERE wagon = vWagonCounter + LIMIT 1; + + UPDATE tmp.ticket + SET shelve = vShelve, + wagon = vWagonCounter + WHERE ticketFk = vTicket; + + DELETE FROM tmp.ticketShelve + WHERE ticketFk = vTicket + OR (shelve = vShelve AND wagon = vWagonCounter); + + END WHILE; + + ELSE + + UPDATE tmp.ticket + SET shelve = 1, wagon = vWagonCounter + WHERE ticketFk = vFirstTicketFk; + + DELETE FROM tmp.ticketShelve + WHERE ticketFk = vFirstTicketFk + AND wagon != vWagonCounter; + + END IF; + + END WHILE; + + -- Eliminamos los que se han quedado sin balda + DELETE FROM tmp.ticket WHERE shelve = 0; + + -- Elimina los tickets bloqueados que no se van a preparar + DELETE tc.* + FROM vn.ticketCollection tc + LEFT JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND t.ticketFk IS NULL; + + -- Elimina los tickets que ya estan en otra coleccion + DELETE tc.* + FROM vn.ticketCollection tc + JOIN vn.ticketCollection tc2 ON tc2.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND tc2.collectionFk != vCollectionFk; + + -- Actualiza el estado de la colección + UPDATE vn.collection c + JOIN vn.state st ON st.code = 'ON_PREPARATION' + SET c.stateFk = st.id + WHERE c.id = vCollectionFk; + + -- Asigna las bandejas y las smartTags + SET @wagon := 0; + UPDATE vn.ticketCollection tc + JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk + JOIN (SELECT @wagon:=@wagon+1 as wagon, ws.shelvingFk + FROM workerShelving ws + WHERE ws.collectionFk = vCollectionFk) sub ON sub.wagon = t.wagon + JOIN smartTag s ON s.shelvingFk = sub.shelvingFk AND s.`level` = t.shelve + SET tc.`level` = t.shelve, tc.wagon = t.wagon, tc.smartTagFk = s.code; + + -- Actualiza el estado de los tickets + INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) + SELECT vStateFk, ticketFk, 19263 + FROM vn.ticketCollection tc + WHERE tc.collectionFk = vCollectionFk; + + -- Aviso para la preparacion previa + INSERT INTO vn.ticketDown(ticketFk, collectionFk) + SELECT tc.ticketFk, tc.collectionFk + FROM vn.ticketCollection tc + WHERE tc.collectionFk = vCollectionFk; + + IF (SELECT count(*) FROM vn.ticketCollection WHERE collectionFk = vCollectionFk) THEN + + CALL vn.salesMerge_byCollection(vCollectionFk); + + UPDATE vn.collection c + JOIN (SELECT count(*) saleTotalCount , + sum(s.isPicked != 0) salePickedCount + FROM vn.ticketCollection tc + JOIN vn.sale s ON s.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND s.quantity > 0 + ) sub + SET c.saleTotalCount = sub.saleTotalCount, + c.salePickedCount = sub.salePickedCount + WHERE c.id = vCollectionFk; + + SELECT vCollectionFk; + + ELSE + + DELETE FROM vn.collection WHERE id = vCollectionFk; + -- SELECT NULL; + + END IF; + + DROP TEMPORARY TABLE tmp.ticketToSplit; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `collection_newWithWagon` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -52009,7 +52132,557 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `collection_new`(vSectorFk INT) +CREATE DEFINER=`root`@`%` PROCEDURE `collection_newWithWagon`(vSectorFk INT, vWagons INT) +proc:BEGIN + + DECLARE vIsPreviousPrepared BOOLEAN; + DECLARE vCollectionFk INT; + DECLARE vWarehouseFk INT; + DECLARE vMaxTickets INT; + DECLARE vStateFk INT; + DECLARE vFirstTicketFk INT; + DECLARE vHour INT; + DECLARE vMinute INT; + DECLARE vWorkerCode VARCHAR(3); + DECLARE vWagon INT; + DECLARE vWagonCounter INT; + DECLARE vShelve INT; + DECLARE vTicket INT; + DECLARE vTicketToSplit INT; + DECLARE myUserIsSalesPersonRole BOOLEAN; + DECLARE vPrintedTickets INT; + DECLARE vMaxTicketPrinted INT; + DECLARE vItemPackingTypeFk VARCHAR(1); + DECLARE hasAssignedTickets BOOLEAN; + DECLARE vMaxNotReadyCollections INT DEFAULT 0; + DECLARE vNotReadyCollections INT; + DECLARE vSectorCode VARCHAR(20); +/* + IF vn.getUser() = 18890 THEN + CALL collection_newSmartTag(vSectorFk); + LEAVE proc; + END IF;*/ + + SELECT w.code INTO vWorkerCode + FROM vn.worker w + WHERE w.id = vn.getUser(); + + -- Establecemos el almacén y si es un sector de preparación previa, así como el estado para los tickets que se vayan preparando + SELECT isPreviousPrepared, warehouseFk, itemPackingTypeFk, code + INTO vIsPreviousPrepared, vWarehouseFk, vItemPackingTypeFk, vSectorCode + FROM vn.sector + WHERE id = vSectorFk; + +-- Si está habilitado el modo cazador para las PDA, y el usuario no está registrado, se sale. + + IF (SELECT deviceHuntingMode FROM vn.config) AND vItemPackingTypeFk = 'H' THEN + + IF (SELECT COUNT(*) FROM vn.workerWithoutDevice wwd WHERE wwd.workerFk = account.userGetId()) THEN + + LEAVE proc; + + END IF; + + END IF; + +-- Si está habilitado el modo cazador para las motos, y el usuario no está registrado, se sale. + + IF (SELECT tractorHuntingMode FROM vn.config) AND vItemPackingTypeFk = 'H' THEN + + IF (SELECT COUNT(*) FROM vn.workerWithoutTractor wwt WHERE wwt.workerFk = account.userGetId()) THEN + + INSERT INTO tmp.kk(userFk) VALUES(vn.getUser()); + + LEAVE proc; + + END IF; + + END IF; + +-- Si hay colecciones sin terminar, sale del proceso + SELECT count(*) INTO vNotReadyCollections + FROM vn.collection c + WHERE c.workerFk = vn.getUser() + AND c.saleTotalCount > c.salePickedCount + 1 + AND c.created > TIMESTAMPADD(HOUR , -5,NOW()); + + IF vMaxNotReadyCollections < vNotReadyCollections THEN + + LEAVE proc; + + END IF; + +/* + IF LENGTH(vSectorCode) = 2 THEN + + SELECT CAST(SUBSTRING(vSectorCode,2,1) AS UNSIGNED) INTO vWagons; + + END IF; +*/ + SET vMaxTicketPrinted = 8 * vWagons; + SET vMaxTickets = 4 * vWagons; + + + IF vIsPreviousPrepared THEN + + LEAVE proc; -- Hasta que tengamos el altillo, vamos a cancelar esta opcion + + SELECT id INTO vStateFk + FROM vn.state + WHERE `code` = 'PREVIOUS_PREPARATION'; + ELSE + + SELECT id INTO vStateFk + FROM vn.state + WHERE `code` = 'ON_PREPARATION'; + + END IF; + + -- Averiguamos si es comercial el usuario + SELECT FALSE -- (r.name = 'salesPerson') + INTO myUserIsSalesPersonRole + FROM account.user u + JOIN account.role r ON r.id = u.role + WHERE u.id = vn.getUser(); + + -- Se obtiene nº de colección y el buffer con los pedidos preparables + INSERT INTO vn.collection + SET workerFk = account.myUser_getId(), + itemPackingTypeFk = vItemPackingTypeFk; + + SELECT LAST_INSERT_ID() INTO vCollectionFk; + + CALL vn.productionControl(vWarehouseFk, 0); + + -- 05/08/2021 PAK Jose Frau pide que los tickets de recogida en Algemesí sólo se saquen si están asignados. + DELETE pb.* + FROM tmp.productionBuffer pb + JOIN vn.state s ON s.id = pb.state + WHERE pb.agency = 'REC_ALGEMESI' + AND s.code != 'PICKER_DESIGNED'; + + -- Comprobamos si hay tickets asignados. En ese caso, nos centramos exclusivamente en esos tickets + -- y los sacamos independientemente de problemas o tamaños + SELECT COUNT(*) INTO hasAssignedTickets + FROM tmp.productionBuffer pb + JOIN vn.state s ON s.id = pb.state + WHERE s.code = 'PICKER_DESIGNED' + AND pb.workerCode = vWorkerCode + AND LENGTH(pb.problem) = 0; + + IF hasAssignedTickets THEN + + UPDATE vn.collection + SET itemPackingTypeFk = NULL + WHERE id = vCollectionFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketToSplit; + CREATE TEMPORARY TABLE tmp.ticketToSplit + SELECT pb.ticketFk + FROM tmp.productionBuffer pb + JOIN vn.state s ON s.id = pb.state + WHERE s.code = 'PICKER_DESIGNED' + AND pb.workerCode = vWorkerCode + AND LENGTH(pb.problem) = 0 + ORDER BY HH, + mm, + s.`order` DESC, + pb.m3 DESC; + + WHILE (SELECT COUNT(*) FROM tmp.ticketToSplit) DO + + SELECT MIN(ticketFk) INTO vTicketToSplit + FROM tmp.ticketToSplit; + + CALL vn.ticket_splitItemPackingType(vTicketToSplit); + + INSERT INTO vn.ticketCollection(ticketFk, collectionFk) + SELECT ticketFk, vCollectionFk + FROM tmp.ticketIPT; + + DELETE FROM tmp.ticketToSplit + WHERE ticketFk = vTicketToSplit; + + DROP TEMPORARY TABLE tmp.ticketIPT; + + END WHILE; + + CALL vn.productionControl(vWarehouseFk, 0); + + ELSE + + SELECT COUNT(*) INTO vPrintedTickets + FROM tmp.productionBuffer pb + JOIN vn.state s ON s.id = pb.state + JOIN vn.agencyMode am ON am.id = pb.agencyModeFk + JOIN vn.agency a ON a.id = am.agencyFk + WHERE pb.shipped = CURDATE() + AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) + AND s.isPreparable + AND (pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH) + OR pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV) + OR pb.F > 0 AND vItemPackingTypeFk = 'F' AND ISNULL(pb.collectionF) + OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)); + + SET vMaxTicketPrinted = vMaxTicketPrinted - vPrintedTickets; + -- AutoPRINT + + IF vMaxTicketPrinted > 0 THEN + + INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) + SELECT s2.id, pb.ticketFk, vn.getUser() + FROM tmp.productionBuffer pb + JOIN vn.agencyMode am ON am.id = pb.agencyModeFk + JOIN vn.agency a ON a.id = am.agencyFk + JOIN vn.state s ON s.id = pb.state + JOIN vn.state s2 ON s2.code = 'PRINTED_AUTO' + JOIN vn.ticket t ON t.id = pb.ticketFk + WHERE pb.shipped = CURDATE() + AND LENGTH(pb.problem) = 0 + AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) + AND s.isPrintable + AND (pb.m3 > 0.05 OR s.isOK) + AND (pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH) + OR pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV) + OR pb.F > 0 AND vItemPackingTypeFk = 'F' AND ISNULL(pb.collectionF) + OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)) + AND t.created < TIMESTAMPADD(MINUTE, -10, NOW()) + ORDER BY HH, + mm, + s.`order` DESC, + pb.m3 DESC + LIMIT vMaxTicketPrinted; + + END IF; + + -- Se seleccionan los primeros tickets, asignando colección para dejarlos bloqueados a otros sacadores. + -- Se splitan los tickets preparables, para que solo tengan un tipo de empaquetado + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketToSplit; + CREATE TEMPORARY TABLE tmp.ticketToSplit + SELECT pb.ticketFk + FROM tmp.productionBuffer pb + JOIN vn.agencyMode am ON am.id = pb.agencyModeFk + JOIN vn.agency a ON a.id = am.agencyFk + JOIN vn.ticketStateToday tst ON tst.ticket = pb.ticketFk + JOIN vn.state s ON s.id = tst.state + WHERE ( pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH) + OR pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV) + OR pb.F > 0 AND vItemPackingTypeFk = 'F' AND ISNULL(pb.collectionF) + OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)) + AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) + AND LENGTH(pb.problem) = 0 + AND s.isPreparable + AND NOT myUserIsSalesPersonRole + ORDER BY pb.HH, pb.mm, s.`order` DESC + LIMIT vMaxTickets; + + WHILE (SELECT COUNT(*) FROM tmp.ticketToSplit) DO + + SELECT MIN(ticketFk) INTO vTicketToSplit + FROM tmp.ticketToSplit; + + CALL vn.ticket_splitItemPackingType(vTicketToSplit); + + INSERT INTO vn.ticketCollection(ticketFk, collectionFk) + SELECT ticketFk, vCollectionFk + FROM tmp.ticketIPT + WHERE itemPackingTypeFk = vItemPackingTypeFk; + + DELETE FROM tmp.ticketToSplit + WHERE ticketFk = vTicketToSplit; + + DROP TEMPORARY TABLE tmp.ticketIPT; + + END WHILE; + + END IF; + + -- Creamos una tabla temporal con los datos que necesitamos para depurar la colección + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + SELECT pb.ticketFk, + pb.`lines`, + pb.m3 * 1000 liters, + 0 as height, + 0 as shelve, + 0 as wagon, + pb.productionOrder, + pb.HH, + pb.mm + FROM tmp.productionBuffer pb + JOIN vn.ticketCollection tc ON tc.ticketFk = pb.ticketFk + WHERE tc.collectionFk = vCollectionFk + LIMIT vMaxTickets; + + -- Es importante que el primer ticket se coja en todos los casos + SET vFirstTicketFk = 0; + + SELECT ticketFk, HH, mm + INTO vFirstTicketFk, vHour, vMinute + FROM tmp.ticket + ORDER BY productionOrder DESC, HH, mm + LIMIT 1; + + -- Hay que excluir aquellos que no tengan la misma hora de preparación + DELETE + FROM tmp.ticket + WHERE HH != vHour + OR mm != vMinute; + + -- En el caso de pedidos de más volumen de un carro, la colección será monoticket. Pero si el primer pedido + -- no es monoticket, excluimos a los de más de un carro + IF (SELECT (t.liters > vc.trolleyM3 * 1000) + FROM tmp.ticket t + JOIN vn.volumeConfig vc + WHERE t.ticketFk = vFirstTicketFk) THEN + + DELETE + FROM tmp.ticket + WHERE ticketFk != vFirstTicketFk; + + ELSE + + DELETE t.* + FROM tmp.ticket t + JOIN vn.volumeConfig vc + WHERE t.liters > vc.trolleyM3 * 1000; + + END IF; + + -- Elimina los tickets bloqueados que no se van a preparar + DELETE tc.* + FROM vn.ticketCollection tc + LEFT JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND t.ticketFk IS NULL; + + /* + * + * Construccion del tren + * + */ + + -- Establece altura máxima por pedido, porque las plantas no se pueden recostar. + UPDATE tmp.ticket t + JOIN + ( SELECT MAX(i.size) maxHeigth, + tc.ticketFk + FROM vn.ticketCollection tc + JOIN vn.sale s ON s.ticketFk = tc.ticketFk + JOIN vn.item i ON i.id = s.itemFk + WHERE i.itemPackingTypeFk = 'V' + AND tc.collectionFk = vCollectionFk + GROUP BY tc.ticketFk) sub ON sub.ticketFk = t.ticketFk + SET t.height = IFNULL(sub.maxHeigth,0); + + -- Vamos a generar una tabla con todas las posibilidades de asignacion de pedido + DROP TEMPORARY TABLE IF EXISTS tmp.wagonsVolumetry; + CREATE TEMPORARY TABLE tmp.wagonsVolumetry + SELECT cv.`level` as shelve, + 1 as wagon, + cv.`lines`, + cv.liters, + cv.height + FROM vn.collectionVolumetry cv; + + SET vWagonCounter = 1; + + WHILE vWagonCounter < vWagons DO + + SET vWagonCounter = vWagonCounter + 1; + + INSERT INTO tmp.wagonsVolumetry(shelve, wagon, `lines`, liters, height) + SELECT cv.`level` as shelve, + vWagonCounter as wagon, + cv.`lines`, + cv.liters, + cv.height + FROM vn.collectionVolumetry cv + WHERE cv.itemPackingTypeFk = IFNULL(vItemPackingTypeFk, 'H'); + + END WHILE; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketShelve; + CREATE TEMPORARY TABLE tmp.ticketShelve + SELECT ticketFk, shelve, wagon, linesDif, LitersDif, heightDif + FROM ( + SELECT t.ticketFk, + wv.shelve, + wv.wagon, + t.productionOrder, + CAST(wv.`lines` AS SIGNED) - t.`lines` as linesDif, + CAST(wv.liters AS SIGNED) - t.liters as litersDif, + CAST(wv.height AS SIGNED) - t.height as heightDif + FROM tmp.wagonsVolumetry wv + JOIN tmp.ticket t + ) sub + WHERE linesDif >= 0 + AND litersDif >= 0 + AND heightDif >= 0 + ORDER BY productionOrder DESC, linesDif, LitersDif, heightDif ; + + -- Insertamos una opcion virtual para carro completo. Todo ticket tiene que poder entrar en un carro completo.... + INSERT INTO tmp.ticketShelve(ticketFk, shelve, wagon, linesDif, LitersDif, heightDif) + SELECT t.ticketFk, 0, wv.wagon, 999, 999,999 + FROM tmp.ticket t + JOIN tmp.wagonsVolumetry wv + GROUP BY t.ticketFk, wv.wagon; + + SET vWagonCounter = 0; + + WHILE vWagonCounter < vWagons DO + + SET vWagonCounter = vWagonCounter + 1; + + -- Asignamos la primera balda util al primer pedido + IF vWagonCounter = 1 THEN + + SELECT shelve INTO vShelve + FROM tmp.ticketShelve + WHERE ticketFk = vFirstTicketFk + AND wagon = vWagonCounter + ORDER BY heightDif, litersDif, linesDif + LIMIT 1; + + ELSE + + SELECT shelve, ticketFk INTO vShelve, vFirstTicketFk + FROM tmp.ticketShelve + WHERE wagon = vWagonCounter + ORDER BY heightDif, litersDif, linesDif + LIMIT 1; + + END IF; + + IF vShelve > 0 THEN + + UPDATE tmp.ticket + SET shelve = vShelve, + wagon = vWagonCounter + WHERE ticketFk = vFirstTicketFk; + + DELETE FROM tmp.ticketShelve + WHERE ticketFk = vFirstTicketFk + OR (shelve = vShelve AND wagon = vWagonCounter); + + WHILE (SELECT COUNT(*) FROM tmp.ticketShelve WHERE wagon = vWagonCounter) DO + + SELECT ticketFk, shelve + INTO vTicket, vShelve + FROM tmp.ticketShelve + WHERE wagon = vWagonCounter + LIMIT 1; + + UPDATE tmp.ticket + SET shelve = vShelve, + wagon = vWagonCounter + WHERE ticketFk = vTicket; + + DELETE FROM tmp.ticketShelve + WHERE ticketFk = vTicket + OR (shelve = vShelve AND wagon = vWagonCounter); + + END WHILE; + + ELSE + + UPDATE tmp.ticket + SET shelve = 1, wagon = vWagonCounter + WHERE ticketFk = vFirstTicketFk; + + DELETE FROM tmp.ticketShelve + WHERE ticketFk = vFirstTicketFk + AND wagon != vWagonCounter; + + END IF; + + END WHILE; + + -- Eliminamos los que se han quedado sin balda + DELETE FROM tmp.ticket WHERE shelve = 0; + + -- Elimina los tickets bloqueados que no se van a preparar + DELETE tc.* + FROM vn.ticketCollection tc + LEFT JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND t.ticketFk IS NULL; + + -- Elimina los tickets que ya estan en otra coleccion + DELETE tc.* + FROM vn.ticketCollection tc + JOIN vn.ticketCollection tc2 ON tc2.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND tc2.collectionFk != vCollectionFk; + + -- Actualiza el estado de la colección + UPDATE vn.collection c + JOIN vn.state st ON st.code = 'ON_PREPARATION' + SET c.stateFk = st.id + WHERE c.id = vCollectionFk; + + -- Asigna las bandejas + UPDATE vn.ticketCollection tc + JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk + SET tc.level = t.shelve, tc.wagon = t.wagon; + + -- Actualiza el estado de los tickets + INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) + SELECT vStateFk, ticketFk, account.myUser_getId() + FROM vn.ticketCollection tc + WHERE tc.collectionFk = vCollectionFk; + + -- Aviso para la preparacion previa + INSERT INTO vn.ticketDown(ticketFk, collectionFk) + SELECT tc.ticketFk, tc.collectionFk + FROM vn.ticketCollection tc + WHERE tc.collectionFk = vCollectionFk; + + IF (SELECT count(*) FROM vn.ticketCollection WHERE collectionFk = vCollectionFk) THEN + + CALL vn.salesMerge_byCollection(vCollectionFk); + + UPDATE vn.collection c + JOIN (SELECT count(*) saleTotalCount , + sum(s.isPicked != 0) salePickedCount + FROM vn.ticketCollection tc + JOIN vn.sale s ON s.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND s.quantity > 0 + ) sub + SET c.saleTotalCount = sub.saleTotalCount, + c.salePickedCount = sub.salePickedCount + WHERE c.id = vCollectionFk; + + SELECT vCollectionFk; + + ELSE + + DELETE FROM vn.collection WHERE id = vCollectionFk; + -- SELECT NULL; + + END IF; + + DROP TEMPORARY TABLE tmp.ticketToSplit; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `collection_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 = 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 `collection_new__`(vSectorFk INT) proc:BEGIN DECLARE vIsPreviousPrepared BOOLEAN; @@ -52502,517 +53175,6 @@ proc:BEGIN DROP TEMPORARY TABLE tmp.ticketIPT; DROP TEMPORARY TABLE IF EXISTS tmp.ticketToSplit; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `collection_newWithWagon` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `collection_newWithWagon`(vSectorFk INT, vWagons INT) -proc:BEGIN - - DECLARE vIsPreviousPrepared BOOLEAN; - DECLARE vCollectionFk INT; - DECLARE vWarehouseFk INT; - DECLARE vMaxTickets INT; - DECLARE vStateFk INT; - DECLARE vFirstTicketFk INT; - DECLARE vHour INT; - DECLARE vMinute INT; - DECLARE vWorkerCode VARCHAR(3); - DECLARE vWagon INT; - DECLARE vWagonCounter INT; - DECLARE vShelve INT; - DECLARE vTicket INT; - DECLARE vTicketToSplit INT; - DECLARE myUserIsSalesPersonRole BOOLEAN; - DECLARE vPrintedTickets INT; - DECLARE vMaxTicketPrinted INT; - DECLARE vItemPackingTypeFk VARCHAR(1); - DECLARE hasAssignedTickets BOOLEAN; - DECLARE vMaxNotReadyCollections INT DEFAULT 0; - DECLARE vNotReadyCollections INT; - DECLARE vSectorCode VARCHAR(20); - - SELECT w.code INTO vWorkerCode - FROM vn.worker w - WHERE w.id = vn.getUser(); - --- Si hay colecciones sin terminar, sale del proceso - SELECT count(*) INTO vNotReadyCollections - FROM vn.collection c - WHERE c.workerFk = vn.getUser() - AND c.saleTotalCount > c.salePickedCount + 1 - AND c.created > TIMESTAMPADD(HOUR , -5,NOW()); - - IF vMaxNotReadyCollections < vNotReadyCollections THEN - - LEAVE proc; - - END IF; - - -- Establecemos el almacén y si es un sector de preparación previa, así como el estado para los tickets que se vayan preparando - SELECT isPreviousPrepared, warehouseFk, itemPackingTypeFk, code - INTO vIsPreviousPrepared, vWarehouseFk, vItemPackingTypeFk, vSectorCode - FROM vn.sector - WHERE id = vSectorFk; - - IF LENGTH(vSectorCode) = 2 THEN - - SELECT CAST(SUBSTRING(vSectorCode,2,1) AS UNSIGNED) INTO vWagons; - - END IF; - - SET vMaxTicketPrinted = 8 * vWagons; - SET vMaxTickets = 4 * vWagons; - - - IF vIsPreviousPrepared THEN - - LEAVE proc; -- Hasta que tengamos el altillo, vamos a cancelar esta opcion - - SELECT id INTO vStateFk - FROM vn.state - WHERE `code` = 'PREVIOUS_PREPARATION'; - ELSE - - SELECT id INTO vStateFk - FROM vn.state - WHERE `code` = 'ON_PREPARATION'; - - END IF; - - -- Averiguamos si es comercial el usuario - SELECT FALSE -- (r.name = 'salesPerson') - INTO myUserIsSalesPersonRole - FROM account.user u - JOIN account.role r ON r.id = u.role - WHERE u.id = vn.getUser(); - - -- Se obtiene nº de colección y el buffer con los pedidos preparables - INSERT INTO vn.collection - SET workerFk = account.myUser_getId(), - itemPackingTypeFk = vItemPackingTypeFk; - - SELECT LAST_INSERT_ID() INTO vCollectionFk; - - CALL vn.productionControl(vWarehouseFk, 0); - - -- Comprobamos si hay tickets asignados. En ese caso, nos centramos exclusivamente en esos tickets - -- y los sacamos independientemente de problemas o tamaños - SELECT COUNT(*) INTO hasAssignedTickets - FROM tmp.productionBuffer pb - JOIN vn.state s ON s.id = pb.state - WHERE s.code = 'PICKER_DESIGNED' - AND pb.workerCode = vWorkerCode - AND LENGTH(pb.problem) = 0; - - IF hasAssignedTickets THEN - - UPDATE vn.collection - SET itemPackingTypeFk = NULL - WHERE id = vCollectionFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketToSplit; - CREATE TEMPORARY TABLE tmp.ticketToSplit - SELECT pb.ticketFk - FROM tmp.productionBuffer pb - JOIN vn.state s ON s.id = pb.state - WHERE s.code = 'PICKER_DESIGNED' - AND pb.workerCode = vWorkerCode - AND LENGTH(pb.problem) = 0 - ORDER BY HH, - mm, - s.`order` DESC, - pb.m3 DESC; - - WHILE (SELECT COUNT(*) FROM tmp.ticketToSplit) DO - - SELECT MIN(ticketFk) INTO vTicketToSplit - FROM tmp.ticketToSplit; - - CALL vn.ticket_splitItemPackingType(vTicketToSplit); - - INSERT INTO vn.ticketCollection(ticketFk, collectionFk) - SELECT ticketFk, vCollectionFk - FROM tmp.ticketIPT; - - DELETE FROM tmp.ticketToSplit - WHERE ticketFk = vTicketToSplit; - - DROP TEMPORARY TABLE tmp.ticketIPT; - - END WHILE; - - CALL vn.productionControl(vWarehouseFk, 0); - - ELSE - - SELECT COUNT(*) INTO vPrintedTickets - FROM tmp.productionBuffer pb - JOIN vn.state s ON s.id = pb.state - JOIN vn.agencyMode am ON am.id = pb.agencyModeFk - JOIN vn.agency a ON a.id = am.agencyFk - WHERE pb.shipped = CURDATE() - AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) - AND s.isPreparable - AND (pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH) - OR pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV) - OR pb.F > 0 AND vItemPackingTypeFk = 'F' AND ISNULL(pb.collectionF) - OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)); - - SET vMaxTicketPrinted = vMaxTicketPrinted - vPrintedTickets; - -- AutoPRINT - - IF vMaxTicketPrinted > 0 THEN - - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) - SELECT s2.id, pb.ticketFk, vn.getUser() - FROM tmp.productionBuffer pb - JOIN vn.agencyMode am ON am.id = pb.agencyModeFk - JOIN vn.agency a ON a.id = am.agencyFk - JOIN vn.state s ON s.id = pb.state - JOIN vn.state s2 ON s2.code = 'PRINTED_AUTO' - JOIN vn.ticket t ON t.id = pb.ticketFk - WHERE pb.shipped = CURDATE() - AND LENGTH(pb.problem) = 0 - AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) - AND s.isPrintable - AND (pb.m3 > 0.05 OR s.isOK) - AND (pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH) - OR pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV) - OR pb.F > 0 AND vItemPackingTypeFk = 'F' AND ISNULL(pb.collectionF) - OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)) - AND t.created < TIMESTAMPADD(MINUTE, -10, NOW()) - ORDER BY HH, - mm, - s.`order` DESC, - pb.m3 DESC - LIMIT vMaxTicketPrinted; - - END IF; - - -- Se seleccionan los primeros tickets, asignando colección para dejarlos bloqueados a otros sacadores. - -- Se splitan los tickets preparables, para que solo tengan un tipo de empaquetado - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketToSplit; - CREATE TEMPORARY TABLE tmp.ticketToSplit - SELECT pb.ticketFk - FROM tmp.productionBuffer pb - JOIN vn.agencyMode am ON am.id = pb.agencyModeFk - JOIN vn.agency a ON a.id = am.agencyFk - JOIN vn.ticketStateToday tst ON tst.ticket = pb.ticketFk - JOIN vn.state s ON s.id = tst.state - WHERE ( pb.H > 0 AND vItemPackingTypeFk = 'H' AND ISNULL(pb.collectionH) - OR pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV) - OR pb.F > 0 AND vItemPackingTypeFk = 'F' AND ISNULL(pb.collectionF) - OR pb.P > 0 AND vItemPackingTypeFk = 'P' AND ISNULL(pb.collectionP)) - AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) - AND LENGTH(pb.problem) = 0 - AND s.isPreparable - AND NOT myUserIsSalesPersonRole - ORDER BY pb.HH, pb.mm, s.`order` DESC - LIMIT vMaxTickets; - - WHILE (SELECT COUNT(*) FROM tmp.ticketToSplit) DO - - SELECT MIN(ticketFk) INTO vTicketToSplit - FROM tmp.ticketToSplit; - - CALL vn.ticket_splitItemPackingType(vTicketToSplit); - - INSERT INTO vn.ticketCollection(ticketFk, collectionFk) - SELECT ticketFk, vCollectionFk - FROM tmp.ticketIPT - WHERE itemPackingTypeFk = vItemPackingTypeFk; - - DELETE FROM tmp.ticketToSplit - WHERE ticketFk = vTicketToSplit; - - DROP TEMPORARY TABLE tmp.ticketIPT; - - END WHILE; - - END IF; - - -- Creamos una tabla temporal con los datos que necesitamos para depurar la colección - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - SELECT pb.ticketFk, - pb.`lines`, - pb.m3 * 1000 liters, - 0 as height, - 0 as shelve, - 0 as wagon, - pb.productionOrder, - pb.HH, - pb.mm - FROM tmp.productionBuffer pb - JOIN vn.ticketCollection tc ON tc.ticketFk = pb.ticketFk - WHERE tc.collectionFk = vCollectionFk - LIMIT vMaxTickets; - - -- Es importante que el primer ticket se coja en todos los casos - SET vFirstTicketFk = 0; - - SELECT ticketFk, HH, mm - INTO vFirstTicketFk, vHour, vMinute - FROM tmp.ticket - ORDER BY productionOrder DESC, HH, mm - LIMIT 1; - - -- Hay que excluir aquellos que no tengan la misma hora de preparación - DELETE - FROM tmp.ticket - WHERE HH != vHour - OR mm != vMinute; - - -- En el caso de pedidos de más volumen de un carro, la colección será monoticket. Pero si el primer pedido - -- no es monoticket, excluimos a los de más de un carro - IF (SELECT (t.liters > vc.carro * 1000) - FROM tmp.ticket t - JOIN vn.volumeConfig vc - WHERE t.ticketFk = vFirstTicketFk) THEN - - DELETE - FROM tmp.ticket - WHERE ticketFk != vFirstTicketFk; - - ELSE - - DELETE t.* - FROM tmp.ticket t - JOIN vn.volumeConfig vc - WHERE t.liters > vc.carro * 1000; - - END IF; - - -- Elimina los tickets bloqueados que no se van a preparar - DELETE tc.* - FROM vn.ticketCollection tc - LEFT JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk - WHERE tc.collectionFk = vCollectionFk - AND t.ticketFk IS NULL; - - /* - * - * Construccion del tren - * - */ - - -- Establece altura máxima por pedido, porque las plantas no se pueden recostar. - UPDATE tmp.ticket t - JOIN - ( SELECT MAX(i.size) maxHeigth, - tc.ticketFk - FROM vn.ticketCollection tc - JOIN vn.sale s ON s.ticketFk = tc.ticketFk - JOIN vn.item i ON i.id = s.itemFk - WHERE i.itemPackingTypeFk = 'V' - AND tc.collectionFk = vCollectionFk - GROUP BY tc.ticketFk) sub ON sub.ticketFk = t.ticketFk - SET t.height = IFNULL(sub.maxHeigth,0); - - -- Vamos a generar una tabla con todas las posibilidades de asignacion de pedido - DROP TEMPORARY TABLE IF EXISTS tmp.wagonsVolumetry; - CREATE TEMPORARY TABLE tmp.wagonsVolumetry - SELECT cv.`level` as shelve, - 1 as wagon, - cv.`lines`, - cv.liters, - cv.height - FROM vn.collectionVolumetry cv; - - SET vWagonCounter = 1; - - WHILE vWagonCounter < vWagons DO - - SET vWagonCounter = vWagonCounter + 1; - - INSERT INTO tmp.wagonsVolumetry(shelve, wagon, `lines`, liters, height) - SELECT cv.`level` as shelve, - vWagonCounter as wagon, - cv.`lines`, - cv.liters, - cv.height - FROM vn.collectionVolumetry cv - WHERE cv.itemPackingTypeFk = IFNULL(vItemPackingTypeFk, 'H'); - - END WHILE; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketShelve; - CREATE TEMPORARY TABLE tmp.ticketShelve - SELECT ticketFk, shelve, wagon, linesDif, LitersDif, heightDif - FROM ( - SELECT t.ticketFk, - wv.shelve, - wv.wagon, - t.productionOrder, - CAST(wv.`lines` AS SIGNED) - t.`lines` as linesDif, - CAST(wv.liters AS SIGNED) - t.liters as litersDif, - CAST(wv.height AS SIGNED) - t.height as heightDif - FROM tmp.wagonsVolumetry wv - JOIN tmp.ticket t - ) sub - WHERE linesDif >= 0 - AND litersDif >= 0 - AND heightDif >= 0 - ORDER BY productionOrder DESC, linesDif, LitersDif, heightDif ; - - -- Insertamos una opcion virtual para carro completo. Todo ticket tiene que poder entrar en un carro completo.... - INSERT INTO tmp.ticketShelve(ticketFk, shelve, wagon, linesDif, LitersDif, heightDif) - SELECT t.ticketFk, 0, wv.wagon, 999, 999,999 - FROM tmp.ticket t - JOIN tmp.wagonsVolumetry wv - GROUP BY t.ticketFk, wv.wagon; - - SET vWagonCounter = 0; - - WHILE vWagonCounter < vWagons DO - - SET vWagonCounter = vWagonCounter + 1; - - -- Asignamos la primera balda util al primer pedido - IF vWagonCounter = 1 THEN - - SELECT shelve INTO vShelve - FROM tmp.ticketShelve - WHERE ticketFk = vFirstTicketFk - AND wagon = vWagonCounter - ORDER BY heightDif, litersDif, linesDif - LIMIT 1; - - ELSE - - SELECT shelve, ticketFk INTO vShelve, vFirstTicketFk - FROM tmp.ticketShelve - WHERE wagon = vWagonCounter - ORDER BY heightDif, litersDif, linesDif - LIMIT 1; - - END IF; - - IF vShelve > 0 THEN - - UPDATE tmp.ticket - SET shelve = vShelve, - wagon = vWagonCounter - WHERE ticketFk = vFirstTicketFk; - - DELETE FROM tmp.ticketShelve - WHERE ticketFk = vFirstTicketFk - OR (shelve = vShelve AND wagon = vWagonCounter); - - WHILE (SELECT COUNT(*) FROM tmp.ticketShelve WHERE wagon = vWagonCounter) DO - - SELECT ticketFk, shelve - INTO vTicket, vShelve - FROM tmp.ticketShelve - WHERE wagon = vWagonCounter - LIMIT 1; - - UPDATE tmp.ticket - SET shelve = vShelve, - wagon = vWagonCounter - WHERE ticketFk = vTicket; - - DELETE FROM tmp.ticketShelve - WHERE ticketFk = vTicket - OR (shelve = vShelve AND wagon = vWagonCounter); - - END WHILE; - - ELSE - - UPDATE tmp.ticket - SET shelve = 1, wagon = vWagonCounter - WHERE ticketFk = vFirstTicketFk; - - DELETE FROM tmp.ticketShelve - WHERE ticketFk = vFirstTicketFk - AND wagon != vWagonCounter; - - END IF; - - END WHILE; - - -- Eliminamos los que se han quedado sin balda - DELETE FROM tmp.ticket WHERE shelve = 0; - - -- Elimina los tickets bloqueados que no se van a preparar - DELETE tc.* - FROM vn.ticketCollection tc - LEFT JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk - WHERE tc.collectionFk = vCollectionFk - AND t.ticketFk IS NULL; - - -- Elimina los tickets que ya estan en otra coleccion - DELETE tc.* - FROM vn.ticketCollection tc - JOIN vn.ticketCollection tc2 ON tc2.ticketFk = tc.ticketFk - WHERE tc.collectionFk = vCollectionFk - AND tc2.collectionFk != vCollectionFk; - - -- Actualiza el estado de la colección - UPDATE vn.collection c - JOIN vn.state st ON st.code = 'ON_PREPARATION' - SET c.stateFk = st.id - WHERE c.id = vCollectionFk; - - -- Asigna las bandejas - UPDATE vn.ticketCollection tc - JOIN tmp.ticket t ON t.ticketFk = tc.ticketFk - SET tc.level = t.shelve, tc.wagon = t.wagon; - - -- Actualiza el estado de los tickets - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) - SELECT vStateFk, ticketFk, account.myUser_getId() - FROM vn.ticketCollection tc - WHERE tc.collectionFk = vCollectionFk; - - -- Aviso para la preparacion previa - INSERT INTO vn.ticketDown(ticketFk, collectionFk) - SELECT tc.ticketFk, tc.collectionFk - FROM vn.ticketCollection tc - WHERE tc.collectionFk = vCollectionFk; - - IF (SELECT count(*) FROM vn.ticketCollection WHERE collectionFk = vCollectionFk) THEN - - CALL vn.salesMerge_byCollection(vCollectionFk); - - UPDATE vn.collection c - JOIN (SELECT count(*) saleTotalCount , - sum(s.isPicked != 0) salePickedCount - FROM vn.ticketCollection tc - JOIN vn.sale s ON s.ticketFk = tc.ticketFk - WHERE tc.collectionFk = vCollectionFk - AND s.quantity > 0 - ) sub - SET c.saleTotalCount = sub.saleTotalCount, - c.salePickedCount = sub.salePickedCount - WHERE c.id = vCollectionFk; - - SELECT vCollectionFk; - - ELSE - - DELETE FROM vn.collection WHERE id = vCollectionFk; - -- SELECT NULL; - - END IF; - - DROP TEMPORARY TABLE tmp.ticketToSplit; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -53241,7 +53403,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `conveyorExpedition_Add`(vDate DATE) +CREATE DEFINER=`root`@`%` PROCEDURE `conveyorExpedition_Add`(vStarted DATETIME, vEnded DATETIME) BEGIN @@ -53255,77 +53417,35 @@ BEGIN width, height, routeFk, - productionMinute) + productionMinute, + truck, + criterion, + conveyorBuildingClassFk) SELECT e.id, e.created, 10 * p.depth as depth, 10 * p.width as width, 10 * p.height as height, IFNULL(t.routeFk,am.agencyFk) routeFk, - hour(e.created) * 60 + minute(e.created) + hour(e.created) * 60 + minute(e.created), + IFNULL(et.description , a.name), + IFNULL(t.routeFk,am.agencyFk) criterion, + IFNULL(p.conveyorBuildingClassFk , pc.defaultConveyorBuildingClass) FROM vn.expedition e JOIN vn.ticket t ON t.id = e.ticketFk JOIN vn.packaging p ON p.id = e.packagingFk LEFT JOIN vn.zone z ON z.id = t.zoneFk LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN vn.agency a ON a.id = am.agencyFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + JOIN vn.packagingConfig pc WHERE t.warehouseFk IN (60,1,44) - AND e.created BETWEEN vDate AND util.dayend(vDate) + AND e.created BETWEEN vStarted AND vEnded AND p.height < 140 AND p.width < 60 AND p.depth < 125; -/* - INSERT INTO vn.conveyorExpedition( expeditionFk, - created, - conveyorBuildingClassFk, - length, - width, - height, - routeFk, - productionMinute) - SELECT e.id, - e.created, - IF(e.itemFk = 94,1,4), - 10 * p.depth as depth, - 10 * p.width as width, - 10 * p.height as height, - IFNULL(t.routeFk,am.agencyFk) routeFk, - hour(e.created) * 60 + minute(e.created) - FROM vn.expedition e - JOIN vn.ticket t ON t.id = e.ticketFk - JOIN vn.packaging p ON p.id = e.packagingFk - LEFT JOIN vn.zone z ON z.id = t.zoneFk - LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk - WHERE t.warehouseFk IN (60,1) - AND t.shipped BETWEEN vDate AND util.dayend(vDate) - AND p.height < 160 - AND p.width < 60 - AND p.depth < 125; - - INSERT INTO vn.conveyorExpedition( expeditionFk, - created, - conveyorBuildingClassFk, - length, - width, - height, - routeFk) - SELECT e.id, - e.created, - 5, - 10 * p.depth as depth, - 10 * p.width as width, - 10 * p.height as height, - IFNULL(t.routeFk,am.agencyFk) routeFk - FROM vn.expedition e - JOIN vn.ticket t ON t.id = e.ticketFk - JOIN vn.packaging p ON p.id = e.packagingFk - LEFT JOIN vn.zone z ON z.id = t.zoneFk - LEFT JOIN vn.agencyMode am ON am.id = z.agencyModeFk - WHERE t.warehouseFk = 44 - AND t.shipped BETWEEN vDate AND util.dayend(vDate) - AND p.height < 160 - AND p.width < 60 - AND p.depth < 125; - */ + SELECT MIN(productionMinute) INTO startingMinute FROM vn.conveyorExpedition ce ; @@ -53657,9 +53777,9 @@ 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 ;; @@ -54004,6 +54124,65 @@ 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 `deviceProductionUser_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`@`%` PROCEDURE `deviceProductionUser_getWorker`(vAndroid_id VARCHAR(50)) +BEGIN +/** + * Selecciona si hay registrado un device con un android_id + * + * @param vAndroid_id el número android_id del dispositivo + * + */ + + SELECT account.user_getNameFromId(dpu.userFk) + FROM deviceProductionUser dpu + JOIN deviceProduction dp ON dpu.deviceProductionFk = dp.id + WHERE dp.android_id = vAndroid_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 `deviceProduction_getnameDevice` */; +/*!50003 SET @saved_cs_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 `deviceProduction_getnameDevice`(vAndroid_id VARCHAR(50)) +BEGIN +/** + * Selecciona el id del dispositivo que corresponde al vAndroid_id + * + * @param vAndroid_id el número android_id del dispositivo + * + */ + + SELECT dp.id + FROM deviceProduction dp + WHERE dp.android_id = vAndroid_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 `duaEntryValueUpdate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -54947,10 +55126,10 @@ BEGIN `input` = vInput, `period` = DATE_FORMAT(NOW(), '%Y-%m-%d %H:00:00'), `activeTime` = vActiveTime, - `consumption` = IFNULL((vConsumption / 3600) * vActiveTime, 0) + `consumption` = CAST(IFNULL((vConsumption / 3600) * vActiveTime, 0) AS DECIMAL(10,2)) ON DUPLICATE KEY UPDATE `activeTime` = `activeTime` + vActiveTime, - `consumption` = `consumption` + VALUES(`consumption`); + `consumption` = `consumption` + CAST(VALUES(`consumption`) AS DECIMAL(10,2)); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -55374,17 +55553,17 @@ 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 `entryVolume` */; +/*!50003 DROP PROCEDURE IF EXISTS `entryVolume__` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_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 `entryVolume`(vEntryFk INT) +CREATE DEFINER=`root`@`%` PROCEDURE `entryVolume__`(vEntryFk INT) BEGIN SELECT ELT(it.temperature + 1,'Calientes','Frios','Secos') AS Temp, @@ -55950,6 +56129,76 @@ BEGIN SET exp.checked = vChecked WHERE exp.id = vExpeditionFk; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `expedition_getState` */; +/*!50003 SET @saved_cs_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 `expedition_getState`(vExpeditionFk INT) +BEGIN + + DECLARE vTicketsPendientes INT; + DECLARE vEtiquetasTotales INT; + DECLARE vEtiquetasEscaneadas INT; + DECLARE vRouteFk INT; + + SELECT t.routeFk INTO vRouteFk + FROM vn.ticket t + JOIN vn.expedition e ON e.ticketFk = t.id + WHERE e.id = vExpeditionFk; + + SELECT COUNT(*) INTO vTicketsPendientes + FROM vn.ticket t + LEFT JOIN vn.expedition e ON e.ticketFk = t.id + WHERE t.routeFk = vRouteFk + AND ISNULL(e.id); + + SELECT COUNT(*) INTO vEtiquetasTotales + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + WHERE t.routeFk = vRouteFk; + + SELECT COUNT(*) INTO vEtiquetasEscaneadas + FROM vn.expeditionScan es + JOIN vn.expedition e ON e.id = es.expeditionFk + JOIN vn.ticket t ON t.id = e.ticketFk + WHERE t.routeFk = vRouteFk; + + SELECT e.ticketFk ticket, + t.nickname cliente, + a.city ciudad, + p.name provincia, + z.name zonaTicket, + am.name zonaRuta, + t.routeFk ruta, + rm.beachFk ubicacion, + et.ETD , + et.description camion, + vTicketsPendientes AS ticketsPendientes, + vEtiquetasTotales AS etiquetasTotales, + vEtiquetasEscaneadas AS etiquetasEscaneadas + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.`zone`z ON z.id = t.zoneFk + LEFT JOIN vn.route r ON r.id = t.routeFk + LEFT JOIN vn.agencyMode am ON am.id = r.agencyModeFk + LEFT JOIN vn.routesMonitor rm ON rm.routeFk = r.id + LEFT JOIN vn.expeditionTruck et ON et.id = rm.expeditionTruckFk + WHERE e.id = vExpeditionFk; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -56071,9 +56320,9 @@ 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 ;; @@ -56105,7 +56354,7 @@ BEGIN JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = t.warehouseFk JOIN vn.buy b ON b.id = lb.buy_id JOIN vn.packaging p ON p.id = b.packageFk - LEFT JOIN vn.packageEquivalent pe ON pe.packageFk = p.id + LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id JOIN vn.address a ON a.id = t.addressFk JOIN vn.province p2 ON p2.id = a.provinceFk JOIN vn.country c ON c.id = p2.countryFk @@ -56123,7 +56372,7 @@ BEGIN JOIN vn.warehouse w ON w.id = t.warehouseFk JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk JOIN vn.packaging p ON p.id = tp.packagingFk - LEFT JOIN vn.packageEquivalent pe ON pe.packageFk = p.id + LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id JOIN vn.address a ON a.id = t.addressFk JOIN vn.province p2 ON p2.id = a.provinceFk JOIN vn.country c ON c.id = p2.countryFk @@ -56143,7 +56392,7 @@ BEGIN JOIN vn.warehouse w ON w.id = t.warehouseFk JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk JOIN vn.packaging p ON p.id = tp.packagingFk - LEFT JOIN vn.packageEquivalent pe ON pe.packageFk = p.id + LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, 1, vDateStart ) AND TIMESTAMPADD(DAY, 1, vDateEnd ) AND wa.name = 'VNH' AND p.isPackageReturnable @@ -56163,9 +56412,9 @@ 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 ;; @@ -56191,7 +56440,7 @@ BEGIN JOIN vn.warehouse w ON w.id = t.warehouseFk JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk JOIN vn.packaging p ON p.id = tp.packagingFk - LEFT JOIN vn.packageEquivalent pe ON pe.packageFk = p.id + LEFT JOIN vn.packageEquivalent pe ON pe.packagingFk = p.id JOIN vn.address a ON a.id = t.addressFk JOIN vn.province p2 ON p2.id = a.provinceFk JOIN vn.country c ON c.id = p2.countryFk @@ -57333,7 +57582,7 @@ DELIMITER ; /*!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 ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -57365,9 +57614,9 @@ DELIMITER ; /*!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 utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceFromClient` */; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -57402,7 +57651,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 */ ; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceFromTicket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -58300,17 +58549,68 @@ BEGIN IF !(SELECT COUNT(*) FROM invoiceInDueDay iid WHERE iid.invoiceInFk = vInvoiceInFk) THEN - + INSERT INTO invoiceInDueDay (invoiceInFk, dueDated, amount, foreignValue) SELECT vInvoiceInFk, - IF(payDay, vn2008.next_venc(issued, detalle, payDay),TIMESTAMPADD(DAY, detalle, issued)), + IF(payDay, vn2008.next_venc(created, detalle, payDay),TIMESTAMPADD(DAY, GREATEST(detalle, 2), created)), IF((@cont:=@cont + 1) < cont, TRUNCATE(venc / cont, 2),venc-(TRUNCATE(venc / cont, 2) * (cont - 1))), IF(@cont < cont, TRUNCATE(foreignValue / cont, 2), foreignValue - (TRUNCATE(foreignValue / cont, 2) * (cont - 1))) - FROM ( - SELECT SUM((1 + (ti.PorcentajeIva / 100)*(s.countryFk = s2.countryFk)) * iit.taxableBase)/COUNT(DISTINCT(pdd.detalle)) venc, + FROM ( SELECT SUM((1 + (IFNULL(ti.PorcentajeIva, 0) / 100)*(s.countryFk = s2.countryFk)) * iit.taxableBase)/COUNT(DISTINCT(pdd.detalle)) venc, + SUM(iit.foreignValue)/COUNT(DISTINCT(pdd.detalle)) foreignValue, + s.payDemFk, + ii.companyFk, + COUNT(DISTINCT(pdd.detalle)) cont, + s.payDay, + DATE(ii.created) created + FROM invoiceIn ii + JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id + LEFT JOIN sage.TiposIva AS ti ON ti.CodigoIva= iit.taxTypeSageFk + JOIN supplier s ON s.id = ii.supplierFk + JOIN supplier s2 ON s2.id = ii.companyFk + JOIN vn2008.pay_dem_det pdd ON pdd.id = s.payDemFk + WHERE ii.id = vInvoiceInFk + GROUP BY ii.id + ) sub + JOIN (SELECT @cont:=0) sub2 + JOIN vn2008.pay_dem_det pdd ON pdd.id = sub.payDemFk + GROUP BY detalle; + 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 `invoiceInDueDay_calculate__` */; +/*!50003 SET @saved_cs_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 `invoiceInDueDay_calculate__`(vInvoiceInFk INT) +BEGIN + + IF !(SELECT COUNT(*) + FROM invoiceInDueDay iid + WHERE iid.invoiceInFk = vInvoiceInFk) THEN + + INSERT INTO invoiceInDueDay (invoiceInFk, + dueDated, + amount, + foreignValue) + SELECT vInvoiceInFk, + IF(payDay, vn2008.next_venc(issued, detalle, payDay),TIMESTAMPADD(DAY, GREATEST(detalle, 2), issued)), + IF((@cont:=@cont + 1) < cont, TRUNCATE(venc / cont, 2),venc-(TRUNCATE(venc / cont, 2) * (cont - 1))), + IF(@cont < cont, TRUNCATE(foreignValue / cont, 2), foreignValue - (TRUNCATE(foreignValue / cont, 2) * (cont - 1))) + FROM ( SELECT SUM((1 + (IFNULL(ti.PorcentajeIva, 0) / 100)*(s.countryFk = s2.countryFk)) * iit.taxableBase)/COUNT(DISTINCT(pdd.detalle)) venc, SUM(iit.foreignValue)/COUNT(DISTINCT(pdd.detalle)) foreignValue, s.payDemFk, ii.companyFk, @@ -58319,18 +58619,18 @@ BEGIN ii.issued FROM invoiceIn ii JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id - JOIN sage.TiposIva AS ti ON ti.CodigoIva= iit.taxTypeSageFk + LEFT JOIN sage.TiposIva AS ti ON ti.CodigoIva= iit.taxTypeSageFk JOIN supplier s ON s.id = ii.supplierFk JOIN supplier s2 ON s2.id = ii.companyFk JOIN vn2008.pay_dem_det pdd ON pdd.id = s.payDemFk WHERE ii.id = vInvoiceInFk GROUP BY ii.id - ) sub + ) sub JOIN (SELECT @cont:=0) sub2 - JOIN vn2008.pay_dem_det pdd ON pdd.id = sub.payDemFk + JOIN vn2008.pay_dem_det pdd ON pdd.id = sub.payDemFk GROUP BY detalle; END IF; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -59763,9 +60063,9 @@ 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 ;; @@ -59825,7 +60125,8 @@ BEGIN c.`grouping` as `grouping`, c.Packing as packing, CONCAT('https://verdnatura.es/vn-image-data/catalog/200x200/', i.image) as urlImage200, - CONCAT('https://verdnatura.es/vn-image-data/catalog/1600x900/', i.image) as urlImage + CONCAT('https://verdnatura.es/vn-image-data/catalog/1600x900/', i.image) as urlImage, + i.itemPackingTypeFk FROM vn.item i LEFT JOIN vn.producer p ON p.id = i.producerFk LEFT JOIN vn.origin o ON o.id = i.originFk @@ -59848,7 +60149,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 `itemDiary` */; +/*!50003 DROP PROCEDURE IF EXISTS `itemDiary__` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -59858,7 +60159,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `itemDiary`(IN vItemId INT, IN vWarehouse INT) +CREATE DEFINER=`root`@`%` PROCEDURE `itemDiary__`(IN vItemId INT, IN vWarehouse INT) BEGIN DECLARE vDateInventory DATETIME; DECLARE vCurdate DATE DEFAULT CURDATE(); @@ -59978,133 +60279,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 `itemDiary__` */; -/*!50003 SET @saved_cs_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 `itemDiary__`(IN vItemId INT, IN vWarehouse INT) -BEGIN - -- BERNAT WORKING IN THIS FILE - DECLARE vDateInventory DATETIME; - DECLARE vCurdate DATE DEFAULT CURDATE(); - DECLARE vDayEnd DATETIME DEFAULT util.dayEnd(vCurdate); - -- traduccion: date, alertLevel, origin, reference, name, In, Out, Balance - SELECT Fechainventario INTO vDateInventory FROM vn2008.tblContadores; - SET @a = 0; - SELECT DATE(date) AS date, - alertLevel, - stateName, - origin, - reference, - clientFk, - name, - `in`, - `out`, - @a := @a + IFNULL(`in`,0) - IFNULL(`out`,0) as balance, - isPicked, - isTicket - FROM - ( SELECT tr.landed as date, - b.quantity as `in`, - NULL as `out`, - IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel, - st.name AS stateName, - s.name as name, - e.ref as reference, - e.id as origin, - s.id as clientFk, - TRUE isPicked, - FALSE AS isTicket - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.supplier s ON s.id = e.supplierFk - JOIN vn.alertLevel al ON al.alertLevel = - CASE - WHEN tr.isReceived != FALSE THEN 3 - WHEN tr.isDelivered THEN 1 - ELSE 0 - END - JOIN vn.state st ON st.code = al.code - WHERE tr.landed >= vDateInventory - AND vWarehouse = tr.warehouseInFk - AND b.itemFk = vItemId - AND e.isInventory = 0 - AND e.isRaid = 0 - UNION ALL - - SELECT tr.shipped as date, - NULL as `in`, - b.quantity as `out`, - IF(tr.isReceived != FALSE,3, IF(tr.isDelivered,1,0)) as alertLevel, - st.name AS stateName, - s.name as name, - e.ref as reference, - e.id as origin, - s.id as clientFk, - TRUE isPicked, - FALSE AS isTicket - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.warehouse w ON w.id = tr.warehouseOutFk - JOIN vn.supplier s ON s.id = e.supplierFk - JOIN vn.alertLevel al ON al.alertLevel = - CASE - WHEN tr.isReceived != FALSE THEN 3 - WHEN tr.isDelivered THEN 1 - ELSE 0 - END - JOIN vn.state st ON st.code = al.code - WHERE tr.shipped >= vDateInventory - AND vWarehouse =tr.warehouseOutFk - AND s.id <> 4 - AND b.itemFk = vItemId - AND e.isInventory = 0 - AND w.isFeedStock = 0 - AND e.isRaid = 0 - UNION ALL - - SELECT t.shipped as date, - NULL as `in`, - s.quantity as `out`, - al.alertLevel as alertLevel, - st.name AS stateName, - t.nickname as name, - t.refFk as reference, - t.id as origin, - t.clientFk, - stk.id as isPicked, -- TRUE as isPicked - TRUE as isTicket - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - LEFT JOIN vn.ticketState ts ON ts.ticket = t.id - JOIN vn.client c ON c.id = t.clientFk - JOIN vn.alertLevel al ON al.alertLevel = - CASE - WHEN t.shipped < vCurdate THEN 3 - WHEN t.shipped > vDayEnd THEN 0 - ELSE IFNULL(ts.alertLevel, 0) - END - JOIN vn.state st ON st.code = al.code - LEFT JOIN vn.saleTracking stk ON stk.saleFk = s.id AND stk.stateFk = 14 -- comentar - WHERE t.shipped >= vDateInventory - AND s.itemFk = vItemId - AND vWarehouse =t.warehouseFk - ) AS itemDiary - ORDER BY date, isTicket, alertLevel DESC, isPicked DESC, `in` DESC, `out` 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 `itemFreight_Show` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -61902,18 +62076,109 @@ 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 `itemShelvingRadar_Urgent`(vWorkerFk INT) BEGIN - + DECLARE vCalcVisibleFk INT; + DECLARE vWarehouseFk INT DEFAULT 60; + -- Eliminar cuando tengamos programador de Android - DECLARE vCalcVisibleFk INT; + CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk); + + SELECT * FROM + (SELECT sub.itemFk, + sub.longName, + CONCAT('Hoy saldrán ', CAST(sub2.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, + CONCAT(IF(sub2.itemFk, IF(sub2.pendiente > (sub.upstairs + sub.downstairs),'(1) ','(2) '),'(3) ' ),sub.producer) producer, + sub.upstairs, + sub.downstairs, + sub.visible, + sub.sectorFk, + CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) nicho + FROM (SELECT iss.itemFk, + CONCAT(i.longName,' ',i.size,' ',IFNULL(i.subName,'') ) longName, + '' size, + CONCAT(iss.parkingCode , ' ', iss.shelvingFk) producer, + 0 upstairs, + SUM(IFNULL(iss.visible,0)) downstairs, + IF(it.isPackaging, null, IFNULL(v.visible,0)) visible, + 0 sectorFk + FROM itemShelvingStock iss + JOIN sector s ON s.id = iss.sectorFk + JOIN item i on i.id = iss.itemFk + JOIN itemType it ON it.id = i.typeFk + LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk + WHERE s.warehouseFk = vWarehouseFk + AND it.workerFk = vWorkerFk + GROUP BY itemFk + ) sub LEFT JOIN (SELECT s.itemFk, SUM(s.quantity) pendiente + FROM sale s + LEFT JOIN saleTracking st ON st.saleFk = s.id + JOIN ticket t ON t.id = s.ticketFk + JOIN client c on c.id = t.clientFk + JOIN clientType ct ON ct.id = c.clientTypeFk + WHERE t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE()) + AND ISNULL(st.saleFk) + AND ct.code IN ('normal', 'trust') + GROUP BY s.itemFk + ) sub2 ON sub2.itemFk = sub.itemFk + UNION ALL + SELECT v.item_id , + i.longName, + CONCAT('Hoy saldrán ', CAST(sub5.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, + CONCAT(IF(sub5.pendiente,'(0) ','(3) ')) producer, + 0, + 0, + v.visible, + 0, + v.visible nicho + FROM cache.visible v + JOIN item i ON i.id = v.item_id + JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemShelvingStock iss ON iss.itemFk = v.item_id + LEFT JOIN (SELECT s.itemFk , SUM(s.quantity) pendiente + FROM sale s + LEFT JOIN saleTracking st ON st.saleFk = s.id + JOIN ticket t ON t.id = s.ticketFk + JOIN client c on c.id = t.clientFk + JOIN clientType ct ON ct.id = c.clientTypeFk + WHERE t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE()) + AND ISNULL(st.saleFk) + AND ct.code IN ('normal', 'trust') + GROUP BY s.itemFk + ) sub5 ON sub5.itemFk = v.item_id + WHERE v.calc_id = vCalcVisibleFk + AND ISNULL(iss.itemFk) + AND it.workerFk = vWorkerFk + ) sub3 + WHERE nicho + ORDER BY producer; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `itemShelvingRadar_Urgent__` */; +/*!50003 SET @saved_cs_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 `itemShelvingRadar_Urgent__`(vWorkerFk INT) +BEGIN + DECLARE vCalcVisibleFk INT; DECLARE vWarehouseFk INT DEFAULT 60; -- DECLARE vSectorFk INt; -- DECLARE vFatherSectorFk INT; @@ -61957,7 +62222,7 @@ BEGIN JOIN vn.client c on c.id = t.clientFk WHERE t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE()) AND ISNULL(st.saleFk) - AND c.isOfficial + AND (c.clientTypeFk = 1 OR c.clientTypeFk = 5) GROUP BY s.itemFk) sub2 ON sub2.itemFk = sub.itemFk UNION ALL @@ -61982,15 +62247,13 @@ BEGIN JOIN vn.client c on c.id = t.clientFk WHERE t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE()) AND ISNULL(st.saleFk) - AND c.isOfficial + AND (c.clientTypeFk = 1 OR c.clientTypeFk = 5) GROUP BY s.itemFk) sub5 ON sub5.itemFk = v.item_id WHERE v.calc_id = vCalcVisibleFk AND ISNULL(iss.itemFk) AND it.workerFk = vWorkerFk) sub3 WHERE nicho ORDER BY producer; - - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -62240,6 +62503,104 @@ BEGIN AND ish.stars IS NULL ORDER BY p.pickingOrder; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `itemShelving_filterBuyer` */; +/*!50003 SET @saved_cs_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 `itemShelving_filterBuyer`(vBuyerFk INT, vWarehouseFk INT) +proc:BEGIN +/** + * Lista de articulos filtrados por comprador + * + * @param vBuyerFk Comprador a filtrar + * @param vWarehouseFk Warehouse + * @return Lista de articulos + */ + DECLARE vCalcVisibleFk INT; + + CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk); + + SELECT * FROM + (SELECT sub.itemFk, + sub.longName, + CONCAT('Hoy saldrán ', CAST(sub2.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, + CONCAT(IF(sub2.itemFk, IF(sub2.pendiente > (sub.upstairs + sub.downstairs),'(1) ','(2) '),'(3) ' ),sub.producer) producer, + sub.upstairs, + sub.downstairs, + sub.visible, + sub.sectorFk, + CAST(visible - upstairs - downstairs AS DECIMAL(10,0)) nicho + FROM (SELECT iss.itemFk, + CONCAT(i.longName,' ',i.size,' ',IFNULL(i.subName,'') ) longName, + '' size, + CONCAT(iss.parkingCode , ' ', iss.shelvingFk) producer, + 0 upstairs, + SUM(IFNULL(iss.visible,0)) downstairs, + IF(it.isPackaging, null, IFNULL(v.visible,0)) visible, + IFNULL(iss.sectorFk,0) sectorFk + FROM itemShelvingStock iss + JOIN sector s ON s.id = iss.sectorFk + JOIN item i on i.id = iss.itemFk + JOIN itemType it ON it.id = i.typeFk + LEFT JOIN cache.visible v ON v.item_id = iss.itemFk AND v.calc_id = vCalcVisibleFk + WHERE s.warehouseFk = vWarehouseFk + AND it.workerFk = vBuyerFk + GROUP BY itemFk + ) sub LEFT JOIN (SELECT s.itemFk, SUM(s.quantity) pendiente + FROM sale s + LEFT JOIN saleTracking st ON st.saleFk = s.id + JOIN ticket t ON t.id = s.ticketFk + JOIN client c on c.id = t.clientFk + JOIN clientType ct ON ct.id = c.clientTypeFk + WHERE t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE()) + AND ISNULL(st.saleFk) + AND ct.code IN ('normal', 'trust') + GROUP BY s.itemFk + ) sub2 ON sub2.itemFk = sub.itemFk + UNION ALL + SELECT v.item_id , + i.longName, + CONCAT('Hoy saldrán ', CAST(sub5.pendiente AS DECIMAL(10,0)), ' unidades.') `size`, + CONCAT(IF(sub5.pendiente,'(0) ','(3) ')) producer, + 0, + 0, + v.visible, + IFNULL(iss.sectorFk,0), + v.visible nicho + FROM cache.visible v + JOIN item i ON i.id = v.item_id + JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemShelvingStock iss ON iss.itemFk = v.item_id + LEFT JOIN (SELECT s.itemFk , SUM(s.quantity) pendiente + FROM sale s + LEFT JOIN saleTracking st ON st.saleFk = s.id + JOIN ticket t ON t.id = s.ticketFk + JOIN client c on c.id = t.clientFk + JOIN clientType ct ON ct.id = c.clientTypeFk + WHERE t.shipped BETWEEN CURDATE() AND util.dayend(CURDATE()) + AND ISNULL(st.saleFk) + AND ct.code IN ('normal', 'trust') + GROUP BY s.itemFk + ) sub5 ON sub5.itemFk = v.item_id + WHERE v.calc_id = vCalcVisibleFk + AND ISNULL(iss.itemFk) + AND it.workerFk = vBuyerFk + ) sub3 + WHERE nicho + ORDER BY producer; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -62358,6 +62719,90 @@ BEGIN DECLARE vTicketFk INT; DECLARE vClientFk INT; DECLARE vCompanyVnlFk INT DEFAULT 442; + DECLARE vVisible INT DEFAULT 0; + DECLARE vCalc INT; + DECLARE vParkedStuff INT; + + SELECT barcodeToItem(vItemFk) INTO vItemFk; + + CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk); + + SELECT IFNULL(visible,0) INTO vVisible + FROM cache.visible + WHERE calc_id = vCalc + AND item_id = vItemFk; + + SELECT sum(visible) INTO vParkedStuff + FROM itemShelvingStock + WHERE warehouseFk = vWarehouseFk + AND itemFk = vItemFk; + + SET vNewVisible = vNewVisible + IFNULL(vParkedStuff,0); + + SELECT IF(vIsTrash, 200, 400) INTO vClientFk; + + SELECT t.id INTO vTicketFk + FROM ticket t + JOIN address a ON a.id=t.addressFk + WHERE t.warehouseFk = vWarehouseFk + AND t.clientFk = vClientFk + AND DATE(t.shipped) = CURDATE() + AND a.isDefaultAddress + LIMIT 1; + + IF vTicketFk IS NULL THEN + + CALL ticket_add( + vClientFk, + CURDATE(), + vWarehouseFk, + vCompanyVnlFk, + NULL, + NULL, + NULL, + CURDATE(), + account.userGetId(), + FALSE, + vTicketFk); + + END IF; + + INSERT INTO sale(ticketFk, itemFk, concept, quantity, price, discount) + SELECT vTicketFk, vItemFk, CONCAT(longName,' ', getWorkerCode(), ' ',LEFT(CAST(NOW() AS TIME),5)), vVisible - vNewVisible, 0, 0 + FROM item + WHERE id = vItemFk; + + UPDATE cache.visible + SET visible = vNewVisible + WHERE calc_id = vCalc + AND item_id = vItemFk; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `itemStockUpdate__` */; +/*!50003 SET @saved_cs_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 `itemStockUpdate__`( + vItemFk INT, + vWarehouseFk INT, + vNewVisible INT, + vIsTrash BOOLEAN) +BEGIN + + DECLARE vTicketFk INT; + DECLARE vClientFk INT; + DECLARE vCompanyVnlFk INT DEFAULT 442; DECLARE vAgencyModeOthersFk INT DEFAULT 2; DECLARE vVisible INT DEFAULT 0; DECLARE vCalc INT; @@ -62808,9 +63253,9 @@ 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 ;; @@ -62823,6 +63268,78 @@ BEGIN DECLARE vTicketFk INT; DECLARE vClientFk INT; + DECLARE vCompanyVnlFk INT DEFAULT 442; + DECLARE vCalc INT; + + SELECT barcodeToItem(vItemFk) INTO vItemFk; + + SELECT IF(vIsTrash, 200, 400) INTO vClientFk; + + SELECT t.id INTO vTicketFk + FROM ticket t + JOIN address a ON a.id=t.addressFk + WHERE t.warehouseFk = vWarehouseFk + AND t.clientFk = vClientFk + AND DATE(t.shipped) = CURDATE() + AND a.isDefaultAddress + LIMIT 1; + + CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk); + + IF vTicketFk IS NULL THEN + + CALL ticket_add( + vClientFk, + CURDATE(), + vWarehouseFk, + vCompanyVnlFk, + NULL, + NULL, + NULL, + CURDATE(), + account.userGetId(), + FALSE, + vTicketFk); + END IF; + + INSERT INTO sale(ticketFk, itemFk, concept, quantity) + SELECT vTicketFk, + vItemFk, + CONCAT(longName,' ',getWorkerCode(), ' ', LEFT(CAST(NOW() AS TIME),5)), + vQuantity + FROM item + WHERE id = vItemFk; + + UPDATE cache.visible + SET visible = visible - vQuantity + WHERE calc_id = vCalc + AND item_id = vItemFk; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `itemTrash__` */; +/*!50003 SET @saved_cs_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 `itemTrash__`( + vItemFk INT, + vWarehouseFk INT, + vQuantity INT, + vIsTrash BOOLEAN) +BEGIN + + DECLARE vTicketFk INT; + DECLARE vClientFk INT; DECLARE vCompanyVnlFk INT DEFAULT 442; DECLARE vAgencyModeOthersFk INT DEFAULT 2; DECLARE vCurrentTime VARCHAR(5); @@ -62925,11 +63442,11 @@ DELIMITER ; /*!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 collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `item_getBalance`(IN vItemId INT, IN vWarehouse INT) +CREATE DEFINER=`root`@`%` PROCEDURE `item_getBalance`(IN vItemId int, IN vWarehouse int) BEGIN DECLARE vDateInventory DATETIME; DECLARE vCurdate DATE DEFAULT CURDATE(); @@ -62947,7 +63464,7 @@ BEGIN reference, clientFk, name, - `in`, + `in` AS invalue, `out`, @a := @a + IFNULL(`in`,0) - IFNULL(`out`,0) as balance, @currentLineFk := IF (@shipped < CURDATE() @@ -63679,6 +64196,32 @@ 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_updatePackingType` */; +/*!50003 SET @saved_cs_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 `item_updatePackingType`(vItem INT, vItemPackingTypeFk VARCHAR(1)) +BEGIN +/** + * Update the packing type of an item + * + * @param vItem id del item a actualizar + * @param vItemPackingTypeFk packing type + */ + UPDATE item SET itemPackingTypeFk = vItemPackingTypeFk WHERE id = vItem; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_ValuateInventory` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -64069,6 +64612,70 @@ 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 `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 `kk`(vCIF VARCHAR(9)) +BEGIN + + DECLARE vLetraInicial VARCHAR(1); + DECLARE vLetraFinal VARCHAR(1); + DECLARE vParteNumerica VARCHAR(7); + DECLARE vSuma INT DEFAULT 0; + DECLARE vNumero INT DEFAULT 0; + DECLARE i INT DEFAULT 0; + DECLARE vResult BOOL DEFAULT FALSE; + + SET vLetraInicial = SUBSTR(vCIF, 1, 1); + SET vLetraFinal = SUBSTR(vCIF, 9, 1); + SET vParteNumerica = SUBSTR(vCIF, 2, 7); + + WHILE i < 7 DO + + SET i = i + 1; + + SET vNumero = CAST(SUBSTR(vParteNumerica, i, 1) AS DECIMAL(1,0)); + + IF i MOD 2 THEN + + SET vNumero = vNumero * 2; + SET vNumero = vNumero MOD 10 + FLOOR(vNumero/10); + + END IF; + + SET vSuma = vSuma + vNumero; + + END WHILE; + + SET vSuma = vSuma MOD 10; + + IF vSuma > 0 THEN + + SET vSuma = 10 - vSuma; + + END IF; + + + -- Comprobación de dígito de control numérico + IF CAST(vLetraFinal AS DECIMAL(1,0)) = vSuma THEN + + SET vResult = TRUE; + + 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 `ledger_doCompensation` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -64342,6 +64949,155 @@ set @cajas := 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 `machineWorker_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 `machineWorker_add`(vPlate VARCHAR(10), vWorkerFk INT) +BEGIN + +/** + * Inserta registro si el vWorkerFk no ha registrado nada en las últimas 12 horas + * @param vPlate número de matrícula + * @param vWorkerFk id del worker + * +*/ + UPDATE vn.machineWorker mw + JOIN vn.machine m ON m.id = mw.machineFk + SET mw.outTimed = NOW() + WHERE (mw.workerFk = vWorkerFk OR m.plate = vPlate) + AND ISNULL(mw.outTimed); + + INSERT INTO machineWorker (machineFk, workerFk) + SELECT m.id, vWorkerFk + FROM machine m + WHERE m.plate= vPlate; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `machineWorker_getHistorical` */; +/*!50003 SET @saved_cs_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 `machineWorker_getHistorical`(vPlate VARCHAR(20), vWorkerFk INT) +BEGIN +/** + * Obtiene historial de la matrícula vPlate que el trabajador vWorkerFk escanea, + * si es jefe de producción muestra el historial completo. + * + * @param vPlate número de matrícula + * @param vWorkerFk id del trabajador + * +*/ + DECLARE vWorkerName VARCHAR(255) DEFAULT account.user_getNameFromId(vWorkerFk); + + SELECT mw.inTimed,account.user_getNameFromId(mw.workerFk) as workerName, mw.outTimed + FROM machineWorker mw + JOIN machine m ON m.plate = vPlate + WHERE mw.machineFk = m.id + AND mw.workerFk = IF(account.user_hasRole(vWorkerName, 'productionAssi'), mw.workerFk, vWorkerFk) + ORDER BY mw.inTimed 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 `machineWorker_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 = 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 `machineWorker_update`(vPlate VARCHAR(10), vWorkerFk INT) +BEGIN + +/** + * Actualiza el registro correspondiente si el vWorkerFk ha registrado en las últimas 12 horas con vPlate, + * + * @param vPlate número de matrícula + * @param vWorkerFk id del trabajador + * +*/ + + DECLARE vMachineFk INT(10); + + SELECT m.id INTO vMachineFk + FROM machine m + WHERE m.plate = vPlate; + + IF (SELECT COUNT(*) + FROM machineWorker m + WHERE m.workerFk = vWorkerFk + AND m.inTimed >= TIMESTAMPADD(HOUR , -12,NOW()) AND ISNULL(m.outTimed)) THEN + + UPDATE machineWorker m + SET m.outTimed = CURRENT_TIMESTAMP() + WHERE m.workerFk = vWorkerFk + AND m.inTimed >= TIMESTAMPADD(HOUR , -12,NOW()) + AND ISNULL(m.outTimed) + AND m.machineFk = vMachineFk; + + 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 `machine_getWorkerPlate` */; +/*!50003 SET @saved_cs_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 `machine_getWorkerPlate`(vWorkerFk INT) +BEGIN +/** + * Selecciona la matrícula del vehículo del workerfk + * + * @param vWorkerFk el id del trabajador + * + * + **/ + + SELECT m.plate + FROM machine m + JOIN machineWorker mw ON mw.machineFk = m.id + WHERE mw.inTimed >= TIMESTAMPADD(HOUR , -12,NOW()) + AND ISNULL(mw.outTimed) + AND mw.workerFk = vWorkerFk; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64553,7 +65309,7 @@ DELIMITER ; /*!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 ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -64599,7 +65355,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 */ ; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `mergeTicketWithArray` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -65221,133 +65977,6 @@ BEGIN 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 `packageInvoicing__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `packageInvoicing__`( - IN vClient INT, - IN vDate DATE, - IN vCompany INT, - IN vIsAllInvoiceable BOOLEAN, - OUT vNewTicket INT(11) - ) -BEGIN - - DECLARE vGraceDays INT; - DECLARE vDateStart DATE DEFAULT '2017-11-21'; - DECLARE vIsInvoiceable BOOLEAN; - DECLARE vWarehouse INT DEFAULT 13; - DECLARE vAgenciaEmbalajes INT DEFAULT 628; - DECLARE vComponentCost INT DEFAULT 28; - DECLARE vGraceDate DATE; - DECLARE vZoneFk INT; - - SET vGraceDays = IF(vIsAllInvoiceable,0,30); - SET vGraceDate = TIMESTAMPADD(DAY, - vGraceDays, vDate); - - /* Clientes especiales: - 3240 MADEFLOR - 992 JAVIER FELIU - 4 TONI VENDRELL - */ - - IF vClient IN (992, 3240, 4) THEN - - SET vGraceDays = 365; - - END IF; - - /* Fin clientes especiales */ - - DROP TEMPORARY TABLE IF EXISTS tmp.packageToInvoice; - - CREATE TEMPORARY TABLE tmp.packageToInvoice - SELECT p.itemFk, - tp.packagingFk, - IF(tp.quantity < 0 OR t.shipped < vGraceDate, tp.quantity, 0) quantity, - tp.ticketFk, - p.price - FROM ticketPackaging tp - JOIN packaging p ON p.id = tp.packagingFk - JOIN ticket t ON t.id = tp.ticketFk - WHERE t.shipped BETWEEN vDateStart AND vDate - AND t.clientFk = vClient; - - DROP TEMPORARY TABLE IF EXISTS tmp.packageToInvoicePositives; - - CREATE TEMPORARY TABLE tmp.packageToInvoicePositives - SELECT itemFk, sum(quantity) as totalQuantity - FROM tmp.packageToInvoice - GROUP BY itemFk - HAVING totalQuantity > 0; - - SELECT GREATEST(COUNT(*),vIsAllInvoiceable) - INTO vIsInvoiceable - FROM tmp.packageToInvoicePositives; - - SELECT id INTO vZoneFk FROM vn.zone WHERE agencyModeFk = vAgenciaEmbalajes LIMIT 1; - - IF vIsInvoiceable THEN - - CALL vn.ticketCreateWithoutZone(vClient, vDate, vWarehouse, vCompany, NULL, vAgenciaEmbalajes, NULL, vDate, account.userGetId(), vNewTicket); - - INSERT INTO ticketPackaging( - ticketFk, - packagingFk, - quantity, - pvp) - SELECT vNewTicket, - pti.packagingFk, - - SUM(pti.quantity) AS totalQuantity, - pti.price - FROM tmp.packageToInvoice pti - LEFT JOIN tmp.packageToInvoicePositives ptip ON pti.itemFk = ptip.itemFk - WHERE ptip.itemFK IS NOT NULL - OR vIsAllInvoiceable - GROUP BY packagingFk - HAVING totalQuantity; - - INSERT INTO sale( - ticketFk, - itemFk, - concept, - quantity, - price - ) - SELECT vNewTicket, - pti.itemFk, - i.name as concept, - sum(pti.quantity) as totalQuantity, - pti.price - FROM tmp.packageToInvoice pti - JOIN item i ON i.id = pti.itemFk - LEFT JOIN tmp.packageToInvoicePositives ptip ON pti.itemFk = ptip.itemFk - WHERE ptip.itemFK IS NOT NULL - OR vIsAllInvoiceable - GROUP BY pti.itemFk - HAVING totalQuantity; - - INSERT INTO saleComponent(saleFk, componentFk, value) - SELECT id, vComponentCost, price - FROM sale - WHERE ticketFk = vNewTicket; - - UPDATE ticket SET zoneFk = vZoneFk WHERE id = vNewTicket; - END IF; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65737,6 +66366,81 @@ DELIMITER ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `payRoll`(IN vFromDated DATE, IN vToDated DATE, IN vFromPaid DATE, IN vToPaid DATE, IN vPartTime BOOL) +BEGIN + + SET @userFk := 0; + + SELECT CONCAT(w.lastName,', ',w.firstname) AS Trabajador, + CAST(Sum((wj.total + wj.permission + wj.lunch)* wj.priceOrdinaryHour + wj.hollyday * wj.priceHollydayHour + + wj.nocturn * wj.priceNocturnHour + + wj.extra * wj.priceExtraHour) AS DECIMAL(10,2)) AS salario, + CAST(Sum(wj.permission) AS DECIMAL(10,2)) AS permission, + CAST(Sum(wj.total) AS DECIMAL(10,2)) AS total, + CAST(Sum(wj.nocturn) AS DECIMAL(10,2)) AS nocturn, + CAST(Sum(wj.hollyday) AS DECIMAL(10,2)) AS hollyday, + CAST(Sum(wj.lunch) AS DECIMAL(10,2)) AS lunch, + CAST(Sum(wj.extra) AS DECIMAL(10,2)) AS extra, + CAST(Sum(wj.contractJourney) AS DECIMAL(10,2)) AS contractJourney, + d.name AS departamento, + CAST(Sum((wj.contractJourney + wj.permission) * wj.priceOrdinaryHour) AS DECIMAL(10,2)) AS teorico, + CAST(Sum((wj.lunch + wj.permission + wj.total) * wj.priceordinaryhour) AS DECIMAL(10,2)) AS practico, + CAST(Sum(wj.nocturn * wj.pricenocturnhour) AS DECIMAL(10,2)) AS nocturno, + CAST(Sum(wj.hollyday * wj.priceHollydayHour) AS DECIMAL(10,2)) AS festivos, + CAST(Sum(wj.extra * wj.priceextrahour) AS DECIMAL(10,2)) AS extras, + MAX(wj.businessFk) as businessFk, + IF(sub.workerFk IS NULL, FALSE, TRUE) isLastBusiness, + Min(b.date_start) AS fromDated, + Max(b.date_end) AS toDated, + blp.importepactado, + bl.porhoras, + IF(wj.userFk != @userFk, CAST(IFNULL(a.Anticipos,0) AS DECIMAL(10,2)), 0) AS Anticipos, + IF(wj.userFk != @userFk, CAST(IFNULL(se.SaldoEuros,0) AS DECIMAL(10,2)), 0) AS SaldoEuros, + @userFk := wj.userFk as userFk + FROM worker w + JOIN workerJourney wj ON w.id = wj.userFk + JOIN postgresql.business b ON b.business_id = wj.businessFk + JOIN postgresql.business_labour bl ON bl.business_id = b.business_id + JOIN postgresql.calendar_labour_type cl ON cl.calendar_labour_type_id = bl.calendar_labour_type_id + JOIN postgresql.business_labour_payroll blp ON blp.business_id = b.business_id + JOIN department d ON bl.department_id = d.id + LEFT JOIN (SELECT pe.id_trabajador, SUM(debe) Anticipos + FROM postgresql.income_employee ie + JOIN postgresql.person pe ON ie.person_id = pe.person_id + WHERE odbc_date BETWEEN vFromPaid AND vToPaid + AND id_incomeType = 14 -- Salario + GROUP BY pe.id_trabajador + ) a ON a.id_trabajador = w.id + LEFT JOIN (SELECT pe.id_trabajador, SUM(debe) - SUM(haber) as SaldoEuros + FROM postgresql.income_employee ie + JOIN postgresql.person pe ON ie.person_id = pe.person_id + GROUP BY pe.id_trabajador + ) se ON se.id_trabajador = w.id + LEFT JOIN (SELECT MAX(IFNULL(ended, DATE_ADD(vToDated, INTERVAL 1 DAY )))dated,wl.workerFk + FROM vn.workerLabour wl + GROUP BY wl.workerFk + HAVING dated<=vToDated + ) sub ON sub.workerFk = w.id + WHERE wj.dated BETWEEN vFromDated AND vToDated + AND IF(vPartTime, cl.hours_week <= 40, cl.hours_week = 40) + GROUP BY w.id + ORDER BY w.lastName, w.firstname; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `payRoll__` */; +/*!50003 SET @saved_cs_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 `payRoll__`(IN vFromDated DATE, IN vToDated DATE, IN vFromPaid DATE, IN vToPaid DATE, IN vPartTime BOOL) BEGIN SET @userFk := 0; @@ -67400,7 +68104,7 @@ BEGIN IF !(vItemPackingTypeFk <=> 'V') THEN SELECT CONCAT(tc.collectionFk,' ',LEFT(cc.code,4)) `level`, - tc.ticketFk, + tc.ticketFk, LEFT(IF(t.routeFk IS null, am.name, zo.name ),12) agencyDescription, am.name, t.clientFk, @@ -67409,7 +68113,8 @@ BEGIN tt.labelCount, IF(HOUR(t.shipped),TIME(t.shipped),TIME(zo.HOUR)) as horaagencia, t.shipped, - count(*) AS urgente + count(*) AS urgente , + t.nickName FROM vn.ticket t JOIN vn.ticketCollection tc ON tc.ticketFk = t.id JOIN vn.collectionColors cc ON cc.shelve = tc.`level` AND cc.wagon = tc.wagon @@ -67438,7 +68143,8 @@ BEGIN tt.labelCount, IF(HOUR(t.shipped),TIME(t.shipped),TIME(zo.HOUR)) as horaagencia, t.shipped, - count(*) AS urgente + count(*) AS urgente , + t.nickName FROM vn.ticket t JOIN vn.ticketCollection tc ON tc.ticketFk = t.id JOIN vn.sale s ON s.ticketFk = t.id @@ -67749,7 +68455,7 @@ BEGIN UPDATE routesMonitor rm JOIN route r ON r.id = rm.routeFk JOIN agencyMode a ON a.id = r.agencyModeFk - JOIN routeGate rg ON rg.routeFk = rm.routeFk + LEFT JOIN routeGate rg ON rg.routeFk = rm.routeFk SET rm.`name` = a.name, rm.dated = r.created, rm.ticketFree = 0, @@ -67859,23 +68565,79 @@ 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 character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `routeUpdateM3`(vRoute INT) BEGIN +/** + * @deprecated Use vn.route_updateM3() + */ + call route_updateM3(vRoute); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `route_doRecalc` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `route_doRecalc`() +proc: BEGIN +/** + * Recalculates modified route. + */ + + DECLARE vDone BOOL; + DECLARE vRouteFk INT; - UPDATE vn.route r - LEFT JOIN ( - SELECT routeFk, SUM(volume) AS m3 - FROM saleVolume - WHERE routeFk = vRoute - ) v ON v.routeFk = r.id - SET r.m3 = IFNULL(v.m3,0) - WHERE r.id =vRoute; + DECLARE cCur CURSOR FOR + SELECT routeFk FROM routeRecalc; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + DO RELEASE_LOCK('vn.route_doRecalc'); + ROLLBACK; + RESIGNAL; + END; + + IF !GET_LOCK('vn.route_doRecalc', 0) THEN + LEAVE proc; + END IF; + + OPEN cCur; + + myLoop: LOOP + SET vDone = FALSE; + FETCH cCur INTO vRouteFk; + + IF vDone THEN + LEAVE myLoop; + END IF; + + START TRANSACTION; + CALL route_updateM3(vRouteFk); + COMMIT; + + DELETE FROM routeRecalc WHERE routeFk = vRouteFk; + END LOOP; + + CLOSE cCur; + DO RELEASE_LOCK('vn.route_doRecalc'); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -67957,6 +68719,33 @@ 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 `route_updateM3` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `route_updateM3`(vRoute INT) +BEGIN + + UPDATE vn.route r + LEFT JOIN ( + SELECT routeFk, SUM(volume) AS m3 + FROM saleVolume + WHERE routeFk = vRoute + ) v ON v.routeFk = r.id + SET r.m3 = IFNULL(v.m3,0) + WHERE r.id =vRoute; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `rutasAnalyze` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -69129,6 +69918,166 @@ 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 `sale_fruitWithoutLot` */; +/*!50003 SET @saved_cs_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 `sale_fruitWithoutLot`() +BEGIN +/** +* +* Manda correo a el usuario encargado de fruta y verdura +* de las lineas de tickets a las que no ha sido asignada +* un lote. +* +*/ + SET SESSION group_concat_max_len = 102400; + + INSERT INTO mail (sender,replyTo,subject,body) + SELECT CONCAT(sub.name, '@verdnatura.es') sender, + 'noreply@verdnatura.es' replyTo, + CONCAT( + 'El ', + CONCAT (CAST((SUM(sub.fail)/COUNT(*))*100 AS DECIMAL(10,2)), ' %'), + CONCAT(' de los artículos han sido vendidos sin lote con fecha: ', DATE_SUB(CURDATE(), INTERVAL 3 DAY )) + ) subject, + GROUP_CONCAT(sub.ticket SEPARATOR '

') body + FROM (SELECT IF (sb.saleFk IS NULL,1, 0) fail, + u.name, + IF (sb.saleFk IS NULL,CONCAT('Artículo ',i.id,', ',i.name,':
     + https://salix.verdnatura.es/#!/ticket/',t.id,'/sale'), NULL) ticket + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + LEFT JOIN saleBuy sb ON sb.saleFk = s.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN account.user u ON u.id = it.workerFk + JOIN itemCategory ic ON ic.id = it.categoryFk + WHERE t.shipped = DATE_SUB(CURDATE(), INTERVAL 1 DAY) + AND ic.code='fruit')sub; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `sale_getFromTicketOrCollection` */; +/*!50003 SET @saved_cs_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 `sale_getFromTicketOrCollection`(vParam INT) +BEGIN + + + /* + * Visualizar lineas de la tabla sale a través del parámetro vParam que puede ser ticket o collection + */ + + DECLARE vItemPackingTypeFk VARCHAR(1); + + + IF (SELECT COUNT(*) FROM vn.ticket WHERE id = vParam AND id > 2000000) THEN + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + SELECT t.id, clientFk, t.id as showTicketFk + FROM vn.ticket t + WHERE t.id = vParam; + + ELSE + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + SELECT tc.ticketFk id, clientFk, tc.ticketFk as showTicketFk + FROM vn.ticketCollection tc + JOIN vn.ticket t ON t.id = tc.ticketFk + WHERE tc.collectionFk = vParam; + + END IF; + + + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket3; + CREATE TEMPORARY TABLE tmp.ticket3 + SELECT * FROM tmp.ticket; + + SELECT showTicketFk ticketFk, + s.id as saleFk, + s.itemFk, + s.quantity, + i.longName, + i.size, + s.reserved, + MAX(IF(st.semaphore <=> 1, TRUE, FALSE)) as isPreviousPrepared, + MAX(IF(st.semaphore <=> 2, TRUE, FALSE)) as isPrepared, + MAX(IF(st.semaphore <=> 3, TRUE, FALSE)) as isControlled, + ic.color, + ip.productor, + s.discount, + s.price, + i.stems, + i.category, + o.code AS origin, + t.clientFk, + s.originalQuantity, + TRIM(CONCAT( + LPAD(s.concept,30,' '), ' ', + RPAD(IFNULL(i.size,''),5,' ') + ) + ) as line1, + TRIM(CONCAT(LPAD(IFNULL(ip.productor,''),30,' '), ' ',LPAD(IFNULL(o.code,''),4,' '))) as line2, + TRIM(CONCAT(ic.color, IF(MAX(IF(st.semaphore <=> 1, TRUE, FALSE)) AND t.id != t.showTicketFk, CONCAT(' [ TICKET ',t.id,' ] '),''), IFNULL(LPAD(st.parkingCode,40,' '),''))) as line3, + s.isAdded, + str.originalQuantity as startQuantity, -- eliminar cuando tengamos la nueva apk + IFNULL(c.workerFk,getUser()), + IFNULL(SUM(iss.quantity),0) as pickedQuantity + FROM vn.sale s + JOIN tmp.ticket t ON t.id = s.ticketFk + JOIN vn.item i ON i.id = s.itemFk + LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = t.id + LEFT JOIN vn.collection c ON c.id = tc.collectionFk + LEFT JOIN vn.saleTracking str ON str.saleFk = s.id AND str.isChecked = 1 + LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = s.id + LEFT JOIN vn.state st ON st.id = str.stateFk + LEFT JOIN vn.itemColor ic ON ic.itemFk = s.itemFk + LEFT JOIN vn.itemProductor ip ON ip.itemFk = s.itemFk + LEFT JOIN vn.origin o ON o.id = i.originFk + LEFT JOIN (SELECT st.saleFk, p.`code` as parkingCode + FROM vn.saleTracking st + JOIN vn.state s ON s.id = st.stateFk + JOIN vn.sale sa ON sa.id = st.saleFk + JOIN tmp.ticket3 t ON t.id = sa.ticketFk + JOIN vn.ticketParking tp ON tp.ticketFk = sa.ticketFk + JOIN vn.parking p ON p.id = tp.parkingFk + WHERE st.isChecked + AND s.semaphore = 1 + GROUP BY st.saleFk) st ON st.saleFk = s.id + WHERE (i.itemPackingTypeFk = c.itemPackingTypeFk OR ISNULL(c.itemPackingTypeFk)) + GROUP BY s.id + + ; + + DROP TEMPORARY TABLE tmp.ticket; + DROP TEMPORARY TABLE tmp.ticket3; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `sale_getProblems` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -69195,6 +70144,10 @@ BEGIN JOIN vn.sale s ON s.ticketFk = tl.ticketFk LEFT JOIN vn.saleComponent sc ON sc.saleFk = s.id LEFT JOIN vn.component c ON c.id = sc.componentFk AND c.isRequired + JOIN vn.ticket t ON t.id = tl.ticketFk + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + JOIN vn.deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE dm.code IN('AGENCY','DELIVERY','PICKUP') GROUP BY tl.ticketFk, s.id; INSERT INTO tmp.sale_problems(ticketFk, isFreezed) @@ -69222,7 +70175,7 @@ BEGIN JOIN tmp.risk r ON r.clientFk = t.clientFk JOIN vn.client c ON c.id = t.clientFk JOIN vn.clientConfig cc - WHERE r.risk - cc.riskTolerance > c.credit + 10 + WHERE r.risk > c.credit + 10 AND a.isRiskFree = FALSE ON DUPLICATE KEY UPDATE risk = r.risk; @@ -69271,7 +70224,7 @@ BEGIN JOIN vn.sale s ON s.ticketFk = t.id JOIN vn.item i ON i.id = s.itemFk JOIN vn.itemType it on it.id = i.typeFk - LEFT JOIN vn.itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + LEFT JOIN vn.itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache WHERE IFNULL(av.available, 0) < 0 AND s.quantity > IFNULL(issw.visible, 0) @@ -69296,7 +70249,7 @@ BEGIN JOIN vn.sale s ON s.ticketFk = t.id JOIN vn.item i ON i.id = s.itemFk JOIN vn.itemType it on it.id = i.typeFk - LEFT JOIN vn.itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk + LEFT JOIN vn.itemShelvingStock_byWarehouse issw ON issw.itemFk = i.id AND issw.warehouseFk = t.warehouseFk WHERE s.quantity > IFNULL(issw.visible, 0) AND s.quantity > 0 AND s.isPicked = FALSE @@ -69312,7 +70265,7 @@ BEGIN END WHILE; CLOSE vCursor; - + INSERT INTO tmp.sale_problems(ticketFk, isTaxDataChecked) SELECT DISTINCT tl.ticketFk, FALSE FROM tmp.ticket_list tl @@ -69323,7 +70276,7 @@ BEGIN DROP TEMPORARY TABLE tmp.clientGetDebt, - tmp.ticket_list; + tmp.ticket_list; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70115,7 +71068,7 @@ DELIMITER ; /*!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 ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -70158,7 +71111,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 */ ; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `stockBuyed` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70194,7 +71147,7 @@ BEGIN -- SELECT Volumen INTO vVolume FROM vn2008.Cubos WHERE Id_Cubo = 'cc' LIMIT 1; INSERT INTO stockBuyed(user, buyed, `date`) - SELECT tr.user_id, SUM(( amount / c.packing ) * vn.buy_getVolume(Id_Compra)) / vc.espai / 1000000 buyed, vDate + SELECT tr.user_id, SUM(( amount / c.packing ) * vn.buy_getVolume(Id_Compra)) / vc.palletM3 / 1000000 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 @@ -70208,7 +71161,7 @@ BEGIN ON DUPLICATE KEY UPDATE buyed = VALUES(buyed); INSERT INTO stockBuyed(USER, buyed, `date`) - SELECT vRuben, @amount := SUM(ic.cm3 * io.amount / vc.espai / 1000000), vDate + SELECT vRuben, @amount := SUM(ic.cm3 * io.amount / vc.palletM3 / 1000000), vDate FROM vn2008.item_out io JOIN vn.itemCost ic ON ic.itemFk = io.item_id AND ic.warehouseFk = vWarehouse JOIN vn.ticket t ON t.id = io.ticketFk @@ -70222,7 +71175,7 @@ BEGIN ON DUPLICATE KEY UPDATE buyed = buyed + @amount; INSERT INTO stockBuyed(USER, buyed, `date`) - SELECT vJose, @amount := SUM(ic.cm3 * io.amount / vc.espai / 1000000), vDate + SELECT vJose, @amount := SUM(ic.cm3 * io.amount / vc.palletM3 / 1000000), vDate FROM vn2008.item_out io JOIN vn.itemCost ic ON ic.itemFk = io.item_id AND ic.warehouseFk = vWarehouse JOIN vn.ticket t ON t.id = io.ticketFk @@ -70236,7 +71189,7 @@ BEGIN ON DUPLICATE KEY UPDATE buyed = buyed + @amount; INSERT INTO stockBuyed(USER, buyed, `date`) - SELECT vClaudi, @amount := SUM(ic.cm3 * io.amount / vc.espai / 1000000), vDate + SELECT vClaudi, @amount := SUM(ic.cm3 * io.amount / vc.palletM3 / 1000000), vDate FROM vn2008.item_out io JOIN vn.itemCost ic ON ic.itemFk = io.item_id AND ic.warehouseFk = vWarehouse JOIN vn.ticket t ON t.id = io.ticketFk @@ -70248,8 +71201,10 @@ BEGIN AND warehouse_id = vWarehouse AND c.country NOT IN ('Francia','Holanda') ON DUPLICATE KEY UPDATE buyed = buyed + @amount; - - + + DROP TEMPORARY TABLE + vn2008.t_item_last_buy, + tmp_item; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -70260,9 +71215,9 @@ 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 character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -70284,24 +71239,27 @@ BEGIN 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 + vn2008.t_item_last_buy, + 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 `stockBuyedByWorkerTest` */; +/*!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 = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_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 = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `stockBuyedByWorkerTest`(vDate DATE, vWorker INT) +CREATE DEFINER=`root`@`%` PROCEDURE `stockBuyedByWorkerTest__`(vDate DATE, vWorker INT) BEGIN DECLARE vVolume DECIMAL(10,2); @@ -70378,7 +71336,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 `stockTraslationTest` */; +/*!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 */ ; @@ -70388,7 +71346,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `stockTraslationTest`(vDate DATE) +CREATE DEFINER=`root`@`%` PROCEDURE `stockTraslationTest__`(vDate DATE) BEGIN /** * Calcula el stock del vWarehouse desde FechaInventario hasta v_date @@ -70733,9 +71691,9 @@ 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 ;; @@ -70744,14 +71702,14 @@ BEGIN SELECT * FROM ( - SELECT supplierFk, itemFk, longName, supplier, entryFk, landed, `out`, `in`, almacen + SELECT supplierFk, itemFk, longName, supplier, entryFk, landed, `out`, `in`, almacen, cost FROM supplierPackaging WHERE supplierFk = vSupplierFk AND landed >= vFromDated UNION ALL - SELECT vSupplierFk, itemFk, longName, supplier, 'anterior', vFromDated, sum(`out`), sum(`in`), NULL + SELECT vSupplierFk, itemFk, longName, supplier, 'anterior', vFromDated, sum(`out`), sum(`in`), NULL, cost FROM supplierPackaging WHERE supplierFk = vSupplierFk AND landed < vFromDated @@ -70759,9 +71717,6 @@ BEGIN ) sub ORDER BY itemFk, landed; - - - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -71509,7 +72464,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 `ticketClosureAgencyListAdd` */; +/*!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 */ ; @@ -71519,7 +72474,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `ticketClosureAgencyListAdd`(vAgencyModeFk INT) +CREATE DEFINER=`root`@`%` PROCEDURE `ticketClosureAgencyListAdd__`(vAgencyModeFk INT) BEGIN /** * Prepara un listado de agencias sobre los que se realizará el cierre. @@ -72068,104 +73023,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 `ticketCreateWithoutZone` */; -/*!50003 SET @saved_cs_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 `ticketCreateWithoutZone`( - vClientId INT - ,vShipped DATE - ,vWarehouseFk INT - ,vCompanyFk INT - ,vAddressFk INT - ,vAgencyModeFk INT - ,vRouteFk INT - ,vlanded DATE - ,vUserId INT - ,OUT vNewTicket INT) -BEGIN - - DECLARE vZoneFk INT; - - IF vClientId IS NULL THEN - CALL util.throw ('CLIENT_NOT_ESPECIFIED'); - END IF; - - IF NOT vAddressFk OR vAddressFk IS NULL THEN - SELECT id INTO vAddressFk - FROM address - WHERE clientFk = vClientId AND isDefaultAddress; - END IF; - - IF NOT vAgencyModeFk OR vAgencyModeFk IS NULL THEN - SELECT agencyModeFk INTO vAgencyModeFk - FROM address - WHERE clientFk = vClientId AND isDefaultAddress; - END IF; - - CALL vn.zone_getShippedWarehouse(vlanded, vAddressFk, vAgencyModeFk); - - SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetShipped - WHERE shipped = vShipped AND warehouseFk = vWarehouseFk LIMIT 1; - - INSERT INTO vn2008.Tickets ( - Id_Cliente, - Fecha, - Id_Consigna, - Id_Agencia, - Alias, - warehouse_id, - Id_Ruta, - empresa_id, - landing, - zoneFk - ) - SELECT - vClientId, - vShipped, - a.id, - IF(vAgencyModeFk, vAgencyModeFk, a.agencyModeFk), - a.nickname, - vWarehouseFk, - IF(vRouteFk,vRouteFk,NULL), - vCompanyFk, - vlanded, - vZoneFk - FROM address a - JOIN agencyMode am ON am.id = a.agencyModeFk - WHERE a.id = vAddressFk; - - 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.id = vAddressFk; - - -- CALL logAddWithUser(vNewTicket, vUserId, 'insert', 'ticket', CONCAT('Ha creado el ticket', ' ', vNewTicket)); - INSERT INTO vn.ticketLog - SET originFk = vNewTicket, userFk = vUserId, `action` = 'insert', description = CONCAT('Ha creado el ticket:', ' ', vNewTicket); - - IF (SELECT ct.isCreatedAsServed FROM vn.clientType ct JOIN vn.client c ON c.typeFk = ct.code WHERE c.id = vClientId ) <> FALSE THEN - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) - SELECT id, vNewTicket, vUserId - 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 `ticketCreateWithoutZone__` */; +/*!50003 DROP PROCEDURE IF EXISTS `ticketCreateWithUser` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -72175,103 +73033,6 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `ticketCreateWithoutZone__`( - vClientId INT - ,vShipped DATE - ,vWarehouseFk INT - ,vCompanyFk INT - ,vAddressFk INT - ,vAgencyModeFk INT - ,vRouteFk INT - ,vlanded DATE - ,vUserId INT - ,OUT vNewTicket INT) -BEGIN - - DECLARE vZoneFk INT; - - IF vClientId IS NULL THEN - CALL util.throw ('CLIENT_NOT_ESPECIFIED'); - END IF; - - IF NOT vAddressFk OR vAddressFk IS NULL THEN - SELECT id INTO vAddressFk - FROM address - WHERE clientFk = vClientId AND isDefaultAddress; - END IF; - - IF NOT vAgencyModeFk OR vAgencyModeFk IS NULL THEN - SELECT agencyModeFk INTO vAgencyModeFk - FROM address - WHERE clientFk = vClientId AND isDefaultAddress; - END IF; - - CALL vn.zone_getShippedWarehouse(vlanded, vAddressFk, vAgencyModeFk); - - SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetShipped - WHERE shipped = vShipped AND warehouseFk = vWarehouseFk LIMIT 1; - - INSERT INTO vn2008.Tickets ( - Id_Cliente, - Fecha, - Id_Consigna, - Id_Agencia, - Alias, - warehouse_id, - Id_Ruta, - empresa_id, - landing, - zoneFk - ) - SELECT - vClientId, - vShipped, - a.id, - IF(vAgencyModeFk, vAgencyModeFk, a.agencyModeFk), - a.nickname, - vWarehouseFk, - IF(vRouteFk,vRouteFk,NULL), - vCompanyFk, - vlanded, - vZoneFk - FROM address a - JOIN agencyMode am ON am.id = a.agencyModeFk - WHERE a.id = vAddressFk; - - 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.id = vAddressFk; - - -- CALL logAddWithUser(vNewTicket, vUserId, 'insert', 'ticket', CONCAT('Ha creado el ticket', ' ', vNewTicket)); - INSERT INTO vn.ticketLog - SET originFk = vNewTicket, userFk = vUserId, `action` = 'insert', description = CONCAT('Ha creado el ticket:', ' ', vNewTicket); - - IF (SELECT ct.isCreatedAsServed FROM vn.clientType ct JOIN vn.client c ON c.typeFk = ct.code WHERE c.id = vClientId ) <> FALSE 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 `ticketCreateWithUser` */; -/*!50003 SET @saved_cs_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 `ticketCreateWithUser`( vClientId INT ,vShipped DATE @@ -72284,7 +73045,7 @@ CREATE DEFINER=`root`@`%` PROCEDURE `ticketCreateWithUser`( ,vUserId INT ,OUT vNewTicket INT) BEGIN - +-- si se modifica algo avisad a jgallego DECLARE vZoneFk INT; DECLARE vPrice DECIMAL(10,2); DECLARE vBonus DECIMAL(10,2); @@ -72503,7 +73264,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 `ticketFilter` */; +/*!50003 DROP PROCEDURE IF EXISTS `ticketFilter__` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -72513,7 +73274,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `ticketFilter`() +CREATE DEFINER=`root`@`%` PROCEDURE `ticketFilter__`() BEGIN /** * Obtiene un listado de tickets @@ -73728,6 +74489,39 @@ BEGIN SELECT TRUE AS IsUpdated; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticketStateToday_setOnchecking` */; +/*!50003 SET @saved_cs_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 `ticketStateToday_setOnchecking`(vParamFk INT) +BEGIN + + DECLARE vAlertLevel INT; + + SELECT s.alertLevel INTO vAlertLevel + FROM vn.state s + JOIN vn.ticketStateToday tst ON tst.state = s.id + WHERE tst.ticket = vParamFk + LIMIT 1; + + IF vAlertLevel < 2 THEN + + CALL vn.ticketStateUpdate(vParamFk, 'ON_CHECKING'); + + END IF; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -74296,6 +75090,110 @@ 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 `ticket_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 `ticket_add`( + vClientId INT + ,vShipped DATE + ,vWarehouseFk INT + ,vCompanyFk INT + ,vAddressFk INT + ,vAgencyModeFk INT + ,vRouteFk INT + ,vlanded DATE + ,vUserId INT + ,vIsRequiredZone INT + ,OUT vNewTicket INT) +BEGIN + + DECLARE vZoneFk INT; + DECLARE vPrice DECIMAL(10,2); + DECLARE vBonus DECIMAL(10,2); + + IF vClientId IS NULL THEN + CALL util.throw ('CLIENT_NOT_ESPECIFIED'); + END IF; + + IF NOT vAddressFk OR vAddressFk IS NULL THEN + SELECT id INTO vAddressFk + FROM address + WHERE clientFk = vClientId AND isDefaultAddress; + END IF; + + IF vAgencyModeFk IS NOT NULL THEN + + CALL vn.zone_getShipped (vlanded, vAddressFk, vAgencyModeFk, TRUE); + + SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus + FROM tmp.zoneGetShipped + WHERE shipped = vShipped AND warehouseFk = vWarehouseFk LIMIT 1; + + IF (vZoneFk IS NULL OR vZoneFk = 0) AND vIsRequiredZone THEN + CALL util.throw ('NOT_ZONE_WITH_THIS_PARAMETERS'); + END IF; + END IF; + INSERT INTO ticket ( + clientFk, + shipped, + addressFk, + agencyModeFk, + nickname, + warehouseFk, + routeFk, + companyFk, + landed, + zoneFk, + zonePrice, + zoneBonus + ) + SELECT + vClientId, + vShipped, + a.id, + vAgencyModeFk, + a.nickname, + vWarehouseFk, + IF(vRouteFk,vRouteFk,NULL), + vCompanyFk, + vlanded, + vZoneFk, + vPrice, + vBonus + FROM address a + JOIN agencyMode am ON am.id = a.agencyModeFk + WHERE a.id = vAddressFk; + + 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.id = vAddressFk; + + INSERT INTO vn.ticketLog + SET originFk = vNewTicket, userFk = vUserId, `action` = 'insert', description = CONCAT('Ha creado el ticket:', ' ', vNewTicket); + + IF (SELECT ct.isCreatedAsServed FROM vn.clientType ct JOIN vn.client c ON c.typeFk = ct.code WHERE c.id = vClientId ) <> FALSE THEN + INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) + SELECT id, vNewTicket, account.myUser_getId() + 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 `ticket_administrativeCopy` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74322,6 +75220,53 @@ BEGIN FROM vn.sale s WHERE s.ticketFk = vOriginalTicket; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_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_changeClient` */; +/*!50003 SET @saved_cs_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_changeClient`(vNewClient INT, vUserFk INT) +BEGIN + +/** + * Dado un conjunto de tickets + * cambia el cliente al nuevo cliente dado + * + * params @vNewClient nuevo cliente + * params @vUserFk usuario que realiza el cambio + * + * table @tmp.ticket(ticketFk) conjunto de tickets + */ + + INSERT INTO ticketLog (originFk, userFk, `action`, changedModel, oldInstance, newInstance) + SELECT t.id, vUserFk, 'update', 'Ticket', CONCAT('{"clientFk":',t.clientFk,'}'), CONCAT('{"clientFk":',vNewClient,'}') + FROM ticket t + JOIN tmp.ticket tt + ON t.id = tt.ticketFk; + + UPDATE ticket t + JOIN tmp.ticket tt + ON t.id = tt.ticketFk + SET t.clientFk = vNewClient; + + UPDATE ticket t + JOIN tmp.ticket tt + ON t.id = tt.ticketFk + JOIN stowaway s + ON s.shipFk = tt.ticketFk + SET t.clientFk = vNewClient; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -74418,7 +75363,12 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `ticket_Clone`(vOriginalTicket INT, OUT vNewTicket INT) BEGIN - +/** + * Clona el contenido de un ticket en otro + * + * @param vOriginalTicket ticket Original + * @param vNewTicket ticket creado + */ DECLARE vStateFk INT; INSERT INTO ticket ( @@ -74466,6 +75416,10 @@ BEGIN INSERT INTO ticketLog SET originFk = vNewTicket, userFk = account.myUser_getId(), `action` = 'insert', description = CONCAT('Ha creado el ticket:', ' ', vNewTicket, ' clonando el ', vOriginalTicket); + + INSERT INTO ticketLog + SET originFk = vOriginalTicket, userFk = account.myUser_getId(), `action` = 'insert', + description = CONCAT('Ha creado el ticket:', ' ', vNewTicket, ' clonando el ', vOriginalTicket); INSERT INTO vncontrol.inter(Id_Ticket, state_id, Id_Trabajador, odbc_date) SELECT vNewTicket, state_id, Id_Trabajador , odbc_date @@ -74482,14 +75436,167 @@ 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 character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET 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_cloneWeekly`(IN vWeek INT) BEGIN + DECLARE vIsDone BOOL; + DECLARE vLanding DATE; + DECLARE vShipment DATE; + DECLARE vWarehouseFk INT; + DECLARE vTicketFk INT; + DECLARE vWeekDay INT; + DECLARE vClientFk INT; + DECLARE vCompanyFk INT; + DECLARE vAddressFk INT; + DECLARE vAgencyModeFk INT; + DECLARE vNewTicket INT; + DECLARE vYear INT; + + DECLARE rsTicket CURSOR FOR + SELECT tt.ticketFk, tt.weekDay, t.clientFk, t.warehouseFk, t.companyFk, t.addressFk, tt.agencyModeFk + FROM vn.ticketWeekly tt + JOIN vn.ticket t ON tt.ticketFk = t.id; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE; + + SET vYear = YEAR(CURDATE()) + IF(vWeek < WEEK(CURDATE()),1, 0); + + OPEN rsTicket; + myLoop: LOOP + BEGIN + DECLARE vSalesPersonEmail VARCHAR(150); + DECLARE vMailSent BOOL; + DECLARE vSubject VARCHAR(150); + DECLARE vMessage TEXT; + + SET vIsDone = FALSE; + FETCH rsTicket INTO vTicketFk, vWeekDay, vClientFk, vWarehouseFk, vCompanyFk, vAddressFk, vAgencyModeFk; + + IF vIsDone THEN + + LEAVE myLoop; + END IF; + SELECT dated INTO vShipment + FROM `time` + WHERE `year` = vYear AND `week` = vWeek + AND WEEKDAY(dated) = vWeekDay; + + -- busca si el ticket ya ha sido clonado + IF (SELECT COUNT(*) FROM vn.ticket tOrig + JOIN vn.sale saleOrig ON tOrig.id = saleOrig.ticketFk + JOIN vn.saleCloned sc ON sc.saleOriginalFk = saleOrig.id + JOIN vn.sale saleClon ON saleClon.id = sc.saleClonedFk + JOIN vn.ticket tClon ON tClon.id = saleClon.ticketFk + WHERE tOrig.id = vTicketFk AND tClon.isDeleted = FALSE AND DATE(tClon.shipped) = vShipment) > 0 + THEN + ITERATE myLoop; + END IF; + + IF vAgencyModeFk IS NULL THEN + SELECT agencyModeFk INTO vAgencyModeFk + FROM address + WHERE clientFk = vClientFk AND isDefaultAddress; + END IF; + + CALL vn.zone_getLanded(vShipment, vAddressFk, vAgencyModeFk, vWarehouseFk,FALSE); + SET vLanding = NULL; + SELECT landed INTO vLanding from tmp.zoneGetLanded LIMIT 1; + + CALL ticket_add( + vClientFk, + vShipment, + vWarehouseFk, + vCompanyFk, + vAddressFk, + vAgencyModeFk, + NULL, + vLanding, + account.userGetId(), + FALSE, + vNewTicket); + + IF (vLanding IS NULL) THEN + + SELECT e.email INTO vSalesPersonEmail + FROM vn.client c + JOIN vn.worker sp ON sp.id = c.salesPersonFk + JOIN account.emailUser e ON e.userFk = sp.userFk + WHERE c.id = vClientFk; + + SET vSubject = CONCAT('Turnos - No se ha podido clonar correctamente el ticket ', vTicketFk, + ' para el dia: ', vShipment); + SET vMessage = CONCAT('No se ha podido clonar el ticket ', vTicketFk, + ' para el dia: ', vShipment, + ' porque no hay una zona de envío disponible. Se ha creado el ticket: ', vNewTicket, + ' pero ha que revisar las fechas y la agencia'); + + SELECT COUNT(*) INTO vMailSent + FROM vn.mail + WHERE sender = vSalesPersonEmail + AND subject = vSubject; + + IF NOT vMailSent THEN + INSERT INTO vn.mail (`sender`,`subject`,`body`) + VALUES (vSalesPersonEmail, vSubject, vMessage); + END IF; + CALL vn.ticketStateUpdate (vNewTicket, 'FIXING'); + END IF; + + INSERT INTO vn.sale (ticketFk, itemFk, concept, quantity, price, discount, priceFixed, isPriceFixed) + SELECT vNewTicket, saleOrig.itemFk , saleOrig.concept , saleOrig.quantity, saleOrig.price , saleOrig.discount, saleOrig.priceFixed, saleOrig.isPriceFixed + FROM vn.sale saleOrig + WHERE saleOrig.ticketFk = vTicketFk; + + INSERT IGNORE INTO vn.saleCloned(saleOriginalFk, saleClonedFk) + SELECT saleOriginal.id, saleClon.id + FROM vn.sale saleOriginal + JOIN vn.sale saleClon ON saleOriginal.itemFk = saleClon.itemFk AND saleOriginal.quantity = saleClon.quantity + WHERE saleOriginal.ticketFk = vTicketFk AND saleClon.ticketFk = vNewTicket; + + INSERT INTO ticketRequest (description,ordered,shipped,salesPersonCode,buyerCode,quantity,price,itemFk,clientFk,response, + total,buyed,saleFk) + SELECT o.description,o.ordered,vShipment,o.salesPersonCode,o.buyerCode,o.quantity,o.price,o.itemFk,o.clientFk,o.response, + o.total,o.buyed,s2.id + FROM sale s JOIN ticketRequest o ON o.saleFk = s.id + JOIN sale s2 ON s.concept = s2.concept AND s.quantity = s2.quantity AND s.itemFk = s2.itemFk + WHERE s.ticketFk = vTicketFk AND s2.ticketFk = vNewTicket; + + INSERT INTO ticketObservation(ticketFk,observationTypeFk,description) VALUES(vNewTicket,4,CONCAT('turno desde ticket: ',vTicketFk)) + ON DUPLICATE KEY UPDATE description = CONCAT(ticketObservation.description,VALUES(description),' '); + + INSERT INTO ticketObservation(ticketFk,observationTypeFk,description) VALUES(vNewTicket,1,'ATENCION: Contiene lineas de TURNO') + ON DUPLICATE KEY UPDATE description = CONCAT(ticketObservation.description,VALUES(description),' '); + + CALL vn.ticketCalculateClon(vNewTicket, vTicketFk); + END; + END LOOP; + + CLOSE rsTicket; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_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_cloneWeekly__` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET 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_cloneWeekly__`(IN vWeek INT) +BEGIN + -- si se modifica algo avisad a jgallego DECLARE vIsDone BOOL; DECLARE vLanding DATE; DECLARE vShipment DATE; @@ -74616,145 +75723,6 @@ BEGIN CLOSE rsTicket; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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_cloneWeekly__` */; -/*!50003 SET @saved_cs_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_cloneWeekly__`(IN vWeek INT) -BEGIN - DECLARE vIsDone BOOL; - DECLARE vLanding DATE; - DECLARE vShipment DATE; - DECLARE vWarehouse INT; - DECLARE vTicket INT; - DECLARE vWeekDay INT; - DECLARE vClient INT; - DECLARE vEmpresa INT; - DECLARE vAddressFk INT; - DECLARE vAgencyModeFk INT; - DECLARE vNewTicket INT; - DECLARE vYear INT; - - DECLARE rsTicket CURSOR FOR - SELECT tw.ticketFk, weekDay, t.clientFk, t.warehouseFk, t.companyFk, t.addressFk, tw.agencyModeFk - FROM ticketWeekly tw - JOIN ticket t ON tt.ticketFk = t.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE; - - SET vYear = YEAR(CURDATE()) + IF(vWeek < WEEK(CURDATE()),1, 0); - - OPEN rsTicket; - - myLoop: LOOP - BEGIN - DECLARE vError TEXT; - DECLARE vSalesPersonEmail VARCHAR(150); - DECLARE vMailSent BOOL; - DECLARE vSubject VARCHAR(150); - DECLARE vMessage TEXT; - DECLARE CONTINUE HANDLER FOR SQLEXCEPTION - BEGIN - GET DIAGNOSTICS CONDITION 1 - vError = MESSAGE_TEXT; - END; - - SET vIsDone = FALSE; - FETCH rsTicket INTO vTicket, vWeekDay, vClient, vWarehouse, vEmpresa, vAddressFk, vAgencyModeFk; - - IF vIsDone THEN - - LEAVE myLoop; - END IF; - SELECT date INTO vShipment - FROM `time` - WHERE `year` = vYear AND `week` = vWeek - AND WEEKDAY(date) = vWeekDay; - - -- busca si el ticket ya ha sido clonado - IF (SELECT COUNT(*) FROM vn.ticket tOrig - JOIN vn.sale saleOrig ON tOrig.id = saleOrig.ticketFk - JOIN vn.saleCloned sc ON sc.saleOriginalFk = saleOrig.id - JOIN vn.sale saleClon ON saleClon.id = sc.saleClonedFk - JOIN vn.ticket tClon ON tClon.id = saleClon.ticketFk - WHERE tOrig.id = vTicket AND DATE(tClon.shipped) = vShipment) > 0 - THEN - ITERATE myLoop; - END IF; - CALL vn.zone_getLanded(vShipment, vAddressFk, vAgencyModeFk, vWarehouse, TRUE); - - SELECT landed INTO vLanding from tmp.zoneGetLanded LIMIT 1; - - CALL vn.ticketCreateWithoutZone(vClient, vShipment, vWarehouse, vEmpresa, vAddressFk, vAgencyModeFk, NULL, vLanding, account.userGetId(), vNewTicket); - - IF (vLanding IS NULL) THEN - - SELECT e.email INTO vSalesPersonEmail - FROM vn.client c - JOIN vn.worker sp ON sp.id = c.salesPersonFk - JOIN account.emailUser e ON e.userFk = sp.userFk - WHERE c.id = vClient; - - SET vSubject = CONCAT('Turnos - No se ha podido clonar correctamente el ticket ', vTicket, - ' para el dia: ', vShipment); - SET vMessage = CONCAT('No se ha podido clonar el ticket ', vTicket, - ' para el dia: ', vShipment, - ' porque no hay una zona de envío disponible. Se ha creado el ticket: ', vNewTicket, - ' pero ha que revisar las fechas y la agencia'); - - SELECT COUNT(*) INTO vMailSent - FROM vn.mail - WHERE sender = vSalesPersonEmail - AND subject = vSubject; - - IF NOT vMailSent THEN - INSERT INTO vn.mail (sender,`subject`,body) - VALUES (vSalesPersonEmail, vSubject, vMessage); - END IF; - CALL vn.ticketStateUpdate (vNewTicket, 'FIXING'); - END IF; - - INSERT INTO vn.sale (ticketFk, itemFk, concept, quantity, price, discount, priceFixed, isPriceFixed) - SELECT vNewTicket, saleOrig.itemFk , saleOrig.concept , saleOrig.quantity, saleOrig.price , saleOrig.discount, saleOrig.priceFixed, saleOrig.isPriceFixed - FROM vn.ticket tOrig - JOIN vn.sale saleOrig ON tOrig.id = saleOrig.ticketFk - LEFT JOIN vn.saleCloned sc ON sc.saleOriginalFk = saleOrig.id - LEFT JOIN vn.sale saleClon ON saleClon.id = sc.saleClonedFk - LEFT JOIN vn.ticket tClon ON tClon.id = saleClon.ticketFk AND DATE(tClon.shipped) = vShipment - WHERE tOrig.id = vTicket AND saleClon.id IS NULL; - - INSERT IGNORE INTO vn.saleCloned(saleOriginalFk, saleClonedFk) - SELECT saleOriginal.id, saleClon.id - FROM vn.sale saleOriginal - JOIN vn.sale saleClon ON saleOriginal.itemFk = saleClon.itemFk AND saleOriginal.quantity = saleClon.quantity - WHERE saleOriginal.ticketFk = vTicket AND saleClon.ticketFk = vNewTicket; - - INSERT INTO ticketRequest (description, ordered, shipped, salesPersonCode, buyerCode, quantity, price, - itemFk ,clientFk, response, total, buyed, saleFk) - SELECT tr.description, tr.ordered, tr.shipped, tr.salesPersonCode, tr.buyerCode, tr.quantity, tr.price, - tr.itemFk, tr.clientFk, tr.response, tr.total, tr.buyed, tr.saleFk - FROM sale s JOIN ticketRequest tr ON tr.saleFk = s.id - JOIN sale s2 ON s.concept = s2.concept AND s.quantity = s2.quantity AND m.Id_Article = m2.Id_Article - WHERE s.ticketFk = vTicket AND s2.ticketFk = vNewTicket; - - CALL vn.ticketCalculateClon(vNewTicket, vTicket); - END; - END LOOP; - - CLOSE rsTicket; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -74880,8 +75848,9 @@ BEGIN END LOOP; CLOSE cur; - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -75068,41 +76037,33 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `ticket_componentMakeUpdate`(IN vTicketFk INT, IN vClientFk INT, IN vAgencyModeFk INT, +CREATE DEFINER=`root`@`%` PROCEDURE `ticket_componentMakeUpdate`(IN vTicketFk INT, IN vClientFk INT, + IN vNickname VARCHAR(50), IN vAgencyModeFk INT, IN vAddressFk INT, IN vZoneFk INT, IN vWarehouseFk TINYINT, IN vCompanyFk SMALLINT, IN vShipped DATETIME, IN vLanded DATE, IN vIsDeleted TINYINT(1), IN vHasToBeUnrouted TINYINT(1), IN vOption INT) BEGIN + /** - * Hay una versión en salix que machacará toda esta función/procedimiento avisa - * a carlosjr de los cambios que quieres hacer. - */ + * Modifica en el ticket los campos que se le pasan por parámetro + * y cambia sus componentes + * + * @param vTicketFk Id del ticket a modificar + * @param vClientFk nuevo cliente + * @param vNickname nuevo alias + * @param vAgencyModeFk nueva agencia + * @param vAddressFk nuevo consignatario + * @param vZoneFk nueva zona + * @param vWarehouseFk nuevo almacen + * @param vCompanyFk nueva empresa + * @param vShipped nueva fecha del envio de mercancia + * @param vLanded nueva fecha de recepcion de mercancia + * @param vIsDeleted si se borra el ticket + * @param vHasToBeUnrouted si se le elimina la ruta al ticket + * @param vOption opcion para el case del proc ticketComponentUpdateSale + */ - - - - - - -/** - * Modifica en el ticket los campos que se le pasan por parámetro - * y cambia sus componentes. - * Este procedimiento es transacionado en Salix - * - * @param vTicketFk Id del ticket a modificar - * @param vClientFk nuevo cliente - * @param vAgencyModeFk nueva agencia - * @param vAddressFk nuevo consignatario - * @param vZoneFk nueva zona - * @param vWarehouseFk nuevo almacen - * @param vCompanyFk nueva empresa - * @param vShipped nueva fecha del envio de mercancia - * @param vLanded nueva fecha de recepcion de mercancia - * @param vIsDeleted si se borra el ticket - * @param vHasToBeUnrouted si se le elimina la ruta al ticket - * @param vOption opcion para el case del proc ticketComponentUpdateSale - */ DECLARE vPrice DECIMAL(10,2); DECLARE vBonus DECIMAL(10,2); @@ -75117,7 +76078,7 @@ BEGIN END IF; - CALL zone_getShippedWarehouse(vlanded, vAddressFk, vAgencyModeFk); + CALL zone_getShipped(vLanded, vAddressFk, vAgencyModeFk, TRUE); SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus FROM tmp.zoneGetShipped @@ -75126,6 +76087,7 @@ BEGIN UPDATE ticket t SET t.clientFk = vClientFk, + t.nickname = vNickname, t.agencyModeFk = vAgencyModeFk, t.addressFk = vAddressFk, t.zoneFk = vZoneFk, @@ -77450,9 +78412,9 @@ 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 ;; @@ -77468,9 +78430,9 @@ BEGIN e.id Id_Entrada, e.REF Referencia, CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * - vn.item_getVolume(b.itemFk ,b.packageFk)) / vc.carro / 1000000 ,1) AS DECIMAL(10,2)) AS CC, + vn.item_getVolume(b.itemFk ,b.packageFk)) / vc.trolleyM3 / 1000000 ,1) AS DECIMAL(10,2)) AS CC, CAST(ROUND(SUM(GREATEST(b.stickers ,b.quantity /b.packing ) * - vn.item_getVolume(b.itemFk ,b.packageFk)) / vc.espai / 1000000,1) AS DECIMAL(10,2)) AS espais + vn.item_getVolume(b.itemFk ,b.packageFk)) / vc.palletM3 / 1000000,1) AS DECIMAL(10,2)) AS espais FROM vn.buy b JOIN vn.entry e ON e.id = b.entryFk JOIN vn.supplier s ON s.id = e.supplierFk @@ -77561,7 +78523,163 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `travel_cloneWithEntries`(IN vTravelFk INT, IN vDateStart DATE, IN vDateEnd DATE, +CREATE DEFINER=`root`@`%` PROCEDURE `travel_cloneWithEntries`( + IN vTravelFk INT, + IN vDateStart DATE, + IN vDateEnd DATE, + IN vWarehouseOutFk INT, + IN vWarehouseInFk INT, + IN vRef VARCHAR(255), + IN vAgencyModeFk INT, + OUT vNewTravelFk INT) +BEGIN +/** + * Clona un travel junto con sus entradas y compras + * + * @param vTravelFk travel plantilla a clonar + * @param vDateStart fecha del shipment del nuevo travel + * @param vDateEnd fecha del landing del nuevo travel + * @param vWarehouseOutFk fecha del salida del nuevo travel + * @param vWarehouseInFk warehouse de landing del nuevo travel + * @param vRef referencia del nuevo travel + * @param vAgencyModeFk del nuevo travel + * @param vNewTravelFk id del nuevo travel + */ + DECLARE vEntryNew INT; + DECLARE vDone BOOLEAN DEFAULT FALSE; + DECLARE vAuxEntryFk INT; + DECLARE vRsEntry CURSOR FOR + SELECT e.id + FROM entry e + JOIN travel t + ON t.id = e.travelFk + WHERE e.travelFk = vTravelFk; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION/*, 1062 Duplicate key*/ + BEGIN + ROLLBACK; + + END; + + START TRANSACTION; + INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyFk, `ref`, isDelivered, isReceived, m3, kg) + SELECT vDateStart, vDateEnd, vWarehouseInFk, vWarehouseOutFk, vAgencyModeFk, vRef, isDelivered, isReceived, m3, kg + FROM travel + WHERE id = vTravelFk; + + SET vNewTravelFk = LAST_INSERT_ID(); + CALL logAdd(vNewTravelFk, 'insert', 'travel', CONCAT('clona travel ',vTravelFk)); + SET vDone = FALSE; + SET @isModeInventory = TRUE; + OPEN vRsEntry ; + FETCH vRsEntry INTO vAuxEntryFk; + + WHILE NOT vDone DO + INSERT INTO entry ( + supplierFk, + ref, + isInventory, + isConfirmed, + isOrdered, + isRaid, + commission, + created, + evaNotes, + travelFk, + currencyFk, + companyFk, + gestDocFk, + invoiceInFk) + SELECT supplierFk, + ref, + isInventory, + isConfirmed, + isOrdered, + isRaid, + commission, + created, + evaNotes, + vNewTravelFk, + currencyFk, + companyFk, + gestDocFk, + invoiceInFk + FROM entry + WHERE id = vAuxEntryFk; + + SET vEntryNew = LAST_INSERT_ID(); + + CALL logAdd(vEntryNew, 'insert', 'entry', CONCAT('clona entrada ',vAuxEntryFk)); + INSERT INTO buy ( + entryFk, + itemFk, + quantity, + buyingValue, + packageFk, + stickers, + freightValue, + packageValue, + comissionValue, + packing, + `grouping`, + groupingMode, + location, + price1, + price2, + price3, + minPrice, + producer, + printedStickers, + isChecked, + weight) + SELECT vEntryNew, + itemFk, + quantity, + buyingValue, + packageFk, + stickers, + freightValue, + packageValue, + comissionValue, + packing, + `grouping`, + groupingMode, + location, + price1, + price2, + price3, + minPrice, + producer, + printedStickers, + isChecked, + weight + FROM buy + WHERE entryFk = vAuxEntryFk; + + FETCH vRsEntry INTO vAuxEntryFk; + END WHILE; + SET @isModeInventory = FALSE; + CLOSE vRsEntry; + 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 `travel_cloneWithEntries__` */; +/*!50003 SET @saved_cs_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 `travel_cloneWithEntries__`(IN vTravelFk INT, IN vDateStart DATE, IN vDateEnd DATE, IN vRef VARCHAR(255), OUT vNewTravelFk INT) BEGIN DECLARE vEntryNew INT; @@ -77785,6 +78903,82 @@ DELIMITER ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `travel_weeklyClone`(vSinceWeek INT, vToWeek INT) +BEGIN +/** + * Clona los travels plantilla para las semanas pasadas por parámetros + * + * @param vSinceWeek Numero de semanas en el futuro para empezar a clonar + * @param vToWeek Número de semenas en el futuro hasta donde clonar + */ + + DECLARE vCounter INT; + DECLARE vCurrentTravelFk INT; + DECLARE vShipped DATE; + DECLARE vLanded DATE; + DECLARE vWarehouseInFk INT; + DECLARE vWarehouseOutFk INT; + DECLARE vAgencyModeFk INT; + DECLARE vRef VARCHAR(255); + DECLARE vDone BOOLEAN DEFAULT FALSE; + DECLARE vRsTravel CURSOR FOR + SELECT travelFk, + @a := TIMESTAMPADD(DAY,vCounter * 7 - WEEKDAY(CURDATE()) - 1 + weekDay,CURDATE()), + @a := TIMESTAMPADD(DAY,duration,@a), + warehouseOutFk, + warehouseInFk, + `ref`, + agencyModeFk + FROM travel_cloneWeekly + WHERE travelFk; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + SET vCounter = vSinceWeek; + vWeekLoop :LOOP + INSERT IGNORE INTO travel (shipped, landed, warehouseOutFk, warehouseInFk, agencyFk, ref, cargoSupplierFk, kg) + SELECT @a := TIMESTAMPADD(DAY, vCounter * 7 - WEEKDAY(CURDATE()) - 1 + weekDay,CURDATE()), + @a := TIMESTAMPADD(DAY, duration, @a), + warehouseOutFk, + warehouseInFk, + agencyModeFk, + ref, + cargoSupplierFk, + kg + FROM travel_cloneWeekly + WHERE travelFk IS NULL; + OPEN vRsTravel; + FETCH vRsTravel INTO vCurrentTravelFk, vShipped, vLanded, vWarehouseOutFk, vWarehouseInFk, vRef, vAgencyModeFk; + SET vDone = FALSE; + WHILE NOT vDone DO + CALL travel_cloneWithEntries(vCurrentTravelFk, vShipped, vLanded, vWarehouseOutFk, vWarehouseInFk, vRef, vAgencyModeFk, @newTravel); + FETCH vRsTravel INTO vCurrentTravelFk, vShipped, vLanded, vWarehouseOutFk, vWarehouseInFk, vRef, vAgencyModeFk; + END WHILE; + CLOSE vRsTravel; + + IF vCounter = vToWeek THEN + LEAVE vWeekLoop; + END IF; + SET vCounter = vCounter + 1; + + END LOOP vWeekLoop; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `travel_weeklyClone__` */; +/*!50003 SET @saved_cs_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 `travel_weeklyClone__`(vSinceWeek INT, vToWeek INT) BEGIN DECLARE vCounter INT; @@ -77811,42 +79005,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 `travel_weeklyClone__` */; -/*!50003 SET @saved_cs_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 `travel_weeklyClone__`(vSinceWeek INT, vToWeek INT) -BEGIN - DECLARE vCounter INT; - - SET vCounter = vSinceWeek; - vWeekLoop :LOOP - INSERT IGNORE INTO travel (shipped, landed, warehouseOutFk, warehouseInFk, agencyFk, ref, cargoSupplierFk) - SELECT @a := TIMESTAMPADD(DAY,vCounter * 7 - WEEKDAY(CURDATE()) - 1 + weekDay,CURDATE()), - @a := TIMESTAMPADD(DAY,duration,@a), - warehouseOutFk, - warehouseInFk, - agencyModeFk, - ref, - cargoSupplierFk - FROM travel_cloneWeekly; - IF vCounter = vToWeek THEN - LEAVE vWeekLoop; - END IF; - SET vCounter = vCounter + 1; - 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 `typeTagMake` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -77859,7 +79017,13 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `typeTagMake`(vTypeFk INT) BEGIN - +/* + * Plantilla para modificar reemplazar todos los tags + * por los valores que tienen los articulos + * + * @param vTypeFk tipo a modificar + * + */ DELETE it.* FROM itemTag it JOIN item i ON i.id = it.itemFk @@ -77928,6 +79092,34 @@ BEGIN UPDATE vn.item SET upToDown = 0 WHERE item.id = vItemFk; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `vehicleWarehouseTimeControl_getHistorical` */; +/*!50003 SET @saved_cs_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 `vehicleWarehouseTimeControl_getHistorical`(vNumberPLate VARCHAR(20), vWorkerFk INT) +BEGIN +/** + * Obtiene historial de la matrícula del trabajador, si es jefe de producción muestra el historial completo. +*/ + + SELECT timed,workerFk,IF (direction="out","Salida","Entrada") direction + FROM vn.vehicleWarehouseTimeControl vwt + JOIN vn.vehicleWarehouse vw ON vw.numberPlate=vNumberPLate + WHERE vwt.vehicleWarehouseFk =vw.id + AND vwt.workerFk = IF(account.userHasRole(account.user_getNameFromId(vWorkerFk), 'productionAssi'), vwt.workerFk, vWorkerFk); + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -78899,6 +80091,45 @@ 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 `workerShelving_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 = 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 `workerShelving_Add`(vWorkerFk INT, vBarcode VARCHAR(12)) +BEGIN +/* + * Inserta en workerShelving asociando los carros al trabajador + * @Param vWorkerFk es id del trabajador + * @Param vBarcode se puede pasar tanto el smarttag como el shelving + */ + DECLARE vIsShelvingFk BOOL; + + SELECT COUNT(*) > 0 INTO vIsShelvingFk + FROM vn.shelving s + WHERE s.code = vBarcode COLLATE utf8_general_ci; + + IF NOT vIsShelvingFk THEN + + SELECT st.shelvingFk INTO vBarcode + FROM vn.smartTag st + WHERE st.code = vBarcode COLLATE utf8_general_ci; + + END IF; + + INSERT INTO vn.workerShelving (workerFk, shelvingFk) + VALUES(vWorkerFk, vBarcode); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControlAdd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -79943,6 +81174,7 @@ BEGIN FETCH vCursor INTO vSender, vWorkerFk, vDated, vTimeWorkDecimal, vTimeWorkSexagesimal, vTimeTable, vTimeWorkedDecimal, vTimeWorkedSexagesimal, vAbsenceType, vBusinessFk, vPermissionRate, vIsTeleworking ; SET vWorkerFkOld = vWorkerFk ; SET vSenderOld = vSender; + SET vIsTeleworkingOld = vIsTeleworking; proc: LOOP IF vDone THEN LEAVE proc; @@ -80090,8 +81322,8 @@ proc: LOOP SET vBody = ''; SET vTimeWorkDecimalTotal = 0; - SET vWorkerFkOld = vWorkerFk ; - SET vIsTeleworkingOld = vIsTeleworking ; + SET vWorkerFkOld = vWorkerFk; + SET vIsTeleworkingOld = vIsTeleworking; SET vSenderOld = vSender; END IF; END LOOP; @@ -81223,7 +82455,7 @@ BEGIN r.kmEnd-r.kmStart km, r.m3 m3Delivery, CAST(r.m3/loadWorker AS DECIMAL(10,2)) m3Load, - CAST(rc.m3Distribution*m3 AS DECIMAL(10,2)) amountDelivery, + CAST(rc.m3Distribution*r.m3 AS DECIMAL(10,2)) amountDelivery, CASE loadWorker WHEN 1 THEN CAST(r.m3/ loadWorker*rc.load1m3 AS DECIMAL(10,2)) WHEN 2 THEN CAST(r.m3/ loadWorker*rc.load2m3 AS DECIMAL(10,2)) @@ -81232,12 +82464,13 @@ BEGIN WHEN 5 THEN CAST(r.m3/ loadWorker*rc.load5m3 AS DECIMAL(10,2)) ELSE CAST(r.m3/ loadWorker*rc.load6m3 AS DECIMAL(10,2)) END amountLoad, - rc.kmRate*(r.kmEnd-r.kmStart) amountKm, + IF(v.isKmTruckRate, rc.kmTruckRate, rc.kmRate)*(r.kmEnd-r.kmStart) amountKm, CAST('' AS CHAR(45)) description, CAST( 0 AS DECIMAL(10,2)) extra, - CAST( 0 AS DECIMAL(10,2)) maxSalary - FROM ticket t - LEFT JOIN route r ON t.routeFk = r.id + CAST( 0 AS DECIMAL(10,2)) maxSalary + FROM route r + LEFT JOIN ticket t ON t.routeFk = r.id + LEFT JOIN vehicle v ON v.id = r.vehicleFk LEFT JOIN worker w ON w.id = r.workerFk LEFT JOIN routeConfig rc ON TRUE LEFT JOIN (SELECT rw.routeFk, COUNT(rw.workerFk) loadWorker @@ -81307,7 +82540,7 @@ BEGIN THEN CAST(((12 * blp.importepactado) / (52 * tb.hoursWeek)) * 4 AS DECIMAL(10,2)) WHEN tb.type = 'Vacaciones' OR tb.type = 'Baja enfermedad común' OR tb.type = 'Permiso retribuido' OR tb.type = 'Festivo' THEN CAST(((12 * blp.importepactado) / (52 * tb.hoursWeek)) * 8 AS DECIMAL(10,2)) - WHEN tb.type = 'Maternidad/Paternidad' + WHEN tb.type = 'Maternidad/Paternidad' THEN 0 END FROM worker w @@ -81316,7 +82549,7 @@ BEGIN JOIN time tm ON tm.dated = tb.dated WHERE tb.dated BETWEEN vDateFrom AND vDateTo AND w.id = vWorkerFk AND - tb.type IN ('Vacaciones 1/2 día', 'Vacaciones', 'Baja enfermedad común','Festivo','Permiso retribuido 1/2 día','Permiso retribuido', 'Maternidad/Paternidad') + tb.type IN ('Vacaciones 1/2 día', 'Vacaciones', 'Baja enfermedad común','Festivo','Permiso retribuido 1/2 día','Permiso retribuido', 'Maternidad/Paternidad') GROUP BY tb.dated; INSERT INTO tmp.workerSalaryRoleDelivery (workerFk, @@ -81429,7 +82662,7 @@ BEGIN dated, description, extra, - maxSalary) + maxSalary) SELECT wdc.workerFk , CONCAT(YEAR(t.dated),'-', MONTH(t.dated),'-01') , CASE @@ -81444,7 +82677,7 @@ BEGIN WHEN wdc.category = 2 THEN CAST(rc.plusCategory2 AS DECIMAL (10,2)) END, - CASE + CASE WHEN wdc.category = 1 THEN CAST(rc.maxSalaryCategory1 AS DECIMAL (10,2)) WHEN wdc.category = 2 @@ -81714,6 +82947,280 @@ 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 `worker_calculateSalaryRoleDelivery___` */; +/*!50003 SET @saved_cs_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 `worker_calculateSalaryRoleDelivery___`(vWorkerFk INTEGER,vDateFrom DATE,vDateTo DATE) +BEGIN +/** + * Calcula el salario de trabajadores para los departamentos de reparto, paletizado + * + * @param vDateFrom + * @param vDateTo + * @param vWorkerFk + * @return tmp.workerSalaryRoleDelivery + */ + DROP TEMPORARY TABLE IF EXISTS tmp.workerSalaryRoleDelivery; + + CREATE TEMPORARY TABLE tmp.workerSalaryRoleDelivery + SELECT w.id workerFk, + r.created dated, + r.id, + SUM(t.packages) packages, + CAST(time_to_sec(TIMEDIFF( DATE_FORMAT(r.finished, '%H:%i:%s'),DATE_FORMAT(r.time, '%H:%i:%s'))) / (60 * 60) AS DECIMAL(10, 1)) hours , + r.kmEnd-r.kmStart km, + r.m3 m3Delivery, + CAST(r.m3/loadWorker AS DECIMAL(10,2)) m3Load, + CAST(rc.m3Distribution*m3 AS DECIMAL(10,2)) amountDelivery, + CASE loadWorker + WHEN 1 THEN CAST(r.m3/ loadWorker*rc.load1m3 AS DECIMAL(10,2)) + WHEN 2 THEN CAST(r.m3/ loadWorker*rc.load2m3 AS DECIMAL(10,2)) + WHEN 3 THEN CAST(r.m3/ loadWorker*rc.load3m3 AS DECIMAL(10,2)) + WHEN 4 THEN CAST(r.m3/ loadWorker*rc.load4m3 AS DECIMAL(10,2)) + WHEN 5 THEN CAST(r.m3/ loadWorker*rc.load5m3 AS DECIMAL(10,2)) + ELSE CAST(r.m3/ loadWorker*rc.load6m3 AS DECIMAL(10,2)) + END amountLoad, + rc.kmRate*(r.kmEnd-r.kmStart) amountKm, + CAST('' AS CHAR(45)) description, + CAST( 0 AS DECIMAL(10,2)) extra, + CAST( 0 AS DECIMAL(10,2)) maxSalary + FROM ticket t + LEFT JOIN route r ON t.routeFk = r.id + LEFT JOIN worker w ON w.id = r.workerFk + LEFT JOIN routeConfig rc ON TRUE + LEFT JOIN (SELECT rw.routeFk, COUNT(rw.workerFk) loadWorker + FROM routeLoadWorker rw + JOIN routeLoadWorker rw2 ON rw.routeFk = rw2.routeFk AND rw2.workerFk = vWorkerFk + GROUP BY rw2.routeFk + ) sub ON sub.routeFk=r.id + WHERE r.created BETWEEN vDateFrom AND vDateTo AND w.id = vWorkerFk + GROUP BY r.id; + + INSERT INTO tmp.workerSalaryRoleDelivery (workerFk, + dated, + id, + packages, + km, + m3Load, + amountLoad) + SELECT w.id , + r.created , + r.id, + SUM(t.packages) , + r.kmEnd-r.kmStart , + CAST(r.m3/loadWorker AS DECIMAL(10,2)) , + CASE loadWorker + WHEN 1 THEN CAST(r.m3/ loadWorker*rc.load1m3 AS DECIMAL(10,2)) + WHEN 2 THEN CAST(r.m3/ loadWorker*rc.load2m3 AS DECIMAL(10,2)) + WHEN 3 THEN CAST(r.m3/ loadWorker*rc.load3m3 AS DECIMAL(10,2)) + WHEN 4 THEN CAST(r.m3/ loadWorker*rc.load4m3 AS DECIMAL(10,2)) + WHEN 5 THEN CAST(r.m3/ loadWorker*rc.load5m3 AS DECIMAL(10,2)) + ELSE CAST(r.m3/ loadWorker*rc.load6m3 AS DECIMAL(10,2)) + END + FROM (SELECT rw.routeFk, COUNT(rw.workerFk) loadWorker + FROM routeLoadWorker rw + JOIN routeLoadWorker rw2 ON rw.routeFk = rw2.routeFk AND rw2.workerFk = vWorkerFk + GROUP BY rw2.routeFk) sub + LEFT JOIN route r ON sub.routeFk = r.id + LEFT JOIN ticket t ON t.routeFk = r.id + LEFT JOIN worker w ON w.id = r.workerFk + LEFT JOIN routeConfig rc ON TRUE + WHERE r.created BETWEEN vDateFrom AND vDateTo AND w.id <> vWorkerFk + GROUP BY r.id; + + INSERT INTO tmp.workerSalaryRoleDelivery(workerFk, + dated, + description, + extra) + SELECT workerFk, + dated, + GROUP_CONCAT(ra.name) , + CAST(SUM(rc.price) AS DECIMAL(9,2)) + FROM routeComplement rc + JOIN routeAction ra ON rc.routeActionFk=ra.id + WHERE dated BETWEEN vDateFrom AND vDateTo AND workerFk=vWorkerFk + GROUP BY dated; + + CALL timeBusiness_calculateByWorker(vWorkerFk, vDateFrom, vDateTo); + + INSERT INTO tmp.workerSalaryRoleDelivery (workerFk, + dated, + description, + extra) + SELECT w.id, + tb.dated, + tb.type COLLATE utf8_general_ci, + CASE + WHEN tb.type = 'Vacaciones 1/2 día' OR tb.type = 'Permiso retribuido 1/2 día' + THEN CAST(((12 * blp.importepactado) / (52 * tb.hoursWeek)) * 4 AS DECIMAL(10,2)) + WHEN tb.type = 'Vacaciones' OR tb.type = 'Baja enfermedad común' OR tb.type = 'Permiso retribuido' OR tb.type = 'Festivo' + THEN CAST(((12 * blp.importepactado) / (52 * tb.hoursWeek)) * 8 AS DECIMAL(10,2)) + WHEN tb.type = 'Maternidad/Paternidad' + THEN 0 + END + FROM worker w + JOIN tmp.timeBusinessCalculate tb ON tb.userFk = w.id + JOIN postgresql.business_labour_payroll blp ON blp.business_id = tb.businessFk + JOIN time tm ON tm.dated = tb.dated + WHERE tb.dated BETWEEN vDateFrom AND vDateTo AND + w.id = vWorkerFk AND + tb.type IN ('Vacaciones 1/2 día', 'Vacaciones', 'Baja enfermedad común','Festivo','Permiso retribuido 1/2 día','Permiso retribuido', 'Maternidad/Paternidad') + GROUP BY tb.dated; + + INSERT INTO tmp.workerSalaryRoleDelivery (workerFk, + dated, + m3Delivery, + amountLoad, + description) + SELECT wdc.workerFk , + r.created, + SUM(r.m3) , + CASE + WHEN wdc.category = 1 + THEN CAST(SUM(r.m3) * rc.distributionM3Category1 AS DECIMAL (10,2)) + WHEN wdc.category = 2 + THEN CAST(SUM(r.m3) * rc.distributionM3Category2 AS DECIMAL (10,2)) + END amountLoad, + 'Gestión de la distribución' description + FROM route r + JOIN agencyMode am ON am.id= r.agencyModeFk + JOIN agency a ON a.id = am.agencyFk + JOIN workerDistributionCategory wdc ON wdc.workerFk = vWorkerFk + JOIN workerLabour wl ON r.created BETWEEN wl.started AND IFNULL(wl.ended, CURDATE()) AND wl.workerFk = wdc.workerFk AND a.workCenterFk = wl.workCenterFk + JOIN department v ON v.id = departmentFk + JOIN routeConfig rc + WHERE r.m3>0 AND created BETWEEN vDateFrom AND vDateTo AND + am.name NOT LIKE "REC_%" AND + v.name= "REPARTO" + GROUP BY r.created; + + INSERT INTO tmp.workerSalaryRoleDelivery (workerFk, + dated, + m3Delivery, + amountLoad, + description) + SELECT sub.workerFk, + r.created, + SUM(r.m3), + CAST( (SUM(r.m3)*sub.percentage /100) * rc.m3Palletization AS DECIMAL (10,2) ), + 'Gestión de paletizado' + FROM route r + JOIN agencyMode am ON am.id= r.agencyModeFk + JOIN agency a ON a.id = am.agencyFk + JOIN (SELECT percentage,workerFk ,dated + FROM routeUserPercentage ru + WHERE workerFk = vWorkerFk AND ru.dated <= vDateTo + ORDER BY dated DESC LIMIT 1 + ) sub + JOIN routeConfig rc + JOIN workerLabour wl ON r.created BETWEEN wl.started AND IFNULL(wl.ended, CURDATE()) AND + wl.workerFk = sub.workerFk + JOIN department v ON v.id = departmentFk + WHERE r.m3>0 AND + r.created BETWEEN vDateFrom AND vDateTo AND + am.name NOT LIKE "REC_%" AND + v.name= "PALETIZADO" + GROUP BY r.created; + + DROP TEMPORARY TABLE IF EXISTS tmp.daysToRateHoliday; + CREATE TEMPORARY TABLE tmp.daysToRateHoliday + SELECT * + FROM tmp.workerSalaryRoleDelivery tb + WHERE (tb.description IN ('Festivo') OR dayofweek(tb.dated)=1) AND tb.extra = 0 ; + + INSERT INTO tmp.workerSalaryRoleDelivery (workerFk,dated,id,packages,hours,km,m3Delivery,m3Load,amountDelivery,amountLoad,AmountKm,description, extra) + SELECT workerFk, + dated, + d.id, + packages, + hours, + km, + m3Delivery, + m3Load, + amountDelivery * r.rateHoliday, + amountLoad * r.rateHoliday, + AmountKm * r.rateHoliday, + CONCAT('Plus festivo: ',description), + extra + FROM tmp.daysToRateHoliday d + LEFT JOIN routeConfig r ON TRUE; + + DROP TEMPORARY TABLE IF EXISTS tmp.daysToDelete; + CREATE TEMPORARY TABLE tmp.daysToDelete + SELECT dated + FROM tmp.workerSalaryRoleDelivery d + WHERE d.description IN ('Baja enfermedad común', 'Maternidad/Paternidad'); + + DELETE d + FROM tmp.workerSalaryRoleDelivery d + JOIN tmp.daysToDelete dd on dd.dated = d.dated + WHERE d.description NOT IN ('Baja enfermedad común', 'Maternidad/Paternidad'); + + INSERT INTO tmp.workerSalaryRoleDelivery (workerFk,dated,id,packages,hours,km,m3Delivery,m3Load,amountDelivery,amountLoad,AmountKm,description, extra) + SELECT workerFk, + dated, + d.id, + packages, + hours, + km, + m3Delivery, + m3Load, + amountDelivery * r.rateHoliday, + amountLoad * r.rateHoliday, + AmountKm * r.rateHoliday, + CONCAT('Plus festivo: ', description), + extra + FROM tmp.daysToRateHoliday d + LEFT JOIN routeConfig r ON TRUE; + + INSERT INTO tmp.workerSalaryRoleDelivery (workerFk, + dated, + description, + extra, + maxSalary) + SELECT wdc.workerFk , + CONCAT(YEAR(t.dated),'-', MONTH(t.dated),'-01') , + CASE + WHEN wdc.category = 1 + THEN rc.plusCategory1Concept + WHEN wdc.category = 2 + THEN rc.plusCategory2Concept + END, + CASE + WHEN wdc.category = 1 + THEN CAST(rc.plusCategory1 AS DECIMAL (10,2)) + WHEN wdc.category = 2 + THEN CAST(rc.plusCategory2 AS DECIMAL (10,2)) + END, + CASE + WHEN wdc.category = 1 + THEN CAST(rc.maxSalaryCategory1 AS DECIMAL (10,2)) + WHEN wdc.category = 2 + THEN CAST(rc.maxSalaryCategory2 AS DECIMAL (10,2)) + END + FROM worker w + JOIN workerDistributionCategory wdc ON wdc.workerFk = w.id + JOIN routeConfig rc + JOIN time t on t.dated BETWEEN vDateFrom AND vDateTo + WHERE w.id = vWorkerFk + GROUP BY MONTH(t.dated), YEAR(t.dated); + + DROP TEMPORARY TABLE tmp.daysToRateHoliday; + DROP TEMPORARY TABLE tmp.daysToDelete; + DROP TEMPORARY TABLE tmp.timeBusinessCalculate; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `worker_getHierarchy` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -81828,7 +83335,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 `worker_getProductionErrors` */; +/*!50003 DROP PROCEDURE IF EXISTS `worker_getProductionerrors` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -81838,7 +83345,81 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `worker_getProductionErrors`(vDepartment VARCHAR(25), vStateCode VARCHAR(25) CHARSET utf8, vDatedFrom DATETIME, vDatedTo DATETIME) +CREATE DEFINER=`root`@`%` PROCEDURE `worker_getProductionerrors`(vAction VARCHAR(25), vDepartment VARCHAR(25), vStateCode VARCHAR(25) CHARSET utf8, vDatedFrom DATETIME, vDatedTo DATETIME) +BEGIN + + DROP TEMPORARY TABLE IF EXISTS tmp.total; + + IF (vDepartment = 'Encajadores') + THEN + CREATE TEMPORARY TABLE tmp.total + ENGINE = MEMORY + SELECT e.workerFk, Count(DISTINCT t.id) AS ticketCount + FROM expedition e + JOIN ticket t ON e.ticketFk = t.id + WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo + GROUP BY e.workerFk; + ELSE + CREATE TEMPORARY TABLE tmp.total + ENGINE = MEMORY + SELECT st.workerFk, Count(DISTINCT t.id) AS ticketCount + FROM state ss + JOIN vn.saleTracking st ON st.stateFk = ss.id + JOIN vn.sale s ON s.id = st.saleFk + JOIN ticket t ON s.ticketFk = t.id + WHERE (t.shipped BETWEEN vDatedFrom AND vDatedTo) AND ss.code = vStateCode + GROUP BY st.workerFk; + END IF; + + SELECT sub1.id, sub1.firstName, sub1.lastName, CAST(sub1.totalTickets AS DECIMAL(10,0)) AS totalTickets, CAST(IFNULL(sub1.errors,0) + IFNULL(sub2.errors,0) AS DECIMAL(10,0)) AS errors + FROM( + SELECT w.id, w.code, w.firstName, w.lastName, t.ticketCount AS totalTickets, sub.errors + FROM tmp.total AS t + JOIN worker w ON w.id = t.workerFk + LEFT JOIN ( + SELECT COUNT(c.ticketFk) AS errors, cd.workerFk + FROM claimDevelopment cd + JOIN claim c ON cd.claimFk = c.id + JOIN ticket t ON c.ticketFk = t.id + JOIN claimResponsible cr ON cd.claimResponsibleFk = cr.id + WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo AND cr.description = vDepartment + GROUP BY cd.workerFk + )sub ON t.workerFk = sub.workerFk + GROUP BY w.code) sub1 + LEFT JOIN( + SELECT sub1.workerFk, COUNT(id) AS errors + FROM ( + SELECT st.workerFk, t.id + FROM vn.saleMistake sm + JOIN vn.saleTracking st ON sm.saleFk = st.saleFk + JOIN state ss ON ss.id = st.stateFk + JOIN vncontrol.accion a ON a.accion_id = st.actionFk + JOIN vn.sale s ON s.id = sm.saleFk + JOIN vn.ticket t on t.id = s.ticketFk + WHERE (t.shipped BETWEEN vDatedFrom AND vDatedTo) AND a.accion = vAction AND ss.code = vStateCode + GROUP BY s.ticketFk + ) sub1 + GROUP BY sub1.workerFk) sub2 ON sub2.workerFk = sub1.id; + + DROP TEMPORARY TABLE tmp.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 `worker_getProductionErrors__` */; +/*!50003 SET @saved_cs_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 `worker_getProductionErrors__`(vDepartment VARCHAR(25), vStateCode VARCHAR(25) CHARSET utf8, vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.total; @@ -81884,51 +83465,8 @@ 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 `worker_getProductionErrors__` */; -/*!50003 SET @saved_cs_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 `worker_getProductionErrors__`(vDepartment VARCHAR(25), vStateCode VARCHAR(25) CHARSET utf8, vDatedFrom DATETIME, vDatedTo DATETIME) -BEGIN - -DROP TEMPORARY TABLE IF EXISTS tmp.total; - CREATE TEMPORARY TABLE tmp.total - ENGINE = MEMORY - SELECT tt.workerFk, Count(tt.ticketFk) AS CuentaDeId_Ticket - FROM state s - INNER JOIN ticketTracking tt ON s.id = tt.stateFk - INNER JOIN ticket t ON tt.ticketFk = t.id - INNER JOIN worker w ON tt.workerFk = w.id - WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo AND s.code = vStateCode - GROUP BY tt.workerFk; - -SELECT w.code, w.firstName, w.lastName, CAST(tmp.total.CuentaDeId_Ticket AS DECIMAL(10,0)) AS Totaltickets, - CAST(sub.CuentaDeId_Ticket AS DECIMAL(10,0)) AS Fallos -fROM tmp.total - JOIN worker w ON w.id= tmp.total.workerFk -LEFT JOIN ( SELECT Count(s.ticketFk) AS CuentaDeId_Ticket, cd.workerFk - FROM (claimDevelopment cd - INNER JOIN ((sale s - INNER JOIN claimBeginning cb ON s.id = cb.saleFk) - INNER JOIN ticket t ON s.ticketFk = t.id) ON cd.claimFk = cb.claimFk) - INNER JOIN claimResponsible cr ON cd.claimResponsibleFk = cr.id - WHERE t.shipped BETwEEN vDatedFrom AND vDatedTo AND cr.description=vDepartment - GROUP BY cd.workerFk)sub ON tmp.total.workerFk = sub.workerFk; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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 ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -81957,9 +83495,9 @@ DELIMITER ; /*!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 utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `workingHoursTimeIn` */; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -81979,9 +83517,9 @@ DELIMITER ; /*!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 utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `workingHoursTimeOut` */; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_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 */ ; @@ -82003,7 +83541,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 */ ; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +ALTER DATABASE `vn` CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `wrongEqualizatedClient` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -82144,7 +83682,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 `zoneClosure_recalc_beta` */; +/*!50003 DROP PROCEDURE IF EXISTS `zoneClosure_recalc_beta__` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -82154,7 +83692,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `zoneClosure_recalc_beta`() +CREATE DEFINER=`root`@`%` PROCEDURE `zoneClosure_recalc_beta__`() proc: BEGIN /** * Recalculates the delivery time (hour) for every zone in days + scope in future @@ -82475,205 +84013,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 `zoneGetAgency__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetAgency__`(vAddress INT, vLanded 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 - * @select Listado de agencias disponibles - */ - - CALL zone_getAgency(vAddress,vLanded); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `zoneGetLanded__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetLanded__`(vShipped DATE, vAddressFk INT, vAgencyModeFk INT, vWarehouseFk INT) -BEGIN -/** -* JGF procedimiento TEMPORAL -* ATENCION hablad conmigo si queréis cambiar algo de aquí -* Devuelve una tabla temporal con el dia de recepcion para vShipped. -* -* @param vShipped Fecha de preparacion de mercancia -* @param vAddressFk Id de consignatario, %NULL para recogida -* @param vAgencyModeFk Id agencia -* @param vWarehouseFk vWarehouseFk -* @table tmp.zoneGetLanded Datos de recepción -*/ - - CALL zone_getFromGeo(address_getGeo(vAddressFk)); - CALL zone_getOptionsForShipment(vShipped, FALSE); - - DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded; - CREATE TEMPORARY TABLE tmp.zoneGetLanded - ENGINE = MEMORY - SELECT vWarehouseFk warehouseFk, - TIMESTAMPADD(DAY,zo.travelingDays, vShipped) landed, - zo.zoneFk - FROM tmp.zoneOption zo - JOIN zone z ON z.id = zo.zoneFk - JOIN zoneWarehouse zw ON zw.zoneFk = z.id - WHERE agencyModeFk = vAgencyModeFk - AND zw.warehouseFk = vWarehouseFk; - - DROP TEMPORARY TABLE - tmp.zone, - tmp.zoneOption; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `zoneGetShippedWarehouse__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetShippedWarehouse__`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT) -BEGIN -/** - * Devuelve la mínima fecha de envío para cada warehouse - * - * @param vLanded La fecha de recepcion - * @param vAddressFk Id del consignatario - * @param vAgencyModeFk Id de la agencia - * @return tmp.zoneGetShipped - */ - CALL zone_getShippedWarehouse(vLanded, vAddressFk, 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 `zoneGetShipped__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetShipped__`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT, vWarehouseFk INT) -BEGIN -/** - * OBSOLETO usar zone_getShippedWarehouse - * Devuelve la mínima fecha de envía para cada warehouse - * - * @param vLanded La fecha de recepcion - * @param vAddressFk Id del consignatario - * @param vAgencyModeFk Id de la agencia - * @return tmp.zoneGetShipped - */ - CALL zone_getShippedWarehouse(vLanded, vAddressFk, vAgencyModeFk); - - SELECT * FROM tmp.zoneGetShipped WHERE warehouseFk <> vWarehouseFk; - DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `zoneGetWarehouse__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetWarehouse__`(vAddress INT, vLanded DATE, vWarehouse INT) -BEGIN -/** -* Devuelve el listado de agencias disponibles para la fecha, - * dirección y warehouse pasadas - * - * @param vAddress - * @param vWarehouse warehouse - * @param vLanded Fecha de recogida - * @select Listado de agencias disponibles - */ - - DECLARE vGeoFk INT; - - SELECT p.geoFk INTO vGeoFk - FROM address a - JOIN town t ON t.provinceFk = a.provinceFk - JOIN postCode p ON p.townFk = t.id AND p.code = a.postalCode - WHERE a.id = vAddress - ORDER BY (a.city SOUNDS LIKE t.`name`) DESC - LIMIT 1; - - - SELECT * FROM ( - SELECT * FROM ( - SELECT am.id agencyModeFk, - am.name agencyMode, - am.description, - am.deliveryMethodFk, - TIMESTAMPADD(DAY,-z.travelingDays, vLanded) shipped, - z.warehouseFk, - zi.isIncluded, - z.id zoneFk - FROM zoneGeo zgSon - JOIN zoneGeo zgFather ON zgSon.lft BETWEEN zgFather.lft AND zgFather.rgt - JOIN zoneIncluded zi ON zi.geoFk = zgFather.id - JOIN zone z ON z.id = zi.zoneFk - JOIN zoneCalendar zc ON zc.zoneFk = z.id - JOIN agencyMode am ON am.id = z.agencyModeFk - WHERE zgSon.`id` = vGeoFk - AND delivered = vLanded - AND z.warehouseFk = vWarehouse - AND IF(TIMESTAMPADD(DAY,-z.travelingDays, vLanded) = CURDATE(), hour(now()) < hour(z.`hour`),TRUE) - ORDER BY z.id, zgFather.depth DESC) t - GROUP BY zoneFk - HAVING isIncluded > 0) t - GROUP BY agencyModeFk; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `zonePromo_Make` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -82876,6 +84215,114 @@ 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 `zone_getCollisions` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `zone_getCollisions`() +BEGIN +/** + * Calcula si para un mismo codigo postal y dia + * hay mas de una zona configurada + * + */ + DECLARE vGeoFk INT DEFAULT NULL; + DECLARE vZoneFk INT; + DECLARE vIsDone INT DEFAULT FALSE; + DECLARE cur1 CURSOR FOR SELECT zoneFk from tmp.zoneOption; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE; + + DROP TEMPORARY TABLE IF EXISTS tmp.zone; + CREATE TEMPORARY TABLE tmp.zone + SELECT z.id + FROM zone z + JOIN agencyMode am ON am.id = z.agencyModeFk + JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk + WHERE dm.code IN ('AGENCY','DELIVERY'); + + CALL zone_getOptionsForShipment(CURDATE(),FALSE); + + DROP TEMPORARY TABLE IF EXISTS tmp.zoneNodes; + CREATE TEMPORARY TABLE tmp.zoneNodes ( + geoFk INT, + name VARCHAR(100), + parentFk INT, + sons INT, + isChecked BOOL DEFAULT 0, + zoneFk INT, + PRIMARY KEY zoneFkk (zoneFk, geoFk)) + ENGINE = MEMORY; + + OPEN cur1; + cur1Loop: LOOP + SET vIsDone = FALSE; + FETCH cur1 INTO vZoneFk; + IF vIsDone THEN + LEAVE cur1Loop; + END IF; + + CALL zone_getLeaves2(vZoneFk, NULL, NULL); + + myLoop: LOOP + SET vGeoFk = NULL; + SELECT geoFk INTO vGeoFk + FROM tmp.zoneNodes zn + WHERE NOT isChecked + LIMIT 1; + + IF vGeoFk IS NULL THEN + LEAVE myLoop; + END IF; + + CALL zone_getLeaves2(vZoneFk, vGeoFk, NULL); + UPDATE tmp.zoneNodes + SET isChecked = TRUE + WHERE geoFk = vGeoFk; + END LOOP; + + END LOOP; + CLOSE cur1; + DELETE FROM tmp.zoneNodes + WHERE sons > 0; + + DROP TEMPORARY TABLE IF EXISTS geoCollision; + CREATE TEMPORARY TABLE geoCollision + SELECT z.agencyModeFk, zn.geoFk + FROM tmp.zoneNodes zn + JOIN zone z ON z.id = zn.zoneFk + GROUP BY z.agencyModeFk, zn.geoFk + HAVING count(*) > 1; + + SELECT zn.name postalCode, + zoneFk, + z.price, + z.name, + CONCAT('https://salix.verdnatura.es/#!/zone/', + zoneFk, + '/location?q=%7B%22search%22:%22', + zn.name, + '%22%7D') salix + FROM tmp.zoneNodes zn + JOIN zone z ON z.id = zn.zoneFk + JOIN geoCollision gc ON gc.agencyModeFk = z.agencyModeFk AND zn.geoFk = gc.geoFk; + + DROP TEMPORARY TABLE + geoCollision, + tmp.zone, + tmp.zoneNodes; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getEvents` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -82949,66 +84396,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 `zone_getEvents__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `zone_getEvents__`( - vProvinceFk INT, - vPostCode VARCHAR(255), - vAgencyModeFk INT) -BEGIN -/** - * Returns available events for the passed province/postcode and agency. - * - * @param vAgencyModeFk The agency mode id - * @param vProvinceFk The province id - * @param vPostCode The postcode or %NULL to use the province - */ - - DECLARE vGeoFk INT; - - IF vPostCode IS NOT NULL THEN - SELECT p.geoFk INTO vGeoFk - FROM postCode p - JOIN town t ON t.id = p.townFk - WHERE p.`code` = vPostCode - AND t.provinceFk = vProvinceFk; - ELSE - SELECT geoFk INTO vGeoFk - FROM province - WHERE id = vProvinceFk; - END IF; - - CALL zone_getFromGeo(vGeoFk); - - IF vAgencyModeFk IS NOT NULL THEN - DELETE t FROM tmp.zone t - JOIN zone z ON z.id = t.id - WHERE z.agencyModeFk != vAgencyModeFk; - END IF; - - SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays - FROM tmp.zone t - JOIN zoneEvent e ON e.zoneFk = t.id; - - SELECT e.zoneFk, e.dated - FROM tmp.zone t - JOIN zoneExclusion e ON e.zoneFk = t.id; - - DROP TEMPORARY TABLE tmp.zone; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getFromGeo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -83223,6 +84610,222 @@ 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 `zone_getLeaves2` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `zone_getLeaves2`( + vSelf INT, + vParentFk INT, + vSearch VARCHAR(255) +) +BEGIN +/** + * HAY QUE REFACTORIZAR ESTE Y zone_getLeaves + * https://redmine.verdnatura.es/issues/3073 + * Devuelve los geoFk incluidos en la ruta y que sean hijos de parentFk + * @param vSelf Id de la zona + * @param vParentFk Id del geo a calcular + * @param vSearch cadena a buscar + * + * @return tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) + * + */ + DECLARE vIsNumber BOOL; + DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch != ''; + + DROP TEMPORARY TABLE IF EXISTS tNodes; + CREATE TEMPORARY TABLE tNodes + (UNIQUE (id)) + ENGINE = MEMORY + SELECT id FROM zoneGeo LIMIT 0; + + IF vIsSearch THEN + SET vIsNumber = vSearch REGEXP '^[0-9]+$'; + + INSERT INTO tNodes + SELECT id FROM zoneGeo + WHERE (vIsNumber AND `name` = vSearch) + OR (!vIsNumber AND `name` LIKE CONCAT('%', vSearch, '%')) + LIMIT 1000; + ELSEIF vParentFk IS NULL THEN + INSERT INTO tNodes + SELECT geoFk FROM zoneIncluded + WHERE zoneFk = vSelf; + END IF; + + IF vParentFk IS NULL THEN + DROP TEMPORARY TABLE IF EXISTS tChilds; + CREATE TEMPORARY TABLE tChilds + ENGINE = MEMORY + SELECT id FROM tNodes; + + DROP TEMPORARY TABLE IF EXISTS tParents; + CREATE TEMPORARY TABLE tParents + ENGINE = MEMORY + SELECT id FROM zoneGeo LIMIT 0; + + myLoop: LOOP + DELETE FROM tParents; + INSERT INTO tParents + SELECT parentFk id + FROM zoneGeo g + JOIN tChilds c ON c.id = g.id + WHERE g.parentFk IS NOT NULL; + + INSERT IGNORE INTO tNodes + SELECT id FROM tParents; + + IF ROW_COUNT() = 0 THEN + LEAVE myLoop; + END IF; + + DELETE FROM tChilds; + INSERT INTO tChilds + SELECT id FROM tParents; + END LOOP; + + DROP TEMPORARY TABLE + tChilds, + tParents; + END IF; + + IF !vIsSearch THEN + INSERT IGNORE INTO tNodes + SELECT id FROM zoneGeo + WHERE parentFk <=> vParentFk; + END IF; + + INSERT IGNORE INTO tmp.zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) + SELECT g.id, + g.`name`, + g.parentFk, + g.sons, + NOT g.sons OR type = 'country', + vSelf + FROM zoneGeo g + JOIN tNodes n ON n.id = g.id + LEFT JOIN zoneIncluded i + ON i.geoFk = g.id AND i.zoneFk = vSelf + WHERE (i.isIncluded = TRUE + OR (i.isIncluded IS NULL AND vParentFk IS NOT NULL)); + DROP TEMPORARY TABLE tNodes; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `zone_getLeaves___` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `zone_getLeaves___`( + vSelf INT, + vParentFk INT, + vSearch VARCHAR(255) +) +BEGIN + DECLARE vIsNumber BOOL; + DECLARE vIsSearch BOOL DEFAULT vSearch IS NOT NULL AND vSearch != ''; + + DROP TEMPORARY TABLE IF EXISTS tNodes; + CREATE TEMPORARY TABLE tNodes + (UNIQUE (id)) + ENGINE = MEMORY + SELECT id FROM zoneGeo LIMIT 0; + + IF vIsSearch THEN + SET vIsNumber = vSearch REGEXP '^[0-9]+$'; + + INSERT INTO tNodes + SELECT id FROM zoneGeo + WHERE (vIsNumber AND `name` = vSearch) + OR (!vIsNumber AND `name` LIKE CONCAT('%', vSearch, '%')) + LIMIT 1000; + ELSEIF vParentFk IS NULL THEN + INSERT INTO tNodes + SELECT geoFk FROM zoneIncluded + WHERE zoneFk = vSelf; + END IF; + + IF vParentFk IS NULL THEN + DROP TEMPORARY TABLE IF EXISTS tChilds; + CREATE TEMPORARY TABLE tChilds + ENGINE = MEMORY + SELECT id FROM tNodes; + + DROP TEMPORARY TABLE IF EXISTS tParents; + CREATE TEMPORARY TABLE tParents + ENGINE = MEMORY + SELECT id FROM zoneGeo LIMIT 0; + + myLoop: LOOP + DELETE FROM tParents; + INSERT INTO tParents + SELECT parentFk id + FROM zoneGeo g + JOIN tChilds c ON c.id = g.id + WHERE g.parentFk IS NOT NULL; + + INSERT IGNORE INTO tNodes + SELECT id FROM tParents; + + IF ROW_COUNT() = 0 THEN + LEAVE myLoop; + END IF; + + DELETE FROM tChilds; + INSERT INTO tChilds + SELECT id FROM tParents; + END LOOP; + + DROP TEMPORARY TABLE + tChilds, + tParents; + END IF; + + IF !vIsSearch THEN + INSERT IGNORE INTO tNodes + SELECT id FROM zoneGeo + WHERE parentFk <=> vParentFk; + END IF; + + + INSERT IGNORE INTO zoneNodes(geoFk, name, parentFk, sons, isChecked, zoneFk) + SELECT g.id, + g.`name`, + g.parentFk, + g.sons, + NOT g.sons OR type = 'country', + vSelf + FROM zoneGeo g + JOIN tNodes n ON n.id = g.id + LEFT JOIN zoneIncluded i + ON i.geoFk = g.id AND i.zoneFk = vSelf + WHERE (i.isIncluded = TRUE + OR (i.isIncluded IS NULL AND vParentFk IS NOT NULL)) + ; + + DROP TEMPORARY TABLE tNodes; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getOptionsForLanding` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -83297,80 +84900,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 `zone_getOptionsForLanding__` */; -/*!50003 SET @saved_cs_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 `zone_getOptionsForLanding__`(vLanded DATE) -BEGIN -/** - * Gets computed options for the passed zones and delivery date. - * - * @table tmp.zones(id) The zones ids - * @param vLanded The delivery date - * @return tmp.zoneOption The computed options - */ - DECLARE vHour TIME DEFAULT TIME(NOW()); - - DROP TEMPORARY TABLE IF EXISTS tTemp; - CREATE TEMPORARY TABLE tTemp - ENGINE = MEMORY - SELECT t.id zoneFk, - IFNULL(TIME(e.`hour`), TIME(z.`hour`)) `hour`, - IFNULL(e.travelingDays, z.travelingDays) travelingDays, - IFNULL(e.price, z.price) price, - IFNULL(e.bonus, z.bonus) bonus, - CASE - WHEN e.`type` = 'day' - THEN 1 - WHEN e.`type` = 'range' - THEN 2 - ELSE 3 - END specificity - FROM tmp.zone t - JOIN zone z ON z.id = t.id - JOIN zoneEvent e ON e.zoneFk = t.id - WHERE ( - e.`type` = 'day' - AND e.dated = vLanded - ) OR ( - e.`type` != 'day' - AND e.weekDays & (1 << WEEKDAY(vLanded)) - AND (e.`started` IS NULL OR vLanded >= e.`started`) - AND (e.`ended` IS NULL OR vLanded <= e.`ended`) - ); - - DELETE t FROM tTemp t - JOIN zoneExclusion e - ON e.zoneFk = t.zoneFk AND e.`dated` = vLanded; - - DELETE FROM tTemp - WHERE (@shipped := TIMESTAMPADD(DAY, -travelingDays, vLanded)) < CURDATE() - OR @shipped = CURDATE() AND vHour > `hour`; - - DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; - CREATE TEMPORARY TABLE tmp.zoneOption - ENGINE = MEMORY - SELECT * - FROM ( - SELECT * FROM tTemp - ORDER BY zoneFk, specificity - ) t - GROUP BY zoneFk; - - DROP TEMPORARY TABLE tTemp; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getOptionsForShipment` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -83567,97 +85096,6 @@ BEGIN -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `zone_getOptionsForShipment__` */; -/*!50003 SET @saved_cs_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 `zone_getOptionsForShipment__`(vShipped DATE, vShowExpiredZones BOOLEAN) -BEGIN -/** - * Gets computed options for the passed zones and shipping date. - * - * @table tmp.zones(id) The zones ids - * @param vShipped The shipping date - * @return tmp.zoneOption(zoneFk, hour, travelingDays, price, bonus, specificity) The computed options - */ - DECLARE vHour TIME DEFAULT TIME(NOW()); - - DROP TEMPORARY TABLE IF EXISTS tLandings; - CREATE TEMPORARY TABLE tLandings - (INDEX (eventFk)) - ENGINE = MEMORY - SELECT e.id eventFk, - @travelingDays := IFNULL(e.travelingDays, z.travelingDays) travelingDays, - TIMESTAMPADD(DAY, @travelingDays, vShipped) landed - FROM tmp.zone t - JOIN zone z ON z.id = t.id - JOIN zoneEvent e ON e.zoneFk = t.id; - - DROP TEMPORARY TABLE IF EXISTS tTemp; - CREATE TEMPORARY TABLE tTemp - ENGINE = MEMORY - SELECT t.id zoneFk, - IFNULL(TIME(e.`hour`), TIME(z.`hour`)) `hour`, - IFNULL(e.price, z.price) price, - IFNULL(e.bonus, z.bonus) bonus, - CASE - WHEN e.`type` = 'day' - THEN 1 - WHEN e.`type` = 'range' - THEN 2 - ELSE 3 - END specificity, - l.travelingDays, - l.landed - FROM tmp.zone t - JOIN zone z ON z.id = t.id - JOIN zoneEvent e ON e.zoneFk = t.id - JOIN tLandings l ON l.eventFk = e.id - WHERE ( - e.`type` = 'day' - AND e.`dated` = l.landed - ) OR ( - e.`type` != 'day' - AND e.weekDays & (1 << WEEKDAY(l.landed)) - AND (e.`started` IS NULL OR l.landed >= e.`started`) - AND (e.`ended` IS NULL OR l.landed <= e.`ended`) - ); - - DELETE t FROM tTemp t - JOIN zoneExclusion e - ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed; - - IF NOT vShowExpiredZones THEN - DELETE FROM tTemp - WHERE vShipped < CURDATE() - OR (vShipped = CURDATE() AND vHour > `hour`); - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; - CREATE TEMPORARY TABLE tmp.zoneOption - ENGINE = MEMORY - SELECT * - FROM ( - SELECT * FROM tTemp - ORDER BY zoneFk, specificity - ) t - GROUP BY zoneFk; - - DROP TEMPORARY TABLE - tTemp, - tLandings; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -83742,57 +85180,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 `zone_getShippedWarehouse__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `zone_getShippedWarehouse__`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT) -BEGIN -/** - * Devuelve la mínima fecha de envío para cada warehouse - * - * @param vLanded La fecha de recepcion - * @param vAddressFk Id del consignatario - * @param vAgencyModeFk Id de la agencia - * @return tmp.zoneGetShipped - */ - - CALL zone_getFromGeo(address_getGeo(vAddressFk)); - CALL zone_getOptionsForLanding(vLanded,TRUE); - - DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetShipped; - CREATE TEMPORARY TABLE tmp.zoneGetShipped - ENGINE = MEMORY - SELECT * FROM ( - SELECT zo.zoneFk, - TIMESTAMPADD(DAY,-zo.travelingDays, vLanded) shipped, - zo.`hour`, - zw.warehouseFk, - z.agencyModeFk, - zo.price, - zo.bonus - FROM tmp.zoneOption zo - JOIN zoneWarehouse zw ON zw.zoneFk = zo.zoneFk - JOIN zone z ON z.id = zo.zoneFk - WHERE z.agencyModeFk = vAgencyModeFk - ORDER BY shipped) t - GROUP BY warehouseFk; - - DROP TEMPORARY TABLE - tmp.zone, - tmp.zoneOption; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getWarehouse` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -83837,56 +85224,6 @@ BEGIN tmp.zone, tmp.zoneOption; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `zone_getWarehouse__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `zone_getWarehouse__`(vAddress INT, vLanded DATE, vWarehouse INT) -BEGIN -/** - * Devuelve el listado de agencias disponibles para la fecha, - * dirección y almacén pasados. - * - * @param vAddress - * @param vWarehouse warehouse - * @param vLanded Fecha de recogida - * @select Listado de agencias disponibles - */ - - CALL zone_getFromGeo(address_getGeo(vAddress)); - CALL zone_getOptionsForLanding(vLanded, FALSE); - - SELECT am.id agencyModeFk, - am.name agencyMode, - am.description, - am.deliveryMethodFk, - TIMESTAMPADD(DAY, -zo.travelingDays, vLanded) shipped, - zw.warehouseFk, - z.id zoneFk - FROM tmp.zoneOption zo - JOIN zone z ON z.id = zo.zoneFk - JOIN agencyMode am ON am.id = z.agencyModeFk - JOIN zoneWarehouse zw ON zw.zoneFk = zo.zoneFk - WHERE zw.warehouseFk - GROUP BY z.agencyModeFk - ORDER BY agencyMode; - - DROP TEMPORARY TABLE - tmp.zone, - tmp.zoneOption; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -84559,221 +85896,6 @@ USE `bs`; /*!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 TABLE IF EXISTS `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 TABLE IF EXISTS `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 `claims_ratio` --- - -/*!50001 DROP TABLE IF EXISTS `claims_ratio`*/; -/*!50001 DROP VIEW IF EXISTS `claims_ratio`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 SET character_set_results = utf8 */; -/*!50001 SET collation_connection = utf8_general_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `claims_ratio` AS select `cr`.`clientFk` AS `Id_Cliente`,`cr`.`yearSale` AS `Consumo`,`cr`.`claimAmount` AS `Reclamaciones`,`cr`.`claimingRate` AS `Ratio`,`cr`.`priceIncreasing` AS `recobro`,`cr`.`packingRate` AS `inflacion` from `vn`.`claimRatio` `cr` */; -/*!50001 SET character_set_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 TABLE IF EXISTS `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 `vn`.`company` `co` on((`co`.`id` = `cr`.`company_id`))) join `vn`.`client` `c` on((`cr`.`customer_id` = `c`.`id`))) join `vn`.`payMethod` `pm` on((`pm`.`id` = `c`.`payMethodFk`))) where (`cr`.`amount` and `co`.`isDefaulter` and `pm`.`outstandingDebt` and (`c`.`typeFk` = 'normal')) union all select `i`.`clientFk` AS `Id_Cliente`,-(round(`i`.`amount`,2)) AS `importe`,`i`.`companyFk` AS `empresa_id` from (((`vn`.`invoiceOut` `i` join `vn`.`client` `c` on((`i`.`clientFk` = `c`.`id`))) join `vn`.`company` `co` on((`co`.`id` = `i`.`companyFk`))) join `vn`.`payMethod` `pm` on((`pm`.`id` = `c`.`payMethodFk`))) where ((`i`.`issued` > (curdate() + interval -(101) day)) and ((`i`.`dued` + interval `pm`.`graceDays` day) > curdate()) and (`i`.`amount` > 0) and `co`.`isDefaulter` and `pm`.`outstandingDebt` and (`c`.`typeFk` = 'normal')) */; -/*!50001 SET character_set_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_risk` --- - -/*!50001 DROP TABLE IF EXISTS `customer_risk`*/; -/*!50001 DROP VIEW IF EXISTS `customer_risk`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 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_risk` AS select `cr`.`clientFk` AS `customer_id`,`cr`.`companyFk` AS `company_id`,`cr`.`amount` AS `amount` from `vn`.`clientRisk` `cr` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `defaulters` --- - -/*!50001 DROP TABLE IF EXISTS `defaulters`*/; -/*!50001 DROP VIEW IF EXISTS `defaulters`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 SET character_set_results = utf8 */; -/*!50001 SET collation_connection = utf8_general_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `defaulters` AS select `d`.`clientFk` AS `client`,`d`.`created` AS `date`,`d`.`amount` AS `amount`,`d`.`defaulterSinced` AS `defaulterSince`,`d`.`hasChanged` AS `hasChanged`,`d`.`frozened` AS `frozened` from `bs`.`defaulter` `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 `facturacion_media_anual` --- - -/*!50001 DROP TABLE IF EXISTS `facturacion_media_anual`*/; -/*!50001 DROP VIEW IF EXISTS `facturacion_media_anual`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 SET character_set_results = utf8 */; -/*!50001 SET collation_connection = utf8_general_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `facturacion_media_anual` AS select `cac`.`clientFk` AS `Id_Cliente`,`cac`.`invoiced` AS `Consumo` from `bs`.`clientAnnualConsumption` `cac` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `rotacion` --- - -/*!50001 DROP TABLE IF EXISTS `rotacion`*/; -/*!50001 DROP VIEW IF EXISTS `rotacion`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 SET character_set_results = utf8 */; -/*!50001 SET collation_connection = utf8_general_ci */; -/*!50001 CREATE ALGORITHM=MERGE */ -/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `rotacion` AS select `ic`.`itemFk` AS `Id_Article`,`ic`.`warehouseFk` AS `warehouse_id`,`ic`.`quantity` AS `total`,`ic`.`rotation` AS `rotacion`,`ic`.`cm3` AS `cm3`,`ic`.`storage` AS `almacenaje`,`ic`.`handling` AS `manipulacion`,`ic`.`extraCharge` AS `auxiliar`,`ic`.`wasted` AS `mermas`,`ic`.`cm3delivery` AS `cm3reparto`,`ic`.`grams` AS `grams` from `vn`.`itemCost` `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 `saleVolume__` --- - -/*!50001 DROP TABLE IF EXISTS `saleVolume__`*/; -/*!50001 DROP VIEW IF EXISTS `saleVolume__`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_general_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `saleVolume__` AS select `s`.`id` AS `saleFk`,sum((((`r`.`cm3` * `i`.`compression`) * `s`.`quantity`) / 1000000)) AS `m3` from (((`vn`.`ticket` `t` join `vn`.`sale` `s` on((`s`.`ticketFk` = `t`.`id`))) join `vn`.`item` `i` on((`i`.`id` = `s`.`itemFk`))) join `bi`.`rotacion` `r` on(((`r`.`Id_Article` = `i`.`id`) and (`r`.`warehouse_id` = `t`.`warehouseFk`)))) */; -/*!50001 SET character_set_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 TABLE IF EXISTS `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 `c`.`id` AS `Id_Componente`,`c`.`name` AS `Componente`,`c`.`typeFk` AS `tarifa_componentes_series_id`,`c`.`classRate` AS `tarifa_class`,`c`.`tax` AS `tax`,`c`.`isRenewable` AS `is_renewable`,`c`.`code` AS `code` from `vn`.`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 `tarifa_componentes_series` --- - -/*!50001 DROP TABLE IF EXISTS `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 `ct`.`id` AS `tarifa_componentes_series_id`,`ct`.`type` AS `Serie`,`ct`.`isBase` AS `base`,`ct`.`isMargin` AS `margen` from `vn`.`componentType` `ct` */; -/*!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` -- @@ -85569,6 +86691,25 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `bankPolicy` +-- + +/*!50001 DROP TABLE IF EXISTS `bankPolicy`*/; +/*!50001 DROP VIEW IF EXISTS `bankPolicy`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `bankPolicy` AS select `bp`.`poliza_id` AS `id`,`bp`.`referencia` AS `ref`,`bp`.`importe` AS `amount`,`bp`.`com_dispuesto` AS `balanceInterestDrawn`,`bp`.`com_no_dispuesto` AS `commissionAvailableBalances`,`bp`.`com_anual` AS `openingCommission`,`bp`.`apertura` AS `started`,`bp`.`cierre` AS `ended`,`bp`.`Id_Banco` AS `bankFk`,`bp`.`empresa_id` AS `companyFk`,`bp`.`supplierFk` AS `supplierFk`,`bp`.`description` AS `description`,`bp`.`hasGuarantee` AS `hasGuarantee`,`bp`.`dmsFk` AS `dmsFk`,`bp`.`notaryFk` AS `notaryFk`,`bp`.`currencyFk` AS `currencyFk`,`bp`.`amortizationTypeFk` AS `amortizationTypeFk`,`bp`.`periodicityTypeFk` AS `periodicityTypeFk`,`bp`.`insuranceExpired` AS `insuranceExpired` from `vn2008`.`Bancos_poliza` `bp` order by `bp`.`poliza_id` 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 `businessCalendar` -- @@ -85697,7 +86838,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `clientRisk__` AS select `c`.`customer_id` AS `clientFk`,`c`.`company_id` AS `companyFk`,`c`.`amount` AS `amount` from `bi`.`customer_risk` `c` */; +/*!50001 VIEW `clientRisk__` AS select `c`.`customer_id` AS `clientFk`,`c`.`company_id` AS `companyFk`,`c`.`amount` AS `amount` from `bi`.`customer_risk__` `c` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -85711,12 +86852,12 @@ USE `vn`; /*!50001 SET @saved_cs_client = @@character_set_client */; /*!50001 SET @saved_cs_results = @@character_set_results */; /*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_general_ci */; +/*!50001 SET character_set_client = utf8 */; +/*!50001 SET character_set_results = utf8 */; +/*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `cmr_list` AS select `cmr`.`id` AS `cmrFk`,`cmr`.`ticketFk` AS `ticketFk`,`cmr`.`truckPlate` AS `truckPlate`,`cmr`.`observations` AS `observations`,`cmr`.`senderInstruccions` AS `senderInstruccions`,`cmr`.`paymentInstruccions` AS `paymentInstruccions`,`cmr`.`specialAgreements` AS `specialAgreements`,`cmr`.`created` AS `created`,`cmr`.`packagesList` AS `packagesList`,`aTo`.`nickname` AS `clientName`,`aTo`.`postalCode` AS `clientPostalCode`,`aTo`.`street` AS `clientStreet`,`aTo`.`city` AS `clientCity`,`pTo`.`name` AS `clientProvince`,`cTo`.`country` AS `clientCountry`,`su`.`name` AS `companyName`,`su`.`street` AS `companyStreet`,`su`.`postCode` AS `companyPostCode`,`su`.`city` AS `companyCity`,`cSu`.`country` AS `companyCountry`,concat(`aFrom`.`street`,' ',`aFrom`.`postalCode`,' ',`aFrom`.`city`,' (',`cFrom`.`country`,')') AS `warehouseAddress`,`cmr`.`created` AS `shipped`,`aTo`.`nickname` AS `clientOficialName`,`cmr`.`supplierFk` AS `supplierFk`,`aSu`.`name` AS `carrierName`,`aSu`.`street` AS `carrierStreet`,`aSu`.`postCode` AS `carrierPostCode`,`aSu`.`city` AS `carrierCity`,`cAs`.`country` AS `carrierCountry`,ifnull(`aTo`.`phone`,`client`.`phone`) AS `phone`,ifnull(`aTo`.`mobile`,`client`.`mobile`) AS `mobile`,`aTo`.`id` AS `addressFk` from (((((((((((`cmr` left join `address` `aTo` on((`aTo`.`id` = `cmr`.`addressToFk`))) left join `province` `pTo` on((`pTo`.`id` = `aTo`.`provinceFk`))) left join `country` `cTo` on((`cTo`.`id` = `pTo`.`countryFk`))) left join `client` on((`client`.`id` = `aTo`.`clientFk`))) left join `supplier` `su` on((`su`.`id` = `cmr`.`companyFk`))) left join `country` `cSu` on((`cSu`.`id` = `su`.`countryFk`))) left join `address` `aFrom` on((`aFrom`.`id` = `cmr`.`addressFromFk`))) left join `province` `pFrom` on((`pFrom`.`id` = `aFrom`.`provinceFk`))) left join `country` `cFrom` on((`cFrom`.`id` = `pFrom`.`countryFk`))) left join `supplier` `aSu` on((`aSu`.`id` = `cmr`.`supplierFk`))) left join `country` `cAs` on((`cAs`.`id` = `aSu`.`countryFk`))) */; +/*!50001 VIEW `cmr_list` AS select `cmr`.`id` AS `cmrFk`,`cmr`.`ticketFk` AS `ticketFk`,`cmr`.`truckPlate` AS `truckPlate`,`cmr`.`observations` AS `observations`,`cmr`.`senderInstruccions` AS `senderInstruccions`,`cmr`.`paymentInstruccions` AS `paymentInstruccions`,`cmr`.`specialAgreements` AS `specialAgreements`,`cmr`.`created` AS `created`,`cmr`.`packagesList` AS `packagesList`,`aTo`.`nickname` AS `clientName`,`aTo`.`postalCode` AS `clientPostalCode`,`aTo`.`street` AS `clientStreet`,`aTo`.`city` AS `clientCity`,`pTo`.`name` AS `clientProvince`,`cTo`.`country` AS `clientCountry`,`su`.`name` AS `companyName`,`su`.`street` AS `companyStreet`,`su`.`postCode` AS `companyPostCode`,`su`.`city` AS `companyCity`,`cSu`.`country` AS `companyCountry`,concat(`aFrom`.`street`,' ',`aFrom`.`postalCode`,' ',`aFrom`.`city`,' (',`cFrom`.`country`,')') AS `warehouseAddress`,`cmr`.`created` AS `shipped`,`aTo`.`nickname` AS `clientOficialName`,`cmr`.`supplierFk` AS `supplierFk`,`aSu`.`name` AS `carrierName`,`aSu`.`street` AS `carrierStreet`,`aSu`.`postCode` AS `carrierPostCode`,`aSu`.`city` AS `carrierCity`,`cAs`.`country` AS `carrierCountry`,ifnull(`aTo`.`phone`,`client`.`phone`) AS `phone`,ifnull(`aTo`.`mobile`,`client`.`mobile`) AS `mobile`,`aTo`.`id` AS `addressFk`,`c`.`stamp` AS `stamp`,`cmr`.`merchandiseDetail` AS `merchandiseDetail` from ((((((((((((`cmr` left join `address` `aTo` on((`aTo`.`id` = `cmr`.`addressToFk`))) left join `province` `pTo` on((`pTo`.`id` = `aTo`.`provinceFk`))) left join `country` `cTo` on((`cTo`.`id` = `pTo`.`countryFk`))) left join `client` on((`client`.`id` = `aTo`.`clientFk`))) left join `supplier` `su` on((`su`.`id` = `cmr`.`companyFk`))) left join `country` `cSu` on((`cSu`.`id` = `su`.`countryFk`))) left join `address` `aFrom` on((`aFrom`.`id` = `cmr`.`addressFromFk`))) left join `province` `pFrom` on((`pFrom`.`id` = `aFrom`.`provinceFk`))) left join `country` `cFrom` on((`cFrom`.`id` = `pFrom`.`countryFk`))) left join `supplier` `aSu` on((`aSu`.`id` = `cmr`.`supplierFk`))) left join `country` `cAs` on((`cAs`.`id` = `aSu`.`countryFk`))) join `company` `c` on((`c`.`id` = `cmr`.`companyFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -85759,6 +86900,25 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `collectionSmartTag2` +-- + +/*!50001 DROP TABLE IF EXISTS `collectionSmartTag2`*/; +/*!50001 DROP VIEW IF EXISTS `collectionSmartTag2`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `collectionSmartTag2` AS select `st`.`code` AS `code`,`tc`.`ticketFk` AS `ticketFk`,`tc`.`level` AS `level`,`tc`.`wagon` AS `wagon`,`st`.`shelvingFk` AS `shelvingFk`,`tc`.`collectionFk` AS `collectionFk`,`am`.`name` AS `agencyFk`,`t`.`clientFk` AS `clientFk`,`u`.`name` AS `worker`,`t`.`shipped` AS `shipped`,`t`.`landed` AS `landed` from ((((((`vn`.`ticketCollection` `tc` join `vn`.`smartTag` `st` on((`st`.`code` = (`tc`.`smartTagFk` collate utf8_general_ci)))) join `vn`.`ticket` `t` on((`t`.`id` = `tc`.`ticketFk`))) join `vn`.`collection` `c` on((`c`.`id` = `tc`.`collectionFk`))) join `vn`.`worker` `w` on((`w`.`id` = `c`.`workerFk`))) join `vn`.`agencyMode` `am` on((`am`.`id` = `t`.`agencyModeFk`))) join `account`.`user` `u` on((`u`.`id` = `w`.`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 `componentRate__` -- @@ -85977,12 +87137,12 @@ USE `vn`; /*!50001 SET @saved_cs_client = @@character_set_client */; /*!50001 SET @saved_cs_results = @@character_set_results */; /*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 SET character_set_results = utf8 */; -/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `exchangeInsuranceOut` AS select `p`.`received` AS `received`,sum(`p`.`divisa`) AS `divisa`,(sum(`p`.`divisa`) / sum(`p`.`amount`)) AS `rate` from (`payment` `p` join `bank` `b` on((`b`.`id` = `p`.`bankFk`))) where ((`p`.`currencyFk` = 2) and (`b`.`cash` = 0) and (`p`.`supplierFk` <> 2213)) group by `p`.`received` */; +/*!50001 VIEW `exchangeInsuranceOut` AS select `p`.`received` AS `received`,sum(`p`.`divisa`) AS `divisa`,(sum(`p`.`divisa`) / sum(`p`.`amount`)) AS `rate` from ((`payment` `p` join `bank` `b` on((`b`.`id` = `p`.`bankFk`))) join `accountingType` `at2` on((`at2`.`id` = `b`.`cash`))) where ((`p`.`currencyFk` = 2) and (`at2`.`code` = 'wireTransfer') and (`p`.`supplierFk` <> 2213)) group by `p`.`received` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -86110,12 +87270,31 @@ USE `vn`; /*!50001 SET @saved_cs_client = @@character_set_client */; /*!50001 SET @saved_cs_results = @@character_set_results */; /*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 SET character_set_results = utf8 */; -/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionSticker` AS select `e`.`id` AS `expeditionFk`,`e`.`ticketFk` AS `ticketFk`,`t`.`addressFk` AS `addressFk`,`t`.`clientFk` AS `clientFk`,`a`.`street` AS `street`,`a`.`postalCode` AS `postalCode`,`a`.`city` AS `city`,`a`.`nickname` AS `nickname`,concat('R(',right(`t`.`routeFk`,4),')') AS `routeFk`,`rm`.`beachFk` AS `beachFk`,if(`t`.`routeFk`,replace(`z`.`name`,'ZONA ','Z'),`am`.`name`) AS `zona`,`p`.`name` AS `province`,ifnull(`a`.`mobile`,`a`.`phone`) AS `phone` from (((((((`expedition` `e` join `ticket` `t` on((`t`.`id` = `e`.`ticketFk`))) join `address` `a` on((`a`.`id` = `t`.`addressFk`))) join `province` `p` on((`p`.`id` = `a`.`provinceFk`))) left join `routesMonitor` `rm` on((`rm`.`routeFk` = `t`.`routeFk`))) left join `beach` `b` on((`b`.`id` = `rm`.`beachFk`))) left join `zone` `z` on((`z`.`id` = `t`.`zoneFk`))) join `agencyMode` `am` on((`t`.`agencyModeFk` = `am`.`id`))) */; +/*!50001 VIEW `expeditionSticker` AS select `e`.`id` AS `expeditionFk`,`e`.`ticketFk` AS `ticketFk`,`t`.`addressFk` AS `addressFk`,`t`.`clientFk` AS `clientFk`,`a`.`street` AS `street`,`a`.`postalCode` AS `postalCode`,`a`.`city` AS `city`,`a`.`nickname` AS `nickname`,concat('R(',convert(right(`t`.`routeFk`,4) using utf8mb4),')') AS `routeFk`,`rm`.`beachFk` AS `beachFk`,if(`t`.`routeFk`,replace(`am`.`name`,'ZONA ','Z'),`z`.`name`) AS `zona`,`p`.`name` AS `province`,ifnull(`c`.`mobile`,ifnull(`a`.`mobile`,ifnull(`c`.`phone`,`a`.`phone`))) AS `phone` from (((((((((`expedition` `e` join `ticket` `t` on((`t`.`id` = `e`.`ticketFk`))) join `address` `a` on((`a`.`id` = `t`.`addressFk`))) join `province` `p` on((`p`.`id` = `a`.`provinceFk`))) left join `routesMonitor` `rm` on((`rm`.`routeFk` = `t`.`routeFk`))) left join `beach` `b` on((`b`.`id` = `rm`.`beachFk`))) left join `zone` `z` on((`z`.`id` = `t`.`zoneFk`))) left join `route` `r` on((`r`.`id` = `t`.`routeFk`))) left join `agencyMode` `am` on((`am`.`id` = `r`.`agencyModeFk`))) join `client` `c` on((`c`.`id` = `a`.`clientFk`))) */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `expeditionSticker__` +-- + +/*!50001 DROP TABLE IF EXISTS `expeditionSticker__`*/; +/*!50001 DROP VIEW IF EXISTS `expeditionSticker__`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `expeditionSticker__` AS select `e`.`id` AS `expeditionFk`,`e`.`ticketFk` AS `ticketFk`,`t`.`addressFk` AS `addressFk`,`t`.`clientFk` AS `clientFk`,`a`.`street` AS `street`,`a`.`postalCode` AS `postalCode`,`a`.`city` AS `city`,`a`.`nickname` AS `nickname`,concat('R(',convert(right(`t`.`routeFk`,4) using utf8mb4),')') AS `routeFk`,`rm`.`beachFk` AS `beachFk`,if(`t`.`routeFk`,replace(`z`.`name`,'ZONA ','Z'),`am`.`name`) AS `zona`,`p`.`name` AS `province`,ifnull(`a`.`mobile`,`a`.`phone`) AS `phone` from (((((((`expedition` `e` join `ticket` `t` on((`t`.`id` = `e`.`ticketFk`))) join `address` `a` on((`a`.`id` = `t`.`addressFk`))) join `province` `p` on((`p`.`id` = `a`.`provinceFk`))) left join `routesMonitor` `rm` on((`rm`.`routeFk` = `t`.`routeFk`))) left join `beach` `b` on((`b`.`id` = `rm`.`beachFk`))) left join `zone` `z` on((`z`.`id` = `t`.`zoneFk`))) join `agencyMode` `am` on((`t`.`agencyModeFk` = `am`.`id`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -86595,6 +87774,25 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `itemSearch` +-- + +/*!50001 DROP TABLE IF EXISTS `itemSearch`*/; +/*!50001 DROP VIEW IF EXISTS `itemSearch`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8 */; +/*!50001 SET character_set_results = utf8 */; +/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `itemSearch` AS select `s`.`itemFk` AS `itemFk`,`s`.`concept` AS `concept`,`s`.`quantity` AS `quantity`,`t`.`nickname` AS `nickname`,`t`.`shipped` AS `shipped` from ((`sale` `s` join `ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `warehouse` `w` on((`w`.`id` = `t`.`warehouseFk`))) where ((`t`.`shipped` between `util`.`yesterday`() and `util`.`tomorrow`()) and (`w`.`name` in ('VNH','Floramondo'))) */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `itemShelvingAvailable` -- @@ -86880,6 +88078,25 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `lastPurchases` +-- + +/*!50001 DROP TABLE IF EXISTS `lastPurchases`*/; +/*!50001 DROP VIEW IF EXISTS `lastPurchases`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8 */; +/*!50001 SET character_set_results = utf8 */; +/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `lastPurchases` AS select `tr`.`landed` AS `landed`,`w`.`id` AS `warehouseFk`,`w`.`name` AS `warehouse`,`i`.`longName` AS `longName`,`i`.`subName` AS `subName`,`e`.`id` AS `entryFk`,`b`.`stickers` AS `stickers`,`b`.`packing` AS `packing`,`e`.`ref` AS `ref`,`b`.`itemFk` AS `itemFk` from ((((`buy` `b` join `entry` `e` on((`e`.`id` = `b`.`entryFk`))) join `item` `i` on((`i`.`id` = `b`.`itemFk`))) join `travel` `tr` on((`tr`.`id` = `e`.`travelFk`))) join `warehouse` `w` on((`w`.`id` = `tr`.`warehouseInFk`))) where ((`tr`.`landed` between `util`.`yesterday`() and `util`.`tomorrow`()) and (`e`.`isRaid` = 0) and (`b`.`stickers` > 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 `lastTopClaims` -- @@ -87003,12 +88220,12 @@ USE `vn`; /*!50001 SET @saved_cs_client = @@character_set_client */; /*!50001 SET @saved_cs_results = @@character_set_results */; /*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 SET character_set_results = utf8 */; -/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `packageEquivalentItem` AS select `i`.`itemFk` AS `itemFk`,`ie`.`itemFk` AS `equivalentFk` from ((`packageEquivalent` `pe` join `packaging` `i` on((`i`.`id` = `pe`.`packageFk`))) join `packaging` `ie` on((`ie`.`id` = `pe`.`equivalentFk`))) */; +/*!50001 VIEW `packageEquivalentItem` AS select `p`.`itemFk` AS `itemFk`,`p2`.`itemFk` AS `equivalentFk` from ((`packageEquivalent` `pe` join `packaging` `p` on((`p`.`id` = `pe`.`packagingFk`))) join `packaging` `p2` on((`p2`.`id` = `pe`.`equivalentFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -87402,12 +88619,12 @@ USE `vn`; /*!50001 SET @saved_cs_client = @@character_set_client */; /*!50001 SET @saved_cs_results = @@character_set_results */; /*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 SET character_set_results = utf8 */; -/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `supplierPackaging` AS select `e`.`supplierFk` AS `supplierFk`,`b`.`itemFk` AS `itemFk`,`i`.`longName` AS `longName`,`s`.`name` AS `supplier`,`b`.`entryFk` AS `entryFk`,`tr`.`landed` AS `landed`,-(least(`b`.`quantity`,0)) AS `out`,greatest(`b`.`quantity`,0) AS `in`,`w`.`name` AS `almacen` from ((((((`buy` `b` join `item` `i` on((`i`.`id` = `b`.`itemFk`))) join `packaging` `p` on((`p`.`itemFk` = `i`.`id`))) join `entry` `e` on((`e`.`id` = `b`.`entryFk`))) join `supplier` `s` on((`s`.`id` = `e`.`supplierFk`))) join `travel` `tr` on((`tr`.`id` = `e`.`travelFk`))) join `warehouse` `w` on((`w`.`id` = `tr`.`warehouseInFk`))) where `p`.`isPackageReturnable` */; +/*!50001 VIEW `supplierPackaging` AS select `e`.`supplierFk` AS `supplierFk`,`b`.`itemFk` AS `itemFk`,`i`.`longName` AS `longName`,`s`.`name` AS `supplier`,`b`.`entryFk` AS `entryFk`,`tr`.`landed` AS `landed`,-(least(`b`.`quantity`,0)) AS `out`,greatest(`b`.`quantity`,0) AS `in`,`w`.`name` AS `almacen`,`b`.`buyingValue` AS `cost` from ((((((`buy` `b` join `item` `i` on((`i`.`id` = `b`.`itemFk`))) join `packaging` `p` on((`p`.`itemFk` = `i`.`id`))) join `entry` `e` on((`e`.`id` = `b`.`entryFk`))) join `supplier` `s` on((`s`.`id` = `e`.`supplierFk`))) join `travel` `tr` on((`tr`.`id` = `e`.`travelFk`))) join `warehouse` `w` on((`w`.`id` = `tr`.`warehouseInFk`))) where `p`.`isPackageReturnable` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -87450,6 +88667,25 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `ticketLabel_Source` +-- + +/*!50001 DROP TABLE IF EXISTS `ticketLabel_Source`*/; +/*!50001 DROP VIEW IF EXISTS `ticketLabel_Source`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8 */; +/*!50001 SET character_set_results = utf8 */; +/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `ticketLabel_Source` AS select concat(`tc`.`collectionFk`,' ',`tc`.`wagon`,'-',`tc`.`level`) AS `level`,`t`.`id` AS `Id_Ticket`,(case when (`t`.`routeFk` is not null) then if(`agr`.`showAgencyName`,concat(right(left(`agr`.`name`,(locate(' ',`agr`.`name`) - 1)),2),'- R',right(`t`.`routeFk`,3)),`agr`.`name`) else if((`am`.`deliveryMethodFk` = 2),`zo`.`name`,`am`.`name`) end) AS `Agencia`,`t`.`clientFk` AS `Id_Cliente`,`t`.`notes` AS `Notas`,'CDT' AS `Sacador`,1 AS `ncarro`,if(hour(`t`.`shipped`),date_format(`t`.`shipped`,'%H:%i'),date_format(`zo`.`hour`,'%H:%i')) AS `horaagencia`,`t`.`shipped` AS `fecha`,if(((now() + interval 1 hour) > `ze`.`etc`),'!!!','') AS `urgente` from (((((((`vn`.`ticket` `t` join `vn`.`agencyMode` `am` on((`t`.`agencyModeFk` = `am`.`id`))) left join `vn`.`address` `a` on((`a`.`id` = `t`.`addressFk`))) left join `vn`.`route` `r` on((`t`.`routeFk` = `r`.`id`))) left join `vn`.`zone_ETD` `ze` on((`ze`.`zoneFk` = `t`.`zoneFk`))) left join `vn`.`ticketCollection` `tc` on((`tc`.`ticketFk` = `t`.`id`))) left join `vn`.`agencyMode` `agr` on((`r`.`agencyModeFk` = `agr`.`id`))) left join `vn`.`zone` `zo` on((`t`.`zoneFk` = `zo`.`id`))) where (`t`.`shipped` between `util`.`yesterday`() and `util`.`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 `ticketLastUpdated` -- @@ -87982,6 +89218,44 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `workerWithoutDevice` +-- + +/*!50001 DROP TABLE IF EXISTS `workerWithoutDevice`*/; +/*!50001 DROP VIEW IF EXISTS `workerWithoutDevice`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8 */; +/*!50001 SET character_set_results = utf8 */; +/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `workerWithoutDevice` AS select `c`.`workerFk` AS `workerFk`,`cl`.`name` AS `Trabajador`,count(distinct `c`.`id`) AS `Colecciones` from ((`collection` `c` join `client` `cl` on((`cl`.`id` = `c`.`workerFk`))) left join `deviceProductionUser` `dpu` on((`dpu`.`userFk` = `c`.`workerFk`))) where ((`c`.`created` > curdate()) and isnull(`dpu`.`userFk`)) group by `c`.`workerFk` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `workerWithoutTractor` +-- + +/*!50001 DROP TABLE IF EXISTS `workerWithoutTractor`*/; +/*!50001 DROP VIEW IF EXISTS `workerWithoutTractor`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `workerWithoutTractor` AS select `c`.`workerFk` AS `workerFk`,`cl`.`name` AS `Trabajador`,count(distinct `c`.`id`) AS `Colecciones`,max(`c`.`created`) AS `created` from ((`collection` `c` join `client` `cl` on((`cl`.`id` = `c`.`workerFk`))) left join `machineWorker` `mw` on(((`mw`.`workerFk` = `c`.`workerFk`) and (`mw`.`inTimed` > curdate())))) where ((`c`.`created` > curdate()) and isnull(`mw`.`workerFk`)) group by `c`.`workerFk` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `zoneEstimatedDelivery` -- @@ -88035,4 +89309,4 @@ USE `vncontrol`; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-06-22 16:15:53 +-- Dump completed on 2021-08-31 14:41:28