From 7d67ca0e8919b758907d4e9faed1341e2e2a06be Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 23 Jun 2022 12:14:16 +0200 Subject: [PATCH] DB structure & data export, DB Dockerfile version changed to 10.7.3 --- db/Dockerfile | 2 +- db/dump/dumpedFixtures.sql | 78 +- db/dump/structure.sql | 40359 +++++++++++------------------------ db/export-data.sh | 4 +- 4 files changed, 12208 insertions(+), 28235 deletions(-) diff --git a/db/Dockerfile b/db/Dockerfile index c7be72a23..cb3aa741c 100644 --- a/db/Dockerfile +++ b/db/Dockerfile @@ -1,4 +1,4 @@ -FROM mariadb:10.4.13 +FROM mariadb:10.7.3 ENV MYSQL_ROOT_PASSWORD root ENV TZ Europe/Madrid diff --git a/db/dump/dumpedFixtures.sql b/db/dump/dumpedFixtures.sql index 464933607..3bcc07d94 100644 --- a/db/dump/dumpedFixtures.sql +++ b/db/dump/dumpedFixtures.sql @@ -1,6 +1,6 @@ USE `util`; --- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.8-MariaDB, for debian-linux-gnu (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,'10450',0,'production',NULL); +INSERT INTO `config` VALUES (1,'10461',0,'production',NULL); /*!40000 ALTER TABLE `config` ENABLE KEYS */; UNLOCK TABLES; @@ -32,7 +32,7 @@ UNLOCK TABLES; LOCK TABLES `version` WRITE; /*!40000 ALTER TABLE `version` DISABLE KEYS */; -INSERT INTO `version` VALUES ('salix','10230','53f69ae8e526a4a5d827c237a5b076d38507b392','2020-11-09 11:06:43',NULL),('vn-database','10129','7ebb66d5a9e47920e2c5ebfdf373bdf9d1bd6221','2022-05-03 13:46:59','10131'); +INSERT INTO `version` VALUES ('salix','10230','53f69ae8e526a4a5d827c237a5b076d38507b392','2020-11-09 11:06:43',NULL),('vn-database','10216','19871f5aac4c06bac92a3c6e50dfc02a818e09de','2022-06-23 11:15:29','10216'); /*!40000 ALTER TABLE `version` ENABLE KEYS */; UNLOCK TABLES; @@ -42,7 +42,7 @@ UNLOCK TABLES; LOCK TABLES `versionLog` WRITE; /*!40000 ALTER TABLE `versionLog` DISABLE KEYS */; -INSERT INTO `versionLog` VALUES ('vn-database','00001','00-test.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','00003','00-sage.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','10008','00-alterRoleConfig.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','10014','00-rolePrefix.sql','jenkins@10.0.2.68','2022-02-11 00:13:25',NULL,NULL),('vn-database','10017','01-firstScript.sql','jenkins@10.0.2.70','2022-03-09 11:36:54',NULL,NULL),('vn-database','10021','00-bankAccount.sql','jenkins@10.0.2.69','2022-03-16 14:11:22',NULL,NULL),('vn-database','10023','00-firstScript.sql','jenkins@10.0.2.69','2022-03-16 15:05:29',NULL,NULL),('vn-database','10026','00-invoiceInIntrastat.sql','jenkins@10.0.2.69','2022-03-21 15:10:53',NULL,NULL),('vn-database','10027','00-Clientes_cedidos.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10028','00-item_last_buy_.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10029','00-bankToViewAccountingToTable.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10030','00-KkejarNiche.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10036','00-updateBuyConfig.sql','jenkins@10.0.2.69','2022-03-29 12:36:54',NULL,NULL),('vn-database','10037','00-firstScript.sql','jenkins@10.0.2.69','2022-03-28 11:14:26',NULL,NULL),('vn-database','10038','00-printServerQueue.sql','jenkins@10.0.2.69','2022-03-29 08:13:24',NULL,NULL),('vn-database','10048','00-firstScript.sql','jenkins@10.0.2.69','2022-03-30 12:29:06',NULL,NULL),('vn-database','10058','00-vehicleAddFields.sql','jenkins@10.0.2.69','2022-04-06 08:48:34',NULL,NULL),('vn-database','10060','00-firstScript.sql','jenkins@10.0.2.69','2022-04-07 08:50:11',NULL,NULL),('vn-database','10062','00-firstScript.sql','jenkins@10.0.2.69','2022-04-06 10:51:45',NULL,NULL),('vn-database','10064','00-firstScript.sql','jenkins@10.0.2.69','2022-04-06 13:57:11',NULL,NULL),('vn-database','10066','00-firstScript.sql','jenkins@10.0.2.69','2022-04-07 08:50:12',NULL,NULL),('vn-database','10067','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 10:18:20',NULL,NULL),('vn-database','10071','00-packingSiteLog.sql','jenkins@10.0.2.69','2022-04-08 09:37:30',NULL,NULL),('vn-database','10072','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 11:01:46',NULL,NULL),('vn-database','10073','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 13:40:56',NULL,NULL),('vn-database','10074','00-firstScript.sql','jenkins@10.0.2.69','2022-04-10 13:15:05',NULL,NULL),('vn-database','10077','00-firstScript.sql','jenkins@10.0.2.69','2022-04-12 08:07:15',NULL,NULL),('vn-database','10078','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 07:44:21',NULL,NULL),('vn-database','10079','00-firstScript.sql','jenkins@10.0.2.69','2022-04-12 12:01:37',NULL,NULL),('vn-database','10086','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 08:58:34',NULL,NULL),('vn-database','10087','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 09:39:49',NULL,NULL),('vn-database','10088','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 15:05:12',NULL,NULL),('vn-database','10089','00-firstScript.sql','jenkins@10.0.2.69','2022-04-18 14:12:52',NULL,NULL),('vn-database','10090','00-firstScript.sql','jenkins@10.0.2.69','2022-04-18 14:34:46',NULL,NULL),('vn-database','10092','00-firstScript.sql','jenkins@10.0.2.69','2022-04-19 14:45:46',NULL,NULL),('vn-database','10093','00-autoradioConfig.sql','jenkins@10.0.2.69','2022-05-03 09:16:47',NULL,NULL),('vn-database','10094','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 10:57:30',NULL,NULL),('vn-database','10099','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 14:35:27',NULL,NULL),('vn-database','10100','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 14:35:27',NULL,NULL),('vn-database','10101','00-firstScript.sql','jenkins@10.0.2.69','2022-04-21 14:59:31',NULL,NULL),('vn-database','10107','00-firstScript.sql','jenkins@10.0.2.69','2022-04-23 10:53:53',NULL,NULL),('vn-database','10114','00-updateConfig.sql','jenkins@10.0.2.69','2022-04-27 13:37:25',NULL,NULL),('vn-database','10116','00-firstScript.sql','jenkins@10.0.2.69','2022-04-28 11:10:14',NULL,NULL),('vn-database','10118','00-firstScript.sql','jenkins@10.0.2.69','2022-04-29 08:10:15',NULL,NULL),('vn-database','10127','00-firstScript.sql','jenkins@10.0.2.69','2022-05-02 11:04:46',NULL,NULL),('vn-database','10128','00-firstScript.sql','jenkins@10.0.2.69','2022-05-02 13:04:31',NULL,NULL),('vn-database','10129','00-firstScript.sql','jenkins@10.0.2.69','2022-05-03 08:21:01',NULL,NULL); +INSERT INTO `versionLog` VALUES ('vn-database','00001','00-test.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','00003','00-sage.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','10008','00-alterRoleConfig.sql','juan@10.5.1.3','2022-01-31 10:12:26',NULL,NULL),('vn-database','10014','00-rolePrefix.sql','jenkins@10.0.2.68','2022-02-11 00:13:25',NULL,NULL),('vn-database','10017','01-firstScript.sql','jenkins@10.0.2.70','2022-03-09 11:36:54',NULL,NULL),('vn-database','10021','00-bankAccount.sql','jenkins@10.0.2.69','2022-03-16 14:11:22',NULL,NULL),('vn-database','10023','00-firstScript.sql','jenkins@10.0.2.69','2022-03-16 15:05:29',NULL,NULL),('vn-database','10026','00-invoiceInIntrastat.sql','jenkins@10.0.2.69','2022-03-21 15:10:53',NULL,NULL),('vn-database','10027','00-Clientes_cedidos.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10028','00-item_last_buy_.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10029','00-bankToViewAccountingToTable.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10030','00-KkejarNiche.sql','jenkins@10.0.2.69','2022-03-22 15:58:12',NULL,NULL),('vn-database','10036','00-updateBuyConfig.sql','jenkins@10.0.2.69','2022-03-29 12:36:54',NULL,NULL),('vn-database','10037','00-firstScript.sql','jenkins@10.0.2.69','2022-03-28 11:14:26',NULL,NULL),('vn-database','10038','00-printServerQueue.sql','jenkins@10.0.2.69','2022-03-29 08:13:24',NULL,NULL),('vn-database','10048','00-firstScript.sql','jenkins@10.0.2.69','2022-03-30 12:29:06',NULL,NULL),('vn-database','10058','00-vehicleAddFields.sql','jenkins@10.0.2.69','2022-04-06 08:48:34',NULL,NULL),('vn-database','10060','00-firstScript.sql','jenkins@10.0.2.69','2022-04-07 08:50:11',NULL,NULL),('vn-database','10062','00-firstScript.sql','jenkins@10.0.2.69','2022-04-06 10:51:45',NULL,NULL),('vn-database','10064','00-firstScript.sql','jenkins@10.0.2.69','2022-04-06 13:57:11',NULL,NULL),('vn-database','10066','00-firstScript.sql','jenkins@10.0.2.69','2022-04-07 08:50:12',NULL,NULL),('vn-database','10067','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 10:18:20',NULL,NULL),('vn-database','10071','00-packingSiteLog.sql','jenkins@10.0.2.69','2022-04-08 09:37:30',NULL,NULL),('vn-database','10072','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 11:01:46',NULL,NULL),('vn-database','10073','00-firstScript.sql','jenkins@10.0.2.69','2022-04-08 13:40:56',NULL,NULL),('vn-database','10074','00-firstScript.sql','jenkins@10.0.2.69','2022-04-10 13:15:05',NULL,NULL),('vn-database','10077','00-firstScript.sql','jenkins@10.0.2.69','2022-04-12 08:07:15',NULL,NULL),('vn-database','10078','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 07:44:21',NULL,NULL),('vn-database','10079','00-firstScript.sql','jenkins@10.0.2.69','2022-04-12 12:01:37',NULL,NULL),('vn-database','10086','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 08:58:34',NULL,NULL),('vn-database','10087','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 09:39:49',NULL,NULL),('vn-database','10088','00-firstScript.sql','jenkins@10.0.2.69','2022-04-13 15:05:12',NULL,NULL),('vn-database','10089','00-firstScript.sql','jenkins@10.0.2.69','2022-04-18 14:12:52',NULL,NULL),('vn-database','10090','00-firstScript.sql','jenkins@10.0.2.69','2022-04-18 14:34:46',NULL,NULL),('vn-database','10092','00-firstScript.sql','jenkins@10.0.2.69','2022-04-19 14:45:46',NULL,NULL),('vn-database','10093','00-autoradioConfig.sql','jenkins@10.0.2.69','2022-05-03 09:16:47',NULL,NULL),('vn-database','10094','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 10:57:30',NULL,NULL),('vn-database','10097','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL),('vn-database','10099','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 14:35:27',NULL,NULL),('vn-database','10100','00-firstScript.sql','jenkins@10.0.2.69','2022-04-20 14:35:27',NULL,NULL),('vn-database','10101','00-firstScript.sql','jenkins@10.0.2.69','2022-04-21 14:59:31',NULL,NULL),('vn-database','10103','00-awbVolume.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL),('vn-database','10104','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:12:59',NULL,NULL),('vn-database','10105','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL),('vn-database','10107','00-firstScript.sql','jenkins@10.0.2.69','2022-04-23 10:53:53',NULL,NULL),('vn-database','10112','00-firstScript.sql','jenkins@10.0.2.69','2022-05-09 09:14:53',NULL,NULL),('vn-database','10113','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL),('vn-database','10114','00-updateConfig.sql','jenkins@10.0.2.69','2022-04-27 13:37:25',NULL,NULL),('vn-database','10116','00-firstScript.sql','jenkins@10.0.2.69','2022-04-28 11:10:14',NULL,NULL),('vn-database','10118','00-firstScript.sql','jenkins@10.0.2.69','2022-04-29 08:10:15',NULL,NULL),('vn-database','10119','00-AfegirFKPart1.sql','jenkins@10.0.2.69','2022-05-05 10:13:00',NULL,NULL),('vn-database','10119','01-AfegirFkPart2.sql','jenkins@10.0.2.69','2022-05-05 10:22:25',NULL,NULL),('vn-database','10125','00-firstScript.sql','jenkins@10.0.2.68','2022-05-18 18:44:30',NULL,NULL),('vn-database','10127','00-firstScript.sql','jenkins@10.0.2.69','2022-05-02 11:04:46',NULL,NULL),('vn-database','10128','00-firstScript.sql','jenkins@10.0.2.69','2022-05-02 13:04:31',NULL,NULL),('vn-database','10129','00-firstScript.sql','jenkins@10.0.2.69','2022-05-03 08:21:01',NULL,NULL),('vn-database','10132','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 10:22:25',NULL,NULL),('vn-database','10133','00-firstScript.sql','jenkins@10.0.2.69','2022-05-05 14:32:30',NULL,NULL),('vn-database','10134','00-firstScript.sql','jenkins@10.0.2.69','2022-05-06 07:45:25',NULL,NULL),('vn-database','10135','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 08:46:17',NULL,NULL),('vn-database','10136','00-workerTimeControl.sql','jenkins@10.0.2.69','2022-05-09 13:51:12',NULL,NULL),('vn-database','10138','00-firstScript.sql','jenkins@10.0.2.69','2022-05-10 13:58:05',NULL,NULL),('vn-database','10139','00-firstScript.sql','jenkins@10.0.2.68','2022-05-16 14:32:37',NULL,NULL),('vn-database','10139','01-secondScript.sql','jenkins@10.0.2.68','2022-05-17 12:16:13',NULL,NULL),('vn-database','10141','00-firstScript.sql','jenkins@10.0.2.70','2022-05-12 08:27:31',NULL,NULL),('vn-database','10142','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:20:31',NULL,NULL),('vn-database','10143','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:20:31',NULL,NULL),('vn-database','10144','00-AfegirFKPArt1.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL),('vn-database','10144','00-firstScript.sql','jenkins@10.0.2.68','2022-05-13 09:44:25',NULL,NULL),('vn-database','10147','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL),('vn-database','10149','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:33',NULL,NULL),('vn-database','10150','00-firstScript.sql','jenkins@10.0.2.68','2022-05-17 09:57:16',NULL,NULL),('vn-database','10152','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL),('vn-database','10153','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL),('vn-database','10154','00-compressionKk.sql','jenkins@10.0.2.68','2022-05-20 09:22:34',NULL,NULL),('vn-database','10157','00-firstScript.sql','jenkins@10.0.2.68','2022-05-20 09:22:35',NULL,NULL),('vn-database','10158','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:21',NULL,NULL),('vn-database','10163','00-firstScript.sql','jenkins@10.0.2.68','2022-05-23 08:17:14',NULL,NULL),('vn-database','10164','00-borrarSectorsDesus.sql','jenkins@10.0.2.68','2022-06-02 12:47:21',NULL,NULL),('vn-database','10165','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10166','00-firstScript.sql','jenkins@10.0.2.68','2022-05-24 16:11:21',NULL,NULL),('vn-database','10167','00-renameVnActiveContrat.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10168','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10169','00-createTableBankEntityConfig.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10169','02-addNotNullToBankEntityBic.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10172','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10174','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 08:46:17',NULL,NULL),('vn-database','10175','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10177','00-crearTablaSpecialLabels.sql','jenkins@10.0.2.68','2022-06-02 12:47:22',NULL,NULL),('vn-database','10178','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL),('vn-database','10179','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL),('vn-database','10183','00-firstScript.sql','jenkins@10.0.2.68','2022-06-02 12:47:24',NULL,NULL),('vn-database','10184','00-firstScript.sql','jenkins@10.0.2.68','2022-06-03 08:05:34',NULL,NULL),('vn-database','10185','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 09:07:45',NULL,NULL),('vn-database','10186','00-desactivar_trigger.sql','jenkins@10.0.2.68','2022-06-07 09:31:23',NULL,NULL),('vn-database','10186','01-alter_Table_buy.sql','jenkins@10.0.2.68','2022-06-07 09:34:47',NULL,NULL),('vn-database','10186','02-alter_table_entryConfig.sql','jenkins@10.0.2.68','2022-06-07 09:34:47',NULL,NULL),('vn-database','10186','04-regularizar_Sticker_Inventario.sql','jenkins@10.0.2.68','2022-06-07 09:34:51',NULL,NULL),('vn-database','10186','09-reactivar_trigger.sql','jenkins@10.0.2.68','2022-06-07 09:34:51',NULL,NULL),('vn-database','10187','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 12:37:31',NULL,NULL),('vn-database','10188','00-firstScript.sql','jenkins@10.0.2.68','2022-06-06 14:03:36',NULL,NULL),('vn-database','10189','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10191','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10194','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10195','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:03:41',NULL,NULL),('vn-database','10200','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL),('vn-database','10201','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL),('vn-database','10202','00-Remove_FK_to_ediGenus.sql','jenkins@10.0.2.69','2022-06-17 09:04:00',NULL,NULL),('vn-database','10203','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:01',NULL,NULL),('vn-database','10204','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:01',NULL,NULL),('vn-database','10205','00-firstScript.sql','jenkins@10.0.2.69','2022-06-17 09:04:21',NULL,NULL),('vn-database','10207','00-Alter_table_entry.sql','jenkins@10.0.2.69','2022-06-16 07:22:50',NULL,NULL),('vn-database','10207','01-Update_invoiceAmount.sql','jenkins@10.0.2.69','2022-06-16 07:23:00',NULL,NULL),('vn-database','10209','00-firstScript.sql','jenkins@10.0.2.69','2022-06-16 08:47:40',NULL,NULL),('vn-database','10210','00-firstScript.sql','jenkins@10.0.2.69','2022-06-16 17:39:17',1046,'Base de datos no seleccionada'),('vn-database','10211','01-firstScript.sql','jenkins@10.0.2.69','2022-06-17 07:11:27',NULL,NULL),('vn-database','10216','00-firstScript.sql','jenkins@10.0.2.69','2022-06-23 11:15:28',NULL,NULL); /*!40000 ALTER TABLE `versionLog` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -54,9 +54,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-05-04 15:58:27 +-- Dump completed on 2022-06-23 12:13:31 USE `account`; --- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.8-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: account -- ------------------------------------------------------ @@ -78,7 +78,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 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'),(102,'preservedBoss','Responsable preservado',1,'2021-09-14 13:45:37','2021-09-14 13:45:37'),(103,'it','Departamento de informática',1,'2021-11-11 09:48:22','2021-11-11 09:48:22'),(104,'itBoss','Jefe de departamento de informática',1,'2021-11-11 09:48:49','2021-11-11 09:48:49'),(105,'grant','Adjudicar roles a usuarios',1,'2021-11-11 12:41:09','2021-11-11 12:41:09'),(106,'ext','Usuarios externos de la Base de datos',1,'2021-11-23 14:51:16','2021-11-23 14:51:16'),(107,'productionPlus','Creado para pepe por orden de Juanvi',1,'2022-02-08 06:47:10','2022-02-08 06:47:10'); +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'),(102,'preservedBoss','Responsable preservado',1,'2021-09-14 13:45:37','2021-09-14 13:45:37'),(103,'it','Departamento de informática',1,'2021-11-11 09:48:22','2021-11-11 09:48:22'),(104,'itBoss','Jefe de departamento de informática',1,'2021-11-11 09:48:49','2021-11-11 09:48:49'),(105,'grant','Adjudicar roles a usuarios',1,'2021-11-11 12:41:09','2021-11-11 12:41:09'),(106,'ext','Usuarios externos de la Base de datos',1,'2021-11-23 14:51:16','2021-11-23 14:51:16'),(107,'productionPlus','Creado para pepe por orden de Juanvi',1,'2022-02-08 06:47:10','2022-02-08 06:47:10'),(108,'system','System user',1,'2022-05-16 08:09:51','2022-05-16 08:09:51'),(109,'salesTeamBoss','Jefe de equipo de comerciales',1,'2022-06-14 13:45:56','2022-06-14 13:45:56'); /*!40000 ALTER TABLE `role` ENABLE KEYS */; UNLOCK TABLES; @@ -88,7 +88,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),(167,9,103),(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),(242,20,9),(22,20,13),(23,20,16),(24,20,65),(134,20,76),(25,21,13),(26,21,18),(27,21,53),(241,21,72),(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),(245,57,33),(83,57,56),(138,57,76),(84,58,1),(85,59,13),(109,59,50),(87,60,5),(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),(168,66,9),(237,66,103),(97,67,5),(98,67,37),(99,69,35),(152,69,47),(101,70,11),(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),(154,102,1),(173,103,1),(194,103,2),(181,103,3),(179,103,5),(201,103,6),(176,103,11),(231,103,13),(212,103,15),(213,103,16),(178,103,17),(230,103,18),(229,103,19),(238,103,20),(228,103,21),(232,103,22),(199,103,30),(200,103,31),(197,103,32),(207,103,33),(182,103,34),(186,103,35),(225,103,36),(204,103,37),(205,103,38),(177,103,39),(202,103,40),(203,103,41),(183,103,42),(184,103,43),(174,103,44),(175,103,45),(191,103,47),(193,103,48),(222,103,49),(224,103,50),(215,103,51),(216,103,52),(206,103,53),(210,103,54),(211,103,55),(195,103,56),(196,103,57),(219,103,58),(220,103,59),(223,103,60),(226,103,61),(185,103,64),(218,103,65),(180,103,67),(192,103,69),(233,103,70),(189,103,71),(190,103,72),(198,103,73),(234,103,74),(188,103,75),(172,103,76),(187,103,101),(221,103,102),(171,104,9),(170,104,66),(169,104,100),(166,104,103),(239,106,11),(240,107,60); +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),(167,9,103),(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),(242,20,9),(22,20,13),(23,20,16),(24,20,65),(134,20,76),(25,21,13),(26,21,18),(27,21,53),(241,21,72),(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),(245,57,33),(83,57,56),(138,57,76),(84,58,1),(85,59,13),(109,59,50),(87,60,5),(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),(168,66,9),(237,66,103),(97,67,5),(98,67,37),(99,69,35),(152,69,47),(101,70,11),(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),(154,102,1),(248,102,13),(246,102,35),(173,103,1),(194,103,2),(181,103,3),(179,103,5),(201,103,6),(176,103,11),(231,103,13),(212,103,15),(213,103,16),(178,103,17),(230,103,18),(229,103,19),(238,103,20),(228,103,21),(232,103,22),(199,103,30),(200,103,31),(197,103,32),(207,103,33),(182,103,34),(186,103,35),(225,103,36),(204,103,37),(205,103,38),(177,103,39),(202,103,40),(203,103,41),(183,103,42),(184,103,43),(174,103,44),(175,103,45),(191,103,47),(193,103,48),(222,103,49),(224,103,50),(215,103,51),(216,103,52),(206,103,53),(210,103,54),(211,103,55),(195,103,56),(196,103,57),(219,103,58),(220,103,59),(223,103,60),(226,103,61),(185,103,64),(218,103,65),(180,103,67),(192,103,69),(233,103,70),(189,103,71),(190,103,72),(198,103,73),(234,103,74),(188,103,75),(172,103,76),(187,103,101),(221,103,102),(171,104,9),(170,104,66),(169,104,100),(166,104,103),(239,106,11),(240,107,60),(247,108,1),(250,109,13),(249,109,18); /*!40000 ALTER TABLE `roleInherit` ENABLE KEYS */; UNLOCK TABLES; @@ -98,7 +98,7 @@ UNLOCK TABLES; LOCK TABLES `roleRole` WRITE; /*!40000 ALTER TABLE `roleRole` DISABLE KEYS */; -INSERT INTO `roleRole` VALUES (85547,1,1),(85548,1,2),(85549,1,3),(85552,1,6),(85551,1,11),(85550,1,70),(85465,2,2),(85467,2,6),(85466,2,11),(85350,3,3),(85352,3,6),(85351,3,11),(85320,5,1),(85327,5,2),(85326,5,3),(85319,5,5),(85332,5,6),(85331,5,11),(85324,5,13),(85328,5,18),(85321,5,21),(85322,5,33),(85329,5,53),(85325,5,70),(85330,5,72),(85323,5,76),(85649,6,6),(85488,9,1),(85489,9,2),(85490,9,3),(85491,9,5),(85492,9,6),(85486,9,9),(85493,9,11),(85494,9,13),(85495,9,15),(85496,9,16),(85497,9,17),(85498,9,18),(85499,9,19),(85500,9,20),(85501,9,21),(85502,9,22),(85503,9,30),(85504,9,31),(85505,9,32),(85506,9,33),(85507,9,34),(85508,9,35),(85509,9,36),(85510,9,37),(85511,9,38),(85512,9,39),(85513,9,40),(85514,9,41),(85515,9,42),(85516,9,43),(85517,9,44),(85518,9,45),(85519,9,47),(85520,9,48),(85521,9,49),(85522,9,50),(85523,9,51),(85524,9,52),(85525,9,53),(85526,9,54),(85527,9,55),(85528,9,56),(85529,9,57),(85530,9,58),(85531,9,59),(85532,9,60),(85533,9,61),(85534,9,64),(85535,9,65),(85536,9,67),(85537,9,69),(85538,9,70),(85539,9,71),(85540,9,72),(85541,9,73),(85542,9,74),(85543,9,75),(85544,9,76),(85545,9,101),(85546,9,102),(85487,9,103),(85240,11,6),(85239,11,11),(86312,13,1),(86313,13,2),(86314,13,3),(86317,13,6),(86316,13,11),(86311,13,13),(86315,13,70),(85861,15,1),(85865,15,2),(85864,15,3),(85868,15,6),(85867,15,11),(85853,15,15),(85854,15,35),(85859,15,36),(85862,15,44),(85866,15,47),(85855,15,49),(85856,15,56),(85858,15,58),(85863,15,70),(85860,15,75),(85857,15,76),(85875,16,1),(85880,16,2),(85879,16,3),(85886,16,6),(85885,16,11),(85870,16,13),(85871,16,15),(85869,16,16),(85874,16,35),(85881,16,36),(85884,16,44),(85883,16,47),(85873,16,49),(85876,16,56),(85882,16,58),(85878,16,70),(85877,16,75),(85872,16,76),(85266,17,1),(85277,17,2),(85276,17,3),(85271,17,5),(85299,17,6),(85270,17,9),(85298,17,11),(85269,17,13),(85281,17,15),(85268,17,16),(85258,17,17),(85283,17,18),(85280,17,19),(85259,17,20),(85272,17,21),(85297,17,22),(85296,17,30),(85295,17,31),(85294,17,32),(85274,17,33),(85293,17,34),(85279,17,35),(85292,17,36),(85260,17,37),(85291,17,38),(85261,17,39),(85290,17,40),(85289,17,41),(85288,17,42),(85287,17,43),(85300,17,44),(85301,17,45),(85302,17,47),(85303,17,48),(85304,17,49),(85278,17,50),(85305,17,51),(85306,17,52),(85284,17,53),(85307,17,54),(85308,17,55),(85286,17,56),(85273,17,57),(85309,17,58),(85310,17,59),(85311,17,60),(85312,17,61),(85262,17,64),(85267,17,65),(85263,17,67),(85313,17,69),(85275,17,70),(85314,17,71),(85285,17,72),(85315,17,73),(85265,17,74),(85316,17,75),(85264,17,76),(85317,17,101),(85318,17,102),(85282,17,103),(86242,18,1),(86245,18,2),(86244,18,3),(86248,18,6),(86247,18,11),(86241,18,18),(86246,18,70),(86243,18,76),(86235,19,1),(86238,19,2),(86237,19,3),(86240,19,6),(86239,19,11),(86230,19,13),(86231,19,18),(86228,19,19),(86229,19,21),(86232,19,53),(86236,19,70),(86233,19,72),(86234,19,76),(85896,20,1),(85904,20,2),(85903,20,3),(85902,20,5),(85901,20,6),(85888,20,9),(85900,20,11),(85889,20,13),(85895,20,15),(85890,20,16),(85899,20,17),(85905,20,18),(85894,20,19),(85887,20,20),(85906,20,21),(85907,20,22),(85908,20,30),(85909,20,31),(85910,20,32),(85911,20,33),(85912,20,34),(85893,20,35),(85913,20,36),(85914,20,37),(85915,20,38),(85916,20,39),(85917,20,40),(85918,20,41),(85919,20,42),(85920,20,43),(85921,20,44),(85922,20,45),(85923,20,47),(85924,20,48),(85925,20,49),(85898,20,50),(85926,20,51),(85927,20,52),(85928,20,53),(85929,20,54),(85930,20,55),(85931,20,56),(85932,20,57),(85933,20,58),(85934,20,59),(85935,20,60),(85936,20,61),(85937,20,64),(85891,20,65),(85938,20,67),(85939,20,69),(85940,20,70),(85941,20,71),(85942,20,72),(85943,20,73),(85944,20,74),(85945,20,75),(85892,20,76),(85946,20,101),(85947,20,102),(85897,20,103),(86222,21,1),(86225,21,2),(86224,21,3),(86227,21,6),(86226,21,11),(86217,21,13),(86218,21,18),(86216,21,21),(86219,21,53),(86223,21,70),(86220,21,72),(86221,21,76),(86322,22,1),(86328,22,2),(86327,22,3),(86330,22,6),(86329,22,11),(86319,22,13),(86321,22,18),(86320,22,21),(86318,22,22),(86323,22,53),(86326,22,70),(86324,22,72),(86325,22,76),(85592,30,1),(85600,30,2),(85599,30,3),(85581,30,5),(85612,30,6),(85589,30,9),(85613,30,11),(85588,30,13),(85594,30,15),(85587,30,16),(85611,30,17),(85597,30,18),(85601,30,19),(85582,30,20),(85591,30,21),(85583,30,22),(85580,30,30),(85610,30,31),(85609,30,32),(85590,30,33),(85608,30,34),(85602,30,35),(85607,30,36),(85606,30,37),(85605,30,38),(85604,30,39),(85614,30,40),(85615,30,41),(85616,30,42),(85617,30,43),(85618,30,44),(85619,30,45),(85620,30,47),(85621,30,48),(85622,30,49),(85603,30,50),(85623,30,51),(85624,30,52),(85584,30,53),(85625,30,54),(85626,30,55),(85627,30,56),(85628,30,57),(85629,30,58),(85630,30,59),(85631,30,60),(85632,30,61),(85585,30,64),(85593,30,65),(85633,30,67),(85634,30,69),(85598,30,70),(85635,30,71),(85596,30,72),(85636,30,73),(85637,30,74),(85638,30,75),(85586,30,76),(85639,30,101),(85640,30,102),(85595,30,103),(85642,31,1),(85643,31,2),(85644,31,3),(85647,31,6),(85646,31,11),(85641,31,31),(85645,31,70),(85554,32,1),(85555,32,2),(85556,32,3),(85559,32,6),(85558,32,11),(85553,32,32),(85557,32,70),(85707,33,33),(85354,34,1),(85359,34,2),(85358,34,3),(85361,34,6),(85360,34,11),(85355,34,13),(85356,34,33),(85353,34,34),(85357,34,70),(85396,35,1),(85401,35,2),(85400,35,3),(85403,35,6),(85402,35,11),(85395,35,35),(85399,35,70),(85397,35,75),(85398,35,76),(86131,36,1),(86133,36,2),(86132,36,3),(86136,36,6),(86135,36,11),(86128,36,36),(86129,36,44),(86130,36,47),(86134,36,70),(85680,37,1),(85685,37,2),(85684,37,3),(85687,37,6),(85686,37,11),(85679,37,37),(85683,37,70),(85681,37,74),(85682,37,76),(85694,38,1),(85697,38,2),(85696,38,3),(85699,38,6),(85698,38,11),(85689,38,13),(85690,38,37),(85688,38,38),(85691,38,64),(85695,38,70),(85693,38,74),(85692,38,76),(85249,39,1),(85255,39,2),(85254,39,3),(85242,39,5),(85257,39,6),(85256,39,11),(85247,39,13),(85246,39,18),(85243,39,21),(85248,39,33),(85241,39,39),(85250,39,53),(85252,39,56),(85244,39,57),(85253,39,70),(85251,39,72),(85245,39,76),(85651,40,1),(85654,40,2),(85653,40,3),(85661,40,6),(85660,40,11),(85656,40,36),(85650,40,40),(85659,40,44),(85658,40,47),(85652,40,49),(85657,40,58),(85655,40,70),(85669,41,1),(85673,41,2),(85672,41,3),(85678,41,6),(85677,41,11),(85663,41,13),(85664,41,35),(85670,41,36),(85665,41,40),(85662,41,41),(85676,41,44),(85675,41,47),(85667,41,49),(85674,41,58),(85671,41,70),(85668,41,75),(85666,41,76),(85368,42,1),(85373,42,2),(85372,42,3),(85376,42,6),(85375,42,11),(85363,42,35),(85366,42,36),(85362,42,42),(85370,42,44),(85374,42,47),(85364,42,49),(85369,42,58),(85371,42,70),(85367,42,75),(85365,42,76),(85381,43,1),(85387,43,2),(85386,43,3),(85393,43,6),(85392,43,11),(85378,43,13),(85380,43,35),(85388,43,36),(85379,43,42),(85377,43,43),(85391,43,44),(85390,43,47),(85382,43,49),(85389,43,58),(85385,43,70),(85384,43,75),(85383,43,76),(85224,44,1),(85225,44,2),(85226,44,3),(85229,44,6),(85228,44,11),(85223,44,44),(85227,44,70),(85233,45,1),(85235,45,2),(85234,45,3),(85238,45,6),(85237,45,11),(85231,45,13),(85232,45,44),(85230,45,45),(85236,45,70),(85436,47,1),(85437,47,2),(85438,47,3),(85441,47,6),(85440,47,11),(85435,47,47),(85439,47,70),(85459,48,1),(85462,48,2),(85461,48,3),(85464,48,6),(85463,48,11),(85454,48,13),(85455,48,35),(85456,48,47),(85453,48,48),(85460,48,70),(85458,48,75),(85457,48,76),(86045,49,1),(86048,49,2),(86047,49,3),(86050,49,6),(86049,49,11),(86041,49,36),(86044,49,44),(86043,49,47),(86040,49,49),(86042,49,58),(86046,49,70),(86091,50,1),(86098,50,2),(86097,50,3),(86100,50,6),(86099,50,11),(86078,50,13),(86090,50,18),(86079,50,21),(86092,50,33),(86080,50,35),(86086,50,36),(86095,50,44),(86094,50,47),(86081,50,49),(86077,50,50),(86089,50,53),(86093,50,56),(86082,50,57),(86085,50,58),(86083,50,59),(86096,50,70),(86088,50,72),(86087,50,75),(86084,50,76),(85949,51,1),(85954,51,2),(85953,51,3),(85956,51,6),(85955,51,11),(85948,51,51),(85952,51,70),(85950,51,74),(85951,51,75),(85966,52,1),(85971,52,2),(85970,52,3),(85974,52,6),(85973,52,11),(85958,52,13),(85968,52,18),(85959,52,19),(85965,52,21),(85960,52,35),(85961,52,51),(85957,52,52),(85967,52,53),(85969,52,70),(85972,52,72),(85963,52,74),(85964,52,75),(85962,52,76),(85701,53,1),(85702,53,2),(85703,53,3),(85706,53,6),(85705,53,11),(85700,53,53),(85704,53,70),(85838,54,1),(85839,54,2),(85840,54,3),(85843,54,6),(85842,54,11),(85837,54,54),(85841,54,70),(85847,55,1),(85849,55,2),(85848,55,3),(85852,55,6),(85851,55,11),(85845,55,13),(85846,55,54),(85844,55,55),(85850,55,70),(85469,56,1),(85470,56,2),(85471,56,3),(85474,56,6),(85473,56,11),(85468,56,56),(85472,56,70),(85480,57,1),(85483,57,2),(85482,57,3),(85485,57,6),(85484,57,11),(85476,57,13),(85477,57,33),(85478,57,56),(85475,57,57),(85481,57,70),(85479,57,76),(86003,58,1),(86004,58,2),(86005,58,3),(86008,58,6),(86007,58,11),(86002,58,58),(86006,58,70),(86013,59,1),(86023,59,2),(86022,59,3),(86032,59,6),(86031,59,11),(86010,59,13),(86020,59,18),(86012,59,21),(86027,59,33),(86014,59,35),(86025,59,36),(86030,59,44),(86029,59,47),(86015,59,49),(86011,59,50),(86019,59,53),(86028,59,56),(86016,59,57),(86026,59,58),(86009,59,59),(86021,59,70),(86018,59,72),(86024,59,75),(86017,59,76),(86059,60,1),(86071,60,2),(86070,60,3),(86052,60,5),(86076,60,6),(86075,60,11),(86056,60,13),(86068,60,18),(86058,60,21),(86057,60,33),(86060,60,35),(86064,60,36),(86074,60,44),(86073,60,47),(86061,60,49),(86053,60,50),(86067,60,53),(86063,60,56),(86054,60,57),(86072,60,58),(86062,60,59),(86051,60,60),(86069,60,70),(86066,60,72),(86065,60,75),(86055,60,76),(86141,61,1),(86145,61,2),(86144,61,3),(86147,61,6),(86146,61,11),(86138,61,13),(86139,61,36),(86140,61,44),(86142,61,47),(86137,61,61),(86143,61,70),(85975,62,62),(85394,64,64),(85983,65,1),(85991,65,2),(85990,65,3),(86001,65,6),(86000,65,11),(85981,65,13),(85994,65,18),(85977,65,19),(85984,65,21),(85996,65,33),(85978,65,35),(85988,65,36),(85999,65,44),(85998,65,47),(85985,65,49),(85979,65,50),(85993,65,53),(85997,65,56),(85986,65,57),(85995,65,58),(85987,65,59),(85976,65,65),(85989,65,70),(85992,65,72),(85982,65,75),(85980,65,76),(86253,66,1),(86252,66,2),(86254,66,3),(86255,66,5),(86256,66,6),(86250,66,9),(86257,66,11),(86258,66,13),(86259,66,15),(86260,66,16),(86261,66,17),(86262,66,18),(86263,66,19),(86264,66,20),(86265,66,21),(86266,66,22),(86267,66,30),(86268,66,31),(86269,66,32),(86270,66,33),(86271,66,34),(86272,66,35),(86273,66,36),(86274,66,37),(86275,66,38),(86276,66,39),(86277,66,40),(86278,66,41),(86279,66,42),(86280,66,43),(86281,66,44),(86282,66,45),(86283,66,47),(86284,66,48),(86285,66,49),(86286,66,50),(86287,66,51),(86288,66,52),(86289,66,53),(86290,66,54),(86291,66,55),(86292,66,56),(86293,66,57),(86294,66,58),(86295,66,59),(86296,66,60),(86297,66,61),(86298,66,64),(86299,66,65),(86249,66,66),(86300,66,67),(86301,66,69),(86302,66,70),(86303,66,71),(86304,66,72),(86305,66,73),(86306,66,74),(86307,66,75),(86308,66,76),(86309,66,101),(86310,66,102),(86251,66,103),(85337,67,1),(85345,67,2),(85344,67,3),(85334,67,5),(85349,67,6),(85348,67,11),(85342,67,13),(85341,67,18),(85336,67,21),(85338,67,33),(85335,67,37),(85346,67,53),(85333,67,67),(85343,67,70),(85347,67,72),(85340,67,74),(85339,67,76),(85446,69,1),(85450,69,2),(85449,69,3),(85452,69,6),(85451,69,11),(85443,69,35),(85444,69,47),(85442,69,69),(85448,69,70),(85445,69,75),(85447,69,76),(86333,70,6),(86332,70,11),(86331,70,70),(85418,71,1),(85421,71,2),(85420,71,3),(85424,71,6),(85423,71,11),(85419,71,58),(85422,71,70),(85417,71,71),(85429,72,1),(85431,72,2),(85430,72,3),(85434,72,6),(85433,72,11),(85426,72,13),(85427,72,18),(85432,72,70),(85425,72,72),(85428,72,76),(85569,73,1),(85574,73,2),(85573,73,3),(85564,73,5),(85579,73,6),(85578,73,11),(85571,73,13),(85575,73,18),(85565,73,19),(85568,73,21),(85567,73,33),(85576,73,53),(85566,73,64),(85572,73,70),(85577,73,72),(85563,73,73),(85570,73,76),(86334,74,74),(85415,75,75),(85416,76,76),(86174,100,1),(86170,100,2),(86156,100,3),(86154,100,5),(86181,100,6),(86173,100,9),(86151,100,11),(86212,100,13),(86192,100,15),(86193,100,16),(86153,100,17),(86210,100,18),(86209,100,19),(86194,100,20),(86208,100,21),(86213,100,22),(86178,100,30),(86179,100,31),(86175,100,32),(86187,100,33),(86157,100,34),(86161,100,35),(86206,100,36),(86184,100,37),(86185,100,38),(86152,100,39),(86182,100,40),(86183,100,41),(86158,100,42),(86159,100,43),(86149,100,44),(86150,100,45),(86167,100,47),(86169,100,48),(86202,100,49),(86204,100,50),(86195,100,51),(86196,100,52),(86186,100,53),(86190,100,54),(86191,100,55),(86171,100,56),(86172,100,57),(86199,100,58),(86200,100,59),(86203,100,60),(86207,100,61),(86197,100,62),(86160,100,64),(86198,100,65),(86211,100,66),(86155,100,67),(86168,100,69),(86214,100,70),(86165,100,71),(86166,100,72),(86177,100,73),(86215,100,74),(86163,100,75),(86164,100,76),(86148,100,100),(86162,100,101),(86201,100,102),(86188,100,103),(86189,100,104),(86180,100,105),(86176,100,106),(86205,100,107),(85408,101,1),(85412,101,2),(85411,101,3),(85414,101,6),(85413,101,11),(85405,101,13),(85406,101,35),(85410,101,70),(85407,101,75),(85409,101,76),(85404,101,101),(86034,102,1),(86035,102,2),(86036,102,3),(86039,102,6),(86038,102,11),(86037,102,70),(86033,102,102),(85709,103,1),(85710,103,2),(85711,103,3),(85712,103,5),(85713,103,6),(85768,103,9),(85714,103,11),(85715,103,13),(85716,103,15),(85717,103,16),(85718,103,17),(85719,103,18),(85720,103,19),(85721,103,20),(85722,103,21),(85723,103,22),(85724,103,30),(85725,103,31),(85726,103,32),(85727,103,33),(85728,103,34),(85729,103,35),(85730,103,36),(85731,103,37),(85732,103,38),(85733,103,39),(85734,103,40),(85735,103,41),(85736,103,42),(85737,103,43),(85738,103,44),(85739,103,45),(85740,103,47),(85741,103,48),(85742,103,49),(85743,103,50),(85744,103,51),(85745,103,52),(85746,103,53),(85747,103,54),(85748,103,55),(85749,103,56),(85750,103,57),(85751,103,58),(85752,103,59),(85753,103,60),(85754,103,61),(85755,103,64),(85756,103,65),(85757,103,67),(85758,103,69),(85759,103,70),(85760,103,71),(85761,103,72),(85762,103,73),(85763,103,74),(85764,103,75),(85765,103,76),(85766,103,101),(85767,103,102),(85708,103,103),(85777,104,1),(85776,104,2),(85775,104,3),(85774,104,5),(85778,104,6),(85770,104,9),(85779,104,11),(85780,104,13),(85781,104,15),(85782,104,16),(85783,104,17),(85784,104,18),(85785,104,19),(85786,104,20),(85787,104,21),(85788,104,22),(85789,104,30),(85790,104,31),(85791,104,32),(85792,104,33),(85793,104,34),(85794,104,35),(85795,104,36),(85796,104,37),(85797,104,38),(85798,104,39),(85799,104,40),(85800,104,41),(85801,104,42),(85802,104,43),(85803,104,44),(85804,104,45),(85805,104,47),(85806,104,48),(85807,104,49),(85808,104,50),(85809,104,51),(85810,104,52),(85811,104,53),(85812,104,54),(85813,104,55),(85814,104,56),(85815,104,57),(85816,104,58),(85817,104,59),(85818,104,60),(85819,104,61),(85835,104,62),(85820,104,64),(85821,104,65),(85771,104,66),(85822,104,67),(85823,104,69),(85824,104,70),(85825,104,71),(85826,104,72),(85827,104,73),(85828,104,74),(85829,104,75),(85830,104,76),(85772,104,100),(85831,104,101),(85832,104,102),(85773,104,103),(85769,104,104),(85834,104,105),(85833,104,106),(85836,104,107),(85648,105,105),(85562,106,6),(85561,106,11),(85560,106,106),(86110,107,1),(86122,107,2),(86121,107,3),(86103,107,5),(86127,107,6),(86126,107,11),(86107,107,13),(86119,107,18),(86109,107,21),(86108,107,33),(86111,107,35),(86115,107,36),(86125,107,44),(86124,107,47),(86112,107,49),(86104,107,50),(86118,107,53),(86114,107,56),(86105,107,57),(86123,107,58),(86113,107,59),(86102,107,60),(86120,107,70),(86117,107,72),(86116,107,75),(86106,107,76),(86101,107,107); +INSERT INTO `roleRole` VALUES (93925,1,1),(93926,1,2),(93927,1,3),(93930,1,6),(93929,1,11),(93928,1,70),(93843,2,2),(93845,2,6),(93844,2,11),(93728,3,3),(93730,3,6),(93729,3,11),(93698,5,1),(93705,5,2),(93704,5,3),(93697,5,5),(93710,5,6),(93709,5,11),(93702,5,13),(93706,5,18),(93699,5,21),(93700,5,33),(93707,5,53),(93703,5,70),(93708,5,72),(93701,5,76),(94027,6,6),(93866,9,1),(93867,9,2),(93868,9,3),(93869,9,5),(93870,9,6),(93864,9,9),(93871,9,11),(93872,9,13),(93873,9,15),(93874,9,16),(93875,9,17),(93876,9,18),(93877,9,19),(93878,9,20),(93879,9,21),(93880,9,22),(93881,9,30),(93882,9,31),(93883,9,32),(93884,9,33),(93885,9,34),(93886,9,35),(93887,9,36),(93888,9,37),(93889,9,38),(93890,9,39),(93891,9,40),(93892,9,41),(93893,9,42),(93894,9,43),(93895,9,44),(93896,9,45),(93897,9,47),(93898,9,48),(93899,9,49),(93900,9,50),(93901,9,51),(93902,9,52),(93903,9,53),(93904,9,54),(93905,9,55),(93906,9,56),(93907,9,57),(93908,9,58),(93909,9,59),(93910,9,60),(93911,9,61),(93912,9,64),(93913,9,65),(93914,9,67),(93915,9,69),(93916,9,70),(93917,9,71),(93918,9,72),(93919,9,73),(93920,9,74),(93921,9,75),(93922,9,76),(93923,9,101),(93924,9,102),(93865,9,103),(93618,11,6),(93617,11,11),(94715,13,1),(94716,13,2),(94717,13,3),(94720,13,6),(94719,13,11),(94714,13,13),(94718,13,70),(94241,15,1),(94245,15,2),(94244,15,3),(94248,15,6),(94247,15,11),(94233,15,15),(94234,15,35),(94239,15,36),(94242,15,44),(94246,15,47),(94235,15,49),(94236,15,56),(94238,15,58),(94243,15,70),(94240,15,75),(94237,15,76),(94255,16,1),(94260,16,2),(94259,16,3),(94266,16,6),(94265,16,11),(94250,16,13),(94251,16,15),(94249,16,16),(94254,16,35),(94261,16,36),(94264,16,44),(94263,16,47),(94253,16,49),(94256,16,56),(94262,16,58),(94258,16,70),(94257,16,75),(94252,16,76),(93644,17,1),(93655,17,2),(93654,17,3),(93649,17,5),(93677,17,6),(93648,17,9),(93676,17,11),(93647,17,13),(93659,17,15),(93646,17,16),(93636,17,17),(93661,17,18),(93658,17,19),(93637,17,20),(93650,17,21),(93675,17,22),(93674,17,30),(93673,17,31),(93672,17,32),(93652,17,33),(93671,17,34),(93657,17,35),(93670,17,36),(93638,17,37),(93669,17,38),(93639,17,39),(93668,17,40),(93667,17,41),(93666,17,42),(93665,17,43),(93678,17,44),(93679,17,45),(93680,17,47),(93681,17,48),(93682,17,49),(93656,17,50),(93683,17,51),(93684,17,52),(93662,17,53),(93685,17,54),(93686,17,55),(93664,17,56),(93651,17,57),(93687,17,58),(93688,17,59),(93689,17,60),(93690,17,61),(93640,17,64),(93645,17,65),(93641,17,67),(93691,17,69),(93653,17,70),(93692,17,71),(93663,17,72),(93693,17,73),(93643,17,74),(93694,17,75),(93642,17,76),(93695,17,101),(93696,17,102),(93660,17,103),(94628,18,1),(94631,18,2),(94630,18,3),(94634,18,6),(94633,18,11),(94627,18,18),(94632,18,70),(94629,18,76),(94621,19,1),(94624,19,2),(94623,19,3),(94626,19,6),(94625,19,11),(94616,19,13),(94617,19,18),(94614,19,19),(94615,19,21),(94618,19,53),(94622,19,70),(94619,19,72),(94620,19,76),(94276,20,1),(94284,20,2),(94283,20,3),(94282,20,5),(94281,20,6),(94268,20,9),(94280,20,11),(94269,20,13),(94275,20,15),(94270,20,16),(94279,20,17),(94285,20,18),(94274,20,19),(94267,20,20),(94286,20,21),(94287,20,22),(94288,20,30),(94289,20,31),(94290,20,32),(94291,20,33),(94292,20,34),(94273,20,35),(94293,20,36),(94294,20,37),(94295,20,38),(94296,20,39),(94297,20,40),(94298,20,41),(94299,20,42),(94300,20,43),(94301,20,44),(94302,20,45),(94303,20,47),(94304,20,48),(94305,20,49),(94278,20,50),(94306,20,51),(94307,20,52),(94308,20,53),(94309,20,54),(94310,20,55),(94311,20,56),(94312,20,57),(94313,20,58),(94314,20,59),(94315,20,60),(94316,20,61),(94317,20,64),(94271,20,65),(94318,20,67),(94319,20,69),(94320,20,70),(94321,20,71),(94322,20,72),(94323,20,73),(94324,20,74),(94325,20,75),(94272,20,76),(94326,20,101),(94327,20,102),(94277,20,103),(94608,21,1),(94611,21,2),(94610,21,3),(94613,21,6),(94612,21,11),(94603,21,13),(94604,21,18),(94602,21,21),(94605,21,53),(94609,21,70),(94606,21,72),(94607,21,76),(94725,22,1),(94731,22,2),(94730,22,3),(94733,22,6),(94732,22,11),(94722,22,13),(94724,22,18),(94723,22,21),(94721,22,22),(94726,22,53),(94729,22,70),(94727,22,72),(94728,22,76),(93970,30,1),(93978,30,2),(93977,30,3),(93959,30,5),(93990,30,6),(93967,30,9),(93991,30,11),(93966,30,13),(93972,30,15),(93965,30,16),(93989,30,17),(93975,30,18),(93979,30,19),(93960,30,20),(93969,30,21),(93961,30,22),(93958,30,30),(93988,30,31),(93987,30,32),(93968,30,33),(93986,30,34),(93980,30,35),(93985,30,36),(93984,30,37),(93983,30,38),(93982,30,39),(93992,30,40),(93993,30,41),(93994,30,42),(93995,30,43),(93996,30,44),(93997,30,45),(93998,30,47),(93999,30,48),(94000,30,49),(93981,30,50),(94001,30,51),(94002,30,52),(93962,30,53),(94003,30,54),(94004,30,55),(94005,30,56),(94006,30,57),(94007,30,58),(94008,30,59),(94009,30,60),(94010,30,61),(93963,30,64),(93971,30,65),(94011,30,67),(94012,30,69),(93976,30,70),(94013,30,71),(93974,30,72),(94014,30,73),(94015,30,74),(94016,30,75),(93964,30,76),(94017,30,101),(94018,30,102),(93973,30,103),(94020,31,1),(94021,31,2),(94022,31,3),(94025,31,6),(94024,31,11),(94019,31,31),(94023,31,70),(93932,32,1),(93933,32,2),(93934,32,3),(93937,32,6),(93936,32,11),(93931,32,32),(93935,32,70),(94085,33,33),(93732,34,1),(93737,34,2),(93736,34,3),(93739,34,6),(93738,34,11),(93733,34,13),(93734,34,33),(93731,34,34),(93735,34,70),(93774,35,1),(93779,35,2),(93778,35,3),(93781,35,6),(93780,35,11),(93773,35,35),(93777,35,70),(93775,35,75),(93776,35,76),(94515,36,1),(94517,36,2),(94516,36,3),(94520,36,6),(94519,36,11),(94512,36,36),(94513,36,44),(94514,36,47),(94518,36,70),(94058,37,1),(94063,37,2),(94062,37,3),(94065,37,6),(94064,37,11),(94057,37,37),(94061,37,70),(94059,37,74),(94060,37,76),(94072,38,1),(94075,38,2),(94074,38,3),(94077,38,6),(94076,38,11),(94067,38,13),(94068,38,37),(94066,38,38),(94069,38,64),(94073,38,70),(94071,38,74),(94070,38,76),(93627,39,1),(93633,39,2),(93632,39,3),(93620,39,5),(93635,39,6),(93634,39,11),(93625,39,13),(93624,39,18),(93621,39,21),(93626,39,33),(93619,39,39),(93628,39,53),(93630,39,56),(93622,39,57),(93631,39,70),(93629,39,72),(93623,39,76),(94029,40,1),(94032,40,2),(94031,40,3),(94039,40,6),(94038,40,11),(94034,40,36),(94028,40,40),(94037,40,44),(94036,40,47),(94030,40,49),(94035,40,58),(94033,40,70),(94047,41,1),(94051,41,2),(94050,41,3),(94056,41,6),(94055,41,11),(94041,41,13),(94042,41,35),(94048,41,36),(94043,41,40),(94040,41,41),(94054,41,44),(94053,41,47),(94045,41,49),(94052,41,58),(94049,41,70),(94046,41,75),(94044,41,76),(93746,42,1),(93751,42,2),(93750,42,3),(93754,42,6),(93753,42,11),(93741,42,35),(93744,42,36),(93740,42,42),(93748,42,44),(93752,42,47),(93742,42,49),(93747,42,58),(93749,42,70),(93745,42,75),(93743,42,76),(93759,43,1),(93765,43,2),(93764,43,3),(93771,43,6),(93770,43,11),(93756,43,13),(93758,43,35),(93766,43,36),(93757,43,42),(93755,43,43),(93769,43,44),(93768,43,47),(93760,43,49),(93767,43,58),(93763,43,70),(93762,43,75),(93761,43,76),(93602,44,1),(93603,44,2),(93604,44,3),(93607,44,6),(93606,44,11),(93601,44,44),(93605,44,70),(93611,45,1),(93613,45,2),(93612,45,3),(93616,45,6),(93615,45,11),(93609,45,13),(93610,45,44),(93608,45,45),(93614,45,70),(93814,47,1),(93815,47,2),(93816,47,3),(93819,47,6),(93818,47,11),(93813,47,47),(93817,47,70),(93837,48,1),(93840,48,2),(93839,48,3),(93842,48,6),(93841,48,11),(93832,48,13),(93833,48,35),(93834,48,47),(93831,48,48),(93838,48,70),(93836,48,75),(93835,48,76),(94429,49,1),(94432,49,2),(94431,49,3),(94434,49,6),(94433,49,11),(94425,49,36),(94428,49,44),(94427,49,47),(94424,49,49),(94426,49,58),(94430,49,70),(94475,50,1),(94482,50,2),(94481,50,3),(94484,50,6),(94483,50,11),(94462,50,13),(94474,50,18),(94463,50,21),(94476,50,33),(94464,50,35),(94470,50,36),(94479,50,44),(94478,50,47),(94465,50,49),(94461,50,50),(94473,50,53),(94477,50,56),(94466,50,57),(94469,50,58),(94467,50,59),(94480,50,70),(94472,50,72),(94471,50,75),(94468,50,76),(94329,51,1),(94334,51,2),(94333,51,3),(94336,51,6),(94335,51,11),(94328,51,51),(94332,51,70),(94330,51,74),(94331,51,75),(94346,52,1),(94351,52,2),(94350,52,3),(94354,52,6),(94353,52,11),(94338,52,13),(94348,52,18),(94339,52,19),(94345,52,21),(94340,52,35),(94341,52,51),(94337,52,52),(94347,52,53),(94349,52,70),(94352,52,72),(94343,52,74),(94344,52,75),(94342,52,76),(94079,53,1),(94080,53,2),(94081,53,3),(94084,53,6),(94083,53,11),(94078,53,53),(94082,53,70),(94218,54,1),(94219,54,2),(94220,54,3),(94223,54,6),(94222,54,11),(94217,54,54),(94221,54,70),(94227,55,1),(94229,55,2),(94228,55,3),(94232,55,6),(94231,55,11),(94225,55,13),(94226,55,54),(94224,55,55),(94230,55,70),(93847,56,1),(93848,56,2),(93849,56,3),(93852,56,6),(93851,56,11),(93846,56,56),(93850,56,70),(93858,57,1),(93861,57,2),(93860,57,3),(93863,57,6),(93862,57,11),(93854,57,13),(93855,57,33),(93856,57,56),(93853,57,57),(93859,57,70),(93857,57,76),(94383,58,1),(94384,58,2),(94385,58,3),(94388,58,6),(94387,58,11),(94382,58,58),(94386,58,70),(94393,59,1),(94403,59,2),(94402,59,3),(94412,59,6),(94411,59,11),(94390,59,13),(94400,59,18),(94392,59,21),(94407,59,33),(94394,59,35),(94405,59,36),(94410,59,44),(94409,59,47),(94395,59,49),(94391,59,50),(94399,59,53),(94408,59,56),(94396,59,57),(94406,59,58),(94389,59,59),(94401,59,70),(94398,59,72),(94404,59,75),(94397,59,76),(94443,60,1),(94455,60,2),(94454,60,3),(94436,60,5),(94460,60,6),(94459,60,11),(94440,60,13),(94452,60,18),(94442,60,21),(94441,60,33),(94444,60,35),(94448,60,36),(94458,60,44),(94457,60,47),(94445,60,49),(94437,60,50),(94451,60,53),(94447,60,56),(94438,60,57),(94456,60,58),(94446,60,59),(94435,60,60),(94453,60,70),(94450,60,72),(94449,60,75),(94439,60,76),(94525,61,1),(94529,61,2),(94528,61,3),(94531,61,6),(94530,61,11),(94522,61,13),(94523,61,36),(94524,61,44),(94526,61,47),(94521,61,61),(94527,61,70),(94355,62,62),(93772,64,64),(94363,65,1),(94371,65,2),(94370,65,3),(94381,65,6),(94380,65,11),(94361,65,13),(94374,65,18),(94357,65,19),(94364,65,21),(94376,65,33),(94358,65,35),(94368,65,36),(94379,65,44),(94378,65,47),(94365,65,49),(94359,65,50),(94373,65,53),(94377,65,56),(94366,65,57),(94375,65,58),(94367,65,59),(94356,65,65),(94369,65,70),(94372,65,72),(94362,65,75),(94360,65,76),(94649,66,1),(94648,66,2),(94650,66,3),(94651,66,5),(94652,66,6),(94646,66,9),(94653,66,11),(94654,66,13),(94655,66,15),(94656,66,16),(94657,66,17),(94658,66,18),(94659,66,19),(94660,66,20),(94661,66,21),(94662,66,22),(94663,66,30),(94664,66,31),(94665,66,32),(94666,66,33),(94667,66,34),(94668,66,35),(94669,66,36),(94670,66,37),(94671,66,38),(94672,66,39),(94673,66,40),(94674,66,41),(94675,66,42),(94676,66,43),(94677,66,44),(94678,66,45),(94679,66,47),(94680,66,48),(94681,66,49),(94682,66,50),(94683,66,51),(94684,66,52),(94685,66,53),(94686,66,54),(94687,66,55),(94688,66,56),(94689,66,57),(94690,66,58),(94691,66,59),(94692,66,60),(94693,66,61),(94694,66,64),(94695,66,65),(94645,66,66),(94696,66,67),(94697,66,69),(94698,66,70),(94699,66,71),(94700,66,72),(94701,66,73),(94702,66,74),(94703,66,75),(94704,66,76),(94705,66,101),(94706,66,102),(94647,66,103),(93715,67,1),(93723,67,2),(93722,67,3),(93712,67,5),(93727,67,6),(93726,67,11),(93720,67,13),(93719,67,18),(93714,67,21),(93716,67,33),(93713,67,37),(93724,67,53),(93711,67,67),(93721,67,70),(93725,67,72),(93718,67,74),(93717,67,76),(93824,69,1),(93828,69,2),(93827,69,3),(93830,69,6),(93829,69,11),(93821,69,35),(93822,69,47),(93820,69,69),(93826,69,70),(93823,69,75),(93825,69,76),(94736,70,6),(94735,70,11),(94734,70,70),(93796,71,1),(93799,71,2),(93798,71,3),(93802,71,6),(93801,71,11),(93797,71,58),(93800,71,70),(93795,71,71),(93807,72,1),(93809,72,2),(93808,72,3),(93812,72,6),(93811,72,11),(93804,72,13),(93805,72,18),(93810,72,70),(93803,72,72),(93806,72,76),(93947,73,1),(93952,73,2),(93951,73,3),(93942,73,5),(93957,73,6),(93956,73,11),(93949,73,13),(93953,73,18),(93943,73,19),(93946,73,21),(93945,73,33),(93954,73,53),(93944,73,64),(93950,73,70),(93955,73,72),(93941,73,73),(93948,73,76),(94737,74,74),(93793,75,75),(93794,76,76),(94558,100,1),(94554,100,2),(94540,100,3),(94538,100,5),(94565,100,6),(94557,100,9),(94535,100,11),(94598,100,13),(94576,100,15),(94577,100,16),(94537,100,17),(94594,100,18),(94593,100,19),(94578,100,20),(94592,100,21),(94599,100,22),(94562,100,30),(94563,100,31),(94559,100,32),(94571,100,33),(94541,100,34),(94545,100,35),(94590,100,36),(94568,100,37),(94569,100,38),(94536,100,39),(94566,100,40),(94567,100,41),(94542,100,42),(94543,100,43),(94533,100,44),(94534,100,45),(94551,100,47),(94553,100,48),(94586,100,49),(94588,100,50),(94579,100,51),(94580,100,52),(94570,100,53),(94574,100,54),(94575,100,55),(94555,100,56),(94556,100,57),(94583,100,58),(94584,100,59),(94587,100,60),(94591,100,61),(94581,100,62),(94544,100,64),(94582,100,65),(94596,100,66),(94539,100,67),(94552,100,69),(94600,100,70),(94549,100,71),(94550,100,72),(94561,100,73),(94601,100,74),(94547,100,75),(94548,100,76),(94532,100,100),(94546,100,101),(94585,100,102),(94572,100,103),(94573,100,104),(94564,100,105),(94560,100,106),(94589,100,107),(94597,100,108),(94595,100,109),(93786,101,1),(93790,101,2),(93789,101,3),(93792,101,6),(93791,101,11),(93783,101,13),(93784,101,35),(93788,101,70),(93785,101,75),(93787,101,76),(93782,101,101),(94414,102,1),(94419,102,2),(94418,102,3),(94423,102,6),(94422,102,11),(94415,102,13),(94416,102,35),(94417,102,70),(94420,102,75),(94421,102,76),(94413,102,102),(94087,103,1),(94088,103,2),(94089,103,3),(94090,103,5),(94091,103,6),(94146,103,9),(94092,103,11),(94093,103,13),(94094,103,15),(94095,103,16),(94096,103,17),(94097,103,18),(94098,103,19),(94099,103,20),(94100,103,21),(94101,103,22),(94102,103,30),(94103,103,31),(94104,103,32),(94105,103,33),(94106,103,34),(94107,103,35),(94108,103,36),(94109,103,37),(94110,103,38),(94111,103,39),(94112,103,40),(94113,103,41),(94114,103,42),(94115,103,43),(94116,103,44),(94117,103,45),(94118,103,47),(94119,103,48),(94120,103,49),(94121,103,50),(94122,103,51),(94123,103,52),(94124,103,53),(94125,103,54),(94126,103,55),(94127,103,56),(94128,103,57),(94129,103,58),(94130,103,59),(94131,103,60),(94132,103,61),(94133,103,64),(94134,103,65),(94135,103,67),(94136,103,69),(94137,103,70),(94138,103,71),(94139,103,72),(94140,103,73),(94141,103,74),(94142,103,75),(94143,103,76),(94144,103,101),(94145,103,102),(94086,103,103),(94155,104,1),(94154,104,2),(94153,104,3),(94152,104,5),(94156,104,6),(94148,104,9),(94157,104,11),(94158,104,13),(94159,104,15),(94160,104,16),(94161,104,17),(94162,104,18),(94163,104,19),(94164,104,20),(94165,104,21),(94166,104,22),(94167,104,30),(94168,104,31),(94169,104,32),(94170,104,33),(94171,104,34),(94172,104,35),(94173,104,36),(94174,104,37),(94175,104,38),(94176,104,39),(94177,104,40),(94178,104,41),(94179,104,42),(94180,104,43),(94181,104,44),(94182,104,45),(94183,104,47),(94184,104,48),(94185,104,49),(94186,104,50),(94187,104,51),(94188,104,52),(94189,104,53),(94190,104,54),(94191,104,55),(94192,104,56),(94193,104,57),(94194,104,58),(94195,104,59),(94196,104,60),(94197,104,61),(94213,104,62),(94198,104,64),(94199,104,65),(94149,104,66),(94200,104,67),(94201,104,69),(94202,104,70),(94203,104,71),(94204,104,72),(94205,104,73),(94206,104,74),(94207,104,75),(94208,104,76),(94150,104,100),(94209,104,101),(94210,104,102),(94151,104,103),(94147,104,104),(94212,104,105),(94211,104,106),(94214,104,107),(94216,104,108),(94215,104,109),(94026,105,105),(93940,106,6),(93939,106,11),(93938,106,106),(94494,107,1),(94506,107,2),(94505,107,3),(94487,107,5),(94511,107,6),(94510,107,11),(94491,107,13),(94503,107,18),(94493,107,21),(94492,107,33),(94495,107,35),(94499,107,36),(94509,107,44),(94508,107,47),(94496,107,49),(94488,107,50),(94502,107,53),(94498,107,56),(94489,107,57),(94507,107,58),(94497,107,59),(94486,107,60),(94504,107,70),(94501,107,72),(94500,107,75),(94490,107,76),(94485,107,107),(94708,108,1),(94709,108,2),(94710,108,3),(94713,108,6),(94712,108,11),(94711,108,70),(94707,108,108),(94639,109,1),(94641,109,2),(94640,109,3),(94644,109,6),(94643,109,11),(94636,109,13),(94637,109,18),(94642,109,70),(94638,109,76),(94635,109,109); /*!40000 ALTER TABLE `roleRole` ENABLE KEYS */; UNLOCK TABLES; @@ -140,9 +140,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-05-04 15:58:27 +-- Dump completed on 2022-06-23 12:13:31 USE `salix`; --- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.8-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: salix -- ------------------------------------------------------ @@ -164,7 +164,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'),(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'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','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'),(165,'TicketDms','*','*','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'),(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','employee'),(270,'SupplierAddress','*','*','ALLOW','ROLE','employee'),(271,'SalesMonitor','*','*','ALLOW','ROLE','employee'),(272,'InvoiceInLog','*','*','ALLOW','ROLE','employee'),(273,'InvoiceInTax','*','*','ALLOW','ROLE','administrative'),(274,'InvoiceInLog','*','READ','ALLOW','ROLE','administrative'),(275,'InvoiceOut','createManualInvoice','WRITE','ALLOW','ROLE','invoicing'),(276,'InvoiceOut','globalInvoicing','WRITE','ALLOW','ROLE','invoicing'),(277,'Role','*','*','ALLOW','ROLE','it'),(278,'RoleInherit','*','WRITE','ALLOW','ROLE','grant'),(279,'MailAlias','*','*','ALLOW','ROLE','marketing'),(282,'UserAccount','*','WRITE','ALLOW','ROLE','it'),(283,'EntryObservation','*','*','ALLOW','ROLE','buyer'),(284,'LdapConfig','*','*','ALLOW','ROLE','sysadmin'),(285,'SambaConfig','*','*','ALLOW','ROLE','sysadmin'),(286,'ACL','*','*','ALLOW','ROLE','developer'),(287,'AccessToken','*','*','ALLOW','ROLE','developer'),(288,'MailAliasAccount','*','*','ALLOW','ROLE','marketing'),(289,'MailAliasAccount','*','*','ALLOW','ROLE','hr'),(290,'MailAlias','*','*','ALLOW','ROLE','hr'),(291,'MailForward','*','*','ALLOW','ROLE','marketing'),(292,'MailForward','*','*','ALLOW','ROLE','hr'),(293,'RoleInherit','*','*','ALLOW','ROLE','it'),(294,'RoleRole','*','*','ALLOW','ROLE','it'),(295,'AccountConfig','*','*','ALLOW','ROLE','sysadmin'),(296,'Collection','*','READ','ALLOW','ROLE','employee'),(297,'Sale','payBack','WRITE','ALLOW','ROLE','employee'),(298,'InvoiceInDueDay','*','*','ALLOW','ROLE','administrative'),(299,'Collection','setSaleQuantity','*','ALLOW','ROLE','employee'),(300,'Docuware','*','*','ALLOW','ROLE','employee'),(301,'Agency','*','READ','ALLOW','ROLE','employee'),(302,'AgencyTerm','*','*','ALLOW','ROLE','administrative'),(303,'ClaimLog','*','READ','ALLOW','ROLE','claimManager'),(304,'Edi','updateData','WRITE','ALLOW','ROLE','employee'),(305,'EducationLevel','*','*','ALLOW','ROLE','employee'),(306,'InvoiceInIntrastat','*','*','ALLOW','ROLE','employee'),(307,'SupplierAgencyTerm','*','*','ALLOW','ROLE','administrative'),(308,'InvoiceInIntrastat','*','*','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'),(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'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','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'),(165,'TicketDms','*','*','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'),(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','employee'),(270,'SupplierAddress','*','*','ALLOW','ROLE','employee'),(271,'SalesMonitor','*','*','ALLOW','ROLE','employee'),(272,'InvoiceInLog','*','*','ALLOW','ROLE','employee'),(273,'InvoiceInTax','*','*','ALLOW','ROLE','administrative'),(274,'InvoiceInLog','*','READ','ALLOW','ROLE','administrative'),(275,'InvoiceOut','createManualInvoice','WRITE','ALLOW','ROLE','invoicing'),(276,'InvoiceOut','globalInvoicing','WRITE','ALLOW','ROLE','invoicing'),(277,'Role','*','*','ALLOW','ROLE','it'),(278,'RoleInherit','*','WRITE','ALLOW','ROLE','grant'),(279,'MailAlias','*','*','ALLOW','ROLE','marketing'),(282,'UserAccount','*','WRITE','ALLOW','ROLE','it'),(283,'EntryObservation','*','*','ALLOW','ROLE','buyer'),(284,'LdapConfig','*','*','ALLOW','ROLE','sysadmin'),(285,'SambaConfig','*','*','ALLOW','ROLE','sysadmin'),(286,'ACL','*','*','ALLOW','ROLE','developer'),(287,'AccessToken','*','*','ALLOW','ROLE','developer'),(288,'MailAliasAccount','*','*','ALLOW','ROLE','marketing'),(289,'MailAliasAccount','*','*','ALLOW','ROLE','hr'),(290,'MailAlias','*','*','ALLOW','ROLE','hr'),(291,'MailForward','*','*','ALLOW','ROLE','marketing'),(292,'MailForward','*','*','ALLOW','ROLE','hr'),(293,'RoleInherit','*','*','ALLOW','ROLE','it'),(294,'RoleRole','*','*','ALLOW','ROLE','it'),(295,'AccountConfig','*','*','ALLOW','ROLE','sysadmin'),(296,'Collection','*','READ','ALLOW','ROLE','employee'),(297,'Sale','refund','WRITE','ALLOW','ROLE','employee'),(298,'InvoiceInDueDay','*','*','ALLOW','ROLE','administrative'),(299,'Collection','setSaleQuantity','*','ALLOW','ROLE','employee'),(300,'Docuware','*','*','ALLOW','ROLE','employee'),(301,'Agency','*','READ','ALLOW','ROLE','employee'),(302,'AgencyTerm','*','*','ALLOW','ROLE','administrative'),(303,'ClaimLog','*','READ','ALLOW','ROLE','claimManager'),(304,'Edi','updateData','WRITE','ALLOW','ROLE','employee'),(305,'EducationLevel','*','*','ALLOW','ROLE','employee'),(306,'InvoiceInIntrastat','*','*','ALLOW','ROLE','employee'),(307,'SupplierAgencyTerm','*','*','ALLOW','ROLE','administrative'),(308,'InvoiceInIntrastat','*','*','ALLOW','ROLE','employee'),(309,'Zone','getZoneClosing','*','ALLOW','ROLE','employee'),(310,'ExpeditionState','*','READ','ALLOW','ROLE','employee'),(311,'Expense','*','READ','ALLOW','ROLE','employee'),(312,'Expense','*','WRITE','ALLOW','ROLE','administrative'),(313,'Sale','refundAll','WRITE','ALLOW','ROLE','employee'),(314,'SupplierActivity','*','READ','ALLOW','ROLE','employee'),(315,'SupplierActivity','*','WRITE','ALLOW','ROLE','administrative'),(316,'Dms','deleteTrashFiles','WRITE','ALLOW','ROLE','employee'),(317,'ClientUnpaid','*','*','ALLOW','ROLE','administrative'),(318,'MdbVersion','*','*','ALLOW','ROLE','developer'); /*!40000 ALTER TABLE `ACL` ENABLE KEYS */; UNLOCK TABLES; @@ -206,9 +206,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-05-04 15:58:28 +-- Dump completed on 2022-06-23 12:13:32 USE `vn`; --- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.8-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: vn -- ------------------------------------------------------ @@ -320,7 +320,7 @@ UNLOCK TABLES; LOCK TABLES `claimResponsible` WRITE; /*!40000 ALTER TABLE `claimResponsible` DISABLE KEYS */; -INSERT INTO `claimResponsible` VALUES (1,'Compradores',0),(2,'Proveedor',0),(3,'Entradores',0),(4,'Camareros',0),(6,'Sacadores',0),(7,'Revisadores',0),(8,'Calidad general',0),(9,'Encajadores',0),(11,'Comerciales',1),(12,'Clientes',1),(13,'Administración',0),(14,'Agencia',0),(15,'Repartidores',0),(16,'Informatica',0),(17,'Transp.origen',0),(18,'Confeccion',0),(19,'OTROS',0),(21,'Gerencia',0),(22,'Paletizadores',0),(23,'Preparación Previa',0),(24,'Almacén PCA',0),(25,'Huelga',0); +INSERT INTO `claimResponsible` VALUES (1,'Compradores',0),(2,'Proveedor',0),(3,'Entradores',0),(4,'Camareros',0),(6,'Sacadores',0),(7,'Revisadores',0),(8,'Calidad general',0),(9,'Encajadores',0),(10,'Clima',0),(11,'Comerciales',1),(12,'Clientes',1),(13,'Administración',0),(14,'Agencia',0),(15,'Repartidores',0),(16,'Informatica',0),(17,'Transp.origen',0),(18,'Confeccion',0),(19,'OTROS',0),(21,'Gerencia',0),(22,'Paletizadores',0),(23,'Preparación Previa',0),(24,'Almacén PCA',0),(25,'Huelga',0); /*!40000 ALTER TABLE `claimResponsible` ENABLE KEYS */; UNLOCK TABLES; @@ -390,7 +390,7 @@ UNLOCK TABLES; LOCK TABLES `department` WRITE; /*!40000 ALTER TABLE `department` DISABLE KEYS */; -INSERT INTO `department` VALUES (1,NULL,'VERDNATURA',1,94,763,0,NULL,NULL,NULL,0,0,0,30,NULL,'/',NULL,0,NULL,0,0,0,0,NULL),(22,NULL,'COMPRAS',2,3,NULL,72,596,2,5,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(23,NULL,'CAMARA',13,14,NULL,72,3758,2,6,1,1,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,1,NULL),(31,'IT','INFORMATICA',4,5,NULL,72,127,3,9,0,0,1,0,1,'/1/','informatica-cau',1,NULL,1,0,0,0,NULL),(34,NULL,'CONTABILIDAD',6,7,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(35,NULL,'FINANZAS',8,9,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(36,NULL,'LABORAL',10,11,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(37,NULL,'PRODUCCION',12,27,NULL,72,3758,3,11,1,1,1,7,1,'/1/',NULL,0,NULL,0,1,1,1,NULL),(38,NULL,'SACADO',15,16,NULL,72,230,4,14,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(39,NULL,'ENCAJADO',17,18,NULL,72,3758,4,12,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(41,NULL,'ADMINISTRACION',28,29,NULL,72,599,3,8,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(43,'VT','VENTAS',30,49,NULL,0,NULL,NULL,NULL,0,0,1,9,1,'/1/',NULL,1,'',1,0,0,0,NULL),(44,NULL,'GERENCIA',50,51,NULL,72,300,2,7,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(45,NULL,'LOGISTICA',52,53,NULL,72,596,3,19,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(46,NULL,'REPARTO',54,55,NULL,72,659,3,10,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL),(48,NULL,'ALMACENAJE',56,57,NULL,0,3758,NULL,NULL,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(49,NULL,'PROPIEDAD',58,59,NULL,72,1008,1,1,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(52,NULL,'CARGA AEREA',60,61,NULL,72,163,4,28,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(53,NULL,'MARKETING Y COMUNICACIÓN',62,63,NULL,72,1238,0,0,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(54,NULL,'ORNAMENTALES',64,65,NULL,72,433,3,21,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(55,NULL,'TALLER NATURAL',66,67,3366,72,3758,2,23,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,1,0,1118),(56,NULL,'TALLER ARTIFICIAL',68,69,8470,72,1780,2,24,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,1,0,1927),(58,NULL,'CAMPOS',70,71,NULL,72,3758,2,2,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(59,NULL,'MANTENIMIENTO',72,73,NULL,72,1907,4,16,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(60,NULL,'RECLAMACIONES',74,75,NULL,72,563,3,20,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(61,NULL,'VNH',76,77,NULL,73,1297,3,17,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(63,NULL,'VENTAS FRANCIA',31,32,NULL,72,277,2,27,0,0,2,0,43,'/1/43/',NULL,0,NULL,0,0,0,0,NULL),(66,NULL,'VERDNAMADRID',78,79,NULL,72,163,3,18,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(68,NULL,'COMPLEMENTOS',19,20,NULL,72,617,3,26,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(69,NULL,'VERDNABARNA',80,81,NULL,74,432,3,22,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(80,NULL,'EQUIPO J VALLES',33,34,NULL,72,693,3,4,0,0,2,0,43,'/1/43/','jvp_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(86,NULL,'LIMPIEZA',82,83,NULL,72,599,0,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(89,NULL,'COORDINACION',84,85,NULL,0,3758,NULL,NULL,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(90,NULL,'TRAILER',86,87,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(91,NULL,'ARTIFICIAL',21,22,NULL,0,3758,NULL,NULL,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(92,NULL,'EQUIPO SILVERIO',35,36,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','sdc_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(93,NULL,'CONFECCION',88,89,NULL,0,3758,NULL,NULL,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,1,0,NULL),(94,NULL,'EQUIPO J BROCAL',37,38,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','jes_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(95,NULL,'EQUIPO C ZAMBRANO',39,40,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','czg_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(96,NULL,'EQUIPO C LOPEZ',41,42,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','cla_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(115,NULL,'EQUIPO CLAUDI',43,44,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','csr_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(123,NULL,'EQUIPO ELENA BASCUÑANA',45,46,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','ebt_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(124,NULL,'CONTROL INTERNO',90,91,NULL,72,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(125,NULL,'EQUIPO MIRIAM MAR',47,48,NULL,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','mir_equipo',1,'direccioncomercial@verdnatura.es',1,0,0,0,NULL),(126,NULL,'PRESERVADO',92,93,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,1,0,NULL),(128,NULL,'PALETIZADO',23,24,NULL,0,NULL,NULL,NULL,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(130,NULL,'REVISION',25,26,NULL,0,NULL,NULL,NULL,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL); +INSERT INTO `department` VALUES (1,NULL,'VERDNATURA',1,94,763,0,NULL,NULL,NULL,0,0,0,30,NULL,'/',NULL,0,NULL,0,0,0,0,NULL),(22,NULL,'COMPRAS',2,3,NULL,72,596,2,5,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(23,NULL,'CAMARA',13,14,NULL,72,3758,2,6,1,1,2,0,37,'/1/37/',NULL,0,NULL,0,1,1,1,NULL),(31,'IT','INFORMATICA',4,5,NULL,72,127,3,9,0,0,1,0,1,'/1/','informatica-cau',1,NULL,1,0,0,0,NULL),(34,NULL,'CONTABILIDAD',6,7,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(35,NULL,'FINANZAS',8,9,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(36,NULL,'LABORAL',10,11,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(37,NULL,'PRODUCCION',12,27,NULL,72,3758,3,11,1,1,1,7,1,'/1/',NULL,0,NULL,0,1,1,1,NULL),(38,NULL,'SACADO',15,16,NULL,72,230,4,14,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(39,NULL,'ENCAJADO',17,18,NULL,72,3758,4,12,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(41,NULL,'ADMINISTRACION',28,29,NULL,72,599,3,8,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(43,'VT','VENTAS',30,49,NULL,0,NULL,NULL,NULL,0,0,1,9,1,'/1/',NULL,1,'',1,0,0,0,NULL),(44,NULL,'GERENCIA',50,51,NULL,72,300,2,7,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(45,NULL,'LOGISTICA',52,53,NULL,72,596,3,19,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(46,NULL,'REPARTO',54,55,NULL,72,659,3,10,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,0,0,NULL),(48,NULL,'ALMACENAJE',56,57,NULL,0,3758,NULL,NULL,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(49,NULL,'PROPIEDAD',58,59,NULL,72,1008,1,1,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(52,NULL,'CARGA AEREA',60,61,NULL,72,163,4,28,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(53,NULL,'MARKETING Y COMUNICACIÓN',62,63,NULL,72,1238,0,0,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(54,NULL,'ORNAMENTALES',64,65,NULL,72,433,3,21,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(55,NULL,'TALLER NATURAL',66,67,3366,72,3758,2,23,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,1,0,1118),(56,NULL,'TALLER ARTIFICIAL',68,69,8470,72,1780,2,24,0,0,1,0,1,'/1/',NULL,0,NULL,0,1,1,0,1927),(58,NULL,'CAMPOS',70,71,NULL,72,3758,2,2,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(59,NULL,'MANTENIMIENTO',72,73,NULL,72,1907,4,16,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(60,NULL,'RECLAMACIONES',74,75,NULL,72,563,3,20,0,0,1,0,1,'/1/',NULL,1,NULL,1,0,0,0,NULL),(61,NULL,'VNH',76,77,NULL,73,1297,3,17,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(63,NULL,'VENTAS FRANCIA',31,32,NULL,72,277,2,27,0,0,2,0,43,'/1/43/',NULL,0,NULL,0,0,0,0,NULL),(66,NULL,'VERDNAMADRID',78,79,NULL,72,163,3,18,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(68,NULL,'COMPLEMENTOS',19,20,NULL,72,617,3,26,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(69,NULL,'VERDNABARNA',80,81,NULL,74,432,3,22,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(80,NULL,'EQUIPO J VALLES',33,34,4250,72,693,3,4,0,0,2,0,43,'/1/43/','jvp_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL),(86,NULL,'LIMPIEZA',82,83,NULL,72,599,0,0,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(89,NULL,'COORDINACION',84,85,NULL,0,3758,NULL,NULL,1,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(90,NULL,'TRAILER',86,87,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,0,0,NULL),(91,NULL,'ARTIFICIAL',21,22,NULL,0,3758,NULL,NULL,1,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(92,NULL,'EQUIPO SILVERIO',35,36,1203,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','sdc_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL),(93,NULL,'CONFECCION',88,89,NULL,0,3758,NULL,NULL,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,1,0,NULL),(94,NULL,'EQUIPO J BROCAL',37,38,3797,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','jes_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL),(95,NULL,'EQUIPO C ZAMBRANO',39,40,4667,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','czg_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL),(96,NULL,'EQUIPO C LOPEZ',41,42,4661,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','cla_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL),(115,NULL,'EQUIPO CLAUDI',43,44,3810,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','csr_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL),(123,NULL,'EQUIPO ELENA BASCUÑANA',45,46,7102,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','ebt_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL),(124,NULL,'CONTROL INTERNO',90,91,NULL,72,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,0,NULL,1,0,0,0,NULL),(125,NULL,'EQUIPO MIRIAM MAR',47,48,1118,0,NULL,NULL,NULL,0,0,2,0,43,'/1/43/','mir_equipo',1,'gestioncomercial@verdnatura.es',1,0,0,0,NULL),(126,NULL,'PRESERVADO',92,93,NULL,0,NULL,NULL,NULL,0,0,1,0,1,'/1/',NULL,0,NULL,0,0,1,0,NULL),(128,NULL,'PALETIZADO',23,24,NULL,0,NULL,NULL,NULL,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL),(130,NULL,'REVISION',25,26,NULL,0,NULL,NULL,NULL,0,0,2,0,37,'/1/37/',NULL,0,NULL,0,0,0,0,NULL); /*!40000 ALTER TABLE `department` ENABLE KEYS */; UNLOCK TABLES; @@ -430,7 +430,7 @@ UNLOCK TABLES; LOCK TABLES `state` WRITE; /*!40000 ALTER TABLE `state` DISABLE KEYS */; -INSERT INTO `state` VALUES (1,'Arreglar',2,0,'FIXING',NULL,1,0,0,0,0,0,0,4,1,'alert'),(2,'Libre',2,0,'FREE',NULL,2,1,0,0,0,1,0,4,1,'notice'),(3,'OK',3,0,'OK',3,28,1,0,0,0,1,1,3,0,'success'),(4,'Impreso',4,0,'PRINTED',2,29,1,0,1,0,0,1,2,0,'success'),(5,'Preparación',6,1,'ON_PREPARATION',7,5,0,0,0,2,0,0,2,0,'warning'),(6,'En Revisión',7,1,'ON_CHECKING',NULL,6,0,1,0,3,0,0,1,0,'warning'),(7,'Sin Acabar',1,0,'NOT_READY',NULL,7,0,0,0,0,0,0,4,1,'alert'),(8,'Revisado',8,1,'CHECKED',NULL,8,0,1,0,3,0,0,1,0,'warning'),(9,'Encajando',9,2,'PACKING',NULL,9,0,1,0,0,0,0,1,0,NULL),(10,'Encajado',10,2,'PACKED',NULL,10,0,1,0,0,0,0,0,0,NULL),(11,'Facturado',0,3,'INVOICED',NULL,11,0,1,0,0,0,0,0,0,NULL),(12,'Bloqueado',0,0,'BLOCKED',NULL,12,0,0,0,0,0,0,4,1,'alert'),(13,'En Reparto',11,3,'ON_DELIVERY',NULL,13,0,1,0,0,0,0,0,0,NULL),(14,'Preparado',6,1,'PREPARED',NULL,14,0,1,0,2,0,0,1,0,'warning'),(15,'Pte Recogida',12,3,'WAITING_FOR_PICKUP',NULL,15,0,1,0,0,0,0,0,0,NULL),(16,'Entregado',13,3,'DELIVERED',NULL,16,0,1,0,0,0,0,0,0,NULL),(20,'Asignado',4,0,'PICKER_DESIGNED',NULL,20,1,0,0,0,0,0,2,0,'success'),(21,'Retornado',4,1,'PRINTED_BACK',6,21,0,0,0,0,0,0,2,0,'success'),(22,'Pte. Ampliar',2,0,'EXPANDABLE',NULL,22,0,0,0,0,0,0,4,1,'alert'),(23,'URGENTE',5,1,'LAST_CALL',NULL,23,1,0,1,0,0,0,4,1,'success'),(24,'Encadenado',4,0,'CHAINED',4,24,0,0,0,0,0,0,3,1,'success'),(25,'Embarcando',3,0,'BOARDING',5,25,1,0,0,0,0,0,3,0,'alert'),(26,'Prep Previa',5,1,'PREVIOUS_PREPARATION',1,28,0,0,0,1,0,0,2,0,'warning'),(27,'Prep Asistida',5,1,'ASSISTED_PREPARATION',7,27,0,0,0,0,0,0,2,0,'success'),(28,'Previa OK',3,1,'OK PREVIOUS',3,28,0,0,0,1,1,1,3,0,'warning'),(29,'Previa Impreso',4,1,'PRINTED PREVIOUS',2,29,0,0,1,1,0,1,3,0,'success'),(30,'Embarcado',4,1,'BOARD',5,30,0,0,0,2,0,0,3,0,'success'),(31,'Polizon Impreso',4,1,'PRINTED STOWAWAY',2,29,1,0,1,0,0,1,3,0,'success'),(32,'Polizon OK',3,1,'OK STOWAWAY',3,31,1,0,0,1,1,1,3,0,'warning'),(33,'Auto_Impreso',4,0,'PRINTED_AUTO',2,29,1,0,1,0,0,1,2,0,'success'),(34,'Pte Pago',3,0,'WAITING_FOR_PAYMENT',NULL,34,0,0,0,0,0,0,4,1,'alert'),(35,'Semi-Encajado',9,2,'HALF_PACKED',NULL,10,0,1,0,0,0,0,1,0,NULL),(36,'Control Previa',3,1,'PREVIOUS_CONTROL',1,36,0,1,0,4,0,1,3,0,'warning'); +INSERT INTO `state` VALUES (1,'Arreglar',2,0,'FIXING',NULL,1,0,0,0,0,0,0,4,1,'alert'),(2,'Libre',2,0,'FREE',NULL,2,1,0,0,0,1,0,4,1,'notice'),(3,'OK',3,0,'OK',3,28,1,0,0,0,1,1,3,0,'success'),(4,'Impreso',4,0,'PRINTED',2,29,1,0,1,0,0,1,2,0,'success'),(5,'Preparación',6,1,'ON_PREPARATION',7,5,0,0,0,2,0,0,2,0,'warning'),(6,'En Revisión',7,1,'ON_CHECKING',NULL,6,0,1,0,3,0,0,1,0,'warning'),(7,'Sin Acabar',1,0,'NOT_READY',NULL,7,0,0,0,0,0,0,4,1,'alert'),(8,'Revisado',8,1,'CHECKED',NULL,8,0,1,0,3,0,0,1,0,'warning'),(9,'Encajando',9,2,'PACKING',NULL,9,0,1,0,0,0,0,1,0,NULL),(10,'Encajado',10,2,'PACKED',NULL,10,0,1,0,0,0,0,0,0,NULL),(11,'Facturado',0,3,'INVOICED',NULL,11,0,1,0,0,0,0,0,0,NULL),(12,'Bloqueado',0,0,'BLOCKED',NULL,12,0,0,0,0,0,0,4,1,'alert'),(13,'En Reparto',11,3,'ON_DELIVERY',NULL,13,0,1,0,0,0,0,0,0,NULL),(14,'Preparado',6,1,'PREPARED',NULL,14,0,1,0,2,0,0,1,0,'warning'),(15,'Pte Recogida',12,3,'WAITING_FOR_PICKUP',NULL,15,0,1,0,0,0,0,0,0,NULL),(16,'Entregado',13,3,'DELIVERED',NULL,16,0,1,0,0,0,0,0,0,NULL),(20,'Asignado',4,0,'PICKER_DESIGNED',NULL,20,1,0,0,0,0,0,2,0,'success'),(21,'Retornado',4,1,'PRINTED_BACK',6,21,0,0,0,0,0,0,2,0,'success'),(22,'Pte. Ampliar',2,0,'EXPANDABLE',NULL,22,0,0,0,0,0,0,4,1,'alert'),(23,'URGENTE',5,1,'LAST_CALL',NULL,23,1,0,1,0,0,0,4,1,'success'),(24,'Encadenado',4,0,'CHAINED',4,24,0,0,0,0,0,0,3,1,'success'),(25,'Embarcando',3,0,'BOARDING',5,25,1,0,0,0,0,0,3,0,'alert'),(26,'Prep Previa',5,1,'PREVIOUS_PREPARATION',1,28,0,0,0,1,0,0,2,0,'warning'),(27,'Prep Asistida',5,1,'ASSISTED_PREPARATION',7,27,0,0,0,0,0,0,2,0,'success'),(28,'Previa OK',3,1,'OK PREVIOUS',3,28,1,0,0,1,1,1,3,0,'warning'),(29,'Previa Impreso',4,0,'PRINTED PREVIOUS',2,29,1,0,1,0,0,1,2,0,'success'),(30,'Embarcado',4,1,'BOARD',5,30,0,0,0,2,0,0,3,0,'success'),(31,'Polizon Impreso',4,1,'PRINTED STOWAWAY',2,29,1,0,1,0,0,1,2,0,'success'),(32,'Polizon OK',3,1,'OK STOWAWAY',3,31,1,0,0,1,1,1,3,0,'warning'),(33,'Auto_Impreso',4,0,'PRINTED_AUTO',2,29,1,0,1,0,0,1,2,0,'success'),(34,'Pte Pago',3,0,'WAITING_FOR_PAYMENT',NULL,34,0,0,0,0,0,0,4,1,'alert'),(35,'Semi-Encajado',9,2,'HALF_PACKED',NULL,10,0,1,0,0,0,0,1,0,NULL),(36,'Previa Revisando',3,1,'PREVIOUS_CONTROL',1,29,0,1,0,4,0,1,3,0,'warning'),(37,'Previa Revisado',3,1,'PREVIOUS_CONTROLLED',1,29,0,1,0,4,0,1,3,0,'warning'); /*!40000 ALTER TABLE `state` ENABLE KEYS */; UNLOCK TABLES; @@ -460,9 +460,19 @@ UNLOCK TABLES; LOCK TABLES `volumeConfig` WRITE; /*!40000 ALTER TABLE `volumeConfig` DISABLE KEYS */; -INSERT INTO `volumeConfig` VALUES (2.67,1.60,0.8,150,0.30,120,57,2.0,75,200,50); +INSERT INTO `volumeConfig` VALUES (2.67,1.60,0.8,150,0.30,120,57,2.0,150,200,50); /*!40000 ALTER TABLE `volumeConfig` ENABLE KEYS */; UNLOCK TABLES; + +-- +-- Dumping data for table `workCenter` +-- + +LOCK TABLES `workCenter` WRITE; +/*!40000 ALTER TABLE `workCenter` DISABLE KEYS */; +INSERT INTO `workCenter` VALUES (1,'Silla',20,859,1,'Av espioca 100',552703),(2,'Mercaflor',19,NULL,NULL,NULL,NULL),(3,'Marjales',26,20008,NULL,NULL,NULL),(4,'VNH',NULL,NULL,NULL,NULL,NULL),(5,'Madrid',28,2869,5,'Av constitución 3',554145),(6,'Vilassar',88,88038,NULL,'Cami del Crist, 33',556412),(7,'Tenerife',NULL,NULL,NULL,NULL,NULL),(8,'Silla-Agrario',26,NULL,NULL,NULL,NULL),(9,'Algemesi',20,1354,60,'Fenollars, 2',523549); +/*!40000 ALTER TABLE `workCenter` ENABLE KEYS */; +UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; @@ -472,9 +482,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-05-04 15:58:28 +-- Dump completed on 2022-06-23 12:13:32 USE `cache`; --- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.8-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: cache -- ------------------------------------------------------ @@ -508,9 +518,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-05-04 15:58:28 +-- Dump completed on 2022-06-23 12:13:32 USE `hedera`; --- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.8-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: hedera -- ------------------------------------------------------ @@ -592,7 +602,7 @@ UNLOCK TABLES; LOCK TABLES `menu` WRITE; /*!40000 ALTER TABLE `menu` DISABLE KEYS */; -INSERT INTO `menu` VALUES (1,'Home','cms/home',6,NULL,1),(2,'Orders',NULL,11,NULL,1),(3,'Catalog','ecomerce/catalog',6,NULL,2),(5,'About',NULL,6,NULL,2),(6,'Location','cms/location',6,5,2),(7,'Administration',NULL,1,NULL,2),(8,'Users','admin/users',1,7,2),(9,'Connections','admin/connections',1,7,2),(11,'Agencies','agencies/packages',3,NULL,2),(12,'News','news/news',1,7,3),(14,'Why','cms/why',6,5,2),(15,'Photos','admin/photos',1,7,3),(16,'Training','cms/training',6,NULL,2),(17,'Configuration',NULL,11,NULL,3),(19,'Control panel','admin/links',1,7,1),(20,'About us','cms/about',6,5,1),(21,'Basket','ecomerce/basket',11,NULL,1),(22,'Last orders','ecomerce/orders',11,2,2),(23,'Invoices','ecomerce/invoices',11,2,2),(24,'Account','account/conf',11,17,1),(25,'Addresses','account/address-list',11,17,2),(26,'Shelves','reports/shelves',1,29,1),(27,'Items list','reports/items-form',1,29,1),(28,'Visits','admin/visits',1,7,2),(29,'Reports',NULL,1,NULL,2),(30,'Items','admin/items',1,7,3); +INSERT INTO `menu` VALUES (1,'Home','cms/home',6,NULL,1),(2,'Orders',NULL,11,NULL,1),(3,'Catalog','ecomerce/catalog',6,NULL,2),(5,'About',NULL,6,NULL,2),(6,'Location','cms/location',6,5,2),(7,'Administration',NULL,1,NULL,2),(8,'Users','admin/users',1,7,2),(9,'Connections','admin/connections',1,7,2),(11,'Agencies','agencies/packages',3,NULL,2),(12,'News','news/news',1,7,3),(14,'Why','cms/why',6,5,2),(15,'Photos','admin/photos',1,7,3),(17,'Configuration',NULL,11,NULL,3),(19,'Control panel','admin/links',1,7,1),(20,'About us','cms/about',6,5,1),(21,'Basket','ecomerce/basket',11,NULL,1),(22,'Last orders','ecomerce/orders',11,2,2),(23,'Invoices','ecomerce/invoices',11,2,2),(24,'Account','account/conf',11,17,1),(25,'Addresses','account/address-list',11,17,2),(26,'Shelves','reports/shelves',1,29,1),(27,'Items list','reports/items-form',1,29,1),(28,'Visits','admin/visits',1,7,2),(29,'Reports',NULL,1,NULL,2),(30,'Items','admin/items',1,7,3); /*!40000 ALTER TABLE `menu` ENABLE KEYS */; UNLOCK TABLES; @@ -632,7 +642,7 @@ UNLOCK TABLES; LOCK TABLES `restPriv` WRITE; /*!40000 ALTER TABLE `restPriv` DISABLE KEYS */; -INSERT INTO `restPriv` VALUES (1,'tpv/transaction',2),(2,'dms/add',1),(3,'image/upload',1),(4,'misc/sms',1),(5,'core/supplant',1),(6,'core/sync-user',5),(7,'core/set-password',1),(8,'core/change-password',11),(9,'misc/access-version',9); +INSERT INTO `restPriv` VALUES (1,'tpv/transaction',2),(3,'image/upload',1),(4,'misc/sms',1),(5,'core/supplant',104),(7,'core/set-password',5),(9,'misc/access-version',NULL),(10,'core/captcha',NULL),(11,'core/log',NULL),(12,'core/login',NULL),(13,'core/logout',NULL),(14,'core/query',NULL),(15,'core/recover-password',NULL),(16,'core/restore-password',NULL),(17,'dms/invoice',2),(18,'image/thumb',NULL),(19,'misc/contact',NULL),(20,'misc/production',NULL),(21,'tpv/confirm-post',NULL),(22,'tpv/confirm-soap',NULL),(23,'client/supplant',18),(24,'client/supplant',35); /*!40000 ALTER TABLE `restPriv` ENABLE KEYS */; UNLOCK TABLES; @@ -674,9 +684,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-05-04 15:58:28 +-- Dump completed on 2022-06-23 12:13:33 USE `postgresql`; --- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.8-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: postgresql -- ------------------------------------------------------ @@ -741,16 +751,6 @@ LOCK TABLES `profile_type` WRITE; INSERT INTO `profile_type` VALUES (1,'Laboral'),(2,'Personal'),(3,'Cliente'),(4,'Proveedor'),(5,'Banco'),(6,'Patronal'); /*!40000 ALTER TABLE `profile_type` ENABLE KEYS */; UNLOCK TABLES; - --- --- Dumping data for table `workcenter` --- - -LOCK TABLES `workcenter` WRITE; -/*!40000 ALTER TABLE `workcenter` DISABLE KEYS */; -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,2869,5,'Av constitución 3',554145),(6,'Vilassar',88,88038,2,'Cami del Crist, 33',556412),(7,'Tenerife',NULL,NULL,10,NULL,NULL),(8,NULL,NULL,NULL,NULL,NULL,NULL),(9,'Algemesi',20,1354,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 */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; @@ -760,9 +760,9 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-05-04 15:58:28 +-- Dump completed on 2022-06-23 12:13:33 USE `sage`; --- MariaDB dump 10.19 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.8-MariaDB, for debian-linux-gnu (x86_64) -- -- Host: db.verdnatura.es Database: sage -- ------------------------------------------------------ @@ -816,4 +816,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-05-04 15:58:29 +-- Dump completed on 2022-06-23 12:13:33 diff --git a/db/dump/structure.sql b/db/dump/structure.sql index cc0ee4785..6a892a49b 100644 --- a/db/dump/structure.sql +++ b/db/dump/structure.sql @@ -1,8 +1,8 @@ --- MariaDB dump 10.19 Distrib 10.5.12-MariaDB, for debian-linux-gnu (x86_64) +-- MariaDB dump 10.19 Distrib 10.6.8-MariaDB, for debian-linux-gnu (x86_64) -- --- Host: 127.0.0.1 Database: account +-- Host: db.verdnatura.es Database: account -- ------------------------------------------------------ --- Server version 10.4.13-MariaDB-1:10.4.13+maria~focal +-- Server version 5.6.25-4-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -161,7 +161,7 @@ CREATE TABLE `ldapConfig` ( `userDn` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The base DN for users', `groupDn` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The base DN for groups', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='LDAP server configuration parameters'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='LDAP server configuration parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -175,7 +175,7 @@ CREATE TABLE `mailAlias` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `alias` varchar(50) CHARACTER SET utf8 NOT NULL, `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `isPublic` tinyint(4) NOT NULL DEFAULT 1, + `isPublic` tinyint(4) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `alias` (`alias`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Mail aliases'; @@ -214,7 +214,7 @@ CREATE TABLE `mailClientAccess` ( `description` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `mailFrom` (`client`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -260,7 +260,7 @@ CREATE TABLE `mailSenderAccess` ( `description` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `mailFrom` (`sender`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -307,9 +307,9 @@ CREATE TABLE `role` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(14) COLLATE utf8_unicode_ci NOT NULL COMMENT 'MySQL doesn''t support more than 14 chars for proxied user names', `description` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, - `hasLogin` tinyint(3) unsigned NOT NULL DEFAULT 1, - `created` timestamp NOT NULL DEFAULT current_timestamp(), - `modified` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `hasLogin` tinyint(3) unsigned NOT NULL DEFAULT '1', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Roles'; @@ -423,9 +423,9 @@ CREATE TABLE `sambaConfig` ( `adController` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The hosname of domain controller', `adUser` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Active directory user', `adPassword` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Active directory password', - `verifyCert` tinyint(3) unsigned NOT NULL DEFAULT 1 COMMENT 'Whether to verify server certificate', + `verifyCert` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT 'Whether to verify server certificate', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters for accounts'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters for accounts'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -441,21 +441,22 @@ CREATE TABLE `user` ( `name` varchar(30) CHARACTER SET utf8 NOT NULL, `nickname` varchar(127) COLLATE utf8_unicode_ci NOT NULL, `bcryptPassword` varchar(512) COLLATE utf8_unicode_ci DEFAULT NULL, - `role` int(10) unsigned NOT NULL DEFAULT 2, - `active` tinyint(1) NOT NULL DEFAULT 1, + `role` int(10) unsigned NOT NULL DEFAULT '2', + `active` tinyint(1) NOT NULL DEFAULT '1', `email` varchar(255) CHARACTER SET utf8 DEFAULT NULL, `emailVerified` tinyint(1) DEFAULT NULL, `verificationToken` varchar(512) CHARACTER SET utf8 DEFAULT NULL, `lang` char(2) CHARACTER SET utf8 DEFAULT NULL, `lastPassChange` datetime DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), - `updated` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `image` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `password` char(64) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Deprecated', - `recoverPass` tinyint(3) unsigned NOT NULL DEFAULT 1 COMMENT 'Deprecated', - `sync` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'Deprecated', + `recoverPass` tinyint(3) unsigned NOT NULL DEFAULT '1' COMMENT 'Deprecated', + `sync` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Deprecated', PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`), + UNIQUE KEY `mail` (`email`), KEY `role` (`role`), KEY `email` (`email`), KEY `nickname` (`nickname`), @@ -528,7 +529,7 @@ BEGIN IF !(NEW.`password` <=> OLD.`password`) THEN SET NEW.bcryptPassword = NULL; - SET NEW.lastPassChange = util.VN_NOW(); + SET NEW.lastPassChange = vn.VN_NOW(); END IF; END */;; DELIMITER ; @@ -566,7 +567,7 @@ BEGIN 'jgallego@verdnatura.es', 'Rol modificado', CONCAT( - myUserGetName(), + myUser_getName(), ' ha modificado el rol del usuario ', NEW.`name`, ' de ', OLD.role, ' a ', NEW.role) ); @@ -611,7 +612,7 @@ CREATE TABLE `userConfig` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `loginKey` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -652,6 +653,8 @@ CREATE TABLE `userSync` ( -- -- Dumping routines for database 'account' -- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `myUserGetId` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -659,8 +662,6 @@ CREATE TABLE `userSync` ( /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `myUserGetId`() RETURNS int(11) READS SQL DATA @@ -676,6 +677,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `myUserGetName` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -683,8 +686,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `myUserGetName`() RETURNS varchar(30) CHARSET utf8 NO SQL @@ -700,6 +701,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `myUserHasRole` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -707,8 +710,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `myUserHasRole`(vRoleName VARCHAR(255)) RETURNS tinyint(1) DETERMINISTIC @@ -723,6 +724,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `myUserHasRoleId` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -730,8 +733,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `myUserHasRoleId`(vRoleId INT) RETURNS tinyint(1) DETERMINISTIC @@ -746,6 +747,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `myUser_checkLogin` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -753,8 +756,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `myUser_checkLogin`() RETURNS tinyint(1) READS SQL DATA @@ -785,6 +786,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `myUser_getId` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -792,8 +795,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `myUser_getId`() RETURNS int(11) READS SQL DATA @@ -821,6 +822,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `myUser_getName` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -828,8 +831,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `myUser_getName`() RETURNS varchar(30) CHARSET utf8 NO SQL @@ -856,6 +857,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `myUser_hasRole` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -863,8 +866,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `myUser_hasRole`(vRoleName VARCHAR(255)) RETURNS tinyint(1) DETERMINISTIC @@ -882,6 +883,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `myUser_hasRoleId` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -889,8 +892,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `myUser_hasRoleId`(vRoleId INT) RETURNS tinyint(1) DETERMINISTIC @@ -901,13 +902,15 @@ BEGIN * @param vRoleName Role id to check * @return %TRUE if it has role, %FALSE otherwise */ - RETURN user_hasRoleId(myUserGetName(), vRoleId); + RETURN user_hasRoleId(myUser_getName(), vRoleId); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `passwordGenerate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -915,63 +918,63 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `passwordGenerate`() RETURNS text CHARSET utf8 COLLATE utf8_unicode_ci READS SQL DATA -BEGIN -/** - * Generates a random password that meets the minimum requirements. - * - * @return Generated password - */ - DECLARE vMinLength TINYINT; - DECLARE vMinAlpha TINYINT; - DECLARE vMinUpper TINYINT; - DECLARE vMinDigits TINYINT; - DECLARE vMinPunct TINYINT; - DECLARE vAlpha TINYINT DEFAULT 0; - DECLARE vUpper TINYINT DEFAULT 0; - DECLARE vDigits TINYINT DEFAULT 0; - DECLARE vPunct TINYINT DEFAULT 0; - DECLARE vRandIndex INT; - DECLARE vPwd TEXT DEFAULT ''; - - DECLARE vAlphaChars TEXT DEFAULT 'abcdefghijklmnopqrstuvwxyz'; - DECLARE vUpperChars TEXT DEFAULT 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; - DECLARE vDigitChars TEXT DEFAULT '1234567890'; - DECLARE vPunctChars TEXT DEFAULT '!$%&()=.'; - - SELECT length, nAlpha, nUpper, nDigits, nPunct - INTO vMinLength, vMinAlpha, vMinUpper, vMinDigits, vMinPunct FROM userPassword; - - WHILE LENGTH(vPwd) < vMinLength OR vAlpha < vMinAlpha - OR vUpper < vMinUpper OR vDigits < vMinDigits OR vPunct < vMinPunct DO - SET vRandIndex = FLOOR((RAND() * 4) + 1); - - CASE - WHEN vRandIndex = 1 THEN - SET vPwd = CONCAT(vPwd, SUBSTRING(vAlphaChars, FLOOR((RAND() * 26) + 1), 1)); - SET vAlpha = vAlpha + 1; - WHEN vRandIndex = 2 THEN - SET vPwd = CONCAT(vPwd, SUBSTRING(vUpperChars, FLOOR((RAND() * 26) + 1), 1)); - SET vUpper = vUpper + 1; - WHEN vRandIndex = 3 THEN - SET vPwd = CONCAT(vPwd, SUBSTRING(vDigitChars, FLOOR((RAND() * 10) + 1), 1)); - SET vDigits = vDigits + 1; - WHEN vRandIndex = 4 THEN - SET vPwd = CONCAT(vPwd, SUBSTRING(vPunctChars, FLOOR((RAND() * LENGTH(vPunctChars)) + 1), 1)); - SET vPunct = vPunct + 1; - END CASE; - END WHILE; - RETURN vPwd; +BEGIN +/** + * Generates a random password that meets the minimum requirements. + * + * @return Generated password + */ + DECLARE vMinLength TINYINT; + DECLARE vMinAlpha TINYINT; + DECLARE vMinUpper TINYINT; + DECLARE vMinDigits TINYINT; + DECLARE vMinPunct TINYINT; + DECLARE vAlpha TINYINT DEFAULT 0; + DECLARE vUpper TINYINT DEFAULT 0; + DECLARE vDigits TINYINT DEFAULT 0; + DECLARE vPunct TINYINT DEFAULT 0; + DECLARE vRandIndex INT; + DECLARE vPwd TEXT DEFAULT ''; + + DECLARE vAlphaChars TEXT DEFAULT 'abcdefghijklmnopqrstuvwxyz'; + DECLARE vUpperChars TEXT DEFAULT 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + DECLARE vDigitChars TEXT DEFAULT '1234567890'; + DECLARE vPunctChars TEXT DEFAULT '!$%&()=.'; + + SELECT length, nAlpha, nUpper, nDigits, nPunct + INTO vMinLength, vMinAlpha, vMinUpper, vMinDigits, vMinPunct FROM userPassword; + + WHILE LENGTH(vPwd) < vMinLength OR vAlpha < vMinAlpha + OR vUpper < vMinUpper OR vDigits < vMinDigits OR vPunct < vMinPunct DO + SET vRandIndex = FLOOR((RAND() * 4) + 1); + + CASE + WHEN vRandIndex = 1 THEN + SET vPwd = CONCAT(vPwd, SUBSTRING(vAlphaChars, FLOOR((RAND() * 26) + 1), 1)); + SET vAlpha = vAlpha + 1; + WHEN vRandIndex = 2 THEN + SET vPwd = CONCAT(vPwd, SUBSTRING(vUpperChars, FLOOR((RAND() * 26) + 1), 1)); + SET vUpper = vUpper + 1; + WHEN vRandIndex = 3 THEN + SET vPwd = CONCAT(vPwd, SUBSTRING(vDigitChars, FLOOR((RAND() * 10) + 1), 1)); + SET vDigits = vDigits + 1; + WHEN vRandIndex = 4 THEN + SET vPwd = CONCAT(vPwd, SUBSTRING(vPunctChars, FLOOR((RAND() * LENGTH(vPunctChars)) + 1), 1)); + SET vPunct = vPunct + 1; + END CASE; + END WHILE; + RETURN vPwd; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `toUnixDays` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -979,8 +982,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `toUnixDays`(vDate DATE) RETURNS int(11) DETERMINISTIC @@ -998,6 +999,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `userGetId` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1005,8 +1008,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `userGetId`() RETURNS int(11) READS SQL DATA @@ -1022,6 +1023,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `userGetName` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1029,8 +1032,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `userGetName`() RETURNS varchar(30) CHARSET utf8 NO SQL @@ -1046,6 +1047,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `userHasRole` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1053,8 +1056,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `userHasRole`(vUserName VARCHAR(255), vRoleName VARCHAR(255)) RETURNS tinyint(1) DETERMINISTIC @@ -1069,6 +1070,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `userHasRoleId` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1076,8 +1079,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `userHasRoleId`(vUser VARCHAR(255), vRoleId INT) RETURNS tinyint(1) DETERMINISTIC @@ -1092,6 +1093,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `user_getMysqlRole` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1099,34 +1102,34 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `user_getMysqlRole`(vUserName VARCHAR(255)) RETURNS varchar(255) CHARSET utf8 COLLATE utf8_unicode_ci DETERMINISTIC -BEGIN -/** - * From a username, it returns the associated MySQL wich should be used when - * using external authentication systems. - * - * @param vUserName The user name - * @return The associated MySQL role - */ - DECLARE vRole VARCHAR(255); - - SELECT CONCAT(IF(r.hasLogin, c.rolePrefix, ''), r.name) INTO vRole - FROM role r - JOIN user u ON u.role = r.id - JOIN roleConfig c - WHERE u.name = vUserName; - - RETURN vRole; +BEGIN +/** + * From a username, it returns the associated MySQL wich should be used when + * using external authentication systems. + * + * @param vUserName The user name + * @return The associated MySQL role + */ + DECLARE vRole VARCHAR(255); + + SELECT CONCAT(IF(r.hasLogin, c.rolePrefix, ''), r.name) INTO vRole + FROM role r + JOIN user u ON u.role = r.id + JOIN roleConfig c + WHERE u.name = vUserName; + + RETURN vRole; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `user_getNameFromId` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1134,31 +1137,31 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `user_getNameFromId`(vSelf INT) RETURNS varchar(30) CHARSET utf8 COLLATE utf8_unicode_ci DETERMINISTIC -BEGIN -/** - * Gets user name from it's id. - * - * @param vSelf The user id - * @return The user name - */ - DECLARE vName VARCHAR(30); - - SELECT `name` INTO vName - FROM user - WHERE id = vSelf; - - RETURN vName; +BEGIN +/** + * Gets user name from it's id. + * + * @param vSelf The user id + * @return The user name + */ + DECLARE vName VARCHAR(30); + + SELECT `name` INTO vName + FROM user + WHERE id = vSelf; + + RETURN vName; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `user_hasRole` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1166,8 +1169,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `user_hasRole`(vUserName VARCHAR(255), vRoleName VARCHAR(255)) RETURNS tinyint(1) DETERMINISTIC @@ -1195,6 +1196,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `user_hasRoleId` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1202,8 +1205,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `user_hasRoleId`(vUser VARCHAR(255), vRoleId INT) RETURNS tinyint(1) DETERMINISTIC @@ -1231,6 +1232,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myUserLogout` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1238,8 +1241,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myUserLogout`() BEGIN @@ -1253,6 +1254,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myUser_changePassword` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1260,8 +1263,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myUser_changePassword`(vOldPassword VARCHAR(255), vPassword VARCHAR(255)) BEGIN @@ -1278,6 +1279,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myUser_login` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1285,8 +1288,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myUser_login`(vUserName VARCHAR(255), vPassword VARCHAR(255)) READS SQL DATA @@ -1316,6 +1317,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myUser_loginWithKey` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1323,8 +1326,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myUser_loginWithKey`(vUserName VARCHAR(255), vKey VARCHAR(255)) READS SQL DATA @@ -1350,6 +1351,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myUser_loginWithName` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1357,8 +1360,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myUser_loginWithName`(vUserName VARCHAR(255)) READS SQL DATA @@ -1387,6 +1388,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myUser_logout` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1394,8 +1397,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myUser_logout`() BEGIN @@ -1411,6 +1412,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myUser_restorePassword` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1418,8 +1421,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myUser_restorePassword`(vVerificationToken VARCHAR(255), vPassword VARCHAR(255)) BEGIN @@ -1436,6 +1437,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `role_checkName` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1443,8 +1446,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `role_checkName`(vRoleName VARCHAR(255)) BEGIN @@ -1465,6 +1466,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `role_getDescendents` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1472,8 +1475,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `role_getDescendents`(vSelf INT) BEGIN @@ -1542,6 +1543,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `role_sync` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1549,8 +1552,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `role_sync`() BEGIN @@ -1606,6 +1607,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `role_syncPrivileges` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -1613,8 +1616,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `role_syncPrivileges`() BEGIN @@ -2185,6 +2186,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `userLogin` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2192,8 +2195,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `userLogin`(vUserName VARCHAR(255), vPassword VARCHAR(255)) READS SQL DATA @@ -2208,6 +2209,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `userLoginWithKey` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2215,8 +2218,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `userLoginWithKey`(vUserName VARCHAR(255), vKey VARCHAR(255)) READS SQL DATA @@ -2231,6 +2232,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `userLoginWithName` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2238,8 +2241,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `userLoginWithName`(vUserName VARCHAR(255)) READS SQL DATA @@ -2254,6 +2255,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `userSetPassword` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2261,8 +2264,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `userSetPassword`(vUserName VARCHAR(255), vPassword VARCHAR(255)) BEGIN @@ -2281,6 +2282,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `user_changePassword` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2288,8 +2291,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `user_changePassword`(vSelf INT, vOldPassword VARCHAR(255), vPassword VARCHAR(255)) BEGIN @@ -2319,6 +2320,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `user_checkName` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2326,8 +2329,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `user_checkName`(vUserName VARCHAR(255)) BEGIN @@ -2347,6 +2348,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `user_checkPassword` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2354,8 +2357,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `user_checkPassword`(vPassword VARCHAR(255)) BEGIN @@ -2415,6 +2416,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `user_restorePassword` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2422,8 +2425,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `user_restorePassword`(vSelf INT, vVerificationToken VARCHAR(255), vPassword VARCHAR(255)) BEGIN @@ -2453,6 +2454,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `user_setPassword` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -2460,8 +2463,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `user_setPassword`(vSelf INT, vPassword VARCHAR(255)) BEGIN @@ -2524,12 +2525,12 @@ DROP TABLE IF EXISTS `bancos_evolution`; CREATE TABLE `bancos_evolution` ( `Fecha` date NOT NULL, `Id_Banco` int(11) NOT NULL, - `saldo` decimal(10,2) NOT NULL DEFAULT 0.00, - `quilla` decimal(10,2) NOT NULL DEFAULT 0.00, - `deuda` decimal(10,2) NOT NULL DEFAULT 0.00, - `liquidez` decimal(10,2) NOT NULL DEFAULT 0.00, - `disponibilidad ajena` decimal(10,2) NOT NULL DEFAULT 0.00, - `saldo_aux` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT 'Saldo auxiliar para el calculo de lo dispuesto en las polizas', + `saldo` decimal(10,2) NOT NULL DEFAULT '0.00', + `quilla` decimal(10,2) NOT NULL DEFAULT '0.00', + `deuda` decimal(10,2) NOT NULL DEFAULT '0.00', + `liquidez` decimal(10,2) NOT NULL DEFAULT '0.00', + `disponibilidad ajena` decimal(10,2) NOT NULL DEFAULT '0.00', + `saldo_aux` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT 'Saldo auxiliar para el calculo de lo dispuesto en las polizas', PRIMARY KEY (`Fecha`,`Id_Banco`), KEY `fk_banco_evolution_idx` (`Id_Banco`), CONSTRAINT `fk_banco_evolution` FOREIGN KEY (`Id_Banco`) REFERENCES `vn`.`accounting` (`id`) ON DELETE CASCADE ON UPDATE CASCADE @@ -2575,7 +2576,7 @@ DROP TABLE IF EXISTS `clientDied`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `clientDied` ( - `id` int(11) NOT NULL DEFAULT 0, + `id` int(11) NOT NULL DEFAULT '0', `clientName` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `lastInvoiced` date DEFAULT NULL, `workerCode` varchar(3) COLLATE utf8_unicode_ci NOT NULL, @@ -2596,8 +2597,8 @@ CREATE TABLE `clientNewBorn` ( `clientFk` int(11) NOT NULL, `firstShipped` date NOT NULL COMMENT 'Primer pedido o de la relacion comercial, o después de un año de inactividad', `lastShipped` date NOT NULL COMMENT 'último pedido del cliente', - `isModified` tinyint(4) DEFAULT 0, - `isRookie` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'define un cliente que ha de ser cuidado por ser nuevo o recuperado', + `isModified` tinyint(4) DEFAULT '0', + `isRookie` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'define un cliente que ha de ser cuidado por ser nuevo o recuperado', PRIMARY KEY (`clientFk`), CONSTRAINT `clientNewBorn_fk1` FOREIGN KEY (`clientFk`) REFERENCES `vn`.`client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Listado de clientes que se consideran nuevos a efectos de cobrar la comision adicional del comercial'; @@ -2698,7 +2699,7 @@ DROP TABLE IF EXISTS `defaulter`; CREATE TABLE `defaulter` ( `clientFk` int(11) NOT NULL, `created` date NOT NULL, - `amount` double NOT NULL DEFAULT 0, + `amount` double NOT NULL DEFAULT '0', `defaulterSinced` date DEFAULT NULL, `hasChanged` tinyint(1) DEFAULT NULL, `frozened` date DEFAULT NULL, @@ -2717,7 +2718,7 @@ DROP TABLE IF EXISTS `experienceIberflora2016`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `experienceIberflora2016` ( `Id_Cliente` int(11) NOT NULL, - `isVisitor` tinyint(4) NOT NULL DEFAULT 0, + `isVisitor` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`Id_Cliente`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de clientes que participan en el estudio sobre la mejora del consumo tras la visita a las instalaciones de Silla'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -2783,7 +2784,7 @@ DROP TABLE IF EXISTS `inspeccionSS_2021`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `inspeccionSS_2021` ( `business_id` int(11) DEFAULT NULL, - `id` int(11) NOT NULL DEFAULT 0, + `id` int(11) NOT NULL DEFAULT '0', `firstName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `lastName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, @@ -2850,98 +2851,18 @@ CREATE TABLE `m3` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `fecha` date NOT NULL, `provinceFk` smallint(5) unsigned DEFAULT NULL, - `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT 0, + `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT '0', `m3` decimal(10,2) DEFAULT NULL, `year` int(11) DEFAULT NULL, `month` int(11) DEFAULT NULL, `week` int(11) DEFAULT NULL, `day` int(11) DEFAULT NULL, `dayName` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, - `euros` decimal(10,2) DEFAULT 0.00, + `euros` decimal(10,2) DEFAULT '0.00', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Temporary table structure for view `m3Silla__` --- - -DROP TABLE IF EXISTS `m3Silla__`; -/*!50001 DROP VIEW IF EXISTS `m3Silla__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `m3Silla__` ( - `fecha` tinyint NOT NULL, - `year` tinyint NOT NULL, - `month` tinyint NOT NULL, - `week` tinyint NOT NULL, - `day` tinyint NOT NULL, - `dayName` tinyint NOT NULL, - `Volumen` tinyint NOT NULL, - `Euros` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `manaCustomer` --- - -DROP TABLE IF EXISTS `manaCustomer`; -/*!50001 DROP VIEW IF EXISTS `manaCustomer`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `manaCustomer` ( - `Id_Cliente` tinyint NOT NULL, - `Mana` tinyint NOT NULL, - `dated` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `manaSpellersExcluded` --- - -DROP TABLE IF EXISTS `manaSpellersExcluded`; -/*!50001 DROP VIEW IF EXISTS `manaSpellersExcluded`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `manaSpellersExcluded` ( - `workerFk` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `mana_spellers` --- - -DROP TABLE IF EXISTS `mana_spellers`; -/*!50001 DROP VIEW IF EXISTS `mana_spellers`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `mana_spellers` ( - `Id_Trabajador` tinyint NOT NULL, - `size` tinyint NOT NULL, - `used` tinyint NOT NULL, - `prices_modifier_rate` tinyint NOT NULL, - `prices_modifier_activated` tinyint NOT NULL, - `minRate` tinyint NOT NULL, - `maxRate` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `mana_spellers_excluded` --- - -DROP TABLE IF EXISTS `mana_spellers_excluded`; -/*!50001 DROP VIEW IF EXISTS `mana_spellers_excluded`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `mana_spellers_excluded` ( - `Id_Trabajador` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - -- -- Table structure for table `mermasCache__` -- @@ -2977,7 +2898,7 @@ CREATE TABLE `nightTask` ( `error` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `errorCode` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -3043,7 +2964,7 @@ CREATE TABLE `nightTaskConfig` ( `id` int(11) NOT NULL AUTO_INCREMENT, `logMail` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3073,15 +2994,15 @@ DROP TABLE IF EXISTS `payMethodClient`; CREATE TABLE `payMethodClient` ( `id` int(11) NOT NULL AUTO_INCREMENT, `dated` date NOT NULL, - `payMethodFk` tinyint(3) unsigned NOT NULL DEFAULT 0, - `clientFk` int(11) NOT NULL DEFAULT 0, + `payMethodFk` tinyint(3) unsigned NOT NULL DEFAULT '0', + `clientFk` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `FkPayMethod_idx` (`payMethodFk`), KEY `FkClientPayMethod_idx` (`clientFk`), KEY `FkDateClientPayMethod` (`dated`,`clientFk`), CONSTRAINT `FkClientPayMethod` FOREIGN KEY (`clientFk`) REFERENCES `vn`.`client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `FkPayMethodClient` FOREIGN KEY (`payMethodFk`) REFERENCES `vn`.`payMethod` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3099,7 +3020,7 @@ CREATE TABLE `payMethodClientEvolution` ( `amount` decimal(10,2) NOT NULL, `equalizationTax` decimal(10,2) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3111,9 +3032,9 @@ DROP TABLE IF EXISTS `produccion`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `produccion` ( `dated` date NOT NULL, - `m3` int(11) NOT NULL DEFAULT 0, - `cost` int(11) NOT NULL DEFAULT 0, - `eurosM3` decimal(10,2) NOT NULL DEFAULT 0.00, + `m3` int(11) NOT NULL DEFAULT '0', + `cost` int(11) NOT NULL DEFAULT '0', + `eurosM3` decimal(10,2) NOT NULL DEFAULT '0.00', PRIMARY KEY (`dated`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -3168,13 +3089,13 @@ DROP TABLE IF EXISTS `sale`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `sale` ( `saleFk` int(11) NOT NULL, - `amount` decimal(10,3) NOT NULL DEFAULT 0.000, - `surcharge` decimal(10,3) NOT NULL DEFAULT 0.000, + `amount` decimal(10,3) NOT NULL DEFAULT '0.000', + `surcharge` decimal(10,3) NOT NULL DEFAULT '0.000', `dated` date NOT NULL, `typeFk` smallint(5) unsigned NOT NULL, - `clientFk` int(11) NOT NULL DEFAULT 1, - `companyFk` smallint(5) unsigned NOT NULL DEFAULT 442, - `margin` decimal(10,3) NOT NULL DEFAULT 0.000, + `clientFk` int(11) NOT NULL DEFAULT '1', + `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', + `margin` decimal(10,3) NOT NULL DEFAULT '0.000', PRIMARY KEY (`saleFk`), KEY `tip_to_tip_idx` (`typeFk`), KEY `clientes_bs_ventas_idx` (`clientFk`), @@ -3196,32 +3117,43 @@ DROP TABLE IF EXISTS `salePersonEvolution__`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `salePersonEvolution__` ( `dated` date NOT NULL DEFAULT '0000-00-00', - `amount` decimal(10,2) NOT NULL DEFAULT 0.00, - `equalizationTax` decimal(10,2) NOT NULL DEFAULT 0.00, - `salesPersonFk` int(11) NOT NULL DEFAULT 0, + `amount` decimal(10,2) NOT NULL DEFAULT '0.00', + `equalizationTax` decimal(10,2) NOT NULL DEFAULT '0.00', + `salesPersonFk` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`dated`,`salesPersonFk`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- --- Temporary table structure for view `sale__` +-- Table structure for table `salesByItemTypeDay` -- -DROP TABLE IF EXISTS `sale__`; -/*!50001 DROP VIEW IF EXISTS `sale__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `sale__` ( - `saleFk` tinyint NOT NULL, - `amount` tinyint NOT NULL, - `surcharge` tinyint NOT NULL, - `dated` tinyint NOT NULL, - `typeFk` tinyint NOT NULL, - `clientFk` tinyint NOT NULL, - `companyFk` tinyint NOT NULL, - `margin` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; +DROP TABLE IF EXISTS `salesByItemTypeDay`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `salesByItemTypeDay` ( + `itemTypeFk` smallint(5) unsigned NOT NULL, + `itemCategoryFk` int(10) unsigned NOT NULL, + `dated` date NOT NULL, + `netSale` int(11) NOT NULL DEFAULT '0', + `stems` int(11) NOT NULL DEFAULT '0', + `references` int(11) NOT NULL DEFAULT '0', + `trash` int(11) NOT NULL DEFAULT '0', + `faults` int(11) NOT NULL DEFAULT '0', + `claimed` decimal(10,2) NOT NULL DEFAULT '0.00', + `accepted` decimal(10,2) NOT NULL DEFAULT '0.00', + `sale` decimal(10,2) NOT NULL DEFAULT '0.00', + `buy` decimal(10,2) NOT NULL DEFAULT '0.00', + `saleComponent` decimal(10,2) NOT NULL DEFAULT '0.00', + `costComponent` decimal(10,2) NOT NULL DEFAULT '0.00', + `marginComponent` decimal(10,2) NOT NULL DEFAULT '0.00', + PRIMARY KEY (`itemTypeFk`,`dated`), + KEY `itemTypeSalesByweek_itemCategoryFk_idx` (`itemCategoryFk`), + KEY `itemTypeSalesByweek_period_idx` (`dated`), + CONSTRAINT `itemTypeSalesByweek_itemCategoryFk` FOREIGN KEY (`itemCategoryFk`) REFERENCES `vn`.`itemCategory` (`id`) ON UPDATE CASCADE, + CONSTRAINT `itemTypeSalesByweek_itemTypeFk` FOREIGN KEY (`itemTypeFk`) REFERENCES `vn`.`itemType` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Ventas diarias agrupadas por reino y familia'; +/*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `salesByWeek` @@ -3249,9 +3181,9 @@ CREATE TABLE `salesByclientSalesPerson` ( `dated` date NOT NULL DEFAULT '0000-00-00', `salesPersonFk` int(10) unsigned DEFAULT NULL, `clientFk` int(11) NOT NULL, - `amount` decimal(10,3) NOT NULL DEFAULT 0.000, - `equalizationTax` decimal(10,3) NOT NULL DEFAULT 0.000, - `amountNewBorn` decimal(10,3) NOT NULL DEFAULT 0.000, + `amount` decimal(10,3) NOT NULL DEFAULT '0.000', + `equalizationTax` decimal(10,3) NOT NULL DEFAULT '0.000', + `amountNewBorn` decimal(10,3) NOT NULL DEFAULT '0.000', PRIMARY KEY (`dated`,`clientFk`), KEY `clientSalePersonEvolution_clientFk` (`clientFk`), KEY `salesByclientSalesPerson_salesPerson` (`salesPersonFk`), @@ -3283,7 +3215,7 @@ CREATE TABLE `salesMonthlySnapshot` ( `newClientScore` decimal(10,3) DEFAULT NULL, `teamBossPlus` decimal(10,3) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3299,7 +3231,7 @@ CREATE TABLE `salesMonthlySnapshot__` ( `year` int(4) NOT NULL, `month` int(2) NOT NULL, `departmentFk` int(11) NOT NULL, - `ownSalesAmount` decimal(10,2) DEFAULT 0.00, + `ownSalesAmount` decimal(10,2) DEFAULT '0.00', `ownSalesPosition` int(11) DEFAULT NULL, `ownSalesBonus` int(11) DEFAULT NULL, `ownSalesScore` int(11) DEFAULT NULL, @@ -3313,7 +3245,7 @@ CREATE TABLE `salesMonthlySnapshot__` ( `teamSalesScore` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `workerFk_UNIQUE` (`workerFk`,`year`,`month`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='cada mes se guardan aqui los datos de forma estática, para consulta en grafana.'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='cada mes se guardan aqui los datos de forma estática, para consulta en grafana.'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3335,7 +3267,7 @@ CREATE TABLE `salesPerson` ( `leasedReplacement` decimal(10,2) DEFAULT NULL, `itemTypeBorrowed` decimal(10,2) DEFAULT NULL, `portfolioWeight` decimal(10,2) DEFAULT NULL COMMENT 'Pero de la cartera del comercial a fecha vendedores.updated', - `updated` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`workerFk`,`year`,`month`), CONSTRAINT `salesPerson_FK` FOREIGN KEY (`workerFk`) REFERENCES `vn`.`worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -3375,39 +3307,15 @@ CREATE TABLE `salesPersonEvolution` ( `id` int(11) NOT NULL AUTO_INCREMENT, `dated` date NOT NULL DEFAULT '0000-00-00', `salesPersonFk` int(10) unsigned DEFAULT NULL, - `amount` decimal(10,3) NOT NULL DEFAULT 0.000, - `equalizationTax` decimal(10,3) NOT NULL DEFAULT 0.000, - `amountNewBorn` decimal(10,3) NOT NULL DEFAULT 0.000, + `amount` decimal(10,3) NOT NULL DEFAULT '0.000', + `equalizationTax` decimal(10,3) NOT NULL DEFAULT '0.000', + `amountNewBorn` decimal(10,3) NOT NULL DEFAULT '0.000', PRIMARY KEY (`id`), KEY `salesPersonEvolution_salesPerson` (`salesPersonFk`), CONSTRAINT `salesPersonEvolution_salesPerson` FOREIGN KEY (`salesPersonFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Evolución Comerciales'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Evolución Comerciales'; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Temporary table structure for view `salesPerson__` --- - -DROP TABLE IF EXISTS `salesPerson__`; -/*!50001 DROP VIEW IF EXISTS `salesPerson__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `salesPerson__` ( - `workerFk` tinyint NOT NULL, - `year` tinyint NOT NULL, - `month` tinyint NOT NULL, - `amount` tinyint NOT NULL, - `commission` tinyint NOT NULL, - `leasedCommission` tinyint NOT NULL, - `cededCommission` tinyint NOT NULL, - `newCommission` tinyint NOT NULL, - `leasedReplacement` tinyint NOT NULL, - `itemTypeBorrowed` tinyint NOT NULL, - `portfolioWeight` tinyint NOT NULL, - `updated` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - -- -- Temporary table structure for view `vendedores` -- @@ -3501,7 +3409,7 @@ CREATE TABLE `waste` ( `year` int(4) NOT NULL, `week` int(2) NOT NULL, `family` varchar(30) COLLATE utf8_unicode_ci NOT NULL, - `itemFk` int(11) NOT NULL DEFAULT 0, + `itemFk` int(11) NOT NULL DEFAULT '0', `itemTypeFk` smallint(5) unsigned DEFAULT NULL, `saleTotal` decimal(16,0) DEFAULT NULL, `saleWaste` decimal(16,0) DEFAULT NULL, @@ -3530,23 +3438,9 @@ CREATE TABLE `workerLabourDataByMonth` ( `permanent` int(5) NOT NULL COMMENT 'Número de empleados fijos', PRIMARY KEY (`id`), KEY `workerLabourDataByMonth_graph_idx` (`code`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Temporary table structure for view `workerMana` --- - -DROP TABLE IF EXISTS `workerMana`; -/*!50001 DROP VIEW IF EXISTS `workerMana`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `workerMana` ( - `workerFk` tinyint NOT NULL, - `amount` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - -- -- Table structure for table `workerProductivity` -- @@ -3569,7 +3463,7 @@ CREATE TABLE `workerProductivity` ( CONSTRAINT `workerProductivity_FK` FOREIGN KEY (`actionFk`) REFERENCES `vncontrol`.`accion` (`accion_id`) ON UPDATE CASCADE, CONSTRAINT `workerProductivity_warehouseFk` FOREIGN KEY (`warehouseFk`) REFERENCES `vn`.`warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `workerProductivity_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3584,7 +3478,7 @@ CREATE TABLE `workerProductivityConfig` ( `minSeconsPackager` int(11) DEFAULT NULL, `minSeconsItemPicker` int(11) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3597,7 +3491,7 @@ DROP TABLE IF EXISTS `workerSpeed__`; CREATE TABLE `workerSpeed__` ( `workerCode` varchar(3) COLLATE utf8_unicode_ci NOT NULL, `accion` varchar(15) COLLATE utf8_unicode_ci NOT NULL, - `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT 1, + `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT '1', `LitrosMinuto` decimal(10,1) DEFAULT NULL, `LitrosMinutoLastHour` decimal(10,1) DEFAULT NULL, `lastUpdated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', @@ -3616,7 +3510,7 @@ CREATE TABLE `zone_ETD__` ( `zoneFk` int(11) DEFAULT NULL, `totalVolume` decimal(5,1) DEFAULT NULL, `remainingVolume` decimal(5,1) DEFAULT NULL, - `speed` decimal(10,2) NOT NULL DEFAULT 0.00, + `speed` decimal(10,2) NOT NULL DEFAULT '0.00', `hourTheoretical` time DEFAULT NULL, `hourPractical` varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -3632,7 +3526,7 @@ DROP TABLE IF EXISTS `zone_ETD_byTime`; CREATE TABLE `zone_ETD_byTime` ( `theorical` time NOT NULL, `practical` time NOT NULL DEFAULT '00:00:00', - `m3` decimal(10,1) NOT NULL DEFAULT 0.0, + `m3` decimal(10,1) NOT NULL DEFAULT '0.0', PRIMARY KEY (`theorical`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -3683,6 +3577,8 @@ DELIMITER ; -- -- Dumping routines for database 'bs' -- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `tramo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -3690,8 +3586,6 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `tramo`(vDateTime DATETIME) RETURNS varchar(20) CHARSET utf8 COLLATE utf8_unicode_ci NO SQL @@ -3715,57 +3609,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 `analisisComponentes__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `analisisComponentes__`() -BEGIN - -DECLARE vDateStart DATE DEFAULT '2016-01-01'; -DECLARE vDateEnd DATE DEFAULT '2016-11-30'; -DECLARE vDate DATE; - -SET vDate = vDateStart; - -DELETE FROM bs.ventasComponentes; - -WHILE vDate <= vDateEnd DO - - INSERT INTO bs.ventasComponentes - SELECT vDate as Fecha, mc.Id_Componente, cast(sum(m.Cantidad * mc.Valor) AS DECIMAL(10,2)) as Importe - FROM vn2008.Movimientos_componentes mc - JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento - JOIN bs.ventas v ON v.Id_Movimiento = mc.Id_Movimiento - WHERE v.fecha = vDate - AND empresa_id IN (442,567) - GROUP BY mc.Id_Componente; - - SET vDate = TIMESTAMPADD(DAY,1,vDate); - - IF DAY(vDate) MOD 28 = 0 THEN - - SELECT vDate; - - END IF; - -END WHILE; - - SELECT vDate; - - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `bancos_evolution_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -3773,8 +3618,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `bancos_evolution_add`(vStartingDate DATE) BEGIN @@ -3784,8 +3627,8 @@ BEGIN * @param vStartingDate Fecha desde la cual se recalculan la tabla bs.bancos_evolution */ DECLARE vCurrentDate DATE; - DECLARE vMaxDate DATE DEFAULT TIMESTAMPADD(MONTH, 7, util.VN_CURDATE()); - IF IFNULL(vStartingDate,0) < TIMESTAMPADD(YEAR, -5, util.VN_CURDATE()) THEN + DECLARE vMaxDate DATE DEFAULT TIMESTAMPADD(MONTH, 7, vn.VN_CURDATE()); + IF IFNULL(vStartingDate,0) < TIMESTAMPADD(YEAR, -5, vn.VN_CURDATE()) THEN CALL util.throw('invalid date'); END IF; DELETE FROM bs.bancos_evolution WHERE Fecha >= vStartingDate; @@ -3840,8 +3683,8 @@ BEGIN SELECT t.dated, p.id_banco, - importe FROM vn.time t join vn2008.pago p ON p.fecha <= t.dated - WHERE t.dated BETWEEN util.VN_CURDATE() AND vMaxDate - AND p.fecha BETWEEN util.VN_CURDATE() AND vMaxDate + WHERE t.dated BETWEEN vn.VN_CURDATE() AND vMaxDate + AND p.fecha BETWEEN vn.VN_CURDATE() AND vMaxDate AND NOT conciliado ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo); @@ -3850,8 +3693,8 @@ BEGIN SELECT t.dated, r.Id_Banco, SUM(Entregado) FROM vn.time t JOIN vn2008.Recibos r ON r.Fechacobro <= t.dated - WHERE r.Fechacobro > util.VN_CURDATE() AND r.Fechacobro <= vMaxDate - AND t.dated BETWEEN util.VN_CURDATE() AND vMaxDate + WHERE r.Fechacobro > vn.VN_CURDATE() AND r.Fechacobro <= vMaxDate + AND t.dated BETWEEN vn.VN_CURDATE() AND vMaxDate GROUP BY t.dated, r.Id_Banco ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo); @@ -3891,122 +3734,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 `bancos_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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `bancos_evolution_add__`() -BEGIN -/** - * Inserta en la tabla bancos_evolution los saldos acumulados de cada banco - */ - DECLARE vCurrentDate DATE; - DECLARE vStartingDate DATE DEFAULT '2016-01-01'; - DECLARE vMaxDate DATE DEFAULT TIMESTAMPADD(MONTH, 7, util.VN_CURDATE()); - - DELETE FROM bs.bancos_evolution WHERE Fecha > vStartingDate; - - SET vCurrentDate = vStartingDate; - - WHILE vCurrentDate < vMaxDate DO - - REPLACE bs.bancos_evolution(Fecha ,Id_Banco, saldo) - - SELECT vCurrentDate - , Id_Banco - , sum(saldo) - - FROM - ( - SELECT Id_Banco ,saldo - FROM bs.bancos_evolution - WHERE Fecha = TIMESTAMPADD(DAY,-1,vCurrentDate) -- los saldos acumulados del dia anterior - - UNION ALL - - SELECT c.Id_Banco, IFNULL(sum(Entrada),0) - ifnull(sum(Salida),0) as saldo - FROM vn2008.Cajas c - JOIN vn2008.Bancos b using(Id_Banco) -- saldos de las cajas - WHERE cash IN (0,3) - AND Cajafecha = vCurrentDate - AND (Serie = 'MB' OR cash = 3) - GROUP BY Id_Banco - - )sub - GROUP BY Id_Banco; - - SET vCurrentDate = TIMESTAMPADD(DAY,1,vCurrentDate); - - END WHILE; - - -- Ahora actualizamos la quilla - UPDATE bs.bancos_evolution be - JOIN - ( - SELECT bp.Id_Banco, - sum(bp.importe) as quilla, t.dated - FROM vn.time t - JOIN vn2008.Bancos_poliza bp ON t.dated between apertura AND IFNULL(cierre, t.dated) - GROUP BY Id_Banco, t.dated - ) sub ON be.Id_Banco = sub.Id_Banco AND sub.dated = be.Fecha - SET be.quilla = sub.quilla; - - -- pagos futuros no concilidados - INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo) - SELECT t.dated, p.id_banco, - importe - FROM vn.time t - join vn2008.pago p ON p.fecha <= t.dated - WHERE p.fecha >= util.VN_CURDATE() - AND NOT conciliado - ON DUPLICATE KEY UPDATE saldo = saldo - VALUES(saldo); - - -- cobros futuros - INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo) - SELECT t.dated, r.Id_Banco, SUM(Entregado) - FROM vn.time t - JOIN vn2008.Recibos r ON r.Fechacobro <= t.dated - WHERE r.Fechacobro > util.VN_CURDATE() - GROUP BY t.dated, r.Id_Banco - ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo); - - -- saldos de la tabla prevision - INSERT INTO bs.bancos_evolution(Fecha, Id_Banco, saldo) - SELECT t.dated, sp.Id_Banco, SUM(Importe) - 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) - GROUP BY t.dated, sp.Id_Banco - ON DUPLICATE KEY UPDATE saldo = saldo + VALUES(saldo); - - -- Utilizamos el saldo_auxiliar para calcular lo dispuesto en las polizas - UPDATE bs.bancos_evolution be - SET saldo_aux = saldo; - - -- Deuda - UPDATE bs.bancos_evolution be - JOIN vn2008.Bancos using(Id_Banco) - SET be.deuda = IF(cash = 3, be.saldo_aux, 0) - , be.saldo = IF(cash = 3, 0, be.saldo_aux) - WHERE Fecha >= vStartingDate; - - -- Liquidez - update bs.bancos_evolution set liquidez = saldo - quilla + deuda WHERE Fecha >= vStartingDate; - - -- Disponibilidad - update bs.bancos_evolution set `disponibilidad ajena` = - quilla + deuda WHERE Fecha >= vStartingDate; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `campaignComparative` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4014,8 +3743,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `campaignComparative`(vDateFrom DATE, vDateTo DATE) BEGIN @@ -4062,6 +3789,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `carteras_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4069,31 +3798,31 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `carteras_add`() -BEGIN -/** - * Inserta en @bs.carteras. - */ - DELETE FROM bs.carteras - WHERE Año >= YEAR(util.VN_CURDATE()) - 1; - - INSERT INTO bs.carteras(Año,Mes,CodigoTrabajador,Peso) - SELECT t.year AS Año, t.month AS Mes, w.code AS CodigoTrabajador, SUM(v.importe) AS Peso - FROM vn.time t - JOIN bs.ventas v on t.dated = v.fecha - JOIN vn.client c on c.id = v.Id_Cliente - JOIN vn.worker w ON w.id = c.salesPersonFk - WHERE t.year >= YEAR(util.VN_CURDATE()) - 1 - GROUP BY w.code, t.year , t.month; +BEGIN +/** + * Inserta en @bs.carteras. + */ + DELETE FROM bs.carteras + WHERE Año >= YEAR(vn.VN_CURDATE()) - 1; + + INSERT INTO bs.carteras(Año,Mes,CodigoTrabajador,Peso) + SELECT t.year AS Año, t.month AS Mes, w.code AS CodigoTrabajador, SUM(v.importe) AS Peso + FROM vn.time t + JOIN bs.ventas v on t.dated = v.fecha + JOIN vn.client c on c.id = v.Id_Cliente + JOIN vn.worker w ON w.id = c.salesPersonFk + WHERE t.year >= YEAR(vn.VN_CURDATE()) - 1 + GROUP BY w.code, t.year , t.month; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clean` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4101,18 +3830,19 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clean`() BEGIN DECLARE vFourYearsAgo DATETIME; DECLARE vOneYearAgo DATETIME; DECLARE vTwoYearAgo DATETIME; + DECLARE vThreeYearAgo DATETIME; - SET vOneYearAgo = TIMESTAMPADD(YEAR, -1,util.VN_CURDATE()); - SET vTwoYearAgo = TIMESTAMPADD(YEAR, -2,util.VN_CURDATE()); - SET vFourYearsAgo = TIMESTAMPADD(YEAR, -4,util.VN_CURDATE()); + + SET vOneYearAgo = TIMESTAMPADD(YEAR, -1,vn.VN_CURDATE()); + SET vTwoYearAgo = TIMESTAMPADD(YEAR, -2,vn.VN_CURDATE()); + SET vThreeYearAgo = TIMESTAMPADD(YEAR, -3,vn.VN_CURDATE()); + SET vFourYearsAgo = TIMESTAMPADD(YEAR, -4,vn.VN_CURDATE()); DELETE FROM bs.clientNewBorn WHERE lastShipped < vOneYearAgo; @@ -4131,12 +3861,17 @@ BEGIN DELETE FROM bs.m3 WHERE fecha < vTwoYearAgo; + + DELETE FROM salesByItemTypeDay + WHERE dated < vThreeYearAgo; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientDied_recalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4144,45 +3879,46 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clientDied_recalc`() BEGIN - SET @primerAviso := TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()); - SET @segundoAviso := TIMESTAMPADD(MONTH,-2,util.VN_CURDATE()); - SET @tercerAviso := TIMESTAMPADD(MONTH,-3,util.VN_CURDATE()); + SET @primerAviso := TIMESTAMPADD(MONTH,-1,vn.VN_CURDATE()); + SET @segundoAviso := TIMESTAMPADD(MONTH,-2,vn.VN_CURDATE()); + SET @tercerAviso := TIMESTAMPADD(MONTH,-3,vn.VN_CURDATE()); TRUNCATE TABLE bs.clientDied; - + INSERT INTO bs.clientDied - SELECT c.id, - c.name as clientName, - maxIssued as lastInvoiced, - w.code AS workerCode, - b.code AS Boss, + SELECT c.id, + c.name clientName, + maxIssued lastInvoiced, + w.code workerCode, + b.code Boss, CASE - WHEN IFNULL(maxIssued,'2000-01-01') < @tercerAviso THEN 'Tercer Aviso' - WHEN maxIssued < @segundoAviso THEN 'Segundo Aviso' - WHEN maxIssued < @primerAviso THEN 'Primer Aviso' + WHEN IFNULL(maxIssued,'2000-01-01') < @tercerAviso THEN 'Tercer Aviso' + WHEN maxIssued < @segundoAviso THEN 'Segundo Aviso' + WHEN maxIssued < @primerAviso THEN 'Primer Aviso' END as Aviso FROM vn.client c JOIN vn.worker w ON w.id = c.salesPersonFk JOIN vn.worker b ON b.id = w.bossFk - JOIN bs.mana_spellers ms ON ms.Id_Trabajador = c.salesPersonFk + JOIN vn.workerMana wm ON wm.workerFk = c.salesPersonFk LEFT JOIN (SELECT clientFk, max(issued) as maxIssued FROM vn.invoiceOut GROUP BY clientFk) io ON io.clientFk = c.id WHERE (maxIssued IS NULL OR maxIssued < @primerAviso) AND c.created < @tercerAviso; 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,util.VN_CURDATE()); + WHERE t.refFk IS NULL + AND t.shipped >=TIMESTAMPADD(MONTH,-1,vn.VN_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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientNewBorn_recalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4190,8 +3926,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clientNewBorn_recalc`() BLOCK1: BEGIN @@ -4215,7 +3949,7 @@ BLOCK1: BEGIN FROM vn.client c JOIN vn.ticket t on t.clientFk = c.id LEFT JOIN clientNewBorn cb on cb.clientFk = c.id - WHERE t.shipped BETWEEN TIMESTAMPADD(YEAR, -1, util.VN_CURDATE()) AND util.VN_CURDATE() AND cb.isModified is null + WHERE t.shipped BETWEEN TIMESTAMPADD(YEAR, -1, vn.VN_CURDATE()) AND vn.VN_CURDATE() AND cb.isModified is null GROUP BY c.id; OPEN cur; @@ -4234,7 +3968,7 @@ BLOCK1: BEGIN DECLARE cur2 CURSOR FOR SELECT shipped FROM vn.ticket - WHERE clientFk = vClientFk AND shipped <= util.VN_CURDATE() + WHERE clientFk = vClientFk AND shipped <= vn.VN_CURDATE() ORDER BY shipped DESC; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone2 = TRUE; @@ -4273,8 +4007,8 @@ BLOCK1: BEGIN LEFT JOIN (SELECT DISTINCT t.clientFk FROM vn.ticket t JOIN vn.productionConfig pc - WHERE t.shipped BETWEEN util.VN_CURDATE() + INTERVAL -(`notBuyingMonths`) MONTH - AND util.VN_CURDATE() + INTERVAL -(`pc`.`rookieDays`) DAY) notRookie ON notRookie.clientFk = cnb.clientFk + WHERE t.shipped BETWEEN vn.VN_CURDATE() + INTERVAL -(`notBuyingMonths`) MONTH + AND vn.VN_CURDATE() + INTERVAL -(`pc`.`rookieDays`) DAY) notRookie ON notRookie.clientFk = cnb.clientFk SET cnd.isRookie = ISNULL(notRookie.clientFk); END BLOCK1 ;; @@ -4283,6 +4017,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `comercialesCompleto` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4290,8 +4026,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `comercialesCompleto`(IN vWorker INT, vDate DATE) BEGIN @@ -4408,131 +4142,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 `comercialesCompleto__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `comercialesCompleto__`(IN vWorker INT, vDate DATE) -BEGIN - DECLARE vAYearAgoStarted DATE DEFAULT DATE_FORMAT(TIMESTAMPADD(YEAR, - 1, vDate), '%Y-%m-01'); - DECLARE vAYearAgoEnded DATE DEFAULT TIMESTAMPADD(YEAR, - 1, LAST_DAY(vDate)); - - CALL vn.worker_GetHierarchy(vWorker); - - INSERT IGNORE INTO tmp.workerHierarchyList (workerFk) - SELECT wd2.workerFk - FROM vn.workerDepartment wd2 - WHERE wd2.workerFk = vWorker; - - -- Falta que en algunos casos solo tenga en cuenta los tipos afectados. - SELECT - c.Id_Cliente id_cliente, - c.calidad, - c.Cliente cliente, - cr.recobro * 100 tarifa, - c.Telefono telefono, - c.movil, - c.POBLACION poblacion, - p.`name` provincia, - vn2008.red(f.futur) futur, - c.Credito credito, - pm.`name` forma_pago, - vn2008.red(c365 / 12) consumo_medio365, - vn2008.red(c365) consumo365, - vn2008.red(CmLy.peso) peso_mes_año_pasado, - vn2008.red(CmLy.peso * 1.19) objetivo, - tr.CodigoTrabajador, - vn2008.red(mes_actual.consumo) consumoMes, - vn2008.red(IFNULL(mes_actual.consumo, 0) - IFNULL(CmLy.peso * 1.19, 0)) como_lo_llevo, - DATE(LastTicket) ultimo_ticket, - dead.muerto, - g.Greuge, - cr.recobro - FROM - vn2008.Clientes c - LEFT JOIN - (SELECT g.Id_Cliente, CAST( SUM(Importe) as DECIMAL(12,2)) AS Greuge - FROM vn2008.Greuges g - JOIN vn.`client` c ON c.id = g.Id_Cliente - LEFT JOIN vn.worker w ON c.salesPersonFk = w.id - WHERE (c.salesPersonFk = vWorker OR w.bossFk = vWorker) - GROUP BY Id_Cliente - ) g ON g.Id_Cliente = c.Id_Cliente - LEFT JOIN - vn2008.province p ON p.province_id = c.province_id - JOIN - vn2008.pay_met pm ON pm.id = c.pay_met_id - LEFT JOIN - vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador - LEFT JOIN - bi.claims_ratio cr on cr.Id_Cliente = c.Id_Cliente - LEFT JOIN - (SELECT v.Id_Cliente, SUM(importe) c365 -- optimizat de 6s /5.3s/ 4.7s a 0.3/0.4/0.3 - FROM bs.ventas v - JOIN vn2008.Clientes c ON c.Id_Cliente = v.Id_Cliente - WHERE v.fecha BETWEEN TIMESTAMPADD(YEAR, - 1, vDate) AND vDate - GROUP BY v.Id_Cliente) c365 ON c365.Id_Cliente = c.Id_Cliente - LEFT JOIN - (SELECT - Id_Cliente, SUM(importe) consumo - FROM - bs.ventas v - INNER JOIN vn2008.Clientes c USING (Id_Cliente) - LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador - WHERE - (c.Id_Trabajador = vWorker OR tr.boss = vWorker) - AND (v.fecha BETWEEN TIMESTAMPADD(DAY, - DAY(vDate) + 1, vDate) AND TIMESTAMPADD(DAY, - 1, vDate)) - GROUP BY Id_Cliente) mes_actual ON mes_actual.Id_Cliente = c.Id_Cliente - LEFT JOIN - (SELECT t.Id_Cliente, SUM(m.preu * m.Cantidad * (1 - m.Descuento / 100)) futur - FROM vn2008.Tickets t - JOIN vn2008.Clientes c ON c.Id_Cliente = t.Id_Cliente - JOIN vn2008.Movimientos m ON m.Id_Ticket = t.Id_Ticket - LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador - WHERE - (c.Id_Trabajador = vWorker OR tr.boss = vWorker) - AND t.Fecha BETWEEN vDate AND util.dayEnd(LAST_DAY(vDate)) - GROUP BY Id_Cliente) f ON c.Id_Cliente = f.Id_Cliente - LEFT JOIN - (SELECT MAX(t.Fecha) LastTicket, c.Id_Cliente - FROM vn2008.Tickets t - JOIN vn2008.Clientes c ON c.Id_cliente = t.Id_Cliente - LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador - WHERE - (c.Id_Trabajador = vWorker OR tr.boss = vWorker) - GROUP BY t.Id_Cliente) LastTicket ON LastTicket.Id_Cliente = c.Id_Cliente - LEFT JOIN - ( - SELECT SUM(importe) peso, c.Id_Cliente - FROM bs.ventas v - JOIN vn2008.Clientes c ON c.Id_Cliente = v.Id_Cliente - LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador - WHERE fecha BETWEEN vAYearAgoStarted and vAYearAgoEnded - AND (c.Id_Trabajador = vWorker OR tr.boss = vWorker) - GROUP BY c.Id_Cliente) CmLy ON CmLy.Id_Cliente = c.Id_Cliente - LEFT JOIN - (SELECT c.Id_Cliente, - IF(MAX(Fecha) < DATE_FORMAT(TIMESTAMPADD(MONTH, - 1, vDate), '%Y- %m-01'), TRUE, FALSE) muerto - FROM vn2008.Facturas f - JOIN vn2008.Clientes c ON c.Id_cliente = f.Id_Cliente - LEFT JOIN vn2008.Trabajadores tr ON c.Id_Trabajador = tr.Id_Trabajador - WHERE (c.Id_Trabajador = vWorker OR tr.boss = vWorker) - GROUP BY Id_Cliente) dead ON dead.Id_Cliente = c.Id_Cliente - JOIN tmp.workerHierarchyList s ON s.workerFk = c.Id_Trabajador; - - DROP TEMPORARY TABLE tmp.workerHierarchyList; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `compradores_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4540,8 +4151,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `compradores_add`(IN vYear INT, IN vWeekFrom INT, IN vWeekTo INT) BEGIN @@ -4567,6 +4176,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `compradores_add_launcher` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4574,8 +4185,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `compradores_add_launcher`() BEGIN @@ -4621,6 +4230,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `compradores_evolution_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4628,8 +4239,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `compradores_evolution_add`() BEGIN @@ -4663,7 +4272,7 @@ SELECT TIMESTAMPADD(DAY,1,MAX(fecha)) INTO datFEC FROM bs.compradores_evolution; END IF; - WHILE datFEC < util.VN_CURDATE() DO + WHILE datFEC < vn.VN_CURDATE() DO IF i mod 150 = 0 THEN SELECT datFEC; @@ -4710,6 +4319,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `fondo_evolution_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4717,8 +4328,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `fondo_evolution_add`() BEGIN @@ -4731,7 +4340,7 @@ BEGIN INTO datFEC FROM bs.fondo_maniobra; - WHILE datFEC < util.VN_CURDATE() DO + WHILE datFEC < vn.VN_CURDATE() DO IF DAY(datFEC) MOD 28 = 0 THEN -- esto solo sirve para no aburrirse mientras esperamos... SELECT datFEC; @@ -4788,6 +4397,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `fruitsEvolution` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4795,8 +4406,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `fruitsEvolution`() BEGIN @@ -4818,6 +4427,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `indicatorsUpdate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4825,8 +4436,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `indicatorsUpdate`(vDated DATE) BEGIN @@ -4874,39 +4483,35 @@ BEGIN UPDATE indicators SET countEmployee = ( SELECT CAST(SUM(hours_week) / 40 AS DECIMAL (10 , 2 )) - FROM - postgresql.business AS b - JOIN postgresql.profile p ON p.profile_id = b.provider_id - JOIN postgresql.person pe ON pe.person_id = p.person_id - LEFT JOIN - postgresql.business_labour AS bl ON bl.business_id = b.business_id - LEFT JOIN - postgresql.calendar_labour_type AS cl ON cl.calendar_labour_type_id = bl.calendar_labour_type_id - WHERE - (vDated BETWEEN b.date_start AND b.date_end OR (b.date_end IS NULL AND b.date_start <= vDated)) - AND pe.name = 'VERDNATURA LEVANTE SL' + FROM postgresql.business b + JOIN postgresql.profile p ON p.profile_id = b.provider_id + JOIN postgresql.person pe ON pe.person_id = p.person_id + LEFT JOIN postgresql.business_labour bl ON bl.business_id = b.business_id + LEFT JOIN postgresql.calendar_labour_type cl ON cl.calendar_labour_type_id = bl.calendar_labour_type_id + WHERE (vDated BETWEEN b.date_start AND b.date_end OR (b.date_end IS NULL AND b.date_start <= vDated)) + AND pe.name = 'VERDNATURA LEVANTE SL' ) WHERE updated = vDated; -- Maná medio acumulado por comercial - UPDATE indicators - SET averageMana = - (SELECT avg(used) - FROM bs.mana_spellers + UPDATE indicators + SET averageMana = + (SELECT AVG(amount) + FROM vn.workerMana ) WHERE updated = vDated; - + -- Número de clientes que han comprado en los últimos 30 dias - UPDATE indicators + UPDATE indicators SET lastMonthActiveClients = (SELECT COUNT(DISTINCT t.clientFk) FROM vn.ticket t WHERE t.shipped BETWEEN oneMonthBefore AND vDated ) - WHERE updated = vDated; - - -- Número de clientes que no han comprado en los últimos 30 dias, pero compraron en los 30 anteriores - UPDATE indicators + WHERE updated = vDated; + + -- Número de clientes que no han comprado en los últimos 30 dias, pero compraron en los 30 anteriores + UPDATE indicators SET lastMonthLostClients = (SELECT COUNT(lm.clientFk) FROM @@ -4924,7 +4529,7 @@ BEGIN ) lm ON lm.clientFk = cm.clientFk WHERE cm.clientFk IS NULL ) - WHERE updated = vDated; + WHERE updated = vDated; -- Número de clientes que han comprado en los últimos 30 dias, pero no compraron en los 30 anteriores UPDATE indicators @@ -4945,17 +4550,17 @@ BEGIN ) lm ON lm.clientFk = cm.clientFk WHERE lm.clientFk IS NULL ) - WHERE updated = vDated; - - -- Porcentaje de autopedidos sobre los pedidos totales - UPDATE indicators - SET lastMonthWebBuyingRate = - ( SELECT (SUM(source_app != '') - SUM(source_app = 'TPV')) / SUM(source_app != '') - FROM hedera.`order` - WHERE date_send BETWEEN oneMonthBefore AND vDated + WHERE updated = vDated; + + -- Porcentaje de autopedidos sobre los pedidos totales + UPDATE indicators + SET lastMonthWebBuyingRate = + ( SELECT (SUM(source_app != '') - SUM(source_app = 'TPV')) / SUM(source_app != '') + FROM hedera.`order` + WHERE date_send BETWEEN oneMonthBefore AND vDated ) - WHERE updated = vDated; - + WHERE updated = vDated; + /* -- Indicadores de producción UPDATE indicators i @@ -4978,22 +4583,22 @@ BEGIN WHERE dated=vDated INTO vWeek; TRUNCATE `bs`.`salesByWeek`; - - INSERT INTO `bs`.`salesByWeek` (week,year,sales) + + INSERT INTO `bs`.`salesByWeek` (week,year,sales) SELECT `t`.`week` AS `week`,`t`.`year` AS `year`, SUM(`v`.`importe` + `v`.`recargo`) AS `sales` FROM `bs`.`ventas` `v` LEFT JOIN `vn`.`time` `t` ON `t`.`dated` = fecha GROUP BY `t`.`week` , `t`.`year` ORDER BY `t`.`week` , `t`.`year`; - - -- CAP Indicador Ventas semana actual - UPDATE indicators i + + -- CAP Indicador Ventas semana actual + UPDATE indicators i JOIN `bs`.`salesByWeek` s ON s.week= vWeek AND s.year = YEAR(vDated) SET i.thisWeekSales = s.sales - WHERE updated = vDated; - - -- CAP indicador ventas semana actual en el año pasado - UPDATE indicators i + WHERE updated = vDated; + + -- CAP indicador ventas semana actual en el año pasado + UPDATE indicators i JOIN `bs`.`salesByWeek` s ON s.week= vWeek AND s.year = YEAR(vDated)-1 SET i.lastYearWeekSales = s.sales WHERE updated = vDated; @@ -5004,6 +4609,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `indicatorsUpdateLauncher` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5011,8 +4618,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `indicatorsUpdateLauncher`() BEGIN @@ -5023,7 +4628,7 @@ BEGIN INTO vDated FROM bs.indicators; - WHILE vDated < util.VN_CURDATE() DO + WHILE vDated < vn.VN_CURDATE() DO CALL indicatorsUpdate(vDated); @@ -5039,6 +4644,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `inspeccionSS_2021_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5046,8 +4653,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `inspeccionSS_2021_add`() BEGIN @@ -5093,6 +4698,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `m3Add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5100,8 +4707,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `m3Add`() BEGIN @@ -5112,7 +4717,7 @@ BEGIN SELECT TIMESTAMPADD(WEEK, -1,MAX(fecha)) INTO datSTART FROM bs.m3; - SET datEND = TIMESTAMPADD(DAY,-1,util.VN_CURDATE()); + SET datEND = TIMESTAMPADD(DAY,-1,vn.VN_CURDATE()); DELETE FROM bs.m3 WHERE fecha >= datSTART; @@ -5138,6 +4743,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `manaCustomerUpdate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5145,8 +4752,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `manaCustomerUpdate`() BEGIN @@ -5186,7 +4791,7 @@ BEGIN INTO vFromDated FROM vn.clientManaCache; - WHILE timestampadd(DAY,30,vFromDated) < util.VN_CURDATE() DO + WHILE timestampadd(DAY,30,vFromDated) < vn.VN_CURDATE() DO SELECT timestampadd(DAY,30,vFromDated), @@ -5244,6 +4849,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `manaSpellers_actualize` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5251,27 +4858,21 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `manaSpellers_actualize`() BEGIN +/** + * Recalcula el valor del campo con el modificador de precio para el componente de maná automático. + */ - /* PAK 2019/08/09 updated - * - * Recalcula el valor del campo con el modificador de precio para el componente de maná automático. - * La tabla mana_spellers es una caché - * - */ - - UPDATE mana_spellers me + UPDATE vn.workerMana wm JOIN - (SELECT Id_Trabajador, FLOOR(SUM(importe)/12) as pesoCarteraMensual + (SELECT Id_Trabajador workerFk, FLOOR(SUM(importe)/12) pesoCarteraMensual FROM bs.vendedores - WHERE año * 100 + mes >= (YEAR(util.VN_CURDATE()) -1) * 100 + MONTH(util.VN_CURDATE()) - GROUP BY Id_Trabajador - ) lastYearSales USING(Id_Trabajador) - SET me.prices_modifier_rate = GREATEST(me.minRate,LEAST(me.maxRate,ROUND(- me.used/lastYearSales.pesoCarteraMensual,3))) ; + WHERE año * 100 + mes >= (YEAR(vn.VN_CURDATE()) -1) * 100 + MONTH(vn.VN_CURDATE()) + GROUP BY workerFk + ) lastYearSales USING(workerFk) + SET pricesModifierRate = GREATEST(minRate, LEAST(maxRate, ROUND(- amount/lastYearSales.pesoCarteraMensual,3))); END ;; DELIMITER ; @@ -5279,43 +4880,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 `mermasCacheUpdate__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `mermasCacheUpdate__`() -BEGIN - - DECLARE vTimeRange INT DEFAULT 30; - DECLARE vCurYearStarted DATE DEFAULT TIMESTAMPADD(DAY, - vTimeRange, util.VN_CURDATE()); - DECLARE vCurYearFinished DATE DEFAULT util.VN_CURDATE(); - DECLARE vLastYearStarted DATE DEFAULT TIMESTAMPADD(YEAR, -1 , vCurYearStarted); - DECLARE vLastYearFinished DATE DEFAULT TIMESTAMPADD(YEAR, -1 , vCurYearFinished); - - REPLACE bs.mermasCache - SELECT Comprador, - IF(Fecha < vCurYearStarted, year(util.VN_CURDATE()) - 1,year(util.VN_CURDATE())) año, - CAST(sum(Importe) as DECIMAL(10,0)) as Valor_Compra, - CAST(sum(IF(Cliente LIKE 'FALTAS',Importe,0)) as DECIMAL(10,0)) as Faltas, - CAST(sum(IF(Cliente LIKE 'BASURA',Importe,0)) as DECIMAL(10,0)) as Basura - FROM bs.mermas - WHERE Fecha BETWEEN vCurYearStarted AND vCurYearFinished - OR Fecha BETWEEN vLastYearStarted AND vLastYearFinished - GROUP BY año, Comprador; - - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `nightTask_launchAll` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5323,8 +4889,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `nightTask_launchAll`() BEGIN @@ -5343,7 +4907,7 @@ BEGIN DECLARE rs CURSOR FOR SELECT id, `schema`, `procedure` FROM nightTask - WHERE finished <= util.VN_CURDATE() + WHERE finished <= vn.VN_CURDATE() OR finished IS NULL ORDER BY `order`; @@ -5362,7 +4926,7 @@ BEGIN END IF; UPDATE nightTask - SET `started` = util.VN_NOW(), + SET `started` = vn.VN_NOW(), `finished` = NULL, `error` = NULL, `errorCode` = NULL @@ -5385,8 +4949,8 @@ BEGIN WHERE id = vId; ELSE UPDATE nightTask - SET finished = util.VN_NOW(), - lastFinished = util.VN_NOW() + SET finished = vn.VN_NOW(), + lastFinished = vn.VN_NOW() WHERE id = vId; END IF; END LOOP; @@ -5413,6 +4977,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `nightTask_launchTask` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5420,8 +4986,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `nightTask_launchTask`( vSchema VARCHAR(255), @@ -5452,6 +5016,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `payMethodClientAdd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5459,13 +5025,11 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `payMethodClientAdd`() BEGIN INSERT IGNORE INTO `bs`.`payMethodClient` (dated, payMethodFk, clientFk) - SELECT util.VN_CURDATE(), c.payMethodFk, c.id + SELECT vn.VN_CURDATE(), c.payMethodFk, c.id FROM vn.client c JOIN vn.payMethod p ON c.payMethodFk = p.id; @@ -5486,6 +5050,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `produccionAdd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5493,8 +5059,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `produccionAdd`(vDate DATE) BEGIN @@ -5537,6 +5101,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `produccion_launcher` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5544,8 +5110,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `produccion_launcher`(vDateFrom DATE, vDateTo DATE) BEGIN @@ -5599,6 +5163,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `produccion_launcher_auto` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5606,15 +5172,13 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `produccion_launcher_auto`() BEGIN - DECLARE vDate DATE DEFAULT TIMESTAMPADD(WEEK, -1, util.VN_CURDATE()); + DECLARE vDate DATE DEFAULT TIMESTAMPADD(WEEK, -1, vn.VN_CURDATE()); - WHILE vDate <= util.VN_CURDATE() DO + WHILE vDate <= vn.VN_CURDATE() DO CALL bs.produccionAdd(vDate); @@ -5622,9 +5186,9 @@ BEGIN END WHILE; - SET vDate = TIMESTAMPADD(DAY,-372, util.VN_CURDATE()); + SET vDate = TIMESTAMPADD(DAY,-372, vn.VN_CURDATE()); - WHILE vDate <= TIMESTAMPADD(YEAR,-1, util.VN_CURDATE()) DO + WHILE vDate <= TIMESTAMPADD(YEAR,-1, vn.VN_CURDATE()) DO CALL bs.produccionAdd(vDate); @@ -5638,6 +5202,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `pruebas` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5645,8 +5211,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `pruebas`(IN vDateStart DATE, IN vDateEnd DATE) BEGIN @@ -5678,6 +5242,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `saleGraphic` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5685,8 +5251,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleGraphic`(IN vItemFk INT, IN vTypeFk INT, IN vCategoryFk INT, IN vFromDate DATE, IN vToDate DATE, IN vProducerFk INT) @@ -5700,8 +5264,8 @@ BEGIN SET vItemFk = IFNULL(vItemFk,0); SET vTypeFk = IFNULL(vTypeFk, 0); SET vCategoryFk = IFNULL(vCategoryFk,0); - SET vFromDate = IFNULL(vFromDate,util.VN_CURDATE()); - SET vToDate = IFNULL(vToDate,util.VN_CURDATE()); + SET vFromDate = IFNULL(vFromDate,vn.VN_CURDATE()); + SET vToDate = IFNULL(vToDate,vn.VN_CURDATE()); SET vProducerFk = IFNULL(vProducerFk,0); SET vFromDateLastYear = TIMESTAMPADD(YEAR,-1,vFromDate); @@ -5730,6 +5294,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `salePersonEvolutionAdd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5737,13 +5303,11 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `salePersonEvolutionAdd`(IN vDateStart DATETIME) BEGIN DELETE FROM bs.salePersonEvolution - WHERE dated <= DATE_SUB(util.VN_CURDATE(), INTERVAL 1 YEAR); + WHERE dated <= DATE_SUB(vn.VN_CURDATE(), INTERVAL 1 YEAR); INSERT INTO bs.salePersonEvolution (dated, amount, equalizationTax, salesPersonFk) @@ -5763,6 +5327,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `salesByclientSalesPerson_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -5770,14 +5336,12 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `salesByclientSalesPerson_add`(vDatedFrom DATE) BEGIN IF vDatedFrom IS NULL THEN - SELECT util.VN_CURDATE() - INTERVAL DAY(util.VN_CURDATE())-1 DAY - INTERVAL 1 MONTH INTO vDatedFrom; + SELECT vn.VN_CURDATE() - INTERVAL DAY(vn.VN_CURDATE())-1 DAY - INTERVAL 1 MONTH INTO vDatedFrom; END IF; INSERT INTO salesByclientSalesPerson( dated, salesPersonFk, clientFk, amount, equalizationTax) @@ -5804,36 +5368,296 @@ 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `salesByItemTypeDay_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `salesByItemTypeDay_add`(vDateStart DATE, vDateEnd DATE) +BEGIN +/** + * Almacena datos relativos a las ventas de artículos agrupados por reino y familia + * + * @param vDateStart + * @param vDateEnd + */ + + DELETE FROM bs.salesByItemTypeDay + WHERE dated BETWEEN vDateStart AND vDateEnd; + + INSERT INTO bs.salesByItemTypeDay (itemTypeFk, itemCategoryFk, dated) + SELECT id, categoryFk, dated + FROM vn.itemType + JOIN vn.`time` + WHERE dated BETWEEN vDateStart AND vDateEnd; + + UPDATE bs.salesByItemTypeDay it + JOIN (SELECT ic.id itemCategoryFk, + it.id itemTypeFk, + bs.dated, + SUM(bs.amount) netSale + FROM bs.sale bs + JOIN vn.itemType it ON it.id = bs.typeFk + JOIN vn .itemCategory ic ON ic.id = it.categoryFk + JOIN vn.client c on c.id = bs.clientFk + JOIN vn.sale s ON s.id = bs.saleFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.`time` ti ON ti.dated = bs.dated + WHERE ic.merchandise + AND bs.dated BETWEEN vDateStart AND vDateEnd + GROUP BY ic.id, it.id, bs.dated) sub ON sub.dated = it.dated AND sub.itemCategoryFk = it.itemCategoryFk AND sub.itemTypeFk = it.itemTypeFk + SET it.netSale = sub.netSale; + + + UPDATE bs.salesByItemTypeDay it + JOIN (SELECT ic.id AS itemCategoryFk, + it.id AS itemTypeFk, + bs.dated, + SUM(i.stems * s.quantity) stems + FROM bs.sale bs + JOIN vn.itemType it ON it.id = bs.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.sale s ON s.id = bs.saleFk + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.`time` tm ON tm.dated = bs.dated + WHERE ic.merchandise + AND bs.dated BETWEEN vDateStart AND vDateEnd + GROUP BY ic.id, it.id, bs.dated) sub ON sub.dated = it.dated AND sub.itemCategoryFk = it.itemCategoryFk AND sub.itemTypeFk = it.itemTypeFk + SET it.stems = sub.stems; + + + UPDATE bs.salesByItemTypeDay it + JOIN (SELECT ic.id AS itemCategoryFk, + it.id AS itemTypeFk, + DATE(t.shipped) dated, + COUNT(DISTINCT(i.id)) `references` + FROM vn.ticket t + 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 + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + WHERE ic.merchandise + AND t.shipped BETWEEN vDateStart AND util.dayEnd(vDateEnd) + GROUP BY ic.id, it.id, dated) sub ON sub.dated = it.dated AND sub.itemCategoryFk = it.itemCategoryFk AND sub.itemTypeFk = it.itemTypeFk + SET it.`references` = sub.`references`; + + UPDATE bs.salesByItemTypeDay it + JOIN (SELECT ic.id AS itemCategoryFk, + it.id AS itemTypeFk, + DATE(t.shipped) dated, + SUM(i.stems*s.quantity) AS trash + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.client c ON c.id = t.clientFk + WHERE c.name = 'BASURA' + AND t.shipped BETWEEN vDateStart AND util.dayEnd(vDateEnd) + GROUP BY ic.id, it.id, dated) sub ON sub.dated = it.dated AND sub.itemCategoryFk = it.itemCategoryFk AND sub.itemTypeFk = it.itemTypeFk + SET it.trash = sub.trash; + + UPDATE bs.salesByItemTypeDay it + JOIN (SELECT ic.id AS itemCategoryFk, + it.id AS itemTypeFk, + DATE(t.shipped) dated, + SUM(IFNULL(i.stems, 1) * s.quantity) AS faults + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.client c ON c.id = t.clientFk + WHERE c.name = 'FALTAS' + AND t.shipped BETWEEN vDateStart AND util.dayEnd(vDateEnd) + GROUP BY ic.id, it.id, dated) sub ON sub.dated = it.dated AND sub.itemCategoryFk = it.itemCategoryFk AND sub.itemTypeFk = it.itemTypeFk + SET it.`faults` = sub.`faults`; + + UPDATE bs.salesByItemTypeDay it + JOIN (SELECT ic.id AS itemCategoryFk, + it.id AS itemTypeFk, + DATE(t.shipped) dated, + SUM((cb.quantity * s.price * (100 - s.discount) / 100) * ((cc.maxResponsibility - c.responsibility )/4 )) accepted, + SUM(cb.quantity * s.price * (100 - s.discount) / 100) claimed + FROM vn.claim c + JOIN vn.claimBeginning cb ON cb.claimFk = c.id + JOIN vn.sale s ON s.id = cb.saleFk + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.claimConfig cc + WHERE ic.merchandise + AND t.shipped BETWEEN vDateStart AND util.dayEnd(vDateEnd) + GROUP BY ic.id, it.id, dated) sub ON sub.dated = it.dated AND sub.itemCategoryFk = it.itemCategoryFk AND sub.itemTypeFk = it.itemTypeFk + SET it.accepted = sub.accepted, + it.claimed = sub.claimed; + + UPDATE bs.salesByItemTypeDay it + JOIN(SELECT itemCategoryFk, + itemTypeFk, + dated, + CAST(SUM(sale) AS DECIMAL(10,2)) sale, + CAST(SUM(buy) AS DECIMAL(10,2))buy + FROM(SELECT ic.id itemCategoryFk, + it.id itemTypeFk, + bs.dated, + SUM(bs.amount) sale, + 0 buy + FROM bs.sale bs + JOIN vn.itemType it ON it.id = bs.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.client c on c.id = bs.clientFk + JOIN vn.`time` tm ON tm.dated = bs.dated + JOIN vn.sale s ON s.id = bs.saleFk + JOIN vn.item i ON i.id = s.itemFk + WHERE ic.merchandise + AND bs.dated BETWEEN vDateStart AND vDateEnd + GROUP BY ic.id, it.id, bs.dated + UNION ALL + SELECT ic.id, + it.id, + t.landed, + 0 , + SUM(b.buyingValue * b.quantity) + FROM vn.entry e + JOIN vn.travel t ON t.id = e.travelFk + JOIN vn.buy b ON b.entryFk = e.id + JOIN vn.item i ON i.id = b.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + WHERE ic.merchandise + AND t.landed BETWEEN vDateStart AND vDateEnd + GROUP BY ic.id, it.id, t.landed) sub + GROUP BY itemCategoryFk, itemTypeFk, dated) sub2 ON sub2.dated = it.dated AND sub2.itemCategoryFk = it.itemCategoryFk AND sub2.itemTypeFk = it.itemTypeFk + SET it.sale = sub2.sale, + it.buy = sub2.buy; + + DROP TEMPORARY TABLE IF EXISTS tmp.`component`; + CREATE TEMPORARY TABLE tmp.`component` + (PRIMARY KEY (`itemTypeFk`,`dated`), + KEY `salesByItemTypeDay_itemCategoryFk_idx` (`itemCategoryFk`), + KEY `salesByItemTypeDay_dated_idx` (`dated`)) + ENGINE = MEMORY + SELECT DATE(t.shipped) dated, + ic.id itemCategoryFk, + it.id itemTypeFk, + SUM(s.quantity * IF(c.code = 'purchaseValue', sc.value,0)) costComponent, + SUM(s.quantity * IF(ct.isMargin, sc.value,0)) marginComponent + FROM vn.ticket t + JOIN vn.sale s ON t.id = s.ticketFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.saleComponent sc ON sc.saleFk = s.id + STRAIGHT_JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk + WHERE t.shipped BETWEEN vDateStart AND util.dayEnd(vDateEnd) + GROUP BY ic.id, it.id, dated; + + UPDATE bs.salesByItemTypeDay it + JOIN tmp.`component` c ON c.dated = it.dated AND c.itemCategoryFk = it.itemCategoryFk AND c.itemTypeFk = it.itemTypeFk + SET it.costComponent = c.costComponent, + it.marginComponent = c.marginComponent, + it.saleComponent = c.costComponent + c.marginComponent; + + DROP TEMPORARY TABLE tmp.`component`; + +/* UPDATE bs.salesByItemTypeDay it + JOIN(SELECT DATE(t.shipped) dated, + ic.id itemCategoryFk, + it.id itemTypeFk, + SUM(s.quantity * IF(c.code = 'purchaseValue', sc.value,0)) costComponent, + SUM(s.quantity * IF(ct.isMargin, sc.value,0)) marginComponent + FROM vn.ticket t + JOIN vn.sale s ON t.id = s.ticketFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + JOIN vn.saleComponent sc ON sc.saleFk = s.id + STRAIGHT_JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk + JOIN vn.`time` tm ON tm.dated = DATE(t.shipped) + WHERE t.shipped BETWEEN vDateStart AND util.dayEnd(vDateEnd) + GROUP BY ic.id, it.id, dated)sub ON sub.dated = it.dated AND sub.itemCategoryFk = it.itemCategoryFk AND sub.itemTypeFk = it.itemTypeFk + SET it.costComponent = sub.costComponent, + it.marginComponent = sub.marginComponent, + it.saleComponent = sub.costComponent + sub.marginComponent;*/ +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `salesByItemTypeDay_addLauncher` */; +/*!50003 SET @saved_cs_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `salesByItemTypeDay_addLauncher`() +BEGIN + DECLARE vDateStart,vDateEnd INT; + + SELECT DATE_SUB(vn.VN_CURDATE(), INTERVAL 30 DAY), vn.VN_CURDATE() INTO vDateStart,vDateEnd; + CALL bs.salesByItemTypeDay_add(vDateStart, vDateEnd); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `salesMonthlySnapshot_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' */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `salesMonthlySnapshot_add`() BEGIN - DECLARE vPlusNewClient INT DEFAULT 100; - DECLARE vScoreNewClient INT DEFAULT 100; + DECLARE vExecutionDay INT; + DECLARE vPlusNewClient INT; + DECLARE vPlusDifference INT; + DECLARE vScoreNewClient INT; + DECLARE vScoreDifference INT; + DECLARE vMaxWorkersWithPlusNewClient INT; DECLARE vRowCount INT DEFAULT 1; DECLARE vMaxRow INT; - - IF(DAY(util.VN_CURDATE()) = 5) THEN + DECLARE vPreviusMonth DATETIME DEFAULT vn.VN_CURDATE(); + + SELECT executionDay, maxPlusNewClient, plusDifference, maxScoreNewClient, scoreDifference, salesPersonWithPlusNewClient + INTO vExecutionDay, vPlusNewClient, vPlusDifference, vScoreNewClient, vScoreDifference, vMaxWorkersWithPlusNewClient + FROM vn.commissionConfig; + + IF(DAY(vn.VN_CURDATE()) = vExecutionDay) THEN -- COMERCIAL Y EQUIPO DROP TEMPORARY TABLE IF EXISTS tmp.salesPersons; CREATE TEMPORARY TABLE tmp.salesPersons ENGINE = MEMORY - SELECT u.id workerFk, + SELECT u.id workerFk, u.name salesPersonName, d.name teamName - FROM vn.department d + FROM vn.department d JOIN vn.workerDepartment wd ON wd.departmentFk = d.id JOIN account.user u ON u.id = wd.workerFk - WHERE d.name LIKE '%EQUIPO%'; - + JOIN vn.department d2 ON d2.id = d.parentFk + WHERE d2.code = 'VT'; + -- VENTA, COMISIÓN DROP TEMPORARY TABLE IF EXISTS tmp.sale; CREATE TEMPORARY TABLE tmp.sale @@ -5850,164 +5674,166 @@ BEGIN JOIN vn.client c ON c.id = s.salesPersonFk JOIN account.user u ON u.id = s.salesPersonFk JOIN vn.commissionConfig cc - WHERE dated BETWEEN util.firstDayOfMonth(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) AND LAST_DAY(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) + WHERE dated BETWEEN util.firstDayOfMonth(vPreviusMonth) AND LAST_DAY(vPreviusMonth) GROUP BY year, month, workerFk; - + -- OBJETIVO EVALUABLE (GRUPO) Y OBJETIVO INCENTIVO (INDIVIDUAL) DROP TEMPORARY TABLE IF EXISTS tmp.objectives; CREATE TEMPORARY TABLE tmp.objectives ENGINE = MEMORY - SELECT sg.rank, - sg.goal goalGroup, - sg2.goal goalIncentive, - sub.walletWeigth, - sub.walletWeigth*sg2.goal/100 AS incentiveObjective, - sub.walletWeigth*sg.goal/100 AS evaluableObjective, - sub.workerFk, - rb.bonus - FROM ( - SELECT - CASE - WHEN portfolioWeight >= sg1.walletWeightFrom - AND portfolioWeight <= sg1.walletWeightTo THEN 1 - WHEN portfolioWeight >= sg2.walletWeightFrom - AND portfolioWeight <= sg2.walletWeightTo THEN 2 - WHEN portfolioWeight >= sg3.walletWeightFrom - AND portfolioWeight <= sg3.walletWeightTo THEN 3 - WHEN portfolioWeight >= sg4.walletWeightFrom - AND portfolioWeight <= sg4.walletWeightTo THEN 4 - WHEN portfolioWeight >= sg5.walletWeightFrom - AND portfolioWeight <= sg5.walletWeightTo THEN 5 - END rank, - u.id workerFk, - IFNULL(v.portfolioWeight,0) AS walletWeigth - FROM bs.vendedores v - JOIN account.`user` u ON u.id = v.Id_Trabajador - JOIN vn.saleGoal sg1 ON sg1.`rank` = 1 AND sg1.`year` = YEAR(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) AND sg1.`month` = MONTH(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) - JOIN vn.saleGoal sg2 ON sg2.`rank` = 2 AND sg2.`year` = YEAR(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) AND sg2.`month` = MONTH(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) - JOIN vn.saleGoal sg3 ON sg3.`rank` = 3 AND sg3.`year` = YEAR(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) AND sg3.`month` = MONTH(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) - JOIN vn.saleGoal sg4 ON sg4.`rank` = 4 AND sg4.`year` = YEAR(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) AND sg4.`month` = MONTH(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) - JOIN vn.saleGoal sg5 ON sg5.`rank` = 5 AND sg5.`year` = YEAR(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) AND sg5.`month` = MONTH(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) - WHERE v.año = YEAR(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH))-1 AND v.mes = MONTH(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) - GROUP BY u.id - ) sub - JOIN vn.saleGoal sg ON sg.`rank` = sub.rank AND sg.goalType = 'grupo' AND sg.`year` = YEAR(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) AND sg.`month` = MONTH(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) - JOIN vn.saleGoal sg2 ON sg2.`rank` = sub.rank AND sg2.goalType = 'individual' AND sg2.`year` = YEAR(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) AND sg2.`month` = MONTH(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) - JOIN vn.rankBonus rb ON rb.`rank` = sub.`rank`; - - -- PUNTUACIÓN EQUIPO, PLUS OBJETIVO EQUIPO Y PLUS VARIABLE JEFE DE EQUIPO - DROP TEMPORARY TABLE IF EXISTS tmp.scoreTeam; + SELECT + sg.rank, + sg.goal goalGroup, + sg4.goal goalIncentive, + sub.walletWeigth, + sub.walletWeigth*sg4.goal/100 AS incentiveObjective, + sub.walletWeigth*sg.goal/100 AS evaluableObjective, + sub.workerFk, + rb.bonus + FROM ( + SELECT sg.`rank` , + u.id workerFk, + IFNULL(v.portfolioWeight,0) AS walletWeigth + FROM bs.vendedores v + JOIN account.`user` u ON u.id = v.Id_Trabajador + JOIN vn.saleGoal sg ON sg.`year` = YEAR(vPreviusMonth) + AND sg.`month` = MONTH(vPreviusMonth) + AND v.portfolioWeight BETWEEN sg.walletWeightFrom AND sg.walletWeightTo + WHERE v.año = YEAR(vPreviusMonth)-1 AND v.mes = MONTH(vPreviusMonth) + GROUP BY u.id + ) sub + JOIN vn.saleGoal sg ON sg.`rank` = sub.rank AND sg.goalType = '1' AND sg.`year` = YEAR(vPreviusMonth) AND sg.`month` = MONTH(vPreviusMonth) + JOIN vn.saleGoal sg4 ON sg4.`rank` = sub.rank AND sg4.goalType = '4' AND sg4.`year` = YEAR(vPreviusMonth) AND sg4.`month` = MONTH(vPreviusMonth) + LEFT JOIN account.`user` u2 ON u2.id = sub.workerFk + JOIN vn.rankBonus rb ON rb.`rank` = sub.`rank`; + + -- PUNTUACIÓN EQUIPO, PLUS OBJETIVO EQUIPO + DROP TEMPORARY TABLE IF EXISTS tmp.scoreTeam; CREATE TEMPORARY TABLE tmp.scoreTeam ENGINE = MEMORY - SELECT *, - IF(sub1.teamScore >= sub1.minScoreForPlusTeam, sub1.plusTeamValue, 0) teamPlus, - IF(sub1.teamScore >= sub1.minScoreForPlusBoss, countSalesPerson * sub1.plusBoss, 0) teamBossPlus + SELECT *, + IF(sub1.teamScore >= sub1.minScoreForPlusTeam, sub1.plusTeamValue, 0) teamPlus FROM ( - SELECT *, - (100/sub.countSalesPerson)*countGroupAchieved teamScore + SELECT *, + (100/sub.countSalesPerson)*countGroupAchieved teamScore FROM ( SELECT COUNT(u.id) countSalesPerson, u.id workerFk, u.name salesPersonName, + d3.workerFk bossFk, d.name teamName, cc.minScoreForPlusTeam, cc.minScoreForPlusBoss, cc.plusTeam plusTeamValue, cc.plusBoss, SUM(IF(s.currentSale > r.evaluableObjective, 1, 0)) countGroupAchieved - FROM vn.department d + FROM vn.department d JOIN vn.workerDepartment wd ON wd.departmentFk = d.id JOIN account.user u ON u.id = wd.workerFk JOIN tmp.sale s ON s.workerFk = wd.workerFk JOIN tmp.objectives r ON r.workerFk = wd.workerFk - JOIN vn.commissionConfig cc - WHERE d.name LIKE '%EQUIPO%' + JOIN vn.commissionConfig cc + JOIN vn.department d2 ON d2.id = d.parentFk + JOIN vn.department d3 ON d3.name = d.name + WHERE d2.code = 'VT' GROUP BY d.name ) sub ) sub1; - + + -- PLUS VARIABLE JEFE DE EQUIPO + DROP TEMPORARY TABLE IF EXISTS tmp.plusBoss; + CREATE TEMPORARY TABLE tmp.plusBoss + ENGINE = MEMORY + SELECT d.workerFk, + IF(st.teamScore >= st.minScoreForPlusBoss , st.countSalesPerson * st.plusBoss, 0) teamBossPlus + FROM tmp.scoreTeam st + JOIN vn.department d ON d.name = st.teamName; + -- PLUS CLIENTES NUEVOS DROP TEMPORARY TABLE IF EXISTS tmp.newClients; CREATE TEMPORARY TABLE tmp.newClients ( - id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, - workerFk INTEGER(11), - name VARCHAR(30), - total DECIMAL(10,3), - newClientPlus INTEGER(11), - newClientScore INTEGER(11) + id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, + workerFk INTEGER(11), + name VARCHAR(30), + total DECIMAL(10,3), + newClientPlus INTEGER(11), + newClientScore INTEGER(11) ); - + INSERT INTO tmp.newClients (workerFk, total, name, newClientPlus) SELECT u.id workerFk, u.name, SUM(v.importe) total, vPlusNewClient - FROM bs.clientNewBorn cn + FROM bs.clientNewBorn cn JOIN bs.ventas v ON DATE_ADD(cn.firstShipped, INTERVAL 1 YEAR) > v.fecha AND v.Id_Cliente = cn.clientFk - JOIN vn.client c ON c.id = v.Id_Cliente - JOIN account.user u ON u.id = c.salesPersonFk - JOIN vn.workerDepartment wd ON wd.workerFk = u.id - JOIN vn.department d On d.id = wd.departmentFk - WHERE v.fecha >= util.firstDayOfMonth(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) - AND cn.firstShipped >= util.firstDayOfMonth(DATE_ADD(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH), INTERVAL -1 year)) - AND d.name LIKE 'EQUIPO%' + JOIN vn.client c ON c.id = v.Id_Cliente + JOIN account.user u ON u.id = c.salesPersonFk + JOIN vn.workerDepartment wd ON wd.workerFk = u.id + JOIN vn.department d On d.id = wd.departmentFk + JOIN vn.department d2 ON d2.id = d.parentFk + WHERE v.fecha >= util.firstDayOfMonth(vPreviusMonth) + AND cn.firstShipped >= util.firstDayOfMonth(DATE_ADD(vPreviusMonth, INTERVAL -1 year)) + AND d2.code = 'VT' GROUP BY u.id ORDER BY total DESC; - + SET vMaxRow = ROW_COUNT(); - + my_loop: LOOP - UPDATE tmp.newClients SET newClientPlus = vPlusNewClient WHERE id = vRowCount; - UPDATE tmp.newClients SET newClientScore = vScoreNewClient WHERE id = vRowCount; - - IF (vRowCount <= 20) THEN - SET vPlusNewClient = vPlusNewClient - 5; - ELSE - SET vPlusNewClient = 0; - END IF; - - SET vScoreNewClient = vScoreNewClient - 1; - SET vRowCount = vRowCount + 1; - - IF vRowCount > vMaxRow THEN - LEAVE my_loop; - END IF; - END LOOP my_loop; - - INSERT INTO bs.salesMonthlySnapshot (salesPersonName, teamName, `year`, `month`, currentSale, commissionSale, individualPlus, teamPlus, teamScore, newClientPlus, newClientScore, teamBossPlus) - SELECT * - FROM ( - SELECT sp.salesPersonName, - sp.teamName, - s.`year`, - s.`month`, - s.currentSale, - s.commissionSale, - IF(s.currentSale > s.minimumSalesByMonth AND s.currentSale > r.incentiveObjective, r.bonus, 0) individualPlus, - np.teamPlus, - np.teamScore, - nc.newClientPlus, - nc.newClientScore, - np.teamBossPlus - FROM tmp.salesPersons sp - LEFT JOIN tmp.sale s ON s.workerFk = sp.workerFk - LEFT JOIN tmp.objectives r ON r.workerFk = sp.workerFk - LEFT JOIN tmp.scoreTeam np ON np.teamName = sp.teamName - LEFT JOIN tmp.newClients nc ON nc.workerFk = sp.workerFk - ) sub - ORDER BY salesPersonName; - - DROP TEMPORARY TABLE + UPDATE tmp.newClients SET newClientPlus = vPlusNewClient WHERE id = vRowCount; + UPDATE tmp.newClients SET newClientScore = vScoreNewClient WHERE id = vRowCount; + + IF (vRowCount <= vMaxWorkersWithPlusNewClient) THEN + SET vPlusNewClient = vPlusNewClient - vPlusDifference; + ELSE + SET vPlusNewClient = 0; + END IF; + + SET vScoreNewClient = vScoreNewClient - vScoreDifference; + SET vRowCount = vRowCount + 1; + + IF vRowCount > vMaxRow THEN + LEAVE my_loop; + END IF; + END LOOP my_loop; + + INSERT INTO bs.salesMonthlySnapshot (salesPersonName, teamName, `year`, `month`, currentSale, commissionSale, individualPlus, teamPlus, teamScore, newClientPlus, newClientScore, teamBossPlus) + SELECT * + FROM ( + SELECT sp.salesPersonName, + sp.teamName, + s.`year`, + s.`month`, + s.currentSale, + s.commissionSale, + IF(s.currentSale > s.minimumSalesByMonth AND s.currentSale > r.incentiveObjective, r.bonus, 0) individualPlus, + np.teamPlus, + np.teamScore, + nc.newClientPlus, + nc.newClientScore, + pb.teamBossPlus + FROM tmp.salesPersons sp + LEFT JOIN tmp.sale s ON s.workerFk = sp.workerFk + LEFT JOIN tmp.objectives r ON r.workerFk = sp.workerFk + LEFT JOIN tmp.scoreTeam np ON np.teamName = sp.teamName + LEFT JOIN tmp.plusBoss pb ON pb.workerFk = sp.workerFk + LEFT JOIN tmp.newClients nc ON nc.workerFk = sp.workerFk + ) sub + ORDER BY salesPersonName; + + DROP TEMPORARY TABLE tmp.salesPersons, tmp.sale, tmp.objectives, tmp.scoreTeam, tmp.newClients; 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `salesPersonEvolution_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6015,8 +5841,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `salesPersonEvolution_add`() BEGIN @@ -6040,7 +5864,7 @@ BEGIN SET vDated = TIMESTAMPADD(DAY, 1, vDated); END IF; - WHILE vDated < util.VN_CURDATE() DO + WHILE vDated < vn.VN_CURDATE() DO SET vCont = vCont + 1; @@ -6065,6 +5889,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `salesPerson_updatePortfolio` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6072,8 +5898,6 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `salesPerson_updatePortfolio`() BEGIN @@ -6081,12 +5905,12 @@ BEGIN * Actualiza el campo portfolioWeight que indica el peso de la cartera del comercial * */ - DECLARE vStarted DATE DEFAULT DATE_FORMAT(DATE_ADD(util.VN_CURDATE(), INTERVAL -17 MONTH), '%Y-%m-01'); + DECLARE vStarted DATE DEFAULT DATE_FORMAT(DATE_ADD(vn.VN_CURDATE(), INTERVAL -17 MONTH), '%Y-%m-01'); UPDATE vendedores v JOIN vn.`time` t ON t.`year` = v.año AND t.`month` = v.mes SET v.portfolioWeight = NULL - WHERE t.dated BETWEEN vStarted AND util.VN_CURDATE(); + WHERE t.dated BETWEEN vStarted AND vn.VN_CURDATE(); UPDATE vendedores v JOIN ( @@ -6098,7 +5922,7 @@ BEGIN STRAIGHT_JOIN bs.ventas v ON t.dated = v.fecha JOIN vn.`client` c ON c.id = v.Id_Cliente WHERE c.lastSalesPersonFk IS NOT NULL - AND v.fecha BETWEEN vStarted AND util.VN_CURDATE() + AND v.fecha BETWEEN vStarted AND vn.VN_CURDATE() GROUP BY c.lastSalesPersonFk, t.`year`, t.`month` ) sub ON sub.lastSalesPersonFk = v.Id_Trabajador AND sub.`year` = v.año AND sub.`month`= v.mes SET v.portfolioWeight = sub.importe; @@ -6108,6 +5932,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `vendedores_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6115,8 +5941,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `vendedores_add`(intYEAR INT, vQuarter INT) BEGIN @@ -6185,6 +6009,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `vendedores_add_launcher` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6192,16 +6018,14 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `vendedores_add_launcher`() BEGIN DECLARE vDatedFrom DATE; - CALL bs.vendedores_add(YEAR(util.VN_CURDATE()),QUARTER(util.VN_CURDATE())); + CALL bs.vendedores_add(YEAR(vn.VN_CURDATE()),QUARTER(vn.VN_CURDATE())); CALL bs.vendedores_evolution_add; - SELECT util.firstDayOfMonth(util.VN_CURDATE())- INTERVAL 1 MONTH INTO vDatedFrom; + SELECT util.firstDayOfMonth(vn.VN_CURDATE())- INTERVAL 1 MONTH INTO vDatedFrom; CALL bs.salesByclientSalesPerson_add(vDatedFrom); END ;; @@ -6210,29 +6034,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 `vendedores_add_launcher__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `vendedores_add_launcher__`() -BEGIN - - CALL bs.vendedores_add(YEAR(util.VN_CURDATE()),QUARTER(util.VN_CURDATE())); - CALL bs.vendedores_evolution_add; - CALL bs.salesPersonClient_add(YEAR(util.VN_CURDATE()), QUARTER(util.VN_CURDATE())); - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `vendedores_evolution_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6240,8 +6043,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `vendedores_evolution_add`() BEGIN @@ -6254,8 +6055,8 @@ Inserta en la tabla compradores_evolution las ventas acumuladas en el ultimo mes DECLARE vDateFrom DATE; DECLARE vDateTo DATE; - SET vCurYear = year(util.VN_CURDATE()); - SET vCurMonth = month(util.VN_CURDATE()); + SET vCurYear = year(vn.VN_CURDATE()); + SET vCurMonth = month(vn.VN_CURDATE()); SELECT IFNULL(max(year),vCurYear-1), IFNULL(max(month),1) INTO vYear, vMonth @@ -6296,6 +6097,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ventas_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6303,8 +6106,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ventas_add`(IN datSTART DATETIME, IN datEND DATETIME) BEGIN @@ -6322,8 +6123,8 @@ BEGIN DECLARE vEndingDate DATETIME; DECLARE TIPO_PATRIMONIAL INT DEFAULT 188; - IF datSTART < TIMESTAMPADD(YEAR,-5,util.VN_CURDATE()) - OR datEND < TIMESTAMPADD(YEAR,-5,util.VN_CURDATE()) THEN + IF datSTART < TIMESTAMPADD(YEAR,-5,vn.VN_CURDATE()) + OR datEND < TIMESTAMPADD(YEAR,-5,vn.VN_CURDATE()) THEN CALL util.throw('fechaDemasiadoAntigua'); END IF; @@ -6388,6 +6189,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ventas_add_launcher` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6395,8 +6198,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ventas_add_launcher`() BEGIN @@ -6407,7 +6208,7 @@ BEGIN * **/ - CALL bs.ventas_add(timestampadd(week,-1,util.VN_CURDATE()),util.VN_CURDATE()); + CALL bs.ventas_add(timestampadd(week,-1,vn.VN_CURDATE()),vn.VN_CURDATE()); END ;; DELIMITER ; @@ -6415,6 +6216,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ventas_contables_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6422,114 +6225,114 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` 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; +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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!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 */ ; @@ -6537,8 +6340,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ventas_contables_add_launcher`() BEGIN @@ -6549,7 +6350,7 @@ BEGIN * **/ - CALL bs.ventas_contables_add(YEAR(TIMESTAMPADD(MONTH,-1,util.VN_CURDATE())), MONTH(TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()))); + CALL bs.ventas_contables_add(YEAR(TIMESTAMPADD(MONTH,-1,vn.VN_CURDATE())), MONTH(TIMESTAMPADD(MONTH,-1,vn.VN_CURDATE()))); END ;; DELIMITER ; @@ -6557,92 +6358,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 `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 = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ventas_contables_add__`(IN vYear INT, IN vMonth INT) -BEGIN -/** - * Reemplaza las ventas contables. Es el origen de datos para el balance de Entradas - * - * @param vYear Año a reemplazar - * @param vMonth Mes a reemplazar - * - * - **/ -DECLARE TIPO_PATRIMONIAL INT DEFAULT 188; - -DELETE FROM bs.ventas_contables - WHERE year = vYear - AND month = vMonth; - -DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; - -CREATE TEMPORARY TABLE tmp.ticket_list - (PRIMARY KEY (Id_Ticket)) - SELECT Id_Ticket - FROM vn2008.Tickets t - JOIN vn2008.Facturas f ON f.Id_Factura = t.Factura - WHERE year(f.Fecha) = vYear - AND month(f.Fecha) = vMonth; - - -INSERT INTO bs.ventas_contables(year - , month - , venta - , grupo - , reino_id - , tipo_id - , empresa_id - , gasto) - - SELECT vYear - , vMonth - , round(sum(Cantidad * Preu * (100 - m.Descuento)/100)) - , if( - e.empresa_grupo = e2.empresa_grupo - ,1 - ,if(e2.empresa_grupo,2,0) - ) as grupo - , tp.reino_id - , a.tipo_id - , t.empresa_id - , 7000000000 - + if(e.empresa_grupo = e2.empresa_grupo - ,1 - ,if(e2.empresa_grupo,2,0) - ) * 1000000 - + tp.reino_id * 10000 as Gasto - FROM vn2008.Movimientos m - JOIN vn2008.Tickets t on t.Id_Ticket = m.Id_Ticket - JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna - JOIN vn2008.Clientes c on c.Id_Cliente = cs.Id_Cliente - JOIN tmp.ticket_list tt on tt.Id_Ticket = t.Id_Ticket - JOIN vn2008.Articles a on m.Id_Article = a.Id_Article - JOIN vn2008.empresa e on e.id = t.empresa_id - LEFT JOIN vn2008.empresa e2 on e2.Id_Cliente = c.Id_Cliente - JOIN vn2008.Tipos tp on tp.tipo_id = a.tipo_id - WHERE Cantidad <> 0 - AND Preu <> 0 - AND m.Descuento <> 100 - AND a.tipo_id != TIPO_PATRIMONIAL - GROUP BY grupo, reino_id, tipo_id, empresa_id, Gasto; - - -DROP TEMPORARY TABLE tmp.ticket_list; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `ventas_contables_por_cliente` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6650,8 +6367,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ventas_contables_por_cliente`(IN vYear INT, IN vMonth INT) BEGIN @@ -6703,6 +6418,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `vivosMuertos` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6710,8 +6427,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `vivosMuertos`() BEGIN @@ -6724,8 +6439,8 @@ BEGIN * @param @datEND Fecha de finalización a buscar */ - SET @datSTART = TIMESTAMPADD(YEAR,-2,util.VN_CURDATE()); - SET @datEND = TIMESTAMPADD(DAY,-DAY(util.VN_CURDATE()),util.VN_CURDATE()); + SET @datSTART = TIMESTAMPADD(YEAR,-2,vn.VN_CURDATE()); + SET @datEND = TIMESTAMPADD(DAY,-DAY(vn.VN_CURDATE()),vn.VN_CURDATE()); DROP TEMPORARY TABLE IF EXISTS tmp.VivosMuertos; @@ -6779,6 +6494,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `waste_addSales` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6786,8 +6503,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `waste_addSales`() BEGIN @@ -6797,7 +6512,7 @@ BEGIN SELECT week, year INTO vWeek, vYear FROM vn.time - WHERE dated = util.VN_CURDATE(); + WHERE dated = vn.VN_CURDATE(); REPLACE bs.waste SELECT *, 100 * mermas / total as porcentaje @@ -6823,66 +6538,21 @@ 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 `waste_addSales_lastWeek__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `waste_addSales_lastWeek__`() -BEGIN - DECLARE vWeek INT; - DECLARE vYear INT; - - SELECT week, year - INTO vWeek, vYear - FROM vn.time - WHERE dated = TIMESTAMPADD(WEEK, -1, util.VN_CURDATE()); - - REPLACE bs.waste - SELECT *, 100 * mermas / total as porcentaje - FROM ( - SELECT buyer, - year, - week, - family, - itemFk, - itemTypeFk, - floor(sum(value)) as total, - floor(sum(IF(clientTypeFk = 'loses', value, 0))) as mermas - FROM vn.saleValue - where year = vYear and week = vWeek - - GROUP BY family, itemFk - - ) sub - ORDER BY mermas 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 `workerLabour_getData` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerLabour_getData`() BEGIN /** * Carga los datos de la plantilla de trabajadores, altas y bajas en la tabla workerLabourDataByMonth para facilitar el cálculo del gráfico en grafana. * Se carga el día 21 de cada mes, elimina los registros del último año y los vuelve a calcular - * */ DECLARE vFristDay DATE; DECLARE vLastDay DATE; @@ -6898,10 +6568,10 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - IF DAY(util.VN_CURDATE()) = 21 THEN + IF DAY(vn.VN_CURDATE()) = 21 THEN - SELECT util.firstDayOfMonth(DATE_SUB(util.VN_CURDATE(), INTERVAL 12 MONTH)), - LAST_DAY(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) + SELECT util.firstDayOfMonth(DATE_SUB(vn.VN_CURDATE(), INTERVAL 12 MONTH)), + LAST_DAY(DATE_SUB(vn.VN_CURDATE(), INTERVAL 1 MONTH)) INTO vDateStarted, vDateEnded; @@ -6923,7 +6593,7 @@ BEGIN INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) SELECT 'hiring', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.workerLabour w - JOIN postgresql.workcenter wc ON wc.workcenter_id = w.workCenterFk + JOIN vn.workCenter wc ON wc.id = w.workCenterFk JOIN postgresql.business_labour_payroll bl ON bl.business_id = w.businessFk JOIN postgresql.person p ON p.id_trabajador = w.workerFk LEFT JOIN vn.workerBusinessType wbt ON wbt.id = bl.cod_contrato @@ -6933,7 +6603,7 @@ BEGIN AND wl.workerFk = w.workerFk WHERE w.started BETWEEN vFristDay AND vLastDay AND wl.ended )sub ON sub.workerFk = w.workerFk - WHERE wc.center_id IS NOT NULL + WHERE wc.payrollCenterFk IS NOT NULL AND w.started BETWEEN vFristDay AND vLastDay AND sub.workerFk IS NULL AND NOT p.isFreelance; @@ -6942,16 +6612,16 @@ BEGIN INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) SELECT 'layoffs', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.workerLabour w - JOIN postgresql.workcenter wc ON wc.workcenter_id = w.workCenterFk + JOIN vn.workCenter wc ON wc.id = w.workCenterFk JOIN postgresql.business_labour_payroll bl ON bl.business_id = w.businessFk JOIN postgresql.person p ON p.id_trabajador = w.workerFk LEFT JOIN vn.workerBusinessType wbt ON wbt.id = bl.cod_contrato LEFT JOIN (SELECT started, workerFk FROM vn.workerLabour) wl ON wl.started >= w.ended AND wl.workerFk = w.workerFk - WHERE wc.center_id IS NOT NULL + WHERE wc.payrollCenterFk IS NOT NULL AND w.ended BETWEEN vFristDay AND vLastDay AND wl.started IS NULL - AND NOT p.isFreelance; + AND NOT p.isFreelance; -- Anterior al periodo SET vLastDay = LAST_DAY(DATE_SUB(vFristDay, INTERVAL 1 DAY)); @@ -6959,11 +6629,11 @@ BEGIN INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) SELECT 'staff', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.workerLabour w - JOIN postgresql.workcenter wc ON wc.workcenter_id = w.workCenterFk + JOIN vn.workCenter wc ON wc.id = w.workCenterFk JOIN postgresql.business_labour_payroll bl ON bl.business_id = w.businessFk JOIN postgresql.person p ON p.id_trabajador = w.workerFk LEFT JOIN vn.workerBusinessType wbt ON wbt.id = bl.cod_contrato - WHERE wc.center_id IS NOT NULL + WHERE wc.payrollCenterFk IS NOT NULL AND vLastDay BETWEEN started AND IFNULL(ended, vLastDay) AND NOT p.isFreelance; @@ -6971,138 +6641,15 @@ BEGIN INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) SELECT 'disabled', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(wbt.isPermanent) FROM vn.workerLabour w - JOIN postgresql.workcenter wc ON wc.workcenter_id = w.workCenterFk + JOIN vn.workCenter wc ON wc.id = w.workCenterFk JOIN postgresql.business_labour_payroll bl ON bl.business_id = w.businessFk JOIN postgresql.person p ON p.id_trabajador = w.workerFk LEFT JOIN vn.workerBusinessType wbt ON wbt.id = bl.cod_contrato - WHERE wc.center_id IS NOT NULL + WHERE wc.payrollCenterFk IS NOT NULL AND vLastDay BETWEEN started AND IFNULL(ended, vLastDay) AND p.isDisable - AND NOT p.isFreelance; - - END LOOP; - CLOSE vCursor; - - 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 `workerLabour_getData__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `workerLabour_getData__`() -BEGIN -/** - * Carga los datos de la plantilla de trabajadores, altas y bajas en la tabla workerLabourDataByMonth para facilitar el cálculo del gráfico en grafana. - * Se carga el día 21 de cada mes, elimina los registros del último año y los vuelve a calcular - * - */ - DECLARE vFristDay DATE; - DECLARE vLastDay DATE; - DECLARE vDone BOOL DEFAULT FALSE; - DECLARE vDateStarted DATE; - DECLARE vDateEnded DATE; - - DECLARE vCursor CURSOR FOR - SELECT util.firstDayOfMonth(t.dated), LAST_DAY(t.dated) - FROM vn.time t - WHERE t.dated BETWEEN vDateStarted AND vDateEnded - GROUP BY year,month; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - IF DAY(util.VN_CURDATE()) = 21 THEN - - SELECT util.firstDayOfMonth(DATE_SUB(util.VN_CURDATE(), INTERVAL 12 MONTH)), - LAST_DAY(DATE_SUB(util.VN_CURDATE(), INTERVAL 1 MONTH)) - INTO vDateStarted, - vDateEnded; - - DELETE FROM workerLabourDataByMonth - WHERE CONCAT(`year`, '-',`month`, '-01') BETWEEN vDateStarted AND vDateEnded; - - OPEN vCursor; - - l: LOOP - SET vDone = FALSE; - - FETCH vCursor INTO vFristDay, vLastDay; - - IF vDone THEN - LEAVE l; - END IF; - - -- Altas periodo - INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) - SELECT 'hiring', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(pc.isPermanent) - FROM vn.workerLabour w - JOIN postgresql.workcenter wc ON wc.workcenter_id = w.workCenterFk - JOIN postgresql.business_labour_payroll bl ON bl.business_id = w.businessFk - JOIN postgresql.person p ON p.id_trabajador = w.workerFk - LEFT JOIN vn2008.payroll_contratos pc ON pc.CodContrato = bl.cod_contrato - LEFT JOIN (SELECT w.workerFk - FROM vn.workerLabour w - LEFT JOIN (SELECT ended, workerFk FROM vn.workerLabour) wl ON wl.ended = DATE_SUB(w.started, INTERVAL 1 DAY) - AND wl.workerFk = w.workerFk - WHERE w.started BETWEEN vFristDay AND vLastDay AND wl.ended - )sub ON sub.workerFk = w.workerFk - WHERE wc.center_id IS NOT NULL - AND w.started BETWEEN vFristDay AND vLastDay - AND sub.workerFk IS NULL - AND NOT p.isFreelance; - - -- Bajas periodo - INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) - SELECT 'layoffs', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(pc.isPermanent) - FROM vn.workerLabour w - JOIN postgresql.workcenter wc ON wc.workcenter_id = w.workCenterFk - JOIN postgresql.business_labour_payroll bl ON bl.business_id = w.businessFk - JOIN postgresql.person p ON p.id_trabajador = w.workerFk - LEFT JOIN vn2008.payroll_contratos pc ON pc.CodContrato = bl.cod_contrato - LEFT JOIN (SELECT started, workerFk FROM vn.workerLabour) wl ON wl.started >= w.ended - AND wl.workerFk = w.workerFk - WHERE wc.center_id IS NOT NULL - AND w.ended BETWEEN vFristDay AND vLastDay - AND wl.started IS NULL - AND NOT p.isFreelance; - - -- Anterior al periodo - SET vLastDay = LAST_DAY(DATE_SUB(vFristDay, INTERVAL 1 DAY)); - - INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) - SELECT 'staff', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(pc.isPermanent) - FROM vn.workerLabour w - JOIN postgresql.workcenter wc ON wc.workcenter_id = w.workCenterFk - JOIN postgresql.business_labour_payroll bl ON bl.business_id = w.businessFk - JOIN postgresql.person p ON p.id_trabajador = w.workerFk - LEFT JOIN vn2008.payroll_contratos pc ON pc.CodContrato = bl.cod_contrato - WHERE wc.center_id IS NOT NULL - AND vLastDay BETWEEN started AND IFNULL(ended, vLastDay) AND NOT p.isFreelance; - -- Discapacidad - INSERT INTO workerLabourDataByMonth (code, month, year, total, permanent) - SELECT 'disabled', MONTH(vFristDay), YEAR(vFristDay), COUNT(*), SUM(pc.isPermanent) - FROM vn.workerLabour w - JOIN postgresql.workcenter wc ON wc.workcenter_id = w.workCenterFk - JOIN postgresql.business_labour_payroll bl ON bl.business_id = w.businessFk - JOIN postgresql.person p ON p.id_trabajador = w.workerFk - LEFT JOIN vn2008.payroll_contratos pc ON pc.CodContrato = bl.cod_contrato - WHERE wc.center_id IS NOT NULL - AND vLastDay BETWEEN started AND IFNULL(ended, vLastDay) - AND p.isDisable - AND NOT p.isFreelance; - END LOOP; CLOSE vCursor; @@ -7113,6 +6660,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerProductivity_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -7120,13 +6669,11 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerProductivity_add`() BEGIN DECLARE vDateFrom DATE; - SELECT DATE_SUB(util.VN_CURDATE(),INTERVAL 30 DAY) INTO vDateFrom; + SELECT DATE_SUB(vn.VN_CURDATE(),INTERVAL 30 DAY) INTO vDateFrom; DELETE FROM workerProductivity WHERE dated >= vDateFrom; @@ -7226,6 +6773,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_ETD_byTime` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -7233,29 +6782,25 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_ETD_byTime`() BEGIN - SET @m := 0; SELECT MAX(hourTheoretical) INTO @h FROM vn.zoneEstimatedDelivery ze - WHERE ze.remainingVolume ; + WHERE ze.remainingVolume ; DROP TEMPORARY TABLE IF EXISTS tmpZone; - CREATE TEMPORARY TABLE tmpZone SELECT remainingVolume, hourTheoretical, @m := @m + minutesLess + HOUR(TIMEDIFF(@h, hourTheoretical)) * 60 + MINUTE(TIMEDIFF(@h, hourTheoretical)) totalMinutes, - @h := hourTheoretical + @h := hourTheoretical previousHourTheoretical FROM vn.zoneEstimatedDelivery ze WHERE ze.remainingVolume ORDER BY ze.hourTheoretical DESC; - + TRUNCATE bs.zone_ETD_byTime ; INSERT INTO bs.zone_ETD_byTime(theorical, practical, m3) @@ -7266,7 +6811,6 @@ BEGIN GROUP BY tz.hourTheoretical; DROP TEMPORARY TABLE tmpZone; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -7290,9 +6834,9 @@ DROP TABLE IF EXISTS `addressFriendship`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `addressFriendship` ( - `addressFk1` int(11) NOT NULL DEFAULT 0, - `addressFk2` int(11) NOT NULL DEFAULT 0, - `friendship` int(11) NOT NULL DEFAULT 0, + `addressFk1` int(11) NOT NULL DEFAULT '0', + `addressFk2` int(11) NOT NULL DEFAULT '0', + `friendship` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`addressFk1`,`addressFk2`), KEY `addressFriendship_fk2_idx` (`addressFk2`), CONSTRAINT `addressFriendship_fk1` FOREIGN KEY (`addressFk1`) REFERENCES `vn`.`address` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, @@ -7362,7 +6906,7 @@ CREATE TABLE `cache_calc` ( `params` varchar(100) CHARACTER SET utf8 NOT NULL DEFAULT '', `last_refresh` datetime DEFAULT NULL, `expires` datetime DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `connection_id` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `cache_name` (`cache_id`,`params`), @@ -7383,7 +6927,7 @@ CREATE TABLE `cache_valid` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `valid` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=MEMORYDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7396,8 +6940,8 @@ DROP TABLE IF EXISTS `departure_limit`; CREATE TABLE `departure_limit` ( `warehouse_id` smallint(6) unsigned NOT NULL, `fecha` date NOT NULL, - `hora` int(11) NOT NULL DEFAULT 0, - `minSpeed` decimal(10,2) NOT NULL DEFAULT 0.00, + `hora` int(11) NOT NULL DEFAULT '0', + `minSpeed` decimal(10,2) NOT NULL DEFAULT '0.00', PRIMARY KEY (`warehouse_id`,`fecha`), CONSTRAINT `warehouse_departure` FOREIGN KEY (`warehouse_id`) REFERENCES `vn`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -7413,11 +6957,12 @@ DROP TABLE IF EXISTS `last_buy`; CREATE TABLE `last_buy` ( `item_id` int(10) unsigned NOT NULL, `warehouse_id` smallint(5) unsigned NOT NULL, - `buy_id` int(10) unsigned DEFAULT NULL, + `buy_id` int(11) DEFAULT NULL, `landing` date DEFAULT NULL, UNIQUE KEY `item_id` (`item_id`,`warehouse_id`) USING HASH, KEY `buy_id` (`buy_id`), - KEY `warehouse_id` (`warehouse_id`) USING BTREE + KEY `warehouse_id` (`warehouse_id`) USING BTREE, + CONSTRAINT `last_buy_FK_1` FOREIGN KEY (`warehouse_id`) REFERENCES `vn`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -7430,14 +6975,14 @@ DROP TABLE IF EXISTS `prod_graphic_source`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `prod_graphic_source` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `m3` double NOT NULL DEFAULT 0, + `m3` double NOT NULL DEFAULT '0', `warehouse_id` int(11) NOT NULL, `hora` int(11) NOT NULL, - `order` int(11) NOT NULL DEFAULT 0, - `graphCategory` int(11) NOT NULL DEFAULT 0, + `order` int(11) NOT NULL DEFAULT '0', + `graphCategory` int(11) NOT NULL DEFAULT '0', `Agencia` varchar(45) CHARACTER SET utf8 NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7482,7 +7027,7 @@ DROP TABLE IF EXISTS `zoneAgencyFriendship`; CREATE TABLE `zoneAgencyFriendship` ( `agencyModeFk` int(11) NOT NULL, `zoneFk` int(11) NOT NULL, - `friendship` bigint(21) NOT NULL DEFAULT 0, + `friendship` bigint(21) NOT NULL DEFAULT '0', PRIMARY KEY (`agencyModeFk`,`zoneFk`), KEY `zoneAgencyFriendship_fk1_idx` (`zoneFk`), CONSTRAINT `zoneAgencyFriendship` FOREIGN KEY (`agencyModeFk`) REFERENCES `vn`.`agencyMode` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, @@ -7536,6 +7081,8 @@ DELIMITER ; -- -- Dumping routines for database 'cache' -- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `addressFriendship_Update` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -7543,8 +7090,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `addressFriendship_Update`() BEGIN @@ -7556,8 +7101,8 @@ BEGIN SELECT t.routeFk, t.zoneFk, t.addressFk addressFk1, t2.addressFk addressFk2 FROM vn.ticket t JOIN vn.ticket t2 USING(routeFk, zoneFk) - WHERE t.shipped >= TIMESTAMPADD(MONTH,-3,util.VN_CURDATE()) - AND t2.shipped >= TIMESTAMPADD(MONTH,-3,util.VN_CURDATE()) + WHERE t.shipped >= TIMESTAMPADD(MONTH,-3,vn.VN_CURDATE()) + AND t2.shipped >= TIMESTAMPADD(MONTH,-3,vn.VN_CURDATE()) AND t.addressFk != t2.addressFk) sub GROUP BY addressFk1, addressFk2; @@ -7565,7 +7110,7 @@ BEGIN SELECT r.agencyModeFk, t.zoneFk, count(*) friendship FROM vn.route r JOIN vn.ticket t ON t.routeFk = r.id - WHERE t.shipped >= TIMESTAMPADD(MONTH,-3,util.VN_CURDATE()) + WHERE t.shipped >= TIMESTAMPADD(MONTH,-3,vn.VN_CURDATE()) AND r.agencyModeFk AND t.routeFk AND t.zoneFk @@ -7576,6 +7121,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `availableNoRaids_refresh` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -7583,157 +7130,157 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `availableNoRaids_refresh`(OUT `vCalc` INT, IN `vRefresh` INT, IN `vWarehouse` INT, IN `vDate` DATE) -proc: BEGIN - DECLARE vStartDate DATE; - DECLARE vEndDate DATETIME; - DECLARE vReserveDate DATETIME; - DECLARE vParams CHAR(100); - DECLARE vInventoryDate DATE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - CALL cache_calc_unlock (vCalc); - RESIGNAL; - END; - - IF vDate < util.VN_CURDATE() THEN - LEAVE proc; - END IF; - - CALL vn.itemStock (vWarehouse, vDate, NULL); - - SET vParams = CONCAT_WS('/', vWarehouse, vDate); - CALL cache_calc_start (vCalc, vRefresh, 'availableNoRaids', vParams); - - IF !vRefresh THEN - LEAVE proc; - END IF; - - -- Calcula algunos parámetros necesarios - - SET vStartDate = TIMESTAMP(vDate, '00:00:00'); - SET vEndDate = TIMESTAMP(TIMESTAMPADD(DAY, 4, vDate), '23:59:59'); - - SELECT inventoried INTO vInventoryDate FROM vn.config; - - SELECT SUBTIME(util.VN_NOW(), reserveTime) INTO vReserveDate - FROM hedera.orderConfig; - - -- Calcula el ultimo dia de vida para cada producto - - DROP TEMPORARY TABLE IF EXISTS item_range; - CREATE TEMPORARY TABLE item_range - (PRIMARY KEY (item_id)) - ENGINE = MEMORY - SELECT c.item_id, IF(it.life IS NULL, NULL, - TIMESTAMP(TIMESTAMPADD(DAY, it.life, c.landing), '23:59:59')) AS date_end - FROM ( - SELECT b.itemFk item_id, MAX(t.landed) landing - FROM vn.buy b - JOIN vn.entry e ON b.entryFk = e.id - JOIN vn.travel t ON t.id = e.travelFk - JOIN vn.warehouse w ON w.id = t.warehouseInFk - JOIN vn.supplier s ON s.id = e.supplierFk - WHERE t.landed BETWEEN vInventoryDate AND vStartDate - AND t.warehouseInFk = vWarehouse - AND s.name != 'INVENTARIO' - AND NOT e.isRaid - GROUP BY b.itemFk - ) c - JOIN vn.item i ON i.id = c.item_id - JOIN vn.itemType it ON it.id = i.typeFk - HAVING date_end >= vStartDate OR date_end IS NULL; - - -- Replica la tabla item_range para poder usarla varias veces en la misma consulta - - DROP TEMPORARY TABLE IF EXISTS item_range_copy1; - CREATE TEMPORARY TABLE item_range_copy1 LIKE item_range; - INSERT INTO item_range_copy1 - SELECT * FROM item_range; - - DROP TEMPORARY TABLE IF EXISTS item_range_copy2; - CREATE TEMPORARY TABLE item_range_copy2 LIKE item_range; - INSERT INTO item_range_copy2 - SELECT * FROM item_range; - - DROP TEMPORARY TABLE IF EXISTS item_range_copy3; - CREATE TEMPORARY TABLE item_range_copy3 LIKE item_range; - INSERT INTO item_range_copy3 - SELECT * FROM item_range; - - DROP TEMPORARY TABLE IF EXISTS item_range_copy4; - CREATE TEMPORARY TABLE item_range_copy4 LIKE item_range; - INSERT INTO item_range_copy4 - SELECT * FROM item_range; - - -- Calcula el ATP - - DELETE FROM availableNoRaids WHERE calc_id = vCalc; - - INSERT INTO availableNoRaids (calc_id, item_id, available) - SELECT vCalc, t.item_id, SUM(stock) amount FROM ( - SELECT il.itemFk AS item_id, stock - FROM tmp.itemList il - JOIN item_range ir ON ir.item_id = il.itemFk - UNION ALL - SELECT t.item_id, minacum(dt, amount, vDate) AS available FROM ( - SELECT itemFk AS item_id, DATE(dat) dt, SUM(quantity) amount FROM ( - SELECT i.itemFk, i.shipped AS dat, i.quantity - FROM vn.itemTicketOut i - JOIN item_range_copy1 ir ON ir.item_id = i.itemFk - WHERE i.shipped >= vStartDate - AND (ir.date_end IS NULL OR i.shipped <= ir.date_end) - AND i.warehouseFk = vWarehouse - UNION ALL - SELECT i.itemFk, i.landed AS dat, i.quantity - FROM vn.itemEntryIn i - JOIN item_range_copy2 ir ON ir.item_id = i.itemFk - WHERE i.landed >= vStartDate - AND (ir.date_end IS NULL OR i.landed <= ir.date_end) - AND i.warehouseInFk = vWarehouse - AND i.isVirtualStock = FALSE - UNION ALL - SELECT i.itemFk, i.shipped AS dat, i.quantity - FROM vn.itemEntryOut i - JOIN item_range_copy3 ir ON ir.item_id = i.itemFk - WHERE i.shipped >= vStartDate - AND (ir.date_end IS NULL OR i.shipped <= ir.date_end) - AND i.warehouseOutFk = vWarehouse - UNION ALL - SELECT r.item_id, r.shipment, -r.amount - FROM hedera.order_row r - JOIN hedera.`order` o ON o.id = r.order_id - JOIN item_range_copy4 ir ON ir.item_id = r.item_id - WHERE r.shipment >= vStartDate - AND (ir.date_end IS NULL OR r.shipment <= ir.date_end) - AND r.warehouse_id = vWarehouse - AND r.created >= vReserveDate - AND NOT o.confirmed - ) t - GROUP BY item_id, dt - ) t - GROUP BY t.item_id - ) t GROUP BY t.item_id; - - DROP TEMPORARY TABLE IF EXISTS - tmp.itemList - ,item_range - ,item_range_copy1 - ,item_range_copy2 - ,item_range_copy3 - ,item_range_copy4; - - CALL cache_calc_end (vCalc); +proc: BEGIN + DECLARE vStartDate DATE; + DECLARE vEndDate DATETIME; + DECLARE vReserveDate DATETIME; + DECLARE vParams CHAR(100); + DECLARE vInventoryDate DATE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + CALL cache_calc_unlock (vCalc); + RESIGNAL; + END; + + IF vDate < vn.VN_CURDATE() THEN + LEAVE proc; + END IF; + + CALL vn.itemStock (vWarehouse, vDate, NULL); + + SET vParams = CONCAT_WS('/', vWarehouse, vDate); + CALL cache_calc_start (vCalc, vRefresh, 'availableNoRaids', vParams); + + IF !vRefresh THEN + LEAVE proc; + END IF; + + -- Calcula algunos parametros necesarios + + SET vStartDate = TIMESTAMP(vDate, '00:00:00'); + SET vEndDate = TIMESTAMP(TIMESTAMPADD(DAY, 4, vDate), '23:59:59'); + + SELECT inventoried INTO vInventoryDate FROM vn.config; + + SELECT SUBTIME(vn.VN_NOW(), reserveTime) INTO vReserveDate + FROM hedera.orderConfig; + + -- Calcula el ultimo dia de vida para cada producto + + DROP TEMPORARY TABLE IF EXISTS item_range; + CREATE TEMPORARY TABLE item_range + (PRIMARY KEY (item_id)) + ENGINE = MEMORY + SELECT c.item_id, IF(it.life IS NULL, NULL, + TIMESTAMP(TIMESTAMPADD(DAY, it.life, c.landing), '23:59:59')) AS date_end + FROM ( + SELECT b.itemFk item_id, MAX(t.landed) landing + FROM vn.buy b + JOIN vn.entry e ON b.entryFk = e.id + JOIN vn.travel t ON t.id = e.travelFk + JOIN vn.warehouse w ON w.id = t.warehouseInFk + JOIN vn.supplier s ON s.id = e.supplierFk + WHERE t.landed BETWEEN vInventoryDate AND vStartDate + AND t.warehouseInFk = vWarehouse + AND s.name != 'INVENTARIO' + AND NOT e.isRaid + GROUP BY b.itemFk + ) c + JOIN vn.item i ON i.id = c.item_id + JOIN vn.itemType it ON it.id = i.typeFk + HAVING date_end >= vStartDate OR date_end IS NULL; + + -- Replica la tabla item_range para poder usarla varias veces en la misma consulta + + DROP TEMPORARY TABLE IF EXISTS item_range_copy1; + CREATE TEMPORARY TABLE item_range_copy1 LIKE item_range; + INSERT INTO item_range_copy1 + SELECT * FROM item_range; + + DROP TEMPORARY TABLE IF EXISTS item_range_copy2; + CREATE TEMPORARY TABLE item_range_copy2 LIKE item_range; + INSERT INTO item_range_copy2 + SELECT * FROM item_range; + + DROP TEMPORARY TABLE IF EXISTS item_range_copy3; + CREATE TEMPORARY TABLE item_range_copy3 LIKE item_range; + INSERT INTO item_range_copy3 + SELECT * FROM item_range; + + DROP TEMPORARY TABLE IF EXISTS item_range_copy4; + CREATE TEMPORARY TABLE item_range_copy4 LIKE item_range; + INSERT INTO item_range_copy4 + SELECT * FROM item_range; + + -- Calcula el ATP + + DELETE FROM availableNoRaids WHERE calc_id = vCalc; + + INSERT INTO availableNoRaids (calc_id, item_id, available) + SELECT vCalc, t.item_id, SUM(stock) amount FROM ( + SELECT il.itemFk AS item_id, stock + FROM tmp.itemList il + JOIN item_range ir ON ir.item_id = il.itemFk + UNION ALL + SELECT t.item_id, minacum(dt, amount, vDate) AS available FROM ( + SELECT itemFk AS item_id, DATE(dat) dt, SUM(quantity) amount FROM ( + SELECT i.itemFk, i.shipped AS dat, i.quantity + FROM vn.itemTicketOut i + JOIN item_range_copy1 ir ON ir.item_id = i.itemFk + WHERE i.shipped >= vStartDate + AND (ir.date_end IS NULL OR i.shipped <= ir.date_end) + AND i.warehouseFk = vWarehouse + UNION ALL + SELECT i.itemFk, i.landed AS dat, i.quantity + FROM vn.itemEntryIn i + JOIN item_range_copy2 ir ON ir.item_id = i.itemFk + WHERE i.landed >= vStartDate + AND (ir.date_end IS NULL OR i.landed <= ir.date_end) + AND i.warehouseInFk = vWarehouse + AND i.isVirtualStock = FALSE + UNION ALL + SELECT i.itemFk, i.shipped AS dat, i.quantity + FROM vn.itemEntryOut i + JOIN item_range_copy3 ir ON ir.item_id = i.itemFk + WHERE i.shipped >= vStartDate + AND (ir.date_end IS NULL OR i.shipped <= ir.date_end) + AND i.warehouseOutFk = vWarehouse + UNION ALL + SELECT r.item_id, r.shipment, -r.amount + FROM hedera.order_row r + JOIN hedera.`order` o ON o.id = r.order_id + JOIN item_range_copy4 ir ON ir.item_id = r.item_id + WHERE r.shipment >= vStartDate + AND (ir.date_end IS NULL OR r.shipment <= ir.date_end) + AND r.warehouse_id = vWarehouse + AND r.created >= vReserveDate + AND NOT o.confirmed + ) t + GROUP BY item_id, dt + ) t + GROUP BY t.item_id + ) t GROUP BY t.item_id; + + DROP TEMPORARY TABLE IF EXISTS + tmp.itemList + ,item_range + ,item_range_copy1 + ,item_range_copy2 + ,item_range_copy3 + ,item_range_copy4; + + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `available_clean` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -7741,8 +7288,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `available_clean`() BEGIN @@ -7769,6 +7314,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `available_refresh` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -7776,13 +7323,10 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `available_refresh`(OUT `vCalc` INT, IN `vRefresh` INT, IN `vWarehouse` INT, IN `vDate` DATE) proc: BEGIN DECLARE vStartDate DATE; - DECLARE vEndDate DATETIME; DECLARE vReserveDate DATETIME; DECLARE vParams CHAR(100); DECLARE vInventoryDate DATE; @@ -7794,7 +7338,7 @@ proc: BEGIN RESIGNAL; END; - IF vDate < util.VN_CURDATE() THEN + IF vDate < vn.VN_CURDATE() THEN LEAVE proc; END IF; @@ -7809,24 +7353,23 @@ proc: BEGIN -- Invoca al procedimiento que genera el stock virtual de Logiflora, si coincide con la peticion de refresco del disponible IF vn.isLogifloraDay(vDate, vWarehouse) THEN - + -- CALL edi.floramondo_offerRefresh; SET vIsLogifloraDay = TRUE; - + ELSE - + SET vIsLogifloraDay = FALSE; - - END IF; - + + END IF; + -- Calcula algunos parámetros necesarios SET vStartDate = TIMESTAMP(vDate, '00:00:00'); - SET vEndDate = TIMESTAMP(TIMESTAMPADD(DAY, 4, vDate), '23:59:59'); SELECT inventoried INTO vInventoryDate FROM vn.config; - SELECT SUBTIME(util.VN_NOW(), reserveTime) INTO vReserveDate + SELECT SUBTIME(vn.VN_NOW(), reserveTime) INTO vReserveDate FROM hedera.orderConfig; -- Calcula el ultimo dia de vida para cada producto @@ -7858,17 +7401,17 @@ proc: BEGIN CREATE TEMPORARY TABLE item_range_copy1 LIKE item_range; INSERT INTO item_range_copy1 SELECT * FROM item_range; - + DROP TEMPORARY TABLE IF EXISTS item_range_copy2; CREATE TEMPORARY TABLE item_range_copy2 LIKE item_range; INSERT INTO item_range_copy2 SELECT * FROM item_range; - + DROP TEMPORARY TABLE IF EXISTS item_range_copy3; CREATE TEMPORARY TABLE item_range_copy3 LIKE item_range; INSERT INTO item_range_copy3 SELECT * FROM item_range; - + DROP TEMPORARY TABLE IF EXISTS item_range_copy4; CREATE TEMPORARY TABLE item_range_copy4 LIKE item_range; INSERT INTO item_range_copy4 @@ -7884,8 +7427,10 @@ proc: BEGIN FROM tmp.itemList il JOIN item_range ir ON ir.item_id = il.itemFk UNION ALL - SELECT t.item_id, minacum(dt, amount, vDate) AS available FROM ( - SELECT itemFk AS item_id, DATE(dat) dt, SUM(quantity) amount FROM ( + SELECT t.item_id, minacum(dt, amount, vDate) AS available + FROM ( + SELECT itemFk AS item_id, DATE(dat) dt, SUM(quantity) amount + FROM ( SELECT i.itemFk, i.shipped AS dat, i.quantity FROM vn.itemTicketOut i JOIN item_range_copy1 ir ON ir.item_id = i.itemFk @@ -7932,7 +7477,6 @@ proc: BEGIN ,item_range_copy3 ,item_range_copy4; - CALL cache_calc_end (vCalc); END ;; DELIMITER ; @@ -7940,6 +7484,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `cacheCalc_clean` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -7947,12 +7493,10 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `cacheCalc_clean`() BEGIN - DECLARE vCleanTime DATETIME DEFAULT TIMESTAMPADD(MINUTE, -5, util.VN_NOW()); + DECLARE vCleanTime DATETIME DEFAULT TIMESTAMPADD(MINUTE, -5, vn.VN_NOW()); DELETE FROM cache_calc WHERE expires < vCleanTime; END ;; DELIMITER ; @@ -7960,6 +7504,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `cache_calc_end` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -7967,37 +7513,37 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `cache_calc_end`(IN `v_calc` INT) -BEGIN - DECLARE v_cache_name VARCHAR(255); - DECLARE v_params VARCHAR(255); - - -- Libera el bloqueo y actualiza la fecha de ultimo refresco. - - UPDATE cache_calc cc JOIN cache c ON c.id = cc.cache_id - SET - cc.last_refresh = util.VN_NOW(), - cc.expires = LEAST(ADDTIME(util.VN_NOW(), c.lifetime), util.midNight()), - cc.connection_id = NULL - WHERE cc.id = v_calc; - - SELECT c.name, ca.params INTO v_cache_name, v_params - FROM cache c - JOIN cache_calc ca ON c.id = ca.cache_id - WHERE ca.id = v_calc; - - IF v_cache_name IS NOT NULL THEN - DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, ''))); - END IF; +BEGIN + DECLARE v_cache_name VARCHAR(255); + DECLARE v_params VARCHAR(255); + + -- Libera el bloqueo y actualiza la fecha de ultimo refresco. + + UPDATE cache_calc cc JOIN cache c ON c.id = cc.cache_id + SET + cc.last_refresh = vn.VN_NOW(), + cc.expires = LEAST(ADDTIME(vn.VN_NOW(), c.lifetime), util.midNight()), + cc.connection_id = NULL + WHERE cc.id = v_calc; + + SELECT c.name, ca.params INTO v_cache_name, v_params + FROM cache c + JOIN cache_calc ca ON c.id = ca.cache_id + WHERE ca.id = v_calc; + + IF v_cache_name IS NOT NULL THEN + DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, ''))); + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `cache_calc_start` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -8005,98 +7551,98 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `cache_calc_start`(OUT `v_calc` INT, INOUT `v_refresh` INT, IN `v_cache_name` VARCHAR(50), IN `v_params` VARCHAR(100)) -proc: BEGIN - DECLARE v_valid BOOL; - DECLARE v_lock_id VARCHAR(100); - DECLARE v_cache_id INT; - DECLARE v_expires DATETIME; - DECLARE v_clean_time DATETIME; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - IF v_lock_id IS NOT NULL THEN - DO RELEASE_LOCK(v_lock_id); - END IF; - - RESIGNAL; - END; - - SET v_params = IFNULL(v_params, ''); - - -- Si el servidor se ha reiniciado invalida todos los calculos. - - SELECT COUNT(*) > 0 INTO v_valid FROM cache_valid; - - IF !v_valid - THEN - DELETE FROM cache_calc; - INSERT INTO cache_valid (valid) VALUES (TRUE); - END IF; - - -- Obtiene un bloqueo exclusivo para que no haya problemas de concurrencia. - - SET v_lock_id = CONCAT_WS('/', v_cache_name, v_params); - - IF !GET_LOCK(v_lock_id, 30) - THEN - SET v_calc = NULL; - SET v_refresh = FALSE; - LEAVE proc; - END IF; - - -- Comprueba si el calculo solicitado existe y esta actualizado. - - SELECT c.id, ca.id, ca.expires - INTO v_cache_id, v_calc, v_expires - FROM cache c - LEFT JOIN cache_calc ca - ON ca.cache_id = c.id AND ca.params = v_params COLLATE 'utf8_general_ci' - WHERE c.name = v_cache_name COLLATE 'utf8_general_ci'; - - -- Si existe una calculo valido libera el bloqueo y devuelve su identificador. - - IF !v_refresh AND util.VN_NOW() < v_expires - THEN - DO RELEASE_LOCK(v_lock_id); - SET v_refresh = FALSE; - LEAVE proc; - END IF; - - -- Si el calculo no existe le crea una entrada en la tabla de calculos. - - IF v_calc IS NULL - THEN - INSERT INTO cache_calc SET - cache_id = v_cache_id, - cacheName = v_cache_name, - params = v_params, - last_refresh = NULL, - expires = NULL, - connection_id = CONNECTION_ID(); - - SET v_calc = LAST_INSERT_ID(); - ELSE - UPDATE cache_calc - SET - last_refresh = NULL, - expires = NULL, - connection_id = CONNECTION_ID() - WHERE id = v_calc; - END IF; - - -- Si se debe recalcular mantiene el bloqueo y devuelve su identificador. - - SET v_refresh = TRUE; +proc: BEGIN + DECLARE v_valid BOOL; + DECLARE v_lock_id VARCHAR(100); + DECLARE v_cache_id INT; + DECLARE v_expires DATETIME; + DECLARE v_clean_time DATETIME; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + IF v_lock_id IS NOT NULL THEN + DO RELEASE_LOCK(v_lock_id); + END IF; + + RESIGNAL; + END; + + SET v_params = IFNULL(v_params, ''); + + -- Si el servidor se ha reiniciado invalida todos los calculos. + + SELECT COUNT(*) > 0 INTO v_valid FROM cache_valid; + + IF !v_valid + THEN + DELETE FROM cache_calc; + INSERT INTO cache_valid (valid) VALUES (TRUE); + END IF; + + -- Obtiene un bloqueo exclusivo para que no haya problemas de concurrencia. + + SET v_lock_id = CONCAT_WS('/', v_cache_name, v_params); + + IF !GET_LOCK(v_lock_id, 30) + THEN + SET v_calc = NULL; + SET v_refresh = FALSE; + LEAVE proc; + END IF; + + -- Comprueba si el calculo solicitado existe y esta actualizado. + + SELECT c.id, ca.id, ca.expires + INTO v_cache_id, v_calc, v_expires + FROM cache c + LEFT JOIN cache_calc ca + ON ca.cache_id = c.id AND ca.params = v_params COLLATE 'utf8_general_ci' + WHERE c.name = v_cache_name COLLATE 'utf8_general_ci'; + + -- Si existe una calculo valido libera el bloqueo y devuelve su identificador. + + IF !v_refresh AND vn.VN_NOW() < v_expires + THEN + DO RELEASE_LOCK(v_lock_id); + SET v_refresh = FALSE; + LEAVE proc; + END IF; + + -- Si el calculo no existe le crea una entrada en la tabla de calculos. + + IF v_calc IS NULL + THEN + INSERT INTO cache_calc SET + cache_id = v_cache_id, + cacheName = v_cache_name, + params = v_params, + last_refresh = NULL, + expires = NULL, + connection_id = CONNECTION_ID(); + + SET v_calc = LAST_INSERT_ID(); + ELSE + UPDATE cache_calc + SET + last_refresh = NULL, + expires = NULL, + connection_id = CONNECTION_ID() + WHERE id = v_calc; + END IF; + + -- Si se debe recalcular mantiene el bloqueo y devuelve su identificador. + + SET v_refresh = TRUE; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `cache_calc_unlock` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -8104,34 +7650,34 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `cache_calc_unlock`(IN `v_calc` INT) -proc: BEGIN - DECLARE v_cache_name VARCHAR(50); - DECLARE v_params VARCHAR(100); - - IF v_calc IS NULL THEN - LEAVE proc; - END IF; - - SELECT c.name, ca.params INTO v_cache_name, v_params - FROM cache c - JOIN cache_calc ca ON c.id = ca.cache_id - WHERE ca.id = v_calc; - - DELETE FROM cache_calc WHERE id = v_calc; - - IF v_cache_name IS NOT NULL THEN - DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, ''))); - END IF; +proc: BEGIN + DECLARE v_cache_name VARCHAR(50); + DECLARE v_params VARCHAR(100); + + IF v_calc IS NULL THEN + LEAVE proc; + END IF; + + SELECT c.name, ca.params INTO v_cache_name, v_params + FROM cache c + JOIN cache_calc ca ON c.id = ca.cache_id + WHERE ca.id = v_calc; + + DELETE FROM cache_calc WHERE id = v_calc; + + IF v_cache_name IS NOT NULL THEN + DO RELEASE_LOCK(CONCAT_WS('/', v_cache_name, IFNULL(v_params, ''))); + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `cache_clean` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -8139,8 +7685,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `cache_clean`() NO SQL @@ -8153,6 +7697,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clean` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -8160,23 +7706,23 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clean`() -BEGIN - - DECLARE vDateShort DATETIME; - - SET vDateShort = TIMESTAMPADD(MONTH, -1, util.VN_CURDATE()); - - DELETE FROM cache.departure_limit WHERE Fecha < vDateShort; +BEGIN + + DECLARE vDateShort DATETIME; + + SET vDateShort = TIMESTAMPADD(MONTH, -1, vn.VN_CURDATE()); + + DELETE FROM cache.departure_limit WHERE Fecha < vDateShort; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `departure_timing` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -8184,8 +7730,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `departure_timing`(vWarehouseId INT) BEGIN @@ -8205,11 +7749,11 @@ DECLARE vLoadingDelay DECIMAL(5) DEFAULT 2; DECLARE rs CURSOR FOR SELECT Departure , Sum(pb.m3)/(GREATEST(IFNULL(lhp.m3,0),IFNULL(dp.minSpeed,0))) AS Horas - , util.VN_CURDATE()+(Departure + vLoadingDelay -(Sum(pb.m3)/(GREATEST(IFNULL(lhp.m3,0),IFNULL(minSpeed,0))))/24) AS InicioPreparacion + , vn.VN_CURDATE()+(Departure + vLoadingDelay -(Sum(pb.m3)/(GREATEST(IFNULL(lhp.m3,0),IFNULL(minSpeed,0))))/24) AS InicioPreparacion FROM tmp.production_buffer pb LEFT JOIN vn.lastHourProduction lhp ON lhp.warehouseFk = pb.warehouse_id - LEFT JOIN cache.departure_limit dp ON dp.warehouse_id = pb.warehouse_id AND dp.fecha = util.VN_CURDATE() - WHERE pb.Fecha = util.VN_CURDATE() + LEFT JOIN cache.departure_limit dp ON dp.warehouse_id = pb.warehouse_id AND dp.fecha = vn.VN_CURDATE() + WHERE pb.Fecha = vn.VN_CURDATE() AND pb.graphCategory > 1 AND IFNULL(Departure,0) > 0 GROUP BY Departure @@ -8217,7 +7761,7 @@ DECLARE rs CURSOR FOR DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - SET myTime = HOUR(util.VN_NOW()) + MINUTE(util.VN_NOW()) / 60; + SET myTime = HOUR(vn.VN_NOW()) + MINUTE(vn.VN_NOW()) / 60; OPEN rs; @@ -8251,10 +7795,10 @@ DECLARE rs CURSOR FOR SELECT minSpeed INTO myMinSpeed FROM cache.departure_limit WHERE warehouse_id = vWarehouseId - AND fecha = util.VN_CURDATE(); + AND fecha = vn.VN_CURDATE(); REPLACE cache.departure_limit(warehouse_id, fecha, hora, minSpeed) - VALUES (vWarehouseId, util.VN_CURDATE(), departureLimit, IFNULL(myMinSpeed,0)); + VALUES (vWarehouseId, vn.VN_CURDATE(), departureLimit, IFNULL(myMinSpeed,0)); CLOSE rs; @@ -8264,95 +7808,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 `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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `departure_timing_beta__`(vWarehouseId INT) -BEGIN - -DECLARE done BOOL DEFAULT FALSE; -DECLARE rsDeparture INT; -DECLARE rsHoras DECIMAL(5,2); -DECLARE rsInicio DECIMAL(5,2); -DECLARE resto DECIMAL(5,2); -DECLARE horasProd DECIMAL(5,2); -DECLARE inicioProd DECIMAL(5,2) DEFAULT 24.00; -DECLARE myTime DECIMAL(5,2); -DECLARE departureLimit INT; - -DECLARE rs CURSOR FOR - SELECT Departure - , Sum(pb.m3)/GREATEST(v.m3,IFNULL(minSpeed,0)) AS Horas - , util.VN_CURDATE()+(Departure-(Sum(pb.m3)/GREATEST(v.m3,IFNULL(minSpeed,0)))/24) AS InicioPreparacion - FROM tmp.production_buffer pb - JOIN vn2008.v_encajado_ultima_hora v ON v.warehouse_id = pb.warehouse_id - LEFT JOIN cache.departure_limit dp ON dp.warehouse_id = pb.warehouse_id AND dp.fecha = util.VN_CURDATE() - WHERE pb.Fecha = util.VN_CURDATE() - AND alert_level < 2 - AND IFNULL(Departure,0) > 0 - GROUP BY Departure - ORDER BY Departure DESC; - -DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - -SET myTime = HOUR(util.VN_NOW()) + MINUTE(util.VN_NOW()) / 60; - -OPEN rs; - -FETCH rs INTO rsDeparture, rsHoras , rsInicio; - -SELECT rsDeparture, rsHoras , rsInicio, vWarehouseId, done; - -WHILE NOT done DO - - SET resto = IF(inicioProd < rsDeparture, rsDeparture - inicioProd,0); - - SET inicioProd = rsDeparture - rsHoras; - - SELECT rsDeparture, rsHoras , rsInicio, resto,inicioProd; - - IF inicioProd - resto < myTime THEN - - SET done = TRUE; - - ELSE - - SET departureLimit = rsDeparture; - - FETCH rs INTO rsDeparture, rsHoras , rsInicio; - - END IF; - -END WHILE; - -SELECT rsDeparture, rsHoras , rsInicio, resto,inicioProd; - - -SET departureLimit = IFNULL(departureLimit,24); - -IF departureLimit > 0 THEN - - REPLACE cache.departure_limit(warehouse_id, fecha, hora, minSpeed) - VALUES (vWarehouseId, util.VN_CURDATE(), departureLimit, myMinSpeed); - -END IF; - -CLOSE rs; - - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `last_buy_refresh` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -8360,8 +7817,6 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `last_buy_refresh`(vRefresh BOOL) proc: BEGIN @@ -8392,7 +7847,7 @@ proc: BEGIN -- TODO: ¿Se puede usar la fecha del ultimo inventario? SELECT inventoried INTO started FROM vn.config LIMIT 1; - SET ended = util.VN_CURDATE(); -- TIMESTAMPADD(DAY, -1, util.VN_CURDATE()); + SET ended = vn.VN_CURDATE(); -- TIMESTAMPADD(DAY, -1, vn.VN_CURDATE()); CALL vn.buyUltimateFromInterval(NULL, started, ended); @@ -8411,6 +7866,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `prod_graphic_refresh` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -8418,8 +7875,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `prod_graphic_refresh`(v_refresh BOOL, wh_id INT) proc: BEGIN @@ -8448,7 +7903,7 @@ proc: BEGIN pb.Agencia FROM tmp.production_buffer pb JOIN vn.state st ON st.id = pb.state - WHERE Fecha = util.VN_CURDATE() + WHERE Fecha = vn.VN_CURDATE() GROUP BY wh_id, graphCategory ; @@ -8460,6 +7915,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `stock_refresh` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -8467,8 +7924,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `stock_refresh`(v_refresh BOOL) proc: BEGIN @@ -8498,7 +7953,7 @@ proc: BEGIN END IF; SET v_date_inv = (SELECT inventoried FROM vn.config LIMIT 1); - SET v_curdate = util.VN_CURDATE(); + SET v_curdate = vn.VN_CURDATE(); DELETE FROM stock; @@ -8526,70 +7981,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 `stock_refresh__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `stock_refresh__`(v_refresh BOOL) -proc: BEGIN -/** - * bernat: WORKING IN THIS FILE - * Crea o actualiza la cache con el disponible hasta el día de - * ayer. Esta cache es usada como base para otros procedimientos - * como el cáculo del visible o del ATP. - * - * @param v_refresh %TRUE para forzar el recálculo de la cache - **/ - DECLARE v_calc INT; - DECLARE v_date_inv DATE; - DECLARE v_curdate DATE; - DECLARE v_last_refresh DATETIME; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - CALL cache_calc_unlock (v_calc); - RESIGNAL; - END; - - CALL cache_calc_start (v_calc, v_refresh, 'stock', NULL); - - IF !v_refresh - THEN - LEAVE proc; - END IF; - - SET v_date_inv = (SELECT FechaInventario FROM vn2008.tblContadores LIMIT 1); - SET v_curdate = util.VN_CURDATE(); - - DELETE FROM stock; - - INSERT INTO stock (item_id, warehouse_id, amount) - SELECT item_id, warehouse_id, SUM(amount) amount FROM - ( - SELECT item_id, warehouse_id, amount FROM vn2008.item_out - WHERE dat >= v_date_inv AND dat < v_curdate - UNION ALL - SELECT item_id, warehouse_id, amount FROM vn2008.item_entry_in - WHERE dat >= v_date_inv AND dat < v_curdate AND isVirtualStock is FALSE - UNION ALL - SELECT item_id ,warehouse_id, amount FROM vn2008.item_entry_out - WHERE dat >= v_date_inv AND dat < v_curdate - ) t - GROUP BY item_id, warehouse_id HAVING amount != 0; - - CALL cache_calc_end (v_calc); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `visible_clean` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -8597,8 +7990,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `visible_clean`() BEGIN @@ -8620,6 +8011,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `visible_refresh` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -8627,8 +8020,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `visible_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT) proc: BEGIN @@ -8656,63 +8047,7 @@ proc: BEGIN WHERE warehouse_id = v_warehouse; -- Calculamos los movimientos confirmados de hoy - - CALL vn.item_GetVisible(v_warehouse, NULL); - - DELETE FROM visible WHERE calc_id = v_calc; - - INSERT INTO visible (calc_id, item_id,visible) - SELECT v_calc, item_id, visible FROM vn2008.tmp_item; - - CALL cache_calc_end (v_calc); - - DROP TEMPORARY TABLE vn2008.tmp_item; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `visible_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `visible_refresh__`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT) -proc: BEGIN - -- bernat working in this file - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - CALL cache_calc_unlock (v_calc); - RESIGNAL; - END; - - CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse); - - IF !v_refresh THEN - LEAVE proc; - END IF; - - -- Calculamos el stock hasta ayer - - CALL `cache`.stock_refresh(false); - - DROP TEMPORARY TABLE IF EXISTS vn2008.tmp_item; - CREATE TEMPORARY TABLE vn2008.tmp_item - (PRIMARY KEY (item_id)) - ENGINE = MEMORY - SELECT item_id, amount stock, amount visible FROM `cache`.stock - WHERE warehouse_id = v_warehouse; - - -- Calculamos los movimientos confirmados de hoy - - CALL vn2008.item_stock_visible(v_warehouse, NULL); - + CALL vn.item_GetVisible(v_warehouse, NULL); DELETE FROM visible WHERE calc_id = v_calc; INSERT INTO visible (calc_id, item_id,visible) @@ -8773,7 +8108,7 @@ DROP TABLE IF EXISTS `VMPSettings`; CREATE TABLE `VMPSettings` ( `VMPID` int(11) NOT NULL, `name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `isEktSender` tinyint(4) NOT NULL DEFAULT 0, + `isEktSender` tinyint(4) NOT NULL DEFAULT '0', `MessageID` int(11) NOT NULL, `dateTimeTry` timestamp NULL DEFAULT NULL, `isVmpBA` tinyint(4) DEFAULT NULL COMMENT 'Basic authentication', @@ -8789,12 +8124,12 @@ CREATE TABLE `VMPSettings` ( `closedFrom` int(11) DEFAULT NULL, `closedTo` int(11) DEFAULT NULL, `totalRefreshHours` int(11) DEFAULT NULL COMMENT 'Numero > 4 para no saturar, no repetir para que no solapen las actualizaciones', - `UseSupplierEmbalageCode` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'vmp you want to see their embalage code', + `UseSupplierEmbalageCode` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'vmp you want to see their embalage code', `firstSupplyResponseId` int(11) DEFAULT NULL, `ApiId` int(11) DEFAULT NULL, `ApiKey` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, - `isBlocked` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'product source not allowed', - `isVNHSupplier` tinyint(1) DEFAULT 0 COMMENT 'The account belongs to VNH', + `isBlocked` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'product source not allowed', + `isVNHSupplier` tinyint(1) DEFAULT '0' COMMENT 'The account belongs to VNH', PRIMARY KEY (`VMPID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -8876,7 +8211,7 @@ CREATE TABLE `deliveryInformation` ( `FirstOrderDateTime` datetime DEFAULT NULL, `LatestOrderDateTime` datetime DEFAULT NULL, `supplyResponseID` int(11) DEFAULT NULL, - `updated` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`ID`), UNIQUE KEY `deliveryInformation_UN` (`Location`,`LatestDeliveryDateTime`,`FirstOrderDateTime`,`LatestOrderDateTime`,`supplyResponseID`), KEY `fgbSupplyResponse_idx` (`supplyResponseID`), @@ -8884,7 +8219,7 @@ CREATE TABLE `deliveryInformation` ( KEY `fgbSupplyResponse_idx3` (`LatestOrderDateTime`) USING BTREE, KEY `deliveryInformation_updated_IDX` (`updated`) USING BTREE, CONSTRAINT `fgbSupplyResponse` FOREIGN KEY (`supplyResponseID`) REFERENCES `supplyResponse` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8895,7 +8230,7 @@ DROP TABLE IF EXISTS `di`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `di` ( - `ID` int(11) NOT NULL DEFAULT 0, + `ID` int(11) NOT NULL DEFAULT '0', `Location` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `LatestDeliveryDateTime` datetime DEFAULT NULL, `FirstOrderDateTime` datetime DEFAULT NULL, @@ -8914,31 +8249,32 @@ DROP TABLE IF EXISTS `ekt`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `ekt` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `barcode` char(15) COLLATE utf8_unicode_ci DEFAULT NULL, - `entryYear` smallint(5) unsigned NOT NULL, - `deliveryNumber` bigint(20) unsigned DEFAULT NULL, - `fec` date DEFAULT NULL, - `hor` time DEFAULT NULL, - `util.VN_NOW` timestamp NULL DEFAULT current_timestamp(), - `ptj` mediumint(8) unsigned DEFAULT NULL, - `ref` int(11) NOT NULL, - `item` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `pac` int(11) DEFAULT 0, - `qty` int(10) NOT NULL, - `ori` varchar(3) COLLATE utf8_unicode_ci DEFAULT 'NL', - `cat` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL, - `agj` int(11) DEFAULT NULL, - `kop` int(11) DEFAULT NULL, - `ptd` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, - `sub` mediumint(8) unsigned DEFAULT NULL, - `pro` mediumint(8) unsigned NOT NULL, - `pri` double NOT NULL, - `package` int(10) unsigned DEFAULT NULL, - `auction` smallint(5) unsigned DEFAULT NULL, - `klo` smallint(5) unsigned DEFAULT NULL, - `k1` smallint(5) unsigned DEFAULT NULL, - `k2` smallint(5) unsigned DEFAULT NULL, + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Id', + `barcode` char(15) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Generated auction barcode', + `entryYear` smallint(5) unsigned NOT NULL COMMENT 'Transaction year', + `batchNumber` bigint(20) unsigned DEFAULT NULL COMMENT 'RFF+BT', + `deliveryNumber` bigint(20) unsigned DEFAULT NULL COMMENT 'RFF+AAJ', + `fec` date DEFAULT NULL COMMENT 'DTM+97', + `hor` time DEFAULT NULL COMMENT 'UNB', + `vn.VN_NOW` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Creation time', + `ptj` mediumint(8) unsigned DEFAULT NULL COMMENT 'NAD+BY', + `ref` int(11) NOT NULL COMMENT 'LIN', + `item` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'IMD+S99', + `pac` int(11) DEFAULT '0' COMMENT 'QTY+52', + `qty` int(10) NOT NULL COMMENT 'QTY+66', + `ori` varchar(3) COLLATE utf8_unicode_ci DEFAULT 'NL' COMMENT 'IMD+S62', + `cat` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'IMD+S98', + `agj` int(11) DEFAULT NULL COMMENT 'RFF+AGJ', + `kop` int(11) DEFAULT NULL COMMENT 'RFF+ADZ', + `ptd` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'RFF+ACE', + `sub` mediumint(8) unsigned DEFAULT NULL COMMENT 'RFF+CTS', + `pro` mediumint(8) unsigned NOT NULL COMMENT 'NAD+MF', + `pri` double NOT NULL COMMENT 'PRI+INV', + `package` int(10) unsigned DEFAULT NULL COMMENT 'PAC', + `auction` smallint(5) unsigned DEFAULT NULL COMMENT 'NAD+FLA', + `klo` smallint(5) unsigned DEFAULT NULL COMMENT 'RFF+FAC', + `k1` smallint(5) unsigned DEFAULT NULL COMMENT 'IMD+K01', + `k2` smallint(5) unsigned DEFAULT NULL COMMENT 'IMD+K02', `k3` tinyint(3) unsigned DEFAULT NULL, `k4` tinyint(3) unsigned DEFAULT NULL, `s1` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, @@ -8947,10 +8283,10 @@ CREATE TABLE `ekt` ( `s4` varchar(4) COLLATE utf8_unicode_ci DEFAULT NULL, `s5` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `s6` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, - `ok` tinyint(4) NOT NULL DEFAULT 0, + `ok` tinyint(4) NOT NULL DEFAULT '0', `trolleyFk` int(11) DEFAULT NULL, - `putOrderFk` bigint(20) unsigned DEFAULT NULL, - `scanned` tinyint(1) NOT NULL DEFAULT 0, + `putOrderFk` bigint(20) unsigned DEFAULT NULL COMMENT 'RFF+ON', + `scanned` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Whether it''s been scanned', PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `barcode_year` (`barcode`,`entryYear`), UNIQUE KEY `entry_year` (`deliveryNumber`,`entryYear`) USING BTREE, @@ -8961,7 +8297,7 @@ CREATE TABLE `ekt` ( KEY `barcode` (`barcode`), KEY `fec` (`fec`), KEY `putOrderFk` (`putOrderFk`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8981,7 +8317,7 @@ CREATE TABLE `ektEntryAssign__` ( `supplierFk` int(11) DEFAULT NULL, `entryFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='define las condiciones para asignar entradas a los ekt'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='define las condiciones para asignar entradas a los ekt'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9024,7 +8360,7 @@ CREATE TABLE `exchange` ( KEY `buy_edi_id` (`ektFk`), CONSTRAINT `exchange_ibfk_1` FOREIGN KEY (`mailFk`) REFERENCES `mail` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `exchange_ibfk_2` FOREIGN KEY (`ektFk`) REFERENCES `ekt` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9043,7 +8379,7 @@ CREATE TABLE `exchangeConfig` ( PRIMARY KEY (`id`), KEY `presale_id` (`presaleFk`), CONSTRAINT `exchangeConfig_ibfk_1` FOREIGN KEY (`presaleFk`) REFERENCES `exchangeType` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Configuration parameters'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Configuration parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9104,8 +8440,8 @@ DROP TABLE IF EXISTS `floraHollandConfig`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `floraHollandConfig` ( - `defaultAdminNumber` int(11) NOT NULL DEFAULT 66011, - `floramondoMargin` decimal(10,2) NOT NULL DEFAULT 0.17 + `defaultAdminNumber` int(11) NOT NULL DEFAULT '66011', + `floramondoMargin` decimal(10,2) NOT NULL DEFAULT '0.17' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -9122,7 +8458,7 @@ CREATE TABLE `ftpConfig` ( `user` varchar(50) CHARACTER SET utf8 NOT NULL, `password` varchar(50) CHARACTER SET utf8 NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Configuration parameters'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Configuration parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9138,7 +8474,7 @@ CREATE TABLE `genus` ( `entry_date` date DEFAULT NULL, `expiry_date` date DEFAULT NULL, `change_date_time` datetime DEFAULT NULL, - `isHazard` tinyint(1) NOT NULL DEFAULT 0, + `isHazard` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`genus_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='/tmp/floricode/florecompc2/FG130916.txt'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -9297,7 +8633,7 @@ CREATE TABLE `item_groupToOffer` ( `group_code` int(11) unsigned NOT NULL, `itemTypeFk` smallint(5) unsigned NOT NULL, `intrastatFk` int(8) unsigned zerofill NOT NULL, - `originFk` tinyint(2) unsigned NOT NULL DEFAULT 17, + `originFk` tinyint(2) unsigned NOT NULL DEFAULT '17', `expenseFk` varchar(10) COLLATE utf8_unicode_ci DEFAULT '7001000000', PRIMARY KEY (`group_code`), KEY `item_groupToOffer_fk2_idx` (`itemTypeFk`), @@ -9318,20 +8654,20 @@ DROP TABLE IF EXISTS `item_track`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `item_track` ( `item_id` int(10) unsigned NOT NULL, - `s1` tinyint(3) NOT NULL DEFAULT 0, - `s2` tinyint(3) NOT NULL DEFAULT 0, - `s3` tinyint(3) NOT NULL DEFAULT 0, - `s4` tinyint(3) NOT NULL DEFAULT 0, - `pac` tinyint(3) NOT NULL DEFAULT 0, - `cat` tinyint(3) NOT NULL DEFAULT 0, - `ori` tinyint(3) NOT NULL DEFAULT 0, - `pro` tinyint(3) NOT NULL DEFAULT 0, - `package` tinyint(3) NOT NULL DEFAULT 0, - `s5` tinyint(3) NOT NULL DEFAULT 0, - `s6` tinyint(3) NOT NULL DEFAULT 0, - `kop` tinyint(3) NOT NULL DEFAULT 0, - `sub` tinyint(3) NOT NULL DEFAULT 0, - `item` tinyint(3) NOT NULL DEFAULT 0, + `s1` tinyint(3) NOT NULL DEFAULT '0', + `s2` tinyint(3) NOT NULL DEFAULT '0', + `s3` tinyint(3) NOT NULL DEFAULT '0', + `s4` tinyint(3) NOT NULL DEFAULT '0', + `pac` tinyint(3) NOT NULL DEFAULT '0', + `cat` tinyint(3) NOT NULL DEFAULT '0', + `ori` tinyint(3) NOT NULL DEFAULT '0', + `pro` tinyint(3) NOT NULL DEFAULT '0', + `package` tinyint(3) NOT NULL DEFAULT '0', + `s5` tinyint(3) NOT NULL DEFAULT '0', + `s6` tinyint(3) NOT NULL DEFAULT '0', + `kop` tinyint(3) NOT NULL DEFAULT '0', + `sub` tinyint(3) NOT NULL DEFAULT '0', + `item` tinyint(3) NOT NULL DEFAULT '0', PRIMARY KEY (`item_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -9348,9 +8684,9 @@ CREATE TABLE `log` ( `tableName` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `fieldName` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `fieldValue` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9367,12 +8703,12 @@ CREATE TABLE `mail` ( `messageId` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `nExchanges` int(10) unsigned NOT NULL, `error` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `mail_id` (`messageId`), KEY `sender_id` (`senderFk`), CONSTRAINT `mail_ibfk_2` FOREIGN KEY (`senderFk`) REFERENCES `mailSender` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9388,7 +8724,7 @@ CREATE TABLE `mailSender` ( `kop` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `mail` (`mail`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='List of allowed mailers'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='List of allowed mailers'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9401,11 +8737,11 @@ DROP TABLE IF EXISTS `marketPlace`; CREATE TABLE `marketPlace` ( `id` varchar(13) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, - `supplierFk` int(11) NOT NULL DEFAULT 1433, - `isOffered` tinyint(2) NOT NULL DEFAULT 0, + `supplierFk` int(11) NOT NULL DEFAULT '1433', + `isOffered` tinyint(2) NOT NULL DEFAULT '0', `MaxLatestDeliveryHour` int(11) DEFAULT NULL COMMENT 'Maxima hora para tener en cuenta la oferta', - `isLatestOrderDateTimeRelevant` tinyint(2) DEFAULT 0 COMMENT 'Se tiene en cuenta para calcular el próximo travel posible', - `isEarlyBird` tinyint(4) NOT NULL DEFAULT 0, + `isLatestOrderDateTimeRelevant` tinyint(2) DEFAULT '0' COMMENT 'Se tiene en cuenta para calcular el próximo travel posible', + `isEarlyBird` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `marketPlaceisOfferedIdx` (`isOffered`), KEY `marketPlaceMaxLatestIdx` (`MaxLatestDeliveryHour`), @@ -9442,12 +8778,13 @@ CREATE TABLE `param` ( `code` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(5) COLLATE utf8_unicode_ci NOT NULL, `subname` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, - `position` tinyint(3) unsigned NOT NULL DEFAULT 1, + `position` tinyint(3) unsigned NOT NULL DEFAULT '1', `type` enum('INTEGER','DOUBLE','STRING','DATE','TIME') COLLATE utf8_unicode_ci NOT NULL, - `required` tinyint(3) unsigned NOT NULL DEFAULT 1, + `required` tinyint(3) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`), + UNIQUE KEY `code` (`code`), UNIQUE KEY `name` (`name`,`subname`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Parameters to capture of every exchange'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Parameters to capture of every exchange'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9480,16 +8817,16 @@ CREATE TABLE `putOrder` ( `deliveryInformationID` int(11) DEFAULT NULL, `supplyResponseID` int(11) DEFAULT NULL, `orderTradelineItemID` int(11) DEFAULT NULL COMMENT 'ticketFk or EntryFk?', - `OrderTradeLineDateTime` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'fecha de creacion en la tabla', + `OrderTradeLineDateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'fecha de creacion en la tabla', `quantity` int(11) DEFAULT NULL, `EndUserPartyID` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `EndUserPartyGLN` varchar(13) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The grower can use this reference in his EKT in the NAD (MA) segment.', - `OrderStatus` int(11) DEFAULT 0 COMMENT '1 pending\n2 confirmed\n3 canceled', + `OrderStatus` int(11) DEFAULT '0' COMMENT '1 pending\n2 confirmed\n3 canceled', `isOrderProcessed` tinyint(4) DEFAULT NULL, `error` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `barcode` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), - `FHAdminNumber` int(11) DEFAULT 66011, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `FHAdminNumber` int(11) DEFAULT '66011', `saleFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `orderTradelineItemID_UNIQUE` (`orderTradelineItemID`), @@ -9497,7 +8834,7 @@ CREATE TABLE `putOrder` ( KEY `supplyResponseID_idx` (`supplyResponseID`), KEY `putOrder_FK` (`saleFk`), CONSTRAINT `putOrder_FK` FOREIGN KEY (`saleFk`) REFERENCES `vn`.`sale` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -9600,7 +8937,7 @@ BEGIN JOIN vn.ticket t ON s.ticketFk = t.id JOIN vn.item i ON i.id = s.itemFk JOIN deliveryInformation di ON di.ID = NEW.deliveryInformationID - WHERE t.clientFk = NEW.EndUserPartyGLN AND t.shipped >= util.VN_CURDATE() + WHERE t.clientFk = NEW.EndUserPartyGLN AND t.shipped >= vn.VN_CURDATE() AND i.supplyResponseFk = NEW.supplyResponseID LIMIT 1; @@ -9609,7 +8946,7 @@ BEGIN JOIN vn.item i ON i.id = s.itemFk JOIN deliveryInformation di ON di.ID = NEW.deliveryInformationID SET s.quantity = 0 - WHERE t.clientFk = NEW.EndUserPartyGLN AND t.shipped >= util.VN_CURDATE() + WHERE t.clientFk = NEW.EndUserPartyGLN AND t.shipped >= vn.VN_CURDATE() AND i.supplyResponseFk = NEW.supplyResponseID; INSERT INTO vn.mail (sender, `subject`, body) @@ -9695,8 +9032,8 @@ CREATE TABLE `supplier` ( `entry_date` date NOT NULL, `expiry_date` date NOT NULL, `change_date_time` datetime NOT NULL, - `isAllowedDirectSales` tinyint(1) NOT NULL DEFAULT 0, - `isBanned` tinyint(1) NOT NULL DEFAULT 0, + `isAllowedDirectSales` tinyint(1) NOT NULL DEFAULT '0', + `isBanned` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`supplier_id`), UNIQUE KEY `supplier_UN` (`glnAddressCode`), KEY `glnaddressCodeidx` (`glnAddressCode`) @@ -9819,9 +9156,9 @@ CREATE TABLE `supplyResponse` ( `widthMeasure` int(11) DEFAULT NULL COMMENT 'mm Embalage Width', `lengthMeasure` int(11) DEFAULT NULL COMMENT 'mm Embalage Length', `heightMeasure` int(11) DEFAULT NULL COMMENT 'mm Embalage Height', - `created` datetime NOT NULL DEFAULT current_timestamp(), + `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `EmbalageCodeSupplier` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, - `updated` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`ID`), KEY `IX_TransNumber` (`TransactionNumber`) COMMENT 'Agregado por Ernesto 11.6.2019\nSe ejecutaba 1 consulta por segundo desde MAIL y consumia un 20% de CPU de todo el servidor !!!!!\nCPU usada es mas estable que Indice en SendererID, cpu vs espacio que ocupa?\n', KEY `supplyResponse_Ix1` (`Item_ArticleCode`), @@ -9832,7 +9169,7 @@ CREATE TABLE `supplyResponse` ( KEY `supplyResponse_updated_IDX` (`updated`) USING BTREE, CONSTRAINT `supplyResponse_fk2` FOREIGN KEY (`MarketPlaceID`) REFERENCES `marketPlace` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `supplyResponseputOrder_FK` FOREIGN KEY (`vmpID`) REFERENCES `VMPSettings` (`VMPID`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -9859,7 +9196,7 @@ BEGIN WHERE i.supplyResponseFk = NEW.ID AND am.name = 'LOGIFLORA' AND e.isRaid - AND tr.landed >= util.VN_CURDATE(); + AND tr.landed >= vn.VN_CURDATE(); END */;; DELIMITER ; @@ -9878,14 +9215,14 @@ DROP TABLE IF EXISTS `supplyResponseLog`; CREATE TABLE `supplyResponseLog` ( `id` int(11) NOT NULL AUTO_INCREMENT, `supplyResponseFk` int(11) NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `NumberOfUnitsOld` int(11) DEFAULT NULL, `NumberOfUnitsNew` int(11) DEFAULT NULL, `lastVMPUpdate` datetime DEFAULT NULL, PRIMARY KEY (`id`), KEY `supplyResponseLog_FK` (`supplyResponseFk`), CONSTRAINT `supplyResponseLog_FK` FOREIGN KEY (`supplyResponseFk`) REFERENCES `supplyResponse` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Esta tabla la utiliza la empresa LOGIFLORA. No kkear.'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Esta tabla la utiliza la empresa LOGIFLORA. No kkear.'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9933,10 +9270,10 @@ DROP TABLE IF EXISTS `warehouseFloramondo`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `warehouseFloramondo` ( `warehouseFk` smallint(6) unsigned NOT NULL, - `travellingDays` int(11) NOT NULL DEFAULT 1, + `travellingDays` int(11) NOT NULL DEFAULT '1', `entryFk` int(11) DEFAULT NULL, `isFV` int(11) DEFAULT NULL COMMENT 'NULL indiferente\n0 no\n1 si\n', - `dayRange` int(11) NOT NULL DEFAULT 0 COMMENT 'dias de margen a futuro', + `dayRange` int(11) NOT NULL DEFAULT '0' COMMENT 'dias de margen a futuro', PRIMARY KEY (`warehouseFk`), KEY `warehouseFloramondo_FK2_idx` (`entryFk`), CONSTRAINT `warehouseFloramondo_FK2` FOREIGN KEY (`entryFk`) REFERENCES `vn`.`entry` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, @@ -9972,6 +9309,8 @@ DELIMITER ; -- -- Dumping routines for database 'edi' -- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `imageName` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -9979,33 +9318,33 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `imageName`(vPictureReference VARCHAR(255)) RETURNS varchar(255) CHARSET utf8 COLLATE utf8_unicode_ci DETERMINISTIC -BEGIN - - SET vPictureReference = REPLACE(vPictureReference,'.',''); - - SET vPictureReference = REPLACE(vPictureReference,'/',''); - - SET vPictureReference = REPLACE(vPictureReference,'%',''); - - SET vPictureReference = REPLACE(vPictureReference,':',''); - - SET vPictureReference = REPLACE(vPictureReference,'?',''); - - SET vPictureReference = REPLACE(vPictureReference,'=',''); - - RETURN vPictureReference; - +BEGIN + + SET vPictureReference = REPLACE(vPictureReference,'.',''); + + SET vPictureReference = REPLACE(vPictureReference,'/',''); + + SET vPictureReference = REPLACE(vPictureReference,'%',''); + + SET vPictureReference = REPLACE(vPictureReference,':',''); + + SET vPictureReference = REPLACE(vPictureReference,'?',''); + + SET vPictureReference = REPLACE(vPictureReference,'=',''); + + RETURN vPictureReference; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clean` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -10013,14 +9352,12 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clean`() BEGIN - DECLARE vFourYearsAgo DATE DEFAULT TIMESTAMPADD(YEAR,-4,util.VN_CURDATE()); - DECLARE vOneWeekAgo DATE DEFAULT TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); + DECLARE vFourYearsAgo DATE DEFAULT TIMESTAMPADD(YEAR,-4,vn.VN_CURDATE()); + DECLARE vOneWeekAgo DATE DEFAULT TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()); DELETE FROM ekt WHERE fec < vFourYearsAgo; @@ -10030,7 +9367,7 @@ BEGIN WHERE di.LatestOrderDateTime < vOneWeekAgo OR di.ID IS NULL; DELETE FROM putOrder - WHERE created < TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()); + WHERE created < TIMESTAMPADD(MONTH,-1,vn.VN_CURDATE()); END ;; DELIMITER ; @@ -10038,6 +9375,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `deliveryInformation_Delete` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -10045,38 +9384,38 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `deliveryInformation_Delete`() -BEGIN - - DECLARE vID INT; - DECLARE vGap INT DEFAULT 100; - DECLARE vTope INT; - - SELECT MIN(ID), MAX(ID) - INTO vID, vTope - FROM edi.deliveryInformation; - - WHILE vID <= vTope DO - - SET vID = vID + vGap; - - DELETE - FROM edi.deliveryInformation - WHERE ID < vID - AND EarliestDespatchDateTime IS NULL; - - END WHILE; - - +BEGIN + + DECLARE vID INT; + DECLARE vGap INT DEFAULT 100; + DECLARE vTope INT; + + SELECT MIN(ID), MAX(ID) + INTO vID, vTope + FROM edi.deliveryInformation; + + WHILE vID <= vTope DO + + SET vID = vID + vGap; + + DELETE + FROM edi.deliveryInformation + WHERE ID < vID + AND EarliestDespatchDateTime IS NULL; + + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ekt_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -10084,8 +9423,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ekt_add`(vPutOrderFk INT) BEGIN @@ -10117,7 +9454,7 @@ BEGIN putOrderFk, `ref`, kop) - SELECT year(util.VN_CURDATE()) entryYear, + SELECT year(vn.VN_CURDATE()) entryYear, p.id deliveryNumber , DATE(di.LatestDeliveryDateTime) fec, HOUR(di.LatestDeliveryDateTime) hor, @@ -10154,6 +9491,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ekt_load` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -10161,8 +9500,6 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ekt_load`(IN `vSelf` INT) proc:BEGIN @@ -10286,7 +9623,7 @@ proc:BEGIN AND IF(t.package, l.package = e.package, TRUE) AND IF(t.item, l.item = e.item, TRUE) AND i.isFloramondo = vIsFloramondoDirect - ORDER BY l.util.VN_NOW DESC, b.id ASC + ORDER BY l.vn.VN_NOW DESC, b.id ASC LIMIT 1; END IF; @@ -10444,6 +9781,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ekt_loadNotBuy` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -10451,48 +9790,48 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ekt_loadNotBuy`() -BEGIN - - /** - * Ejecuta ekt_load para aquellos ekt de hoy que no tienen vn.buy - */ - - DECLARE vEktFk INTEGER; - DECLARE done BOOL; - - - DECLARE cursor1 CURSOR FOR SELECT e.id - FROM edi.ekt e - LEFT JOIN vn.buy b ON b.ektFk = e.id - WHERE e.fec >= util.VN_CURDATE() - AND ISNULL(b.ektFk); - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; - - OPEN cursor1; - bucle: LOOP - - FETCH cursor1 INTO vEktFk; - - IF done THEN - LEAVE bucle; - END IF; - - CALL edi.ekt_load(vEktFk); - - END LOOP bucle; - CLOSE cursor1; - +BEGIN + + /** + * Ejecuta ekt_load para aquellos ekt de hoy que no tienen vn.buy + */ + + DECLARE vEktFk INTEGER; + DECLARE done BOOL; + + + DECLARE cursor1 CURSOR FOR SELECT e.id + FROM edi.ekt e + LEFT JOIN vn.buy b ON b.ektFk = e.id + WHERE e.fec >= vn.VN_CURDATE() + AND ISNULL(b.ektFk); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1; + + OPEN cursor1; + bucle: LOOP + + FETCH cursor1 INTO vEktFk; + + IF done THEN + LEAVE bucle; + END IF; + + CALL edi.ekt_load(vEktFk); + + END LOOP bucle; + CLOSE cursor1; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `exchange_new` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -10500,48 +9839,46 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `exchange_new`( IN `vMailFk` INT, - IN `vItem` VARCHAR(255), - IN `vType` MEDIUMINT, - IN `vDeliveryNumber` BIGINT, - IN `vDate` DATE, - IN `vHour` TIME, - IN `vRef` INT, - IN `vAgj` INT, - IN `vCat` VARCHAR(2), - IN `vPac` INT, - IN `vSub` MEDIUMINT, - IN `vKop` INT, - IN `vPtd` VARCHAR(6), - IN `vPro` MEDIUMINT, - IN `vOrigin` VARCHAR(3), - IN `vPtj` MEDIUMINT, - IN `vQuantiy` INT, - IN `vPrice` DOUBLE, - IN `vClock` SMALLINT, - IN `vS1` VARCHAR(3), - IN `vS2` VARCHAR(3), - IN `vS3` VARCHAR(3), - IN `vS4` VARCHAR(4), - IN `vS5` VARCHAR(3), - IN `vS6` VARCHAR(3), - IN `vK1` SMALLINT, - IN `vK2` SMALLINT, - IN `vP1` TINYINT, - IN `vP2` TINYINT, - IN `vAuction` SMALLINT, - IN `vPackage` INT, - IN `vPutOrderFk` BIGINT) + IN `vItem` VARCHAR(255), + IN `vType` MEDIUMINT, + IN `vBatchNumber` BIGINT, + IN `vDeliveryNumber` BIGINT, + IN `vDate` DATE, + IN `vHour` TIME, + IN `vRef` INT, + IN `vAgj` INT, + IN `vCat` VARCHAR(2), + IN `vPac` INT, + IN `vSub` MEDIUMINT, + IN `vKop` INT, + IN `vPtd` VARCHAR(6), + IN `vPro` MEDIUMINT, + IN `vOrigin` VARCHAR(3), + IN `vPtj` MEDIUMINT, + IN `vQuantiy` INT, + IN `vPrice` DOUBLE, + IN `vClock` SMALLINT, + IN `vS1` VARCHAR(3), + IN `vS2` VARCHAR(3), + IN `vS3` VARCHAR(3), + IN `vS4` VARCHAR(4), + IN `vS5` VARCHAR(3), + IN `vS6` VARCHAR(3), + IN `vK1` SMALLINT, + IN `vK2` SMALLINT, + IN `vP1` TINYINT, + IN `vP2` TINYINT, + IN `vAuction` SMALLINT, + IN `vPackage` INT, + IN `vPutOrderFk` BIGINT) BEGIN /** - * Adds a new exchange, generates it's barcode and - * inserts/updates the transaction. When the referenced - * transaction exists as provisional, updates it with - * the new values. + * Adds a new exchange, generates it's barcode and inserts/updates the + * transaction. When the referenced transaction exists as provisional, updates + * it with the new values. */ DECLARE vEkt INT; DECLARE vRewriteKop INT DEFAULT NULL; @@ -10556,7 +9893,7 @@ BEGIN -- Generates the barcode - IF vAgj != 0 AND vAgj IS NOT NULL + IF vAgj != 0 AND vAgj IS NOT NULL THEN SET vBarcode = CONCAT( LPAD(vAuction, 2, 0), @@ -10569,22 +9906,6 @@ BEGIN ); END IF; - -- Generates the barcode - - /*IF vAgj != 0 AND vAgj IS NOT NULL - THEN - SET vBarcode = CONCAT( - LPAD(vAuction, 2, 0), - LPAD(IFNULL(vClock, 99), 2, 0), - LPAD(DAYOFYEAR(vDate), 3, 0), - IF(vClock IS NULL OR vClock = 99, - LPAD(vAgj, 7, 0), - CONCAT(LPAD(vAgj, 5, 0), '01') - ), - '0' - ); - END IF;*/ - -- Rewrites the kop parameter IF vKop IS NULL THEN @@ -10599,15 +9920,15 @@ BEGIN SET vKop = IFNULL(vRewriteKop, vKop); -- Inserts the new transaction - call util.debugAdd('vBarcode',vBarcode); - call util.debugAdd('vDeliveryNumber',vDeliveryNumber); + SET vIsDuplicated = FALSE; SET vTruncatePutOrder = vPutOrderFk MOD 1000000; INSERT INTO ekt SET barcode = IFNULL(vBarcode, barcode) - ,deliveryNumber = vDeliveryNumber ,entryYear = YEAR(vDate) + ,batchNumber = vBatchNumber + ,deliveryNumber = vDeliveryNumber ,fec = vDate ,hor = vHour ,ref = vRef @@ -10636,11 +9957,11 @@ BEGIN ,k4 = vP2 ,auction = vAuction ,package = vPackage - ,putOrderFk = vTruncatePutOrder; + ,putOrderFk = vTruncatePutOrder; -- If it exists duplicado updates it - IF NOT vIsDuplicated + IF NOT vIsDuplicated THEN SET vEkt = LAST_INSERT_ID(); CALL ekt_load (vEkt); @@ -10693,12 +10014,12 @@ BEGIN ,k4 = vP2 ,auction = vAuction ,package = vPackage - ,putOrderFk = IFNULL(vTruncatePutOrder, putOrderFk) + ,putOrderFk = IFNULL(vTruncatePutOrder, putOrderFk) WHERE id = vEkt; END IF; -- Registers the exchange - + INSERT INTO `exchange` SET mailFk = vMailFk ,typeFk = vType @@ -10709,15 +10030,15 @@ 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `floramondo_offerRefresh` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_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 character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `floramondo_offerRefresh`() proc: BEGIN @@ -10747,7 +10068,7 @@ proc: BEGIN RESIGNAL; END; - SET vStartingTime = util.VN_NOW(); + SET vStartingTime = vn.VN_NOW(); TRUNCATE edi.offerList ; @@ -10785,7 +10106,7 @@ proc: BEGIN FROM ( SELECT * FROM edi.supplyOffer - ORDER BY (MarketPlaceID = vAalsmeerMarketPlaceID) DESC, NumberOfUnits DESC) t + ORDER BY (MarketPlaceID = vAalsmeerMarketPlaceID) DESC, NumberOfUnits DESC LIMIT 10000000000000000000) t GROUP BY t.srId; DROP TEMPORARY TABLE IF EXISTS edi.offer; @@ -10863,19 +10184,19 @@ proc: BEGIN AND i.quality <=> o.Quality JOIN vn.itemType it ON it.id = i.typeFk LEFT JOIN vn.sale s ON s.itemFk = i.id - LEFT JOIN vn.ticket t ON t.id = s.ticketFk AND t.shipped > TIMESTAMPADD(WEEK, -1, util.VN_CURDATE()) + LEFT JOIN vn.ticket t ON t.id = s.ticketFk AND t.shipped > TIMESTAMPADD(WEEK, -1, vn.VN_CURDATE()) LEFT JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk LEFT JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID - LEFT JOIN edi.putOrder po ON po.supplyResponseID = i.supplyResponseFk AND po.OrderTradeLineDateTime > TIMESTAMPADD(WEEK, -1, util.VN_CURDATE()) + LEFT JOIN edi.putOrder po ON po.supplyResponseID = i.supplyResponseFk AND po.OrderTradeLineDateTime > TIMESTAMPADD(WEEK, -1, vn.VN_CURDATE()) SET i.supplyResponseFk = o.srID WHERE ( sr.ID IS NULL OR sr.NumberOfUnits = 0 - OR di.LatestOrderDateTime < util.VN_NOW() + OR di.LatestOrderDateTime < vn.VN_NOW() OR di.ID IS NULL) AND it.isInventory AND t.id IS NULL AND po.id IS NULL; - -- select util.VN_NOW(),'Antes de crear ITO'; + -- select vn.VN_NOW(),'Antes de crear ITO'; DROP TEMPORARY TABLE IF EXISTS itemToInsert; CREATE TEMPORARY TABLE itemToInsert ENGINE = MEMORY SELECT o.*, CAST(NULL AS DECIMAL(6,0)) as itemFk @@ -11056,7 +10377,7 @@ proc: BEGIN JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID JOIN vn.floramondoConfig fc WHERE mp.isLatestOrderDateTimeRelevant - AND di.LatestOrderDateTime > IF(fc.MaxLatestOrderHour > HOUR(util.VN_NOW()), util.VN_CURDATE(), TIMESTAMPADD(DAY,1,util.VN_CURDATE())); + AND di.LatestOrderDateTime > IF(fc.MaxLatestOrderHour > HOUR(vn.VN_NOW()), vn.VN_CURDATE(), TIMESTAMPADD(DAY,1,vn.VN_CURDATE())); UPDATE vn.floramondoConfig SET nextLanded = vLanded @@ -11071,7 +10392,7 @@ proc: BEGIN LEFT JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID LEFT JOIN edi.deliveryInformation di ON di.ID = b.deliveryFk SET b.quantity = 0 - WHERE (IFNULL(di.LatestOrderDateTime,util.VN_NOW()) <= util.VN_NOW() + WHERE (IFNULL(di.LatestOrderDateTime,vn.VN_NOW()) <= vn.VN_NOW() OR i.supplyResponseFk IS NULL OR sr.NumberOfUnits = 0) AND am.name = 'LOGIFLORA' @@ -11100,7 +10421,7 @@ proc: BEGIN JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk; */ -- Se inserta el resto - SET vLastInserted := util.VN_NOW(); + SET vLastInserted := vn.VN_NOW(); -- Inserta la oferta INSERT INTO vn.buy( entryFk, @@ -11190,7 +10511,7 @@ proc: BEGIN AND typeFk = 17; INSERT INTO edi.log(tableName, fieldName,fieldValue) - VALUES('floramondo_offerRefresh','Tiempo de proceso',TIMEDIFF(util.VN_NOW(),vStartingTime)); + VALUES('floramondo_offerRefresh','Tiempo de proceso',TIMEDIFF(vn.VN_NOW(),vStartingTime)); @@ -11200,945 +10521,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 `floramondo_offerRefresh_beta` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `floramondo_offerRefresh_beta`() -proc: BEGIN - - DECLARE vLanded DATETIME; - DECLARE done INT DEFAULT FALSE; - DECLARE vFreeId INT; - DECLARE vSupplyResponseFk INT; - DECLARE vLastInserted DATETIME; - DECLARE vIsAuctionDay BOOLEAN; - DECLARE vMaxNewItems INT DEFAULT 10000; - DECLARE vStartingTime DATETIME; - DECLARE vAalsmeerMarketPlaceID VARCHAR(13) DEFAULT '8713783439043'; - - DECLARE cur1 CURSOR FOR - SELECT id - FROM edi.item_free; - - DECLARE cur2 CURSOR FOR - SELECT srId - FROM itemToInsert; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - DECLARE EXIT HANDLER FOR SQLSTATE '45000' - BEGIN - ROLLBACK; - RESIGNAL; - END; - - SET vStartingTime = util.VN_NOW(); - - TRUNCATE edi.offerList ; - - INSERT INTO edi.offerList(supplier, total) - SELECT v.name, COUNT(DISTINCT sr.ID) total - FROM edi.supplyResponse sr - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - WHERE sr.NumberOfUnits > 0 - AND sr.EmbalageCode != 999 - GROUP BY sr.vmpID; - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(*) total - FROM edi.supplyOffer sr - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.`filter` = sub.total; - - -- Refresca las fotos de los items existentes, con prioridad baja (0.7 seg) - INSERT IGNORE INTO vn.itemImageQueue(itemFk, url,priority) - SELECT i.id, sr.PictureReference , 100 - FROM edi.supplyResponse sr - JOIN vn.item i ON i.supplyResponseFk = sr.ID - WHERE i.image != edi.imageName(sr.PictureReference) - AND sr.NumberOfUnits > 0; - - -- Elimina de la lista de items libres aquellos que ya existen - DELETE itf.* - FROM edi.item_free itf - JOIN vn.item i ON i.id = itf.id; - - DROP TEMPORARY TABLE IF EXISTS tmp; - CREATE TEMPORARY TABLE tmp (INDEX (`Item_ArticleCode`)) ENGINE = MEMORY - SELECT t.* - FROM ( - SELECT * - FROM edi.supplyOffer - ORDER BY (MarketPlaceID = vAalsmeerMarketPlaceID) DESC, NumberOfUnits DESC) t - GROUP BY t.srId; - - DROP TEMPORARY TABLE IF EXISTS edi.offer; - CREATE TEMPORARY TABLE edi.offer (INDEX (`srID`), INDEX (`EmbalageCode`), - INDEX (`ef1`), INDEX (`ef2`), INDEX (`ef3`), INDEX (`ef4`),INDEX (`ef5`), INDEX (`ef6`), - INDEX (`s1Value`), INDEX (`s2Value`), INDEX (`s3Value`), INDEX (`s4Value`),INDEX (`s5Value`), INDEX (`s6Value`)) - ENGINE = MEMORY - SELECT so.*, - ev1.type_description s1Value, - ev2.type_description s2Value, - ev3.type_description s3Value, - ev4.type_description s4Value, - ev5.type_description s5Value, - ev6.type_description s6Value, - eif1.feature ef1, - eif2.feature ef2, - eif3.feature ef3, - eif4.feature ef4, - eif5.feature ef5, - eif6.feature ef6 - FROM tmp so - LEFT JOIN edi.item_feature eif1 ON eif1.item_id = so.Item_ArticleCode - AND eif1.presentation_order = 1 AND eif1.expiry_date IS NULL - LEFT JOIN edi.item_feature eif2 ON eif2.item_id = so.Item_ArticleCode - AND eif2.presentation_order = 2 AND eif2.expiry_date IS NULL - LEFT JOIN edi.item_feature eif3 ON eif3.item_id = so.Item_ArticleCode - AND eif3.presentation_order = 3 AND eif3.expiry_date IS NULL - LEFT JOIN edi.item_feature eif4 ON eif4.item_id = so.Item_ArticleCode - AND eif4.presentation_order = 4 AND eif4.expiry_date IS NULL - LEFT JOIN edi.item_feature eif5 ON eif5.item_id = so.Item_ArticleCode - AND eif5.presentation_order = 5 AND eif5.expiry_date IS NULL - LEFT JOIN edi.item_feature eif6 ON eif6.item_id = so.Item_ArticleCode - AND eif6.presentation_order = 6 AND eif6.expiry_date IS NULL - LEFT JOIN edi.`value` ev1 ON ev1.type_id = eif1.feature AND so.s1 = ev1.type_value - LEFT JOIN edi.`value` ev2 ON ev2.type_id = eif2.feature AND so.s2 = ev2.type_value - LEFT JOIN edi.`value` ev3 ON ev3.type_id = eif3.feature AND so.s3 = ev3.type_value - LEFT JOIN edi.`value` ev4 ON ev4.type_id = eif4.feature AND so.s4 = ev4.type_value - LEFT JOIN edi.`value` ev5 ON ev5.type_id = eif5.feature AND so.s5 = ev5.type_value - LEFT JOIN edi.`value` ev6 ON ev6.type_id = eif6.feature AND so.s6 = ev6.type_value - ORDER BY Price; - - DROP TEMPORARY TABLE tmp; - - DELETE o - FROM edi.offer o - LEFT JOIN vn.tag t1 ON t1.ediTypeFk = o.ef1 AND t1.overwrite = 'size' - LEFT JOIN vn.tag t2 ON t2.ediTypeFk = o.ef2 AND t2.overwrite = 'size' - LEFT JOIN vn.tag t3 ON t3.ediTypeFk = o.ef3 AND t3.overwrite = 'size' - LEFT JOIN vn.tag t4 ON t4.ediTypeFk = o.ef4 AND t4.overwrite = 'size' - LEFT JOIN vn.tag t5 ON t5.ediTypeFk = o.ef5 AND t5.overwrite = 'size' - LEFT JOIN vn.tag t6 ON t6.ediTypeFk = o.ef6 AND t6.overwrite = 'size' - JOIN vn.floramondoConfig fc ON TRUE - WHERE (t1.id IS NOT NULL AND CONVERT(s1Value, UNSIGNED) > fc.itemMaxSize) - OR(t2.id IS NOT NULL AND CONVERT(s2Value, UNSIGNED) > fc.itemMaxSize) - OR(t3.id IS NOT NULL AND CONVERT(s3Value, UNSIGNED) > fc.itemMaxSize) - OR(t4.id IS NOT NULL AND CONVERT(s4Value, UNSIGNED) > fc.itemMaxSize) - OR(t5.id IS NOT NULL AND CONVERT(s5Value, UNSIGNED) > fc.itemMaxSize) - OR(t6.id IS NOT NULL AND CONVERT(s6Value, UNSIGNED) > fc.itemMaxSize); - - START TRANSACTION; - - -- Actualizamos el campo supplyResponseFk para aquellos articulos que ya estan creados y reutilizamos - UPDATE IGNORE edi.offer o - JOIN vn.item i - ON i.name = o.product_name - AND i.subname <=> o.company_name - AND i.value5 <=> o.s1Value - AND i.value6 <=> o.s2Value - AND i.value7 <=> o.s3Value - AND i.value8 <=> o.s4Value - AND i.value9 <=> o.s5Value - AND i.value10 <=> o.s6Value - AND i.NumberOfItemsPerCask <=> o.NumberOfItemsPerCask - AND i.EmbalageCode <=> o.EmbalageCode - AND i.quality <=> o.Quality - JOIN vn.itemType it ON it.id = i.typeFk - LEFT JOIN vn.sale s ON s.itemFk = i.id - LEFT JOIN vn.ticket t ON t.id = s.ticketFk AND t.shipped > TIMESTAMPADD(WEEK, -1, util.VN_CURDATE()) - LEFT JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - LEFT JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID - LEFT JOIN edi.putOrder po ON po.supplyResponseID = i.supplyResponseFk AND po.OrderTradeLineDateTime > TIMESTAMPADD(WEEK, -1, util.VN_CURDATE()) - SET i.supplyResponseFk = o.srID - WHERE ( sr.ID IS NULL - OR sr.NumberOfUnits = 0 - OR di.LatestOrderDateTime < util.VN_NOW() - OR di.ID IS NULL) - AND it.isInventory - AND t.id IS NULL - AND po.id IS NULL; - -- select util.VN_NOW(),'Antes de crear ITO'; - DROP TEMPORARY TABLE IF EXISTS itemToInsert; - CREATE TEMPORARY TABLE itemToInsert ENGINE = MEMORY - SELECT o.*, CAST(NULL AS DECIMAL(6,0)) as itemFk - FROM edi.offer o - LEFT JOIN vn.item i ON i.supplyResponseFk = o.srId - WHERE i.id IS NULL - LIMIT vMaxNewItems; - - -- Reciclado de nº de item - OPEN cur1; - OPEN cur2; - - read_loop: LOOP - - FETCH cur2 INTO vSupplyResponseFk; - FETCH cur1 INTO vFreeId; - - IF done THEN - LEAVE read_loop; - END IF; - - UPDATE itemToInsert - SET itemFk = vFreeId - WHERE srId = vSupplyResponseFk; - - END LOOP; - - CLOSE cur1; - CLOSE cur2; - - -- Insertamos todos los items en Articles de la oferta - INSERT INTO vn.item(id, - `name`, - longName, - subName, - expenceFk, - typeFk, - intrastatFk, - originFk, - supplyResponseFk, - numberOfItemsPerCask, - embalageCode, - quality, - isFloramondo) - SELECT iti.itemFk, - iti.product_name, - iti.product_name, - iti.company_name, - iti.expenseFk, - iti.itemTypeFk, - iti.intrastatFk, - iti.originFk, - iti.`srId`, - iti.NumberOfItemsPerCask, - iti.EmbalageCode, - iti.Quality, - TRUE - FROM itemToInsert iti; - - INSERT IGNORE INTO vn.itemImageQueue(itemFk, url) - SELECT i.id, PictureReference - FROM itemToInsert ii - JOIN vn.item i ON i.supplyResponseFk = ii.srId - WHERE PictureReference IS NOT NULL; - - INSERT INTO edi.log(tableName, fieldName,fieldValue) - SELECT 'itemImageQueue','NumImagenesPtes', COUNT(*) - FROM vn.itemImageQueue - WHERE attempts = 0; - - -- Inserta si se añadiesen tags nuevos - INSERT IGNORE INTO vn.tag (name, ediTypeFk) - SELECT description, type_id FROM edi.type; - - -- Inserta los tags sólo en los articulos nuevos - - -- desabilita el trigger para recalcular los tags al final - SET @isTriggerDisabled = TRUE; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.product_name, 1 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Producto' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ISNULL(ii.product_name); - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.Quality, 3 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Calidad' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ISNULL(ii.Quality); - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.company_name, 4 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Productor' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ISNULL(ii.company_name); - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s1Value, 5 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef1 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ISNULL(s1Value); - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s2Value, 6 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef2 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ISNULL(s2Value); - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s3Value, 7 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef3 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ISNULL(s3Value); - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s4Value, 8 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef4 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ISNULL(s4Value); - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s5Value, 9 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef5 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ISNULL(s5Value); - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s6Value, 10 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef6 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE NOT ISNULL(s6Value); - - INSERT IGNORE INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id, IFNULL(ink.name, ik.color), 11 - FROM itemToInsert ii - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - JOIN vn.tag t ON t.`name` = 'Color' - LEFT JOIN edi.feature f ON f.item_id = ii.Item_ArticleCode - LEFT JOIN edi.`type` tp ON tp.type_id = f.feature_type_id AND tp.`description` = 'Hoofdkleur 1' - LEFT JOIN vn.ink ON ink.dutchCode = f.feature_value - LEFT JOIN vn.itemInk ik ON ik.longName = i.longName - WHERE ink.name IS NOT NULL - OR ik.color IS NOT NULL; - - UPDATE vn.item i - JOIN itemToInsert ii ON i.supplyResponseFk = ii.`srId` - JOIN vn.packaging p ON p.id LIKE ii.EmbalageCode AND hasCompressionVariations - JOIN vn.itemTag diameter ON diameter.itemFk = i.id - JOIN vn.tag tDiameter ON tDiameter.overwrite = 'diameter' AND tDiameter.id = diameter.tagFk - JOIN vn.itemTag size ON size.itemFk = i.id - JOIN vn.tag tSize ON tSize.overwrite = 'size' AND tSize.id = size.tagFk - SET i.`compression` = - (PI() * POW(diameter.`value`/ 2, 2) * size.`value`) - / - ((p.width * p.depth * p.height) / ii.NumberOfItemsPerCask); - - DROP TABLE IF EXISTS tmp.item; - CREATE TABLE tmp.item - (PRIMARY KEY (id)) - SELECT i.id FROM vn.item i - JOIN itemToInsert ii ON i.supplyResponseFk = ii.`srId`; - - CALL vn.item_refreshTags(); - - SET @isTriggerDisabled = FALSE; - - SELECT MIN(LatestDeliveryDateTime) INTO vLanded - FROM edi.supplyResponse sr - JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID - JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID - JOIN vn.floramondoConfig fc - WHERE mp.isLatestOrderDateTimeRelevant - AND di.LatestOrderDateTime > IF(fc.MaxLatestOrderHour > HOUR(util.VN_NOW()), util.VN_CURDATE(), TIMESTAMPADD(DAY,1,util.VN_CURDATE())); - - UPDATE vn.floramondoConfig - SET nextLanded = vLanded - WHERE vLanded IS NOT NULL; - - -- Elimina la oferta obsoleta - UPDATE vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.agencyMode am ON am.id = tr.agencyFk - JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID - LEFT JOIN edi.deliveryInformation di ON di.ID = b.deliveryFk - SET b.quantity = 0 - WHERE (IFNULL(di.LatestOrderDateTime,util.VN_NOW()) <= util.VN_NOW() - OR i.supplyResponseFk IS NULL - OR sr.NumberOfUnits = 0) - AND am.name = 'LOGIFLORA' - AND e.isRaid; - - -- Localiza las entradas de cada almacen - UPDATE edi.warehouseFloramondo - SET entryFk = vn.entry_getForLogiflora(TIMESTAMPADD(DAY,travellingDays,vLanded), warehouseFk); - - - IF vLanded IS NOT NULL THEN - -- actualiza la oferta existente - UPDATE vn.buy b - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.offer o ON i.supplyResponseFk = o.`srId` - SET b.quantity = o.NumberOfUnits * o.NumberOfItemsPerCask, - b.buyingValue = o.price - WHERE (b.quantity <> o.NumberOfUnits * o.NumberOfItemsPerCask OR b.buyingValue <> o.price); -/* - -- Se eliminan las ofertas ya incluidas en las entradas - DELETE o - FROM edi.offer o - JOIN vn.item i ON i.supplyResponseFk = o.srId - JOIN vn.buy b ON i.id = b.itemFk - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk; - */ - -- Se inserta el resto - SET vLastInserted := util.VN_NOW(); - - -- Inserta la oferta - INSERT INTO vn.buy( entryFk, - itemFk, - quantity, - buyingValue, - stickers, - packing, - `grouping`, - groupingMode, - packageFk, - deliveryFk) - - SELECT wf.entryFk, - i.id, - o.NumberOfUnits * o.NumberOfItemsPerCask as quantity, - o.Price, - o.NumberOfUnits as etiquetas, - o.NumberOfItemsPerCask as packing, - GREATEST(1, IFNULL(o.MinimumQuantity,0)) * o.NumberOfItemsPerCask as `grouping`, - 2, -- Obliga al Packing - o.embalageCode, - o.diId - FROM edi.offer o - JOIN vn.item i ON i.supplyResponseFk = o.srId - JOIN edi.warehouseFloramondo wf - JOIN vn.packaging p ON p.id LIKE o.embalageCode - LEFT JOIN vn.buy b ON b.itemFk = i.id AND b.entryFk = wf.entryFk - WHERE ISNULL(b.id); -- llevar esta linea i mirar de crear els packages a temps real - - DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; - - CREATE TEMPORARY TABLE tmp.buyRecalc - SELECT b.id - FROM vn.buy b - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - WHERE b.created >= vLastInserted; - - CALL vn.buy_recalcPrices(); - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total - FROM vn.buy b - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.warehouse w ON w.id = wf.warehouseFk - WHERE w.name = 'VNH' - AND b.quantity > 0 - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.vnh = sub.total; - - UPDATE edi.offerList o - JOIN (SELECT v.name, COUNT(DISTINCT b.itemFk) total - FROM vn.buy b - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - JOIN edi.VMPSettings v ON v.VMPID = sr.vmpID - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.warehouse w ON w.id = wf.warehouseFk - WHERE w.name = 'ALGEMESI' - AND b.quantity > 0 - GROUP BY sr.vmpID) sub ON o.supplier = sub.name - SET o.algemesi = sub.total; - - - END IF; - - DROP TEMPORARY TABLE - edi.offer, - itemToInsert; - - DROP TABLE tmp.item; - - COMMIT; - - -- Esto habria que pasarlo a procesos programados o trabajar con tags y dejar las familias - UPDATE vn.item i - SET typeFk = 121 - WHERE i.longName LIKE 'Rosa Garden %' - AND typeFk = 17; - - UPDATE vn.item i - SET typeFk = 156 - WHERE i.longName LIKE 'Rosa ec %' - AND typeFk = 17; - - INSERT INTO edi.log(tableName, fieldName,fieldValue) - VALUES('floramondo_offerRefresh','Tiempo de proceso',TIMEDIFF(util.VN_NOW(),vStartingTime)); - - - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `floramondo_offerRefresh__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `floramondo_offerRefresh__`() -proc: BEGIN - - DECLARE vLanded DATETIME; - DECLARE done INT DEFAULT FALSE; - DECLARE vFreeId INT; - DECLARE vSupplyResponseFk INT; - DECLARE vLastInserted DATETIME; - DECLARE vIsAuctionDay BOOLEAN; - DECLARE vMaxNewItems INT DEFAULT 10000; - DECLARE vStartingTime DATETIME; - DECLARE vAalsmeerMarketPlaceID VARCHAR(13) DEFAULT '8713783439043'; - - DECLARE cur1 CURSOR FOR - SELECT id - FROM edi.item_free; - - DECLARE cur2 CURSOR FOR - SELECT srId - FROM itemToInsert; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - DECLARE EXIT HANDLER FOR SQLSTATE '45000' - BEGIN - ROLLBACK; - RESIGNAL; - END; - - SET vStartingTime = util.VN_NOW(); - - CALL util.debugAdd('edi.floramondo_offerRefresh',CONCAT('MaxItemId:' ,(SELECT MAX(id) FROM vn.item))); - - -- CALL vn.clean_logiflora(); - - -- Refresca las fotos de los items existentes, con prioridad baja (0.7 seg) - INSERT IGNORE INTO vn.itemImageQueue(itemFk, url,priority) - SELECT i.id, sr.PictureReference , 100 - FROM edi.supplyResponse sr - JOIN vn.item i ON i.supplyResponseFk = sr.ID - WHERE i.image != edi.imageName(sr.PictureReference) - AND sr.NumberOfUnits > 0; - - -- Elimina de la lista de items libres aquellos que ya existen - DELETE itf.* - FROM edi.item_free itf - JOIN vn.item i ON i.id = itf.id; - - DROP TEMPORARY TABLE IF EXISTS tmp; - CREATE TEMPORARY TABLE tmp (INDEX (`Item_ArticleCode`)) ENGINE = MEMORY - SELECT t.*, - IFNULL(idt.itemTypeFk, igo.itemTypeFk) itemTypeFk, - igo.expenseFk , - igo.intrastatFk , - igo.originFk - FROM ( - SELECT * - FROM edi.supplyOffer - ORDER BY (MarketPlaceID = vAalsmeerMarketPlaceID) DESC, NumberOfUnits DESC) t - JOIN edi.item_groupToOffer igo ON igo.group_code = t.group_id - LEFT JOIN edi.item_defaultType idt ON idt.item_id = t.Item_ArticleCode - GROUP BY t.srId - -- GROUP BY Item_ArticleCode, s1, s2, s3, s4, s5, s6, company_name, Quality, NumberOfItemsPerCask, EmbalageCode, Price, PictureReference - ; - - -- select util.VN_NOW(),'Antes de crear edi.offer'; - - DROP TEMPORARY TABLE IF EXISTS edi.offer; - CREATE TEMPORARY TABLE edi.offer (INDEX (`srID`), INDEX (`EmbalageCode`), - INDEX (`ef1`), INDEX (`ef2`), INDEX (`ef3`), INDEX (`ef4`),INDEX (`ef5`), INDEX (`ef6`), - INDEX (`s1Value`), INDEX (`s2Value`), INDEX (`s3Value`), INDEX (`s4Value`),INDEX (`s5Value`), INDEX (`s6Value`)) - ENGINE = MEMORY - SELECT so.*, ev1.type_description s1Value, ev2.type_description s2Value, ev3.type_description s3Value, - ev4.type_description s4Value, ev5.type_description s5Value, ev6.type_description s6Value, - eif1.feature ef1, eif2.feature ef2, eif3.feature ef3, eif4.feature ef4, eif5.feature ef5, eif6.feature ef6 - FROM tmp so - LEFT JOIN edi.item_feature eif1 ON eif1.item_id = so.Item_ArticleCode - AND eif1.presentation_order = 1 AND eif1.expiry_date IS NULL - LEFT JOIN edi.item_feature eif2 ON eif2.item_id = so.Item_ArticleCode - AND eif2.presentation_order = 2 AND eif2.expiry_date IS NULL - LEFT JOIN edi.item_feature eif3 ON eif3.item_id = so.Item_ArticleCode - AND eif3.presentation_order = 3 AND eif3.expiry_date IS NULL - LEFT JOIN edi.item_feature eif4 ON eif4.item_id = so.Item_ArticleCode - AND eif4.presentation_order = 4 AND eif4.expiry_date IS NULL - LEFT JOIN edi.item_feature eif5 ON eif5.item_id = so.Item_ArticleCode - AND eif5.presentation_order = 5 AND eif5.expiry_date IS NULL - LEFT JOIN edi.item_feature eif6 ON eif6.item_id = so.Item_ArticleCode - AND eif6.presentation_order = 6 AND eif6.expiry_date IS NULL - LEFT JOIN edi.`value` ev1 ON ev1.type_id = eif1.feature AND so.s1 = ev1.type_value - LEFT JOIN edi.`value` ev2 ON ev2.type_id = eif2.feature AND so.s2 = ev2.type_value - LEFT JOIN edi.`value` ev3 ON ev3.type_id = eif3.feature AND so.s3 = ev3.type_value - LEFT JOIN edi.`value` ev4 ON ev4.type_id = eif4.feature AND so.s4 = ev4.type_value - LEFT JOIN edi.`value` ev5 ON ev5.type_id = eif5.feature AND so.s5 = ev5.type_value - LEFT JOIN edi.`value` ev6 ON ev6.type_id = eif6.feature AND so.s6 = ev6.type_value - ORDER BY Price; - - DROP TEMPORARY TABLE tmp; - - DELETE o - FROM edi.offer o - LEFT JOIN vn.tag t1 ON t1.ediTypeFk = o.ef1 AND t1.overwrite = 'size' - LEFT JOIN vn.tag t2 ON t2.ediTypeFk = o.ef2 AND t2.overwrite = 'size' - LEFT JOIN vn.tag t3 ON t3.ediTypeFk = o.ef3 AND t3.overwrite = 'size' - LEFT JOIN vn.tag t4 ON t4.ediTypeFk = o.ef4 AND t4.overwrite = 'size' - LEFT JOIN vn.tag t5 ON t5.ediTypeFk = o.ef5 AND t5.overwrite = 'size' - LEFT JOIN vn.tag t6 ON t6.ediTypeFk = o.ef6 AND t6.overwrite = 'size' - JOIN vn.floramondoConfig fc ON TRUE - WHERE (t1.id IS NOT NULL AND CONVERT(s1Value, UNSIGNED) > fc.itemMaxSize) - OR(t2.id IS NOT NULL AND CONVERT(s2Value, UNSIGNED) > fc.itemMaxSize) - OR(t3.id IS NOT NULL AND CONVERT(s3Value, UNSIGNED) > fc.itemMaxSize) - OR(t4.id IS NOT NULL AND CONVERT(s4Value, UNSIGNED) > fc.itemMaxSize) - OR(t5.id IS NOT NULL AND CONVERT(s5Value, UNSIGNED) > fc.itemMaxSize) - OR(t6.id IS NOT NULL AND CONVERT(s6Value, UNSIGNED) > fc.itemMaxSize); - - START TRANSACTION; - - -- Actualizamos el campo supplyResponseFk para aquellos articulos que ya estan creados y reutilizamos - UPDATE IGNORE edi.offer o - JOIN vn.item i - ON i.name = o.product_name - AND i.subname <=> o.company_name - AND i.value5 <=> o.s1Value - AND i.value6 <=> o.s2Value - AND i.value7 <=> o.s3Value - AND i.value8 <=> o.s4Value - AND i.value9 <=> o.s5Value - AND i.value10 <=> o.s6Value - AND i.NumberOfItemsPerCask <=> o.NumberOfItemsPerCask - AND i.EmbalageCode <=> o.EmbalageCode - AND i.quality <=> o.Quality - JOIN vn.itemType it ON it.id = i.typeFk - LEFT JOIN vn.sale s ON s.itemFk = i.id - LEFT JOIN vn.ticket t ON t.id = s.ticketFk AND t.shipped > TIMESTAMPADD(WEEK, -1, util.VN_CURDATE()) - LEFT JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - LEFT JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID - LEFT JOIN edi.putOrder po ON po.supplyResponseID = i.supplyResponseFk AND po.OrderTradeLineDateTime > TIMESTAMPADD(WEEK, -1, util.VN_CURDATE()) - SET i.supplyResponseFk = o.srID - WHERE ( sr.ID IS NULL - OR sr.NumberOfUnits = 0 - OR di.LatestOrderDateTime < util.VN_NOW() - OR di.ID IS NULL) - AND it.isInventory - AND t.id IS NULL - AND po.id IS NULL; - -- select util.VN_NOW(),'Antes de crear ITO'; - DROP TEMPORARY TABLE IF EXISTS itemToInsert; - CREATE TEMPORARY TABLE itemToInsert ENGINE = MEMORY - SELECT o.*, CAST(NULL AS DECIMAL(6,0)) as itemFk - FROM edi.offer o - LEFT JOIN vn.item i ON i.supplyResponseFk = o.srId - WHERE i.id IS NULL - LIMIT vMaxNewItems; - - -- Reciclado de nº de item - OPEN cur1; - OPEN cur2; - - read_loop: LOOP - - FETCH cur2 INTO vSupplyResponseFk; - FETCH cur1 INTO vFreeId; - - IF done THEN - LEAVE read_loop; - END IF; - - UPDATE itemToInsert - SET itemFk = vFreeId - WHERE srId = vSupplyResponseFk; - - END LOOP; - - CLOSE cur1; - CLOSE cur2; - - -- Insertamos todos los items en Articles de la oferta - INSERT INTO vn.item( id, - `name`, - longName, - subName, - expenceFk, - typeFk, - intrastatFk, - originFk, - supplyResponseFk, - numberOfItemsPerCask, - embalageCode, - quality, - isFloramondo) - SELECT iti.itemFk, - iti.product_name, - iti.product_name, - iti.company_name, - iti.expenseFk, - iti.itemTypeFk, - iti.intrastatFk, - iti.originFk, - iti.`srId`, - iti.NumberOfItemsPerCask, - iti.EmbalageCode, - iti.Quality, - TRUE - FROM itemToInsert iti; - - INSERT IGNORE INTO vn.itemImageQueue(itemFk, url) - SELECT i.id, PictureReference - FROM itemToInsert ii - JOIN vn.item i ON i.supplyResponseFk = ii.srId - WHERE PictureReference IS NOT NULL; - - INSERT INTO edi.log(tableName, fieldName,fieldValue) - SELECT 'itemImageQueue','NumImagenesPtes', COUNT(*) - FROM vn.itemImageQueue - WHERE attempts = 0; - - -- Inserta si se añadiesen tags nuevos - INSERT IGNORE INTO vn.tag (name, ediTypeFk) - SELECT description, type_id FROM edi.type; - - -- Inserta los tags sólo en los articulos nuevos - - -- desabilita el trigger para recalcular los tags al final - SET @isTriggerDisabled = TRUE; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.product_name, 1 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Producto' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId`; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.Quality, 3 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Calidad' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId`; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , ii.company_name, 4 - FROM itemToInsert ii - JOIN vn.tag t ON t.`name` = 'Productor' - JOIN vn.item i ON i.supplyResponseFk = ii.`srId`; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s1Value, 5 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef1 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE s1Value != ''; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s2Value, 6 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef2 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE s2Value != ''; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s3Value, 7 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef3 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE s3Value != ''; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s4Value, 8 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef4 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE s4Value != ''; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s5Value, 9 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef5 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE s5Value != ''; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id , s6Value, 10 - FROM itemToInsert ii - JOIN vn.tag t ON t.ediTypeFk = ii.ef6 - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - WHERE s6Value != ''; - - INSERT IGNORE INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id, IFNULL(ink.name, ik.color), 11 - FROM itemToInsert ii - JOIN vn.item i ON i.supplyResponseFk = ii.`srId` - JOIN vn.tag t ON t.`name` = 'Color' - LEFT JOIN edi.feature f ON f.item_id = ii.Item_ArticleCode - LEFT JOIN edi.`type` tp ON tp.type_id = f.feature_type_id AND tp.`description` = 'Hoofdkleur 1' - LEFT JOIN vn.ink ON ink.dutchCode = f.feature_value - LEFT JOIN vn.itemInk ik ON ik.longName = i.longName - WHERE ink.name IS NOT NULL - OR ik.color IS NOT NULL; - - UPDATE vn.item i - JOIN itemToInsert ii ON i.supplyResponseFk = ii.`srId` - JOIN vn.packaging p ON p.id LIKE ii.EmbalageCode AND hasCompressionVariations - JOIN vn.itemTag diameter ON diameter.itemFk = i.id - JOIN vn.tag tDiameter ON tDiameter.overwrite = 'diameter' AND tDiameter.id = diameter.tagFk - JOIN vn.itemTag size ON size.itemFk = i.id - JOIN vn.tag tSize ON tSize.overwrite = 'size' AND tSize.id = size.tagFk - SET i.`compression` = - (PI() * POW(diameter.`value`/ 2, 2) * size.`value`) - / - ((p.width * p.depth * p.height) / ii.NumberOfItemsPerCask); - - DROP TABLE IF EXISTS tmp.item; - CREATE TABLE tmp.item - (PRIMARY KEY (id)) - SELECT i.id FROM vn.item i - JOIN itemToInsert ii ON i.supplyResponseFk = ii.`srId`; - - CALL vn.item_refreshTags(); - - SET @isTriggerDisabled = FALSE; - - SELECT MIN(LatestDeliveryDateTime) INTO vLanded - FROM edi.supplyResponse sr - JOIN edi.deliveryInformation di ON di.supplyResponseID = sr.ID - JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID - JOIN vn.floramondoConfig fc - WHERE mp.isLatestOrderDateTimeRelevant - AND di.LatestOrderDateTime > IF(fc.MaxLatestOrderHour > HOUR(util.VN_NOW()), util.VN_CURDATE(), TIMESTAMPADD(DAY,1,util.VN_CURDATE())); - - UPDATE vn.floramondoConfig - SET nextLanded = vLanded - WHERE vLanded IS NOT NULL; - - -- Elimina la oferta obsoleta - UPDATE vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.agencyMode am ON am.id = tr.agencyFk - JOIN vn.item i ON i.id = b.itemFk - LEFT JOIN edi.supplyResponse sr ON i.supplyResponseFk = sr.ID - LEFT JOIN edi.deliveryInformation di ON di.ID = b.deliveryFk - SET b.quantity = 0 - WHERE (IFNULL(di.LatestOrderDateTime,util.VN_NOW()) <= util.VN_NOW() - OR i.supplyResponseFk IS NULL - OR sr.NumberOfUnits = 0) - AND am.name = 'LOGIFLORA' - AND e.isRaid; - - -- Localiza las entradas de cada almacen - UPDATE edi.warehouseFloramondo - SET entryFk = vn.floramondo_getEntry(TIMESTAMPADD(DAY,travellingDays,vLanded), warehouseFk); - - IF vLanded IS NOT NULL THEN - -- actualiza la oferta existente - UPDATE vn.buy b - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - JOIN vn.item i ON i.id = b.itemFk - JOIN edi.offer o ON i.supplyResponseFk = o.`srId` - SET b.quantity = o.NumberOfUnits * o.NumberOfItemsPerCask, - b.buyingValue = o.price - WHERE (b.quantity <> o.NumberOfUnits * o.NumberOfItemsPerCask OR b.buyingValue <> o.price); - - -- Se eliminan las ofertas ya incluidas en las entradas - DELETE o - FROM edi.offer o - JOIN vn.item i ON i.supplyResponseFk = o.srId - JOIN vn.buy b ON i.id = b.itemFk - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk; - - -- Se inserta el resto - SET vLastInserted := util.VN_NOW(); - - -- Inserta la oferta - INSERT INTO vn.buy(entryFk, - itemFk, - quantity, - buyingValue, - stickers, - packing, - `grouping`, - groupingMode, - packageFk, - deliveryFk) - - SELECT wf.entryFk, - i.id, - o.NumberOfUnits * o.NumberOfItemsPerCask as quantity, - o.Price, - o.NumberOfUnits as etiquetas, - o.NumberOfItemsPerCask as packing, - GREATEST(1, IFNULL(o.MinimumQuantity,0)) * o.NumberOfItemsPerCask as `grouping`, - 2, -- Obliga al Packing - o.embalageCode, - o.diId - FROM edi.offer o - JOIN vn.item i ON i.supplyResponseFk = o.srId - -- JOIN vn.itemType it ON it.id = i.typeFk - JOIN edi.warehouseFloramondo wf - JOIN vn.packaging p ON p.id LIKE o.embalageCode; -- llevar esta linea i mirar de crear els packages a temps real - - DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc; - - CREATE TEMPORARY TABLE tmp.buyRecalc - SELECT b.id - FROM vn.buy b - JOIN edi.warehouseFloramondo wf ON wf.entryFk = b.entryFk - WHERE b.created >= vLastInserted; - - CALL vn.buy_recalcPrices(); - - END IF; - - DROP TEMPORARY TABLE - edi.offer, - itemToInsert; - - DROP TABLE tmp.item; - - COMMIT; - - -- Esto habria que pasarlo a procesos programados o trabajar con tags y dejar las familias - UPDATE vn.item i - SET typeFk = 121 - WHERE i.longName LIKE 'Rosa Garden %' - AND typeFk = 17; - - UPDATE vn.item i - SET typeFk = 156 - WHERE i.longName LIKE 'Rosa ec %' - AND typeFk = 17; - - INSERT INTO edi.log(tableName, fieldName,fieldValue) - VALUES('floramondo_offerRefresh','Tiempo de proceso',TIMEDIFF(util.VN_NOW(),vStartingTime)); - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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_freeAdd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -12146,66 +10530,66 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_freeAdd`() -BEGIN - - /** - * Rellena la tabla item_free con los id ausentes en vn.item - * - */ - - DECLARE vCounter INT DEFAULT 400000; - - DECLARE vCounterNewItems INT DEFAULT 0; - - DECLARE vMaxItem INT; - - DECLARE vExists BOOLEAN DEFAULT FALSE; - - SELECT MAX(id) - INTO vMaxItem - FROM vn.item; - - DROP TEMPORARY TABLE IF EXISTS tmp.itemBusy; - CREATE TEMPORARY TABLE tmp.itemBusy - (id INT PRIMARY KEY) - SELECT i.id - FROM vn.item i - WHERE id >= 400000 - UNION ALL - SELECT ifr.id - FROM edi.item_free ifr; - - WHILE vCounter < vMaxItem DO - - SET vCounter = vCounter + 1; - - SELECT count(*) INTO vExists - FROM tmp.itemBusy - WHERE id = vCounter; - - IF NOT vExists THEN - - SET vCounterNewItems = vCounterNewItems + 1; - - INSERT INTO edi.item_free(id) - VALUES (vCounter); - - END IF; - - END WHILE; - - DROP TEMPORARY TABLE tmp.itemBusy; - +BEGIN + + /** + * Rellena la tabla item_free con los id ausentes en vn.item + * + */ + + DECLARE vCounter INT DEFAULT 400000; + + DECLARE vCounterNewItems INT DEFAULT 0; + + DECLARE vMaxItem INT; + + DECLARE vExists BOOLEAN DEFAULT FALSE; + + SELECT MAX(id) + INTO vMaxItem + FROM vn.item; + + DROP TEMPORARY TABLE IF EXISTS tmp.itemBusy; + CREATE TEMPORARY TABLE tmp.itemBusy + (id INT PRIMARY KEY) + SELECT i.id + FROM vn.item i + WHERE id >= 400000 + UNION ALL + SELECT ifr.id + FROM edi.item_free ifr; + + WHILE vCounter < vMaxItem DO + + SET vCounter = vCounter + 1; + + SELECT count(*) INTO vExists + FROM tmp.itemBusy + WHERE id = vCounter; + + IF NOT vExists THEN + + SET vCounterNewItems = vCounterNewItems + 1; + + INSERT INTO edi.item_free(id) + VALUES (vCounter); + + END IF; + + END WHILE; + + DROP TEMPORARY TABLE tmp.itemBusy; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_getNewByEkt` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -12213,8 +10597,6 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getNewByEkt`(vEktFk INT, OUT vItemFk INT) BEGIN @@ -12398,6 +10780,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `mail_new` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -12405,8 +10789,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `mail_new`( vMessageId VARCHAR(100) @@ -12451,66 +10833,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 `orderLog__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `orderLog__`(vItemFk INT) -BEGIN - - DECLARE vSupplyResponseFk INT; - DECLARE vDescription VARCHAR(100); - - SELECT supplyResponseFk, CONCAT(id, ' ',longName) INTO vSupplyResponseFk, vDescription - FROM vn.item - WHERE id = vItemFk; - - SELECT * FROM - ( - SELECT 'Cliente confirma' accion, or2.created hora, amount Cantidad - FROM hedera.order_row or2 - JOIN vn.item i ON i.id = or2.item_id - WHERE i.supplyResponseFk = vSupplyResponseFk - - UNION ALL - - SELECT vDescription, NULL, NULL - - UNION ALL - - SELECT 'Cliente se conecta' , o.date_make , NULL - FROM hedera.`order` o - JOIN hedera.order_row or2 ON or2.order_id = o.id - JOIN vn.item i ON i.id = or2.item_id - WHERE i.supplyResponseFk = vSupplyResponseFk - - UNION ALL - - SELECT DISTINCT 'Subasta cambia cantidad', srl.created, srl.NumberOfUnitsNew * sr.NumberOfItemsPerCask - FROM edi.supplyResponseLog srl - JOIN edi.supplyResponse sr ON sr.ID = srl.supplyResponseFk - WHERE srl.supplyResponseFk = vSupplyResponseFk - - UNION ALL - - SELECT 'Linea de venta definitiva', s.created, s.quantity - FROM vn.sale s - JOIN vn.item i ON i.id = s.itemFk - WHERE i.supplyResponseFk = vSupplyResponseFk) sub - ORDER BY hora; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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_calcCompByFloramondo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -12518,59 +10842,57 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_calcCompByFloramondo`(vSelf INT) -BEGIN - - /** - * Recalcula "a pelo" los componentes para un ticket de Floramondo - * - * Pendiente de concretar la solución cuando Logiflora conteste. - * - * @param vSelf Identificador de vn.ticket - */ - - CALL cache.last_buy_refresh(TRUE); - - DELETE sc.* - FROM vn.saleComponent sc - JOIN vn.sale s ON s.id = sc.saleFk - WHERE s.ticketFk = vSelf; - - UPDATE vn.sale s - JOIN vn.item i ON i.id = s.itemFk - JOIN edi.floraHollandConfig fhc - LEFT JOIN cache.last_buy lb ON lb.item_id = i.id - LEFT JOIN vn.buy b ON b.id = lb.buy_id - LEFT JOIN vn.warehouse w ON w.id = lb.warehouse_id AND w.name = 'Floramondo' - SET s.price = b.buyingValue * (1 + fhc.floramondoMargin) - WHERE s.ticketFk = vSelf; - - INSERT INTO vn.saleComponent(saleFk, componentFk, value) - SELECT s.id, c.id, MAX(b.buyingValue) - FROM vn.sale s - JOIN vn.item i ON i.id = s.itemFk - LEFT JOIN cache.last_buy lb ON lb.item_id = i.id - LEFT JOIN vn.buy b ON b.id = lb.buy_id - LEFT JOIN vn.warehouse w ON w.id = lb.warehouse_id AND w.name = 'Floramondo' - JOIN vn.component c ON c.code = 'purchaseValue' - WHERE s.ticketFk = vSelf - GROUP BY s.id; - - INSERT INTO vn.saleComponent(saleFk, componentFk, value) - SELECT s.id, c.id, MAX(b.buyingValue) * fhc.floramondoMargin - FROM vn.sale s - JOIN vn.item i ON i.id = s.itemFk - JOIN edi.floraHollandConfig fhc - LEFT JOIN cache.last_buy lb ON lb.item_id = i.id - LEFT JOIN vn.buy b ON b.id = lb.buy_id - LEFT JOIN vn.warehouse w ON w.id = lb.warehouse_id AND w.name = 'Floramondo' - JOIN vn.component c ON c.code = 'margin' - WHERE s.ticketFk = vSelf - GROUP BY s.id; - +BEGIN + + /** + * Recalcula "a pelo" los componentes para un ticket de Floramondo + * + * Pendiente de concretar la solución cuando Logiflora conteste. + * + * @param vSelf Identificador de vn.ticket + */ + + CALL cache.last_buy_refresh(TRUE); + + DELETE sc.* + FROM vn.saleComponent sc + JOIN vn.sale s ON s.id = sc.saleFk + WHERE s.ticketFk = vSelf; + + UPDATE vn.sale s + JOIN vn.item i ON i.id = s.itemFk + JOIN edi.floraHollandConfig fhc + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id + LEFT JOIN vn.buy b ON b.id = lb.buy_id + LEFT JOIN vn.warehouse w ON w.id = lb.warehouse_id AND w.name = 'Floramondo' + SET s.price = b.buyingValue * (1 + fhc.floramondoMargin) + WHERE s.ticketFk = vSelf; + + INSERT INTO vn.saleComponent(saleFk, componentFk, value) + SELECT s.id, c.id, MAX(b.buyingValue) + FROM vn.sale s + JOIN vn.item i ON i.id = s.itemFk + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id + LEFT JOIN vn.buy b ON b.id = lb.buy_id + LEFT JOIN vn.warehouse w ON w.id = lb.warehouse_id AND w.name = 'Floramondo' + JOIN vn.component c ON c.code = 'purchaseValue' + WHERE s.ticketFk = vSelf + GROUP BY s.id; + + INSERT INTO vn.saleComponent(saleFk, componentFk, value) + SELECT s.id, c.id, MAX(b.buyingValue) * fhc.floramondoMargin + FROM vn.sale s + JOIN vn.item i ON i.id = s.itemFk + JOIN edi.floraHollandConfig fhc + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id + LEFT JOIN vn.buy b ON b.id = lb.buy_id + LEFT JOIN vn.warehouse w ON w.id = lb.warehouse_id AND w.name = 'Floramondo' + JOIN vn.component c ON c.code = 'margin' + WHERE s.ticketFk = vSelf + GROUP BY s.id; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -12656,7 +10978,7 @@ CREATE TABLE `config` ( `dmsDir` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Directory where documents are allocated', PRIMARY KEY (`id`), KEY `jwtkey_IX` (`jwtKey`) COMMENT 'Prueba de Ernesto 3.8.2020. MySQL se queja de no tener indices. Si, se que solo tiene un registro pero molesta para depurar otros.' -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -12670,7 +10992,7 @@ CREATE TABLE `contact` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `recipient` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -12685,7 +11007,7 @@ CREATE TABLE `image` ( `collectionFk` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `updated` int(11) DEFAULT NULL, - `nRefs` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'Number of references, don''t modify this column manually', + `nRefs` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Number of references, don''t modify this column manually', PRIMARY KEY (`id`), UNIQUE KEY `collection` (`collectionFk`,`name`), CONSTRAINT `image_ibfk_1` FOREIGN KEY (`collectionFk`) REFERENCES `imageCollection` (`name`) ON UPDATE CASCADE @@ -12710,8 +11032,8 @@ CREATE TABLE `imageCollection` ( `schema` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Deprecated', `table` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Deprecated', `column` varchar(50) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Deprecated', - `readRoleFk` int(10) unsigned DEFAULT 1, - `writeRoleFk` int(10) unsigned DEFAULT 1, + `readRoleFk` int(10) unsigned DEFAULT '1', + `writeRoleFk` int(10) unsigned DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`), KEY `role_id_writeRoleFk` (`writeRoleFk`), @@ -12733,7 +11055,7 @@ CREATE TABLE `imageCollectionSize` ( `collectionFk` int(10) unsigned NOT NULL, `width` int(10) unsigned NOT NULL, `height` int(10) unsigned NOT NULL, - `crop` tinyint(3) unsigned NOT NULL DEFAULT 0, + `crop` tinyint(3) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `image_schema_id` (`collectionFk`), CONSTRAINT `imageCollectionSize_ibfk_1` FOREIGN KEY (`collectionFk`) REFERENCES `imageCollection` (`id`) ON UPDATE CASCADE @@ -12753,7 +11075,7 @@ CREATE TABLE `imageConfig` ( `useXsendfile` tinyint(4) NOT NULL COMMENT 'Whether to use the apache module XSendfile', `url` varchar(255) NOT NULL COMMENT 'Public URL where image are hosted', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Global image parameters'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COMMENT='Global image parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -12767,7 +11089,7 @@ CREATE TABLE `language` ( `code` varchar(10) CHARACTER SET utf8 NOT NULL, `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `orgName` varchar(255) COLLATE utf8_unicode_ci NOT NULL, - `isActive` tinyint(1) NOT NULL DEFAULT 0, + `isActive` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -12786,7 +11108,7 @@ CREATE TABLE `link` ( `link` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `image` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -12871,7 +11193,7 @@ CREATE TABLE `location` ( `phone` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `language` char(2) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -12884,14 +11206,14 @@ DROP TABLE IF EXISTS `mailConfig`; CREATE TABLE `mailConfig` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Identifier', `host` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'localhost' COMMENT 'SMTP host', - `port` smallint(6) NOT NULL DEFAULT 465 COMMENT 'SMTP port', - `secure` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Wether to use a secure connection', + `port` smallint(6) NOT NULL DEFAULT '465' COMMENT 'SMTP port', + `secure` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Wether to use a secure connection', `sender` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The sender mail address', `senderName` varchar(75) CHARACTER SET utf8 NOT NULL COMMENT 'The sender name', `user` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'SMTP user', `password` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'SMTP password, base64 encoded', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -12934,12 +11256,12 @@ CREATE TABLE `menu` ( `path` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `roleFk` int(10) unsigned NOT NULL, `parentFk` int(10) unsigned DEFAULT NULL, - `displayOrder` tinyint(4) unsigned NOT NULL DEFAULT 1, + `displayOrder` tinyint(4) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`), KEY `group_id` (`roleFk`), KEY `parent` (`parentFk`), CONSTRAINT `menu_ibfk_1` FOREIGN KEY (`roleFk`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -12955,7 +11277,7 @@ CREATE TABLE `message` ( `description` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -13284,15 +11606,15 @@ CREATE TABLE `news` ( `text` text COLLATE utf8_unicode_ci NOT NULL, `image` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `userFk` int(10) unsigned NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), - `priority` tinyint(3) unsigned NOT NULL DEFAULT 3, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `priority` tinyint(3) unsigned NOT NULL DEFAULT '3', `tag` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'new', PRIMARY KEY (`id`), KEY `user` (`userFk`), KEY `tag` (`tag`), CONSTRAINT `news_ibfk_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`account` (`id`) ON UPDATE CASCADE, CONSTRAINT `news_ibfk_2` FOREIGN KEY (`tag`) REFERENCES `newsTag` (`name`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -13383,15 +11705,15 @@ CREATE TABLE `order` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `date_send` date NOT NULL DEFAULT '0000-00-00', `customer_id` int(11) NOT NULL, - `delivery_method_id` int(11) DEFAULT 3, - `agency_id` int(11) DEFAULT 2, + `delivery_method_id` int(11) DEFAULT '3', + `agency_id` int(11) DEFAULT '2', `address_id` int(11) DEFAULT NULL, - `company_id` smallint(5) unsigned NOT NULL DEFAULT 442, + `company_id` smallint(5) unsigned NOT NULL DEFAULT '442', `note` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `source_app` set('WEB','ANDROID','IOS','SALIX','TPV','TABLET_VN','') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'TPV', - `is_bionic` tinyint(1) NOT NULL DEFAULT 1, - `confirmed` tinyint(1) NOT NULL DEFAULT 0, - `date_make` timestamp NOT NULL DEFAULT current_timestamp(), + `is_bionic` tinyint(1) NOT NULL DEFAULT '1', + `confirmed` tinyint(1) NOT NULL DEFAULT '0', + `date_make` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `first_row_stamp` datetime DEFAULT NULL, `confirm_date` datetime DEFAULT NULL, `taxableBase` decimal(10,2) NOT NULL, @@ -13430,7 +11752,7 @@ BEGIN 'jgallego@verdnatura.es', 'noreply@verdnatura.es', 'Creada order al address 2850', - CONCAT(account.myUserGetName(), ' ha creado la order ',NEW.id) + CONCAT(account.myUser_getName(), ' ha creado la order ',NEW.id) ); END IF; @@ -13449,27 +11771,27 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`order_afterUpdate` - AFTER UPDATE ON `order` - FOR EACH ROW -BEGIN - CALL stock.log_add('order', NEW.id, OLD.id); - - IF !(OLD.address_id <=> NEW.address_id) - OR !(OLD.company_id <=> NEW.company_id) - OR !(OLD.customer_id <=> NEW.customer_id) THEN - CALL order_requestRecalc(NEW.id); - END IF; - - IF !(OLD.address_id <=> NEW.address_id) AND NEW.address_id = 2850 THEN - -- Fallo que se actualiza no se sabe como tickets en este cliente - CALL vn.mail_insert( - 'jgallego@verdnatura.es', - 'noreply@verdnatura.es', - 'Actualizada order al address 2850', - CONCAT(account.myUserGetName(), ' ha creado la order ',NEW.id) - ); - END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `hedera`.`order_afterUpdate` + AFTER UPDATE ON `order` + FOR EACH ROW +BEGIN + CALL stock.log_add('order', NEW.id, OLD.id); + + IF !(OLD.address_id <=> NEW.address_id) + OR !(OLD.company_id <=> NEW.company_id) + OR !(OLD.customer_id <=> NEW.customer_id) THEN + CALL order_requestRecalc(NEW.id); + END IF; + + IF !(OLD.address_id <=> NEW.address_id) AND NEW.address_id = 2850 THEN + -- Fallo que se actualiza no se sabe como tickets en este cliente + CALL vn.mail_insert( + 'jgallego@verdnatura.es', + 'noreply@verdnatura.es', + 'Actualizada order al address 2850', + CONCAT(account.myUser_getName(), ' ha creado la order ',NEW.id) + ); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -13525,7 +11847,7 @@ CREATE TABLE `orderConfig` ( CONSTRAINT `orderConfig_ibfk_3` FOREIGN KEY (`guestAgencyFk`) REFERENCES `vn`.`agencyMode` (`id`) ON UPDATE CASCADE, CONSTRAINT `orderConfig_ibfk_4` FOREIGN KEY (`defaultAgencyFk`) REFERENCES `vn`.`agencyMode` (`id`), CONSTRAINT `orderConfig_ibfk_5` FOREIGN KEY (`guestAddressFk`) REFERENCES `vn`.`address` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -13551,22 +11873,24 @@ DROP TABLE IF EXISTS `orderRow`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `orderRow` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `orderFk` int(10) unsigned NOT NULL DEFAULT 0, - `itemFk` int(11) NOT NULL DEFAULT 0, + `orderFk` int(10) unsigned NOT NULL DEFAULT '0', + `itemFk` int(11) NOT NULL DEFAULT '0', `warehouseFk` int(11) DEFAULT NULL, `shipment` date DEFAULT NULL, - `amount` smallint(6) unsigned NOT NULL DEFAULT 0, + `amount` smallint(6) unsigned NOT NULL DEFAULT '0', `price` decimal(10,2) DEFAULT NULL, `rate` smallint(5) unsigned DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `saleFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `item` (`itemFk`), KEY `order_id` (`orderFk`), KEY `created` (`created`), KEY `warehouse_shipment` (`warehouseFk`,`shipment`), + KEY `orderRow_ibfk_4` (`saleFk`), CONSTRAINT `orderRow_ibfk_2` FOREIGN KEY (`itemFk`) REFERENCES `vn`.`item` (`id`) ON UPDATE CASCADE, - CONSTRAINT `orderRow_ibfk_3` FOREIGN KEY (`orderFk`) REFERENCES `order` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE + CONSTRAINT `orderRow_ibfk_3` FOREIGN KEY (`orderFk`) REFERENCES `order` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `orderRow_ibfk_4` FOREIGN KEY (`saleFk`) REFERENCES `vn`.`sale` (`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -13589,7 +11913,7 @@ BEGIN WHERE id = NEW.orderFk; IF vIsFirst THEN - UPDATE `order` SET first_row_stamp = util.VN_NOW() + UPDATE `order` SET first_row_stamp = vn.VN_NOW() WHERE id = NEW.orderFk; END IF; END */;; @@ -13741,11 +12065,11 @@ DROP TABLE IF EXISTS `restPriv`; CREATE TABLE `restPriv` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `methodPath` varchar(255) COLLATE utf8_unicode_ci NOT NULL, - `role` int(10) unsigned NOT NULL, + `role` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), KEY `role` (`role`), CONSTRAINT `restPriv_ibfk_1` FOREIGN KEY (`role`) REFERENCES `account`.`role` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -13783,7 +12107,7 @@ CREATE TABLE `shelfConfig` ( `shelf` int(10) unsigned NOT NULL, `maxAmount` smallint(5) unsigned DEFAULT NULL, `showPacking` tinyint(4) NOT NULL, - `stack` tinyint(4) NOT NULL DEFAULT 0, + `stack` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `shelf_id` (`shelf`), KEY `family_id` (`family`), @@ -13791,7 +12115,7 @@ CREATE TABLE `shelfConfig` ( CONSTRAINT `shelfConfig_ibfk_1` FOREIGN KEY (`family`) REFERENCES `vn`.`itemType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `shelfConfig_ibfk_2` FOREIGN KEY (`shelf`) REFERENCES `shelf` (`id`) ON UPDATE CASCADE, CONSTRAINT `shelfConfig_ibfk_3` FOREIGN KEY (`warehouse`) REFERENCES `vn`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -13809,7 +12133,7 @@ CREATE TABLE `social` ( `priority` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `priority` (`priority`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -13823,7 +12147,7 @@ CREATE TABLE `survey` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `question` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -13837,7 +12161,7 @@ CREATE TABLE `surveyAnswer` ( `id` int(10) unsigned NOT NULL, `surveyFk` int(10) unsigned NOT NULL, `answer` varchar(30) COLLATE utf8_unicode_ci NOT NULL, - `votes` int(10) unsigned NOT NULL DEFAULT 0, + `votes` int(10) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `survey` (`surveyFk`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -13875,7 +12199,7 @@ CREATE TABLE `tpvConfig` ( `maxAmount` int(10) unsigned DEFAULT NULL, `employeeFk` int(10) unsigned NOT NULL, `url` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The bank web service URL for production environment', - `testMode` tinyint(3) unsigned NOT NULL DEFAULT 0 COMMENT 'Whether test mode is enabled', + `testMode` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'Whether test mode is enabled', `testUrl` varchar(255) CHARACTER SET utf8 DEFAULT NULL COMMENT 'The bank web service URL for test environment', `testKey` varchar(50) CHARACTER SET utf8 DEFAULT NULL COMMENT 'The bank secret key for test environment', `merchantUrl` varchar(255) CHARACTER SET utf8 DEFAULT NULL, @@ -13915,7 +12239,7 @@ CREATE TABLE `tpvImapConfig` ( `successFolder` varchar(150) CHARACTER SET utf8 DEFAULT NULL, `errorFolder` varchar(150) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='IMAP configuration parameters for virtual TPV'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='IMAP configuration parameters for virtual TPV'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -13946,7 +12270,7 @@ DROP TABLE IF EXISTS `tpvMerchantEnable`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tpvMerchantEnable` ( - `merchantFk` int(10) unsigned NOT NULL DEFAULT 0, + `merchantFk` int(10) unsigned NOT NULL DEFAULT '0', `companyFk` smallint(6) unsigned NOT NULL, PRIMARY KEY (`merchantFk`,`companyFk`), UNIQUE KEY `company_id` (`companyFk`), @@ -13984,7 +12308,7 @@ CREATE TABLE `tpvTransaction` ( `response` smallint(5) unsigned DEFAULT NULL COMMENT 'Status notified by bank: NULL if no notification, 0 if success, error otherwise', `errorCode` char(7) COLLATE utf8_unicode_ci DEFAULT NULL, `status` enum('started','ok','ko') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'started', - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `merchant_id` (`merchantFk`), KEY `receipt_id` (`receiptFk`), @@ -14005,10 +12329,10 @@ DROP TABLE IF EXISTS `userSession`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `userSession` ( - `created` datetime NOT NULL DEFAULT current_timestamp(), - `lastUpdate` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `lastUpdate` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `ssid` char(64) COLLATE utf8_unicode_ci NOT NULL, - `data` text COLLATE utf8_unicode_ci DEFAULT NULL, + `data` text COLLATE utf8_unicode_ci, `userVisitFk` int(10) unsigned DEFAULT NULL, UNIQUE KEY `ssid` (`ssid`), KEY `userVisit` (`userVisitFk`), @@ -14042,7 +12366,7 @@ DROP TABLE IF EXISTS `visitAccess`; CREATE TABLE `visitAccess` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `agentFk` int(10) unsigned NOT NULL, - `stamp` datetime NOT NULL DEFAULT current_timestamp(), + `stamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `ip` int(10) unsigned DEFAULT NULL, `referer` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), @@ -14088,7 +12412,7 @@ CREATE TABLE `visitUser` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `accessFk` int(10) unsigned NOT NULL, `userFk` int(10) unsigned DEFAULT NULL, - `stamp` timestamp NOT NULL DEFAULT current_timestamp(), + `stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `access_id` (`accessFk`), KEY `date_time` (`stamp`), @@ -14125,15 +12449,15 @@ DELIMITER ; -- -- Dumping routines for database 'hedera' -- -/*!50003 DROP FUNCTION IF EXISTS `MYBASKET_GETID` */; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `myBasket_getId` */; /*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `MYBASKET_GETID`() RETURNS int(11) DETERMINISTIC @@ -14150,6 +12474,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `myClient_getDebt` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14157,8 +12483,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `myClient_getDebt`(vDate DATE) RETURNS decimal(10,2) DETERMINISTIC @@ -14168,13 +12492,15 @@ BEGIN * * @return Saldo del cliente */ - RETURN vn.clientGetDebt(account.userGetId(), vDate); + RETURN vn.clientGetDebt(account.myUser_getId(), vDate); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `myUser_checkRestPriv` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14182,32 +12508,42 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `myUser_checkRestPriv`(vMethodPath VARCHAR(255)) RETURNS tinyint(1) DETERMINISTIC BEGIN /** - * Comprueba si el usuario actual tiene permiso para ejecutar - * un servicio REST. + * Checks if the current user has permission to run a REST service. * - * @param vMethodPath Ruta del servicio REST a ejecutar - * @return %TRUE si tiene permisos, %FALSE en caso contrario - **/ - DECLARE vRole INT DEFAULT NULL; + * @param vMethodPath Route of the REST service + * @return %TRUE if it has permissions, otherwise %FALSE + */ + DECLARE vCount INT; + DECLARE vHasRole INT DEFAULT NULL; - SELECT role INTO vRole FROM restPriv + SELECT COUNT(*) INTO vCount FROM restPriv WHERE methodPath = vMethodPath; - - RETURN vRole IS NULL - OR account.myUserHasRoleId (vRole); + + IF vCount = 0 THEN + RETURN FALSE; + END IF; + + SELECT COUNT(*) > 0 + INTO vHasRole + FROM restPriv + WHERE methodPath = vMethodPath + AND (`role` IS NULL OR account.myUser_hasRoleId(`role`)) + LIMIT 1; + + RETURN vHasRole; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `order_getTotal` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14215,8 +12551,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `order_getTotal`(vSelf INT) RETURNS decimal(10,2) READS SQL DATA @@ -14251,6 +12585,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `catalog_calcFromMyAddress` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14258,8 +12594,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_calcFromMyAddress`(vDelivery DATE, vAddress INT) BEGIN @@ -14303,6 +12637,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `catalog_calcFromMyAddress_beta` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14310,8 +12646,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_calcFromMyAddress_beta`(vDelivery DATE, vAddress INT) BEGIN @@ -14355,81 +12689,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 `catalog_getTags__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_getTags__`(vLimit INT) -BEGIN -/** - * Returns the main tags for a list of items. - * - * @table tItems The list of items - * @select The main tags for the passed items - */ - CALL catalogGetAvailable; - - DROP TEMPORARY TABLE IF EXISTS tTags; - CREATE TEMPORARY TABLE tTags - (INDEX (tagFk)) - ENGINE = MEMORY - SELECT it.tagFk, SUM(it.priority) priority - FROM vn.itemTag it - JOIN tItems i ON i.id = it.itemFk - GROUP BY tagFk - LIMIT vLimit; - - SELECT l.id, l.name - FROM tTags t - JOIN vn.tagL10n l ON l.id = t.tagFk - ORDER BY priority DESC; - - DROP TEMPORARY TABLE tTags; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `catalog_getTagValues__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_getTagValues__`(vTag INT) -BEGIN -/** - * Returns the list of available values for a tag and a list of items. - * - * @table tItems The list of items - * @param vTag The tag identifier - * @select The list of available tags - */ - CALL catalogGetAvailable; - - SELECT DISTINCT it.value - FROM vn.itemTag it - JOIN tItems i ON i.id = it.itemFk - WHERE it.tagFk = vTag - ORDER BY value - LIMIT 200; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `image_ref` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14437,8 +12698,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `image_ref`( vCollection VARCHAR(255), @@ -14468,6 +12727,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `image_unref` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14475,8 +12736,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `image_unref`( vCollection VARCHAR(255), @@ -14498,6 +12757,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_calcCatalog` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14505,8 +12766,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_calcCatalog`( vSelf INT, @@ -14546,6 +12805,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_getList` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14553,8 +12814,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getList`(IN `vWarehouse` SMALLINT, IN `vShipping` DATE, IN `vCategory` INT, IN `vRate` TINYINT) BEGIN @@ -14595,6 +12854,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_getVisible` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14602,8 +12863,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getVisible`( vWarehouse TINYINT, @@ -14671,7 +12930,7 @@ BEGIN 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 util.VN_CURDATE() + WHERE t.shipped BETWEEN vDateInv AND vn.VN_CURDATE() AND t.warehouseOutFk = vWarehouse AND NOT e.isRaid AND t.isDelivered @@ -14680,7 +12939,7 @@ BEGIN 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 util.VN_CURDATE() + WHERE t.shipped BETWEEN vDateInv AND vn.VN_CURDATE() AND t.warehouseFk = vWarehouse AND s.alertLevel = 3 ) t @@ -14702,6 +12961,7 @@ BEGIN AND b.price2 >= 0 AND b.packageFk IS NOT NULL ORDER BY t.warehouseInFk = vWarehouse DESC, t.landed DESC + LIMIT 10000000000000000000 ) t GROUP BY itemFk; DROP TEMPORARY TABLE IF EXISTS tmp.itemVisible; @@ -14719,7 +12979,7 @@ BEGIN 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 */ ; + /* AND p.box */; DROP TEMPORARY TABLE `filter`, @@ -14731,127 +12991,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 `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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getVisible__`( - vWarehouse TINYINT, - vDate DATE, - 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(); - - 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 util.VN_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 util.VN_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_listAllocation` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14859,40 +13000,40 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_listAllocation`(IN `vWh` TINYINT, IN `vDate` DATE, IN `vType` INT, IN `vPrefix` VARCHAR(255), IN `vUseIds` BOOLEAN) -BEGIN -/** - * Lists visible items and it's box sizes of the specified - * type at specified date. - * - * @param vWh The warehouse id - * @param vDate The visible date - * @param vType The type id - * @param vPrefix The article prefix to filter or %NULL for all - * @param vUseIds Whether to order the result by item id - * @select List of visible items with it's box sizes - */ - CALL item_getVisible(vWh, vDate, vType, vPrefix); - - IF vUseIds - THEN - SELECT * FROM tmp.itemVisible - ORDER BY Id_Article; - ELSE - SELECT * FROM tmp.itemVisible - ORDER BY Article, packing; - END IF; - - DROP TEMPORARY TABLE tmp.itemVisible; +BEGIN +/** + * Lists visible items and it's box sizes of the specified + * type at specified date. + * + * @param vWh The warehouse id + * @param vDate The visible date + * @param vType The type id + * @param vPrefix The article prefix to filter or %NULL for all + * @param vUseIds Whether to order the result by item id + * @select List of visible items with it's box sizes + */ + CALL item_getVisible(vWh, vDate, vType, vPrefix); + + IF vUseIds + THEN + SELECT * FROM tmp.itemVisible + ORDER BY Id_Article; + ELSE + SELECT * FROM tmp.itemVisible + ORDER BY Article, packing; + END IF; + + DROP TEMPORARY TABLE tmp.itemVisible; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myBasket_addItem` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14900,8 +13041,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myBasket_addItem`( vWarehouse INT, @@ -14915,6 +13054,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myBasket_calcCatalogFromItem` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14922,8 +13063,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myBasket_calcCatalogFromItem`(vItem INT) BEGIN @@ -14945,6 +13084,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myBasket_calcCatalogFull` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14952,8 +13093,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myBasket_calcCatalogFull`() BEGIN @@ -14975,6 +13114,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myBasket_check` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -14982,8 +13123,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myBasket_check`() BEGIN @@ -15009,7 +13148,7 @@ BEGIN THEN CALL order_checkConfig(vSelf); - IF vStatus = 'OK' AND vCreated < TIMESTAMPADD(DAY, -1, util.VN_NOW()) + IF vStatus = 'OK' AND vCreated < TIMESTAMPADD(DAY, -1, vn.VN_NOW()) THEN CALL order_update(vSelf); SET vStatus = 'UPDATED'; @@ -15023,6 +13162,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myBasket_configure` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15030,91 +13171,91 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `myBasket_configure`( - vDelivery DATE, - vDeliveryMethod VARCHAR(45), - vAgency INT, +CREATE DEFINER=`root`@`localhost` PROCEDURE `myBasket_configure`( + vDelivery DATE, + vDeliveryMethod VARCHAR(45), + vAgency INT, vAddress INT) -BEGIN -/** - * Configura la cesta de la compra utilizando los parámetros - * pasados. Si los parámetros no son válidos devuelve un error. - * - * @param vDelivery Fecha de recogida - * @param vAgency Id de la agencia - * @param vAddress Id de dirección de envío, @NULL si es recogida - */ - DECLARE vSelf INT; - DECLARE vCompany INT; - DECLARE vDeliveryMethodId INT; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL; - DECLARE EXIT HANDLER FOR SQLSTATE '45000' - BEGIN - ROLLBACK; - RESIGNAL; - END; - - START TRANSACTION; - - SELECT id INTO vDeliveryMethodId - FROM vn.deliveryMethod - WHERE code = vDeliveryMethod; - - IF vDeliveryMethod = 'PICKUP' AND vAddress IS NULL - THEN - SELECT defaultAddressFk INTO vAddress - FROM myClient; - END IF; - - SET vSelf = myBasket_getId(); - - IF vSelf IS NULL - THEN - - SELECT defaultCompanyFk INTO vCompany - FROM orderConfig; - - INSERT INTO `order` - SET - customer_id = account.userGetId(), - date_send = vDelivery, - delivery_method_id = vDeliveryMethodId, - agency_id = vAgency, - address_id = vAddress, - source_app = 'WEB', - company_id = vCompany; - - SET vSelf = LAST_INSERT_ID(); - - INSERT INTO basketOrder SET - clientFk = account.userGetId(), - orderFk = vSelf; - ELSE - UPDATE `order` - SET - date_send = vDelivery, - delivery_method_id = vDeliveryMethodId, - agency_id = vAgency, - address_id = vAddress - WHERE - id = vSelf; - - CALL order_update(vSelf); - END IF; - - CALL order_checkConfig(vSelf); - - COMMIT; +BEGIN +/** + * Configura la cesta de la compra utilizando los parámetros + * pasados. Si los parámetros no son válidos devuelve un error. + * + * @param vDelivery Fecha de recogida + * @param vAgency Id de la agencia + * @param vAddress Id de dirección de envío, @NULL si es recogida + */ + DECLARE vSelf INT; + DECLARE vCompany INT; + DECLARE vDeliveryMethodId INT; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL; + DECLARE EXIT HANDLER FOR SQLSTATE '45000' + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + SELECT id INTO vDeliveryMethodId + FROM vn.deliveryMethod + WHERE code = vDeliveryMethod; + + IF vDeliveryMethod = 'PICKUP' AND vAddress IS NULL + THEN + SELECT defaultAddressFk INTO vAddress + FROM myClient; + END IF; + + SET vSelf = myBasket_getId(); + + IF vSelf IS NULL + THEN + + SELECT defaultCompanyFk INTO vCompany + FROM orderConfig; + + INSERT INTO `order` + SET + customer_id = account.myUser_getId(), + date_send = vDelivery, + delivery_method_id = vDeliveryMethodId, + agency_id = vAgency, + address_id = vAddress, + source_app = 'WEB', + company_id = vCompany; + + SET vSelf = LAST_INSERT_ID(); + + INSERT INTO basketOrder SET + clientFk = account.myUser_getId(), + orderFk = vSelf; + ELSE + UPDATE `order` + SET + date_send = vDelivery, + delivery_method_id = vDeliveryMethodId, + agency_id = vAgency, + address_id = vAddress + WHERE + id = vSelf; + + CALL order_update(vSelf); + END IF; + + CALL order_checkConfig(vSelf); + + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myBasket_configureForGuest` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15122,8 +13263,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myBasket_configureForGuest`() BEGIN @@ -15137,7 +13276,7 @@ BEGIN FROM orderConfig LIMIT 1; - SET vDate = TIMESTAMPADD(DAY, 1, util.VN_CURDATE()); + SET vDate = TIMESTAMPADD(DAY, 1, vn.VN_CURDATE()); IF WEEKDAY(vDate) BETWEEN 5 AND 6 THEN SET vDate = TIMESTAMPADD(DAY, 7 - WEEKDAY(vDate), vDate); @@ -15150,6 +13289,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myBasket_confirm` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15157,8 +13298,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myBasket_confirm`() BEGIN @@ -15176,6 +13315,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myBasket_getAvailable` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15183,8 +13324,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myBasket_getAvailable`() BEGIN @@ -15200,6 +13339,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myBasket_getTax` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15207,8 +13348,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myBasket_getTax`() READS SQL DATA @@ -15232,6 +13371,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myOrder_addItem` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15239,8 +13380,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myOrder_addItem`( vSelf INT, @@ -15263,6 +13402,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myOrder_confirm` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15270,8 +13411,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myOrder_confirm`(vSelf INT) BEGIN @@ -15290,6 +13429,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myOrder_getAvailable` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15297,8 +13438,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myOrder_getAvailable`(vSelf INT) BEGIN @@ -15323,6 +13462,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myOrder_newWithAddress` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15330,71 +13471,71 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `myOrder_newWithAddress`( - OUT vSelf INT, - vLandingDate DATE, +CREATE DEFINER=`root`@`localhost` PROCEDURE `myOrder_newWithAddress`( + OUT vSelf INT, + vLandingDate DATE, vAddressFk INT) -BEGIN -/** - * Crea una nueva orden para el usuario actual especificando - * una fecha de entrega. - * - * @param vSelf Id de la nueva orden - * @param vLandingDate Fecha de entrega - */ - DECLARE vCompany INT; - DECLARE vDeliveryMethodId INT; - DECLARE vAgencyMode INT; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL; - DECLARE EXIT HANDLER FOR SQLSTATE '45000' - BEGIN - ROLLBACK; - SET vSelf = NULL; - RESIGNAL; - END; - - START TRANSACTION; - - SELECT a.agencyModeFk, a.id - INTO vAgencyMode, vAddressFk - FROM vn.address a - WHERE a.id = vAddressFk; - - SELECT deliveryMethodFk INTO vDeliveryMethodId - FROM vn.agencyMode am - WHERE am.id = vAgencyMode; - - IF vCompany IS NULL - THEN - SELECT defaultCompanyFk INTO vCompany - FROM orderConfig; - END IF; - - INSERT INTO `order` - SET - customer_id = account.userGetId(), - date_send = vLandingDate, - delivery_method_id = vDeliveryMethodId, - agency_id = vAgencyMode, - address_id = vAddressFk, - source_app = 'WEB', - company_id = vCompany; - - SET vSelf = LAST_INSERT_ID(); - - CALL order_checkConfig(vSelf); - - COMMIT; +BEGIN +/** + * Crea una nueva orden para el usuario actual especificando + * una fecha de entrega. + * + * @param vSelf Id de la nueva orden + * @param vLandingDate Fecha de entrega + */ + DECLARE vCompany INT; + DECLARE vDeliveryMethodId INT; + DECLARE vAgencyMode INT; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL; + DECLARE EXIT HANDLER FOR SQLSTATE '45000' + BEGIN + ROLLBACK; + SET vSelf = NULL; + RESIGNAL; + END; + + START TRANSACTION; + + SELECT a.agencyModeFk, a.id + INTO vAgencyMode, vAddressFk + FROM vn.address a + WHERE a.id = vAddressFk; + + SELECT deliveryMethodFk INTO vDeliveryMethodId + FROM vn.agencyMode am + WHERE am.id = vAgencyMode; + + IF vCompany IS NULL + THEN + SELECT defaultCompanyFk INTO vCompany + FROM orderConfig; + END IF; + + INSERT INTO `order` + SET + customer_id = account.myUser_getId(), + date_send = vLandingDate, + delivery_method_id = vDeliveryMethodId, + agency_id = vAgencyMode, + address_id = vAddressFk, + source_app = 'WEB', + company_id = vCompany; + + SET vSelf = LAST_INSERT_ID(); + + CALL order_checkConfig(vSelf); + + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myOrder_newWithDate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15402,71 +13543,71 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `myOrder_newWithDate`( - OUT vSelf INT, +CREATE DEFINER=`root`@`localhost` PROCEDURE `myOrder_newWithDate`( + OUT vSelf INT, vLandingDate DATE) -BEGIN -/** - * Crea una nueva orden para el usuario actual especificando - * una fecha de entrega. - * - * @param vSelf Id de la nueva orden - * @param vLandingDate Fecha de entrega - */ - DECLARE vCompany INT; - DECLARE vDeliveryMethodId INT; - DECLARE vAgencyMode INT; - DECLARE vAddress INT; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL; - DECLARE EXIT HANDLER FOR SQLSTATE '45000' - BEGIN - ROLLBACK; - SET vSelf = NULL; - RESIGNAL; - END; - - START TRANSACTION; - - SELECT a.agencyModeFk, a.id - INTO vAgencyMode, vAddress - FROM myClient c - JOIN vn.address a ON a.id = c.defaultAddressFk; - - SELECT deliveryMethodFk INTO vDeliveryMethodId - FROM vn.agencyMode am - WHERE am.id = vAgencyMode; - - IF vCompany IS NULL - THEN - SELECT defaultCompanyFk INTO vCompany - FROM orderConfig; - END IF; - - INSERT INTO `order` - SET - customer_id = account.userGetId(), - date_send = vLandingDate, - delivery_method_id = vDeliveryMethodId, - agency_id = vAgencyMode, - address_id = vAddress, - source_app = 'WEB', - company_id = vCompany; - - SET vSelf = LAST_INSERT_ID(); - - CALL order_checkConfig(vSelf); - - COMMIT; +BEGIN +/** + * Crea una nueva orden para el usuario actual especificando + * una fecha de entrega. + * + * @param vSelf Id de la nueva orden + * @param vLandingDate Fecha de entrega + */ + DECLARE vCompany INT; + DECLARE vDeliveryMethodId INT; + DECLARE vAgencyMode INT; + DECLARE vAddress INT; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vSelf = NULL; + DECLARE EXIT HANDLER FOR SQLSTATE '45000' + BEGIN + ROLLBACK; + SET vSelf = NULL; + RESIGNAL; + END; + + START TRANSACTION; + + SELECT a.agencyModeFk, a.id + INTO vAgencyMode, vAddress + FROM myClient c + JOIN vn.address a ON a.id = c.defaultAddressFk; + + SELECT deliveryMethodFk INTO vDeliveryMethodId + FROM vn.agencyMode am + WHERE am.id = vAgencyMode; + + IF vCompany IS NULL + THEN + SELECT defaultCompanyFk INTO vCompany + FROM orderConfig; + END IF; + + INSERT INTO `order` + SET + customer_id = account.myUser_getId(), + date_send = vLandingDate, + delivery_method_id = vDeliveryMethodId, + agency_id = vAgencyMode, + address_id = vAddress, + source_app = 'WEB', + company_id = vCompany; + + SET vSelf = LAST_INSERT_ID(); + + CALL order_checkConfig(vSelf); + + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myTicket_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15474,8 +13615,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myTicket_get`(vSelf INT) BEGIN @@ -15521,6 +13660,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myTicket_getPackages` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15528,8 +13669,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myTicket_getPackages`(vSelf INT) BEGIN @@ -15554,6 +13693,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myTicket_getRows` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15561,8 +13702,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myTicket_getRows`(vSelf INT) BEGIN @@ -15583,6 +13722,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myTicket_getServices` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15590,8 +13731,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myTicket_getServices`(vSelf INT) BEGIN @@ -15610,6 +13749,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myTicket_list` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15617,8 +13758,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myTicket_list`(vFrom DATE, vTo DATE) BEGIN @@ -15630,8 +13769,8 @@ BEGIN * @param vTo To date, if %NULL current date * @select The tickets list */ - SET vFrom = IFNULL(vFrom, DATE_FORMAT(TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()), '%Y-%m-01')); - SET vTo = IFNULL(vTo, TIMESTAMPADD(YEAR, 1, util.VN_CURDATE())); + SET vFrom = IFNULL(vFrom, DATE_FORMAT(TIMESTAMPADD(MONTH, -3, vn.VN_CURDATE()), '%Y-%m-01')); + SET vTo = IFNULL(vTo, TIMESTAMPADD(YEAR, 1, vn.VN_CURDATE())); DROP TEMPORARY TABLE IF EXISTS tmp.ticket; CREATE TEMPORARY TABLE tmp.ticket @@ -15662,6 +13801,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myTicket_logAccess` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15669,8 +13810,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myTicket_logAccess`(vSelf INT) BEGIN @@ -15681,7 +13820,7 @@ BEGIN */ INSERT INTO vn.ticketLog (originFk, userFk, `action`, description) - SELECT vSelf, account.userGetId(), 'select', 'Accede a ticket' + SELECT vSelf, account.myUser_getId(), 'select', 'Accede a ticket' FROM myTicket t WHERE t.id = vSelf; END ;; @@ -15690,6 +13829,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myTpvTransaction_end` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15697,8 +13838,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myTpvTransaction_end`(vSelf INT, vStatus VARCHAR(12)) BEGIN @@ -15723,6 +13862,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `myTpvTransaction_start` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15730,8 +13871,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `myTpvTransaction_start`(vAmount INT, vCompany INT) BEGIN @@ -15786,7 +13925,7 @@ BEGIN INSERT INTO myTpvTransaction SET merchantFk = vMerchant - ,clientFk = account.userGetId() + ,clientFk = account.myUser_getId() ,amount = vAmount; SET vSelf = LAST_INSERT_ID(); @@ -15810,6 +13949,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `order_addItem` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15817,8 +13958,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_addItem`( vSelf INT, @@ -15926,6 +14065,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `order_calcCatalog` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15933,8 +14074,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_calcCatalog`(vSelf INT) BEGIN @@ -15973,6 +14112,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `order_calcCatalogFromItem` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -15980,8 +14121,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_calcCatalogFromItem`(vSelf INT, vItem INT) BEGIN @@ -16013,6 +14152,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `order_calcCatalogFull` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -16020,8 +14161,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_calcCatalogFull`(vSelf INT) BEGIN @@ -16048,7 +14187,7 @@ BEGIN CALL vn.catalog_calculate(vDate, vAddress, vAgencyMode); - IF account.myUserGetName() = 'visitor' + IF account.myUser_getName() = 'visitor' THEN DROP TEMPORARY TABLE tmp.ticketComponent; UPDATE tmp.ticketCalculateItem SET price = NULL; @@ -16059,6 +14198,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `order_checkConfig` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -16066,8 +14207,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_checkConfig`(vSelf INT) BEGIN @@ -16117,6 +14256,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `order_confirm` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -16124,8 +14265,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_confirm`(vSelf INT) BEGIN @@ -16135,7 +14274,7 @@ BEGIN * * @param vSelf The order identifier */ - DECLARE vUser INT DEFAULT account.userGetId(); + DECLARE vUser INT DEFAULT account.myUser_getId(); CALL order_confirmWithUser(vSelf, vUser); END ;; DELIMITER ; @@ -16143,6 +14282,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `order_confirmWithUser` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -16150,12 +14291,9 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_confirmWithUser`(IN `vOrder` INT, IN `vUserId` INT) BEGIN - /** * Confirms an order, creating each of its tickets on the corresponding * date, store and user. @@ -16183,8 +14321,8 @@ BEGIN DECLARE vCompanyId INT; DECLARE vAgencyModeId INT; DECLARE TICKET_FREE INT DEFAULT 2; - DECLARE vIsFloramondoWarehouse BOOL; DECLARE vCalc INT; + DECLARE vIsLogifloraItem BOOL; DECLARE cDates CURSOR FOR SELECT zgs.shipped, r.warehouse_id @@ -16194,8 +14332,8 @@ BEGIN WHERE o.id = vOrder AND r.amount != 0 GROUP BY r.warehouse_id; - DECLARE cRows CURSOR FOR - SELECT r.id, r.item_id, i.name, r.amount, r.price, r.rate + DECLARE cRows CURSOR FOR + SELECT r.id, r.item_id, i.name, r.amount, r.price, r.rate, i.isFloramondo FROM order_row r JOIN vn.item i ON i.id = r.item_id WHERE r.amount != 0 @@ -16214,14 +14352,33 @@ BEGIN -- Carga los datos del pedido SELECT o.date_send, o.address_id, o.note, - a.clientFk, o.company_id, o.agency_id - INTO vDelivery, vAddress, vNotes, - vClientId, vCompanyId, vAgencyModeId + a.clientFk, o.company_id, o.agency_id + INTO vDelivery, vAddress, vNotes, + vClientId, vCompanyId, vAgencyModeId FROM hedera.`order` o JOIN vn.address a ON a.id = o.address_id WHERE o.id = vOrder; - - -- Comprueba que el pedido no est? vac?o + + -- Carga las fechas de salida de cada almac?n + CALL vn.zone_getShipped (vDelivery, vAddress, vAgencyModeId, FALSE); + + -- Trabajador que realiza la accion + IF vUserId IS NULL THEN + SELECT employeeFk INTO vUserId FROM orderConfig; + END IF; + + START TRANSACTION; + -- Comprueba que el pedido no esta confirmado + SELECT o.confirmed INTO vIsConfirmed + FROM hedera.`order` o + WHERE o.id = vOrder + FOR UPDATE; + + IF vIsConfirmed THEN + CALL util.throw ('ORDER_ALREADY_CONFIRMED'); + END IF; + + -- Comprueba que el pedido no esta vacio SELECT COUNT(*) > 0 INTO vOk FROM order_row WHERE order_id = vOrder AND amount > 0; @@ -16229,18 +14386,7 @@ BEGIN CALL util.throw ('ORDER_EMPTY'); END IF; - -- Carga las fechas de salida de cada almac?n - CALL vn.zone_getShipped (vDelivery, vAddress, vAgencyModeId, FALSE); - - -- Trabajador que realiza la acci?n - IF vUserId IS NULL THEN - SELECT employeeFk INTO vUserId FROM orderConfig; - END IF; - -- Crea los tickets del pedido - - START TRANSACTION; - OPEN cDates; lDates: @@ -16248,7 +14394,7 @@ BEGIN SET vTicket = NULL; SET vDone = FALSE; FETCH cDates INTO vShipment, vWarehouse; - + IF vDone THEN LEAVE lDates; END IF; @@ -16262,20 +14408,20 @@ BEGIN ON o.address_id = t.addressFk AND vWarehouse = t.warehouseFk -- AND o.agency_id = t.agencyModeFk - AND o.date_send = t.landed + AND o.date_send = t.landed AND vShipment = DATE(t.shipped) WHERE o.id = vOrder - AND t.invoiceOutFk IS NULL + AND t.refFk IS NULL AND IFNULL(tls.alertLevel,0) = 0 LIMIT 1; - + -- Crea el ticket en el caso de no existir uno adecuado IF vTicket IS NULL THEN - - SET vShipment = IFNULL(vShipment, util.VN_CURDATE()); - + + SET vShipment = IFNULL(vShipment, vn.VN_CURDATE()); + CALL vn.ticket_add( vClientId, vShipment, @@ -16295,49 +14441,54 @@ BEGIN Id_Trabajador = vUserId, state_id = TICKET_FREE; END IF; - + INSERT IGNORE INTO vn.orderTicket SET orderFk = vOrder, ticketFk = vTicket; - -- A?ade las notas + -- Añade las notas IF vNotes IS NOT NULL AND vNotes != '' THEN INSERT INTO vn.ticketObservation SET ticketFk = vTicket, - observationTypeFk = 4 /* salesperson */ , + observationTypeFk = 4 /* salesperson */, `description` = vNotes ON DUPLICATE KEY UPDATE `description` = CONCAT(VALUES(`description`),'. ', `description`); END IF; - -- A?ade los movimientos y sus componentes + -- Añade los movimientos y sus componentes OPEN cRows; lRows: LOOP + SET vDone = FALSE; - FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate; + + FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate, vIsLogifloraItem; IF vDone THEN LEAVE lRows; END IF; + SET vSale = NULL; + SELECT s.id INTO vSale FROM vn.sale s WHERE ticketFk = vTicket AND price = vPrice AND itemFk = vItem - AND discount = 0 + AND discount = 0 LIMIT 1; + IF vSale THEN UPDATE vn.sale SET quantity = quantity + vAmount WHERE id = vSale; ELSE - INSERT INTO vn.sale + INSERT INTO vn.sale SET itemFk = vItem, ticketFk = vTicket, @@ -16357,37 +14508,37 @@ BEGIN WHERE cm.order_row_id = vRowId GROUP BY vSale, cm.component_id; END IF; - UPDATE order_row SET Id_Movimiento = vSale + UPDATE order_row SET Id_Movimiento = vSale WHERE id = vRowId; - - -- Inserta en putOrder si la compra es de Floramondo - IF vn.isLogifloraDay(vShipment, vWarehouse) THEN - + + -- Inserta en putOrder si la compra es de Floramondo + IF vIsLogifloraItem THEN + CALL cache.availableNoRaids_refresh(vCalc,FALSE,vWarehouse,vShipment); - + SET @available := 0; - + SELECT GREATEST(0,available) INTO @available FROM cache.availableNoRaids WHERE calc_id = vCalc AND item_id = vItem; - - UPDATE cache.availableNoRaids + + UPDATE cache.availableNoRaids SET available = GREATEST(0,available - vAmount) WHERE item_id = vItem AND calc_id = vCalc; - - INSERT INTO edi.putOrder (deliveryInformationID, - supplyResponseId, - quantity , - EndUserPartyId, + + INSERT INTO edi.putOrder (deliveryInformationID, + supplyResponseId, + quantity , + EndUserPartyId, EndUserPartyGLN, FHAdminNumber, saleFk) - SELECT di.ID, - i.supplyResponseFk, - CEIL((vAmount - @available)/ sr.NumberOfItemsPerCask ), - o.address_id , + SELECT di.ID, + i.supplyResponseFk, + CEIL((vAmount - @available)/ sr.NumberOfItemsPerCask), + o.address_id , vClientId, IFNULL(ca.fhAdminNumber, fhc.defaultAdminNumber), vSale @@ -16397,16 +14548,16 @@ BEGIN LEFT JOIN edi.clientFHAdminNumber ca ON ca.clientFk = vClientId JOIN edi.floraHollandConfig fhc JOIN hedera.`order` o ON o.id = vOrder - WHERE i.id = vItem - AND di.LatestOrderDateTime > util.VN_NOW() + WHERE i.id = vItem + AND di.LatestOrderDateTime > vn.VN_NOW() AND vAmount > @available LIMIT 1; - + END IF; - + END LOOP; - - CLOSE cRows; + + CLOSE cRows; -- Fija el coste DROP TEMPORARY TABLE IF EXISTS tComponents; @@ -16431,19 +14582,8 @@ BEGIN CLOSE cDates; DELETE FROM basketOrder WHERE orderFk = vOrder; - - SELECT o.confirmed INTO vIsConfirmed - FROM hedera.`order` o - JOIN vn.address a ON a.id = o.address_id - WHERE o.id = vOrder; - -- Comprueba que el pedido no est? confirmado - - IF vIsConfirmed THEN - CALL util.throw ('ORDER_ALREADY_CONFIRMED'); - END IF; - - UPDATE `order` SET confirmed = TRUE, confirm_date = util.VN_NOW() + UPDATE `order` SET confirmed = TRUE, confirm_date = vn.VN_NOW() WHERE id = vOrder; COMMIT; @@ -16453,6 +14593,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `order_doRecalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -16460,8 +14602,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_doRecalc`() proc: BEGIN @@ -16515,6 +14655,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `order_getAvailable` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -16522,8 +14664,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_getAvailable`(vSelf INT) BEGIN @@ -16560,6 +14700,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `order_getTax` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -16567,8 +14709,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_getTax`() READS SQL DATA @@ -16635,6 +14775,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `order_getTotal` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -16642,8 +14784,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_getTotal`() BEGIN @@ -16673,6 +14813,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `order_recalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -16680,8 +14822,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_recalc`(vSelf INT) BEGIN @@ -16719,6 +14859,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `order_requestRecalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -16726,8 +14868,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_requestRecalc`(vSelf INT) proc: BEGIN @@ -16747,6 +14887,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `order_update` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -16754,8 +14896,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `order_update`(vSelf INT) proc: BEGIN @@ -16817,7 +14957,7 @@ proc: BEGIN CALL vn.ticketCalculatePurge; END IF; - UPDATE `order` SET date_make = util.VN_NOW() + UPDATE `order` SET date_make = vn.VN_NOW() WHERE id = vSelf; COMMIT; @@ -16827,6 +14967,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `survey_vote` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -16834,8 +14976,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `survey_vote`(vAnswer INT) BEGIN @@ -16849,7 +14989,7 @@ BEGIN INSERT INTO surveyVote SET surveyFk = vSurvey, - userFk = account.userGetId(); + userFk = account.myUser_getId(); UPDATE surveyAnswer SET votes = votes + 1 WHERE id = vAnswer; @@ -16859,6 +14999,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `tpvTransaction_confirm` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -16866,8 +15008,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `tpvTransaction_confirm`( vAmount INT @@ -16984,6 +15124,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `tpvTransaction_confirmAll` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -16991,8 +15133,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `tpvTransaction_confirmAll`(vDate DATE) BEGIN @@ -17035,6 +15175,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `tpvTransaction_confirmById` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -17042,8 +15184,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `tpvTransaction_confirmById`(vOrder INT) BEGIN @@ -17077,6 +15217,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `tpvTransaction_undo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -17084,8 +15226,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `tpvTransaction_undo`(vSelf INT) p: BEGIN @@ -17171,6 +15311,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `visitUser_new` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -17178,8 +15320,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `visitUser_new`( vAccess INT @@ -17190,7 +15330,7 @@ BEGIN INSERT INTO visitUser SET accessFk = vAccess, - userFk = account.userGetId(); + userFk = account.myUser_getId(); SET vUserVisit = LAST_INSERT_ID(); @@ -17198,13 +15338,15 @@ BEGIN WHERE ssid = vSsid; DELETE FROM userSession - WHERE lastUpdate < TIMESTAMPADD(HOUR, -1, util.VN_NOW()); + WHERE lastUpdate < TIMESTAMPADD(HOUR, -1, vn.VN_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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `visit_listByBrowser` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -17212,8 +15354,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `visit_listByBrowser`(vFrom DATE, vTo DATE) BEGIN @@ -17242,6 +15382,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `visit_register` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -17249,8 +15391,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `visit_register`( vVisit INT @@ -17389,11 +15529,11 @@ CREATE TABLE `labourTree` ( `id` int(11) NOT NULL AUTO_INCREMENT, `lft` int(11) NOT NULL, `rgt` int(11) NOT NULL, - `depth` int(11) NOT NULL DEFAULT 0, - `sons` int(11) NOT NULL DEFAULT 0, + `depth` int(11) NOT NULL DEFAULT '0', + `sons` int(11) NOT NULL DEFAULT '0', `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -17410,7 +15550,7 @@ CREATE TABLE `nst` ( PRIMARY KEY (`id`), UNIQUE KEY `lft_UNIQUE` (`lft`), UNIQUE KEY `rgt_UNIQUE` (`rgt`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -17420,6 +15560,8 @@ CREATE TABLE `nst` ( -- -- Dumping routines for database 'nst' -- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `nodeAdd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -17427,8 +15569,6 @@ CREATE TABLE `nst` ( /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `nodeAdd`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45), IN `vParentFk` INT, IN `vChild` VARCHAR(100)) BEGIN @@ -17495,6 +15635,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `nodeDelete` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -17502,8 +15644,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `nodeDelete`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45), IN `vNodeId` INT) BEGIN @@ -17538,6 +15678,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `nodeMove` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -17545,8 +15687,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `nodeMove`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45), IN `vNodeId` INT, IN `vFatherId` INT) BEGIN @@ -17621,6 +15761,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `nodeRecalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -17628,8 +15770,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `nodeRecalc`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45)) BEGIN @@ -17653,6 +15793,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `nodeTree` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -17660,8 +15802,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `nodeTree`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45), IN `vGap` INT, IN `vShouldShow` BOOLEAN) BEGIN @@ -17696,6 +15836,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `nodeTree_pako` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -17703,8 +15845,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `nodeTree_pako`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45), IN `vGap` INT, IN `vShouldShow` BOOLEAN) BEGIN @@ -17811,7 +15951,7 @@ DROP TABLE IF EXISTS `cdr`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cdr` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `call_date` datetime NOT NULL DEFAULT current_timestamp(), + `call_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `clid` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `src` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `dst` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', @@ -17820,10 +15960,10 @@ CREATE TABLE `cdr` ( `dst_channel` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `last_app` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `last_data` varchar(80) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `duration` int(11) NOT NULL DEFAULT 0, - `billsec` int(11) NOT NULL DEFAULT 0, + `duration` int(11) NOT NULL DEFAULT '0', + `billsec` int(11) NOT NULL DEFAULT '0', `disposition` varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `ama_flags` int(11) NOT NULL DEFAULT 0, + `ama_flags` int(11) NOT NULL DEFAULT '0', `account_code` varchar(20) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `unique_id` varchar(32) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `user_field` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', @@ -17834,7 +15974,7 @@ CREATE TABLE `cdr` ( KEY `dstchannel` (`dst_channel`), KEY `disposition` (`disposition`), KEY `src` (`src`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -17877,7 +16017,7 @@ CREATE TABLE `config` ( `sundayFestive` tinyint(4) NOT NULL, `countryPrefix` varchar(20) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -17967,7 +16107,7 @@ CREATE TABLE `followmeConfig` ( `declineCall` char(1) CHARACTER SET utf8 NOT NULL, `timeout` int(11) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18003,7 +16143,7 @@ CREATE TABLE `queue` ( UNIQUE KEY `description` (`description`), KEY `config` (`config`), CONSTRAINT `queue_ibfk_1` FOREIGN KEY (`config`) REFERENCES `queueConfig` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queues'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queues'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -18081,7 +16221,7 @@ CREATE TABLE `queueConfig` ( `maxLen` int(10) unsigned NOT NULL, `ringInUse` tinyint(4) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Default values for queues configuration'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Default values for queues configuration'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18100,7 +16240,7 @@ CREATE TABLE `queueMember` ( KEY `extension` (`extension`), CONSTRAINT `queueMember_ibfk_1` FOREIGN KEY (`queue`) REFERENCES `queue` (`name`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `queueMember_ibfk_2` FOREIGN KEY (`extension`) REFERENCES `sip` (`extension`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queue members'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queue members'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18133,7 +16273,7 @@ CREATE TABLE `queuePhone` ( PRIMARY KEY (`id`), UNIQUE KEY `queue` (`queue`,`phone`), CONSTRAINT `queuePhone_ibfk_1` FOREIGN KEY (`queue`) REFERENCES `queue` (`name`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -18192,7 +16332,7 @@ CREATE TABLE `schedule` ( PRIMARY KEY (`id`), KEY `queue` (`queue`), CONSTRAINT `schedule_ibfk_1` FOREIGN KEY (`queue`) REFERENCES `queue` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18203,7 +16343,7 @@ DROP TABLE IF EXISTS `sip`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `sip` ( - `user_id` int(10) unsigned NOT NULL DEFAULT 0 COMMENT 'The user id', + `user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'The user id', `extension` varchar(128) CHARACTER SET utf8 NOT NULL COMMENT 'The softphone extension', `md5Secret` varchar(80) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'MD5 hash of extension and password', `secret` varchar(80) CHARACTER SET utf8 DEFAULT NULL COMMENT 'Deprecated', @@ -18369,7 +16509,7 @@ CREATE TABLE `sipConfig` ( `dtlssetup` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `nat` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Default values for SIP accounts'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Default values for SIP accounts'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18401,6 +16541,8 @@ CREATE TABLE `sipReg` ( -- -- Dumping routines for database 'pbx' -- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `clientFromPhone` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -18408,8 +16550,6 @@ CREATE TABLE `sipReg` ( /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `clientFromPhone`(vPhone VARCHAR(255)) RETURNS int(11) DETERMINISTIC @@ -18424,6 +16564,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `phone_format` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -18431,8 +16573,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `phone_format`(vPhone VARCHAR(255)) RETURNS varchar(255) CHARSET utf8 DETERMINISTIC @@ -18472,6 +16612,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `phone_isValid` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -18479,8 +16621,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `phone_isValid`(vPhone VARCHAR(255)) BEGIN @@ -18507,6 +16647,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `queue_isValid` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -18514,8 +16656,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `queue_isValid`(vQueue VARCHAR(255)) BEGIN @@ -18540,6 +16680,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sip_getExtension` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -18547,29 +16689,29 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sip_getExtension`(vUserId INT(10)) -BEGIN - - /* - * Devuelve la extensión pbx del usuario - * - * @param vUserId Id del usuario - * - */ - - SELECT extension - FROM sip s - WHERE s.user_id = vUserId; - +BEGIN + + /* + * Devuelve la extensión pbx del usuario + * + * @param vUserId Id del usuario + * + */ + + SELECT extension + FROM sip s + WHERE s.user_id = vUserId; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sip_isValid` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -18577,8 +16719,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sip_isValid`(vExtension VARCHAR(255)) BEGIN @@ -18604,6 +16744,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sip_setPassword` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -18611,8 +16753,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sip_setPassword`( vUser VARCHAR(255), @@ -18657,7 +16797,7 @@ CREATE TABLE `address` ( KEY `address_town_id_idx` (`town_id`), CONSTRAINT `address_ibfk_1` FOREIGN KEY (`address_type_id`) REFERENCES `address_type` (`address_type_id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `address_ibfk_2` FOREIGN KEY (`town_id`) REFERENCES `townKk` (`town_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18671,7 +16811,7 @@ CREATE TABLE `address_type` ( `address_type_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) NOT NULL, PRIMARY KEY (`address_type_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18705,7 +16845,7 @@ CREATE TABLE `bank_account` ( CONSTRAINT `bank_account_client_id` FOREIGN KEY (`client_id`) REFERENCES `profile` (`profile_id`) ON UPDATE CASCADE, CONSTRAINT `bank_account_nation_id` FOREIGN KEY (`nation_id`) REFERENCES `vn`.`country` (`id`) ON UPDATE CASCADE, CONSTRAINT `bank_account_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18719,7 +16859,7 @@ CREATE TABLE `bank_account_type` ( `bank_account_type_id` int(11) NOT NULL AUTO_INCREMENT, `name` char(15) DEFAULT NULL, PRIMARY KEY (`bank_account_type_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18753,7 +16893,7 @@ CREATE TABLE `business` ( `provider_id` int(11) DEFAULT NULL, `date_start` date DEFAULT NULL, `date_end` date DEFAULT NULL, - `workerBusiness` longtext DEFAULT NULL, + `workerBusiness` longtext, `reasonEndFk` int(11) DEFAULT NULL, `payedHolidays` int(11) DEFAULT NULL, `occupationCodeFk` varchar(1) DEFAULT NULL, @@ -18775,32 +16915,32 @@ CREATE TABLE `business` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `postgresql`.`business_beforeUpdate` - BEFORE UPDATE ON `business` - FOR EACH ROW -BEGIN - DECLARE isOverlapping BOOL; - - IF !(OLD.date_start <=> NEW.date_start AND OLD.date_end <=> NEW.date_end) THEN - - SELECT COUNT(*) > 0 INTO isOverlapping - FROM business b - WHERE (util.hasDateOverlapped( - NEW.date_start, - IFNULL(NEW.date_end,b.date_start), - b.date_start, - IFNULL(b.date_end,NEW.date_start)) - OR (NEW.date_end <=> NULL AND b.date_end <=> NULL)) - AND b.business_id <> OLD.business_id - AND client_id = OLD.client_id - ; - - IF isOverlapping THEN - CALL util.throw ('IS_OVERLAPPING'); - END IF; - - END IF; - +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `postgresql`.`business_beforeUpdate` + BEFORE UPDATE ON `business` + FOR EACH ROW +BEGIN + DECLARE isOverlapping BOOL; + + IF !(OLD.date_start <=> NEW.date_start AND OLD.date_end <=> NEW.date_end) THEN + + SELECT COUNT(*) > 0 INTO isOverlapping + FROM business b + WHERE (util.hasDateOverlapped( + NEW.date_start, + IFNULL(NEW.date_end,b.date_start), + b.date_start, + IFNULL(b.date_end,NEW.date_start)) + OR (NEW.date_end <=> NULL AND b.date_end <=> NULL)) + AND b.business_id <> OLD.business_id + AND client_id = OLD.client_id + ; + + IF isOverlapping THEN + CALL util.throw ('IS_OVERLAPPING'); + END IF; + + END IF; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -18817,12 +16957,12 @@ DROP TABLE IF EXISTS `business_labour`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `business_labour` ( `business_id` int(11) NOT NULL, - `notes` longtext DEFAULT NULL, + `notes` longtext, `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, - `porhoras` smallint(6) NOT NULL DEFAULT 0, + `professional_category_id` int(11) DEFAULT '0', + `incentivo` double DEFAULT '0', + `calendar_labour_type_id` int(11) DEFAULT '1', + `porhoras` smallint(6) NOT NULL DEFAULT '0', `labour_agreement_id` int(11) DEFAULT NULL, `workcenter_id` int(11) NOT NULL, PRIMARY KEY (`business_id`), @@ -18831,10 +16971,10 @@ CREATE TABLE `business_labour` ( KEY `horario_tipo` (`calendar_labour_type_id`), 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_FK` FOREIGN KEY (`workcenter_id`) REFERENCES `vn`.`workCenter` (`id`) 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_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 UPDATE CASCADE + CONSTRAINT `horario_tipo` FOREIGN KEY (`calendar_labour_type_id`) REFERENCES `calendar_labour_type` (`calendar_labour_type_id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; @@ -18850,7 +16990,7 @@ CREATE TABLE `business_labour_payroll` ( `cod_tarifa` int(11) DEFAULT NULL, `cod_categoria` int(11) DEFAULT NULL, `cod_contrato` int(11) DEFAULT NULL, - `importepactado` decimal(10,2) NOT NULL DEFAULT 0.00, + `importepactado` decimal(10,2) NOT NULL DEFAULT '0.00', PRIMARY KEY (`business_id`), KEY `business_labour_payroll_cod_categoria_idx` (`cod_categoria`), KEY `business_labour_payroll_FK` (`cod_contrato`), @@ -18888,7 +17028,7 @@ CREATE TABLE `calendar_free__` ( `type` varchar(20) NOT NULL, `rgb` varchar(7) DEFAULT NULL, PRIMARY KEY (`calendar_free_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18913,8 +17053,8 @@ CREATE TABLE `calendar_labour__` ( KEY `fki_workcenter_calendar` (`workcenter_id`), CONSTRAINT `fk_calendar_labour_calendar_free1` FOREIGN KEY (`calendar_free_id`) REFERENCES `calendar_free__` (`calendar_free_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_calendar_labour_legend_id` FOREIGN KEY (`calendar_labour_legend_id`) REFERENCES `calendar_labour_legend__` (`calendar_labour_legend_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `workcenter_calendar` FOREIGN KEY (`workcenter_id`) REFERENCES `workcenter` (`workcenter_id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; + CONSTRAINT `workcenter_calendar` FOREIGN KEY (`workcenter_id`) REFERENCES `workcenter__` (`workcenter_id`) ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18926,10 +17066,10 @@ DROP TABLE IF EXISTS `calendar_labour_legend__`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `calendar_labour_legend__` ( `calendar_labour_legend_id` int(11) NOT NULL AUTO_INCREMENT, - `descripcion` longtext DEFAULT NULL, + `descripcion` longtext, PRIMARY KEY (`calendar_labour_legend_id`), UNIQUE KEY `calendar_labour_legend_calendar_labour_legend_id_key` (`calendar_labour_legend_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18944,34 +17084,12 @@ CREATE TABLE `calendar_labour_type` ( `descripcion` varchar(50) DEFAULT NULL, `pausa_remunerada` time DEFAULT NULL, `hours_week` smallint(6) DEFAULT NULL, - `isPartial` tinyint(1) NOT NULL DEFAULT 0, + `isPartial` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`calendar_labour_type_id`), UNIQUE KEY `hours_labour_hours_labour_id_key` (`calendar_labour_type_id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `calendar_state` --- - -DROP TABLE IF EXISTS `calendar_state`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `calendar_state` ( - `calendar_state_id` int(11) NOT NULL AUTO_INCREMENT, - `type` varchar(30) NOT NULL, - `rgb` varchar(7) NOT NULL, - `color` bigint(20) DEFAULT 0, - `permissionRate` decimal(3,2) DEFAULT NULL, - `code` varchar(45) DEFAULT NULL, - `isAllowedToWork` tinyint(4) NOT NULL DEFAULT 0, - `isPrintable` tinyint(1) NOT NULL DEFAULT 0, - `discountRate` decimal(3,2) DEFAULT NULL, - `holidayEntitlementRate` decimal(3,2) DEFAULT 1.00, - PRIMARY KEY (`calendar_state_id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `currency__` -- @@ -18983,7 +17101,7 @@ CREATE TABLE `currency__` ( `currency_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(15) NOT NULL, PRIMARY KEY (`currency_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19010,18 +17128,18 @@ DROP TABLE IF EXISTS `income_employee`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `income_employee` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `debe` decimal(10,2) NOT NULL DEFAULT 0.00, - `haber` decimal(10,2) NOT NULL DEFAULT 0.00, + `debe` decimal(10,2) NOT NULL DEFAULT '0.00', + `haber` decimal(10,2) NOT NULL DEFAULT '0.00', `id_incomeType` int(11) DEFAULT NULL, `odbc_date` date DEFAULT NULL, `person_id` int(11) DEFAULT NULL, - `concepto` longtext DEFAULT NULL, + `concepto` longtext, PRIMARY KEY (`id`), KEY `fperson_id` (`person_id`), KEY `income_employeeId_incomeType_idx` (`id_incomeType`), CONSTRAINT `income_employeeId_incomeType` FOREIGN KEY (`id_incomeType`) REFERENCES `vn2008`.`payroll_conceptos` (`conceptoid`) ON UPDATE CASCADE, CONSTRAINT `income_employee_FK` FOREIGN KEY (`person_id`) REFERENCES `vn`.`person` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19034,8 +17152,8 @@ DROP TABLE IF EXISTS `incometype_employee`; CREATE TABLE `incometype_employee` ( `id_incometype` int(11) NOT NULL, `descripcion` varchar(255) DEFAULT NULL, - `nomina` smallint(6) DEFAULT 0, - `isExtraSalarial` tinyint(4) NOT NULL DEFAULT 0, + `nomina` smallint(6) DEFAULT '0', + `isExtraSalarial` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`id_incometype`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; @@ -19049,7 +17167,7 @@ DROP TABLE IF EXISTS `journey`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `journey` ( `journey_id` int(11) NOT NULL AUTO_INCREMENT, - `day_id` smallint(6) NOT NULL DEFAULT 1 COMMENT 'Lunes = 1 \nDomingo = 7', + `day_id` smallint(6) NOT NULL DEFAULT '1' COMMENT 'Lunes = 1 \nDomingo = 7', `start` time DEFAULT NULL, `end` time DEFAULT NULL, `business_id` int(11) NOT NULL, @@ -19057,7 +17175,7 @@ CREATE TABLE `journey` ( UNIQUE KEY `day_id` (`day_id`,`start`,`end`,`business_id`), KEY `fki_business_journey` (`business_id`), CONSTRAINT `business_journey` FOREIGN KEY (`business_id`) REFERENCES `business` (`business_id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19120,25 +17238,25 @@ DROP TABLE IF EXISTS `nation__`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `nation__` ( `nation_id` int(11) NOT NULL AUTO_INCREMENT, - `currency_id` int(11) NOT NULL DEFAULT 1, + `currency_id` int(11) NOT NULL DEFAULT '1', `name` varchar(20) NOT NULL, `brief` char(3) NOT NULL, - `flag` longblob DEFAULT NULL, + `flag` longblob, PRIMARY KEY (`nation_id`), UNIQUE KEY `nation_name_key` (`name`), KEY `nation_currency_id_idx` (`currency_id`), CONSTRAINT `nation___ibfk_1` FOREIGN KEY (`currency_id`) REFERENCES `currency__` (`currency_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `periodos` +-- Table structure for table `periodos__` -- -DROP TABLE IF EXISTS `periodos`; +DROP TABLE IF EXISTS `periodos__`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `periodos` ( +CREATE TABLE `periodos__` ( `fecha` date NOT NULL, `periodo` int(11) DEFAULT NULL, PRIMARY KEY (`fecha`) @@ -19161,7 +17279,6 @@ SET character_set_client = utf8; `birth` tinyint NOT NULL, `firstname` tinyint NOT NULL, `p2` tinyint NOT NULL, - `nis` tinyint NOT NULL, `id_trabajador` tinyint NOT NULL, `isDisable` tinyint NOT NULL, `isFreelance` tinyint NOT NULL, @@ -19184,12 +17301,12 @@ CREATE TABLE `person__` ( `nif` varchar(15) DEFAULT NULL, `birth` date DEFAULT NULL, `firstname` varchar(20) DEFAULT NULL, - `p2` longtext DEFAULT NULL, + `p2` longtext, `nis` int(11) DEFAULT NULL, `id_trabajador` int(10) unsigned DEFAULT NULL, - `isDisable` smallint(6) NOT NULL DEFAULT 0, - `isFreelance` smallint(6) NOT NULL DEFAULT 0 COMMENT 'M Male\nF Female', - `isSsDiscounted` smallint(6) NOT NULL DEFAULT 0, + `isDisable` smallint(6) NOT NULL DEFAULT '0', + `isFreelance` smallint(6) NOT NULL DEFAULT '0' COMMENT 'M Male\nF Female', + `isSsDiscounted` smallint(6) NOT NULL DEFAULT '0', `sex` enum('M','F') NOT NULL DEFAULT 'F' COMMENT 'M Masculino F Femenino', PRIMARY KEY (`person_id`), UNIQUE KEY `person_nis` (`person_id`), @@ -19199,7 +17316,7 @@ CREATE TABLE `person__` ( KEY `index1` (`person_id`,`name`,`nickname`,`firstname`), KEY `person_worker` (`id_trabajador`), CONSTRAINT `Person_ibfk_1` FOREIGN KEY (`id_trabajador`) REFERENCES `vn`.`worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19213,7 +17330,7 @@ CREATE TABLE `professional_category` ( `professional_category_id` int(11) NOT NULL AUTO_INCREMENT, `category_name` varchar(50) NOT NULL, `professional_levels_id` int(11) DEFAULT NULL, - `fichajes` tinyint(4) NOT NULL DEFAULT 1, + `fichajes` tinyint(4) NOT NULL DEFAULT '1', `holiday_days` decimal(3,1) DEFAULT NULL, `dayBreak` int(11) DEFAULT NULL, PRIMARY KEY (`professional_category_id`), @@ -19233,7 +17350,7 @@ CREATE TABLE `professional_levels` ( `level_name` varchar(5) DEFAULT NULL, `price_overtime` double DEFAULT NULL, PRIMARY KEY (`professional_levels_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19246,7 +17363,7 @@ DROP TABLE IF EXISTS `profile`; CREATE TABLE `profile` ( `profile_id` int(11) NOT NULL AUTO_INCREMENT, `person_id` int(11) NOT NULL, - `profile_type_id` int(11) NOT NULL DEFAULT 1, + `profile_type_id` int(11) NOT NULL DEFAULT '1', PRIMARY KEY (`profile_id`), KEY `profile_person_id_idx` (`person_id`), KEY `profile_profile_type_id_idx` (`profile_type_id`), @@ -19268,7 +17385,7 @@ CREATE TABLE `profile_address` ( PRIMARY KEY (`profile_address_id`), KEY `profile_address_address_id_idx` (`address_id`), KEY `profile_address_profile_id_idx` (`profile_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19319,7 +17436,7 @@ CREATE TABLE `province` ( UNIQUE KEY `province_name_key` (`name`), KEY `province_nation_id_idx` (`nation_id`), CONSTRAINT `fk_province_nation1` FOREIGN KEY (`nation_id`) REFERENCES `nation__` (`nation_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19337,19 +17454,19 @@ CREATE TABLE `townKk` ( PRIMARY KEY (`town_id`), KEY `town_province_id_idx` (`province_id`), CONSTRAINT `townKk_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `workcenter` +-- Table structure for table `workcenter__` -- -DROP TABLE IF EXISTS `workcenter`; +DROP TABLE IF EXISTS `workcenter__`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `workcenter` ( +CREATE TABLE `workcenter__` ( `workcenter_id` int(11) NOT NULL AUTO_INCREMENT, - `name` longtext DEFAULT NULL, + `name` longtext, `center_id` int(11) DEFAULT NULL, `counter` bigint(20) DEFAULT NULL, `warehouseFk` smallint(6) DEFAULT NULL, @@ -19386,7 +17503,7 @@ DROP TABLE IF EXISTS `workers20190711_FichadasAbril`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `workers20190711_FichadasAbril` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `person_id` int(11) NOT NULL DEFAULT 0, + `person_id` int(11) NOT NULL DEFAULT '0', `nif` varchar(15) CHARACTER SET utf8 DEFAULT NULL, `Apellidos` varchar(60) CHARACTER SET utf8 NOT NULL, `Nombre` varchar(20) CHARACTER SET utf8 DEFAULT NULL, @@ -19394,7 +17511,7 @@ CREATE TABLE `workers20190711_FichadasAbril` ( `Hora` int(2) DEFAULT NULL, `Minuto` int(2) DEFAULT NULL, `sumable` double DEFAULT NULL, - `jornada` decimal(5,2) NOT NULL DEFAULT 8.00, + `jornada` decimal(5,2) NOT NULL DEFAULT '8.00', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -19459,16 +17576,16 @@ DROP TABLE IF EXISTS `Naciones`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Naciones` ( `countryFk` mediumint(8) NOT NULL, - `CodigoNacion` smallint(6) NOT NULL DEFAULT 108, - `CodigoNacion347` smallint(6) NOT NULL DEFAULT 108, + `CodigoNacion` smallint(6) NOT NULL DEFAULT '108', + `CodigoNacion347` smallint(6) NOT NULL DEFAULT '108', `Nacion` varchar(25) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `SiglaNacion` varchar(2) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'ES', `TipoCodigo` varchar(1) CHARACTER SET utf8 NOT NULL DEFAULT 'A', - `Longitud1` tinyint(4) NOT NULL DEFAULT 0, - `Longitud2` tinyint(4) NOT NULL DEFAULT 0, - `Longitud3` tinyint(4) NOT NULL DEFAULT 0, - `Longitud4` tinyint(4) NOT NULL DEFAULT 0, - `NacionCEE` smallint(6) NOT NULL DEFAULT 0, + `Longitud1` tinyint(4) NOT NULL DEFAULT '0', + `Longitud2` tinyint(4) NOT NULL DEFAULT '0', + `Longitud3` tinyint(4) NOT NULL DEFAULT '0', + `Longitud4` tinyint(4) NOT NULL DEFAULT '0', + `NacionCEE` smallint(6) NOT NULL DEFAULT '0', `FechaCEE` datetime DEFAULT NULL, `NacionISO` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT '', PRIMARY KEY (`countryFk`,`CodigoNacion`) @@ -19487,7 +17604,7 @@ CREATE TABLE `Provincias` ( `CodigoProvincia` varchar(5) NOT NULL DEFAULT '', `CodigoMatricula` varchar(2) NOT NULL DEFAULT '', `Provincia` varchar(20) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `RecargoProvincial` decimal(28,10) NOT NULL DEFAULT 0.0000000000, + `RecargoProvincial` decimal(28,10) NOT NULL DEFAULT '0.0000000000', PRIMARY KEY (`CodigoProvincia`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; @@ -19500,12 +17617,12 @@ DROP TABLE IF EXISTS `TiposIva`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `TiposIva` ( - `CodigoIva` smallint(6) NOT NULL DEFAULT 0, - `CodigoTerritorio` smallint(6) NOT NULL DEFAULT 0, + `CodigoIva` smallint(6) NOT NULL DEFAULT '0', + `CodigoTerritorio` smallint(6) NOT NULL DEFAULT '0', `Iva` varchar(30) NOT NULL DEFAULT '', - `BaseCorrectora` decimal(28,10) NOT NULL DEFAULT 0.0000000000, - `PorcentajeIva` decimal(28,10) NOT NULL DEFAULT 0.0000000000, - `RecargoEquivalencia` decimal(28,10) NOT NULL DEFAULT 0.0000000000, + `BaseCorrectora` decimal(28,10) NOT NULL DEFAULT '0.0000000000', + `PorcentajeIva` decimal(28,10) NOT NULL DEFAULT '0.0000000000', + `RecargoEquivalencia` decimal(28,10) NOT NULL DEFAULT '0.0000000000', `CuentaIvaSoportado` varchar(15) NOT NULL DEFAULT '', `CuentaIvaRepercutido` varchar(15) NOT NULL DEFAULT '', `CuentaRecargo` varchar(15) NOT NULL DEFAULT '', @@ -19524,8 +17641,8 @@ CREATE TABLE `TiposIva` ( `CuentaIVARecCaja` varchar(15) NOT NULL DEFAULT '', `CuentaIVARecCajaPu` varchar(15) NOT NULL DEFAULT '', `CuentaIVARecCajaVen` varchar(15) NOT NULL DEFAULT '', - `IGICImplicito` smallint(6) NOT NULL DEFAULT 0, - `isIntracommunity` tinyint(2) NOT NULL DEFAULT 0, + `IGICImplicito` smallint(6) NOT NULL DEFAULT '0', + `isIntracommunity` tinyint(2) NOT NULL DEFAULT '0', PRIMARY KEY (`CodigoIva`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; @@ -19538,9 +17655,9 @@ DROP TABLE IF EXISTS `TiposRetencion`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `TiposRetencion` ( - `CodigoRetencion` smallint(6) NOT NULL DEFAULT 0, + `CodigoRetencion` smallint(6) NOT NULL DEFAULT '0', `Retencion` varchar(50) NOT NULL DEFAULT '', - `PorcentajeRetencion` decimal(28,10) NOT NULL DEFAULT 0.0000000000, + `PorcentajeRetencion` decimal(28,10) NOT NULL DEFAULT '0.0000000000', `CuentaCargo` varchar(15) DEFAULT NULL, `CuentaAbono` varchar(15) DEFAULT NULL, `ClaveIrpf` varchar(2) DEFAULT NULL, @@ -19559,10 +17676,10 @@ DROP TABLE IF EXISTS `TiposTransacciones`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `TiposTransacciones` ( - `CodigoTransaccion` tinyint(4) NOT NULL DEFAULT 0, + `CodigoTransaccion` tinyint(4) NOT NULL DEFAULT '0', `Transaccion` varchar(50) NOT NULL DEFAULT '', `TipoFactura` varchar(1) NOT NULL DEFAULT '', - `Autofactura` smallint(6) NOT NULL DEFAULT 0, + `Autofactura` smallint(6) NOT NULL DEFAULT '0', `ClaveOperacionDefecto` varchar(1) NOT NULL DEFAULT '', PRIMARY KEY (`CodigoTransaccion`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -19618,31 +17735,31 @@ CREATE TABLE `clientesProveedores` ( `ColaMunicipio` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `CodigoProvincia` varchar(5) COLLATE utf8_unicode_ci NOT NULL, `Provincia` varchar(20) COLLATE utf8_unicode_ci NOT NULL, - `CodigoNacion` smallint(6) NOT NULL DEFAULT 0, + `CodigoNacion` smallint(6) NOT NULL DEFAULT '0', `Nacion` varchar(25) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `Telefono` varchar(15) COLLATE utf8_unicode_ci NOT NULL, `Telefono2` varchar(15) COLLATE utf8_unicode_ci NOT NULL, `Telefono3` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `Fax` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `CodigoTransaccion` tinyint(4) NOT NULL DEFAULT 0, + `CodigoTransaccion` tinyint(4) NOT NULL DEFAULT '0', `CodigoRetencion` smallint(6) NOT NULL, - `Deducible` smallint(6) NOT NULL DEFAULT 0, - `CodigoIva` smallint(6) NOT NULL DEFAULT 0, - `Mediacion` smallint(6) NOT NULL DEFAULT 0, - `Exclusion347` smallint(6) NOT NULL DEFAULT 0, - `NumeroPlazos` tinyint(4) NOT NULL DEFAULT 1, - `DiasPrimerPlazo` smallint(6) NOT NULL DEFAULT 0, - `DiasEntrePlazos` smallint(6) NOT NULL DEFAULT 0, - `DiasFijos1` tinyint(4) NOT NULL DEFAULT 0, - `DiasFijos2` tinyint(4) NOT NULL DEFAULT 0, - `DiasFijos3` tinyint(4) NOT NULL DEFAULT 0, - `InicioNoPago` smallint(6) NOT NULL DEFAULT 0, - `FinNoPago` smallint(6) NOT NULL DEFAULT 0, - `ControlarFestivos` smallint(6) NOT NULL DEFAULT 0, - `DiasRetroceso` tinyint(4) NOT NULL DEFAULT 0, - `MesesComerciales` smallint(6) NOT NULL DEFAULT 0, + `Deducible` smallint(6) NOT NULL DEFAULT '0', + `CodigoIva` smallint(6) NOT NULL DEFAULT '0', + `Mediacion` smallint(6) NOT NULL DEFAULT '0', + `Exclusion347` smallint(6) NOT NULL DEFAULT '0', + `NumeroPlazos` tinyint(4) NOT NULL DEFAULT '1', + `DiasPrimerPlazo` smallint(6) NOT NULL DEFAULT '0', + `DiasEntrePlazos` smallint(6) NOT NULL DEFAULT '0', + `DiasFijos1` tinyint(4) NOT NULL DEFAULT '0', + `DiasFijos2` tinyint(4) NOT NULL DEFAULT '0', + `DiasFijos3` tinyint(4) NOT NULL DEFAULT '0', + `InicioNoPago` smallint(6) NOT NULL DEFAULT '0', + `FinNoPago` smallint(6) NOT NULL DEFAULT '0', + `ControlarFestivos` smallint(6) NOT NULL DEFAULT '0', + `DiasRetroceso` tinyint(4) NOT NULL DEFAULT '0', + `MesesComerciales` smallint(6) NOT NULL DEFAULT '0', `RemesaHabitual` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `CodigoTipoEfecto` smallint(6) NOT NULL DEFAULT 0, + `CodigoTipoEfecto` smallint(6) NOT NULL DEFAULT '0', `Email1` varchar(250) COLLATE utf8_unicode_ci NOT NULL, `Email2` varchar(250) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `CodigoCategoriaCliente_` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'CLI', @@ -19655,25 +17772,25 @@ CREATE TABLE `clientesProveedores` ( `DC` varchar(2) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `CCC` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `IBAN` varchar(34) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `CodigoCondiciones` smallint(6) NOT NULL DEFAULT 0, - `StatusTraspasadoIME` tinyint(4) NOT NULL DEFAULT 0, - `TipoImportacionIME` tinyint(4) NOT NULL DEFAULT 2, - `TipoPlanCuentaIME` smallint(6) NOT NULL DEFAULT 2, + `CodigoCondiciones` smallint(6) NOT NULL DEFAULT '0', + `StatusTraspasadoIME` tinyint(4) NOT NULL DEFAULT '0', + `TipoImportacionIME` tinyint(4) NOT NULL DEFAULT '2', + `TipoPlanCuentaIME` smallint(6) NOT NULL DEFAULT '2', `Contrapartida` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `CodigoCuentaImpagado` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `CodigoCuentaEfecto` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `Comentarios` text COLLATE utf8_unicode_ci NOT NULL, - `CodigoTerritorio` smallint(6) NOT NULL DEFAULT 0, + `CodigoTerritorio` smallint(6) NOT NULL DEFAULT '0', `CodigoIdioma_` varchar(3) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `TarifaPrecio` smallint(6) NOT NULL DEFAULT 0, - `%Descuento` decimal(28,10) NOT NULL DEFAULT 0.0000000000, - `%Rappel` decimal(28,10) NOT NULL DEFAULT 0.0000000000, - `%ProntoPago` decimal(28,10) NOT NULL DEFAULT 0.0000000000, - `%Financiacion` decimal(28,10) NOT NULL DEFAULT 0.0000000000, - `CodigoComisionista` int(11) NOT NULL DEFAULT 0, - `TarifaDescuento` smallint(6) NOT NULL DEFAULT 0, + `TarifaPrecio` smallint(6) NOT NULL DEFAULT '0', + `%Descuento` decimal(28,10) NOT NULL DEFAULT '0.0000000000', + `%Rappel` decimal(28,10) NOT NULL DEFAULT '0.0000000000', + `%ProntoPago` decimal(28,10) NOT NULL DEFAULT '0.0000000000', + `%Financiacion` decimal(28,10) NOT NULL DEFAULT '0.0000000000', + `CodigoComisionista` int(11) NOT NULL DEFAULT '0', + `TarifaDescuento` smallint(6) NOT NULL DEFAULT '0', `SiglaNacion` varchar(2) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `MarcaMenorSinNif` smallint(6) NOT NULL DEFAULT 0, + `MarcaMenorSinNif` smallint(6) NOT NULL DEFAULT '0', `PersonaFisicaJuridica` varchar(1) COLLATE utf8_unicode_ci NOT NULL, `SiglaNacionRepresentante` varchar(2) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `CifDniRepresentante` varchar(13) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', @@ -19681,12 +17798,12 @@ CREATE TABLE `clientesProveedores` ( `TipoDocumentoPersona` smallint(6) NOT NULL, `TipoCif` varchar(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `MotivoBajaClienteLc` varchar(30) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `PuntosSR` decimal(28,10) NOT NULL DEFAULT 0.0000000000, + `PuntosSR` decimal(28,10) NOT NULL DEFAULT '0.0000000000', `TarjetaSR` varchar(100) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `FechaNacimiento` datetime DEFAULT NULL, `Domicilio2` varchar(40) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `CuentaProvision` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `CodigoTransportista` int(11) NOT NULL DEFAULT 0, + `CodigoTransportista` int(11) NOT NULL DEFAULT '0', `FormadePago` varchar(35) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `ObservacionesCliente` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `CodigoTipoClienteLc` varchar(3) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', @@ -19698,14 +17815,14 @@ CREATE TABLE `clientesProveedores` ( `NombreEmpleado` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `PrimerApellidoEmpleado` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `SegundoApellidoEmpleado` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `sysTick` int(11) NOT NULL DEFAULT 0, - `RiesgoMaximo` decimal(28,10) NOT NULL DEFAULT 0.0000000000, - `PlazoMedioPCMA` smallint(6) NOT NULL DEFAULT 0, - `CriterioIvaIME` smallint(6) NOT NULL DEFAULT 0, + `sysTick` int(11) NOT NULL DEFAULT '0', + `RiesgoMaximo` decimal(28,10) NOT NULL DEFAULT '0.0000000000', + `PlazoMedioPCMA` smallint(6) NOT NULL DEFAULT '0', + `CriterioIvaIME` smallint(6) NOT NULL DEFAULT '0', `ReferenciaMandato` varchar(35) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `%Comision` decimal(28,10) NOT NULL DEFAULT 0.0000000000, - `CodigoZona` int(11) NOT NULL DEFAULT 0, - `BloqueoAlbaran` smallint(6) NOT NULL DEFAULT 0, + `%Comision` decimal(28,10) NOT NULL DEFAULT '0.0000000000', + `CodigoZona` int(11) NOT NULL DEFAULT '0', + `BloqueoAlbaran` smallint(6) NOT NULL DEFAULT '0', `CodigoSeccion` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `CodigoSector_` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `CodigoProyecto` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', @@ -19765,7 +17882,7 @@ CREATE TABLE `movContaIVA` ( `CuotaIva1` double DEFAULT NULL, `PorRecargoEquivalencia1` double DEFAULT NULL, `RecargoEquivalencia1` double DEFAULT NULL, - `CodigoTransaccion1` double NOT NULL DEFAULT 0, + `CodigoTransaccion1` double NOT NULL DEFAULT '0', `CodigoIva1` smallint(6) NOT NULL, `BaseIva2` double DEFAULT NULL, `PorBaseCorrectora2` double DEFAULT NULL, @@ -19773,7 +17890,7 @@ CREATE TABLE `movContaIVA` ( `CuotaIva2` double DEFAULT NULL, `PorRecargoEquivalencia2` double DEFAULT NULL, `RecargoEquivalencia2` double DEFAULT NULL, - `CodigoTransaccion2` double NOT NULL DEFAULT 0, + `CodigoTransaccion2` double NOT NULL DEFAULT '0', `CodigoIva2` smallint(6) NOT NULL, `BaseIva3` double DEFAULT NULL, `PorBaseCorrectora3` double DEFAULT NULL, @@ -19781,7 +17898,7 @@ CREATE TABLE `movContaIVA` ( `CuotaIva3` double DEFAULT NULL, `PorRecargoEquivalencia3` double DEFAULT NULL, `RecargoEquivalencia3` double DEFAULT NULL, - `CodigoTransaccion3` double NOT NULL DEFAULT 0, + `CodigoTransaccion3` double NOT NULL DEFAULT '0', `CodigoIva3` smallint(6) NOT NULL, `BaseIva4` double DEFAULT NULL, `PorBaseCorrectora4` double DEFAULT NULL, @@ -19789,7 +17906,7 @@ CREATE TABLE `movContaIVA` ( `CuotaIva4` double DEFAULT NULL, `PorRecargoEquivalencia4` double DEFAULT NULL, `RecargoEquivalencia4` double DEFAULT NULL, - `CodigoTransaccion4` double NOT NULL DEFAULT 0, + `CodigoTransaccion4` double NOT NULL DEFAULT '0', `CodigoIva4` smallint(6) NOT NULL, `Año` int(11) DEFAULT NULL, `Serie` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, @@ -19809,7 +17926,7 @@ CREATE TABLE `movContaIVA` ( `EjercicioFactura` int(2) DEFAULT NULL, `FechaOperacion` date DEFAULT NULL, `Exclusion347` int(2) DEFAULT NULL, - `MantenerAsiento` int(2) DEFAULT -1, + `MantenerAsiento` int(2) DEFAULT '-1', `Metalico347` int(2) DEFAULT NULL, `ClaveOperacionFactura` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `TipoRectificativa` int(2) DEFAULT NULL, @@ -19819,13 +17936,13 @@ CREATE TABLE `movContaIVA` ( `ClaseAbonoRectificativas` int(2) DEFAULT NULL, `RecargoEquivalenciaOriginal` double DEFAULT NULL, `LibreA1` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, - `IvaDeducible1` int(2) NOT NULL DEFAULT -1, - `IvaDeducible2` int(2) NOT NULL DEFAULT -1, - `IvaDeducible3` int(2) NOT NULL DEFAULT -1, - `IvaDeducible4` int(2) NOT NULL DEFAULT -1, + `IvaDeducible1` int(2) NOT NULL DEFAULT '-1', + `IvaDeducible2` int(2) NOT NULL DEFAULT '-1', + `IvaDeducible3` int(2) NOT NULL DEFAULT '-1', + `IvaDeducible4` int(2) NOT NULL DEFAULT '-1', `FechaGrabacion` date DEFAULT NULL, - `Intracomunitaria` tinyint(1) DEFAULT 0, - `moveData` tinyint(1) DEFAULT 1, + `Intracomunitaria` tinyint(1) DEFAULT '0', + `moveData` tinyint(1) DEFAULT '1', PRIMARY KEY (`id`), CONSTRAINT `movContaIVA_fk1` FOREIGN KEY (`id`) REFERENCES `vn`.`XDiario` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Informa del valor de los campos de IVA para enlazar en la tabla vn.movConta'; @@ -19845,7 +17962,7 @@ CREATE TABLE `pgcToSage` ( `accountTaxInput` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, `accountTaxOutput` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Tabla relaciona cuentas pgc con Código de IVA y Código de Transacción en Sage'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COMMENT='Tabla relaciona cuentas pgc con Código de IVA y Código de Transacción en Sage'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -19861,16 +17978,16 @@ CREATE TABLE `planCuentasPGC` ( `Cuenta` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `ClienteOProveedor` varchar(1) COLLATE utf8_unicode_ci NOT NULL, `CodigoDivisa` varchar(3) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `IndicadorProrrata` smallint(6) NOT NULL DEFAULT 0, - `TipoPlanCuentaIME` smallint(6) NOT NULL DEFAULT 2, - `StatusAnalitica` smallint(6) NOT NULL DEFAULT 0, + `IndicadorProrrata` smallint(6) NOT NULL DEFAULT '0', + `TipoPlanCuentaIME` smallint(6) NOT NULL DEFAULT '2', + `StatusAnalitica` smallint(6) NOT NULL DEFAULT '0', `AnaCodigoCuenta` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `StatusTraspasadoIME` tinyint(4) NOT NULL DEFAULT 0, - `TipoImportacionIME` tinyint(4) NOT NULL DEFAULT 0, - `CierrePatrimonio_` smallint(6) NOT NULL DEFAULT 0, + `StatusTraspasadoIME` tinyint(4) NOT NULL DEFAULT '0', + `TipoImportacionIME` tinyint(4) NOT NULL DEFAULT '0', + `CierrePatrimonio_` smallint(6) NOT NULL DEFAULT '0', `CuentaPatrimonio_` varchar(15) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', - `CuentaVarios` smallint(6) NOT NULL DEFAULT 0, - `TodasLasActividades` smallint(6) NOT NULL DEFAULT 0, + `CuentaVarios` smallint(6) NOT NULL DEFAULT '0', + `TodasLasActividades` smallint(6) NOT NULL DEFAULT '0', `ValorDelegacion` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `ValorDepartamento` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', `ValorProyecto` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', @@ -19902,15 +18019,15 @@ SET character_set_client = @saved_cs_client; -- -- Dumping routines for database 'sage' -- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `accountingMovements_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' */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `accountingMovements_add`(vYear INT, vCompanyFk INT) BEGIN @@ -20163,6 +18280,7 @@ BEGIN FROM vn.XDiario WHERE enlazadoSage = FALSE ORDER BY ASIEN, FECREGCON DESC, FECHA_EX DESC + LIMIT 10000000000000000000 ) sub GROUP BY ASIEN )sub2 ON sub2.ASIEN = x.ASIEN LEFT JOIN ( SELECT DISTINCT(account),cu.code @@ -20354,558 +18472,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 `accountingMovements_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`@`localhost` PROCEDURE `accountingMovements_add__`(vYear INT, vCompanyFk INT) -BEGIN -/** - * Traslada la info de contabilidad generada en base a vn.XDiario a la tabla sage.movConta para poder ejecutar posteriormente el proceso de importación de datos de SQL Server - * Solo traladará los asientos marcados con el campo vn.XDiario.enlazadoSage = FALSE - * @vYear Año contable del que se quiere trasladar la información - * @vCompanyFk Empresa de la que se quiere trasladar datos - */ - DECLARE vDatedFrom DATETIME; - DECLARE vDatedTo DATETIME; - DECLARE vDuaTransactionFk INT; - DECLARE vTaxImportFk INT; - DECLARE vTaxImportReducedFk INT; - DECLARE vTransactionExportFk INT; - DECLARE vTransactionExportTaxFreeFk INT; - DECLARE vSerialDua VARCHAR(1) DEFAULT 'D'; - DECLARE vInvoiceTypeInformativeCode VARCHAR(1); - DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2) ; - DECLARE vBookEntries TEXT; - - SELECT SiglaNacion INTO vCountryCanariasCode - FROM Naciones - WHERE Nacion ='ISLAS CANARIAS'; - - SELECT SiglaNacion INTO vCountryCeutaMelillaCode - FROM Naciones - WHERE Nacion ='CEUTA Y MELILLA'; - - SELECT CodigoTransaccion INTO vDuaTransactionFk - FROM TiposTransacciones - WHERE Transaccion = 'Import. bienes y serv. corrientes pdte. liquidar'; - - SELECT CodigoIva INTO vTaxImportFk - FROM TiposIva - WHERE Iva = 'IVA 21% importaciones'; - - SELECT CodigoIva INTO vTaxImportReducedFk - FROM TiposIva - WHERE Iva = 'IVA 10% importaciones'; - - SELECT CodigoTransaccion INTO vTransactionExportFk - FROM TiposTransacciones - WHERE Transaccion = 'Exportaciones definitivas'; - - SELECT CodigoTransaccion INTO vTransactionExportTaxFreeFk - FROM TiposTransacciones - WHERE Transaccion = 'Envíos definitivos a Canarias, Ceuta y Melilla'; - - SELECT codeSage INTO vInvoiceTypeInformativeCode - FROM invoiceType WHERE code ='informative'; - - SELECT CAST(CONCAT(vYear, '-01-01') AS DATETIME), util.dayEnd(CAST(CONCAT(vYear, '-12-31') AS DATE)) - INTO vDatedFrom, vDatedTo; - - TRUNCATE movContaIVA; - - DELETE FROM movConta - WHERE enlazadoSage = FALSE - AND Asiento <> 1 ; - - CALL clientSupplier_add(vCompanyFk); - CALL pgc_add(vCompanyFk); - CALL invoiceOut_manager(vYear, vCompanyFk); - CALL invoiceIn_manager(vYear, vCompanyFk); - - INSERT INTO movConta(TipoEntrada, - Ejercicio, - CodigoEmpresa, - Asiento, - CargoAbono, - CodigoCuenta, - Contrapartida, - FechaAsiento, - Comentario, - ImporteAsiento, - NumeroPeriodo, - FechaGrabacion, - CodigoDivisa, - ImporteCambio, - ImporteDivisa, - FactorCambio, - IdProcesoIME, - TipoCarteraIME, - TipoAnaliticaIME, - StatusTraspasadoIME, - TipoImportacionIME, - Metalico347, - BaseIva1, - PorBaseCorrectora1, - PorIva1, - CuotaIva1, - PorRecargoEquivalencia1, - RecargoEquivalencia1, - CodigoTransaccion1, - BaseIva2, - PorBaseCorrectora2, - PorIva2, - CuotaIva2, - PorRecargoEquivalencia2, - RecargoEquivalencia2, - CodigoTransaccion2, - BaseIva3, - PorBaseCorrectora3, - PorIva3, - CuotaIva3, - PorRecargoEquivalencia3, - RecargoEquivalencia3, - CodigoTransaccion3, - BaseIva4, - PorBaseCorrectora4, - PorIva4, - CuotaIva4, - PorRecargoEquivalencia4, - RecargoEquivalencia4, - CodigoTransaccion4, - Año, - Serie, - Factura, - SuFacturaNo, - FechaFactura, - ImporteFactura, - TipoFactura, - CodigoCuentaFactura, - CifDni, - Nombre, - CodigoRetencion, - BaseRetencion, - PorRetencion, - ImporteRetencion, - SiglaNacion, - EjercicioFactura, - FechaOperacion, - Exclusion347, - MantenerAsiento, - ClaveOperacionFactura_, - TipoRectificativa, - FechaFacturaOriginal, - BaseImponibleOriginal, - CuotaIvaOriginal, - ClaseAbonoRectificativas, - RecargoEquivalenciaOriginal, - LibreA1, - CodigoIva1, - CodigoIva2, - CodigoIva3, - CodigoIva4, - IvaDeducible1, - IvaDeducible2, - IvaDeducible3, - IvaDeducible4, - Intracomunitaria - ) - SELECT 'EN' TipoEntrada, - YEAR(x.FECHA) Ejercicio, - IF (@@hostname = 'db', c.companyCode, companyCodeTest) AS CodigoEmpresa, - x.ASIEN Asiento, - IF(EURODEBE <> 0 OR (EURODEBE = 0 AND EUROHABER IS NULL), 'D', 'H') CargoAbono, - x.SUBCTA CodigoCuenta, - x.CONTRA Contrapartida, - x.FECHA FechaAsiento, - x.CONCEPTO Comentario, - IF(x.EURODEBE, x.EURODEBE, x.EUROHABER) ImporteAsiento, - MONTH(x.FECHA) NumeroPeriodo, - IF(sub2.FECREGCON IS NULL, sub2.FECHA_EX, sub2.FECREGCON) FechaGrabacion, - IF(x.CAMBIO, IFNULL(mci.CodigoDivisa, sub3.code), '') CodigoDivisa, - x.CAMBIO ImporteCambio, - IFNULL(x.DEBEME, x.HABERME) ImporteDivisa, - IF(x.CAMBIO, TRUE, FALSE) FactorCambio, - NULL IdProcesoIME, - 0 TipoCarteraIME, - 0 TipoAnaliticaIME, - 0 StatusTraspasadoIME, - 0 TipoImportacionIME, - x.METAL Metalico347, - mci.BaseIva1, - mci.PorBaseCorrectora1, - mci.PorIva1, - mci.CuotaIva1, - mci.PorRecargoEquivalencia1, - mci.RecargoEquivalencia1, - mci.CodigoTransaccion1, - mci.BaseIva2, - mci.PorBaseCorrectora2, - mci.PorIva2, - mci.CuotaIva2, - mci.PorRecargoEquivalencia2, - mci.RecargoEquivalencia2, - mci.CodigoTransaccion2, - mci.BaseIva3, - mci.PorBaseCorrectora3, - mci.PorIva3, - mci.CuotaIva3, - mci.PorRecargoEquivalencia3, - mci.RecargoEquivalencia3, - mci.CodigoTransaccion3, - mci.BaseIva4, - mci.PorBaseCorrectora4, - mci.PorIva4, - mci.CuotaIva4, - mci.PorRecargoEquivalencia4, - mci.RecargoEquivalencia4, - mci.CodigoTransaccion4, - mci.Año, - mci.Serie, - mci.Factura, - mci.SuFacturaNo, - mci.FechaFactura, - mci.ImporteFactura, - mci.TipoFactura, - mci.CodigoCuentaFactura, - mci.CifDni, - mci.Nombre, - mci.CodigoRetencion, - mci.BaseRetencion, - mci.PorRetencion, - mci.ImporteRetencion, - mci.SiglaNacion, - mci.EjercicioFactura, - mci.FechaOperacion, - mci.Exclusion347, - TRUE, - mci.ClaveOperacionFactura, - mci.TipoRectificativa, - mci.FechaFacturaOriginal, - mci.BaseImponibleOriginal, - mci.CuotaIvaOriginal, - mci.ClaseAbonoRectificativas, - mci.RecargoEquivalenciaOriginal, - mci.LibreA1, - mci.CodigoIva1, - mci.CodigoIva2, - mci.CodigoIva3, - mci.CodigoIva4, - mci.IvaDeducible1, - mci.IvaDeducible2, - mci.IvaDeducible3, - mci.IvaDeducible4, - mci.Intracomunitaria - FROM vn.XDiario x - JOIN vn.company c ON c.id = x.empresa_id - LEFT JOIN movContaIVA mci ON mci.id = x.id - LEFT JOIN (SELECT * - FROM (SELECT DISTINCT ASIEN, FECREGCON, FECHA_EX - FROM vn.XDiario - WHERE enlazadoSage = FALSE - ORDER BY ASIEN, FECREGCON DESC, FECHA_EX DESC - ) sub GROUP BY ASIEN - )sub2 ON sub2.ASIEN = x.ASIEN - LEFT JOIN ( SELECT DISTINCT(account),cu.code - FROM vn.bank b - JOIN vn.currency cu ON cu.id = b.currencyFk - WHERE cu.code <> 'EUR' -- no se informa cuando la divisa en EUR - )sub3 ON sub3.account = x.SUBCTA - WHERE x.enlazadoSage = FALSE - AND x.empresa_id = vCompanyFk - AND x.FECHA BETWEEN vDatedFrom AND vDatedTo; - --- Metálicos - UPDATE movConta m - JOIN (SELECT Asiento, - c.socialName name, - c.fi, - n.SiglaNacion, - m.CodigoCuenta, - m.Contrapartida - FROM movConta m - LEFT JOIN vn.client c ON c.id = IF(m.CargoAbono = 'H', - CAST(SUBSTRING(m.CodigoCuenta, 3, LENGTH(m.CodigoCuenta)) AS UNSIGNED), - CAST(SUBSTRING(m.Contrapartida, 3, LENGTH(m.Contrapartida)) AS UNSIGNED)) - LEFT JOIN Naciones n ON n.countryFk = c.countryFk - WHERE m.Metalico347 = TRUE - AND m.enlazadoSage = FALSE - )sub ON m.Asiento = sub.Asiento - SET m.Metalico347 = TRUE, - m.TipoFactura = vInvoiceTypeInformativeCode, - m.CifDni = sub.fi, - m.Nombre = sub.name, - m.SiglaNacion = sub.SiglaNacion - WHERE m.enlazadoSage = FALSE; - - UPDATE movConta m - SET m.Metalico347 = FALSE, - m.TipoFactura = '' - WHERE m.CargoAbono = 'D' - AND m.enlazadoSage = FALSE; - --- Elimina cuentas de cliente/proveedor que no se utilizarán en la importación - DELETE cp - FROM clientesProveedores cp - LEFT JOIN movConta mc ON mc.codigoCuenta = cp.codigoCuenta - AND mc.enlazadoSage = FALSE - WHERE mc.codigoCuenta IS NULL; - --- Elimina cuentas contables que no se utilizarán en la importación - DELETE pc - FROM planCuentasPGC pc - LEFT JOIN movConta mc ON mc.codigoCuenta = pc.codigoCuenta - AND mc.enlazadoSage = FALSE - WHERE mc.codigoCuenta IS NULL; - --- DUAS - UPDATE movConta mci - JOIN vn.XDiario x ON x.ASIEN = mci.Asiento - JOIN TiposIva ti ON ti.CodigoIva = x.IVA - JOIN vn.pgcMaster pm ON pm.code = mci.CodigoCuenta COLLATE utf8_general_ci - SET mci.BaseIva1 = x.BASEEURO, - mci.PorIva1 = x.IVA, - mci.CuotaIva1 = CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)), - mci.CodigoTransaccion1 = vDuaTransactionFk, - mci.CodigoIva1 = vTaxImportReducedFk, - mci.IvaDeducible1 = TRUE, - mci.FechaFacturaOriginal = x.FECHA_EX, - mci.SuFacturaNo = x.FACTURAEX, - mci.FechaOperacion = x.FECHA_OP, - mci.ImporteFactura = mci.ImporteFactura + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) - WHERE pm.description = 'HP Iva pendiente' - AND mci.enlazadoSage = FALSE - AND x.SERIE = vSerialDua COLLATE utf8_general_ci - AND ti.Iva = 'I.V.A. 10% Nacional'; - - UPDATE movConta mci - JOIN vn.XDiario x ON x.ASIEN = mci.Asiento - JOIN TiposIva ti ON ti.CodigoIva = x.IVA - JOIN vn.pgcMaster pm ON pm.code = mci.CodigoCuenta COLLATE utf8_general_ci - SET mci.BaseIva2 = x.BASEEURO , - mci.PorIva2 = x.IVA, - mci.CuotaIva2 = CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10,2)), - mci.CodigoTransaccion2 = vDuaTransactionFk , - mci.CodigoIva2 = vTaxImportFk, - mci.IvaDeducible2 = TRUE, - mci.ImporteFactura = mci.ImporteFactura + x.BASEEURO + CAST((x.IVA / 100) * x.BASEEURO AS DECIMAL(10, 2)) - WHERE pm.description = 'HP Iva pendiente' - AND mci.enlazadoSage = FALSE - AND x.SERIE = vSerialDua COLLATE utf8_general_ci - AND ti.Iva = 'I.V.A. 21%'; - --- Rectificativas - UPDATE movConta mci - JOIN (SELECT x.ASIEN, x.FECHA_RT, x.SERIE_RT, x.FACTU_RT - FROM movConta mci - JOIN vn.XDiario x ON x.ASIEN = mci.Asiento - WHERE mci.TipoRectificativa > 0 - AND mci.enlazadoSage = FALSE - AND x.FACTU_RT IS NOT NULL - GROUP BY x.ASIEN - ) sub ON sub.ASIEN = mci.Asiento - SET mci.EjercicioFacturaOriginal = YEAR(sub.FECHA_RT), - mci.SerieFacturaOriginal = sub.SERIE_RT, - mci.NumeroFacturaOriginal = sub.FACTU_RT - WHERE mci.TipoRectificativa > 0 AND - mci.enlazadoSage = FALSE ; - --- Exportaciones Andorras y Canarias cambia TT (la cuenta es compartida) - UPDATE movConta mci - SET CodigoTransaccion1 = vTransactionExportTaxFreeFk, - CodigoTransaccion2 = IF(CodigoTransaccion2 = 0, 0, vTransactionExportTaxFreeFk), - CodigoTransaccion3 = IF(CodigoTransaccion3 = 0, 0, vTransactionExportTaxFreeFk), - CodigoTransaccion4 = IF(CodigoTransaccion4 = 0, 0, vTransactionExportTaxFreeFk) - WHERE enlazadoSage = FALSE - AND (CodigoTransaccion1 = vTransactionExportFk - OR CodigoTransaccion2 = vTransactionExportFk - OR CodigoTransaccion3 = vTransactionExportFk - OR CodigoTransaccion4 = vTransactionExportFk) - AND SiglaNacion IN (vCountryCanariasCode COLLATE utf8_general_ci, vCountryCeutaMelillaCode COLLATE utf8_general_ci); - - UPDATE movConta mc - SET CodigoDivisa = 'USD', - FactorCambio = TRUE, - ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio = 0, ImporteAsiento / ImporteDivisa, ImporteCambio) AS DECIMAL( 10, 2))) - WHERE enlazadoSage = FALSE - AND (ImporteCambio <> 0 OR ImporteDivisa <> 0 OR FactorCambio); - - UPDATE movConta mc - SET importeDivisa= -importeDivisa - WHERE enlazadoSage = FALSE - AND importeDivisa > 0 - AND ImporteAsiento < 0; - - -- Comprobación que los importes e ivas sean correctos, avisa vía CAU - SELECT GROUP_CONCAT(Asiento ORDER BY Asiento ASC SEPARATOR ' \n\r') INTO vBookEntries - FROM(SELECT sub.Asiento - FROM (SELECT mc.Asiento, SUM(mc.ImporteAsiento) amount - FROM movConta mc - WHERE mc.enlazadoSage = FALSE - GROUP BY mc.Asiento)sub - JOIN (SELECT x.ASIEN, SUM(IFNULL(x.EURODEBE,0) + IFNULL(x.EUROHABER,0)) amount - FROM vn.XDiario x - WHERE x.enlazadoSage = FALSE - GROUP BY ASIEN)sub2 ON sub2.ASIEN = sub.Asiento - WHERE sub.amount <> sub2.amount - UNION ALL - SELECT sub.Asiento - FROM (SELECT Asiento, SUM(BaseIva1 + BaseIva2 + BaseIva3 + BaseIva4) amountTaxableBase - FROM movConta - WHERE TipoFactura <> 'I' - AND enlazadoSage = FALSE - GROUP BY Asiento) sub - JOIN (SELECT ASIEN, SUM(BASEEURO) amountTaxableBase - FROM (SELECT ASIEN, SUM(BASEEURO) BASEEURO - FROM vn.XDiario - WHERE FACTURA - AND auxiliar <> '*' - AND enlazadoSage = FALSE - GROUP BY FACTURA, ASIEN)sub3 - GROUP BY ASIEN) sub2 ON sub2.ASIEN = sub.Asiento - WHERE sub.amountTaxableBase<>sub2.amountTaxableBase - AND sub.amountTaxableBase/2 <> sub2.amountTaxableBase) sub; - - IF vBookEntries IS NOT NULL THEN - CALL vn.mail_insert('cau@verdnatura.es, administracion@verdnatura.es', - 'noreply@verdnatura.es', - CONCAT('Asientos contables importados incorrectamente'), - CONCAT('

Existen asientos que difieren entre la info. de XDiario y la que se ha importado a Sage.

- Asientos nº ', vBookEntries, '
')); - 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 `clientesProveedoresAdd__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `clientesProveedoresAdd__`() -BEGIN -TRUNCATE TABLE clientesProveedores; - INSERT INTO clientesProveedores - (CodigoEmpresa, - ClienteOProveedor, - CodigoClienteProveedor, - RazonSocial, - Nombre, - Domicilio, - CodigoCuenta, - CifDni, - CifEuropeo, - CodigoPostal, - Municipio, - CodigoProvincia, - Provincia, - CodigoNacion, - SiglaNacion, - PersonaFisicaJuridica, - TipoDocumentoPersona, - CodigoIva, - Nacion, - Telefono, - Telefono2, - CodigoTransaccion, - CodigoRetencion, - Email1, - iban) - SELECT IF (@@hostname = 'db', c.companyCode, companyCodeTest) CodigoEmpresa, - 'C' ClienteOProveedor, - cl.id CodigoClienteProveedor, - cl.socialName RazonSocial, - cl.name Nombre, - cl.street Domicilio, - cl.accountingAccount CodigoCuenta, - TRIM(IF(co.code = LEFT(cl.fi,2), MID(cl.fi,3, length(cl.fi)-1), cl.fi)) AS CifDni, - IF(sn.NacionCEE,TRIM(CONCAT(co.code, IF(co.code = LEFT(cl.fi,2), MID(cl.fi,3, length(cl.fi)-1), cl.fi))) , "")AS CifEuropeo, - cl.postcode CodigoPostal, - cl.city Municipio, - sp.CodigoProvincia CodigoProvincia, - p.name Provincia, - 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), 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, - cl.phone Telefono, - cl.mobile Telefono2, - cl.transactionTypeSageFk CodigoTransaccion, - 0 CodigoRetencion, - SUBSTR(cl.email, 1, LOCATE(',', CONCAT(cl.email,','))-1) Email1, - cl.iban iban - FROM vn.client cl - JOIN vn2008.v_xsubclien ON v_xsubclien.Id_Cliente = cl.id - LEFT JOIN vn.country co ON co.id = cl.countryFk - LEFT JOIN sage.Naciones sn ON sn.countryFk = co.id - LEFT JOIN vn.province p ON p.id = cl.provinceFk - LEFT JOIN sage.Provincias sp ON sp.provinceFk = p.id - JOIN vn.company c ON c.id = v_xsubclien.empresa_id - WHERE cl.isRelevant AND c.code = 'VNL' - UNION ALL - SELECT IF (@@hostname = 'db', c.companyCode, companyCodeTest) CodigoEmpresa, - 'P' ClienteOProveedor, - s.id CodigoClienteProveedor, - s.name RazonSocial, - s.name Nombre, - s.street Domicilio, - s.account CodigoCuenta, - TRIM(IF(co.code = LEFT(s.nif,2), MID(s.nif,3, length(s.nif)-1), s.nif)) CifDni, - IF(sn.NacionCEE,TRIM(CONCAT(co.code, IF(co.code = LEFT(s.nif,2), MID(s.nif,3, length(s.nif)-1), s.nif))), "") AS CifEuropeo, - s.postCode CodigoPostal, - s.city Municipio, - sp.CodigoProvincia CodigoProvincia, - p.name Provincia, - sn.CodigoNacion CodigoNacion, - sn.SiglaNacion SiglaNacion, - IF((s.nif REGEXP '^([[:blank:]]|[[:digit:]])'),'J','F') PersonaFisicaJuridica, - IF((co.id = 1 OR co.id = 30),1,IF((co.isUeeMember = 1), 2, 4)) TipoDocumentoPersona, - -- 'I' CodigoIva, - s.taxTypeSageFk CodigoIva, - sn.Nacion Nacion, - con.Telefono Telefono, - con.Movil Telefono2, - s.transactionTypeSageFk CodigoTransaccion, - s.withholdingSageFk CodigoRetencion, - SUBSTR(con.email,1,(COALESCE(NULLIF(LOCATE(',', con.email), 0), 99) - 1)) Email1, - sa.iban iban - FROM vn.supplier s - JOIN vn2008.v_xsubprov xsp ON xsp.proveedor_id = s.id -- Proveedores activos los últimos 3 meses - LEFT JOIN vn.country co ON co.id = s.countryFk - LEFT JOIN sage.Naciones sn ON sn.countryFk = co.id - LEFT JOIN vn.province p ON p.id = s.provinceFk - LEFT JOIN sage.Provincias sp ON sp.provinceFk = p.id - LEFT JOIN vn2008.Relaciones r ON r.Id_Proveedor = s.id - LEFT JOIN vn.supplierAccount sa ON sa.supplierFk = s.id - LEFT JOIN vn2008.Contactos con ON con.Id_Contacto = r.Id_Contacto - JOIN vn.company c ON c.id = xsp.empresa_id - WHERE - c.code = 'VNL' AND - s.isActive AND - s.nif <> '' -GROUP BY xsp.proveedor_id , xsp.empresa_id; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientSupplier_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -20913,8 +18481,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clientSupplier_add`(vCompanyFk INT) BEGIN @@ -21020,11 +18586,11 @@ BEGIN IF(co.country IN ('España', 'España exento'), 1,IF(co.isUeeMember = 1, 2, 4)), IFNULL(s.taxTypeSageFk, 0), n.Nacion, - IFNULL(con.Telefono, ''), - IFNULL(con.Movil, ''), + IFNULL(sc.phone, ''), + IFNULL(sc.mobile, ''), IFNULL(s.transactionTypeSageFk, 0), IFNULL(s.withholdingSageFk, '0'), - IFNULL(SUBSTR(con.email, 1, (COALESCE(NULLIF(LOCATE(',', con.email), 0), 99) - 1)), ''), + IFNULL(SUBSTR(sc.email, 1, (COALESCE(NULLIF(LOCATE(',', sc.email), 0), 99) - 1)), ''), IFNULL(iban, '') FROM vn.supplier s JOIN providerLastThreeMonths pl ON pl.supplierFk = s.id @@ -21032,9 +18598,8 @@ BEGIN LEFT JOIN Naciones n ON n.countryFk = co.id LEFT JOIN vn.province p ON p.id = s.provinceFk LEFT JOIN Provincias pr ON pr.provinceFk = p.id - LEFT JOIN vn2008.Relaciones r ON r.Id_Proveedor = s.id + LEFT JOIN vn.supplierContact sc ON sc.supplierFk = s.id LEFT JOIN vn.supplierAccount sa ON sa.supplierFk = s.id - LEFT JOIN vn2008.Contactos con ON con.Id_Contacto = r.Id_Contacto JOIN vn.company c ON c.id = pl.companyFk WHERE c.id = vCompanyFk AND s.isActive AND @@ -21046,146 +18611,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 `clientSupplier_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `clientSupplier_add__`(vCompanyFk INT) -BEGIN -/** - * Prepara los datos de clientes y proveedores para exportarlos a Sage - * @vCompanyFk Empresa dela que se quiere trasladar datos - */ - DECLARE vCountryCeutaMelillaFk INT; - DECLARE vCountryCanariasCode, vCountryCeutaMelillaCode VARCHAR(2); - - SELECT SiglaNacion INTO vCountryCanariasCode - FROM Naciones - WHERE Nacion ='ISLAS CANARIAS'; - - SELECT CodigoNacion, SiglaNacion INTO vCountryCeutaMelillaFk, vCountryCeutaMelillaCode - FROM Naciones - WHERE Nacion ='CEUTA Y MELILLA'; - - TRUNCATE TABLE clientesProveedores; - - INSERT INTO clientesProveedores - (CodigoEmpresa, - ClienteOProveedor, - CodigoClienteProveedor, - RazonSocial, - Nombre, - Domicilio, - CodigoCuenta, - CifDni, - CifEuropeo, - CodigoPostal, - Municipio, - CodigoProvincia, - Provincia, - CodigoNacion, - SiglaNacion, - PersonaFisicaJuridica, - TipoDocumentoPersona, - CodigoIva, - Nacion, - Telefono, - Telefono2, - CodigoTransaccion, - CodigoRetencion, - Email1, - iban) - SELECT - IF (@@hostname = 'db', co.companyCode, co.companyCodeTest), - 'C', - c.id, - c.socialName, - c.name, - IFNULL(c.street, ''), - c.accountingAccount, - TRIM(IF(cu.code = LEFT(c.fi, 2), MID(c.fi, 3, LENGTH(c.fi)-1), c.fi)), - IF(n.NacionCEE,TRIM(CONCAT(cu.code, IF(cu.code = LEFT(c.fi,2), MID(c.fi,3, LENGTH(c.fi)-1), c.fi))) , ''), - IFNULL(c.postcode, ''), - IFNULL(c.city, ''), - IFNULL(pr.CodigoProvincia, ''), - IFNULL(p.name, ''), - IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8_general_ci, IF(@isCeutaMelilla := IF(pr.Provincia IN ('CEUTA', 'MELILLA'), TRUE, FALSE), vCountryCeutaMelillaFk, IF (@isCanarias, vCountryCanariasCode, n.CodigoNacion)), n.CodigoNacion), - IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8_general_ci, IF(@isCeutaMelilla, vCountryCeutaMelillaCode, IF (@isCanarias, vCountryCanariasCode, n.SiglaNacion)), n.SiglaNacion), - IF((c.fi REGEXP '^([[:blank:]]|[[:digit:]])'), 'J','F'), - IF(cu.code IN('ES','EX'), - 1, - IF((cu.isUeeMember AND c.isVies), 2, 4)), - IFNULL(c.taxTypeSageFk,0), - IF(n.SiglaNacion = vCountryCanariasCode COLLATE utf8_general_ci, - IF(@isCeutaMelilla, 'CEUTA Y MELILLA', IF (@isCanarias, 'ISLAS CANARIAS', n.Nacion)), - n.Nacion), - IFNULL(c.phone, ''), - IFNULL(c.mobile, ''), - IFNULL(c.transactionTypeSageFk, 0), - '0', - IFNULL(SUBSTR(c.email, 1, LOCATE(',', CONCAT(c.email, ','))-1), ''), - IFNULL(c.iban, '') - FROM vn.`client` c - JOIN clientLastTwoMonths clm ON clm.clientFk = c.id - JOIN vn.company co ON co.id = clm.companyFk - LEFT JOIN vn.country cu ON cu.id = c.countryFk - LEFT JOIN Naciones n ON n.countryFk = cu.id - LEFT JOIN vn.province p ON p.id = c.provinceFk - LEFT JOIN Provincias pr ON pr.provinceFk = p.id - WHERE c.isRelevant - AND co.id = vCompanyFk - UNION ALL - SELECT IF (@@hostname = 'db', c.companyCode, companyCodeTest), - 'P', - s.id, - s.name, - s.name, - IFNULL(s.street, ''), - s.account, - TRIM(IF(co.code = LEFT(s.nif, 2), MID(s.nif, 3, LENGTH(s.nif) - 1), s.nif)), - IF(n.NacionCEE, TRIM(CONCAT(co.code, IF(co.code = LEFT(s.nif, 2), MID(s.nif, 3, LENGTH(s.nif) - 1), s.nif))), ''), - IFNULL(s.postCode,''), - IFNULL(s.city, ''), - IFNULL(pr.CodigoProvincia, ''), - IFNULL(p.name, ''), - n.CodigoNacion, - n.SiglaNacion COLLATE utf8_general_ci, - IF((s.nif REGEXP '^([[:blank:]]|[[:digit:]])'),'J','F'), - IF(co.country IN ('España', 'España exento'), 1,IF(co.isUeeMember = 1, 2, 4)), - IFNULL(s.taxTypeSageFk, 0), - n.Nacion, - IFNULL(con.Telefono, ''), - IFNULL(con.Movil, ''), - IFNULL(s.transactionTypeSageFk, 0), - IFNULL(s.withholdingSageFk, '0'), - IFNULL(SUBSTR(con.email, 1, (COALESCE(NULLIF(LOCATE(',', con.email), 0), 99) - 1)), ''), - IFNULL(iban, '') - FROM vn.supplier s - JOIN providerLastThreeMonths pl ON pl.supplierFk = s.id - LEFT JOIN vn.country co ON co.id = s.countryFk - LEFT JOIN Naciones n ON n.countryFk = co.id - LEFT JOIN vn.province p ON p.id = s.provinceFk - LEFT JOIN Provincias pr ON pr.provinceFk = p.id - LEFT JOIN vn2008.Relaciones r ON r.Id_Proveedor = s.id - LEFT JOIN vn.supplierAccount sa ON sa.supplierFk = s.id - LEFT JOIN vn2008.Contactos con ON con.Id_Contacto = r.Id_Contacto - JOIN vn.company c ON c.id = pl.companyFk - WHERE c.id = vCompanyFk AND - s.isActive AND - s.nif <> '' - GROUP BY pl.supplierFk, pl.companyFk; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceIn_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -21193,8 +18620,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceIn_add`(vInvoiceInFk INT, vXDiarioFk INT) BEGIN @@ -21364,6 +18789,7 @@ BEGIN JOIN vn.invoiceInTax iit ON iit.invoiceInFk = ii.id JOIN vn.expence e ON e.id = iit.expenceFk JOIN TiposRetencion t ON t.CodigoRetencion = ii.withholdingSageFk + LEFT JOIN tmp.invoiceDua id ON id.id = mci.id JOIN (SELECT SUM(x2.BASEEURO) taxableBase, SUM(x2.EURODEBE) taxBase FROM vn.XDiario x1 JOIN vn.XDiario x2 ON x1.ASIEN = x2.ASIEN @@ -21377,7 +18803,8 @@ BEGIN mci.PorRetencion = t.PorcentajeRetencion, mci.ImporteRetencion = iit.taxableBase * - 1 WHERE mci.id = vXDiarioFk - AND e.name = 'Retenciones'; + AND e.name = 'Retenciones' + AND id.id IS NULL; END ;; DELIMITER ; @@ -21385,6 +18812,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceIn_manager` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -21392,8 +18821,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceIn_manager`(vYear INT, vCompanyFk INT) BEGIN @@ -21671,6 +19098,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceOut_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -21678,8 +19107,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_add`(IN vInvoiceOutFk INT, IN vXDiarioFk INT) BEGIN @@ -21871,6 +19298,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceOut_manager` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -21878,8 +19307,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_manager`(vYear INT, vCompanyFk INT) BEGIN @@ -21938,561 +19365,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 `movContaAdd__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `movContaAdd__`() -BEGIN - /* Copia en movConta los asientos de XDiario para que luego los importe el proceso automático que hay en SQL Server - */ - DECLARE vDated DATE; - SELECT CONCAT(YEAR(util.VN_CURDATE()), "-01-01") INTO vDated; -SELECT "2021-01-01" INTO vDated; - TRUNCATE XDiario_movConta_IVA; - DELETE FROM movConta WHERE enlazadoSage = FALSE AND Asiento <> 1 ; - CALL clientesProveedoresAdd; - CALL planCuentasPgcAdd; - CALL XDiario_movConta_IVA_InvoiceOutAdd_Manager; - CALL XDiario_movConta_IVA_InvoiceInAdd_Manager; - INSERT INTO movConta( - TipoEntrada, -- VARCHAR(2) - Ejercicio, -- Año - CodigoEmpresa, -- ENT(2) - Asiento, -- LONG(4), nº ASIENTO - CargoAbono, -- VARCHAR(1) "D" debe ó "H" haber - CodigoCuenta, -- VARCHAR(15) partida contable - Contrapartida, -- VARCHAR(15) partida contable - FechaAsiento, -- FECHA(8) - Comentario, -- VARCHAR(40) - ImporteAsiento, -- DOBLE(19) - NumeroPeriodo, -- ENT(2) "-1" Al informar este valor se calcula automát. A partir de la fecha de asiento - FechaGrabacion, -- FECHA(8) - CodigoDivisa, -- VARCHAR(3) - ImporteCambio, -- DOBLE(19) - ImporteDivisa, -- DOBLE(19) - FactorCambio, -- DOBLE(19) - IdProcesoIME, -- GUID(16) - TipoCarteraIME, -- ENT(2) "0" para que no genere cartera - TipoAnaliticaIME, -- ENT(2) - StatusTraspasadoIME, -- BYTE "0" para dejar como no importado aún - TipoImportacionIME, -- BYTE "0" Alta "1" Baja - Metalico347, -- ENT(2) - /* ESTOS CAMPOS SOLO SE INFORMAN EN EL CASO DE SER FACTURA */ - BaseIva1, -- DOBLE(19) - PorBaseCorrectora1, -- DOBLE(19) - PorIva1, -- DOBLE(19) - CuotaIva1, -- DOBLE(19) - PorRecargoEquivalencia1,-- DOBLE(19) - RecargoEquivalencia1, -- DOBLE(19) - CodigoTransaccion1, -- BYTE "0" Nacional "1" Intracomunitario "2" Extracomunitario - BaseIva2, - PorBaseCorrectora2, - PorIva2, - CuotaIva2, - PorRecargoEquivalencia2, - RecargoEquivalencia2, - CodigoTransaccion2, - BaseIva3, - PorBaseCorrectora3, - PorIva3, - CuotaIva3, - PorRecargoEquivalencia3, - RecargoEquivalencia3, - CodigoTransaccion3, - BaseIva4, - PorBaseCorrectora4, - PorIva4, - CuotaIva4, - PorRecargoEquivalencia4, - RecargoEquivalencia4, - CodigoTransaccion4, - Año, -- ENT(2) - Serie, -- VARCHAR(10) - Factura, -- LONG(4) - SuFacturaNo, -- VARCHAR(40) - FechaFactura, -- FECHA(8) - ImporteFactura, -- DOBLE(19) - TipoFactura, -- VARCHAR(1) "E" / "R" / "I" - CodigoCuentaFactura, -- VARCHAR(15) cuenta del cliente/proveedor - CifDni, -- VARCHAR(13) - Nombre, -- VARCHAR(35) - CodigoRetencion, -- ENT(2) - BaseRetencion, -- DOBLE(19) - PorRetencion, -- DOBLE(19) - ImporteRetencion, -- DOBLE(19) - SiglaNacion, -- VARCHAR(2) "ES" por defecto - EjercicioFactura, -- ENT(2) - FechaOperacion, -- FECHA(8) - Exclusion347, -- ENT(2) - MantenerAsiento, -- BYTE "-1" mantener "0" Sage asigna nuevo - ClaveOperacionFactura_, -- VARCHAR(1) P(4721000011,4721000021)-I(4721000015-4720000005-4720000006)-D (Rectificativas) - TipoRectificativa, -- ENT(2) - FechaFacturaOriginal, -- FECHA(8) - BaseImponibleOriginal, -- DOBLE(19) - CuotaIvaOriginal, -- DOBLE(19) - ClaseAbonoRectificativas,-- ENT(2) - RecargoEquivalenciaOriginal, -- DOBLE(19) */ - LibreA1, - CodigoIva1, -- ENT(6) - CodigoIva2, -- ENT(6) - CodigoIva3, -- ENT(6) - CodigoIva4, -- ENT(6) - IvaDeducible1, -- Entero 2 ((-1)) - IvaDeducible2, -- Entero 2 ((-1)) - IvaDeducible3, -- Entero 2 ((-1)) - IvaDeducible4, -- Entero 2 ((-1))-- ENT(6) - Intracomunitaria -- INT(2) - ) - SELECT 'EN' as TipoEntrada, - YEAR(x.FECHA) AS Ejercicio, - IF (@@hostname = 'db', c.companyCode, companyCodeTest) AS CodigoEmpresa, -- ENT(2) c.companyCode AS CodigoEmpresa, - x.ASIEN AS Asiento, -- LONG(4), nº ASIENTO - IF(EURODEBE<>0 OR (EURODEBE=0 AND EUROHABER IS NULL),'D','H')AS CargoAbono, -- IF(EURODEBE IS NULL,"H","D") AS CargoAbono, VARCHAR(1) "D" debe ó "H" haber - x.SUBCTA AS CodigoCuenta, -- VARCHAR(15) partida contable - x.CONTRA AS Contrapartida, -- VARCHAR(15) partida contable - x.FECHA AS FechaAsiento, -- FECHA(8) - SUBSTRING(x.CONCEPTO, 1, 40) AS Comentario, -- VARCHAR(40) - IF(x.EURODEBE,x.EURODEBE,x.EUROHABER) AS ImporteAsiento, -- DOBLE(19) - MONTH(x.FECHA) AS NumeroPeriodo, -- ENT(2) "-1" Al informar este valor se calcula automát. A partir de la fecha de asiento - IF( sub2.FECREGCON IS NULL, sub2.FECHA_EX, sub2.FECREGCON) FechaGrabacion, -- FECHA(8) - IF(x.CAMBIO,IFNULL(xmi.CodigoDivisa, sub3.code),'') CodigoDivisa, -- VARCHAR(3) - x.CAMBIO AS ImporteCambio, -- DOBLE(19) - IFNULL(x.DEBEME,x.HABERME) AS ImporteDivisa, -- DOBLE(19) - IF(x.CAMBIO,1,0) AS FactorCambio, -- DOBLE(19) - NULL AS IdProcesoIME, -- GUID(16) - 0 AS TipoCarteraIME, -- ENT(2) "0" para que no genere cartera - 0 AS TipoAnaliticaIME, -- ENT(2) - 0 AS StatusTraspasadoIME, -- BYTE "0" para dejar como no importado aún - 0 AS TipoImportacionIME, -- BYTE "0" Alta "1" Baja - x.METAL as Metalico347, - /* ESTOS CAMPOS SOLO SE INFORMAN EN EL CASO DE SER FACTURA */ - xmi.BaseIva1, -- DOBLE(19) - xmi.PorBaseCorrectora1, -- DOBLE(19) - xmi.PorIva1, -- DOBLE(19) - xmi.CuotaIva1, -- DOBLE(19) - xmi.PorRecargoEquivalencia1,-- DOBLE(19) - xmi.RecargoEquivalencia1, -- DOBLE(19) - xmi.CodigoTransaccion1, -- BYTE "0" Nacional "1" Intracomunitario "2" Extracomunitario - xmi.BaseIva2, - xmi.PorBaseCorrectora2, - xmi.PorIva2, - xmi.CuotaIva2, - xmi.PorRecargoEquivalencia2, - xmi.RecargoEquivalencia2, - xmi.CodigoTransaccion2, - xmi.BaseIva3, - xmi.PorBaseCorrectora3, - xmi.PorIva3, - xmi.CuotaIva3, - xmi.PorRecargoEquivalencia3, - xmi.RecargoEquivalencia3, - xmi.CodigoTransaccion3, - xmi.BaseIva4, - xmi.PorBaseCorrectora4, - xmi.PorIva4, - xmi.CuotaIva4, - xmi.PorRecargoEquivalencia4, - xmi.RecargoEquivalencia4, - xmi.CodigoTransaccion4, - xmi.Año, -- ENT(2) - xmi.Serie, -- VARCHAR(10) - xmi.Factura, -- LONG(4) - xmi.SuFacturaNo, -- VARCHAR(40) - xmi.FechaFactura, -- FECHA(8) - xmi.ImporteFactura, -- DOBLE(19) - xmi.TipoFactura, -- VARCHAR(1) "E" / "R" - xmi.CodigoCuentaFactura, -- VARCHAR(15) cuenta del cliente/proveedor - xmi.CifDni, -- VARCHAR(13) - xmi.Nombre, -- VARCHAR(35) - xmi.CodigoRetencion, -- ENT(2) - xmi.BaseRetencion, -- DOBLE(19) - xmi.PorRetencion, -- DOBLE(19) - xmi.ImporteRetencion, -- DOBLE(19) - xmi.SiglaNacion, -- VARCHAR(2) "ES" por defecto - xmi.EjercicioFactura, -- ENT(2) - xmi.FechaOperacion, -- FECHA(8) - xmi.Exclusion347, -- ENT(2) - 1, -- xmi.MantenerAsiento BYTE "-1" mantener "0" Sage asigna nuevo - xmi.ClaveOperacionFactura, -- VARCHAR(1) - xmi.TipoRectificativa, -- ENT(2) - xmi.FechaFacturaOriginal, -- FECHA(8) - xmi.BaseImponibleOriginal, -- DOBLE(19) - xmi.CuotaIvaOriginal, -- DOBLE(19) - xmi.ClaseAbonoRectificativas,-- ENT(2) - xmi.RecargoEquivalenciaOriginal,-- DOBLE(19) */ - xmi.LibreA1, - xmi.CodigoIva1, -- ENT(6) - xmi.CodigoIva2, -- ENT(6) - xmi.CodigoIva3, -- ENT(6) - xmi.CodigoIva4, -- ENT(6) - xmi.IvaDeducible1, -- Entero 2 ((-1)) - xmi.IvaDeducible2, -- Entero 2 ((-1)) - xmi.IvaDeducible3, -- Entero 2 ((-1)) - xmi.IvaDeducible4, -- Entero 2 ((-1))-- ENT(6) - xmi.Intracomunitaria -- TINYINT(1) - FROM vn2008.XDiario x - JOIN vn.company c ON c.id = x.empresa_id - LEFT JOIN XDiario_movConta_IVA xmi ON xmi.id = x.id AND xmi.moveData > 0 - LEFT JOIN (SELECT ASIEN, FECREGCON, FECHA_EX - FROM (SELECT DISTINCT ASIEN, FECREGCON, FECHA_EX - FROM vn2008.XDiario - ORDER BY ASIEN, FECREGCON DESC, FECHA_EX DESC - ) sub GROUP BY ASIEN - )sub2 ON sub2.ASIEN = x.ASIEN - LEFT JOIN ( SELECT DISTINCT(account),cu.code - FROM vn.bank b - JOIN vn.currency cu ON cu.id = b.currencyFk - WHERE cu.code <> "EUR" -- no se informa cuando la divisa en EUR - )sub3 ON sub3.account = x.SUBCTA - WHERE x.enlazadoSage = 0 AND - c.companyCode AND - x.FECHA >= vDated; - --- Prepara Metálicos - UPDATE sage.movConta m - JOIN (SELECT Asiento, SUBSTR(c.socialName,1,35) Nombre, c.fi, n.SiglaNacion - FROM sage.movConta m - JOIN vn.client c ON c.id = IF(m.CargoAbono = "H", m.CodigoCuenta-4300000000, m.Contrapartida-4300000000 ) - LEFT JOIN Naciones n ON n.countryFk = c.countryFk - WHERE m.Metalico347 = TRUE AND - m.enlazadoSage = FALSE - ) AS sub ON m.Asiento = sub.Asiento - SET m.Metalico347 = TRUE, - m.TipoFactura = "I", - m.CifDni = sub.fi , - m.Nombre = sub.Nombre, - m.SiglaNacion = sub.SiglaNacion - WHERE m.enlazadoSage = FALSE; - - UPDATE sage.movConta m - SET Metalico347 = FALSE, - m.TipoFactura = "", - m.Metalico347 = FALSE - WHERE CargoAbono = "D" AND - m.enlazadoSage = FALSE; - --- Elimina cuentas de cliente/proveedor que no se utilizarán en la importación - DELETE cp - FROM clientesProveedores cp - JOIN (SELECT cp.codigoCuenta - FROM clientesProveedores cp - LEFT JOIN movConta mc ON mc.codigoCuenta = cp.codigoCuenta AND mc.enlazadoSage = FALSE - WHERE mc.codigoCuenta IS NULL - GROUP BY cp.codigoCuenta - ) sub ON sub.codigoCuenta = cp.codigoCuenta ; - --- Elimina cuentas contables que no se utilizarán en la importación - DELETE pc - FROM planCuentasPGC pc - JOIN ( SELECT pc.codigoCuenta - FROM planCuentasPGC pc - LEFT JOIN movConta mc ON mc.codigoCuenta = pc.codigoCuenta AND mc.enlazadoSage = FALSE - WHERE mc.codigoCuenta IS NULL - GROUP BY pc.codigoCuenta - ) sub ON sub.codigoCuenta = pc.codigoCuenta ; - --- DUAS - UPDATE movConta m - JOIN vn.XDiario x ON x.ASIEN = m.Asiento - SET m.BaseIva1 = x.BASEEURO , - m.PorIva1 = x.IVA, - m.CuotaIva1 = CAST((x.IVA/100) * x.BASEEURO AS DECIMAL(10,2)) , - m.CodigoTransaccion1 = 56 , - m.CodigoIva1 = 22, - m.IvaDeducible1 = TRUE, - m.FechaFacturaOriginal = x.FECHA_EX, - m.SuFacturaNo = x.FACTURAEX, - m.FechaOperacion = x.FECHA_OP, - m.ImporteFactura = m.ImporteFactura + x.BASEEURO + CAST((x.IVA/100) * x.BASEEURO AS DECIMAL(10,2)) - WHERE m.CodigoCuenta = 4700000999 - AND m.enlazadoSage = FALSE - AND x.SERIE='D' - AND x.IVA = 10; - - UPDATE movConta m - JOIN vn.XDiario x ON x.ASIEN = m.Asiento - SET m.BaseIva2 = x.BASEEURO , - m.PorIva2 = x.IVA, - m.CuotaIva2 = CAST((x.IVA/100) * x.BASEEURO AS DECIMAL(10,2)), - m.CodigoTransaccion2 = 56 , - m.CodigoIva2 = 90, - m.IvaDeducible2 = TRUE, - m.ImporteFactura = m.ImporteFactura + x.BASEEURO + CAST((x.IVA/100) * x.BASEEURO AS DECIMAL(10,2)) - WHERE m.CodigoCuenta = 4700000999 - AND m.enlazadoSage = FALSE - AND x.SERIE='D' - AND x.IVA = 21; - --- Rectificativas -UPDATE movConta m - JOIN (SELECT x.ASIEN, x.FECHA_RT, x.SERIE_RT, x.FACTU_RT - FROM movConta m - JOIN vn.XDiario x ON x.ASIEN = m.Asiento - WHERE m.TipoRectificativa>0 AND - m.enlazadoSage = FALSE AND - x.FACTU_RT IS NOT NULL - GROUP BY x.ASIEN - ) sub ON sub.ASIEN = m.Asiento - SET m.EjercicioFacturaOriginal = YEAR(sub.FECHA_RT), - m.SerieFacturaOriginal = sub.SERIE_RT, - m.NumeroFacturaOriginal = sub.FACTU_RT - WHERE m.TipoRectificativa > 0 AND - m.enlazadoSage = FALSE ; - --- Exportaciones Andorras y Canarias cambia TT (la cuenta de taxCode es compartida, id:125) -UPDATE sage.movConta m - SET CodigoTransaccion1 = 15, - CodigoTransaccion2 = IF(CodigoTransaccion2 = 0, 0, 15), - CodigoTransaccion3 = IF(CodigoTransaccion3 = 0, 0, 15), - CodigoTransaccion4 = IF(CodigoTransaccion4 = 0, 0, 15) - WHERE enlazadoSage = FALSE AND - (CodigoTransaccion1 = 14 OR CodigoTransaccion2 = 14 OR CodigoTransaccion3 = 14 OR CodigoTransaccion4 = 14) AND - SiglaNAcion IN ('XC','XB'); - --- Divisas - - UPDATE sage.movConta mc - SET CodigoDivisa = 'USD', - FactorCambio = 1, - ImporteCambio = ABS( CAST( IF( ImporteDivisa <> 0 AND ImporteCambio=0, ImporteAsiento / ImporteDivisa, ImporteCambio) AS DECIMAL( 10, 2))) - WHERE (ImporteCambio <> 0 OR ImporteDivisa <> 0 OR FactorCambio <> 0) - AND enlazadoSage = FALSE ; - - UPDATE sage.movConta mc - SET importeDivisa= importeDivisa * -1 - WHERE enlazadoSage = FALSE - AND importeDivisa > 0 - AND ImporteAsiento < 0; - - - -/*-- Actualiza las facturas DUA para excluirlas del 347 y marcarlas como intracomunitarias -/*UPDATE sage.movConta mc - SET - mc.Intracomunitaria = 1, - mc.Exclusion347 = 1 -WHERE - mc.CodigoCuenta = '4700000999'; */ - - --- MARCAR EN CASO DE SER INTRACOMUNITARIA -/* -UPDATE sage.movConta mc - SET - mc.Intracomunitaria = 1 -WHERE - mc.CodigoTransaccion1 IN (20,29); -*/ - - - -- LAS FACTURAS RTECTIFICATIVAS QUE TIENEN CUENTA DE IVA 477.2 SALE CON T.T. 1, TODAS ESTAS FACTURAS DEBEN DE TENER T.T. 15 - - /*UPDATE sage.movConta mc - JOIN - (SELECT - Asiento - FROM - sage.movConta - WHERE - CodigoCuenta = 4770000002) sub ON sub.Asiento = mc.Asiento -SET - CodigoTransaccion1 = CASE - WHEN CodigoTransaccion1 = 1 THEN 15 - ELSE CodigoTransaccion1 - END, - CodigoTransaccion2 = CASE - WHEN CodigoTransaccion2 = 1 THEN 15 - ELSE CodigoTransaccion2 - END, - CodigoTransaccion3 = CASE - WHEN CodigoTransaccion3 = 1 THEN 15 - ELSE CodigoTransaccion3 - END, - CodigoTransaccion4 = CASE - WHEN CodigoTransaccion4 = 1 THEN 15 - ELSE CodigoTransaccion4 - END -WHERE - serie = 'R'; - -*/ - -/* -Nombre Tipo Longitud Descripción campo / Valor por defecto -MovPosicion Guid contador 16 Automático, no informar -Ejercicio Entero 2 -1 -- Al informar este valor se calcula automát. A partir de la fecha de asiento -CodigoEmpresa Entero 2 Empresa de Sage 200c donde va destinado el asiento -Asiento Entero Largo 4 Número de asiento -CargoAbono Texto 1 "D" - Debe / "H" - Haber -CodigoCuenta Texto 15 Cuenta contable del movimiento -Contrapartida Texto 15 Es informativo, no es necesario informarlo -FechaAsiento Fecha 8 Fecha del asiento -TipoDocumento Texto 6 -DocumentoConta Texto 9 -Comentario Texto 40 Comentario del asiento -ImporteAsiento Doble 19 Importe del movimiento -CodigoDiario Entero 2 -CodigoCanal Texto 10 Centro coste analítico (no necesario informar) -CodigoActividad Texto 1 -FechaVencimiento Fecha 8 Si se tienen que generar efectos, será la fecha de vto. Del efecto. No informar -NumeroPeriodo Entero 2 -1 -- Al informar este valor se calcula automát. A partir de la fecha de asiento -CodigoUsuario Entero 2 -FechaGrabacion Fecha 8 -TipoEntrada Texto 2 -CodigoDepartamento Texto 10 Centro coste analítico (no necesario informar) -CodigoSeccion Texto 10 Centro coste analítico (no necesario informar) -CodigoDivisa Texto 3 -ImporteCambio Doble 19 -ImporteDivisa Doble 19 -FactorCambio Doble 19 -CodigoProyecto Texto 10 Centro coste analítico (no necesario informar) -LibreN1 Entero Largo 4 Campo libre numérico -LibreN2 Entero Largo 4 Campo libre numérico -LibreA1 Texto 15 Campo libre alfanumérico -LibreA2 Texto 15 Campo libre alfanumérico -IdDelegacion Texto 10 Centro coste analítico (no necesario informar) -OrdenMovimientos Contador 4 Número de orden de cada movimiento dentro de un mismo asiento, autonumerar para cada asiento -MovCartera Guid 16 -IdProcesoIME Guid 16 guid igual para todos los registros que correspondan a una misma importación. -TipoCarteraIME Entero 2 0 - Para que no genere cartera -TipoAnaliticaIME Entero 2 -StatusTraspasadoIME Byte 1 0 - Para que quede marcado el movimiento como no importado todavía. -TipoImportacionIME Byte 1 0 - Alta -BaseIva1 Doble 19 Base para el IVA 1 (idéntico para cada posible IVA hasta el 4) (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -PorBaseCorrectora1 Doble 19 Base correctora (en caso de que la haya) para el IVA 1 (idéntico para cada posible IVA hasta el 4) (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -PorIva1 Doble 19 Porcentaje IVA 1 (idéntico para cada posible IVA hasta el 4) (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -CuotaIva1 Doble 19 Cuota IVA 1 (idéntico para cada posible IVA hasta el 4) (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -PorRecargoEquivalencia1 Doble 19 Si hay recargo - Porcentaje de recargo para el IVA 1 (idéntico para cada posible IVA hasta el 4) (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -RecargoEquivalencia1 Doble 19 Si hay recargo - Importe de Recargo para el IVA 1 (idéntico para cada posible IVA hasta el 4) (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -CodigoTransaccion1 Byte 1 Ver con dpto. de contabilidad - Depende de la naturaleza del asiento (Nacional, Intracoumunitario, etc…) (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -BaseIva2 Doble 19 0 -PorBaseCorrectora2 Doble 19 0 -PorIva2 Doble 19 0 -CuotaIva2 Doble 19 0 -PorRecargoEquivalencia2 Doble 19 0 -RecargoEquivalencia2 Doble 19 0 -CodigoTransaccion2 Byte 1 0 -BaseIva3 Doble 19 0 -PorBaseCorrectora3 Doble 19 0 -PorIva3 Doble 19 0 -CuotaIva3 Doble 19 0 -PorRecargoEquivalencia3 Doble 19 0 -RecargoEquivalencia3 Doble 19 0 -CodigoTransaccion3 Byte 1 0 -BaseIva4 Doble 19 0 -PorBaseCorrectora4 Doble 19 0 -PorIva4 Doble 19 0 -CuotaIva4 Doble 19 0 -PorRecargoEquivalencia4 Doble 19 0 -RecargoEquivalencia4 Doble 19 0 -CodigoTransaccion4 Byte 1 0 -Año Entero 2 Ejercicio de la factura en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -Serie Texto 10 Serie de la factura en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -Factura Entero Largo 4 Número de la factura en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -SuFacturaNo Texto 40 Número de la factura del proveedor para factura recibidas, en el caso de que el asiento sea de una factura. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -FechaFactura Fecha 8 Fecha de la factura en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -ImporteFactura Doble 19 Importe de la factura en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -TipoFactura Texto 1 "E" - Factura emitida / "R" - Factura Recibida - en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -CodigoCuentaFactura Texto 15 Cuenta contable del cliente / proveedor en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -CifDni Texto 13 CIF del cliente / proveedor en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -Nombre Texto 35 Nombre del cliente / proveedor en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -CodigoRetencion Entero 2 Código de retención de la factura en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -BaseRetencion Doble 19 Base de retención de la factura en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -PorRetencion Doble 19 Porcentaje de retención de la factura en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -ImporteRetencion Doble 19 Importe de retención de la factura en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -AbonoIva Entero 2 0 -CodigoActividadF Texto 1 ('') -Intracomunitaria Entero 2 0 -CodigoTerritorio Entero 2 0 -SiglaNacion Texto 2 Sigla de la nación de la factura en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -RetencionInformativa Entero 2 0 -EjercicioFacturaOriginal Entero 2 0 -SerieFacturaOriginal Texto 10 ('') -NumeroFacturaOriginal Entero Largo 4 0 -EjercicioFactura Entero 2 Ejercicio de la factura en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -CobroPagoRetencion Texto 1 ('') -FechaOperacion Fecha 8 Normalmente Fecha Factura en el caso de que sea un asiento de facturas. (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -Exclusion347 Entero 2 0 -MovIdentificadorIME Guid contador 16 (newid()) -Previsiones Texto 1 ('') -MantenerAsiento Byte 1 -1 si se quiere mantener el número de asiento que se informa en la importación o "0" si se quiere que se asigne automáticamente el asiento en Sage 200c -OrdenMovIME Entero 2 0 -Metalico347 Entero 2 0 -ClaveOperacionFactura_ Texto 1 Ver con dpto. de contabilidad - Depende de la naturaleza del asiento (Nacional, Intracoumunitario, etc…) (Solamente se informa en el movimiento de la factura - cuenta cliente / proveedor) -SerieAgrupacion_ Texto 10 ('') -NumeroFacturaInicial_ Entero Largo 4 0 -NumeroFacturaFinal_ Entero Largo 4 0 -IdAsientoExterno Texto 50 ('') -IdDiarioExterno Texto 10 ('') -IdFacturaExterno Texto 50 ('') -IdMovimiento Texto 40 ('') -IdCuadre Entero 2 ((0)) -FechaCuadre Fecha 8 (getdate()) -TipoCuadre Texto 4 ('') -AgrupacionCuadre Entero Largo 4 ((0)) -StatusSaldo Entero 2 ((0)) -StatusConciliacion Entero 2 ((0)) -CodigoConciliacion Entero Largo 4 ((0)) -FechaConciliacion Fecha 8 -TipoConciliacion Entero 2 ((0)) -IndicadorContaBanco Texto 1 ('') -Descripcion3 Texto 40 ('') -Descripcion4 Texto 40 ('') -Descripcion5 Texto 40 ('') -Descripcion6 Texto 40 ('') -Descripcion7 Texto 40 ('') -Descripcion8 Texto 50 ('') -Descripcion9 Texto 50 ('') -Descripcion2 Texto 250 ('') -Descripcion1 Texto 250 ('') -Punteo1 Entero 2 ((0)) -Punteo9 Entero 2 ((0)) -Punteo8 Entero 2 ((0)) -Punteo7 Entero 2 ((0)) -Punteo6 Entero 2 ((0)) -Punteo5 Entero 2 ((0)) -Punteo4 Entero 2 ((0)) -Punteo3 Entero 2 ((0)) -Punteo2 Entero 2 ((0)) -CodigoIva1 Entero 2 ((0)) -CodigoIva2 Entero 2 ((0)) -CodigoIva3 Entero 2 ((0)) -CodigoIva4 Entero 2 ((0)) -CriterioIva Byte 1 ((0)) -FechaMaxVencimiento Fecha 8 -TipoCriterioCaja Byte 1 ((0)) -MovFacturaOrigenIME Texto 50 ('') -IdFacturaExternoFinal Texto 50 ('') -IdFacturaExternoInicial Texto 50 ('') -IdFacturaExternoOriginal Texto 50 ('') -NumFacturasExternoAgrupacion Entero Largo 4 ((0)) -CodigoMedioCobro Texto 1 ('') -MedioCobro Texto 31 ('') -IvaDeducible1 Entero 2 ((-1)) -IvaDeducible2 Entero 2 ((-1)) -IvaDeducible3 Entero 2 ((-1)) -IvaDeducible4 Entero 2 ((-1)) -TipoRectificativa Entero 2 ((0)) -FechaFacturaOriginal Fecha 8 -BaseImponibleOriginal Doble 19 ((0)) -CuotaIvaOriginal Doble 19 ((0)) -ClaseAbonoRectificativas Entero 2 ((0)) -RecargoEquivalenciaOriginal Doble 19 ((0)) -ObjetoFactura Texto 500 ('') -*/ -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `pgc_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -22500,8 +19374,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `pgc_add`(vCompanyFk INT) BEGIN @@ -22547,793 +19419,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 `planCuentasPgcAdd__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `planCuentasPgcAdd__`() -BEGIN - -TRUNCATE TABLE planCuentasPGC; - -REPLACE INTO planCuentasPGC( - CodigoEmpresa, - CodigoCuenta, - Cuenta, - ClienteOProveedor - ) - SELECT codigoEmpresa, CodigoCuenta, Cuenta, ClienteOProveedor - FROM - ( - SELECT - IF (@@hostname = 'db', c.companyCode, companyCodeTest) AS codigoEmpresa, - e.id AS CodigoCuenta, - UCASE(e.name) AS Cuenta, - '' AS ClienteOProveedor - FROM - (vn.expence e - JOIN vn.company c) - WHERE - c.companyCode - GROUP BY e.id - - UNION - SELECT - IF (@@hostname = 'db', c.companyCode, companyCodeTest) AS codigoEmpresa, - b.account AS CodigoCuenta, - UCASE(b.bank) AS Cuenta, - '' AS ClienteOProveedor - FROM - (vn.bank b - JOIN vn.company c) - WHERE (c.companyCode AND b.isActive) - AND b.account - GROUP BY b.account - UNION - SELECT - codigoEmpresa, - CodigoCuenta, - Nombre AS Cuenta, - ClienteOProveedor - FROM clientesProveedores - GROUP BY CodigoCuenta - ) pgc - GROUP BY CodigoCuenta; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `XDiario_movConta_IVA_InvoiceInAdd_Manager__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `XDiario_movConta_IVA_InvoiceInAdd_Manager__`() -BEGIN - DECLARE done BOOL DEFAULT FALSE; - DECLARE vInvoiceFk INT; - DECLARE vXDiarioFk INT; - DECLARE vDated DATE; - DECLARE rs CURSOR FOR - SELECT IFNULL(x.CLAVE,x.FACTURA) invoiceInFk, x.id XDiarioFk - FROM vn2008.XDiario x - JOIN(SELECT DISTINCT (x.ASIEN) - FROM vn2008.XDiario x - LEFT JOIN vn.invoiceIn ii ON x.CLAVE = ii.id - LEFT JOIN vn.invoiceInTax it ON it.invoiceInFk = ii.id - WHERE(it.taxTypeSageFk IS NOT NULL OR x.SERIE='D') AND - x.enlazadoSage = FALSE AND - x.FECHA >= vDated - ) sub ON sub.ASIEN =x.ASIEN -- Elimina las Facturas con IVA 0 (-) no se trasladan a sage - WHERE x.enlazadoSage = FALSE AND - x.FECHA >= vDated AND - x.CLAVE IS NOT NULL ; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - SELECT CONCAT(YEAR(util.VN_CURDATE()), "-01-01") INTO vDated; - SELECT "2021-01-01" INTO vDated; - DROP TEMPORARY TABLE IF EXISTS tmp.invoiceDua; - CREATE TEMPORARY TABLE tmp.invoiceDua - SELECT id - FROM vn2008.XDiario x - WHERE ASIEN IN (SELECT ASIEN - FROM vn2008.XDiario x - WHERE x.enlazadoSage = FALSE AND - x.SUBCTA = '4700000999' AND - x.FECHA >= vDated - ) AND - NOT CONTRA <=> "4330002067"; - - DROP TEMPORARY TABLE IF EXISTS tmp.invoiceInList; - CREATE TEMPORARY TABLE tmp.invoiceInList - SELECT i.id id, - i.supplierRef supplierRef, - i.serial serial, - i.supplierFk supplierFk, - i.issued issued, - IF(expenceFkDeductible, FALSE, i.isVatDeductible) isVatDeductible, - i.serialNumber serialNumber, - IF(c.code = "EUR", '',c.code) currencyFk - FROM vn.invoiceIn i - JOIN vn.currency c ON c.id = i.currencyFk - WHERE i.bookEntried >= vDated - UNION ALL - SELECT d.id , - d.code , - 'D' , - d.companyFk , - d.issued , - FALSE, - d.id, - '' -- EUROS - FROM vn.dua d - WHERE d.issued IS NOT NULL AND - code IS NOT NULL; - - OPEN rs; - FETCH rs INTO vInvoiceFk, vXDiarioFk; - WHILE NOT done DO - CALL XDiario_movConta_IVA_InvoiceInAdd(vInvoiceFk, vXDiarioFk); - FETCH rs INTO vInvoiceFk, vXDiarioFk; - END WHILE; - CLOSE rs; - - DROP TEMPORARY TABLE tmp.invoiceDua; - DROP TEMPORARY TABLE tmp.invoiceInList; - - -- ASIENTOS CON IVA SOPORTADO 472. y 477. hay que informar 2 líneas la info de facturas una como tipo de factura emitida y otra como recibida - DROP TEMPORARY TABLE IF EXISTS tmp.XDiario_movConta_IVA; - CREATE TEMPORARY TABLE tmp.XDiario_movConta_IVA - SELECT - sub3.id, - mc.CodigoDivisa, - mc.BaseIva1, - mc.PorBaseCorrectora1, - mc.PorIva1, - mc.CuotaIva1, - mc.PorRecargoEquivalencia1, - mc.RecargoEquivalencia1, - mc.CodigoTransaccion1, - mc.CodigoIva1, - mc.BaseIva2, - mc.PorBaseCorrectora2, - mc.PorIva2, - mc.CuotaIva2, - mc.PorRecargoEquivalencia2, - mc.RecargoEquivalencia2, - mc.CodigoTransaccion2, - mc.CodigoIva2, - mc.BaseIva3, - mc.PorBaseCorrectora3, - mc.PorIva3, - mc.CuotaIva3, - mc.PorRecargoEquivalencia3, - mc.RecargoEquivalencia3, - mc.CodigoTransaccion3, - mc.CodigoIva3, - mc.BaseIva4, - mc.PorBaseCorrectora4, - mc.PorIva4, - mc.CuotaIva4, - mc.PorRecargoEquivalencia4, - mc.RecargoEquivalencia4, - mc.CodigoTransaccion4, - mc.CodigoIva4, - mc.Año, - mc.Serie, - mc.Factura, - mc.SuFacturaNo, - mc.FechaFactura, - mc.ImporteFactura, - 'E', - mc.CodigoCuentaFactura, - mc.CifDni, - mc.Nombre, - mc.CodigoRetencion, - mc.BaseRetencion, - mc.PorRetencion, - mc.ImporteRetencion, - mc.SiglaNacion, - mc.EjercicioFactura, - x.FECHA, - mc.Exclusion347, - mc.MantenerAsiento, - mc.Metalico347, - mc.ClaveOperacionFactura, - mc.TipoRectificativa, - mc.FechaFacturaOriginal, - mc.CuotaIvaOriginal, - mc.BaseImponibleOriginal, - mc.ClaseAbonoRectificativas, - mc.RecargoEquivalenciaOriginal, - mc.LibreA1, - mc.IvaDeducible1, - mc.IvaDeducible2, - mc.IvaDeducible3, - mc.IvaDeducible4, - mc.FechaGrabacion, - mc.Intracomunitaria, - mc.moveData - FROM sage.XDiario_movConta_IVA mc - JOIN vn.XDiario x ON x.id = mc.id - JOIN (SELECT x.ASIEN, x.id - FROM vn.XDiario x - JOIN(SELECT DISTINCT(x.ASIEN) ASIEN - FROM (SELECT DISTINCT(ASIEN) - FROM vn.XDiario x - WHERE SUBCTA LIKE '472%' AND - x.enlazadoSage = FALSE AND - x.FECHA >= vDated - ) sub JOIN vn.XDiario x ON x.ASIEN = sub.ASIEN - WHERE x.SUBCTA LIKE '477%' - )sub2 ON sub2.ASIEN = x.ASIEN - WHERE x.CONTRA IS NOT NULL AND x.SUBCTA LIKE '477%' - GROUP BY x.ASIEN - )sub3 ON sub3.ASIEN = x.ASIEN; - - INSERT INTO sage.XDiario_movConta_IVA - (`id`, - `CodigoDivisa`, - `BaseIva1`, - `PorBaseCorrectora1`, - `PorIva1`, - `CuotaIva1`, - `PorRecargoEquivalencia1`, - `RecargoEquivalencia1`, - `CodigoTransaccion1`, - `CodigoIva1`, - `BaseIva2`, - `PorBaseCorrectora2`, - `PorIva2`, - `CuotaIva2`, - `PorRecargoEquivalencia2`, - `RecargoEquivalencia2`, - `CodigoTransaccion2`, - `CodigoIva2`, - `BaseIva3`, - `PorBaseCorrectora3`, - `PorIva3`, - `CuotaIva3`, - `PorRecargoEquivalencia3`, - `RecargoEquivalencia3`, - `CodigoTransaccion3`, - `CodigoIva3`, - `BaseIva4`, - `PorBaseCorrectora4`, - `PorIva4`, - `CuotaIva4`, - `PorRecargoEquivalencia4`, - `RecargoEquivalencia4`, - `CodigoTransaccion4`, - `CodigoIva4`, - `Año`, - `Serie`, - `Factura`, - `SuFacturaNo`, - `FechaFactura`, - `ImporteFactura`, - `TipoFactura`, - `CodigoCuentaFactura`, - `CifDni`, - `Nombre`, - `CodigoRetencion`, - `BaseRetencion`, - `PorRetencion`, - `ImporteRetencion`, - `SiglaNacion`, - `EjercicioFactura`, - `FechaOperacion`, - `Exclusion347`, - `MantenerAsiento`, - `Metalico347`, - `ClaveOperacionFactura`, - `TipoRectificativa`, - `FechaFacturaOriginal`, - `CuotaIvaOriginal`, - `BaseImponibleOriginal`, - `ClaseAbonoRectificativas`, - `RecargoEquivalenciaOriginal`, - `LibreA1`, - `IvaDeducible1`, - `IvaDeducible2`, - `IvaDeducible3`, - `IvaDeducible4`, - `FechaGrabacion`, - `Intracomunitaria`, - `moveData`) - SELECT * - FROM tmp.XDiario_movConta_IVA; - DROP TEMPORARY TABLE tmp.XDiario_movConta_IVA; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `XDiario_movConta_IVA_InvoiceInAdd__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `XDiario_movConta_IVA_InvoiceInAdd__`(IN vInvoiceInFk INT, IN vXDiarioId INT) -BEGIN - - DECLARE vDone BOOL DEFAULT FALSE; - DECLARE vBase DOUBLE; - DECLARE vVat DOUBLE; - DECLARE vRate DOUBLE; - DECLARE vTransactionCode INT; - DECLARE vCounter INT DEFAULT 0; - DECLARE vTransactionCodeOld INT; - DECLARE vTaxCode INT; - DECLARE vTaxCodeOld INT; - DECLARE vOperationCode VARCHAR(1); - DECLARE vIsIntracommunity BOOL DEFAULT FALSE; - DECLARE vDuaExcluded INT; - - DECLARE rs CURSOR FOR -- IVA - SELECT it.taxableBase BASEEURO, - CAST((( it.taxableBase / 100) * t.PorcentajeIva) AS DECIMAL (10,2)) vat, - t.PorcentajeIva rate, - it.transactionTypeSageFk transactionCode, - it.taxTypeSageFk taxCode, - t.isIntracommunity, - tt.ClaveOperacionDefecto operationCode, - id.id - FROM vn.invoiceIn i - JOIN vn.invoiceInTax it ON it.InvoiceInFk = i.id - 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) - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - DELETE FROM XDiario_movConta_IVA - WHERE id = vXDiarioId; - - INSERT INTO XDiario_movConta_IVA(id, LibreA1) - VALUES (vXDiarioId, vInvoiceInFk); - - OPEN rs; - FETCH rs INTO vBase, - vVat, - vRate, - vTransactionCode, - vTaxCode, - vIsIntracommunity, - vOperationCode, - vDuaExcluded; - - SET vTransactionCodeOld=vTransactionCode; - SET vTaxCodeOld=vTaxCode; - - WHILE NOT vDone DO - IF vOperationCode IS NOT NULL THEN - UPDATE XDiario_movConta_IVA - SET ClaveOperacionFactura = vOperationCode - WHERE id = vXDiarioId; - END IF; - - IF vTransactionCode IS NULL THEN - SET vTransactionCode = vTransactionCodeOld; - END IF; - - IF vTaxCodeOld IS NULL THEN - SET vTaxCode = vTaxCodeOld; - END IF; - - SET vCounter = vCounter + 1; - CASE vCounter - WHEN 1 THEN - UPDATE XDiario_movConta_IVA - SET BaseIva1 = vBase, - PorIva1 = vRate, - CuotaIva1 = vVat, - CodigoTransaccion1 = vTransactionCode, - CodigoIva1 = vTaxCode - WHERE id = vXDiarioId; - WHEN 2 THEN - UPDATE XDiario_movConta_IVA - SET BaseIva2 = vBase, - PorIva2 = vRate, - CuotaIva2 = vVat, - CodigoTransaccion2 = vTransactionCode, - CodigoIva2 = vTaxCode - WHERE id = vXDiarioId; - WHEN 3 THEN - UPDATE XDiario_movConta_IVA - SET BaseIva3 = vBase, - PorIva3 = vRate, - CuotaIva3 = vVat, - CodigoTransaccion3 = vTransactionCode, - CodigoIva3 = vTaxCode - WHERE id = vXDiarioId; - WHEN 4 THEN - UPDATE XDiario_movConta_IVA - SET BaseIva4 = vBase, - PorIva4 = vRate, - CuotaIva4 = vVat, - CodigoTransaccion4 = vTransactionCode, - CodigoIva4 = vTaxCode - WHERE id = vXDiarioId; - ELSE - SELECT vXDiarioId INTO vXDiarioId; - END CASE; - - IF vIsIntracommunity THEN - UPDATE XDiario_movConta_IVA - SET Intracomunitaria = TRUE - WHERE id = vXDiarioId; - END IF; - - SET vTransactionCodeOld=vTransactionCode; - SET vTaxCodeOld=vTaxCode; - - FETCH rs INTO vBase, - vVat, - vRate, - vTransactionCode, - vTaxCode, - vIsIntracommunity, - vOperationCode, - vDuaExcluded; - END WHILE; - CLOSE rs; - - UPDATE XDiario_movConta_IVA xmi - JOIN tmp.invoiceInList ii ON ii.id = vInvoiceInFk - JOIN vn2008.XDiario x ON x.id = xmi.id - LEFT JOIN tmp.invoiceDua id ON id.id = xmi.id - JOIN vn.supplier s ON s.id = ii.supplierFk - JOIN Naciones n ON n.countryFk = s.countryFk - SET xmi.CodigoDivisa = ii.currencyFk, - xmi.Año = YEAR(ii.issued), - xmi.Serie = ii.serial, - xmi.Factura = ii.serialNumber, -- x.FACTURA, DUAS¿? - xmi.FechaFactura = ii.issued, - xmi.ImporteFactura = IFNULL(xmi.BaseIva1, 0) + IFNULL(xmi.CuotaIva1, 0) + - IFNULL(xmi.BaseIva2, 0) + IFNULL(xmi.CuotaIva2, 0) + - IFNULL(xmi.BaseIva3, 0) + IFNULL(xmi.CuotaIva3, 0) + - IFNULL(xmi.BaseIva4, 0) + IFNULL(xmi.CuotaIva4, 0), - xmi.TipoFactura = IF(id.id,IF( ii.serial = 'D', 'R','I'), 'R'), -- MARCAR I para informativa - xmi.CodigoCuentaFactura = x.SUBCTA, - xmi.CifDni = IF(LEFT(TRIM(s.nif),2) = n.SiglaNacion, SUBSTRING(TRIM(s.nif),3) ,s.nif), - xmi.Nombre = s.name, - xmi.SiglaNacion = n.SiglaNacion, - xmi.EjercicioFactura = YEAR(ii.issued), - xmi.FechaOperacion = ii.issued, - xmi.MantenerAsiento = TRUE, - xmi.SuFacturaNo = ii.supplierRef, - 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 - 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 ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `XDiario_movConta_IVA_InvoiceOutAdd_Manager__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `XDiario_movConta_IVA_InvoiceOutAdd_Manager__`() -BEGIN - - DECLARE done BOOL DEFAULT FALSE; - DECLARE vInvoiceFk INT; - DECLARE vXDiarioFk INT; - DECLARE vDated DATE; - - DECLARE rs CURSOR FOR - SELECT io.id invoiceOutFk, x.XDiarioFk - FROM vn.invoiceOut io - JOIN (SELECT MIN(id) XDiarioFk, refFk - FROM vn2008.XDiario x - JOIN (SELECT x.ASIEN, CONCAT(x.SERIE,x.FACTURA) AS refFk - FROM vn2008.XDiario x - JOIN vn.company c ON c.id = x.empresa_id - WHERE enlazadoSage = FALSE AND - x.FACTURA AND - c.companyCode AND - x.FECHA >= vDated - GROUP BY refFk - ) a ON a.ASIEN = x.ASIEN - GROUP BY refFk - ) x ON x.refFk = io.ref; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - SELECT CONCAT(YEAR(util.VN_CURDATE()), "-01-01") INTO vDated; -SELECT "2021-01-01" INTO vDated; - OPEN rs; - FETCH rs INTO vInvoiceFk, vXDiarioFk; - WHILE NOT done DO - CALL XDiario_movConta_IVA_InvoiceOutAdd(vInvoiceFk, vXDiarioFk); - FETCH rs INTO vInvoiceFk, vXDiarioFk; - END WHILE; - CLOSE rs; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `XDiario_movConta_IVA_InvoiceOutAdd__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `XDiario_movConta_IVA_InvoiceOutAdd__`(IN vInvoiceOutFk INT, IN vXDiarioId INT) -BEGIN - - DECLARE vDone BOOL DEFAULT FALSE; - DECLARE vBase DOUBLE; - DECLARE vVat DOUBLE; - DECLARE vRate DOUBLE; - DECLARE vIs340 DOUBLE; - DECLARE vIs347 DOUBLE; - DECLARE vVatRE DOUBLE; - DECLARE vRateRE DOUBLE; - DECLARE vTransactionCode INT; - DECLARE vCounter INT DEFAULT 0; - DECLARE vInvoiceOutCorrectedFk INT; - DECLARE vTaxCode INT; - DECLARE vIsIntracommunity BOOL DEFAULT FALSE; - DECLARE vOperationCode VARCHAR(1); - - -- IVA - DECLARE rs CURSOR FOR - SELECT oit.taxableBase, - oit.vat, - pgc.rate, - pgc.mod340, - pgc.mod347, - pgcRE.rate as rateRE, - oitRE.vat as vatRE, - tc.transactionCode , - tc.taxCode, - tc.isIntracommunity, - tc.operationcode - FROM vn.invoiceOutTax oit - JOIN vn.pgc ON pgc.code = oit.pgcFk - LEFT JOIN vn.pgcEqu e ON e.vatFk = oit.pgcFk - LEFT JOIN vn.pgcEqu eRE ON eRE.equFk = oit.pgcFk - LEFT JOIN vn.invoiceOutTax oitRE ON oitRE.invoiceOutFk = oit.invoiceOutFk AND oitRE.pgcFk = e.equFk - LEFT JOIN vn.pgc pgcRE ON pgcRE.code = oitRE.pgcFk - LEFT JOIN vn.taxCode tc ON tc.code = pgc.code COLLATE 'utf8_general_ci' - WHERE eRE.equFk Is NULL - AND oit.invoiceOutFk = vInvoiceOutFk - GROUP by pgc.code; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - DELETE FROM XDiario_movConta_IVA - WHERE id = vXDiarioId; - - INSERT INTO XDiario_movConta_IVA(id) - VALUES (vXDiarioId); - OPEN rs; - FETCH rs INTO vBase, - vVat, - vRate, - vIs340, - vIs347, - vVatRE, - vRateRE, - vTransactionCode, - vTaxCode, - vIsIntracommunity, - vOperationCode; - - WHILE NOT vDone DO - - IF vOperationCode IS NOT NULL THEN - UPDATE XDiario_movConta_IVA - SET ClaveOperacionFactura = vOperationCode - WHERE id = vXDiarioId; - END IF; - - SET vCounter = vCounter + 1; - CASE vCounter - WHEN 1 THEN - UPDATE XDiario_movConta_IVA - SET BaseIva1 = vBase, - PorIva1 = vRate, - CuotaIva1 = vVat, - PorRecargoEquivalencia1 = vVatRE, - RecargoEquivalencia1 = vRateRE, - CodigoTransaccion1 = vTransactionCode, - CodigoIva1 = vTaxCode - WHERE id = vXDiarioId; - WHEN 2 THEN - UPDATE XDiario_movConta_IVA - SET BaseIva2 = vBase, - PorIva2 = vRate, - CuotaIva2 = vVat, - PorRecargoEquivalencia2 = vVatRE, - RecargoEquivalencia2 =vRateRE, - CodigoTransaccion2 = vTransactionCode, - CodigoIva2 = vTaxCode - WHERE id = vXDiarioId; - WHEN 3 THEN - UPDATE XDiario_movConta_IVA - SET BaseIva3 = vBase, - PorIva3 = vRate, - CuotaIva3 = vVat, - PorRecargoEquivalencia3 = vVatRE, - RecargoEquivalencia3 = vRateRE, - CodigoTransaccion3 = vTransactionCode, - CodigoIva3 = vTaxCode - WHERE id = vXDiarioId; - WHEN 4 THEN - UPDATE XDiario_movConta_IVA - SET BaseIva4 = vBase, - PorIva4 = vRate, - CuotaIva4 = vVat, - PorRecargoEquivalencia4 = vVatRE, - RecargoEquivalencia4 = vRateRE, - CodigoTransaccion4 = vTransactionCode, - CodigoIva4 = vTaxCode - WHERE id = vXDiarioId; - END CASE; - - UPDATE XDiario_movConta_IVA - SET Exclusion347 = NOT vIs347 - WHERE id = vXDiarioId; - - IF vIsIntracommunity THEN - UPDATE XDiario_movConta_IVA - SET Intracomunitaria = TRUE - WHERE id = vXDiarioId; - END IF; - - FETCH rs INTO vBase, - vVat, - vRate, - vIs340, - vIs347, - vVatRE, - vRateRE, - vTransactionCode, - vTaxCode, - vIsIntracommunity, - vOperationCode; - END WHILE; - CLOSE rs; - -- OTROS CAMPOS RELATIVOS A LAS FACTURAS - UPDATE XDiario_movConta_IVA xmi - JOIN vn.invoiceOut io ON io.id = vInvoiceOutFk - LEFT JOIN vn.invoiceCorrection ic ON ic.correctedFk = vInvoiceOutFk - LEFT JOIN vn.invoiceOut ioc ON ioc.id = ic.correctingFk - JOIN vn2008.XDiario x ON x.id = xmi.id - JOIN vn.client c ON c.id = io.clientFk - JOIN Naciones n ON n.countryFk = c.countryFk - JOIN vn.invoiceOutSerial ios ON ios.code = io.serial - JOIN vn.taxArea ta ON ta.code = ios.taxAreaFk - JOIN (SELECT SERIE - FROM vn2008.XDiario - WHERE ASIEN = (SELECT ASIEN - FROM vn2008.XDiario - WHERE id = vXDiarioId - ) - AND SERIE IS NOT NULL - ) sub - SET xmi.Año = YEAR(io.issued), - xmi.Serie = sub.SERIE, - xmi.Factura = RIGHT(io.ref, LENGTH(io.ref) -1), - xmi.FechaFactura = io.issued, - xmi.ImporteFactura = io.amount, - xmi.TipoFactura = "E", - xmi.CodigoCuentaFactura = x.SUBCTA, - xmi.CifDni = c.fi, - xmi.Nombre = SUBSTR(c.socialName,1,35), - xmi.SiglaNacion = n.SiglaNacion, - xmi.EjercicioFactura = YEAR(io.issued), - xmi.FechaOperacion = io.issued, - xmi.MantenerAsiento = TRUE, - xmi.FechaFacturaOriginal = x.FECHA_EX - WHERE xmi.id = vXDiarioId; - - -- RECTIFICATIVAS - SELECT correctedFk - INTO vInvoiceOutCorrectedFk - FROM vn.invoiceCorrection - WHERE correctingFk = vInvoiceOutFk; - - IF vInvoiceOutCorrectedFk THEN - UPDATE XDiario_movConta_IVA xmi - JOIN vn.invoiceOut ioc ON ioc.id = vInvoiceOutCorrectedFk - JOIN vn.invoiceCorrection ic ON ic.correctedFk = vInvoiceOutCorrectedFk - JOIN vn.invoiceOut io ON io.id = vInvoiceOutCorrectedFk - JOIN ( - SELECT sum(IF(IFNULL(e.vatFk,1),iot.taxableBase,0)) AS Base, - sum(IF(IFNULL(e.vatFk,1),iot.vat,0)) AS CuotaIva, - sum(IF(IFNULL(e.vatFk,1),0,iot.vat)) as RE - FROM vn.invoiceOutTax iot - LEFT JOIN vn.pgcEqu e ON e.vatFk = iot.pgcFk - WHERE iot.invoiceOutFk = vInvoiceOutCorrectedFk - ) iocTAX - SET xmi.TipoRectificativa = 2, - xmi.ClaseAbonoRectificativas = 1, -- ic.invoiceCorrectionTypeFk no coincide con las opcioens de SAGE * - xmi.FechaFacturaOriginal = io.issued, - xmi.FechaOperacion = io.issued, - xmi.BaseImponibleOriginal = iocTAX.Base, - xmi.CuotaIvaOriginal = iocTAX.CuotaIva, - xmi.RecargoEquivalenciaOriginal = RE, - xmi.ClaveOperacionFactura = 'D' - WHERE xmi.id = vXDiarioId; - /* - Envases y embalajes / descuentos y bonificaciones / eror fundado - Concurso de acreedores - Creditos incobrables - resto de tectificativas - Restificativas de facturas simplificadas - */ - 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: `salix` @@ -23508,10 +19593,10 @@ CREATE TABLE `userConfigView` ( `id` int(11) NOT NULL AUTO_INCREMENT, `userFk` int(10) unsigned NOT NULL, `tableCode` varchar(255) COLLATE utf8_unicode_ci NOT NULL, - `configuration` text COLLATE utf8_unicode_ci DEFAULT NULL, + `configuration` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`), UNIQUE KEY `uniqueUser_TableCode` (`userFk`,`tableCode`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -23542,7 +19627,7 @@ CREATE TABLE `inbound` ( `tableName` set('buy','sale') NOT NULL, `tableId` int(10) unsigned NOT NULL, `isSync` tinyint(4) NOT NULL, - `isPicked` tinyint(4) NOT NULL DEFAULT 0, + `isPicked` tinyint(4) NOT NULL DEFAULT '0', `warehouseFk` int(10) unsigned NOT NULL, `itemFk` int(10) unsigned NOT NULL, `dated` datetime NOT NULL, @@ -23568,7 +19653,7 @@ DELIMITER ;; BEFORE INSERT ON `inbound` FOR EACH ROW BEGIN - SET NEW.isPicked = NEW.isPicked OR NEW.dated < util.VN_CURDATE(); + SET NEW.isPicked = NEW.isPicked OR NEW.dated < vn.VN_CURDATE(); CALL visible_log( NEW.isPicked, @@ -23663,7 +19748,7 @@ CREATE TABLE `outbound` ( `tableName` set('sale','buy','orderRow') NOT NULL, `tableId` int(10) unsigned NOT NULL, `isSync` tinyint(3) unsigned NOT NULL, - `isPicked` tinyint(4) NOT NULL DEFAULT 0, + `isPicked` tinyint(4) NOT NULL DEFAULT '0', `warehouseFk` int(10) unsigned NOT NULL, `itemFk` int(10) unsigned NOT NULL, `dated` datetime NOT NULL, @@ -23692,7 +19777,7 @@ DELIMITER ;; FOR EACH ROW BEGIN SET NEW.lack = NEW.quantity; - SET NEW.isPicked = NEW.isPicked OR NEW.dated < util.VN_CURDATE(); + SET NEW.isPicked = NEW.isPicked OR NEW.dated < vn.VN_CURDATE(); CALL visible_log( NEW.isPicked, @@ -23802,6 +19887,8 @@ DELIMITER ; -- -- Dumping routines for database 'stock' -- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `inbound_addPick` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -23809,8 +19896,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `inbound_addPick`( vSelf INT, @@ -23831,6 +19916,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `inbound_removePick` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -23838,8 +19925,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `inbound_removePick`( vSelf INT, @@ -23864,6 +19949,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `inbound_requestQuantity` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -23871,8 +19958,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `inbound_requestQuantity`( vSelf INT, @@ -23938,6 +20023,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `inbound_sync` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -23945,8 +20032,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `inbound_sync`(vSelf INT) BEGIN @@ -24035,6 +20120,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `log_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24042,8 +20129,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `log_add`(IN `vTableName` VARCHAR(255), IN `vNewId` VARCHAR(255), IN `vOldId` VARCHAR(255)) proc: BEGIN @@ -24069,76 +20154,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 `log_add_beta__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `log_add_beta__`(IN `vTableName` VARCHAR(255), IN `vNewId` VARCHAR(255), IN `vOldId` VARCHAR(255)) -proc: BEGIN - -- XXX: Disabled while testing - DECLARE vLanded DATE; - DECLARE vWarehouseFk INT; - DECLARE vBuyerFk INT; - DECLARE vEntryFk INT; - DECLARE vItemFk INT; - DECLARE vItemName VARCHAR(50); - - -- LEAVE proc; - - IF vOldId IS NOT NULL AND !(vOldId <=> vNewId) THEN - INSERT IGNORE INTO `log` SET - tableName = vTableName, - tableId = vOldId, - operation = 'delete'; - END IF; - - IF vNewId IS NOT NULL THEN - INSERT IGNORE INTO `log` SET - tableName = vTableName, - tableId = vNewId, - operation = 'insert'; - END IF; - - IF vTableName = 'buy' THEN - - SELECT IFNULL(tr.landed,'2000-01-01') - INTO vLanded - FROM vn.travel tr - JOIN vn.entry e ON e.travelFk = tr.id - JOIN vn.buy b ON b.entryFk = e.id - JOIN vn.warehouse w ON w.id = tr.warehouseInFk - WHERE b.id = vNewId - AND w.isBuyerToBeEmailed; - - IF vLanded = util.VN_CURDATE() THEN - - SELECT it.workerFk, b.entryFk, i.id, i.longName - INTO vBuyerFk, vEntryFk, vItemFk, vItemName - FROM vn.itemType it - JOIN vn.item i ON i.typeFk = it.id - JOIN vn.buy b ON b.itemFk = i.id - WHERE b.id = vNewId; - - CALL vn.mail_insert(CONCAT(account.user_getNameFromId(vBuyerFk),'@verdnatura.es'), - CONCAT(account.myUser_getName(),'@verdnatura.es'), - CONCAT('E-',vEntryFk,' Se ha modificado item ', vItemFk, ' ',vItemName), - 'Este email se ha generado automáticamente'); - - END IF; - END IF; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `log_clean` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24146,8 +20163,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `log_clean`() BEGIN @@ -24159,6 +20174,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `log_delete` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24166,8 +20183,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `log_delete`(vTableName VARCHAR(255), vTableId INT) proc: BEGIN @@ -24191,6 +20206,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `log_refreshAll` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24198,8 +20215,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `log_refreshAll`() BEGIN @@ -24237,6 +20252,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `log_refreshBuy` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24244,8 +20261,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `log_refreshBuy`( `vTableName` VARCHAR(255), @@ -24324,6 +20339,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `log_refreshOrder` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24331,15 +20348,13 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `log_refreshOrder`( `vTableName` VARCHAR(255), `vTableId` INT) BEGIN DECLARE vExpireTime INT DEFAULT 20; - DECLARE vExpired DATETIME DEFAULT TIMESTAMPADD(MINUTE, -vExpireTime, util.VN_NOW()); + DECLARE vExpired DATETIME DEFAULT TIMESTAMPADD(MINUTE, -vExpireTime, vn.VN_NOW()); DROP TEMPORARY TABLE IF EXISTS tValues; CREATE TEMPORARY TABLE tValues @@ -24384,6 +20399,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `log_refreshSale` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24391,8 +20408,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `log_refreshSale`( `vTableName` VARCHAR(255), @@ -24462,6 +20477,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `log_sync` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24469,8 +20486,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `log_sync`(vSync BOOL) proc: BEGIN @@ -24543,7 +20558,7 @@ proc: BEGIN -- Deletes expired outbounds - DELETE FROM outbound WHERE expired <= util.VN_NOW(); + DELETE FROM outbound WHERE expired <= vn.VN_NOW(); -- Attaches desync inbounds @@ -24598,6 +20613,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `log_syncNoWait` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24605,8 +20622,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `log_syncNoWait`() BEGIN @@ -24627,6 +20642,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `outbound_requestQuantity` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24634,8 +20651,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `outbound_requestQuantity`( vSelf INT, @@ -24701,6 +20716,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `outbound_sync` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24708,8 +20725,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `outbound_sync`(vSelf INT) BEGIN @@ -24792,6 +20807,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `visible_log` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24799,8 +20816,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `visible_log`( vIsPicked BOOL, @@ -24830,8 +20845,7 @@ DELIMITER ; -- Current Database: `util` -- - -CREATE SCHEMA IF NOT EXISTS `util`; +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `util` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */; USE `util`; @@ -24845,7 +20859,7 @@ DROP TABLE IF EXISTS `config`; CREATE TABLE `config` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `dbVersion` char(11) CHARACTER SET utf8 DEFAULT NULL COMMENT 'The current database version', - `hasTriggersDisabled` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Defines if triggers are disabled', + `hasTriggersDisabled` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Defines if triggers are disabled', `environment` varchar(45) CHARACTER SET utf8 DEFAULT NULL COMMENT 'The current Database environment', `lastDump` datetime DEFAULT NULL COMMENT 'Timestamp of the last data dump', PRIMARY KEY (`id`) @@ -24861,7 +20875,7 @@ DROP TABLE IF EXISTS `debug`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `debug` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, - `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `connectionId` int(10) unsigned DEFAULT NULL, `user` varchar(255) CHARACTER SET utf8 DEFAULT NULL, `host` varchar(255) CHARACTER SET utf8 DEFAULT NULL, @@ -24869,7 +20883,7 @@ CREATE TABLE `debug` ( `value` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `created` (`created`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Log de depuración'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Log de depuración'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -24897,7 +20911,7 @@ DROP TABLE IF EXISTS `versionLog`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `versionLog` ( - `code` varchar(200) COLLATE utf8_unicode_ci NOT NULL, + `code` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `number` char(11) COLLATE utf8_unicode_ci NOT NULL, `file` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `user` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, @@ -24936,6 +20950,8 @@ DELIMITER ; -- -- Dumping routines for database 'util' -- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `accountShortToStandard` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24943,8 +20959,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `accountShortToStandard`(vAccount VARCHAR(10)) RETURNS varchar(10) CHARSET utf8 COLLATE utf8_unicode_ci DETERMINISTIC @@ -24956,6 +20970,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `capitalizeFirst` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -24963,8 +20979,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `capitalizeFirst`(vString VARCHAR(255)) RETURNS varchar(255) CHARSET utf8 NO SQL @@ -25010,6 +21024,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `crypt` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25017,8 +21033,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `crypt`(vText VARCHAR(255), vKey VARCHAR(255)) RETURNS varchar(255) CHARSET utf8 READS SQL DATA @@ -25036,6 +21050,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `cryptOff` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25043,8 +21059,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `cryptOff`(vText VARCHAR(255), vKey VARCHAR(255)) RETURNS varchar(255) CHARSET utf8 READS SQL DATA @@ -25062,15 +21076,15 @@ 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 `dayend` */; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `dayEnd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `dayend`(vDated DATE) RETURNS datetime NO SQL @@ -25089,6 +21103,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `firstDayOfMonth` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25096,8 +21112,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `firstDayOfMonth`(vDate DATE) RETURNS date NO SQL @@ -25116,6 +21130,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `firstDayOfYear` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25123,8 +21139,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `firstDayOfYear`(vDate DATE) RETURNS date NO SQL @@ -25143,6 +21157,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `formatRow` */; +/*!50003 SET @saved_cs_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `formatRow`(vType CHAR(3), vValues VARCHAR(512)) RETURNS varchar(512) CHARSET utf8 COLLATE utf8_unicode_ci + DETERMINISTIC +BEGIN + DECLARE vRow VARCHAR(512); + + IF vValues IS NOT NULL THEN + SET vRow = CONCAT(' + + ', vType ,' + ', REPLACE(vValues, ',', '') ,' + + '); + ELSE + SET vRow = ''; + END IF; + + RETURN vRow; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `formatTable` */; +/*!50003 SET @saved_cs_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `formatTable`(vFields VARCHAR(512), vOldValues VARCHAR(512), vNewValues VARCHAR(512)) RETURNS text CHARSET utf8 COLLATE utf8_unicode_ci + DETERMINISTIC +BEGIN + DECLARE vTable TEXT; + + SET vTable = CONCAT(' + + + + + + ', formatRow('old', vOldValues) ,' + ', formatRow('new', vNewValues) ,' + +
type', REPLACE(vFields, ',', '') ,' +
+ '); + + RETURN vTable; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `hasDateOverlapped` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25150,8 +21234,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `hasDateOverlapped`(vSarted1 DATE, vEnded1 DATE, vSarted2 DATE, vEnded2 DATE) RETURNS tinyint(1) DETERMINISTIC @@ -25165,6 +21247,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `hmacSha2` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25172,8 +21256,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `hmacSha2`(`vAlg` SMALLINT, `vMsg` MEDIUMBLOB, `vKey` MEDIUMBLOB) RETURNS varchar(128) CHARSET utf8 NO SQL @@ -25209,6 +21291,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `isLeapYear` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25216,8 +21300,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `isLeapYear`(vYear INT) RETURNS tinyint(1) DETERMINISTIC @@ -25231,6 +21313,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `lang` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25238,8 +21322,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `lang`() RETURNS char(2) CHARSET utf8 NO SQL @@ -25257,6 +21339,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `lastDayOfYear` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25264,8 +21348,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `lastDayOfYear`(vDate DATE) RETURNS date NO SQL @@ -25284,6 +21366,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `midnight` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25291,14 +21375,12 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `midnight`() RETURNS datetime READS SQL DATA BEGIN - RETURN TIMESTAMP(util.VN_CURDATE(), '23:59:59'); + RETURN TIMESTAMP(vn.VN_CURDATE(), '23:59:59'); END ;; DELIMITER ; @@ -25306,6 +21388,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `nextWeek` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25313,8 +21397,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `nextWeek`(vYearWeek INT) RETURNS int(11) DETERMINISTIC @@ -25337,6 +21419,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `quarterFirstDay` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25344,8 +21428,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `quarterFirstDay`(vYear INT, vQuarter INT) RETURNS date DETERMINISTIC @@ -25357,6 +21439,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `stringXor` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25364,8 +21448,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `stringXor`(vString MEDIUMBLOB, vConst TINYINT UNSIGNED) RETURNS mediumblob NO SQL @@ -25393,6 +21475,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `today` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25400,26 +21484,26 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `today`() RETURNS date DETERMINISTIC BEGIN /** * Devuelve la fecha actual. Usar en lugar de la función nativa - * util.VN_CURDATE() en aquellos que se necesite rendimiento ya que la + * vn.VN_CURDATE() en aquellos que se necesite rendimiento ya que la * la última no es determinista. * * @return La fecha actual */ - RETURN util.VN_CURDATE(); + RETURN vn.VN_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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `tomorrow` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25427,8 +21511,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `tomorrow`() RETURNS date DETERMINISTIC @@ -25438,13 +21520,15 @@ BEGIN * * @return La fecha de mañana */ - RETURN TIMESTAMPADD(DAY, 1, util.VN_CURDATE()); + RETURN TIMESTAMPADD(DAY, 1, vn.VN_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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `twoDaysAgo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25452,8 +21536,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `twoDaysAgo`() RETURNS date DETERMINISTIC @@ -25463,13 +21545,15 @@ BEGIN * * @return La fecha de antes de ayer */ - RETURN TIMESTAMPADD(DAY, -2, util.VN_CURDATE()); + RETURN TIMESTAMPADD(DAY, -2, vn.VN_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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `yearRelativePosition` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25477,8 +21561,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `yearRelativePosition`(vYear INT) RETURNS varchar(20) CHARSET utf8 DETERMINISTIC @@ -25490,7 +21572,7 @@ BEGIN * @param vYear Año a evaluar * @return La posicion relativa del año */ - DECLARE vCurYear INT DEFAULT YEAR(util.VN_CURDATE()); + DECLARE vCurYear INT DEFAULT YEAR(vn.VN_CURDATE()); IF vYear = vCurYear THEN RETURN 'curYear'; @@ -25511,6 +21593,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `yesterday` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25518,8 +21602,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `yesterday`() RETURNS date DETERMINISTIC @@ -25529,13 +21611,15 @@ BEGIN * * @return La fecha de ayer */ - RETURN TIMESTAMPADD(DAY, -1, util.VN_CURDATE()); + RETURN TIMESTAMPADD(DAY, -1, vn.VN_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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `compareObjects` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25543,8 +21627,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `compareObjects`(vChain VARCHAR(45),vCompare VARCHAR(45)) READS SQL DATA @@ -25652,6 +21734,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `debugAdd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25659,8 +21743,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `debugAdd`(vVariable VARCHAR(255), vValue VARCHAR(255)) MODIFIES SQL DATA @@ -25685,6 +21767,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `exec` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25692,8 +21776,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `exec`(vSqlQuery TEXT) BEGIN @@ -25715,6 +21797,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `findObject` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25722,8 +21806,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `findObject`(vChain VARCHAR(45)) READS SQL DATA @@ -25786,6 +21868,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `procNoOverlap` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25793,8 +21877,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `procNoOverlap`(procName VARCHAR(255)) SQL SECURITY INVOKER @@ -25823,6 +21905,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `proc_changedPrivs` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25830,8 +21914,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_changedPrivs`() BEGIN @@ -25851,6 +21933,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `proc_restorePrivs` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25858,8 +21942,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_restorePrivs`() BEGIN @@ -25879,6 +21961,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `proc_savePrivs` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25886,8 +21970,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_savePrivs`() BEGIN @@ -25907,6 +21989,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `slowLog_prune` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25914,30 +21998,30 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `slowLog_prune`() -BEGIN -/** - * Prunes MySQL slow query log table deleting all records older than one week. - */ - DECLARE vSlowQueryLog INT DEFAULT @@slow_query_log; - - SET GLOBAL slow_query_log = 'OFF'; - RENAME TABLE `mysql`.`slow_log` TO `mysql`.`slow_log_temp`; - - DELETE FROM `mysql`.`slow_log_temp` - WHERE start_time < TIMESTAMPADD(WEEK, -1, util.VN_NOW()); - - RENAME TABLE `mysql`.`slow_log_temp` TO `mysql`.`slow_log`; - SET GLOBAL slow_query_log = vSlowQueryLog; +BEGIN +/** + * Prunes MySQL slow query log table deleting all records older than one week. + */ + DECLARE vSlowQueryLog INT DEFAULT @@slow_query_log; + + SET GLOBAL slow_query_log = 'OFF'; + RENAME TABLE `mysql`.`slow_log` TO `mysql`.`slow_log_temp`; + + DELETE FROM `mysql`.`slow_log_temp` + WHERE start_time < TIMESTAMPADD(WEEK, -1, vn.VN_NOW()); + + RENAME TABLE `mysql`.`slow_log_temp` TO `mysql`.`slow_log`; + SET GLOBAL slow_query_log = vSlowQueryLog; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `throw` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25945,8 +22029,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `throw`(vMessage CHAR(55)) BEGIN @@ -25963,6 +22045,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `time_createTable` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25970,8 +22054,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `time_createTable`(vStarted DATE, vEnded DATE) BEGIN @@ -25991,6 +22073,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `warn` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -25998,8 +22082,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `warn`(vCode CHAR(35)) BEGIN @@ -26056,7 +22138,7 @@ CREATE TABLE `XDiario` ( `FACTURA` varchar(8) COLLATE utf8_unicode_ci DEFAULT '0', `BASEIMPO` decimal(10,2) DEFAULT NULL, `IVA` decimal(10,2) DEFAULT NULL, - `RECEQUIV` decimal(10,2) DEFAULT 0.00, + `RECEQUIV` decimal(10,2) DEFAULT '0.00', `DOCUMENTO` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `DEPARTA` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `CLAVE` int(11) DEFAULT NULL, @@ -26074,24 +22156,24 @@ CREATE TABLE `XDiario` ( `CODDIVISA` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, `IMPAUXME` decimal(10,2) DEFAULT NULL, `MONEDAUSO` varchar(1) COLLATE utf8_unicode_ci DEFAULT '2', - `NOCONV` tinyint(1) NOT NULL DEFAULT 0, + `NOCONV` tinyint(1) NOT NULL DEFAULT '0', `NUMEROINV` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `TIPOOPE` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, - `NFACTICK` tinyint(1) NOT NULL DEFAULT 1, - `TERIDNIF` tinyint(1) NOT NULL DEFAULT 2, + `NFACTICK` tinyint(1) NOT NULL DEFAULT '1', + `TERIDNIF` tinyint(1) NOT NULL DEFAULT '2', `TERNIF` varchar(20) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'I.F.', `TERNOM` varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Nombre Importador', - `OPBIENES` tinyint(1) NOT NULL DEFAULT 1, + `OPBIENES` tinyint(1) NOT NULL DEFAULT '1', `TIPOFAC` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `TIPOIVA` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, - `L340` tinyint(2) NOT NULL DEFAULT 0, - `enlazado` tinyint(1) NOT NULL DEFAULT 0, + `L340` tinyint(2) NOT NULL DEFAULT '0', + `enlazado` tinyint(1) NOT NULL DEFAULT '0', `FECHA_EX` date DEFAULT NULL COMMENT 'FEcha de expedicion de la factura', - `LRECT349` tinyint(1) NOT NULL DEFAULT 0, - `empresa_id` smallint(5) unsigned NOT NULL DEFAULT 442, - `LDIFADUAN` tinyint(4) NOT NULL DEFAULT 0, - `METAL` tinyint(1) NOT NULL DEFAULT 0, - `METALIMP` decimal(10,2) NOT NULL DEFAULT 0.00, + `LRECT349` tinyint(1) NOT NULL DEFAULT '0', + `empresa_id` smallint(5) unsigned NOT NULL DEFAULT '442', + `LDIFADUAN` tinyint(4) NOT NULL DEFAULT '0', + `METAL` tinyint(1) NOT NULL DEFAULT '0', + `METALIMP` decimal(10,2) NOT NULL DEFAULT '0.00', `CLIENTE` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, `METALEJE` varchar(4) COLLATE utf8_unicode_ci DEFAULT NULL, `FECHA_OP` date DEFAULT NULL COMMENT 'FEcha de operacion', @@ -26105,12 +22187,12 @@ CREATE TABLE `XDiario` ( `FACTU_RT` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `BASEIMP_RT` decimal(10,2) DEFAULT NULL, `BASEIMP_RF` decimal(10,2) DEFAULT NULL, - `RECTIFICA` int(1) NOT NULL DEFAULT 0, + `RECTIFICA` int(1) NOT NULL DEFAULT '0', `FECHA_RT` date DEFAULT NULL, - `created` timestamp NULL DEFAULT current_timestamp(), - `updated` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `FECREGCON` date DEFAULT NULL, - `enlazadoSage` tinyint(1) NOT NULL DEFAULT 0, + `enlazadoSage` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `empresa_id` (`empresa_id`), KEY `ASIENidx` (`id`,`ASIEN`), @@ -26118,7 +22200,7 @@ CREATE TABLE `XDiario` ( KEY `XDiario` (`enlazado`), KEY `enlazadoSage` (`enlazadoSage`), CONSTRAINT `XDiario_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -26169,23 +22251,41 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; -- --- Temporary table structure for view `absenceType` +-- Temporary table structure for view `__coolerPathDetail` +-- + +DROP TABLE IF EXISTS `__coolerPathDetail`; +/*!50001 DROP VIEW IF EXISTS `__coolerPathDetail`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `__coolerPathDetail` ( + `id` tinyint NOT NULL, + `coolerPathFk` tinyint NOT NULL, + `hallway` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + +-- +-- Table structure for table `absenceType` -- DROP TABLE IF EXISTS `absenceType`; -/*!50001 DROP VIEW IF EXISTS `absenceType`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `absenceType` ( - `id` tinyint NOT NULL, - `name` tinyint NOT NULL, - `rgb` tinyint NOT NULL, - `code` tinyint NOT NULL, - `permissionRate` tinyint NOT NULL, - `holidayEntitlementRate` tinyint NOT NULL, - `discountRate` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `absenceType` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(30) NOT NULL, + `rgb` varchar(7) NOT NULL, + `color` bigint(20) DEFAULT '0', + `permissionRate` decimal(3,2) DEFAULT NULL, + `code` varchar(45) DEFAULT NULL, + `isAllowedToWork` tinyint(4) NOT NULL DEFAULT '0', + `isPrintable` tinyint(1) NOT NULL DEFAULT '0', + `discountRate` decimal(3,2) DEFAULT NULL, + `holidayEntitlementRate` decimal(3,2) DEFAULT '1.00', + PRIMARY KEY (`id`) +) ENGINE=InnoDBDEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; -- -- Table structure for table `accounting` @@ -26195,13 +22295,13 @@ DROP TABLE IF EXISTS `accounting`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `accounting` ( - `id` int(11) NOT NULL DEFAULT 0, + `id` int(11) NOT NULL DEFAULT '0', `bank` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `account` varchar(10) CHARACTER SET utf8 DEFAULT NULL, - `accountingTypeFk` smallint(6) NOT NULL DEFAULT 0, - `entityFk` int(10) unsigned NOT NULL, - `isActive` tinyint(4) NOT NULL DEFAULT 1, - `currencyFk` tinyint(3) unsigned DEFAULT 1, + `accountingTypeFk` smallint(6) NOT NULL DEFAULT '0', + `entityFk` int(10) unsigned DEFAULT NULL, + `isActive` tinyint(4) NOT NULL DEFAULT '1', + `currencyFk` tinyint(3) unsigned DEFAULT '1', `code` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `BancosBanco` (`bank`), @@ -26209,6 +22309,7 @@ CREATE TABLE `accounting` ( KEY `foreignkey1_idx` (`accountingTypeFk`), KEY `Bancoscurrency_idx` (`currencyFk`), CONSTRAINT `Bancoscurrency` FOREIGN KEY (`currencyFk`) REFERENCES `currency` (`id`) ON UPDATE CASCADE, + CONSTRAINT `accounting_FK` FOREIGN KEY (`entityFk`) REFERENCES `bankEntity` (`id`) ON UPDATE CASCADE, CONSTRAINT `bank_FK` FOREIGN KEY (`accountingTypeFk`) REFERENCES `accountingType` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Apunta a la vista vn.Accounting\nLa columna cash es la FK de vn.AccountingType'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -26221,11 +22322,11 @@ DROP TABLE IF EXISTS `accountingType`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `accountingType` ( - `id` smallint(6) NOT NULL DEFAULT 0, + `id` smallint(6) NOT NULL DEFAULT '0', `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `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', + `isAutoConciliated` tinyint(1) DEFAULT '1' COMMENT 'Si hay que marcar como conciliado el recibo al usar este tipo', `maxAmount` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `accountingType_code_IDX` (`code`) USING BTREE @@ -26233,13 +22334,13 @@ CREATE TABLE `accountingType` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `activeContrat` +-- Table structure for table `activeContrat__` -- -DROP TABLE IF EXISTS `activeContrat`; +DROP TABLE IF EXISTS `activeContrat__`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `activeContrat` ( +CREATE TABLE `activeContrat__` ( `date` date NOT NULL, `business_id` int(11) NOT NULL, PRIMARY KEY (`date`,`business_id`) @@ -26255,9 +22356,9 @@ DROP TABLE IF EXISTS `activityTaxDismissed`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `activityTaxDismissed` ( `clientFk` int(11) NOT NULL, - `isNotified` tinyint(1) DEFAULT 0, - `isDismissed` tinyint(1) DEFAULT 0, - `notified` int(11) DEFAULT 0, + `isNotified` tinyint(1) DEFAULT '0', + `isDismissed` tinyint(1) DEFAULT '0', + `notified` int(11) DEFAULT '0', PRIMARY KEY (`clientFk`), CONSTRAINT `clientFk` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -26272,8 +22373,8 @@ DROP TABLE IF EXISTS `address`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `address` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `clientFk` int(11) NOT NULL DEFAULT 0, - `warehouseFk__` smallint(6) unsigned DEFAULT 1, + `clientFk` int(11) NOT NULL DEFAULT '0', + `warehouseFk__` smallint(6) unsigned DEFAULT '1', `street` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `city` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `provinceFk` smallint(5) unsigned DEFAULT NULL, @@ -26281,12 +22382,12 @@ CREATE TABLE `address` ( `phone` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `mobile` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `nickname` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL, - `isDefaultAddress` tinyint(1) NOT NULL DEFAULT 0, - `agencyModeFk` int(11) NOT NULL DEFAULT 2, + `isDefaultAddress` tinyint(1) NOT NULL DEFAULT '0', + `agencyModeFk` int(11) NOT NULL DEFAULT '2', `notes__` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `hasInsurance__` tinyint(1) NOT NULL DEFAULT 0, + `hasInsurance__` tinyint(1) NOT NULL DEFAULT '0', `porte__` double DEFAULT NULL, - `isActive` tinyint(4) NOT NULL DEFAULT 1, + `isActive` tinyint(4) NOT NULL DEFAULT '1', `postcodeOLD__` int(11) unsigned DEFAULT NULL, `longitude` decimal(11,7) DEFAULT NULL, `latitude` decimal(11,7) DEFAULT NULL, @@ -26294,8 +22395,8 @@ CREATE TABLE `address` ( `isEqualizated` tinyint(1) DEFAULT NULL, `customsAgentFk` int(11) DEFAULT NULL, `incotermsFk` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, - `isVilassarBuyer__` tinyint(4) NOT NULL DEFAULT 0, - `isLogifloraAllowed` tinyint(4) NOT NULL DEFAULT 0, + `isVilassarBuyer__` tinyint(4) NOT NULL DEFAULT '0', + `isLogifloraAllowed` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `Id_Agencia` (`agencyModeFk`), KEY `Id_cliente` (`clientFk`), @@ -26434,12 +22535,12 @@ DROP TABLE IF EXISTS `addressFilter`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `addressFilter` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `provinceFk` smallint(5) unsigned DEFAULT NULL, `countryFk` mediumint(8) unsigned DEFAULT NULL, - `isLogifloraAllowed` tinyint(1) DEFAULT 0, - `isVNHSupplier` tinyint(1) DEFAULT 0 COMMENT 'corresponde al campo edi.VMPSettings.isVNHSupplier', - `isEarlyBird` tinyint(1) DEFAULT 0 COMMENT 'corresponde al campo edi.marketPlace.isEarlybird', + `isLogifloraAllowed` tinyint(1) DEFAULT '0', + `isVNHSupplier` tinyint(1) DEFAULT '0' COMMENT 'corresponde al campo edi.VMPSettings.isVNHSupplier', + `isEarlyBird` tinyint(1) DEFAULT '0' COMMENT 'corresponde al campo edi.marketPlace.isEarlybird', `warehouseFk` smallint(5) unsigned DEFAULT NULL, `beforeDated` date DEFAULT NULL, `afterDated` date DEFAULT NULL, @@ -26450,7 +22551,7 @@ CREATE TABLE `addressFilter` ( CONSTRAINT `addressFilter_FK` FOREIGN KEY (`provinceFk`) REFERENCES `province` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `addressFilter_FK_1` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `addressFilter_FK_2` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Establece los criterios para habilitar las compras directas a Logiflora'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Establece los criterios para habilitar las compras directas a Logiflora'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26462,7 +22563,7 @@ DROP TABLE IF EXISTS `addressForPackaging`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `addressForPackaging` ( `addressFk` int(11) NOT NULL, - `packagingValue` decimal(10,2) NOT NULL DEFAULT 0.04, + `packagingValue` decimal(10,2) NOT NULL DEFAULT '0.04', PRIMARY KEY (`addressFk`), CONSTRAINT `addresForPackaging_fk1` FOREIGN KEY (`addressFk`) REFERENCES `address` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -26499,22 +22600,23 @@ CREATE TABLE `agency` ( `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(25) COLLATE utf8_unicode_ci NOT NULL, `warehouseFk` smallint(5) unsigned DEFAULT NULL COMMENT 'A nulo si se puede enrutar desde todos los almacenes', - `isVolumetric` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'Si el calculo del porte se hacer por volumen', - `bankFk` int(11) NOT NULL DEFAULT 8 COMMENT 'para realizar los reembolsos', + `isVolumetric__` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Si el calculo del porte se hacer por volumen', + `bankFk__` int(11) NOT NULL DEFAULT '8' COMMENT 'para realizar los reembolsos', `warehouseAliasFk` smallint(5) unsigned DEFAULT NULL, - `isOwn` tinyint(1) NOT NULL DEFAULT 0, - `labelZone` tinyint(4) NOT NULL DEFAULT 0, + `isOwn` tinyint(1) NOT NULL DEFAULT '0', + `labelZone__` tinyint(4) NOT NULL DEFAULT '0', `workCenterFk` int(11) DEFAULT NULL, `supplierFk__` int(11) DEFAULT NULL, `isAnyVolumeAllowed` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Permite vender productos que tengan vn.itemType.IsUnconventionalSize = TRUE', PRIMARY KEY (`id`), KEY `warehouse_id` (`warehouseFk`), - KEY `Id_Banco` (`bankFk`), + KEY `Id_Banco` (`bankFk__`), KEY `agencias_alias_idx` (`warehouseAliasFk`), KEY `agency_ibfk_3_idx` (`workCenterFk`), KEY `agency_ibfk_4_idx` (`supplierFk__`), + CONSTRAINT `agency_FK` FOREIGN KEY (`warehouseAliasFk`) REFERENCES `warehouseAlias` (`id`) ON UPDATE CASCADE, CONSTRAINT `agency_ibfk_1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, - CONSTRAINT `agency_ibfk_2` FOREIGN KEY (`bankFk`) REFERENCES `accounting` (`id`) ON UPDATE CASCADE, + CONSTRAINT `agency_ibfk_2` FOREIGN KEY (`bankFk__`) REFERENCES `accounting` (`id`) ON UPDATE CASCADE, CONSTRAINT `agency_ibfk_3` FOREIGN KEY (`workCenterFk`) REFERENCES `workCenter` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -26571,19 +22673,19 @@ CREATE TABLE `agencyMode` ( `name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `description` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `deliveryMethodFk` int(11) DEFAULT NULL, - `m3` double DEFAULT 0, - `cod71__` tinyint(3) unsigned DEFAULT 0, - `web` smallint(1) unsigned zerofill NOT NULL DEFAULT 0, + `m3` double DEFAULT '0', + `cod71__` tinyint(3) unsigned DEFAULT '0', + `web` smallint(1) unsigned zerofill NOT NULL DEFAULT '0', `agencyFk` smallint(5) unsigned NOT NULL, - `inflation` decimal(5,2) NOT NULL DEFAULT 0.00 COMMENT 'Este valor se utiliza para aumentar el valor del componente porte.', - `isVolumetric` tinyint(1) NOT NULL DEFAULT 0, + `inflation` decimal(5,2) NOT NULL DEFAULT '0.00' COMMENT 'Este valor se utiliza para aumentar el valor del componente porte.', + `isVolumetric` tinyint(1) NOT NULL DEFAULT '0', `reportMail` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, - `showAgencyName` tinyint(1) DEFAULT 1 COMMENT 'obsoleta', - `isActive` tinyint(1) NOT NULL DEFAULT 1, - `isExternalAgency` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'obsoleta', - `flag` blob DEFAULT NULL COMMENT 'obsoleta', + `showAgencyName` tinyint(1) DEFAULT '1' COMMENT 'obsoleta', + `isActive` tinyint(1) NOT NULL DEFAULT '1', + `isExternalAgency` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'obsoleta', + `flag` blob COMMENT 'obsoleta', `code` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `isRiskFree` tinyint(1) NOT NULL DEFAULT 0, + `isRiskFree` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `Agencias` (`name`), KEY `Vista` (`deliveryMethodFk`), @@ -26614,26 +22716,6 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; --- --- Temporary table structure for view `agencyTerm` --- - -DROP TABLE IF EXISTS `agencyTerm`; -/*!50001 DROP VIEW IF EXISTS `agencyTerm`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `agencyTerm` ( - `agencyFk` tinyint NOT NULL, - `minimumPackages` tinyint NOT NULL, - `kmPrice` tinyint NOT NULL, - `packagePrice` tinyint NOT NULL, - `routePrice` tinyint NOT NULL, - `minimumKm` tinyint NOT NULL, - `minimumM3` tinyint NOT NULL, - `m3Price` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - -- -- Table structure for table `agencyTermConfig` -- @@ -26705,7 +22787,7 @@ CREATE TABLE `assignedTicketToWorker` ( PRIMARY KEY (`id`), UNIQUE KEY `idWorker_UNIQUE` (`idWorker`), UNIQUE KEY `idTicket_UNIQUE` (`idTicket`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla para relacionar un ticket con el sacador del altillo '; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla para relacionar un ticket con el sacador del altillo '; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26736,12 +22818,12 @@ DROP TABLE IF EXISTS `autoRadioLogCall`; CREATE TABLE `autoRadioLogCall` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ticketFk` int(11) NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `response` longtext COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), KEY `ticket_idx` (`ticketFk`), CONSTRAINT `ticket` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26759,7 +22841,7 @@ CREATE TABLE `autonomousRegion__` ( PRIMARY KEY (`id`), KEY `countryFk` (`countryFk`), CONSTRAINT `countryFk` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -26864,12 +22946,12 @@ CREATE TABLE `awb` ( `code` varchar(18) COLLATE utf8_unicode_ci NOT NULL, `package` float unsigned NOT NULL, `weight` float unsigned DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `transitoryFk` int(11) DEFAULT NULL, - `taxFk` int(10) unsigned DEFAULT 62, + `taxFk` int(10) unsigned DEFAULT '62', `duakk` varchar(18) COLLATE utf8_unicode_ci DEFAULT NULL, `docFk` int(11) DEFAULT NULL, - `amount` double NOT NULL DEFAULT 0, + `amount` double NOT NULL DEFAULT '0', `freightFk` int(11) DEFAULT NULL, `m3` double unsigned DEFAULT NULL, `stems` int(10) unsigned DEFAULT NULL, @@ -26882,11 +22964,11 @@ CREATE TABLE `awb` ( `operated` datetime DEFAULT NULL, `bookEntried` date DEFAULT NULL, `invoiceInFk` mediumint(8) unsigned DEFAULT NULL, - `isChecked` tinyint(3) DEFAULT 0, - `isTransitoryChecked` tinyint(3) DEFAULT 0, + `isChecked` tinyint(3) DEFAULT '0', + `isTransitoryChecked` tinyint(3) DEFAULT '0', `year` int(4) DEFAULT NULL, `observation` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `hasFreightPrepaid` tinyint(3) DEFAULT 0, + `hasFreightPrepaid` tinyint(3) DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `codigo_UNIQUE` (`code`,`year`), KEY `proveedor_id` (`transitoryFk`), @@ -26894,8 +22976,12 @@ CREATE TABLE `awb` ( KEY `carguera_id` (`freightFk`), KEY `flight_id` (`flightFk`), KEY `awbInvoiceIn` (`invoiceInFk`), + KEY `awb_FK` (`docFk`), CONSTRAINT `awbInvoiceIn` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `awbTransitoryFk` FOREIGN KEY (`transitoryFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE, + CONSTRAINT `awb_FK` FOREIGN KEY (`docFk`) REFERENCES `dms` (`id`) ON UPDATE CASCADE, + CONSTRAINT `awb_FK_1` FOREIGN KEY (`flightFk`) REFERENCES `vn2008`.`flight` (`flight_id`) ON UPDATE CASCADE, + CONSTRAINT `awb_FK_2` FOREIGN KEY (`freightFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE, CONSTRAINT `awb_ibfk_1` FOREIGN KEY (`taxFk`) REFERENCES `taxCode` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -26913,7 +22999,7 @@ DELIMITER ;; FOR EACH ROW BEGIN - SET NEW.year= year(util.VN_CURDATE()); + SET NEW.year= year(vn.VN_CURDATE()); END */;; @@ -26922,30 +23008,21 @@ 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 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`awb_au` - AFTER UPDATE ON `awb` - FOR EACH ROW -BEGIN - IF NEW.amount <> OLD.amount THEN - CALL vn2008.buy_tarifas_awb(NEW.code); - END IF; +-- +-- Temporary table structure for view `awbVolume` +-- -END */;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; +DROP TABLE IF EXISTS `awbVolume`; +/*!50001 DROP VIEW IF EXISTS `awbVolume`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `awbVolume` ( + `awbFk` tinyint NOT NULL, + `volume` tinyint NOT NULL, + `buyFk` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; -- -- Temporary table structure for view `bank` @@ -26975,16 +23052,103 @@ DROP TABLE IF EXISTS `bankEntity`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `bankEntity` ( - `countryFk` mediumint(8) unsigned NOT NULL DEFAULT 1, + `countryFk` mediumint(8) unsigned NOT NULL DEFAULT '1', `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, - `bic` varchar(11) CHARACTER SET utf8 DEFAULT NULL, + `bic` varchar(11) CHARACTER SET utf8 NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `bic_UNIQUE` (`bic`), KEY `fg_entity1_idx` (`countryFk`), CONSTRAINT `fg_entity1` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Entidades bancarias '; /*!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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`bankEntity_beforeInsert` + BEFORE INSERT ON `bankEntity` + FOR EACH ROW +BEGIN + CALL bankEntity_checkBic(NEW.bic); +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`bankEntity_beforeUpdate` + BEFORE UPDATE ON `bankEntity` + FOR EACH ROW +BEGIN + IF NOT (NEW.bic <=> OLD.bic) THEN + CALL bankEntity_checkBic(NEW.bic); + 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 `bankEntityConfig` +-- + +DROP TABLE IF EXISTS `bankEntityConfig`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `bankEntityConfig` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `bicLength` tinyint(4) DEFAULT '11' COMMENT 'Tamaño del campo bic', + PRIMARY KEY (`id`) +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!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` @@ -26994,13 +23158,9 @@ DROP TABLE IF EXISTS `beach`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `beach` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `warehouseFk` smallint(6) NOT NULL, - `x` int(11) NOT NULL, - `y` int(11) NOT NULL, - `name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `isShowed` tinyint(1) DEFAULT 0, - PRIMARY KEY (`id`) + `code` varchar(45) COLLATE utf8_unicode_ci NOT NULL, + `warehouseFk` smallint(6) NOT NULL DEFAULT '60', + PRIMARY KEY (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Ubicaciones respecto a la playa del almacén'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -27030,12 +23190,12 @@ DROP TABLE IF EXISTS `bookingPlanner`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `bookingPlanner` ( `id` int(10) NOT NULL AUTO_INCREMENT, - `effectived` timestamp NOT NULL DEFAULT current_timestamp(), + `effectived` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `pgcFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `taxAreaFk` varchar(15) CHARACTER SET utf8 NOT NULL DEFAULT 'SPAIN', `priority` int(2) unsigned DEFAULT NULL, - `taxClassFk` tinyint(3) unsigned NOT NULL DEFAULT 1, - `countryFk` mediumint(8) unsigned NOT NULL DEFAULT 1, + `taxClassFk` tinyint(3) unsigned NOT NULL DEFAULT '1', + `countryFk` mediumint(8) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`), KEY `pgcFk_bookingPlanner_idx` (`pgcFk`), KEY `taxClassFk` (`taxClassFk`), @@ -27062,14 +23222,14 @@ CREATE TABLE `botanicExport` ( `countryFk` mediumint(8) unsigned DEFAULT NULL, `restriction` enum('Sin restriccion','Importacion Prohibida','pasaporte fitosanitario','pasaporte individual','declaracion origen') CHARACTER SET utf8 NOT NULL, `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `isProtectedZone` tinyint(1) NOT NULL DEFAULT 0, + `isProtectedZone` tinyint(1) NOT NULL DEFAULT '0', `code` enum('importProhibited','phytosanitaryPassport','individualPassport') COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `Id_Paises` (`countryFk`), KEY `botanicExport_ibfk_2_idx` (`ediGenusFk`), KEY `botanicExport_ibfk_3_idx` (`ediSpecieFk`), CONSTRAINT `botanicExport_ibfk_1` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Especifica los generos y especies prohibidos en paises'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Especifica los generos y especies prohibidos en paises'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -27103,14 +23263,14 @@ DROP TABLE IF EXISTS `budget`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `budget` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `started` date DEFAULT NULL, `finished` date DEFAULT NULL, `userFk` int(10) unsigned DEFAULT NULL, `departmentFk` int(11) DEFAULT NULL, `supplierFk` int(11) DEFAULT NULL, - `photo` blob DEFAULT NULL, + `photo` blob, `amount` decimal(10,2) DEFAULT NULL, `projectFk` int(11) NOT NULL, PRIMARY KEY (`id`), @@ -27122,7 +23282,7 @@ CREATE TABLE `budget` ( CONSTRAINT `budget_FK_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `budget_FK_2` FOREIGN KEY (`departmentFk`) REFERENCES `department` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `budget_FK_3` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Master de presupuestos de project'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Master de presupuestos de project'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -27141,7 +23301,7 @@ CREATE TABLE `budgetDms` ( KEY `budgetDms_FK_1` (`dmsFk`), CONSTRAINT `budgetDms_FK` FOREIGN KEY (`budgetFk`) REFERENCES `budget` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `budgetDms_FK_1` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Gestion documental de budget'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Gestion documental de budget'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -27154,7 +23314,7 @@ DROP TABLE IF EXISTS `budgetInvoiceIn`; CREATE TABLE `budgetInvoiceIn` ( `id` int(11) NOT NULL AUTO_INCREMENT, `budgetFk` int(11) NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `invoiceInFk` mediumint(8) unsigned NOT NULL, `amount` decimal(10,2) NOT NULL, PRIMARY KEY (`id`), @@ -27162,7 +23322,7 @@ CREATE TABLE `budgetInvoiceIn` ( KEY `budgetInvoiceIn_FK_1` (`invoiceInFk`), CONSTRAINT `budgetInvoiceIn_FK` FOREIGN KEY (`budgetFk`) REFERENCES `budget` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `budgetInvoiceIn_FK_1` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Facturas relativas al presupuesto'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Facturas relativas al presupuesto'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -27175,7 +23335,7 @@ DROP TABLE IF EXISTS `budgetNotes`; CREATE TABLE `budgetNotes` ( `id` int(11) NOT NULL AUTO_INCREMENT, `budgetFk` int(11) NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `txt` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `userFk` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), @@ -27183,7 +23343,7 @@ CREATE TABLE `budgetNotes` ( KEY `budgetNotes_FK_2` (`userFk`), CONSTRAINT `budgetNotes_FK` FOREIGN KEY (`budgetFk`) REFERENCES `budget` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `budgetNotes_FK_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historico de budget'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historico de budget'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -27239,7 +23399,7 @@ CREATE TABLE `businessReasonEnd` ( `id` tinyint(3) NOT NULL AUTO_INCREMENT, `reason` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -27265,33 +23425,33 @@ DROP TABLE IF EXISTS `buy`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `buy` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `entryFk` int(11) NOT NULL DEFAULT 0, - `itemFk` int(11) NOT NULL DEFAULT 90, - `quantity` int(11) DEFAULT 0, - `dispatched` int(11) NOT NULL DEFAULT 0, - `buyingValue` decimal(10,3) DEFAULT 0.000, - `freightValue` decimal(10,3) DEFAULT 0.000, - `isIgnored` tinyint(1) NOT NULL DEFAULT 0, - `stickers` int(11) DEFAULT 0, - `packing` int(11) DEFAULT 0, - `grouping` smallint(5) unsigned NOT NULL DEFAULT 1, - `groupingMode` tinyint(4) NOT NULL DEFAULT 0 COMMENT '0=sin obligar 1=groping 2=packing', + `entryFk` int(11) NOT NULL DEFAULT '0', + `itemFk` int(11) NOT NULL DEFAULT '90', + `quantity` int(11) DEFAULT '0', + `dispatched` int(11) NOT NULL DEFAULT '0', + `buyingValue` decimal(10,3) DEFAULT '0.000', + `freightValue` decimal(10,3) DEFAULT '0.000', + `isIgnored` tinyint(1) NOT NULL DEFAULT '0', + `stickers` int(11) NOT NULL DEFAULT '0', + `packing` int(11) DEFAULT '0', + `grouping` smallint(5) unsigned NOT NULL DEFAULT '1', + `groupingMode` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0=sin obligar 1=groping 2=packing', `containerFk` smallint(5) unsigned DEFAULT NULL, - `comissionValue` decimal(10,3) DEFAULT 0.000, - `packageValue` decimal(10,3) DEFAULT 0.000, + `comissionValue` decimal(10,3) DEFAULT '0.000', + `packageValue` decimal(10,3) DEFAULT '0.000', `location` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, `packageFk` varchar(10) COLLATE utf8_unicode_ci DEFAULT '--', - `price1` decimal(10,2) DEFAULT 0.00, - `price2` decimal(10,2) DEFAULT 0.00, - `price3` decimal(10,2) DEFAULT 0.00, - `minPrice` decimal(10,2) DEFAULT 0.00, + `price1` decimal(10,2) DEFAULT '0.00', + `price2` decimal(10,2) DEFAULT '0.00', + `price3` decimal(10,2) DEFAULT '0.00', + `minPrice` decimal(10,2) DEFAULT '0.00', `producer` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `printedStickers` int(11) DEFAULT 0, - `workerFk` int(11) DEFAULT 0, - `isChecked` tinyint(1) NOT NULL DEFAULT 0, - `isPickedOff` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Esta mercancia no va a la zona de picking.', - `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), - `__cm2` int(10) unsigned NOT NULL DEFAULT 0, + `printedStickers` int(11) DEFAULT '0', + `workerFk` int(11) DEFAULT '0', + `isChecked` tinyint(1) NOT NULL DEFAULT '0', + `isPickedOff` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Esta mercancia no va a la zona de picking.', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `__cm2` int(10) unsigned NOT NULL DEFAULT '0', `ektFk` int(11) DEFAULT NULL, `weight` decimal(10,2) unsigned DEFAULT NULL, `deliveryFk` int(11) DEFAULT NULL, @@ -27306,6 +23466,7 @@ CREATE TABLE `buy` ( KEY `buy_fk_4_idx` (`deliveryFk`), KEY `buy_FK` (`itemOriginalFk`), CONSTRAINT `buy_FK` FOREIGN KEY (`itemOriginalFk`) REFERENCES `item` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `buy_FK_1` FOREIGN KEY (`containerFk`) REFERENCES `vn2008`.`container` (`container_id`) ON UPDATE CASCADE, CONSTRAINT `buy_ektFk` FOREIGN KEY (`ektFk`) REFERENCES `edi`.`ekt` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `buy_fk_4` FOREIGN KEY (`deliveryFk`) REFERENCES `edi`.`deliveryInformation` (`ID`) ON DELETE SET NULL ON UPDATE SET NULL, CONSTRAINT `buy_ibfk_1` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON UPDATE CASCADE, @@ -27333,18 +23494,16 @@ trig: BEGIN DECLARE vGroupingMode TINYINT; DECLARE vGenericFk INT; DECLARE vGenericInDate BOOL; - - IF @isModeInventory THEN + + IF @isModeInventory THEN LEAVE trig; END IF; - - CALL buy_checkGrouping(NEW.`grouping`); + CALL buy_checkGrouping(NEW.`grouping`); SELECT t.warehouseInFk, t.landed INTO vWarehouse, vLanding - FROM entry e + FROM entry e JOIN travel t ON t.id = e.travelFk WHERE e.id = NEW.entryFk; - SELECT b.`grouping`, b.groupingMode INTO vGrouping, vGroupingMode FROM buy b JOIN entry e ON e.id = b.entryFk @@ -27354,40 +23513,32 @@ trig: BEGIN AND !b.isIgnored ORDER BY t.warehouseInFk = vWarehouse DESC, t.landed DESC, b.id DESC LIMIT 1; - IF NEW.`grouping` IS NULL THEN SET NEW.`grouping` = vGrouping; END IF; - IF NEW.groupingMode IS NULL THEN SET NEW.groupingMode = vGroupingMode; END IF; - -- Generics - SELECT i.genericFk INTO vGenericFk FROM vn.item i WHERE i.id = NEW.itemFk; - + IF vGenericFk THEN - + SELECT COUNT(*) INTO vGenericInDate - FROM vn.genericAllocation ga + FROM vn.genericAllocation ga JOIN vn.entry e ON e.id = NEW.entryFk JOIN vn.travel tr on tr.id = e.travelFk WHERE ga.itemFk = vGenericFk AND tr.landed BETWEEN ga.startDated AND ga.endDated; - IF vGenericInDate THEN - SET NEW.itemOriginalFk = NEW.itemFk; - + SET NEW.itemFk = vGenericFk; - END IF; - - END IF; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -27407,13 +23558,31 @@ DELIMITER ;; AFTER INSERT ON `buy` FOR EACH ROW trig: BEGIN + DECLARE vValues VARCHAR(255); + CALL stock.log_add('buy', NEW.id, NULL); IF @isModeInventory THEN LEAVE trig; END IF; - CALL buy_afterUpsert(NEW.id); + IF @isTriggerDisabled THEN + LEAVE trig; + END IF; + + CALL buy_afterUpsert(NEW.id); + + /*IF entry_isInventoryOrPrevious(NEW.entryFk) THEN + SET vValues = CONCAT_WS(',', + NEW.entryFk, + NEW.itemFk, + NEW.quantity, + NEW.price1, + NEW.price2, + NEW.price3 + ); + CALL entry_notifyChanged(NEW.entryFk, NEW.id, vValues, NULL); + END IF;*/ END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -27432,43 +23601,43 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_beforeUpdate` BEFORE UPDATE ON `buy` FOR EACH ROW -trig:BEGIN +trig:BEGIN DECLARE vGenericFk INT; DECLARE vGenericInDate BOOL; - - IF @isTriggerDisabled THEN - + DECLARE vIsInventory BOOL; + IF @isTriggerDisabled THEN LEAVE trig; - END IF; - - IF !(NEW.`grouping` <=> OLD.`grouping`) THEN + IF !(NEW.`grouping` <=> OLD.`grouping`) THEN CALL buy_checkGrouping(NEW.`grouping`); END IF; - -- Generics - SELECT i.genericFk INTO vGenericFk FROM vn.item i WHERE i.id = NEW.itemFk; - + IF vGenericFk THEN - SELECT COUNT(*) INTO vGenericInDate - FROM vn.genericAllocation ga + FROM vn.genericAllocation ga JOIN vn.entry e ON e.id = NEW.entryFk JOIN vn.travel tr on tr.id = e.travelFk WHERE ga.itemFk = vGenericFk AND tr.landed BETWEEN ga.startDated AND ga.endDated; - IF vGenericInDate THEN - SET NEW.itemOriginalFk = NEW.itemFk; - SET NEW.itemFk = vGenericFk; - END IF; - + END IF; + SELECT COUNT(*) INTO vIsInventory + FROM vn.entry e + JOIN vn.supplier s ON s.id = e.supplierFk + JOIN vn.entryConfig ec ON ec.inventorySupplierFk = e.supplierFk + WHERE e.id = NEW.entryFk; + + IF vIsInventory THEN + IF NOT NEW.printedStickers <=> OLD.printedStickers THEN + CALL util.throw("Stickers cannot be modified if they are inventory"); + END IF; END IF; END */;; DELIMITER ; @@ -27494,7 +23663,8 @@ trig: BEGIN DECLARE vIsBuyerToBeEmailed BOOL; DECLARE vItemName VARCHAR(50); DECLARE vIsInventory BOOL; - DECLARE vEmail VARCHAR(255); + DECLARE vNewValues VARCHAR(255); + DECLARE vOldValues VARCHAR(255); IF !(NEW.id <=> OLD.id) OR !(NEW.entryFk <=> OLD.entryFk) @@ -27508,6 +23678,10 @@ trig: BEGIN LEAVE trig; END IF; + IF @isTriggerDisabled THEN + LEAVE trig; + END IF; + CALL buy_afterUpsert(NEW.id); IF !(NEW.weight <=> OLD.weight) AND NEW.weight THEN @@ -27532,7 +23706,7 @@ trig: BEGIN IF vIsBuyerToBeEmailed AND vBuyerFk != account.myUser_getId() AND - vLanded = util.VN_CURDATE() THEN + vLanded = vn.VN_CURDATE() THEN IF !(NEW.itemFk <=> OLD.itemFk) OR !(NEW.quantity <=> OLD.quantity) OR !(NEW.packing <=> OLD.packing) OR @@ -27547,33 +23721,55 @@ trig: BEGIN ); END IF; END IF; - - SELECT e.isInventory INTO vIsInventory - FROM entry e - WHERE e.id = NEW.entryFk; - - SELECT e.mailToNotify INTO vEmail - FROM entryConfig e - LIMIT 1; - - IF vIsInventory AND - (!(NEW.quantity <=> OLD.quantity) - OR !(NEW.price1<=>OLD.price1) - OR !(NEW.price2<=>OLD.price2) - OR !(NEW.price3<=>OLD.price3)) THEN - - CALL mail_insert( - vEmail, - NULL, - CONCAT('Se ha modificado la entrada ', NEW.entryFk ,' del Artículo ', NEW.itemFk, ' siendo inventario'), - CONCAT( - 'Antes: Cantidad: ', OLD.quantity, ' Precio1: ', OLD.price1, ' Precio2: ', OLD.price2, ' Precio3: ', OLD.price3, - '
', - 'Despues: Cantidad: ', NEW.quantity, ' Precio1: ', NEW.price1, ' Precio2: ', NEW.price2, ' Precio3: ', NEW.price3 - ) +/* + IF (!(NEW.entryFk <=> OLD.entryFk) + OR !(NEW.quantity <=> OLD.quantity) + OR !(NEW.price1 <=> OLD.price1) + OR !(NEW.price2 <=> OLD.price2) + OR !(NEW.price3 <=> OLD.price3)) + AND (entry_isInventoryOrPrevious(NEW.entryFk) + OR entry_isInventoryOrPrevious(OLD.entryFk)) THEN + SET vOldValues = CONCAT_WS(',', + OLD.entryFk, + OLD.itemFk, + OLD.quantity, + OLD.price1, + OLD.price2, + OLD.price3 ); - END IF; - + SET vNewValues = CONCAT_WS(',', + NEW.entryFk, + NEW.itemFk, + NEW.quantity, + NEW.price1, + NEW.price2, + NEW.price3 + ); + CALL entry_notifyChanged(NEW.entryFk, NEW.id, vNewValues, vOldValues); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_beforeDelete` + BEFORE DELETE ON buy + FOR EACH ROW +BEGIN + IF OLD.printedStickers <> 0 THEN + CALL util.throw("it is not possible to delete buys with printed labels "); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -27592,8 +23788,26 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`buy_afterDelete` AFTER DELETE ON `buy` FOR EACH ROW -BEGIN +trig: BEGIN + DECLARE vValues VARCHAR(255); + + IF @isTriggerDisabled THEN + LEAVE trig; + END IF; + CALL stock.log_add('buy', NULL, OLD.id); + + /*IF entry_isInventoryOrPrevious(OLD.entryFk) THEN + SET vValues = CONCAT_WS(',', + OLD.entryFk, + OLD.itemFk, + OLD.quantity, + OLD.price1, + OLD.price2, + OLD.price3 + ); + CALL entry_notifyChanged(OLD.entryFk, OLD.id, NULL, vValues); + END IF;*/ END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -27612,7 +23826,7 @@ CREATE TABLE `buyMark` ( `id` int(11) NOT NULL, `comment` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `mark` tinyint(1) DEFAULT NULL, - `odbcDate` timestamp NULL DEFAULT current_timestamp(), + `odbcDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), CONSTRAINT `Compres_mark_ibfk_1` FOREIGN KEY (`id`) REFERENCES `buy` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -27665,8 +23879,8 @@ 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 DELETE CASCADE 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 + CONSTRAINT `calendar_FK` FOREIGN KEY (`dayOffTypeFk`) REFERENCES `absenceType` (`id`) ON UPDATE CASCADE, + CONSTRAINT `calendar_businessFk` FOREIGN KEY (`businessFk`) REFERENCES `postgresql`.`business` (`business_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; @@ -27723,22 +23937,6 @@ CREATE TABLE `calendarHolidaysType` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Temporary table structure for view `calendar__` --- - -DROP TABLE IF EXISTS `calendar__`; -/*!50001 DROP VIEW IF EXISTS `calendar__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `calendar__` ( - `id` tinyint NOT NULL, - `businessFk` tinyint NOT NULL, - `dayOffTypeFk` tinyint NOT NULL, - `dated` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - -- -- Table structure for table `campaign` -- @@ -27749,8 +23947,8 @@ DROP TABLE IF EXISTS `campaign`; CREATE TABLE `campaign` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code` enum('mothersDay','allSaints','valentinesDay') COLLATE utf8_unicode_ci NOT NULL, - `dated` datetime NOT NULL DEFAULT current_timestamp(), - `scopeDays` int(11) NOT NULL DEFAULT 15, + `dated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `scopeDays` int(11) NOT NULL DEFAULT '15', PRIMARY KEY (`id`), UNIQUE KEY `campaign_dated_uindex` (`dated`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -27768,7 +23966,7 @@ CREATE TABLE `category` ( `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `nick` varchar(3) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -27781,12 +23979,12 @@ DROP TABLE IF EXISTS `chain`; CREATE TABLE `chain` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, - `rappel` decimal(5,2) NOT NULL DEFAULT 0.00, + `rappel` decimal(5,2) NOT NULL DEFAULT '0.00', `componentFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `chain_FK` (`componentFk`), CONSTRAINT `chain_FK` FOREIGN KEY (`componentFk`) REFERENCES `component` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Grupos de clientes'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Grupos de clientes'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -27817,13 +24015,13 @@ CREATE TABLE `claim` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `ticketCreated` date NOT NULL, `claimDepartmentFk__` tinyint(3) unsigned DEFAULT NULL, - `claimStateFk` int(10) unsigned NOT NULL DEFAULT 1, - `observation` text COLLATE utf8_unicode_ci DEFAULT NULL, + `claimStateFk` int(10) unsigned NOT NULL DEFAULT '1', + `observation` text COLLATE utf8_unicode_ci, `clientFk` int(11) NOT NULL, `workerFk` int(11) NOT NULL, - `responsibility` int(1) unsigned NOT NULL DEFAULT 3, - `isChargedToMana` tinyint(1) NOT NULL DEFAULT 0, - `created` timestamp NULL DEFAULT current_timestamp(), + `responsibility` int(1) unsigned NOT NULL DEFAULT '3', + `isChargedToMana` tinyint(1) NOT NULL DEFAULT '0', + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `ticketFk` int(11) DEFAULT NULL, `hasToPickUp` tinyint(1) NOT NULL, `packages` smallint(10) unsigned DEFAULT '0' COMMENT 'packages received by the client', @@ -27851,8 +24049,8 @@ CREATE TABLE `claimBeginning` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `claimFk` int(10) unsigned NOT NULL, `saleFk` int(11) DEFAULT NULL, - `claimComplaintFk__` int(10) unsigned NOT NULL DEFAULT 1, - `claimRequestFk__` int(1) unsigned NOT NULL DEFAULT 1, + `claimComplaintFk__` int(10) unsigned NOT NULL DEFAULT '1', + `claimRequestFk__` int(1) unsigned NOT NULL DEFAULT '1', `quantity` double DEFAULT NULL, PRIMARY KEY (`id`), KEY `Id_Movimiento` (`saleFk`), @@ -27900,6 +24098,7 @@ DROP TABLE IF EXISTS `claimConfig`; CREATE TABLE `claimConfig` ( `id` int(11) NOT NULL, `pickupContact` varchar(250) COLLATE utf8_unicode_ci DEFAULT NULL, + `maxResponsibility` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -27931,12 +24130,12 @@ DROP TABLE IF EXISTS `claimDevelopment`; CREATE TABLE `claimDevelopment` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `claimFk` int(10) unsigned NOT NULL, - `claimResponsibleFk` int(10) unsigned NOT NULL DEFAULT 1, + `claimResponsibleFk` int(10) unsigned NOT NULL DEFAULT '1', `workerFk` int(10) unsigned DEFAULT NULL, - `claimReasonFk` int(10) unsigned NOT NULL DEFAULT 1, - `claimResultFk` int(10) unsigned NOT NULL DEFAULT 1, - `claimRedeliveryFk` tinyint(3) unsigned NOT NULL DEFAULT 1, - `claimDestinationFk` tinyint(3) unsigned NOT NULL DEFAULT 2, + `claimReasonFk` int(10) unsigned NOT NULL DEFAULT '1', + `claimResultFk` int(10) unsigned NOT NULL DEFAULT '1', + `claimRedeliveryFk` tinyint(3) unsigned NOT NULL DEFAULT '1', + `claimDestinationFk` tinyint(3) unsigned NOT NULL DEFAULT '2', PRIMARY KEY (`id`), KEY `cl_main_id` (`claimFk`), KEY `cl_res_id` (`claimResponsibleFk`), @@ -27983,9 +24182,9 @@ CREATE TABLE `claimEnd` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `saleFk` int(11) DEFAULT NULL, `claimFk` int(10) unsigned NOT NULL, - `workerFk` int(10) unsigned NOT NULL DEFAULT 20, + `workerFk` int(10) unsigned NOT NULL DEFAULT '20', `claimDestinationFk` tinyint(4) DEFAULT NULL, - `isGreuge` tinyint(4) NOT NULL DEFAULT 0, + `isGreuge` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `cl_main_id` (`claimFk`), KEY `Id_Trabajador` (`workerFk`), @@ -28009,11 +24208,11 @@ CREATE TABLE `claimLog` ( `originFk` int(10) 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 DEFAULT 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 DEFAULT NULL, - `newInstance` text 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`), @@ -28021,7 +24220,7 @@ CREATE TABLE `claimLog` ( KEY `userFk` (`userFk`), CONSTRAINT `claimOriginFk` FOREIGN KEY (`originFk`) REFERENCES `claim` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `claimUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -28032,12 +24231,12 @@ DROP TABLE IF EXISTS `claimRatio`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `claimRatio` ( - `clientFk` int(11) NOT NULL DEFAULT 0, + `clientFk` int(11) NOT NULL DEFAULT '0', `yearSale` decimal(10,2) DEFAULT NULL, `claimAmount` decimal(10,2) DEFAULT NULL, `claimingRate` decimal(5,2) DEFAULT NULL, `priceIncreasing` decimal(5,2) DEFAULT NULL, - `packingRate` decimal(5,2) NOT NULL DEFAULT 1.00, + `packingRate` decimal(5,2) NOT NULL DEFAULT '1.00', PRIMARY KEY (`clientFk`), CONSTRAINT `claimRatio_ibfk_1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -28053,7 +24252,7 @@ DROP TABLE IF EXISTS `claimReason`; CREATE TABLE `claimReason` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, - `isTired` tinyint(1) NOT NULL DEFAULT 0, + `isTired` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Motivos de las fallos'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -28082,7 +24281,7 @@ DROP TABLE IF EXISTS `claimResponsible`; CREATE TABLE `claimResponsible` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, - `responsability` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'if=1 >sensib >culpa', + `responsability` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'if=1 >sensib >culpa', PRIMARY KEY (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Responsables de las causas'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -28131,72 +24330,72 @@ DROP TABLE IF EXISTS `client`; CREATE TABLE `client` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, - `discount` tinyint(3) unsigned NOT NULL DEFAULT 0 COMMENT 'obsoleta (comprobar)', + `discount__` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', `defaultAddressFk` int(11) DEFAULT NULL, - `street` longtext COLLATE utf8_unicode_ci DEFAULT NULL, + `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)', `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, - `receipt__` int(11) DEFAULT 1 COMMENT 'obsoleta', - `isOfficial__` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'obsoleta (comprobar)', - `isTaxDataChecked` tinyint(1) NOT NULL DEFAULT 0, + `cc__` varchar(23) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'obsoleta (comprobar)', + `dueDay` smallint(6) NOT NULL DEFAULT '5', + `receipt__` int(11) DEFAULT '1' COMMENT 'obsoleta', + `isOfficial__` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'obsoleta (comprobar)', + `isTaxDataChecked` tinyint(1) NOT NULL DEFAULT '0', `mobile` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `accountingAccount` varchar(10) CHARACTER SET utf8 NOT NULL, - `isEqualizated` tinyint(1) NOT NULL DEFAULT 0, + `isEqualizated` tinyint(1) NOT NULL DEFAULT '0', `city` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL, `provinceFk` smallint(5) unsigned DEFAULT NULL, `postcode` varchar(8) COLLATE utf8_unicode_ci DEFAULT NULL, `socialName` varchar(60) COLLATE utf8_unicode_ci DEFAULT NULL, `contact` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `wholesaler__` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'obsoleta (comprobar)', - `isReExpedition__` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'obsoleta (comprobar)', - `hasToInvoice` tinyint(1) NOT NULL DEFAULT 1, - `notes` text COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'obsoleta (comprobar)', + `wholesaler__` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', + `isReExpedition__` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', + `hasToInvoice` tinyint(1) NOT NULL DEFAULT '1', + `notes__` text COLLATE utf8_unicode_ci COMMENT 'obsoleta (comprobar)', `administrativeNotes__` text COLLATE utf8_unicode_ci NOT NULL COMMENT 'obsoleta (comprobar)', - `invoiceCopy__` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'obsoleta (comprobar)', - `hold__` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'obsoleta (comprobar)', - `isFreezed` tinyint(1) NOT NULL DEFAULT 0, + `invoiceCopy__` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', + `hold__` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', + `isFreezed` tinyint(1) NOT NULL DEFAULT '0', `salesPersonFk` int(10) unsigned DEFAULT NULL, - `credit` decimal(10,2) NOT NULL DEFAULT 0.00, - `cyc` double DEFAULT NULL COMMENT 'obsoleta (comprobar)', - `countryFk` mediumint(8) unsigned NOT NULL DEFAULT 1, - `isActive` tinyint(1) NOT NULL DEFAULT 1, + `credit` decimal(10,2) NOT NULL DEFAULT '0.00', + `cyc__` double DEFAULT NULL COMMENT 'obsoleta (comprobar)', + `countryFk` mediumint(8) unsigned NOT NULL DEFAULT '1', + `isActive` tinyint(1) NOT NULL DEFAULT '1', `gestdocFk` int(11) DEFAULT NULL, - `quality` int(2) DEFAULT 11, - `payMethodFk` tinyint(3) unsigned NOT NULL DEFAULT 5, - `created` timestamp NULL DEFAULT current_timestamp(), - `isToBeMailed` tinyint(1) NOT NULL DEFAULT 1, + `quality` int(2) DEFAULT '11', + `payMethodFk` tinyint(3) unsigned NOT NULL DEFAULT '5', + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `isToBeMailed` tinyint(1) NOT NULL DEFAULT '1', `contactChannelFk` smallint(6) DEFAULT NULL, - `isVies` tinyint(4) NOT NULL DEFAULT 0, - `splitHolland__` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'obsoleta (comprobar)', - `sepaFth__` tinyint(1) DEFAULT 0 COMMENT 'campo para recibir los escritos de los clientes para el sepaobsoleta (comprobar)', - `hasSepaVnl` tinyint(1) DEFAULT 0, - `coreFth__` tinyint(1) DEFAULT 0 COMMENT 'obsoleta (comprobar)', - `hasCoreVnl` tinyint(1) DEFAULT 0, + `isVies` tinyint(4) NOT NULL DEFAULT '0', + `splitHolland__` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'obsoleta (comprobar)', + `sepaFth__` tinyint(1) DEFAULT '0' COMMENT 'campo para recibir los escritos de los clientes para el sepaobsoleta (comprobar)', + `hasSepaVnl` tinyint(1) DEFAULT '0', + `coreFth__` tinyint(1) DEFAULT '0' COMMENT 'obsoleta (comprobar)', + `hasCoreVnl` tinyint(1) DEFAULT '0', `riskCalculated` date NOT NULL, - `hasCoreVnh` tinyint(1) DEFAULT 0, - `isRelevant` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Define los clientes cuyas ventas hay que tener en cuenta en los calculos estadisticos.', - `clientTypeFk` int(11) NOT NULL DEFAULT 1, + `hasCoreVnh` tinyint(1) DEFAULT '0', + `isRelevant` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Define los clientes cuyas ventas hay que tener en cuenta en los calculos estadisticos.', + `clientTypeFk` int(11) NOT NULL DEFAULT '1', `postcodeOld__` int(11) unsigned DEFAULT NULL COMMENT 'obsoleta (comprobar)', `mailAddress` int(11) DEFAULT NULL, `codposOLD__` char(5) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'obsoleta (comprobar)', `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', - `isCreatedAsServed` tinyint(1) DEFAULT 0, - `hasInvoiceSimplified` tinyint(1) NOT NULL DEFAULT 0, + `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', + `isCreatedAsServed` tinyint(1) DEFAULT '0', + `hasInvoiceSimplified` tinyint(1) NOT NULL DEFAULT '0', `iban` varchar(45) CHARACTER SET utf8 DEFAULT NULL, - `hasLcr` tinyint(1) NOT NULL DEFAULT 0, - `bankEntityFk` int(10) DEFAULT NULL, + `hasLcr` tinyint(1) NOT NULL DEFAULT '0', + `bankEntityFk` int(10) unsigned DEFAULT NULL, `typeFk` varchar(20) CHARACTER SET utf8 NOT NULL DEFAULT 'normal', `taxTypeSageFk` smallint(6) DEFAULT NULL COMMENT 'Tipo de Iva por defecto asociado al cliente en SAGE', `transactionTypeSageFk` tinyint(4) DEFAULT NULL COMMENT 'Tipo de transacción por defecto asociado al cliente en SAGE', `transferorFk` int(11) DEFAULT NULL COMMENT 'Cliente que le ha transmitido la titularidad de la empresa', - `lastSalesPersonFk` int(11) DEFAULT NULL COMMENT 'ultimo comercial que tuvo, para el calculo del peso en los rankings de equipo', + `lastSalesPersonFk` int(10) unsigned DEFAULT NULL COMMENT 'ultimo comercial que tuvo, para el calculo del peso en los rankings de equipo', `businessTypeFk` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `IF` (`fi`), @@ -28217,8 +24416,12 @@ CREATE TABLE `client` ( KEY `client_transactionTypeSageFk_idx` (`transactionTypeSageFk`), KEY `client_FK` (`businessTypeFk`), KEY `client_lastSalesPersonFk_IDX` (`lastSalesPersonFk`) USING BTREE, + KEY `client_FK_3` (`transferorFk`), CONSTRAINT `canal_nuevo_cliente` FOREIGN KEY (`contactChannelFk`) REFERENCES `contactChannel` (`id`) ON UPDATE CASCADE, CONSTRAINT `client_FK` FOREIGN KEY (`businessTypeFk`) REFERENCES `businessType` (`code`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `client_FK_1` FOREIGN KEY (`bankEntityFk`) REFERENCES `bankEntity` (`id`) ON UPDATE CASCADE, + CONSTRAINT `client_FK_2` FOREIGN KEY (`lastSalesPersonFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, + CONSTRAINT `client_FK_3` FOREIGN KEY (`transferorFk`) REFERENCES `client` (`id`), CONSTRAINT `client_ibfk_1` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE, CONSTRAINT `client_ibfk_2` FOREIGN KEY (`payMethodFk`) REFERENCES `payMethod` (`id`) ON UPDATE CASCADE, CONSTRAINT `client_ibfk_3` FOREIGN KEY (`salesPersonFk`) REFERENCES `worker` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, @@ -28386,7 +24589,7 @@ CREATE TABLE `clientChain` ( KEY `clientChain_fk2_idx` (`chainFk`), CONSTRAINT `clientChain_fk1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `clientChain_fk2` FOREIGN KEY (`chainFk`) REFERENCES `chain` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -28399,6 +24602,8 @@ DROP TABLE IF EXISTS `clientConfig`; CREATE TABLE `clientConfig` ( `id` int(11) NOT NULL AUTO_INCREMENT, `riskTolerance` int(11) DEFAULT NULL COMMENT 'Maximo riesgo de un cliente para preparar su pedido', + `maxCreditRows` int(11) DEFAULT NULL COMMENT 'Máximo número de registros a mantener en la tabla clientCredit', + `maxPriceIncreasingRatio` decimal(2,2) NOT NULL DEFAULT '0.25' COMMENT 'máximo recobro permitido', PRIMARY KEY (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -28430,7 +24635,7 @@ CREATE TABLE `clientCredit` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `clientFk` int(11) NOT NULL, `amount` double unsigned NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `workerFk` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), KEY `workers_fk_idx` (`workerFk`), @@ -28505,7 +24710,7 @@ CREATE TABLE `clientDms` ( PRIMARY KEY (`dmsFk`), KEY `gest_doc_id` (`dmsFk`), KEY `fk_clientes_gestdoc_1_idx` (`clientFk`), - CONSTRAINT `clientDms_ibfk_2` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `clientDms_ibfk_2` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fk_clientes_gestdoc_3` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -28562,11 +24767,11 @@ CREATE TABLE `clientLog` ( `originFk` int(11) 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 DEFAULT 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 DEFAULT NULL, - `newInstance` text 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`), @@ -28574,7 +24779,7 @@ CREATE TABLE `clientLog` ( KEY `userFk` (`userFk`), CONSTRAINT `clientLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `clientLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -28601,7 +24806,7 @@ DROP TABLE IF EXISTS `clientManaCache`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `clientManaCache` ( `clientFk` int(11) NOT NULL, - `mana` decimal(10,0) NOT NULL DEFAULT 0, + `mana` decimal(10,0) NOT NULL DEFAULT '0', `dated` date NOT NULL, PRIMARY KEY (`clientFk`,`dated`), KEY `manaCustomerIdx1` (`dated`), @@ -28609,21 +24814,6 @@ CREATE TABLE `clientManaCache` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Temporary table structure for view `clientManaCache__` --- - -DROP TABLE IF EXISTS `clientManaCache__`; -/*!50001 DROP VIEW IF EXISTS `clientManaCache__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `clientManaCache__` ( - `clientFk` tinyint NOT NULL, - `mana` tinyint NOT NULL, - `dated` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - -- -- Table structure for table `clientObservation` -- @@ -28636,7 +24826,7 @@ CREATE TABLE `clientObservation` ( `clientFk` int(11) NOT NULL, `workerFk` int(10) unsigned DEFAULT NULL, `text` text COLLATE utf8_unicode_ci NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `Id_Trabajador` (`workerFk`), KEY `Id_Cliente` (`clientFk`), @@ -28699,7 +24889,7 @@ DROP TABLE IF EXISTS `clientPackagingGifts`; CREATE TABLE `clientPackagingGifts` ( `clientFk` int(11) NOT NULL, `giftFk` int(11) NOT NULL, - `added` timestamp NOT NULL DEFAULT current_timestamp(), + `added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`clientFk`,`giftFk`), KEY `clientPackagingGifts_FK_1` (`giftFk`), CONSTRAINT `clientPackagingGifts_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`), @@ -28731,7 +24921,7 @@ DROP TABLE IF EXISTS `clientProtected`; CREATE TABLE `clientProtected` ( `clientFk` int(11) NOT NULL, `workerFk` int(10) unsigned NOT NULL, - `isValidated__` tinyint(1) NOT NULL DEFAULT 0, + `isValidated__` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`clientFk`), KEY `clientProtected_fk2_idx` (`workerFk`), CONSTRAINT `clientProtected_fk1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, @@ -28747,8 +24937,8 @@ DROP TABLE IF EXISTS `clientRisk`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `clientRisk` ( - `clientFk` int(11) NOT NULL DEFAULT 0, - `companyFk` smallint(6) unsigned NOT NULL DEFAULT 0, + `clientFk` int(11) NOT NULL DEFAULT '0', + `companyFk` smallint(6) unsigned NOT NULL DEFAULT '0', `amount` decimal(10,2) DEFAULT NULL, PRIMARY KEY (`clientFk`,`companyFk`), KEY `company_id` (`companyFk`), @@ -28768,7 +24958,7 @@ CREATE TABLE `clientSample` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `clientFk` int(10) unsigned NOT NULL, `typeFk` int(10) unsigned NOT NULL, - `created` datetime NOT NULL DEFAULT current_timestamp(), + `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `workerFk` int(10) unsigned NOT NULL, `balance` float NOT NULL, `companyFk` smallint(5) unsigned DEFAULT NULL, @@ -28790,12 +24980,28 @@ CREATE TABLE `clientType` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code` varchar(20) CHARACTER SET utf8 NOT NULL, `type` varchar(45) COLLATE utf8_unicode_ci NOT NULL, - `isCreatedAsServed` tinyint(1) DEFAULT 0, + `isCreatedAsServed` tinyint(1) DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `code_UNIQUE` (`code`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Establece categorias para poder agrupar las ventas'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `clientUnpaid` +-- + +DROP TABLE IF EXISTS `clientUnpaid`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `clientUnpaid` ( + `clientFk` int(11) NOT NULL, + `dated` date NOT NULL, + `amount` double DEFAULT '0', + PRIMARY KEY (`clientFk`), + CONSTRAINT `clientUnpaid_clientFk` FOREIGN KEY (`clientFk`) REFERENCES `client` (`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 `clientYoke` -- @@ -28828,7 +25034,7 @@ CREATE TABLE `cmr` ( `senderInstruccions` varchar(255) COLLATE utf8_unicode_ci DEFAULT 'Flowers 4º C. Plants 14º C', `paymentInstruccions` varchar(255) COLLATE utf8_unicode_ci DEFAULT 'Carriage paid', `specialAgreements` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `created` timestamp NULL DEFAULT current_timestamp(), + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `companyFk` smallint(5) unsigned DEFAULT NULL, `addressToFk` int(11) DEFAULT NULL, `addressFromFk` int(11) DEFAULT NULL, @@ -28843,11 +25049,13 @@ CREATE TABLE `cmr` ( KEY `cmr_fk2_idx` (`companyFk`), KEY `cmr_fk3_idx` (`addressToFk`), KEY `cm_fk4_idx` (`supplierFk`), + KEY `cmr_FK` (`addressFromFk`), CONSTRAINT `cm_fk4` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE, + CONSTRAINT `cmr_FK` FOREIGN KEY (`addressFromFk`) REFERENCES `address` (`id`) ON UPDATE CASCADE, CONSTRAINT `cmr_fk1` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `cmr_fk2` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `cmr_fk3` FOREIGN KEY (`addressToFk`) REFERENCES `address` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -28916,7 +25124,7 @@ CREATE TABLE `cmr_expeditionPallet` ( `id` int(11) NOT NULL AUTO_INCREMENT, `cmrFk` int(11) NOT NULL, `expeditionPalletFk` int(11) NOT NULL, - `scanned` timestamp NOT NULL DEFAULT current_timestamp(), + `scanned` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `cmr_expeditionPallet_fk1_idx` (`cmrFk`), KEY `cmr_expeditionPallet_fk2_idx` (`expeditionPalletFk`), @@ -28980,13 +25188,13 @@ DROP TABLE IF EXISTS `collection`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `collection` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `workerFk` int(10) unsigned DEFAULT NULL, `stateFk` tinyint(3) unsigned DEFAULT NULL, `itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, - `saleTotalCount` int(11) NOT NULL DEFAULT 0, - `salePickedCount` int(11) NOT NULL DEFAULT 0, - `trainFk` int(11) NOT NULL DEFAULT 1, + `saleTotalCount` int(11) NOT NULL DEFAULT '0', + `salePickedCount` int(11) NOT NULL DEFAULT '0', + `trainFk` int(11) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), KEY `ticketCollection_idx` (`workerFk`), KEY `collection_id2_idx` (`stateFk`), @@ -29006,39 +25214,39 @@ CREATE TABLE `collection` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collection_BEFORE_UPDATE` - BEFORE UPDATE ON `collection` - FOR EACH ROW -BEGIN - - DECLARE vStateFk INT; - DECLARE vTotalLines INT; - DECLARE vPickedLines INT; - - IF NEW.saleTotalCount <= NEW.salePickedCount - AND (NEW.saleTotalCount != OLD.saleTotalCount - OR NEW.salePickedCount != OLD.salePickedCount) - THEN - - SELECT id INTO vStateFk - FROM vn.state - WHERE code = 'PREPARED'; - - SET NEW.stateFk = vStateFk; - - END IF; - - IF NEW.saleTotalCount > NEW.salePickedCount - AND (NEW.saleTotalCount != OLD.saleTotalCount OR NEW.salePickedCount != OLD.salePickedCount) THEN - - SELECT id INTO vStateFk - FROM vn.state - WHERE code = 'ON_PREPARATION'; - - SET NEW.stateFk = vStateFk; - - END IF; - +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`collection_BEFORE_UPDATE` + BEFORE UPDATE ON `collection` + FOR EACH ROW +BEGIN + + DECLARE vStateFk INT; + DECLARE vTotalLines INT; + DECLARE vPickedLines INT; + + IF NEW.saleTotalCount <= NEW.salePickedCount + AND (NEW.saleTotalCount != OLD.saleTotalCount + OR NEW.salePickedCount != OLD.salePickedCount) + THEN + + SELECT id INTO vStateFk + FROM vn.state + WHERE code = 'PREPARED'; + + SET NEW.stateFk = vStateFk; + + END IF; + + IF NEW.saleTotalCount > NEW.salePickedCount + AND (NEW.saleTotalCount != OLD.saleTotalCount OR NEW.salePickedCount != OLD.salePickedCount) THEN + + SELECT id INTO vStateFk + FROM vn.state + WHERE code = 'ON_PREPARATION'; + + SET NEW.stateFk = vStateFk; + + END IF; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -29056,35 +25264,15 @@ DROP TABLE IF EXISTS `collectionColors`; CREATE TABLE `collectionColors` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code` varchar(20) COLLATE utf8_unicode_ci NOT NULL, - `shelve` int(11) NOT NULL DEFAULT 1, - `wagon` int(11) NOT NULL DEFAULT 1, - `trainFk` int(11) NOT NULL DEFAULT 1, + `shelve` int(11) NOT NULL DEFAULT '1', + `wagon` int(11) NOT NULL DEFAULT '1', + `trainFk` int(11) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), KEY `collectionColors_FK` (`trainFk`), CONSTRAINT `collectionColors_FK` FOREIGN KEY (`trainFk`) REFERENCES `train` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Recoge los colores para las baldas de las colecciones'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Recoge los colores para las baldas de las colecciones'; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Temporary table structure for view `collectionReportSource` --- - -DROP TABLE IF EXISTS `collectionReportSource`; -/*!50001 DROP VIEW IF EXISTS `collectionReportSource`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `collectionReportSource` ( - `collectionFk` tinyint NOT NULL, - `ticketFk` tinyint NOT NULL, - `itemFk` tinyint NOT NULL, - `concept` tinyint NOT NULL, - `size` tinyint NOT NULL, - `quantity` tinyint NOT NULL, - `nicho` tinyint NOT NULL, - `level` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - -- -- Temporary table structure for view `collectionSmartTag` -- @@ -29137,18 +25325,18 @@ DROP TABLE IF EXISTS `collectionVolumetry`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `collectionVolumetry` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `level` int(10) unsigned NOT NULL DEFAULT 0, - `lines` int(10) unsigned NOT NULL DEFAULT 1, - `liters` int(10) unsigned NOT NULL DEFAULT 0, - `height` int(10) unsigned NOT NULL DEFAULT 20, + `level` int(10) unsigned NOT NULL DEFAULT '0', + `lines` int(10) unsigned NOT NULL DEFAULT '1', + `liters` int(10) unsigned NOT NULL DEFAULT '0', + `height` int(10) unsigned NOT NULL DEFAULT '20', `itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'H', - `trainFk` int(11) NOT NULL DEFAULT 1, + `trainFk` int(11) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), KEY `collectionVolumetry_FK` (`itemPackingTypeFk`), KEY `collectionVolumetry_FK_1` (`trainFk`), CONSTRAINT `collectionVolumetry_FK` FOREIGN KEY (`itemPackingTypeFk`) REFERENCES `itemPackingType` (`code`) ON UPDATE CASCADE, CONSTRAINT `collectionVolumetry_FK_1` FOREIGN KEY (`trainFk`) REFERENCES `train` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29159,7 +25347,7 @@ DROP TABLE IF EXISTS `commissionConfig`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `commissionConfig` ( - `rate` decimal(5,4) NOT NULL DEFAULT 0.0000, + `rate` decimal(5,4) NOT NULL DEFAULT '0.0000', `plusTeamAmount` int(11) DEFAULT NULL, `plusNewBornAmount` int(11) DEFAULT NULL, `plusSalesAmount` int(11) DEFAULT NULL, @@ -29171,6 +25359,12 @@ CREATE TABLE `commissionConfig` ( `minScoreForPlusBoss` int(11) DEFAULT NULL, `plusTeam` int(11) DEFAULT NULL, `plusBoss` int(11) DEFAULT NULL COMMENT 'Este campo se deberá multiplicar x el número de miembros del equipo', + `executionDay` smallint(6) DEFAULT NULL, + `salesPersonWithPlusNewClient` int(11) DEFAULT NULL, + `maxPlusNewClient` int(11) DEFAULT NULL, + `plusDifference` int(11) DEFAULT NULL, + `maxScoreNewClient` int(11) DEFAULT NULL, + `scoreDifference` int(11) DEFAULT NULL, PRIMARY KEY (`rate`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -29189,22 +25383,22 @@ CREATE TABLE `company` ( `workerManagerFk` int(10) unsigned NOT NULL, `registered` date NOT NULL, `expired` date DEFAULT NULL, - `logo` longblob DEFAULT NULL, - `isOfficial` tinyint(1) unsigned NOT NULL DEFAULT 1, - `hasCyc` tinyint(1) unsigned zerofill NOT NULL DEFAULT 0, + `logo` longblob, + `isOfficial` tinyint(1) unsigned NOT NULL DEFAULT '1', + `hasCyc` tinyint(1) unsigned zerofill NOT NULL DEFAULT '0', `rgb` varchar(6) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(30) COLLATE utf8_unicode_ci NOT NULL, - `stamp` blob DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE current_timestamp(), + `stamp` blob, + `created` timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP, `clientFk` int(11) DEFAULT NULL, `sage200Company` int(2) DEFAULT NULL, `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL, - `isDefaulter` tinyint(4) NOT NULL DEFAULT 0, - `companyGroupFk` int(11) NOT NULL DEFAULT 1 COMMENT 'usado para calcular los greuges ', + `isDefaulter` tinyint(4) NOT NULL DEFAULT '0', + `companyGroupFk` int(11) NOT NULL DEFAULT '1' COMMENT 'usado para calcular los greuges ', `companyCode` int(2) DEFAULT NULL COMMENT 'Campo para movConta', `companyCodeTest` int(2) DEFAULT NULL, - `footnotes` longtext COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'pie de paginas en las facturas', - `phytosanitary` longtext COLLATE utf8_unicode_ci DEFAULT NULL, + `footnotes` longtext COLLATE utf8_unicode_ci COMMENT 'pie de paginas en las facturas', + `phytosanitary` longtext COLLATE utf8_unicode_ci, `fhAdminNumber` int(11) DEFAULT NULL COMMENT 'número de cliente en FloraHolland', PRIMARY KEY (`id`), KEY `gerente_id` (`workerManagerFk`), @@ -29246,9 +25440,9 @@ CREATE TABLE `component` ( `typeFk` int(11) NOT NULL, `classRate` smallint(6) DEFAULT NULL, `tax` double DEFAULT NULL, - `isRenewable` tinyint(2) NOT NULL DEFAULT 1, + `isRenewable` tinyint(2) NOT NULL DEFAULT '1', `code` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `isRequired` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Son componentes imprescindibles en toda venta', + `isRequired` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Son componentes imprescindibles en toda venta', PRIMARY KEY (`id`), KEY `series_componentes_idx` (`typeFk`), KEY `comp` (`classRate`), @@ -29266,8 +25460,8 @@ DROP TABLE IF EXISTS `componentType`; CREATE TABLE `componentType` ( `id` int(11) NOT NULL AUTO_INCREMENT, `type` varchar(45) COLLATE utf8_unicode_ci NOT NULL, - `isBase` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'Marca aquellas series que se utilizan para calcular el precio base de las ventas, a efectos estadisticos', - `isMargin` tinyint(4) NOT NULL DEFAULT 0, + `isBase` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Marca aquellas series que se utilizan para calcular el precio base de las ventas, a efectos estadisticos', + `isMargin` tinyint(4) NOT NULL DEFAULT '0', `code` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `Serie_UNIQUE` (`type`) @@ -29285,7 +25479,7 @@ CREATE TABLE `confectionType` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29298,49 +25492,49 @@ DROP TABLE IF EXISTS `config`; CREATE TABLE `config` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ochoa` int(10) unsigned NOT NULL, - `invoiceOutFk` int(11) DEFAULT 0, - `bookFk` int(11) DEFAULT 0, - `serialAFk` int(11) DEFAULT 0, - `serialEFk` int(11) DEFAULT 0, - `serialRFk` int(11) DEFAULT 0, - `serialCFk` int(11) DEFAULT 0, - `serialHFk` int(11) NOT NULL, - `serialPFk` int(11) DEFAULT 0, - `serialTFk` int(11) DEFAULT 0, + `invoiceOutFk` int(11) DEFAULT '0', + `bookFk__` int(11) DEFAULT '0', + `serialAFk__` int(11) DEFAULT '0', + `serialEFk__` int(11) DEFAULT '0', + `serialRFk__` int(11) DEFAULT '0', + `serialCFk__` int(11) DEFAULT '0', + `serialHFk__` int(11) NOT NULL, + `serialPFk__` int(11) DEFAULT '0', + `serialTFk__` int(11) DEFAULT '0', `inventoried` datetime DEFAULT NULL, - `serialMFk` int(11) DEFAULT 0, - `itemLog` int(11) DEFAULT 0, + `serialMFk__` int(11) DEFAULT '0', + `itemLog` int(11) DEFAULT '0', `weekGoal` int(11) DEFAULT NULL, `photosPath` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `cashBoxNumber` int(11) DEFAULT 0, + `cashBoxNumber` int(11) DEFAULT '0', `redCode` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `TabletTime` datetime DEFAULT NULL, - `t0` int(11) NOT NULL DEFAULT 0, - `t1` int(11) NOT NULL DEFAULT 0, - `t2` int(11) NOT NULL DEFAULT 0, - `t3` int(11) NOT NULL DEFAULT 0, - `cc` double NOT NULL DEFAULT 0, - `palet` double NOT NULL DEFAULT 0, + `t0` int(11) NOT NULL DEFAULT '0', + `t1` int(11) NOT NULL DEFAULT '0', + `t2` int(11) NOT NULL DEFAULT '0', + `t3` int(11) NOT NULL DEFAULT '0', + `cc` double NOT NULL DEFAULT '0', + `palet` double NOT NULL DEFAULT '0', `campaign` datetime NOT NULL, `campaignLife` tinyint(3) unsigned NOT NULL, `truckDays` tinyint(3) unsigned NOT NULL, `transportCharges` double NOT NULL, `escanerPath` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `printedTurn` int(4) DEFAULT NULL, - `truckLength` int(11) DEFAULT 24, + `truckLength` int(11) DEFAULT '24', `fuelConsumption` int(11) DEFAULT NULL, `petrol` decimal(10,1) DEFAULT NULL, `maintenance` decimal(10,1) DEFAULT NULL, `hourPrice` decimal(10,1) DEFAULT NULL, `meterPrice` decimal(10,1) DEFAULT NULL, `kmPrice` decimal(10,1) DEFAULT NULL, - `routeOption` int(11) DEFAULT 1, - `dbproduccion` tinyint(1) NOT NULL DEFAULT 1, + `routeOption` int(11) DEFAULT '1', + `dbproduccion` tinyint(1) NOT NULL DEFAULT '1', `mdbServer` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `fakeEmail` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `defaultersMaxAmount` int(10) DEFAULT 200 COMMENT 'maxima deuda permitida a partir de la cual se bloquea a un usuario', + `defaultersMaxAmount` int(10) DEFAULT '200' COMMENT 'maxima deuda permitida a partir de la cual se bloquea a un usuario', `ASIEN` bigint(20) DEFAULT NULL, - `dayStartingHour` int(11) NOT NULL DEFAULT 3 COMMENT 'Hora a la que empieza una nueva jornada de producción', + `dayStartingHour` int(11) NOT NULL DEFAULT '3' COMMENT 'Hora a la que empieza una nueva jornada de producción', PRIMARY KEY (`id`), KEY `fechainv_idx` (`inventoried`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -29388,7 +25582,7 @@ CREATE TABLE `contratos_subvencion_270619` ( `workerFk` int(10) unsigned NOT NULL, `cod_centroFk` int(11) NOT NULL, `CodContratoFk` int(11) NOT NULL, - `journey` decimal(5,2) NOT NULL DEFAULT 8.00, + `journey` decimal(5,2) NOT NULL DEFAULT '8.00', `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `nif` varchar(12) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), @@ -29398,7 +25592,7 @@ CREATE TABLE `contratos_subvencion_270619` ( CONSTRAINT `contratos_subvencion_270619_fk1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `contratos_subvencion_270619_fk2` FOREIGN KEY (`cod_centroFk`) REFERENCES `vn2008`.`payroll_centros` (`cod_centro`) ON UPDATE CASCADE, CONSTRAINT `contratos_subvencion_270619_fk3` FOREIGN KEY (`CodContratoFk`) REFERENCES `vn2008`.`payroll_contratos__` (`CodContrato`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Segun los informes de vida laboral aportados por la SS'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Segun los informes de vida laboral aportados por la SS'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29411,20 +25605,20 @@ DROP TABLE IF EXISTS `conveyor`; CREATE TABLE `conveyor` ( `id` int(11) NOT NULL AUTO_INCREMENT, `typeFk` int(11) NOT NULL, - `stratum` int(11) NOT NULL DEFAULT 0, + `stratum` int(11) NOT NULL DEFAULT '0', `length` int(11) DEFAULT NULL, `width` int(11) DEFAULT NULL, `height` int(11) DEFAULT NULL, `x` int(11) DEFAULT NULL, `y` int(11) DEFAULT NULL, - `freeSpace` int(11) NOT NULL DEFAULT 0, - `isBusy` tinyint(1) NOT NULL DEFAULT 0, + `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 -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29437,10 +25631,10 @@ DROP TABLE IF EXISTS `conveyorBuildingClass`; 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, + `priority` int(11) NOT NULL DEFAULT '0', `weightThreshold` int(11) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tipo de caja para el montaje de pallets'; +) 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 */; -- @@ -29458,7 +25652,7 @@ CREATE TABLE `conveyorConfig` ( `height` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `itemName_UNIQUE` (`itemName`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29471,20 +25665,20 @@ DROP TABLE IF EXISTS `conveyorExpedition`; CREATE TABLE `conveyorExpedition` ( `expeditionFk` int(11) NOT NULL, `conveyorFk` int(11) DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), - `conveyorBuildingClassFk` int(11) NOT NULL DEFAULT 1, - `length` int(11) NOT NULL DEFAULT 1, - `width` int(11) NOT NULL DEFAULT 1, - `height` int(11) NOT NULL DEFAULT 1, - `x` int(11) NOT NULL DEFAULT 18100, - `y` int(11) NOT NULL DEFAULT 1, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `conveyorBuildingClassFk` int(11) NOT NULL DEFAULT '1', + `length` int(11) NOT NULL DEFAULT '1', + `width` int(11) NOT NULL DEFAULT '1', + `height` int(11) NOT NULL DEFAULT '1', + `x` int(11) NOT NULL DEFAULT '18100', + `y` int(11) NOT NULL DEFAULT '1', `routeFk` int(11) NOT NULL, - `isIn` tinyint(4) NOT NULL DEFAULT 0, + `isIn` tinyint(4) NOT NULL DEFAULT '0', `productionMinute` int(11) DEFAULT NULL, - `isOut` tinyint(4) NOT NULL DEFAULT 0, + `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, + `isHeavy` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`expeditionFk`), KEY `conveyorExpedition_fk1_idx` (`conveyorFk`), KEY `conveyorExpedition_fk2_idx` (`conveyorBuildingClassFk`), @@ -29504,7 +25698,7 @@ CREATE TABLE `conveyorMode` ( `code` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `saturacion` int(11) NOT NULL, `gap` int(11) NOT NULL, - `isActive` tinyint(4) NOT NULL DEFAULT 0, + `isActive` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -29521,7 +25715,7 @@ CREATE TABLE `conveyorType` ( `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `color` int(11) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29533,7 +25727,7 @@ DROP TABLE IF EXISTS `corridor`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `corridor` ( `code` varchar(1) COLLATE utf8_unicode_ci NOT NULL COMMENT 'letra que da nombre al pasillo', - `isAscendent` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'TRUE cuando se prepara de menor a mayor, FALSE cuando es a la inversa', + `isAscendent` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'TRUE cuando se prepara de menor a mayor, FALSE cuando es a la inversa', `prepOrder` int(10) unsigned NOT NULL COMMENT 'orden de preparacion de los pasillos', PRIMARY KEY (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='establece el orden y sentido de preparacion de los pasillos del parking'; @@ -29549,13 +25743,13 @@ DROP TABLE IF EXISTS `country`; CREATE TABLE `country` ( `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `country` varchar(25) COLLATE utf8_unicode_ci NOT NULL, - `CEE` tinyint(1) NOT NULL DEFAULT 1, + `CEE` tinyint(1) NOT NULL DEFAULT '1', `code` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL, - `currencyFk` tinyint(3) unsigned NOT NULL DEFAULT 1, + `currencyFk` tinyint(3) unsigned NOT NULL DEFAULT '1', `politicalCountryFk` mediumint(8) unsigned NOT NULL COMMENT 'Pais Real(apaño por culpa del España Exento)', `geoFk` int(11) DEFAULT NULL, - `hasDailyInvoice` tinyint(4) NOT NULL DEFAULT 0, - `isUeeMember` tinyint(4) NOT NULL DEFAULT 0, + `hasDailyInvoice` tinyint(4) NOT NULL DEFAULT '0', + `isUeeMember` tinyint(4) NOT NULL DEFAULT '0', `ibanLength` tinyint(4) DEFAULT NULL, `continentFk` tinyint(4) DEFAULT NULL, `a3Code` int(11) DEFAULT NULL COMMENT 'Código país para a3', @@ -29564,7 +25758,10 @@ CREATE TABLE `country` ( KEY `currency_id_fk_idx` (`currencyFk`), KEY `country_Ix4` (`country`), KEY `continent_id_fk_idx` (`continentFk`), + KEY `country_FK_1` (`geoFk`), CONSTRAINT `continent_id_fk` FOREIGN KEY (`continentFk`) REFERENCES `continent` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `country_FK` FOREIGN KEY (`politicalCountryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE, + CONSTRAINT `country_FK_1` FOREIGN KEY (`geoFk`) REFERENCES `zoneGeo` (`id`) ON UPDATE CASCADE, CONSTRAINT `currency_id_fk` FOREIGN KEY (`currencyFk`) REFERENCES `currency` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -29700,7 +25897,7 @@ CREATE TABLE `cplusCorrectingType` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -29871,7 +26068,7 @@ CREATE TABLE `creditInsurance` ( `id` int(11) NOT NULL AUTO_INCREMENT, `creditClassification` int(11) DEFAULT NULL, `credit` int(11) DEFAULT NULL, - `creationDate` timestamp NOT NULL DEFAULT current_timestamp(), + `creationDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `grade` tinyint(1) DEFAULT NULL, PRIMARY KEY (`id`), KEY `CreditInsurance_Fk1_idx` (`creditClassification`), @@ -29913,7 +26110,7 @@ CREATE TABLE `currency` ( `id` tinyint(3) unsigned NOT NULL, `code` varchar(3) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `ratio` double NOT NULL DEFAULT 1, + `ratio` double NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `Moneda_UNIQUE` (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -29981,7 +26178,7 @@ DROP TABLE IF EXISTS `delivery`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `delivery` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `longitude` decimal(11,7) DEFAULT NULL, `latitude` decimal(11,7) DEFAULT NULL, `dated` datetime DEFAULT NULL, @@ -29989,7 +26186,7 @@ CREATE TABLE `delivery` ( PRIMARY KEY (`id`), KEY `delivery_FK` (`addressFk`), CONSTRAINT `delivery_FK` FOREIGN KEY (`addressFk`) REFERENCES `address` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Informa de los datos geográficos y temporales de las entregas de los repartidores'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Informa de los datos geográficos y temporales de las entregas de los repartidores'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30050,7 +26247,7 @@ CREATE TABLE `delivery_zip` ( KEY `postal_code_idx` (`postal_code`), KEY `admin_name3_idx` (`admin_name3`), KEY `admin_name2_idx` (`admin_name2`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30071,14 +26268,14 @@ CREATE TABLE `department` ( `bossFk__` int(11) DEFAULT NULL, `x__` int(11) DEFAULT NULL, `y__` int(11) DEFAULT NULL, - `isProduction` tinyint(4) NOT NULL DEFAULT 0, - `isSelected` tinyint(1) NOT NULL DEFAULT 0, - `depth` int(11) NOT NULL DEFAULT 0, - `sons` decimal(10,0) NOT NULL DEFAULT 0, - `parentFk` int(10) unsigned DEFAULT 1, + `isProduction` tinyint(4) NOT NULL DEFAULT '0', + `isSelected` tinyint(1) NOT NULL DEFAULT '0', + `depth` int(11) NOT NULL DEFAULT '0', + `sons` decimal(10,0) NOT NULL DEFAULT '0', + `parentFk` int(11) DEFAULT '1', `path` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `chatName` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `isTeleworking` tinyint(1) DEFAULT 0, + `isTeleworking` tinyint(1) DEFAULT '0', `notificationEmail` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL, `hasToRefill` tinyint(1) DEFAULT '0' COMMENT 'Rellenar días sin fichadas presenciales', `hasToSendMail` tinyint(1) DEFAULT '0' COMMENT 'Para el envio de mail en el procedimiento workerTimeControl_sendMail()', @@ -30091,7 +26288,9 @@ CREATE TABLE `department` ( KEY `dep_org_ibfk_3_idx` (`companyFk`), KEY `lft_rgt_depth_idx` (`lft`,`rgt`,`depth`), KEY `department_FK` (`clientFk`), + KEY `department_FK_1` (`parentFk`), CONSTRAINT `department_FK` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `department_FK_1` FOREIGN KEY (`parentFk`) REFERENCES `department` (`id`), CONSTRAINT `fk_department_Trabajadores1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -30214,7 +26413,7 @@ CREATE TABLE `department_recalc` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `isChanged` tinyint(4) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30245,12 +26444,14 @@ DROP TABLE IF EXISTS `deviceLog`; 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(), + `userFk` int(10) unsigned DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `nameApp` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `versionApp` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + PRIMARY KEY (`id`), + KEY `deviceLog_FK` (`userFk`), + CONSTRAINT `deviceLog_FK` FOREIGN KEY (`userFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30267,7 +26468,7 @@ CREATE TABLE `deviceProduction` ( `macWifi` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `serialNumber` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `departmentFk` int(11) DEFAULT NULL, - `isOutOfService` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0: Ok - 1: No disponible - 2: Sat', + `isOutOfService` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0: Ok - 1: No disponible - 2: Sat', `android_id` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `purchased` date NOT NULL DEFAULT '1900-01-01' COMMENT 'Fecha de compra', PRIMARY KEY (`id`), @@ -30278,7 +26479,7 @@ CREATE TABLE `deviceProduction` ( KEY `departmentFgn` (`departmentFk`), CONSTRAINT `departmentFgn` FOREIGN KEY (`departmentFk`) REFERENCES `department` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `deviceProductionModelsFgn` FOREIGN KEY (`modelFk`) REFERENCES `deviceProductionModels` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30290,10 +26491,10 @@ DROP TABLE IF EXISTS `deviceProductionConfig`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `deviceProductionConfig` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `isAllUsersallowed` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Permite que cualquier usuario pueda loguearse', - `isTractorHuntingMode` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Habilita el modo cazador para usuarios que no se han logeado un tractor para sacar', + `isAllUsersallowed` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Permite que cualquier usuario pueda loguearse', + `isTractorHuntingMode` 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`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -30309,7 +26510,7 @@ DELIMITER ;; FOR EACH ROW BEGIN IF NEW.isAllUsersAllowed = 1 OR NEW.isAllUsersAllowed = -1 THEN - SET @username := (SELECT account.userGetName()); + SET @username := (SELECT account.myUser_getName()); INSERT INTO vn.mail (receiver, subject, body) VALUES ('cau@verdnatura.es', 'Se ha activado la autenticación sin restricciones en la app', CONCAT('El usuario ', @username,' ha habilitado la opción para que todos los usuarios puedan acceder a la app sin restricciones')); @@ -30362,7 +26563,7 @@ CREATE TABLE `disabilityGrade` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Grados de discapacidad Modelo 145 IRPF', `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30374,17 +26575,17 @@ DROP TABLE IF EXISTS `dms`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `dms` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `dmsTypeFk` int(11) NOT NULL DEFAULT 1, + `dmsTypeFk` int(11) NOT NULL DEFAULT '1', `reference` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `description` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL, - `companyFk` smallint(5) unsigned NOT NULL DEFAULT 442, + `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', `hardCopyNumber` mediumint(8) unsigned DEFAULT NULL, `contentType` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL, `file` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, - `hasFile` tinyint(4) NOT NULL DEFAULT 0, + `hasFile` tinyint(4) NOT NULL DEFAULT '0', `workerFk` int(10) unsigned DEFAULT NULL, - `created` timestamp NULL DEFAULT current_timestamp(), - `warehouseFk` smallint(5) unsigned DEFAULT 60, + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `warehouseFk` smallint(5) unsigned DEFAULT '60', PRIMARY KEY (`id`), UNIQUE KEY `emp_id` (`companyFk`,`hardCopyNumber`,`warehouseFk`), UNIQUE KEY `dms_hardCopyNumber_IDX` (`hardCopyNumber`,`warehouseFk`) USING BTREE, @@ -30445,31 +26646,59 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`dms_beforeUpdate` - BEFORE UPDATE ON `dms` +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`dms_beforeUpdate` + BEFORE UPDATE ON `dms` + FOR EACH ROW +BEGIN + DECLARE vHardCopyNumber INT; + + IF (NEW.hasFile <> 0) AND (OLD.hasFile = 0) AND (NEW.hardCopyNumber IS NULL) + OR + (NEW.hardCopyNumber = OLD.hardCopyNumber AND OLD.warehouseFk <> NEW.warehouseFk) THEN + + IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN + SET NEW.warehouseFk = (SELECT id FROM warehouse WHERE name = 'Algemesi'); + END IF; + + SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber + FROM dms + WHERE warehouseFk = NEW.warehouseFk; + + SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1); + END IF; + + IF ((NEW.hardCopyNumber = 0) OR NEW.hardCopyNumber IS NULL) AND (OLD.hardCopyNumber <> 0) THEN + + SET NEW.hasFile = 0; + END IF; +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`dms_beforeDelete` + BEFORE DELETE ON `dms` FOR EACH ROW -BEGIN - DECLARE vHardCopyNumber INT; - - IF (NEW.hasFile <> 0) AND (OLD.hasFile = 0) AND (NEW.hardCopyNumber IS NULL) - OR - (NEW.hardCopyNumber = OLD.hardCopyNumber AND OLD.warehouseFk <> NEW.warehouseFk) THEN - - IF (SELECT NOT hasDms FROM warehouse WHERE id = NEW.warehouseFk) THEN - SET NEW.warehouseFk = (SELECT id FROM warehouse WHERE name = 'Algemesi'); - END IF; - - SELECT 1 + MAX(hardCopyNumber) INTO vHardCopyNumber - FROM dms - WHERE warehouseFk = NEW.warehouseFk; - - SET NEW.hardCopyNumber = IFNULL(vHardCopyNumber,1); - END IF; - - IF ((NEW.hardCopyNumber = 0) OR NEW.hardCopyNumber IS NULL) AND (OLD.hardCopyNumber <> 0) THEN - - SET NEW.hasFile = 0; - END IF; +BEGIN + DECLARE vCanNotBeDeleted INT; + SELECT COUNT(*) INTO vCanNotBeDeleted + FROM dmsType dt + WHERE NOT (code <=> 'trash') + AND dt.id = OLD.dmsTypeFk; + + IF vCanNotBeDeleted THEN + CALL util.throw('A dms can not be deleted'); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -30487,12 +26716,12 @@ DROP TABLE IF EXISTS `dmsRecover`; CREATE TABLE `dmsRecover` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ticketFk` int(11) DEFAULT NULL, - `sign` text COLLATE utf8_unicode_ci DEFAULT NULL, - `created` timestamp NULL DEFAULT current_timestamp(), + `sign` text COLLATE utf8_unicode_ci, + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `ticketFk_idx` (`ticketFk`), CONSTRAINT `ticketFk` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30509,6 +26738,7 @@ CREATE TABLE `dmsType` ( `writeRoleFk` int(10) unsigned DEFAULT NULL, `readRoleFk` int(10) unsigned DEFAULT NULL, `code` varchar(45) COLLATE utf8_unicode_ci NOT NULL, + `monthToDelete` int(10) unsigned DEFAULT NULL COMMENT 'Meses en el pasado para ir borrando registros, dejar a null para no borrarlos nunca', PRIMARY KEY (`id`), KEY `readRoleFk` (`readRoleFk`), KEY `writeRoleFk` (`writeRoleFk`), @@ -30580,7 +26810,7 @@ CREATE TABLE `dua` ( `bookEntried` date DEFAULT NULL, `gestdocFk` int(11) DEFAULT NULL, `customsValue` decimal(10,2) DEFAULT NULL, - `companyFk` smallint(5) unsigned NOT NULL DEFAULT 442, + `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', `ASIEN` double DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code_UNIQUE` (`code`), @@ -30625,13 +26855,13 @@ CREATE TABLE `duaIntrastat` ( `id` int(11) NOT NULL AUTO_INCREMENT, `duaFk` int(11) NOT NULL, `intrastatFk` int(8) unsigned NOT NULL, - `amount` decimal(10,2) NOT NULL DEFAULT 0.00, + `amount` decimal(10,2) NOT NULL DEFAULT '0.00', PRIMARY KEY (`id`), KEY `duaIntrastat_fk1_idx` (`intrastatFk`), KEY `duaIntrastat_fk2_idx` (`duaFk`), CONSTRAINT `duaIntrastat_fk1` FOREIGN KEY (`intrastatFk`) REFERENCES `intrastat` (`id`) ON UPDATE CASCADE, CONSTRAINT `duaIntrastat_fk2` FOREIGN KEY (`duaFk`) REFERENCES `dua` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30676,7 +26906,7 @@ CREATE TABLE `duaTax` ( CONSTRAINT `duaTax_fk1` FOREIGN KEY (`duaFk`) REFERENCES `dua` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `duaTax_fk2` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE, CONSTRAINT `duaTax_fk3` FOREIGN KEY (`taxClassFk`) REFERENCES `taxClass` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -30793,7 +27023,7 @@ CREATE TABLE `ektEntryAssign` ( UNIQUE KEY `ektEntryAssign_ix1` (`kop`,`sub`,`pro`), KEY `ektEntryAssign_FK` (`addressFk`), CONSTRAINT `ektEntryAssign_FK` FOREIGN KEY (`addressFk`) REFERENCES `address` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='define las condiciones para asignar entradas a los ekt'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='define las condiciones para asignar entradas a los ekt'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30824,7 +27054,7 @@ CREATE TABLE `emergencyMedia` ( `name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `value` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Table to save all emergency phones', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -30867,28 +27097,30 @@ DROP TABLE IF EXISTS `entry`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `entry` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `supplierFk` int(11) NOT NULL DEFAULT 644, + `supplierFk` int(11) NOT NULL DEFAULT '644', `dated` datetime NOT NULL, `ref` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `isBooked` tinyint(1) NOT NULL DEFAULT 0, - `isInventory` tinyint(1) NOT NULL DEFAULT 0, - `notes` longtext COLLATE utf8_unicode_ci DEFAULT NULL, - `isConfirmed` tinyint(1) NOT NULL DEFAULT 0, - `isOrdered` tinyint(1) NOT NULL DEFAULT 0, - `isRaid` tinyint(1) NOT NULL DEFAULT 0, - `commission` float DEFAULT 0, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `isBooked` tinyint(1) NOT NULL DEFAULT '0', + `isInventory` tinyint(1) NOT NULL DEFAULT '0', + `notes` longtext COLLATE utf8_unicode_ci, + `isConfirmed` tinyint(1) NOT NULL DEFAULT '0', + `isOrdered` tinyint(1) NOT NULL DEFAULT '0', + `isRaid` tinyint(1) NOT NULL DEFAULT '0', + `commission` float DEFAULT '0', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `evaNotes` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `travelFk` int(11) unsigned DEFAULT NULL, - `currencyFk` tinyint(3) unsigned DEFAULT 1, - `companyFk` smallint(5) unsigned NOT NULL DEFAULT 442, + `currencyFk` tinyint(3) unsigned DEFAULT '1', + `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', `gestDocFk` int(11) DEFAULT NULL, `invoiceInFk` mediumint(8) unsigned DEFAULT NULL, - `isBlocked` tinyint(4) NOT NULL DEFAULT 0, + `isBlocked` tinyint(4) NOT NULL DEFAULT '0', `loadPriority` int(11) DEFAULT NULL, `kop` int(11) DEFAULT NULL, `sub` mediumint(8) unsigned DEFAULT NULL, `pro` mediumint(8) unsigned DEFAULT NULL, + `invoiceAmount` decimal(10,2) DEFAULT NULL, + `buyerFk` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), KEY `Id_Proveedor` (`supplierFk`), KEY `Fecha` (`dated`), @@ -30896,7 +27128,9 @@ CREATE TABLE `entry` ( KEY `empresa_id` (`companyFk`), KEY `gestdoc_id` (`gestDocFk`), KEY `recibida_id` (`invoiceInFk`), + KEY `entry_FK` (`buyerFk`), CONSTRAINT `Entradas_fk8` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `entry_FK` FOREIGN KEY (`buyerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `entry_ibfk_1` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE, CONSTRAINT `entry_ibfk_6` FOREIGN KEY (`travelFk`) REFERENCES `travel` (`id`) ON UPDATE CASCADE, CONSTRAINT `entry_ibfk_7` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE @@ -31034,6 +27268,16 @@ BEGIN CALL travel_requestRecalc(OLD.travelFk); CALL travel_requestRecalc(NEW.travelFk); END IF; + + IF NOT (NEW.invoiceAmount <=> OLD.invoiceAmount) THEN + INSERT INTO vn.entryLog SET + `action` = 'update', + userFk = account.myUser_getId(), + originFk = NEW.id, + changedModel = 'Entry', + oldInstance = CONCAT('{"old invoiceAmount":', OLD.invoiceAmount, '}'), + newInstance = CONCAT('{"new invoiceAmount":', NEW.invoiceAmount, '}'); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -31091,6 +27335,7 @@ DROP TABLE IF EXISTS `entryConfig`; CREATE TABLE `entryConfig` ( `defaultEntry` int(11) NOT NULL, `mailToNotify` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + `inventorySupplierFk` int(11) DEFAULT '4', PRIMARY KEY (`defaultEntry`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -31129,11 +27374,11 @@ CREATE TABLE `entryLog` ( `originFk` int(11) NOT NULL, `userFk` int(10) unsigned NOT NULL, `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL, - `creationDate` timestamp NULL DEFAULT current_timestamp(), - `description` text CHARACTER SET utf8 DEFAULT 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 DEFAULT NULL, - `newInstance` text 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`), @@ -31141,7 +27386,7 @@ CREATE TABLE `entryLog` ( KEY `entryLog_ibfk_2` (`userFk`), CONSTRAINT `entryLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `entry` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `entryLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31155,13 +27400,13 @@ CREATE TABLE `entryObservation` ( `id` int(11) NOT NULL AUTO_INCREMENT, `entryFk` int(11) NOT NULL, `observationTypeFk` tinyint(3) unsigned DEFAULT NULL, - `description` text COLLATE utf8_unicode_ci DEFAULT NULL, + `description` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`), UNIQUE KEY `entryFk_observationTypeFk_UNIQUE` (`entryFk`,`observationTypeFk`), KEY `observationType_id_observationTypeFk` (`observationTypeFk`), CONSTRAINT `entry_id_entryFk` FOREIGN KEY (`entryFk`) REFERENCES `entry` (`id`), CONSTRAINT `observationType_id_observationTypeFk` FOREIGN KEY (`observationTypeFk`) REFERENCES `observationType` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31246,7 +27491,7 @@ CREATE TABLE `envialiaCity` ( PRIMARY KEY (`id`), KEY `agencyFk` (`agencyFk`), KEY `postalCode` (`postalCode`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -31283,7 +27528,7 @@ CREATE TABLE `envialiaConfig` ( `endRange` bigint(25) DEFAULT NULL COMMENT 'limite del rango que nos proporciona enviaría', `cargoAgency` varchar(25) COLLATE utf8_unicode_ci DEFAULT '004666' COMMENT 'numero de verdnatura dado por enviaría', `actualNumber` bigint(25) DEFAULT NULL COMMENT 'Numero actual de etiquetas imprimidas , comprimido entre startRange y endRange, ', - `isAlreadyNotified` int(1) NOT NULL DEFAULT 0 COMMENT 'Booleano para que el evento vn.envialiaRangeChecker compruebe si se a enviado una notificación\n', + `isAlreadyNotified` int(1) NOT NULL DEFAULT '0' COMMENT 'Booleano para que el evento vn.envialiaRangeChecker compruebe si se a enviado una notificación\n', `notificationThrehold` int(11) DEFAULT NULL COMMENT 'Umbral para avisar a enviaría de reseetar el startRange y endRange\nSe avisara a enviaría si el umbral + el actualNumber es superior a endRange\n', PRIMARY KEY (`serviceType`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -31302,7 +27547,7 @@ CREATE TABLE `errorLogApp` ( `date` datetime DEFAULT NULL, `workerFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Guarda un registro de errores e la app de almacén'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Guarda un registro de errores e la app de almacén'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31327,7 +27572,7 @@ CREATE TABLE `errorProduction` ( `hourWorked` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `dated` date DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31350,7 +27595,7 @@ CREATE TABLE `errorProduction__` ( `month` int(11) DEFAULT NULL, `year` int(11) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31365,7 +27610,7 @@ CREATE TABLE `erte` ( `workerFk` int(11) NOT NULL, `started` date DEFAULT NULL, `ended` date DEFAULT NULL, - `reduction` int(3) NOT NULL DEFAULT 1, + `reduction` int(3) NOT NULL DEFAULT '1', `monday` tinyint(1) DEFAULT NULL, `tuesday` tinyint(1) DEFAULT NULL, `wednesday` tinyint(1) DEFAULT NULL, @@ -31374,7 +27619,7 @@ CREATE TABLE `erte` ( `saturday` tinyint(1) DEFAULT NULL, `sunday` tinyint(1) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31392,6 +27637,21 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `exchangeInsuranceIn` +-- + +DROP TABLE IF EXISTS `exchangeInsuranceIn`; +/*!50001 DROP VIEW IF EXISTS `exchangeInsuranceIn`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `exchangeInsuranceIn` ( + `dated` tinyint NOT NULL, + `amount` tinyint NOT NULL, + `rate` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Temporary table structure for view `exchangeInsuranceOut` -- @@ -31407,6 +27667,25 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `exchangeReportSourcePrevious` +-- + +DROP TABLE IF EXISTS `exchangeReportSourcePrevious`; +/*!50001 DROP VIEW IF EXISTS `exchangeReportSourcePrevious`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `exchangeReportSourcePrevious` ( + `dated` tinyint NOT NULL, + `amountIn` tinyint NOT NULL, + `rateIn` tinyint NOT NULL, + `amountOut` tinyint NOT NULL, + `rateOut` tinyint NOT NULL, + `amountEntry` tinyint NOT NULL, + `rateEntry` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `excuse` -- @@ -31417,9 +27696,9 @@ DROP TABLE IF EXISTS `excuse`; CREATE TABLE `excuse` ( `id` int(11) NOT NULL AUTO_INCREMENT, `txt` varchar(255) CHARACTER SET latin1 NOT NULL, - `date` datetime NOT NULL DEFAULT current_timestamp(), + `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31433,19 +27712,20 @@ CREATE TABLE `expedition` ( `id` int(11) NOT NULL AUTO_INCREMENT, `agencyModeFk` int(11) NOT NULL, `ticketFk` int(10) NOT NULL, - `isBox` int(11) DEFAULT 1 COMMENT 'Este campo realmente en un campo itemFk, haciendo referencia al artículo que nos va a facturar el proveedor de transporte.\nSe debería llamar freightItemFk', - `created` timestamp NULL DEFAULT current_timestamp(), - `isRefund` bit(1) DEFAULT b'0', - `isPickUp` bit(1) DEFAULT b'0', + `isBox` int(11) DEFAULT '1' COMMENT 'Este campo realmente en un campo itemFk, haciendo referencia al artículo que nos va a facturar el proveedor de transporte.\nSe debería llamar freightItemFk', + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `isRefund__` bit(1) DEFAULT b'0' COMMENT 'Deprecado 01/06/2022', + `isPickUp__` bit(1) DEFAULT b'0' COMMENT 'Deprecado 01/06/2022', `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, + `checked__` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Deprecado 01/06/2022', `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, `stateTypeFk` int(11) DEFAULT NULL COMMENT 'Ultimo estado de la expedicion', + `hasNewRoute` bit(1) NOT NULL DEFAULT b'0', PRIMARY KEY (`id`), KEY `index1` (`agencyModeFk`), KEY `index2` (`isBox`), @@ -31573,7 +27853,8 @@ CREATE TABLE `expeditionBoxVol` ( `boxFk` int(11) NOT NULL, `m3` double NOT NULL, `ratio` double NOT NULL, - PRIMARY KEY (`boxFk`) + PRIMARY KEY (`boxFk`), + CONSTRAINT `expeditionBoxVol_FK` FOREIGN KEY (`boxFk`) REFERENCES `item` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Establece el volumen de cada servicio para poder comparar el teorico y el real en el control de portes'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -31610,9 +27891,9 @@ DROP TABLE IF EXISTS `expeditionPallet`; CREATE TABLE `expeditionPallet` ( `id` int(11) NOT NULL AUTO_INCREMENT, `truckFk` int(11) NOT NULL, - `built` datetime NOT NULL DEFAULT current_timestamp(), + `built` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `position` int(11) DEFAULT NULL, - `isPrint` tinyint(4) NOT NULL DEFAULT 2, + `isPrint` tinyint(4) NOT NULL DEFAULT '2', PRIMARY KEY (`id`), KEY `expeditionPallet_fk1_idx` (`truckFk`), CONSTRAINT `expeditionPallet_fk1` FOREIGN KEY (`truckFk`) REFERENCES `expeditionTruck` (`id`) ON DELETE CASCADE ON UPDATE CASCADE @@ -31646,6 +27927,57 @@ 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 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER vn.expeditionPallet_beforeDelete +BEFORE DELETE +ON expeditionPallet FOR EACH ROW +BEGIN + DECLARE vIndex INT DEFAULT INSTR(USER(), '@'); + + CALL util.debugAdd('expeditionPallet_deleted', CONCAT(OLD.id,' ', vn.getWorkerCode())); + + INSERT INTO util.debug(connectionId, `user`, host, variable, value) + SELECT CONNECTION_ID(), + LEFT(USER(), vIndex - 1), + RIGHT(USER(), CHAR_LENGTH(USER()) - vIndex), + 'expeditionScan_deleted', + es.id + FROM vn.expeditionScan es + WHERE es.palletFk = 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 */ ; + +-- +-- Temporary table structure for view `expeditionPallet_Print` +-- + +DROP TABLE IF EXISTS `expeditionPallet_Print`; +/*!50001 DROP VIEW IF EXISTS `expeditionPallet_Print`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `expeditionPallet_Print` ( + `truck` tinyint NOT NULL, + `routeFk` tinyint NOT NULL, + `zone` tinyint NOT NULL, + `eti` tinyint NOT NULL, + `palletFk` tinyint NOT NULL, + `isMatch` tinyint NOT NULL, + `warehouseFk` tinyint NOT NULL, + `nombreDia` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; -- -- Temporary table structure for view `expeditionRoute_Monitor` @@ -31693,7 +28025,7 @@ DROP TABLE IF EXISTS `expeditionScan`; CREATE TABLE `expeditionScan` ( `id` int(11) NOT NULL AUTO_INCREMENT, `expeditionFk` int(11) NOT NULL, - `scanned` datetime NOT NULL DEFAULT current_timestamp(), + `scanned` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `palletFk` int(11) NOT NULL, `workerFk` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), @@ -31722,6 +28054,28 @@ BEGIN SET NEW.workerFk = vn.getUser(); +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER vn.expeditionScan_afterDelete +AFTER DELETE +ON expeditionScan FOR EACH ROW +BEGIN + + CALL util.debugAdd('expeditionScan_deleted', CONCAT(OLD.id,' ', vn.getWorkerCode())); + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -31759,7 +28113,7 @@ DROP TABLE IF EXISTS `expeditionState`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `expeditionState` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `expeditionFk` int(11) NOT NULL, `typeFk` int(11) NOT NULL, `userFk` int(11) DEFAULT NULL, @@ -31768,7 +28122,7 @@ CREATE TABLE `expeditionState` ( KEY `expeditionState_FK_1` (`typeFk`), CONSTRAINT `expeditionState_FK` FOREIGN KEY (`expeditionFk`) REFERENCES `expedition` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `expeditionState_FK_1` FOREIGN KEY (`typeFk`) REFERENCES `expeditionStateType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historico de estados de las expediciones'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historico de estados de las expediciones'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -31829,7 +28183,7 @@ CREATE TABLE `expeditionStateType` ( `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `code` varchar(100) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Posibles estados de una expedición'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Posibles estados de una expedición'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -31858,31 +28212,6 @@ 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 `expeditionTicket_NoBoxes` -- @@ -32056,9 +28385,9 @@ CREATE TABLE `expence` ( `id` varchar(10) NOT NULL, `taxTypeFk` tinyint(4) NOT NULL, `name` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `isConbase` tinyint(4) NOT NULL DEFAULT 1, - `isWithheld` tinyint(4) NOT NULL DEFAULT 0, - `isForSale` tinyint(4) NOT NULL DEFAULT 0, + `isConbase` tinyint(4) NOT NULL DEFAULT '1', + `isWithheld` tinyint(4) NOT NULL DEFAULT '0', + `isForSale` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`id`,`taxTypeFk`), KEY `iva_tipo_id` (`taxTypeFk`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -32110,7 +28439,7 @@ CREATE TABLE `floramondoConfig` ( `warehouseOutFk__` smallint(6) unsigned DEFAULT NULL, `agencyModeFk__` int(11) DEFAULT NULL, `MaxLatestDeliveryHour` int(11) DEFAULT NULL, - `MaxLatestOrderHour` int(11) DEFAULT 12 COMMENT 'Hora máxima para aceptar pedidos hoy', + `MaxLatestOrderHour` int(11) DEFAULT '12' COMMENT 'Hora máxima para aceptar pedidos hoy', `LastUpdated` datetime DEFAULT NULL, `itemMaxSize` int(11) DEFAULT NULL COMMENT 'tamaño maximo de los articulos a mostrar', PRIMARY KEY (`id`), @@ -32120,7 +28449,7 @@ CREATE TABLE `floramondoConfig` ( CONSTRAINT `floramondoConfigAgencyModeFk` FOREIGN KEY (`agencyModeFk__`) REFERENCES `agencyMode` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `floramondoConfigWarehouseInFk` FOREIGN KEY (`warehouseInFk`) REFERENCES `warehouse` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `floramondoConfigWarehouseOutFk` FOREIGN KEY (`warehouseOutFk__`) REFERENCES `warehouse` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -32152,7 +28481,7 @@ DROP TABLE IF EXISTS `floramondoNotOfferDay__`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `floramondoNotOfferDay__` ( `dated` date NOT NULL, - `warehouseFk` int(11) NOT NULL DEFAULT 60, + `warehouseFk` int(11) NOT NULL DEFAULT '60', PRIMARY KEY (`dated`,`warehouseFk`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='no muestra oferta en floramondo para ese dia y almacen'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -32170,7 +28499,7 @@ CREATE TABLE `fuelType` ( `code` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code_UNIQUE` (`code`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32185,7 +28514,7 @@ CREATE TABLE `gateArea` ( `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32221,7 +28550,7 @@ CREATE TABLE `genericAllocation` ( KEY `genericAllocation_longName_IDX` (`longName`) USING BTREE, KEY `genericAllocation_size_IDX` (`size`) USING BTREE, CONSTRAINT `genericAllocation_FK` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los filtros para asignar códigos genéricos a los items'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los filtros para asignar códigos genéricos a los items'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32257,7 +28586,7 @@ CREATE TABLE `glsConfig` ( `refund` int(1) DEFAULT NULL, `weight` int(1) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32272,7 +28601,7 @@ CREATE TABLE `glsExpedition__` ( `barcode` bigint(20) unsigned DEFAULT NULL, `uid` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `codexp` int(11) DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`expeditionFk`), CONSTRAINT `glsInfo_FK` FOREIGN KEY (`expeditionFk`) REFERENCES `expedition` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -32290,8 +28619,8 @@ CREATE TABLE `greuge` ( `clientFk` int(10) unsigned NOT NULL, `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `amount` decimal(10,2) NOT NULL, - `shipped` datetime NOT NULL DEFAULT current_timestamp(), - `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `shipped` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `greugeTypeFk` int(11) DEFAULT NULL, `ticketFk` int(11) DEFAULT NULL, PRIMARY KEY (`Id`), @@ -32315,7 +28644,7 @@ DELIMITER ;; BEFORE UPDATE ON `greuge` FOR EACH ROW BEGIN - DECLARE vMaxDate DATETIME DEFAULT TIMESTAMPADD(YEAR,1,util.VN_CURDATE()); + DECLARE vMaxDate DATETIME DEFAULT TIMESTAMPADD(YEAR,1,vn.VN_CURDATE()); IF NEW.shipped > vMaxDate THEN SET NEW.shipped = vMaxDate; @@ -32356,65 +28685,6 @@ CREATE TABLE `greugeType` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Temporary table structure for view `holidayDetail__` --- - -DROP TABLE IF EXISTS `holidayDetail__`; -/*!50001 DROP VIEW IF EXISTS `holidayDetail__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `holidayDetail__` ( - `id` tinyint NOT NULL, - `description` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `holidayLegend__` --- - -DROP TABLE IF EXISTS `holidayLegend__`; -/*!50001 DROP VIEW IF EXISTS `holidayLegend__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `holidayLegend__` ( - `id` tinyint NOT NULL, - `description` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `holidayType__` --- - -DROP TABLE IF EXISTS `holidayType__`; -/*!50001 DROP VIEW IF EXISTS `holidayType__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `holidayType__` ( - `id` tinyint NOT NULL, - `name` tinyint NOT NULL, - `rgb` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `holiday__` --- - -DROP TABLE IF EXISTS `holiday__`; -/*!50001 DROP VIEW IF EXISTS `holiday__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `holiday__` ( - `holidayDetailFk` tinyint NOT NULL, - `holidayTypeFk` tinyint NOT NULL, - `workCenterFk` tinyint NOT NULL, - `dated` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - -- -- Table structure for table `host` -- @@ -32466,7 +28736,7 @@ DELIMITER ;; BEFORE UPDATE ON `host` FOR EACH ROW BEGIN - SET new.updated = util.VN_NOW(); + SET new.updated = vn.VN_NOW(); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -32500,11 +28770,11 @@ CREATE TABLE `ink` ( `name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `picture` blob NOT NULL, `showOrder` int(11) NOT NULL, - `ball` blob DEFAULT NULL, - `isCargex` tinyint(4) NOT NULL DEFAULT 0, + `ball` blob, + `isCargex` tinyint(4) NOT NULL DEFAULT '0', `dutchCode` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `hex` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, - `isRealColor` tinyint(1) NOT NULL DEFAULT 1, + `isRealColor` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `dutchCode_UNIQUE` (`dutchCode`), CONSTRAINT `ink_fk1` FOREIGN KEY (`dutchCode`) REFERENCES `edi`.`feature` (`feature_value`) ON DELETE SET NULL ON UPDATE CASCADE @@ -32522,7 +28792,8 @@ CREATE TABLE `inkI18n` ( `inkFk` char(3) COLLATE utf8_unicode_ci NOT NULL, `lang` char(2) CHARACTER SET utf8 NOT NULL, `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, - PRIMARY KEY (`inkFk`,`lang`) + PRIMARY KEY (`inkFk`,`lang`), + CONSTRAINT `inkI18n_FK` FOREIGN KEY (`inkFk`) REFERENCES `ink` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -32550,9 +28821,9 @@ DROP TABLE IF EXISTS `intrastat`; CREATE TABLE `intrastat` ( `id` int(8) unsigned zerofill NOT NULL, `description` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `import__` tinyint(4) NOT NULL DEFAULT 0, - `taxClassFk` tinyint(3) unsigned NOT NULL DEFAULT 2, - `taxCodeFk` tinyint(2) unsigned NOT NULL DEFAULT 64, + `import__` tinyint(4) NOT NULL DEFAULT '0', + `taxClassFk` tinyint(3) unsigned NOT NULL DEFAULT '2', + `taxCodeFk` tinyint(2) unsigned NOT NULL DEFAULT '64', PRIMARY KEY (`id`), KEY `iva_group_id` (`taxClassFk`), CONSTRAINT `intrastat_ibfk_1` FOREIGN KEY (`taxClassFk`) REFERENCES `taxClass` (`id`) ON UPDATE CASCADE @@ -32588,7 +28859,7 @@ CREATE TABLE `inventoryFailure` ( CONSTRAINT `inventoryFailure_fk3` FOREIGN KEY (`guiltyFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `inventoryFailure_fk4` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `inventoryFailure_fk5` FOREIGN KEY (`causeFk`) REFERENCES `inventoryFailureCause` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32602,7 +28873,7 @@ CREATE TABLE `inventoryFailureCause` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32617,7 +28888,7 @@ CREATE TABLE `invoiceCorrection` ( `correctedFk` int(10) unsigned NOT NULL COMMENT 'Factura rectificada', `cplusRectificationTypeFk` int(10) unsigned NOT NULL, `cplusInvoiceType477Fk` int(10) unsigned NOT NULL, - `invoiceCorrectionTypeFk` int(11) NOT NULL DEFAULT 3, + `invoiceCorrectionTypeFk` int(11) NOT NULL DEFAULT '3', PRIMARY KEY (`correctingFk`), KEY `correctedFk_idx` (`correctedFk`), KEY `invoiceCorrection_ibfk_1_idx` (`cplusRectificationTypeFk`), @@ -32663,7 +28934,7 @@ CREATE TABLE `invoiceCorrectionType` ( `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `description_UNIQUE` (`description`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -32680,20 +28951,20 @@ CREATE TABLE `invoiceIn` ( `supplierFk` int(11) NOT NULL, `issued` date DEFAULT NULL COMMENT 'Fecha de emision de la factura', `supplierRef` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `isBooked` tinyint(1) NOT NULL DEFAULT 0, - `currencyFk` tinyint(3) unsigned NOT NULL DEFAULT 1, - `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), - `companyFk` smallint(5) unsigned NOT NULL DEFAULT 442, + `isBooked` tinyint(1) NOT NULL DEFAULT '0', + `currencyFk` tinyint(3) unsigned NOT NULL DEFAULT '1', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', `docFk` int(11) DEFAULT NULL, `booked` date DEFAULT NULL COMMENT 'Fecha de contabilizacion', `operated` date DEFAULT NULL COMMENT 'Fecha de entrega de la mercancia o el suministro', - `cplusInvoiceType472Fk` int(10) unsigned DEFAULT 1, - `cplusRectificationTypeFk` int(10) unsigned DEFAULT 1, - `cplusSubjectOpFk` int(10) unsigned DEFAULT 1, - `cplusTaxBreakFk` int(10) unsigned DEFAULT 1, - `cplusTrascendency472Fk` int(10) unsigned DEFAULT 1, + `cplusInvoiceType472Fk` int(10) unsigned DEFAULT '1', + `cplusRectificationTypeFk` int(10) unsigned DEFAULT '1', + `cplusSubjectOpFk` int(10) unsigned DEFAULT '1', + `cplusTaxBreakFk` int(10) unsigned DEFAULT '1', + `cplusTrascendency472Fk` int(10) unsigned DEFAULT '1', `bookEntried` date DEFAULT NULL COMMENT 'Fecha Asiento', - `isVatDeductible` tinyint(1) NOT NULL DEFAULT 1, + `isVatDeductible` tinyint(1) NOT NULL DEFAULT '1', `withholdingSageFk` smallint(6) DEFAULT NULL COMMENT 'Tipos de retención SAGE', `expenceFkDeductible` varchar(10) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`id`), @@ -32880,10 +29151,10 @@ CREATE TABLE `invoiceInDueDay` ( `id` int(11) NOT NULL AUTO_INCREMENT, `invoiceInFk` mediumint(8) unsigned NOT NULL, `dueDated` date NOT NULL, - `bankFk` int(11) NOT NULL DEFAULT 3117, - `amount` decimal(10,2) NOT NULL DEFAULT 0.00, + `bankFk` int(11) NOT NULL DEFAULT '3117', + `amount` decimal(10,2) NOT NULL DEFAULT '0.00', `foreignValue` decimal(10,2) DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `recibida_id` (`invoiceInFk`), KEY `banco_id` (`bankFk`), @@ -32912,14 +29183,14 @@ BEGIN JOIN vn.payMethod pm ON pm.id = s.payMethodFk WHERE ii.id = NEW.invoiceInFk; - IF (NEW.dueDated <= util.VN_CURDATE() AND vIsNotified) + IF (NEW.dueDated <= vn.VN_CURDATE() AND vIsNotified) THEN CALL mail_insert( 'begonya@verdnatura.es', 'begonya@verdnatura.es', 'Añadido vencimiento en el pasado', CONCAT( - account.myUserGetName(), ' ha añadido un vencimiento de ', + account.myUser_getName(), ' ha añadido un vencimiento de ', NEW.amount, '€ en una fecha pasada en la recibida ', NEW.invoiceInFk ) ); @@ -32952,14 +29223,14 @@ BEGIN JOIN vn.payMethod pm ON pm.id = s.payMethodFk WHERE ii.id = NEW.invoiceInFk; - IF (NEW.dueDated <= util.VN_CURDATE() AND vIsNotified) + IF (NEW.dueDated <= vn.VN_CURDATE() AND vIsNotified) THEN CALL mail_insert( 'begonya@verdnatura.es', 'begonya@verdnatura.es', 'Añadido vencimiento en el pasado', CONCAT( - account.myUserGetName(), ' ha añadido un vencimiento de ', + account.myUser_getName(), ' ha añadido un vencimiento de ', NEW.amount,'€ en una fecha pasada en la recibida ',NEW.invoiceInFk ) ); @@ -32983,18 +29254,18 @@ CREATE TABLE `invoiceInIntrastat` ( `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `invoiceInFk` mediumint(8) unsigned NOT NULL, `net` decimal(10,2) DEFAULT NULL, - `intrastatFk` int(8) unsigned zerofill NOT NULL DEFAULT 06049190, + `intrastatFk` int(8) unsigned zerofill NOT NULL DEFAULT '06049190', `amount` double NOT NULL, `stems` int(11) NOT NULL, `countryFk` mediumint(8) unsigned DEFAULT NULL, - `dated` timestamp NOT NULL DEFAULT current_timestamp(), - `statisticalValue` double NOT NULL DEFAULT 0, + `dated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `statisticalValue` double NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `intrastat_id` (`intrastatFk`), KEY `invoiceInIntrastat_FK` (`invoiceInFk`), CONSTRAINT `invoiceInIntrastat_FK` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE, CONSTRAINT `invoiceInIntrastat_ibfk_1` FOREIGN KEY (`intrastatFk`) REFERENCES `intrastat` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33028,11 +29299,11 @@ CREATE TABLE `invoiceInLog` ( `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 DEFAULT 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 DEFAULT NULL, - `newInstance` text 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`), @@ -33056,7 +29327,7 @@ CREATE TABLE `invoiceInSage` ( `invoiceInSerialFk` varchar(2) COLLATE utf8_unicode_ci NOT NULL, `taxTypeSageFk` smallint(6) NOT NULL, `transactionTypeSageFk` tinyint(4) NOT NULL, - `isService` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Para diferenciar producto de servicio', + `isService` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Para diferenciar producto de servicio', `expenceFk` varchar(10) CHARACTER SET utf8 NOT NULL, `withholdingSageFk` smallint(6) DEFAULT NULL, PRIMARY KEY (`id`), @@ -33073,7 +29344,7 @@ CREATE TABLE `invoiceInSage` ( CONSTRAINT `invoiceInSage_taxTypeSageFk` FOREIGN KEY (`taxTypeSageFk`) REFERENCES `sage`.`TiposIva` (`CodigoIva`) ON UPDATE CASCADE, CONSTRAINT `invoiceInSage_transactionTypeSageFk` FOREIGN KEY (`transactionTypeSageFk`) REFERENCES `sage`.`TiposTransacciones` (`CodigoTransaccion`) ON UPDATE CASCADE, CONSTRAINT `invoiceInSage_withholdingSageFk` FOREIGN KEY (`withholdingSageFk`) REFERENCES `sage`.`TiposRetencion` (`CodigoRetencion`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciones de entrelas series de facturas recibidas y sus tipo de IVA con código Iva y codigo de Transación en Sage. Para precontabilizadar facturas recibidas'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciones de entrelas series de facturas recibidas y sus tipo de IVA con código Iva y codigo de Transación en Sage. Para precontabilizadar facturas recibidas'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33086,7 +29357,7 @@ DROP TABLE IF EXISTS `invoiceInSerial`; CREATE TABLE `invoiceInSerial` ( `code` varchar(2) COLLATE utf8_unicode_ci NOT NULL, `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `cplusTerIdNifFk` int(11) NOT NULL DEFAULT 1, + `cplusTerIdNifFk` int(11) NOT NULL DEFAULT '1', `taxAreaFk` varchar(15) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`code`), KEY `InvoiceInSerial_Fk1_idx` (`cplusTerIdNifFk`), @@ -33112,7 +29383,7 @@ CREATE TABLE `invoiceInTax` ( `foreignValue` decimal(10,2) DEFAULT NULL, `taxTypeSageFk` smallint(6) DEFAULT NULL COMMENT 'Tipo de IVA SAGE', `transactionTypeSageFk` tinyint(4) DEFAULT NULL COMMENT 'Tipo de transacción SAGE', - `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `recibida_id` (`invoiceInFk`), KEY `recibida_iva_ibfk_2` (`taxCodeFk`), @@ -33135,13 +29406,13 @@ DROP TABLE IF EXISTS `invoiceInTaxBookingAccount`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `invoiceInTaxBookingAccount` ( `id` int(10) NOT NULL AUTO_INCREMENT, - `effectived` timestamp NOT NULL DEFAULT current_timestamp(), + `effectived` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `account` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `taxAreaFk` varchar(15) CHARACTER SET utf8 NOT NULL, `priority` int(2) unsigned DEFAULT NULL, - `taxClassFk` tinyint(3) unsigned NOT NULL DEFAULT 1, - `countryFk` mediumint(8) unsigned NOT NULL DEFAULT 1, - `rate` decimal(5,2) NOT NULL DEFAULT 0.00, + `taxClassFk` tinyint(3) unsigned NOT NULL DEFAULT '1', + `countryFk` mediumint(8) unsigned NOT NULL DEFAULT '1', + `rate` decimal(5,2) NOT NULL DEFAULT '0.00', PRIMARY KEY (`id`), KEY `invoiceInTaxBookingAccount_fk1_idx` (`taxAreaFk`), KEY `invoiceInTaxBookingAccount_fk2_idx` (`taxClassFk`), @@ -33149,7 +29420,7 @@ CREATE TABLE `invoiceInTaxBookingAccount` ( CONSTRAINT `invoiceInTaxBookingAccount_fk1` FOREIGN KEY (`taxAreaFk`) REFERENCES `taxArea` (`code`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceInTaxBookingAccount_fk2` FOREIGN KEY (`taxClassFk`) REFERENCES `taxClass` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoiceInTaxBookingAccount_fk3` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33164,25 +29435,25 @@ CREATE TABLE `invoiceOut` ( `ref` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `serial` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL, `issued` date DEFAULT NULL, - `amount` decimal(12,2) DEFAULT 0.00, + `amount` decimal(12,2) DEFAULT '0.00', `dued` datetime DEFAULT NULL, `bankFk` int(11) DEFAULT NULL, - `clientFk` 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, - `hasPdf` tinyint(3) unsigned NOT NULL DEFAULT 0, + `clientFk` 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', + `hasPdf` tinyint(3) unsigned NOT NULL DEFAULT '0', `booked` date DEFAULT NULL, - `cplusInvoiceType477Fk` int(10) unsigned NOT NULL DEFAULT 1, - `cplusTaxBreakFk` int(10) unsigned NOT NULL DEFAULT 1, - `cplusSubjectOpFk` int(10) unsigned NOT NULL DEFAULT 1, - `cplusTrascendency477Fk` int(10) unsigned NOT NULL DEFAULT 1, + `cplusInvoiceType477Fk` int(10) unsigned NOT NULL DEFAULT '1', + `cplusTaxBreakFk` int(10) unsigned NOT NULL DEFAULT '1', + `cplusSubjectOpFk` int(10) unsigned NOT NULL DEFAULT '1', + `cplusTrascendency477Fk` int(10) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`,`ref`), UNIQUE KEY `Id_Factura` (`ref`), KEY `Id_Banco` (`bankFk`), @@ -33225,7 +29496,7 @@ BEGIN SELECT CONCAT(NEW.serial, IFNULL(RIGHT(MAX(i.ref), LENGTH(i.ref)-1) , - RPAD(CONCAT(c.sage200Company, RIGHT(YEAR(util.VN_CURDATE()), 2)), 7,'0')) + 1) INTO vRef + RPAD(CONCAT(c.sage200Company, RIGHT(YEAR(vn.VN_CURDATE()), 2)), 7,'0')) + 1) INTO vRef FROM invoiceOut i LEFT JOIN company c ON c.id = i.companyFk WHERE i.serial = NEW.serial @@ -33235,7 +29506,7 @@ BEGIN SELECT CONCAT(NEW.serial, IFNULL(RIGHT(MAX(i.ref), LENGTH(i.ref)-1) , - RPAD(CONCAT(c.sage200Company, RIGHT(YEAR(util.VN_CURDATE()), 2)), 8,'0')) + 1) INTO vRef + RPAD(CONCAT(c.sage200Company, RIGHT(YEAR(vn.VN_CURDATE()), 2)), 8,'0')) + 1) INTO vRef FROM invoiceOut i LEFT JOIN company c ON c.id = i.companyFk WHERE i.serial = NEW.serial @@ -33335,9 +29606,9 @@ DROP TABLE IF EXISTS `invoiceOutExpence`; CREATE TABLE `invoiceOutExpence` ( `id` int(11) NOT NULL AUTO_INCREMENT, `invoiceOutFk` int(10) unsigned NOT NULL, - `amount` decimal(10,2) NOT NULL DEFAULT 0.00, + `amount` decimal(10,2) NOT NULL DEFAULT '0.00', `expenceFk` varchar(10) CHARACTER SET utf8 NOT NULL, - `created` timestamp NULL DEFAULT current_timestamp(), + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `invoiceOutExpence_FK_1_idx` (`invoiceOutFk`), KEY `invoiceOutExpence_FK_2_idx` (`expenceFk`), @@ -33356,12 +29627,12 @@ DROP TABLE IF EXISTS `invoiceOutSerial`; CREATE TABLE `invoiceOutSerial` ( `code` varchar(2) COLLATE utf8_unicode_ci NOT NULL, `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `isTaxed` tinyint(1) NOT NULL DEFAULT 1, + `isTaxed` tinyint(1) NOT NULL DEFAULT '1', `taxAreaFk` varchar(15) CHARACTER SET utf8 NOT NULL DEFAULT 'NATIONAL', - `isCEE` tinyint(1) NOT NULL DEFAULT 0, - `cplusInvoiceType477Fk` int(10) unsigned DEFAULT 1, - `footNotes` longtext COLLATE utf8_unicode_ci DEFAULT NULL, - `isRefEditable` tinyint(4) NOT NULL DEFAULT 0, + `isCEE` tinyint(1) NOT NULL DEFAULT '0', + `cplusInvoiceType477Fk` int(10) unsigned DEFAULT '1', + `footNotes` longtext COLLATE utf8_unicode_ci, + `isRefEditable` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`code`), KEY `taxAreaFk_idx` (`taxAreaFk`), CONSTRAINT `invoiceOutSeriaTaxArea` FOREIGN KEY (`taxAreaFk`) REFERENCES `taxArea` (`code`) ON UPDATE CASCADE @@ -33379,8 +29650,8 @@ CREATE TABLE `invoiceOutTax` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `invoiceOutFk` int(10) unsigned NOT NULL, `taxableBase` decimal(10,2) NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), - `vat` decimal(10,2) NOT NULL DEFAULT 0.00, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `vat` decimal(10,2) NOT NULL DEFAULT '0.00', `pgcFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0000000000', PRIMARY KEY (`id`), UNIQUE KEY `invoiceOutTax_Resctriccion` (`invoiceOutFk`,`pgcFk`), @@ -33403,7 +29674,7 @@ CREATE TABLE `invoiceOutTaxConfig` ( `taxClassCodeFk` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `taxTypeSageFk` smallint(6) DEFAULT NULL, `transactionTypeSageFk` tinyint(4) DEFAULT NULL, - `isService` tinyint(1) DEFAULT 0, + `isService` tinyint(1) DEFAULT '0', `expenceFk` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `invoiceOutTaxConfig_FK` (`taxClassCodeFk`), @@ -33412,7 +29683,24 @@ CREATE TABLE `invoiceOutTaxConfig` ( CONSTRAINT `invoiceOutTaxConfig_FK` FOREIGN KEY (`taxClassCodeFk`) REFERENCES `taxClass` (`code`), CONSTRAINT `invoiceOutTaxConfig_FK_1` FOREIGN KEY (`taxTypeSageFk`) REFERENCES `sage`.`TiposIva` (`CodigoIva`), CONSTRAINT `invoiceOutTaxConfig_FK_2` FOREIGN KEY (`transactionTypeSageFk`) REFERENCES `sage`.`TiposTransacciones` (`CodigoTransaccion`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `invoiceOut_queue` +-- + +DROP TABLE IF EXISTS `invoiceOut_queue`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `invoiceOut_queue` ( + `invoiceFk` int(10) unsigned NOT NULL, + `queued` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + `printed` datetime DEFAULT NULL, + `status` varchar(50) COLLATE utf8_unicode_ci DEFAULT '', + PRIMARY KEY (`invoiceFk`), + CONSTRAINT `invoiceOut_queue_invoiceOut_id_fk` FOREIGN KEY (`invoiceFk`) REFERENCES `invoiceOut` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queue for PDF invoicing'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -33427,33 +29715,33 @@ CREATE TABLE `item` ( `equivalent` int(11) unsigned DEFAULT NULL, `name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `size` int(10) unsigned DEFAULT NULL, - `stems` int(11) DEFAULT 1, - `minPrice` double DEFAULT 0, - `isToPrint` tinyint(1) NOT NULL DEFAULT 0, - `isDeliveryNote__` tinyint(1) NOT NULL DEFAULT 0, - `taxClassFk__` tinyint(4) unsigned NOT NULL DEFAULT 1, + `stems` int(11) DEFAULT '1', + `minPrice` double DEFAULT '0', + `isToPrint` tinyint(1) NOT NULL DEFAULT '0', + `isDeliveryNote__` tinyint(1) NOT NULL DEFAULT '0', + `taxClassFk__` tinyint(4) unsigned NOT NULL DEFAULT '1', `family` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT 'VT', - `box` tinyint(1) NOT NULL DEFAULT 0, + `box` tinyint(1) NOT NULL DEFAULT '0', `category` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `originFk` tinyint(2) unsigned NOT NULL, - `doPhoto` tinyint(4) NOT NULL DEFAULT 0, + `doPhoto` tinyint(4) NOT NULL DEFAULT '0', `image` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `inkFk` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, `niche__` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, - `intrastatFk` int(8) unsigned zerofill NOT NULL DEFAULT 06039010, - `hasMinPrice` tinyint(1) NOT NULL DEFAULT 0, - `created` timestamp NOT NULL DEFAULT current_timestamp(), - `isOnOffer__` tinyint(4) NOT NULL DEFAULT 0, - `isBargain__` tinyint(4) NOT NULL DEFAULT 0, + `intrastatFk` int(8) unsigned zerofill NOT NULL DEFAULT '06039010', + `hasMinPrice` tinyint(1) NOT NULL DEFAULT '0', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `isOnOffer__` tinyint(4) NOT NULL DEFAULT '0', + `isBargain__` tinyint(4) NOT NULL DEFAULT '0', `comment` varchar(150) COLLATE utf8_unicode_ci DEFAULT NULL, `typeFk` smallint(5) unsigned NOT NULL, - `generic` tinyint(1) unsigned zerofill NOT NULL DEFAULT 0, + `generic` tinyint(1) unsigned zerofill NOT NULL DEFAULT '0', `producerFk` mediumint(3) unsigned DEFAULT NULL, `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `density` int(11) NOT NULL DEFAULT 167 COMMENT 'Almacena la densidad en kg/m3 para el calculo de los portes, si no se especifica se pone por defecto la del tipo en un trigger', - `relevancy` tinyint(1) NOT NULL DEFAULT 0, + `density` int(11) NOT NULL DEFAULT '167' COMMENT 'Almacena la densidad en kg/m3 para el calculo de los portes, si no se especifica se pone por defecto la del tipo en un trigger', + `relevancy` tinyint(1) NOT NULL DEFAULT '0', `expenceFk` varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '7001000000', - `isActive` tinyint(1) NOT NULL DEFAULT 1, + `isActive` tinyint(1) NOT NULL DEFAULT '1', `longName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `subName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `tag5` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, @@ -33468,23 +29756,25 @@ CREATE TABLE `item` ( `value9` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `tag10` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `value10` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `compression` decimal(5,2) NOT NULL DEFAULT 1.00 COMMENT 'Relacion de compresividad entre el volumen de las entradas en Silla y el empaquetado en los envios a clientes.\n\nMenor que 1 significa que se puede comprimir más que el volumen original.', - `minimum` decimal(10,0) unsigned NOT NULL DEFAULT 3 COMMENT 'Cantidad máxima de cajas / cubos que cabe en un nicho', - `upToDown` decimal(10,0) unsigned NOT NULL DEFAULT 0 COMMENT 'Se muestra el precio por kilo ', + `compression__` decimal(5,2) NOT NULL DEFAULT '1.00' COMMENT 'Relacion de compresividad entre el volumen de las entradas en Silla y el empaquetado en los envios a clientes.', + `minimum` decimal(10,0) unsigned NOT NULL DEFAULT '3' COMMENT 'Cantidad máxima de cajas / cubos que cabe en un nicho', + `upToDown` decimal(10,0) unsigned NOT NULL DEFAULT '0' COMMENT 'Se muestra el precio por kilo ', `supplyResponseFk` int(11) DEFAULT NULL, `hasKgPrice` tinyint(1) NOT NULL DEFAULT '0', - `sectorFk` int(11) DEFAULT NULL, + `sectorFk__` int(11) DEFAULT NULL, `isFloramondo` tinyint(1) NOT NULL DEFAULT '0', `isFragile` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'articulos solo para recogidas por su fragilidad', `numberOfItemsPerCask` int(11) DEFAULT NULL COMMENT 'Campo para Floramondo', `embalageCode` int(11) DEFAULT NULL COMMENT 'Campo para Floramondo', `quality` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Campo para Floramondo', `stars` int(11) DEFAULT NULL, - `stemMultiplier` double NOT NULL DEFAULT 1 COMMENT 'este valor multiplica las unidades y divide los precios en el procedimiento edi.ekt_load', + `stemMultiplier` double NOT NULL DEFAULT '1' COMMENT 'este valor multiplica las unidades y divide los precios en el procedimiento edi.ekt_load', `itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `packingOut` decimal(10,2) DEFAULT NULL COMMENT 'cantidad que cabe en una caja de verdnatura', `genericFk` int(11) DEFAULT NULL COMMENT 'Item genérico', `packingShelve` int(11) DEFAULT NULL COMMENT 'unidades que caben en una bandeja, en el caso de los sacadores', + `isLaid` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Indica si el producto se puede tumbar a efectos del transporte desde Holanda', + `lastUsed` datetime DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `item_supplyResponseFk_idx` (`supplyResponseFk`), KEY `Color` (`inkFk`), @@ -33494,7 +29784,7 @@ CREATE TABLE `item` ( KEY `tipo_id` (`typeFk`), KEY `producer_id` (`producerFk`), KEY `ArticlesIsActive_idx` (`isActive`), - KEY `item_ibfk_6_idx` (`sectorFk`), + KEY `item_ibfk_6_idx` (`sectorFk__`), KEY `item_expenceFk` (`expenceFk`), KEY `Article` (`name`,`subName`,`value5`,`value6`,`value7`,`value8`,`value9`,`value10`), KEY `item_id10` (`embalageCode`), @@ -33504,6 +29794,7 @@ CREATE TABLE `item` ( KEY `item_FK` (`genericFk`), KEY `item_size_IDX` (`size`) USING BTREE, KEY `item_size_IDX2` (`longName`) USING BTREE, + KEY `item_lastUsed_IDX` (`lastUsed`) USING BTREE, CONSTRAINT `item_FK` FOREIGN KEY (`genericFk`) REFERENCES `item` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `item_expenceFk` FOREIGN KEY (`expenceFk`) REFERENCES `expence` (`id`) ON UPDATE CASCADE, CONSTRAINT `item_family` FOREIGN KEY (`family`) REFERENCES `itemFamily` (`code`) ON UPDATE CASCADE, @@ -33511,7 +29802,6 @@ CREATE TABLE `item` ( CONSTRAINT `item_ibfk_2` FOREIGN KEY (`intrastatFk`) REFERENCES `intrastat` (`id`) ON UPDATE CASCADE, CONSTRAINT `item_ibfk_4` FOREIGN KEY (`taxClassFk__`) REFERENCES `taxClass` (`id`) ON UPDATE CASCADE, CONSTRAINT `item_ibfk_5` FOREIGN KEY (`typeFk`) REFERENCES `itemType` (`id`) ON UPDATE CASCADE, - CONSTRAINT `item_ibfk_6` FOREIGN KEY (`sectorFk`) REFERENCES `sector` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `itemsupplyResponseFk` FOREIGN KEY (`supplyResponseFk`) REFERENCES `edi`.`supplyResponse` (`ID`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `producer_id` FOREIGN KEY (`producerFk`) REFERENCES `producer` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -33530,32 +29820,24 @@ DELIMITER ;; FOR EACH ROW BEGIN DECLARE vDensity DOUBLE; - DECLARE vCompression DOUBLE; DECLARE vItemPackingType VARCHAR(1); IF NEW.density IS NULL THEN SELECT density INTO vDensity FROM itemType WHERE id = NEW.typeFk; - + SET NEW.density = vDensity; END IF; - - IF NEW.compression IS NULL OR NEW.compression = 1 THEN - SELECT compression INTO vCompression - FROM itemType WHERE id = NEW.typeFk; - - SET NEW.compression = vCompression; + + IF NEW.itemPackingTypeFk IS NULL THEN + + SELECT itemPackingTypeFk INTO vItemPackingType + FROM vn.itemType it + WHERE id = NEW.typeFk; + + SET NEW.itemPackingTypeFk = vItemPackingType; + END IF; - - IF NEW.itemPackingTypeFk IS NULL THEN - - SELECT itemPackingTypeFk INTO vItemPackingType - FROM vn.itemType it - WHERE id = NEW.typeFk; - - SET NEW.itemPackingTypeFk = vItemPackingType; - - END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -33571,26 +29853,26 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`item_afterInsert` - AFTER INSERT ON `item` - FOR EACH ROW -BEGIN - - CALL hedera.image_ref('catalog', NEW.image); - - INSERT INTO vn.itemTaxCountry(itemFk, countryFk) - SELECT NEW.id, 1; - - INSERT INTO vn.itemTaxCountry(itemFk, countryFk) - SELECT NEW.id, 5; - - INSERT INTO vn.itemTaxCountry(itemFk, countryFk) - SELECT NEW.id, 30; - - DELETE ifr.* - FROM edi.item_free ifr - WHERE ifr.id = NEW.id; - +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`item_afterInsert` + AFTER INSERT ON `item` + FOR EACH ROW +BEGIN + + CALL hedera.image_ref('catalog', NEW.image); + + INSERT INTO vn.itemTaxCountry(itemFk, countryFk) + SELECT NEW.id, 1; + + INSERT INTO vn.itemTaxCountry(itemFk, countryFk) + SELECT NEW.id, 5; + + INSERT INTO vn.itemTaxCountry(itemFk, countryFk) + SELECT NEW.id, 30; + + DELETE ifr.* + FROM edi.item_free ifr + WHERE ifr.id = NEW.id; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -33748,10 +30030,10 @@ CREATE TABLE `itemCategory` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `order` int(10) unsigned DEFAULT NULL, - `display` tinyint(4) NOT NULL DEFAULT 1, + `display` tinyint(4) NOT NULL DEFAULT '1', `color` char(6) COLLATE utf8_unicode_ci DEFAULT NULL, - `shortLife` int(11) NOT NULL DEFAULT 0 COMMENT 'Sirve para filtrar aquellos reinos que tienen precios estables', - `merchandise` tinyint(1) NOT NULL DEFAULT 1, + `shortLife` int(11) NOT NULL DEFAULT '0' COMMENT 'Sirve para filtrar aquellos reinos que tienen precios estables', + `merchandise` tinyint(1) NOT NULL DEFAULT '1', `icon` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `code` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `isReclining` tinyint(4) NOT NULL DEFAULT '1', @@ -33817,6 +30099,38 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `itemCleanConfig` +-- + +DROP TABLE IF EXISTS `itemCleanConfig`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `itemCleanConfig` ( + `id` int(11) NOT NULL, + `step` int(11) NOT NULL COMMENT 'Indica los items que procesa en cada ciclo', + `quantity` int(11) NOT NULL COMMENT 'Indica el número de items que va a procesar', + `isStop` tinyint(1) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `itemCleanCount` +-- + +DROP TABLE IF EXISTS `itemCleanCount`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `itemCleanCount` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `itemFrom` int(11) DEFAULT NULL COMMENT 'Indica el item por donde ha empezado', + `itemDeleted` int(11) DEFAULT NULL COMMENT 'Indica la cantidad de items que ha eliminado', + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`) +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Temporary table structure for view `itemColor` -- @@ -33839,7 +30153,8 @@ DROP TABLE IF EXISTS `itemConfig`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `itemConfig` ( - `isItemTagTriggerDisabled` tinyint(1) NOT NULL DEFAULT '1' + `isItemTagTriggerDisabled` tinyint(1) NOT NULL DEFAULT '1', + `monthToDeactivate` int(3) NOT NULL DEFAULT '24' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -33870,15 +30185,15 @@ DROP TABLE IF EXISTS `itemCost`; CREATE TABLE `itemCost` ( `itemFk` int(11) NOT NULL, `warehouseFk` smallint(6) unsigned NOT NULL, - `quantity` int(10) NOT NULL DEFAULT 0, - `rotation` decimal(10,4) NOT NULL DEFAULT 0.0000, - `cm3` int(11) NOT NULL DEFAULT 0, - `storage` decimal(10,4) NOT NULL DEFAULT 0.0000, - `handling` decimal(10,4) NOT NULL DEFAULT 0.0000, - `extraCharge` decimal(10,4) NOT NULL DEFAULT 0.0000, - `wasted` decimal(10,4) NOT NULL DEFAULT 0.0000, - `cm3delivery` int(11) NOT NULL DEFAULT 0, - `grams` int(11) NOT NULL DEFAULT 0 COMMENT 'peso en gramos de una unidad de venta', + `quantity` int(10) NOT NULL DEFAULT '0', + `rotation` decimal(10,4) NOT NULL DEFAULT '0.0000', + `cm3` int(11) NOT NULL DEFAULT '0', + `storage` decimal(10,4) NOT NULL DEFAULT '0.0000', + `handling` decimal(10,4) NOT NULL DEFAULT '0.0000', + `extraCharge` decimal(10,4) NOT NULL DEFAULT '0.0000', + `wasted` decimal(10,4) NOT NULL DEFAULT '0.0000', + `cm3delivery` int(11) NOT NULL DEFAULT '0', + `grams` int(11) NOT NULL DEFAULT '0' COMMENT 'peso en gramos de una unidad de venta', PRIMARY KEY (`itemFk`,`warehouseFk`), KEY `warehouse_id_rotacion_idx` (`warehouseFk`), CONSTRAINT `id_article_rotaci` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, @@ -33934,7 +30249,7 @@ BEGIN JOIN vn.route r ON r.id = t.routeFk WHERE r.isOk = FALSE AND ic.itemFk = NEW.itemFk - AND r.created >= util.VN_CURDATE() + AND r.created >= vn.VN_CURDATE() GROUP BY r.id; IF NEW.cm3Delivery = 0 AND NEW.warehouseFk = 60 THEN CALL mail_insert( @@ -34012,11 +30327,11 @@ DROP TABLE IF EXISTS `itemImageQueue`; CREATE TABLE `itemImageQueue` ( `itemFk` int(11) NOT NULL, `url` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `error` text COLLATE utf8_unicode_ci DEFAULT NULL, - `attempts` int(11) DEFAULT 0, - `created` timestamp NULL DEFAULT current_timestamp(), - `updated` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), - `priority` int(11) DEFAULT 99, + `error` text COLLATE utf8_unicode_ci, + `attempts` int(11) DEFAULT '0', + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `priority` int(11) DEFAULT '99', PRIMARY KEY (`itemFk`), CONSTRAINT `itemImageQueueItemIdx` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Cola para añadir las imagenes al campo vn.item.image a partir de una url'; @@ -34051,7 +30366,7 @@ CREATE TABLE `itemLabel` ( `price` decimal(10,2) DEFAULT NULL, `labels` int(11) DEFAULT NULL COMMENT 'Tabla hecha para Ruben Espinosa, para sacar etiquetas en Holanda para un cliente.', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -34066,11 +30381,11 @@ CREATE TABLE `itemLog` ( `originFk` int(11) 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 DEFAULT 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 DEFAULT NULL, - `newInstance` text 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`), @@ -34112,77 +30427,6 @@ CREATE TABLE `itemPackingType` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Define la linea de encajado para cada producto'; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `itemPlacement` --- - -DROP TABLE IF EXISTS `itemPlacement`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `itemPlacement` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `itemFk` int(11) NOT NULL, - `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT 1, - `code` varchar(10) COLLATE utf8_unicode_ci NOT NULL, - `modificationDate` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), - `reserve` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, - `pickable` int(11) unsigned NOT NULL DEFAULT 0, - `sectorFk` int(11) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `Id_Article_UNIQUE` (`itemFk`,`warehouseFk`), - KEY `Articles_nicho_wh_fk` (`warehouseFk`), - KEY `itemPlacement_fk3_idx` (`id`,`sectorFk`), - KEY `itemPlacement_fk3_idx1` (`sectorFk`), - CONSTRAINT `Articles_nicho_wh_fk` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `Articles_nichos_fk` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `itemPlacement_fk3` FOREIGN KEY (`sectorFk`) REFERENCES `sector` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemPlacement_BEFORE_INSERT` - BEFORE INSERT ON `itemPlacement` - FOR EACH ROW -BEGIN - IF LENGTH(NEW.code) < 3 THEN - CALL util.throw('code too short'); - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemPlacement_BEFORE_UPDATE` - BEFORE UPDATE ON `itemPlacement` - FOR EACH ROW -BEGIN - IF LENGTH(NEW.code) < 3 THEN - CALL util.throw('code too short'); - 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 `itemPlacementSupply` -- @@ -34193,9 +30437,9 @@ DROP TABLE IF EXISTS `itemPlacementSupply`; CREATE TABLE `itemPlacementSupply` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `itemFk` int(11) NOT NULL, - `quantity` decimal(10,0) NOT NULL DEFAULT 0, - `priority` int(10) unsigned NOT NULL DEFAULT 0, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `quantity` decimal(10,0) NOT NULL DEFAULT '0', + `priority` int(10) unsigned NOT NULL DEFAULT '0', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `userFk` int(10) unsigned NOT NULL COMMENT 'Persona que crea la orden', `repoUserFk` int(10) unsigned DEFAULT NULL COMMENT 'Reponedor que la tiene asignada', `sectorFk` int(11) DEFAULT NULL, @@ -34208,7 +30452,7 @@ CREATE TABLE `itemPlacementSupply` ( CONSTRAINT `itemPlacementSupply_fk2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemPlacementSupply_fk3` FOREIGN KEY (`repoUserFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemPlacementSupply_fk4` FOREIGN KEY (`sectorFk`) REFERENCES `sector` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de nichos de picking que hay que reponer'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de nichos de picking que hay que reponer'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -34237,6 +30481,75 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `itemPlacement__` +-- + +DROP TABLE IF EXISTS `itemPlacement__`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `itemPlacement__` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `itemFk` int(11) NOT NULL, + `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT '1', + `code` varchar(10) COLLATE utf8_unicode_ci NOT NULL, + `modificationDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `reserve` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, + `pickable` int(11) unsigned NOT NULL DEFAULT '0', + `sectorFk` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `Id_Article_UNIQUE` (`itemFk`,`warehouseFk`), + KEY `Articles_nicho_wh_fk` (`warehouseFk`), + KEY `itemPlacement_fk3_idx` (`id`,`sectorFk`), + KEY `itemPlacement_fk3_idx1` (`sectorFk`), + CONSTRAINT `Articles_nicho_wh_fk` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `Articles_nichos_fk` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `itemPlacement_fk3` FOREIGN KEY (`sectorFk`) REFERENCES `sector` (`id`) ON DELETE SET NULL ON UPDATE CASCADE +) 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemPlacement_BEFORE_INSERT` + BEFORE INSERT ON `itemPlacement__` FOR EACH ROW +BEGIN + IF LENGTH(NEW.code) < 3 THEN + CALL util.throw('code too short'); + 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`itemPlacement_BEFORE_UPDATE` + BEFORE UPDATE ON `itemPlacement__` FOR EACH ROW +BEGIN + IF LENGTH(NEW.code) < 3 THEN + CALL util.throw('code too short'); + END IF; +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; + -- -- Temporary table structure for view `itemProductor` -- @@ -34261,7 +30574,7 @@ DROP TABLE IF EXISTS `itemProposal`; CREATE TABLE `itemProposal` ( `itemFk` int(11) NOT NULL, `mateFk` int(11) NOT NULL, - `counter` int(11) NOT NULL DEFAULT 0, + `counter` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`itemFk`,`mateFk`), KEY `itemProposal_fk2_idx` (`mateFk`), CONSTRAINT `itemProposal_fk1` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, @@ -34278,7 +30591,7 @@ DROP TABLE IF EXISTS `itemRepo__`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `itemRepo__` ( `itemFk` int(11) NOT NULL, - `quantity` int(10) unsigned NOT NULL DEFAULT 0, + `quantity` int(10) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`itemFk`), CONSTRAINT `itemRepo_fk1` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -34349,7 +30662,7 @@ DELIMITER ;; FOR EACH ROW BEGIN - SET NEW.userFk = account.userGetId(); + SET NEW.userFk = account.myUser_getId(); END */;; @@ -34407,7 +30720,7 @@ DELIMITER ;; BEFORE UPDATE ON `itemShelving` FOR EACH ROW BEGIN - SET NEW.userFk = account.userGetId(); + SET NEW.userFk = account.myUser_getId(); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -34436,7 +30749,7 @@ INSERT INTO vn.itemShelvingLog( itemShelvingFk, packing, stars) VALUES( NEW.id, - account.userGetId(), + account.myUser_getId(), 'CAMBIO', NEW.itemFk, NEW.shelvingFk, @@ -34468,7 +30781,7 @@ INSERT INTO vn.itemShelvingLog(itemShelvingFk, shelvingFk, itemFk) VALUES( OLD.id, - account.userGetId(), + account.myUser_getId(), 'ELIMINADO', OLD.shelvingFk, OLD.itemFk) */;; @@ -34546,7 +30859,7 @@ CREATE TABLE `itemShelvingLog` ( `id` int(11) NOT NULL AUTO_INCREMENT, `itemShelvingFk` int(10) unsigned DEFAULT NULL, `workerFk` int(11) DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `accion` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `itemFk` int(11) DEFAULT NULL, `shelvingFk` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, @@ -34572,10 +30885,10 @@ CREATE TABLE `itemShelvingPlacementSupply` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `itemShelvingFk` int(10) unsigned NOT NULL, `itemPlacementSupplyFk` int(10) unsigned NOT NULL, - `quantity` decimal(10,0) NOT NULL DEFAULT 0, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `quantity` decimal(10,0) NOT NULL DEFAULT '0', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `userFk` int(10) unsigned NOT NULL, - `isPicked` tinyint(4) NOT NULL DEFAULT 0, + `isPicked` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `itemShelvingPlacementSupply_fk1_idx` (`itemShelvingFk`), KEY `itemShelvingPlacementSupply_fk2_idx` (`itemPlacementSupplyFk`), @@ -34621,8 +30934,8 @@ CREATE TABLE `itemShelvingSale` ( `id` int(11) NOT NULL AUTO_INCREMENT, `itemShelvingFk` int(10) unsigned NOT NULL, `saleFk` int(11) NOT NULL, - `quantity` decimal(10,0) NOT NULL DEFAULT 0, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `quantity` decimal(10,0) NOT NULL DEFAULT '0', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `userFk` int(11) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `itemShelvingSale_fk1_idx` (`itemShelvingFk`), @@ -34771,9 +31084,10 @@ CREATE TABLE `itemTag` ( `tagFk` int(11) NOT NULL, `value` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `intValue` int(11) DEFAULT NULL, - `priority` int(2) NOT NULL DEFAULT 0, + `priority` int(2) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `itemTagItemUq` (`itemFk`,`tagFk`), + UNIQUE KEY `itemTagItemPriority` (`itemFk`,`priority`), KEY `tagFk` (`tagFk`,`value`), KEY `priorityItem` (`priority`,`itemFk`), KEY `value` (`value`), @@ -34956,8 +31270,8 @@ CREATE TABLE `itemTaxCountry` ( `id` int(11) NOT NULL AUTO_INCREMENT, `itemFk` int(11) DEFAULT NULL, `countryFk` mediumint(8) unsigned DEFAULT NULL, - `taxClassFk` tinyint(3) unsigned NOT NULL DEFAULT 1, - `effectived` timestamp NOT NULL DEFAULT current_timestamp(), + `taxClassFk` tinyint(3) unsigned NOT NULL DEFAULT '1', + `effectived` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `itemFk_UNIQUE` (`itemFk`,`countryFk`), KEY `taxClassFK_idx` (`taxClassFk`), @@ -35000,31 +31314,33 @@ CREATE TABLE `itemType` ( `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `code` varchar(3) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(30) COLLATE utf8_unicode_ci NOT NULL, - `gramsMin` int(11) DEFAULT NULL, + `gramsMin__` int(11) DEFAULT NULL, `gramsMax` int(11) DEFAULT NULL, - `order` int(11) DEFAULT 0, + `order` int(11) DEFAULT '0', `categoryFk` int(10) unsigned NOT NULL, `workerFk` int(10) unsigned NOT NULL, - `isInventory` tinyint(4) NOT NULL DEFAULT 1 COMMENT 'Se utiliza tanto en el cálculo del inventario, como en el del informe del inventario valorado', - `created` timestamp NULL DEFAULT current_timestamp(), - `f11` tinyint(4) NOT NULL DEFAULT 0, - `transaction` tinyint(4) NOT NULL DEFAULT 0, + `isInventory` tinyint(4) NOT NULL DEFAULT '1' COMMENT 'Se utiliza tanto en el cálculo del inventario, como en el del informe del inventario valorado', + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `f11__` tinyint(4) NOT NULL DEFAULT '0', + `transaction` tinyint(4) NOT NULL DEFAULT '0', `making` int(10) unsigned DEFAULT NULL COMMENT 'Son productos de confección propia', `location` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `life` smallint(5) unsigned DEFAULT NULL, - `maneuver` double NOT NULL DEFAULT 0.21, - `target` double NOT NULL DEFAULT 0.15, - `topMargin` double NOT NULL DEFAULT 0.3, - `profit` double NOT NULL DEFAULT 0.02, - `density` double NOT NULL DEFAULT 167 COMMENT 'Almacena el valor por defecto de la densidad en kg/m3 para el calculo de los portes aereos, en articulos se guarda la correcta', - `promo` double NOT NULL DEFAULT 0, - `isPackaging` tinyint(1) NOT NULL DEFAULT 0, - `hasComponents` tinyint(1) NOT NULL DEFAULT 1, - `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT 60, - `compression` decimal(5,2) DEFAULT 1.00, + `maneuver` double NOT NULL DEFAULT '0.21', + `target` double NOT NULL DEFAULT '0.15', + `topMargin` double NOT NULL DEFAULT '0.3', + `profit` double NOT NULL DEFAULT '0.02', + `density` double NOT NULL DEFAULT '167' COMMENT 'Almacena el valor por defecto de la densidad en kg/m3 para el calculo de los portes aereos, en articulos se guarda la correcta', + `promo` double NOT NULL DEFAULT '0', + `isPackaging` tinyint(1) NOT NULL DEFAULT '0', + `hasComponents` tinyint(1) NOT NULL DEFAULT '1', + `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT '60', + `compression` decimal(5,2) DEFAULT '1.00', `itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `temperatureFk` varchar(10) CHARACTER SET utf8 DEFAULT NULL, - `isUnconventionalSize` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'familia con productos cuyas medidas no son aptas para la cinta transportadora o paletizar', + `isUnconventionalSize` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'familia con productos cuyas medidas no son aptas para la cinta transportadora o paletizar', + `isLaid` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Indica si el producto se puede tumbar a efectos del transporte desde Holanda', + `maxRefs` int(10) unsigned DEFAULT NULL COMMENT 'Indica el número máximo de referencias', PRIMARY KEY (`code`), UNIQUE KEY `tipo_id_UNIQUE` (`id`), UNIQUE KEY `Tipo_UNIQUE` (`name`,`categoryFk`), @@ -35120,7 +31436,7 @@ CREATE TABLE `itemTypeRestriction` ( UNIQUE KEY `itemTypeRestriction_UN` (`itemTypeFk`,`dated`), KEY `itemTypeRestriction_dated_IDX` (`dated`,`itemTypeFk`) USING BTREE, CONSTRAINT `itemTypeRestriction_itemType_id_fk` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35134,7 +31450,7 @@ CREATE TABLE `itemTypeTag` ( `id` int(11) NOT NULL AUTO_INCREMENT, `itemTypeFk` smallint(5) unsigned NOT NULL, `tagFk` int(11) NOT NULL, - `priority` int(2) unsigned NOT NULL DEFAULT 0, + `priority` int(2) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `itemTypeFk_UNIQUE` (`itemTypeFk`,`tagFk`), KEY `itemTypeTagTipo_idx` (`itemTypeFk`), @@ -35200,20 +31516,6 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; --- --- Table structure for table `labelReport` --- - -DROP TABLE IF EXISTS `labelReport`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `labelReport` ( - `id` tinyint(3) unsigned NOT NULL, - `name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `labourTree` -- @@ -35222,11 +31524,11 @@ DROP TABLE IF EXISTS `labourTree`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `labourTree` ( - `id` int(11) NOT NULL DEFAULT 0, + `id` int(11) NOT NULL DEFAULT '0', `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `lft` int(11) NOT NULL, `rgt` int(11) NOT NULL, - `depth` bigint(22) NOT NULL DEFAULT 0, + `depth` bigint(22) NOT NULL DEFAULT '0', `sons` decimal(10,0) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -35336,9 +31638,9 @@ CREATE TABLE `machine` ( `type` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `use` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `productionYear` int(11) DEFAULT NULL, - `photo` blob DEFAULT NULL, + `photo` blob, `workerFk` int(10) unsigned DEFAULT NULL, - `companyFk` smallint(5) unsigned NOT NULL DEFAULT 442, + `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', `ppeFk` int(11) DEFAULT NULL, `supplierFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`), @@ -35350,7 +31652,7 @@ CREATE TABLE `machine` ( CONSTRAINT `machine_FK` FOREIGN KEY (`ppeFk`) REFERENCES `ppe` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `machine_FK_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `machine_FK_2` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Maquinaria industrial, vehículos y demás elementos amortizables'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Maquinaria industrial, vehículos y demás elementos amortizables'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -35397,7 +31699,7 @@ CREATE TABLE `machineDetail` ( CONSTRAINT `machineDetail_FK` FOREIGN KEY (`machineFk`) REFERENCES `machine` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `machineDetail_FK_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `machineDetail_FK_2` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35416,7 +31718,7 @@ CREATE TABLE `machineDms` ( KEY `machineDms_FK` (`dmsFk`), CONSTRAINT `machineDms_FK` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `machineDms_FK_1` FOREIGN KEY (`machineFk`) REFERENCES `machine` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35430,14 +31732,14 @@ 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(), + `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=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Registros horarios de vehículos de almacén por empleado'; +) 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 */; -- @@ -35451,7 +31753,7 @@ CREATE TABLE `machineWorkerConfig` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `maxHours` smallint(5) unsigned NOT NULL COMMENT 'Indicates how many hours a user record is reviewed to update or insert', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35468,16 +31770,20 @@ CREATE TABLE `mail` ( `replyTo` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `subject` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `body` text COLLATE utf8_unicode_ci NOT NULL, - `sent` tinyint(2) NOT NULL DEFAULT 0, - `creationDate` timestamp NOT NULL DEFAULT current_timestamp(), + `sent` tinyint(2) NOT NULL DEFAULT '0', + `creationDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `attachment` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `status` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'OK', - `senderFk` int(11) DEFAULT NULL, - `recipientFk` int(11) DEFAULT NULL, - `plainTextBody` text COLLATE utf8_unicode_ci DEFAULT NULL, + `senderFk` int(10) unsigned DEFAULT NULL, + `recipientFk` int(10) unsigned DEFAULT NULL, + `plainTextBody` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`), KEY `sent_idx` (`sent`), - KEY `creation_idx` (`creationDate`) + KEY `creation_idx` (`creationDate`), + KEY `mail_FK_1` (`recipientFk`), + KEY `mail_FK` (`senderFk`), + CONSTRAINT `mail_FK` FOREIGN KEY (`senderFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE, + CONSTRAINT `mail_FK_1` FOREIGN KEY (`recipientFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -35519,7 +31825,7 @@ CREATE TABLE `mailTemplates` ( `name` varchar(50) CHARACTER SET utf8 NOT NULL, `attachmentPath` text CHARACTER SET utf8 NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35534,7 +31840,7 @@ CREATE TABLE `mandate` ( `clientFk` int(11) NOT NULL, `companyFk` smallint(5) unsigned NOT NULL, `code` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL, - `created` timestamp NULL DEFAULT current_timestamp(), + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `finished` timestamp NULL DEFAULT NULL, `mandateTypeFk` smallint(5) NOT NULL, PRIMARY KEY (`id`), @@ -35595,10 +31901,39 @@ DROP TABLE IF EXISTS `manuscript`; CREATE TABLE `manuscript` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code` varchar(45) CHARACTER SET utf8 NOT NULL, - `description` text COLLATE utf8_unicode_ci DEFAULT NULL, - `enabled` tinyint(1) NOT NULL DEFAULT 1, + `description` text COLLATE utf8_unicode_ci, + `enabled` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `code_UNIQUE` (`code`) +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `mdbBranch` +-- + +DROP TABLE IF EXISTS `mdbBranch`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `mdbBranch` ( + `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL DEFAULT '', + PRIMARY KEY (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `mdbVersion` +-- + +DROP TABLE IF EXISTS `mdbVersion`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `mdbVersion` ( + `app` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + `branchFk` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + `version` int(11) DEFAULT NULL, + KEY `mdbVersion_branchFk` (`branchFk`), + CONSTRAINT `mdbVersion_branchFk` FOREIGN KEY (`branchFk`) REFERENCES `mdbBranch` (`name`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -35613,7 +31948,7 @@ CREATE TABLE `medicalCenter` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35632,13 +31967,13 @@ CREATE TABLE `medicalReview` ( `isFit` tinyint(1) DEFAULT NULL, `amount` double DEFAULT NULL, `invoice` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, - `remark` longtext COLLATE utf8_unicode_ci DEFAULT NULL, + `remark` longtext COLLATE utf8_unicode_ci, PRIMARY KEY (`id`), KEY `frgcenter_idx` (`centerFk`), KEY `frgnkWorker_idx` (`workerFk`), CONSTRAINT `frgcenter` FOREIGN KEY (`centerFk`) REFERENCES `medicalCenter` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `frgnkWorker` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35653,13 +31988,13 @@ CREATE TABLE `message` ( `uuid` varchar(50) CHARACTER SET utf8 NOT NULL, `sender` varchar(50) CHARACTER SET utf8 NOT NULL, `recipient` varchar(50) CHARACTER SET utf8 NOT NULL, - `message` longtext CHARACTER SET utf8 DEFAULT NULL, - `sendDate` timestamp NULL DEFAULT current_timestamp(), + `message` longtext CHARACTER SET utf8, + `sendDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `sender` (`sender`), KEY `recipient` (`recipient`), KEY `uuid` (`uuid`(8)) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35675,13 +32010,13 @@ CREATE TABLE `messageInbox` ( `sender` varchar(50) CHARACTER SET utf8 NOT NULL, `recipient` varchar(45) CHARACTER SET utf8 NOT NULL, `finalRecipient` varchar(50) CHARACTER SET utf8 NOT NULL, - `message` longtext CHARACTER SET utf8 DEFAULT NULL, - `sendDate` timestamp NULL DEFAULT current_timestamp(), + `message` longtext CHARACTER SET utf8, + `sendDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `read` varchar(45) CHARACTER SET utf8 NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `uuid` (`uuid`(8)), KEY `finalRecipient` (`finalRecipient`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35735,7 +32070,7 @@ CREATE TABLE `mistakeType` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35749,9 +32084,13 @@ CREATE TABLE `mobileAppVersionControl` ( `id` int(11) NOT NULL AUTO_INCREMENT, `appName` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `version` varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0', - `IsVersionCritical` tinyint(1) DEFAULT 0, + `isVersionCritical` tinyint(1) DEFAULT '0', + `urlProduction` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, + `urlBeta` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, + `versionBeta` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + `isVersionBetaCritical` tinyint(1) DEFAULT '0', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla para llevar el control de las Versions de las aplicaciones móvil '; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla para llevar el control de las Versions de las aplicaciones móvil '; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35768,7 +32107,7 @@ CREATE TABLE `mrw` ( `shipped` date DEFAULT NULL, `price` decimal(10,2) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35788,23 +32127,6 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; --- --- Temporary table structure for view `newBornSales__` --- - -DROP TABLE IF EXISTS `newBornSales__`; -/*!50001 DROP VIEW IF EXISTS `newBornSales__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `newBornSales__` ( - `amount` tinyint NOT NULL, - `clientFk` tinyint NOT NULL, - `userFk` tinyint NOT NULL, - `dated` tinyint NOT NULL, - `firstShipped` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - -- -- Table structure for table `noticeCategory` -- @@ -35817,12 +32139,12 @@ CREATE TABLE `noticeCategory` ( `keyName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `subject` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `description` text COLLATE utf8_unicode_ci DEFAULT NULL, - `isEnabled` tinyint(1) NOT NULL DEFAULT 1, - `requiredRole` int(11) NOT NULL DEFAULT 1, + `description` text COLLATE utf8_unicode_ci, + `isEnabled` tinyint(1) NOT NULL DEFAULT '1', + `requiredRole` int(11) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `keyName_UNIQUE` (`keyName`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -35833,8 +32155,8 @@ DROP TABLE IF EXISTS `noticeSubscription`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `noticeSubscription` ( - `noticeCategoryFk` int(11) NOT NULL DEFAULT 0, - `userFk` int(10) unsigned NOT NULL DEFAULT 0, + `noticeCategoryFk` int(11) NOT NULL DEFAULT '0', + `userFk` int(10) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`noticeCategoryFk`,`userFk`), KEY `noticeSubscription_ibfk_2` (`userFk`), CONSTRAINT `noticeSubscription_ibfk_1` FOREIGN KEY (`noticeCategoryFk`) REFERENCES `noticeCategory` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, @@ -35853,7 +32175,7 @@ CREATE TABLE `observationType` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, `description` varchar(15) COLLATE utf8_unicode_ci NOT NULL, `code` varchar(45) COLLATE utf8_unicode_ci NOT NULL, - `hasNewBornMessage` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Indica aquellos que deben de recibir un mensaje advirtiendo de un cliente nuevo', + `hasNewBornMessage` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Indica aquellos que deben de recibir un mensaje advirtiendo de un cliente nuevo', PRIMARY KEY (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -35881,7 +32203,7 @@ DROP TABLE IF EXISTS `orderTicket`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `orderTicket` ( `orderFk` int(10) unsigned NOT NULL, - `ticketFk` int(11) NOT NULL DEFAULT 0, + `ticketFk` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ticketFk`,`orderFk`), KEY `order_id` (`orderFk`), CONSTRAINT `hedera_id` FOREIGN KEY (`orderFk`) REFERENCES `hedera`.`order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, @@ -35900,10 +32222,10 @@ CREATE TABLE `origin` ( `id` tinyint(2) unsigned NOT NULL AUTO_INCREMENT, `code` varchar(3) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL, - `warehouseFk` smallint(5) unsigned DEFAULT 4, - `flag` blob DEFAULT NULL, - `nl` tinyint(4) NOT NULL DEFAULT 0, - `countryFk` mediumint(8) unsigned NOT NULL DEFAULT 1, + `warehouseFk` smallint(5) unsigned DEFAULT '4', + `flag__` blob, + `nl__` tinyint(4) NOT NULL DEFAULT '0', + `countryFk` mediumint(8) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `Abreviatura` (`code`), KEY `warehouse_id` (`warehouseFk`), @@ -35970,7 +32292,7 @@ CREATE TABLE `packageChecked` ( PRIMARY KEY (`id`), UNIQUE KEY `entryFk_UNIQUE` (`itemFk`), KEY `fkItem_idx` (`itemFk`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36013,33 +32335,35 @@ DROP TABLE IF EXISTS `packaging`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `packaging` ( `id` varchar(10) COLLATE utf8_unicode_ci NOT NULL, - `volume` decimal(10,2) DEFAULT 0.00, - `width` decimal(10,2) DEFAULT 0.00, - `depth` decimal(10,2) DEFAULT 0.00, - `height` decimal(10,2) DEFAULT 0.00, - `value` decimal(10,2) DEFAULT 0.00, - `isPackageReturnable` tinyint(1) NOT NULL DEFAULT 0, - `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `volume` decimal(10,2) DEFAULT '0.00', + `width` decimal(10,2) DEFAULT '0.00', + `depth` decimal(10,2) DEFAULT '0.00', + `height` decimal(10,2) DEFAULT '0.00', + `value` decimal(10,2) DEFAULT '0.00', + `isPackageReturnable` tinyint(1) NOT NULL DEFAULT '0', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `packagingReturnFk` int(11) DEFAULT NULL, `lower` int(11) DEFAULT NULL, `upload` int(11) DEFAULT NULL, `base` decimal(10,2) DEFAULT NULL, `itemFk` int(11) DEFAULT NULL, `price` decimal(10,2) NOT NULL, - `isBox` tinyint(1) NOT NULL DEFAULT 0, + `isBox` tinyint(1) NOT NULL DEFAULT '0', `cubicPackage` decimal(10,2) DEFAULT NULL, - `returnCost` decimal(10,2) NOT NULL DEFAULT 0.00, + `returnCost` decimal(10,2) NOT NULL DEFAULT '0.00', `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', + `hasCompressionVariations` tinyint(1) DEFAULT '0' COMMENT 'Floramondo puede servirlos no llenos del todo', `conveyorBuildingClassFk` int(11) DEFAULT NULL, - `isTrolley` tinyint(1) NOT NULL DEFAULT 0, - `isPallet` tinyint(1) NOT NULL DEFAULT 0, + `isTrolley` tinyint(1) NOT NULL DEFAULT '0', + `isPallet` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `packaging_fk1` (`itemFk`), KEY `packaging_fk2_idx` (`freightItemFk`), KEY `packaging_FK` (`conveyorBuildingClassFk`), + KEY `packaging_FK_1` (`packagingReturnFk`), CONSTRAINT `packaging_FK` FOREIGN KEY (`conveyorBuildingClassFk`) REFERENCES `conveyorBuildingClass` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `packaging_FK_1` FOREIGN KEY (`packagingReturnFk`) REFERENCES `vn2008`.`Cubos_Retorno` (`idCubos_Retorno`) 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; @@ -36071,7 +32395,7 @@ DROP TABLE IF EXISTS `packagingGifts`; CREATE TABLE `packagingGifts` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(255) COLLATE utf8_unicode_ci NOT NULL, - `photo` blob DEFAULT NULL, + `photo` blob, `started` date NOT NULL, `ended` date NOT NULL, `warehouseFk` smallint(5) unsigned DEFAULT NULL, @@ -36084,7 +32408,7 @@ CREATE TABLE `packagingGifts` ( CONSTRAINT `PackagingGifts_FK` FOREIGN KEY (`provinceFk`) REFERENCES `province` (`id`), CONSTRAINT `PackagingGifts_FK_1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`), CONSTRAINT `PackagingGifts_FK_2` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36122,8 +32446,8 @@ CREATE TABLE `packingSiteLog` ( `workerFk` int(10) unsigned NOT NULL, `printerModelFk` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `typeErrorFk` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, - `creationDate` timestamp NULL DEFAULT current_timestamp(), - `description` text COLLATE utf8_unicode_ci DEFAULT NULL, + `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `description` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`), UNIQUE KEY `packingSiteLog_UN` (`id`), KEY `packingSiteLog_FK` (`workerFk`), @@ -36134,7 +32458,7 @@ CREATE TABLE `packingSiteLog` ( CONSTRAINT `packingSiteLog_FK_1` FOREIGN KEY (`printerModelFk`) REFERENCES `printerModel` (`code`) ON UPDATE CASCADE, CONSTRAINT `packingSiteLog_FK_2` FOREIGN KEY (`packingSiteFk`) REFERENCES `packingSite` (`code`) ON UPDATE CASCADE, CONSTRAINT `packingSiteLog_FK_4` FOREIGN KEY (`typeErrorFk`) REFERENCES `packingSiteTypeError` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36162,7 +32486,7 @@ CREATE TABLE `parking` ( `id` int(11) NOT NULL AUTO_INCREMENT, `column` varchar(5) CHARACTER SET utf8 DEFAULT '--', `row` varchar(5) CHARACTER SET utf8 DEFAULT '--', - `sectorFk` int(11) NOT NULL DEFAULT 2, + `sectorFk` int(11) NOT NULL DEFAULT '2', `code` varchar(8) CHARACTER SET utf8 DEFAULT NULL, `pickingOrder` int(11) DEFAULT NULL, PRIMARY KEY (`id`), @@ -36256,13 +32580,13 @@ CREATE TABLE `payMethod` ( `code` varchar(50) CHARACTER SET utf8 DEFAULT NULL, `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `solution` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, - `outstandingDebt` tinyint(3) unsigned zerofill NOT NULL DEFAULT 000, - `graceDays` int(11) unsigned NOT NULL DEFAULT 0, - `isIbanRequiredForClients` tinyint(3) DEFAULT 0, - `isIbanRequiredForSuppliers` tinyint(3) DEFAULT 0, - `isNotified` tinyint(3) NOT NULL DEFAULT 1, - `hasVerified` tinyint(1) DEFAULT 0, - `graceMonthsDisableChecked` int(11) unsigned NOT NULL DEFAULT 0 COMMENT 'Deshabilita la comprobación de los datos bancarios de todos aquellos proveedores que no hayan recibido un pago en los meses especificados', + `outstandingDebt` tinyint(3) unsigned zerofill NOT NULL DEFAULT '000', + `graceDays` int(11) unsigned NOT NULL DEFAULT '0', + `isIbanRequiredForClients` tinyint(3) DEFAULT '0', + `isIbanRequiredForSuppliers` tinyint(3) DEFAULT '0', + `isNotified` tinyint(3) NOT NULL DEFAULT '1', + `hasVerified` tinyint(1) DEFAULT '0', + `graceMonthsDisableChecked` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'Deshabilita la comprobación de los datos bancarios de todos aquellos proveedores que no hayan recibido un pago en los meses especificados', PRIMARY KEY (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -36278,17 +32602,17 @@ CREATE TABLE `payment` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `received` date NOT NULL, `supplierFk` int(11) NOT NULL, - `amount` decimal(10,2) NOT NULL DEFAULT 0.00, - `currencyFk` tinyint(3) unsigned NOT NULL DEFAULT 1, + `amount` decimal(10,2) NOT NULL DEFAULT '0.00', + `currencyFk` tinyint(3) unsigned NOT NULL DEFAULT '1', `divisa` decimal(10,2) DEFAULT NULL, - `bankFk` int(11) NOT NULL DEFAULT 0, + `bankFk` int(11) NOT NULL DEFAULT '0', `payMethodFk` tinyint(3) unsigned NOT NULL, - `bankingFees` double(6,2) unsigned NOT NULL DEFAULT 0.00, + `bankingFees` double(6,2) unsigned NOT NULL DEFAULT '0.00', `concept` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, - `companyFk` smallint(5) unsigned NOT NULL DEFAULT 442, - `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), - `isConciliated` tinyint(1) unsigned zerofill NOT NULL DEFAULT 0, - `exchangeInsuranceFk` int(11) DEFAULT NULL, + `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `isConciliated` tinyint(1) unsigned zerofill NOT NULL DEFAULT '0', + `exchangeInsuranceFk__` int(11) DEFAULT NULL, `dueDated` date DEFAULT NULL, `workerFk` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), @@ -36296,7 +32620,7 @@ CREATE TABLE `payment` ( KEY `id_banco` (`bankFk`), KEY `id_moneda` (`currencyFk`), KEY `pay_met` (`payMethodFk`), - KEY `fk_pago_pago_sdc1_idx` (`exchangeInsuranceFk`), + KEY `fk_pago_pago_sdc1_idx` (`exchangeInsuranceFk__`), KEY `pagoDueDatedIdx` (`dueDated`), KEY `pago_ibfk_3` (`supplierFk`), KEY `payment_FK` (`workerFk`), @@ -36306,7 +32630,7 @@ CREATE TABLE `payment` ( CONSTRAINT `payment_FK` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`), CONSTRAINT `payment_ibfk_1` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE, CONSTRAINT `payment_ibfk_2` FOREIGN KEY (`bankFk`) REFERENCES `accounting` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -36487,13 +32811,13 @@ DROP TABLE IF EXISTS `pcs`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `pcs` ( - `created` timestamp NULL DEFAULT current_timestamp(), + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `routeFk` int(10) unsigned DEFAULT NULL, `id` int(11) NOT NULL AUTO_INCREMENT, `pallet` int(11) DEFAULT NULL, `box` int(11) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36504,7 +32828,7 @@ DROP TABLE IF EXISTS `pcs_graf`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `pcs_graf` ( - `id` int(11) NOT NULL DEFAULT 0, + `id` int(11) NOT NULL DEFAULT '0', `dia` date DEFAULT NULL, `created` datetime DEFAULT NULL, `box` decimal(4,0) DEFAULT NULL, @@ -36530,7 +32854,7 @@ CREATE TABLE `pedidosInternos` ( `idArticle` int(11) DEFAULT NULL, `quantity` int(11) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36560,17 +32884,17 @@ CREATE TABLE `person` ( `surnames` varchar(60) COLLATE utf8_unicode_ci NOT NULL, `fi` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `birth` date DEFAULT NULL, - `readerId` int(11) DEFAULT NULL, + `readerId__` int(11) DEFAULT NULL, `workerFk` int(10) unsigned DEFAULT NULL, - `isDisable` tinyint(1) NOT NULL DEFAULT 0, - `isFreelance` tinyint(1) NOT NULL DEFAULT 0, - `isSsDiscounted` tinyint(1) NOT NULL DEFAULT 0, + `isDisable` tinyint(1) NOT NULL DEFAULT '0', + `isFreelance` tinyint(1) NOT NULL DEFAULT '0', + `isSsDiscounted` tinyint(1) NOT NULL DEFAULT '0', `nickname` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, - `p2` longtext COLLATE utf8_unicode_ci DEFAULT NULL, + `p2` longtext COLLATE utf8_unicode_ci, `sex` enum('M','F') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'F' COMMENT 'M Masculino F Femenino', PRIMARY KEY (`id`), UNIQUE KEY `nif` (`fi`), - UNIQUE KEY `person_UN` (`readerId`), + UNIQUE KEY `person_UN` (`readerId__`), KEY `nifIndex` (`fi`), KEY `workerFk_idx` (`workerFk`), CONSTRAINT `Person_ibfk_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE @@ -36602,11 +32926,11 @@ CREATE TABLE `pgc` ( `code` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `rate` decimal(10,2) NOT NULL, `name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `cplusTaxBreakFk` int(10) unsigned DEFAULT 1, - `mod340` tinyint(1) NOT NULL DEFAULT 0, - `mod347` tinyint(1) NOT NULL DEFAULT 0, - `cplusTrascendency477Fk` int(10) unsigned DEFAULT 1, - `isEqualizated` tinyint(1) DEFAULT 0, + `cplusTaxBreakFk` int(10) unsigned DEFAULT '1', + `mod340` tinyint(1) NOT NULL DEFAULT '0', + `mod347` tinyint(1) NOT NULL DEFAULT '0', + `cplusTrascendency477Fk` int(10) unsigned DEFAULT '1', + `isEqualizated` tinyint(1) DEFAULT '0', PRIMARY KEY (`code`), KEY `pgc_fk1_idx` (`cplusTaxBreakFk`), KEY `pgc_fk2_idx` (`cplusTrascendency477Fk`), @@ -36646,6 +32970,22 @@ CREATE TABLE `pgcMaster` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='tan solo tiene las cuentas de contaplus'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `phoneBook` +-- + +DROP TABLE IF EXISTS `phoneBook`; +/*!50001 DROP VIEW IF EXISTS `phoneBook`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `phoneBook` ( + `Tipo` tinyint NOT NULL, + `Id` tinyint NOT NULL, + `Cliente` tinyint NOT NULL, + `Telefono` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `plantpassport` -- @@ -36657,7 +32997,7 @@ CREATE TABLE `plantpassport` ( `producerFk` mediumint(3) unsigned NOT NULL, `plantpassportAuthorityFk` mediumint(3) unsigned NOT NULL, `number` varchar(25) CHARACTER SET utf8 DEFAULT NULL, - `isRequested` tinyint(2) NOT NULL DEFAULT 0, + `isRequested` tinyint(2) NOT NULL DEFAULT '0', PRIMARY KEY (`producerFk`,`plantpassportAuthorityFk`), KEY `plantpassport_authority_idx` (`plantpassportAuthorityFk`), KEY `producer_id_idx` (`producerFk`), @@ -36801,11 +33141,11 @@ DROP TABLE IF EXISTS `ppe`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `ppe` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `amortization` decimal(10,2) NOT NULL DEFAULT 0.00, + `amortization` decimal(10,2) NOT NULL DEFAULT '0.00', `firstAmortizated` date DEFAULT NULL, `lastAmortizated` date DEFAULT NULL, `finished` date DEFAULT NULL, - `value` decimal(10,2) NOT NULL DEFAULT 0.00, + `value` decimal(10,2) NOT NULL DEFAULT '0.00', `planFk` int(11) NOT NULL, `groupFk` int(11) DEFAULT NULL, `account` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, @@ -36815,10 +33155,10 @@ CREATE TABLE `ppe` ( `location` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, `discharged` date DEFAULT NULL, `cause` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `photo` blob DEFAULT NULL, - `isInvestmentAsset` tinyint(4) NOT NULL DEFAULT 0, + `photo` blob, + `isInvestmentAsset` tinyint(4) NOT NULL DEFAULT '0', `workerFk` int(10) unsigned DEFAULT NULL, - `companyFk` smallint(5) unsigned NOT NULL DEFAULT 442, + `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `ppe_fk1_idx` (`workerFk`), @@ -36835,7 +33175,7 @@ CREATE TABLE `ppe` ( CONSTRAINT `ppe_fk5` FOREIGN KEY (`account`) REFERENCES `pgcMaster` (`code`) ON UPDATE CASCADE, CONSTRAINT `ppe_fk6` FOREIGN KEY (`endowment`) REFERENCES `pgcMaster` (`code`) ON UPDATE CASCADE, CONSTRAINT `ppe_fk7` FOREIGN KEY (`elementAccount`) REFERENCES `pgcMaster` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Property, plant & equipment\nInmvolizado, en español'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Property, plant & equipment\nInmvolizado, en español'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36849,13 +33189,13 @@ CREATE TABLE `ppeComponent` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ppeFk` int(11) NOT NULL, `invoiceInFk` mediumint(8) unsigned NOT NULL, - `amount` decimal(10,2) NOT NULL DEFAULT 0.00, + `amount` decimal(10,2) NOT NULL DEFAULT '0.00', PRIMARY KEY (`id`), KEY `ppeComponent_fk1_idx` (`ppeFk`), KEY `ppeComponent_fk2_idx` (`invoiceInFk`), CONSTRAINT `ppeComponent_fk1` FOREIGN KEY (`ppeFk`) REFERENCES `ppe` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ppeComponent_fk2` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36874,7 +33214,7 @@ CREATE TABLE `ppeDMS` ( KEY `ppeDMS_fk2_idx` (`ppeFk`), CONSTRAINT `ppeDMS_fk1` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ppeDMS_fk2` FOREIGN KEY (`ppeFk`) REFERENCES `ppe` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36888,7 +33228,7 @@ CREATE TABLE `ppeGroup` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tipo de inmovilizado'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tipo de inmovilizado'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36900,10 +33240,10 @@ DROP TABLE IF EXISTS `ppePlan`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `ppePlan` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `rate` decimal(3,2) NOT NULL DEFAULT 1.00, - `days` int(11) NOT NULL DEFAULT 365, + `rate` decimal(3,2) NOT NULL DEFAULT '1.00', + `days` int(11) NOT NULL DEFAULT '365', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Plan de amortizacion para la tabla ppe'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Plan de amortizacion para la tabla ppe'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -36921,9 +33261,9 @@ CREATE TABLE `priceFixed` ( `rate3` double NOT NULL, `started` date NOT NULL, `ended` date NOT NULL, - `bonus` double NOT NULL DEFAULT 0, - `warehouseFk` smallint(5) unsigned NOT NULL DEFAULT 0, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `bonus` double NOT NULL DEFAULT '0', + `warehouseFk` smallint(5) unsigned NOT NULL DEFAULT '0', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `id` int(11) NOT NULL AUTO_INCREMENT, `grouping` smallint(5) DEFAULT NULL, `packing` int(11) DEFAULT NULL, @@ -36989,6 +33329,67 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +-- +-- Table structure for table `printQueue` +-- + +DROP TABLE IF EXISTS `printQueue`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `printQueue` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `printerFk` tinyint(3) unsigned DEFAULT NULL, + `priorityFk` tinyint(3) unsigned NOT NULL DEFAULT '3' COMMENT '1 - high, 2 - normal, 3 - low', + `reportFk` tinyint(3) unsigned DEFAULT NULL, + `statusCode` enum('queued','error','printing') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'queued', + `started` datetime DEFAULT NULL, + `finished` datetime DEFAULT NULL, + `workerFk` int(11) DEFAULT NULL, + `error` text COLLATE utf8_unicode_ci, + `errorNumber` int(11) DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + KEY `statusCode` (`statusCode`), + KEY `printerFk` (`printerFk`), + KEY `priorityFk` (`priorityFk`), + KEY `workerFk` (`workerFk`), + KEY `printQueue_report` (`reportFk`), + CONSTRAINT `printQueue_printerFk` FOREIGN KEY (`printerFk`) REFERENCES `printer` (`id`) ON UPDATE CASCADE, + CONSTRAINT `printQueue_priorityFk` FOREIGN KEY (`priorityFk`) REFERENCES `queuePriority` (`id`) ON UPDATE CASCADE, + CONSTRAINT `printQueue_report` FOREIGN KEY (`reportFk`) REFERENCES `report` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `printQueueArgs` +-- + +DROP TABLE IF EXISTS `printQueueArgs`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `printQueueArgs` ( + `printQueueFk` int(10) unsigned NOT NULL, + `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + `value` varchar(255) COLLATE utf8_unicode_ci NOT NULL, + KEY `printQueueArgs_printQueueFk_idx` (`printQueueFk`), + CONSTRAINT `printQueueArgs_printQueueFk` FOREIGN KEY (`printQueueFk`) REFERENCES `printQueue` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Argumentos que se pasarán al informe para generarlos'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `printQueueConfig` +-- + +DROP TABLE IF EXISTS `printQueueConfig`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `printQueueConfig` ( + `networkDrive` varchar(10) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'X:\\', + `dmsPath` varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT ' \\\\server\\dms', + `printQueueLimit` int(11) NOT NULL DEFAULT '30' COMMENT 'Número máximo de filas de la cola de impresión a mostrar al enviar correo a través del evento vn.printQueue_check' +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `printServerQueue` -- @@ -37001,15 +33402,15 @@ CREATE TABLE `printServerQueue` ( `printerFk` tinyint(3) unsigned DEFAULT NULL, `priorityFk` tinyint(3) unsigned DEFAULT NULL, `labelReportFk` tinyint(3) unsigned DEFAULT NULL, - `statusFk` tinyint(3) unsigned DEFAULT 1, + `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 DEFAULT NULL, - `error` text COLLATE utf8_unicode_ci DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `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`), KEY `Id_estado` (`statusFk`), @@ -37017,7 +33418,7 @@ CREATE TABLE `printServerQueue` ( KEY `Id_Prioridad` (`priorityFk`), KEY `Id_Trabajador` (`workerFk`), KEY `printServerQueue_FK` (`labelReportFk`), - CONSTRAINT `printServerQueue_FK` FOREIGN KEY (`labelReportFk`) REFERENCES `labelReport` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `printServerQueue_FK` FOREIGN KEY (`labelReportFk`) REFERENCES `report` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `printServerQueue_ibfk_3` FOREIGN KEY (`priorityFk`) REFERENCES `queuePriority` (`id`) ON UPDATE CASCADE, CONSTRAINT `printServerQueue_printerFk` FOREIGN KEY (`printerFk`) REFERENCES `printer` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -37034,22 +33435,53 @@ CREATE TABLE `printServerQueue2` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `printerFk` tinyint(3) unsigned DEFAULT NULL, `priorityFk` tinyint(3) unsigned DEFAULT NULL, - `reportFk` tinyint(3) unsigned DEFAULT 0, - `statusFk` tinyint(3) unsigned DEFAULT 1, + `reportFk` tinyint(3) unsigned DEFAULT '0', + `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 DEFAULT NULL, - `error` text COLLATE utf8_unicode_ci DEFAULT NULL, + `param3` text COLLATE utf8_unicode_ci, + `error` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`), UNIQUE KEY `Id_Impresora_2` (`printerFk`,`priorityFk`,`reportFk`,`statusFk`,`param1`,`workerFk`,`param2`), KEY `Id_estado` (`statusFk`), KEY `Id_Impresora` (`printerFk`), KEY `Id_Informe` (`reportFk`), KEY `Id_Prioridad` (`priorityFk`), - KEY `Id_Trabajador` (`workerFk`) + KEY `Id_Trabajador` (`workerFk`), + CONSTRAINT `printServerQueue2_FK_1` FOREIGN KEY (`printerFk`) REFERENCES `printer` (`id`), + CONSTRAINT `printServerQueue2_FK_2` FOREIGN KEY (`priorityFk`) REFERENCES `queuePriority` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `printer` +-- + +DROP TABLE IF EXISTS `printer`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `printer` ( + `id` tinyint(3) unsigned NOT NULL, + `name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, + `path` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, + `modelFk` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, + `macWifi` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, + `ipAddress` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, + `reference` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, + `isLabeler` tinyint(1) DEFAULT '0' COMMENT 'Indica si es impresora de etiquetas', + `sectorFk` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `printer_UN` (`reference`), + UNIQUE KEY `printer_UN1` (`macWifi`), + UNIQUE KEY `printer_UN2` (`name`), + KEY `printer_FK` (`modelFk`), + KEY `printer_sectorFk_idx` (`id`,`sectorFk`), + KEY `printer_sectorFk` (`sectorFk`), + CONSTRAINT `printer_FK` FOREIGN KEY (`modelFk`) REFERENCES `printerModel` (`code`) ON UPDATE CASCADE, + CONSTRAINT `printer_sectorFk` FOREIGN KEY (`sectorFk`) REFERENCES `sector` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -37066,49 +33498,6 @@ CREATE TABLE `printerModel` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Temporary table structure for view `printer__` --- - -DROP TABLE IF EXISTS `printer__`; -/*!50001 DROP VIEW IF EXISTS `printer__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `printer__` ( - `id` tinyint NOT NULL, - `path` tinyint NOT NULL, - `name` tinyint NOT NULL, - `reference` tinyint NOT NULL, - `isLabeler` tinyint NOT NULL, - `description` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `printer` --- - -DROP TABLE IF EXISTS `printer`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `printer` ( - `id` tinyint(3) unsigned NOT NULL, - `name` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL, - `path` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL, - `modelFk` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL, - `macWifi` varchar(20) COLLATE utf8mb3_unicode_ci DEFAULT NULL, - `ipAddress` varchar(15) COLLATE utf8mb3_unicode_ci DEFAULT NULL, - `reference` varchar(50) COLLATE utf8mb3_unicode_ci DEFAULT NULL, - `isLabeler` tinyint(1) DEFAULT 0 COMMENT 'Indica si es impresora de etiquetas', - PRIMARY KEY (`id`), - UNIQUE KEY `printer_UN` (`reference`), - UNIQUE KEY `printer_UN1` (`macWifi`), - UNIQUE KEY `printer_UN2` (`name`), - KEY `printer_FK` (`modelFk`), - CONSTRAINT `printer_FK` FOREIGN KEY (`modelFk`) REFERENCES `printerModel` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `printingQueueCheck` -- @@ -37117,9 +33506,9 @@ DROP TABLE IF EXISTS `printingQueueCheck`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `printingQueueCheck` ( - `lastCount` int(11) unsigned NOT NULL DEFAULT 0, - `lastCheckSum` int(11) unsigned NOT NULL DEFAULT 0, - `isAlreadyNotified` tinyint(2) NOT NULL DEFAULT 0, + `lastCount` int(11) unsigned NOT NULL DEFAULT '0', + `lastCheckSum` int(11) unsigned NOT NULL DEFAULT '0', + `isAlreadyNotified` tinyint(2) NOT NULL DEFAULT '0', PRIMARY KEY (`lastCount`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Comprueba que el servidor de impresion no esta parado'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -37134,12 +33523,31 @@ DROP TABLE IF EXISTS `producer`; CREATE TABLE `producer` ( `id` mediumint(3) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `isVisible` tinyint(1) NOT NULL DEFAULT 1, - `created` timestamp NULL DEFAULT current_timestamp(), + `isVisible` tinyint(1) NOT NULL DEFAULT '1', + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `name_UNIQUE` (`name`) ) 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_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`producer_afterUpdate` + AFTER INSERT ON `producer` FOR EACH ROW +BEGIN + CALL util.debugAdd('producer',CONCAT(NEW.name, NEW.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 `productionConfig` @@ -37210,7 +33618,7 @@ CREATE TABLE `professionalCategory` ( `salaryorSeniority` decimal(10,2) DEFAULT NULL, `year` int(2) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37223,7 +33631,7 @@ DROP TABLE IF EXISTS `profile`; CREATE TABLE `profile` ( `id` int(11) NOT NULL AUTO_INCREMENT, `personFk` int(11) DEFAULT NULL, - `profileTypeFk` int(11) NOT NULL DEFAULT 1, + `profileTypeFk` int(11) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), KEY `personFk` (`personFk`), KEY `profileTypeFk` (`profileTypeFk`), @@ -37243,7 +33651,7 @@ CREATE TABLE `profileType` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(15) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37255,14 +33663,14 @@ DROP TABLE IF EXISTS `project`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `project` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `name` varchar(100) COLLATE utf8_unicode_ci NOT NULL, - `photo` blob DEFAULT NULL, + `photo` blob, `started` date DEFAULT NULL, `finished` date DEFAULT NULL, `userFk` int(11) unsigned NOT NULL, `departmentFk` int(11) DEFAULT NULL, - `companyFk` smallint(5) unsigned NOT NULL DEFAULT 442, + `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', `location` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `amount` decimal(15,2) DEFAULT NULL, PRIMARY KEY (`id`), @@ -37272,7 +33680,7 @@ CREATE TABLE `project` ( CONSTRAINT `project_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `project_FK_1` FOREIGN KEY (`departmentFk`) REFERENCES `department` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `project_FK_2` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla master de proyectos'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla master de proyectos'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37284,7 +33692,7 @@ DROP TABLE IF EXISTS `projectNotes`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `projectNotes` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `txt` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `userFk` int(10) unsigned DEFAULT NULL, `projectFk` int(11) NOT NULL, @@ -37293,7 +33701,7 @@ CREATE TABLE `projectNotes` ( KEY `projectNotes_FK_1` (`userFk`), CONSTRAINT `projectNotes_FK` FOREIGN KEY (`projectFk`) REFERENCES `project` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `projectNotes_FK_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historico de notas para project'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Historico de notas para project'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -37345,7 +33753,7 @@ CREATE TABLE `property` ( `value` int(11) DEFAULT NULL, `propertyGroupFk` int(11) NOT NULL, `companyFk` smallint(5) unsigned NOT NULL, - `photo` blob DEFAULT NULL, + `photo` blob, `allocation` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL, `m2` decimal(10,2) DEFAULT NULL, `tome` int(11) DEFAULT NULL, @@ -37358,7 +33766,7 @@ CREATE TABLE `property` ( CONSTRAINT `property_FK` FOREIGN KEY (`propertyGroupFk`) REFERENCES `propertyGroup` (`id`) ON UPDATE CASCADE, CONSTRAINT `property_FK_1` FOREIGN KEY (`townFk`) REFERENCES `town` (`id`) ON UPDATE CASCADE, CONSTRAINT `property_company` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37375,9 +33783,9 @@ CREATE TABLE `propertyDms` ( PRIMARY KEY (`id`), KEY `propertyDms_FK` (`dmsFk`), KEY `propertyDms_FK_1` (`propertyFk`), - CONSTRAINT `propertyDms_FK` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON UPDATE CASCADE, + CONSTRAINT `propertyDms_FK` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `propertyDms_FK_1` FOREIGN KEY (`propertyFk`) REFERENCES `property` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37391,7 +33799,7 @@ CREATE TABLE `propertyGroup` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37412,7 +33820,7 @@ CREATE TABLE `propertyNotes` ( KEY `propertyNotes_FK` (`propertyFk`), CONSTRAINT `propertyNotes_FK` FOREIGN KEY (`propertyFk`) REFERENCES `property` (`id`), CONSTRAINT `propertyNotes_FK_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37501,19 +33909,19 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_afterUpdate` - AFTER UPDATE ON `province` - FOR EACH ROW -BEGIN - IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN - CALL zoneGeo_setParent(NEW.geoFk, - (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk)); - END IF; - - IF !(OLD.`name` <=> NEW.`name`) THEN - UPDATE zoneGeo SET `name` = NEW.`name` - WHERE id = NEW.geoFk; - END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`province_afterUpdate` + AFTER UPDATE ON `province` + FOR EACH ROW +BEGIN + IF !(OLD.autonomyFk <=> NEW.autonomyFk) THEN + CALL zoneGeo_setParent(NEW.geoFk, + (SELECT geoFk FROM autonomy WHERE id = NEW.autonomyFk)); + 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 */ ; @@ -37550,7 +33958,7 @@ DROP TABLE IF EXISTS `punchState`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `punchState` ( `workerFk` int(11) NOT NULL, - `state` tinyint(4) DEFAULT 1, + `state` tinyint(4) DEFAULT '1', `created` datetime DEFAULT NULL, PRIMARY KEY (`workerFk`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Table for storing punches that have cars with errors'; @@ -37564,8 +33972,9 @@ DROP TABLE IF EXISTS `queuePriority`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `queuePriority` ( - `id` tinyint(3) unsigned NOT NULL DEFAULT 0, + `id` tinyint(3) unsigned NOT NULL DEFAULT '0', `priority` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, + `code` varchar(6) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -37583,38 +33992,6 @@ CREATE TABLE `rankBonus` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Temporary table structure for view `rankingNewBornByQuarter__` --- - -DROP TABLE IF EXISTS `rankingNewBornByQuarter__`; -/*!50001 DROP VIEW IF EXISTS `rankingNewBornByQuarter__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `rankingNewBornByQuarter__` ( - `total` tinyint NOT NULL, - `name` tinyint NOT NULL, - `time_sec` tinyint NOT NULL, - `userFk` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - --- --- Temporary table structure for view `rankingSellingByQuarter__` --- - -DROP TABLE IF EXISTS `rankingSellingByQuarter__`; -/*!50001 DROP VIEW IF EXISTS `rankingSellingByQuarter__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `rankingSellingByQuarter__` ( - `importe` tinyint NOT NULL, - `name` tinyint NOT NULL, - `userFk` tinyint NOT NULL, - `time_sec` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - -- -- Table structure for table `rate` -- @@ -37663,15 +34040,15 @@ DROP TABLE IF EXISTS `receipt`; CREATE TABLE `receipt` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `invoiceFk` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'nombre incorrecto, renombrar a description', - `amountPaid` decimal(10,2) NOT NULL DEFAULT 0.00, - `amountUnpaid__` decimal(10,2) NOT NULL DEFAULT 0.00, + `amountPaid` decimal(10,2) NOT NULL DEFAULT '0.00', + `amountUnpaid__` decimal(10,2) NOT NULL DEFAULT '0.00', `payed` datetime DEFAULT NULL, `workerFk` int(10) unsigned DEFAULT NULL, - `bankFk` int(11) DEFAULT 0, - `clientFk` int(11) DEFAULT 0, - `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), - `companyFk` smallint(5) unsigned NOT NULL DEFAULT 442, - `isConciliate` tinyint(1) unsigned zerofill NOT NULL DEFAULT 0, + `bankFk` int(11) DEFAULT '0', + `clientFk` int(11) DEFAULT '0', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', + `isConciliate` tinyint(1) unsigned zerofill NOT NULL DEFAULT '0', PRIMARY KEY (`Id`), KEY `Id_Banco` (`bankFk`), KEY `Id_Trabajador` (`workerFk`), @@ -37694,20 +34071,20 @@ CREATE TABLE `receipt` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_beforeInsert` - BEFORE INSERT ON `receipt` - FOR EACH ROW -BEGIN - DECLARE vIsAutoConciliated BOOLEAN; - - IF NEW.isConciliate = FALSE THEN - SELECT isAutoConciliated INTO vIsAutoConciliated - FROM accounting a - JOIN accountingType at2 ON at2.id = a.accountingTypeFk - WHERE a.id = NEW.bankFk; - - SET NEW.isConciliate = vIsAutoConciliated; - END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_beforeInsert` + BEFORE INSERT ON `receipt` + FOR EACH ROW +BEGIN + DECLARE vIsAutoConciliated BOOLEAN; + + IF NEW.isConciliate = FALSE THEN + SELECT isAutoConciliated INTO vIsAutoConciliated + FROM accounting a + JOIN accountingType at2 ON at2.id = a.accountingTypeFk + WHERE a.id = NEW.bankFk; + + SET NEW.isConciliate = vIsAutoConciliated; + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -37763,18 +34140,18 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_afterUpdate` - AFTER UPDATE ON `receipt` - FOR EACH ROW -BEGIN - IF NEW.isConciliate = FALSE AND NEW.payed > OLD.payed THEN - CALL mail_insert( - 'finanzas@verdnatura.es', - NULL, - CONCAT('Cambios de recibos del cliente: ', NEW.clientFk), - CONCAT('Se ha cambiado el recibo: ', NEW.Id, ' de ', OLD.payed, ' a ', NEW.payed) - ); - END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`receipt_afterUpdate` + AFTER UPDATE ON `receipt` + FOR EACH ROW +BEGIN + IF NEW.isConciliate = FALSE AND NEW.payed > OLD.payed THEN + CALL mail_insert( + 'finanzas@verdnatura.es', + NULL, + CONCAT('Cambios de recibos del cliente: ', NEW.clientFk), + CONCAT('Se ha cambiado el recibo: ', NEW.Id, ' de ', OLD.payed, ' a ', NEW.payed) + ); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -37815,13 +34192,15 @@ CREATE TABLE `recipe` ( `originFk` tinyint(2) unsigned DEFAULT NULL, `typeFk` smallint(5) unsigned DEFAULT NULL, `longName` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `quantity` int(11) NOT NULL DEFAULT 1, + `quantity` int(11) NOT NULL DEFAULT '1', `element` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `inkFk` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `recipe_ix_1` (`element`), - KEY `recipe_ix_2` (`itemFk`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + KEY `recipe_ix_2` (`itemFk`), + KEY `recipe_FK` (`inkFk`), + CONSTRAINT `recipe_FK` FOREIGN KEY (`inkFk`) REFERENCES `ink` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37839,8 +34218,10 @@ CREATE TABLE `recipe_log` ( PRIMARY KEY (`id`), KEY `recipe_log_ix1` (`recipe_ItemFk`), KEY `recipe_log_ix2` (`element`), - KEY `recipe_log_ix3` (`selected_ItemFk`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena las decisiones tomadas al generar recetas'; + KEY `recipe_log_ix3` (`selected_ItemFk`), + CONSTRAINT `recipe_log_FK` FOREIGN KEY (`recipe_ItemFk`) REFERENCES `item` (`id`) ON UPDATE CASCADE, + CONSTRAINT `recipe_log_FK_1` FOREIGN KEY (`selected_ItemFk`) REFERENCES `item` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena las decisiones tomadas al generar recetas'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -37852,11 +34233,11 @@ DROP TABLE IF EXISTS `recovery`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `recovery` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `clientFk` int(11) NOT NULL DEFAULT 0, + `clientFk` int(11) NOT NULL DEFAULT '0', `started` date NOT NULL COMMENT 'Fecha a partir de la que comienza el recobro', `finished` date DEFAULT NULL COMMENT 'Fecha en la que acaba', `amount` double NOT NULL, - `period` tinyint(3) unsigned NOT NULL DEFAULT 7 COMMENT 'numero de dias que indica cada cuanto hare el recobro', + `period` tinyint(3) unsigned NOT NULL DEFAULT '7' COMMENT 'numero de dias que indica cada cuanto hare el recobro', PRIMARY KEY (`id`), KEY `cliente_idx` (`clientFk`), CONSTRAINT `cliente333` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE, @@ -37905,11 +34286,25 @@ DROP TABLE IF EXISTS `referenceRateConfig`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `referenceRateConfig` ( - `simulatedValue` float unsigned NOT NULL DEFAULT 1.2309, + `simulatedValue` float unsigned NOT NULL DEFAULT '1.2309', PRIMARY KEY (`simulatedValue`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `report` +-- + +DROP TABLE IF EXISTS `report`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `report` ( + `id` tinyint(3) unsigned NOT NULL, + `name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Temporary table structure for view `role` -- @@ -37940,7 +34335,7 @@ CREATE TABLE `route` ( `vehicleFk` int(10) unsigned DEFAULT NULL, `agencyModeFk` int(11) DEFAULT NULL, `time` datetime DEFAULT NULL, - `isOk` tinyint(1) unsigned NOT NULL DEFAULT 0, + `isOk` tinyint(1) unsigned NOT NULL DEFAULT '0', `kmStart` mediumint(9) NOT NULL, `kmEnd` mediumint(9) NOT NULL, `started` datetime NOT NULL, @@ -37948,9 +34343,9 @@ CREATE TABLE `route` ( `gestdocFk` int(11) DEFAULT NULL, `cost` double unsigned DEFAULT NULL, `m3` decimal(10,1) unsigned DEFAULT NULL, - `description` text COLLATE utf8_unicode_ci DEFAULT NULL, + `description` text COLLATE utf8_unicode_ci, `zoneFk` int(11) DEFAULT NULL, - `priority` int(11) NOT NULL DEFAULT 0, + `priority` int(11) NOT NULL DEFAULT '0', `invoiceInFk` mediumint(8) unsigned DEFAULT NULL, `beachFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`), @@ -38064,7 +34459,7 @@ CREATE TABLE `routeAction` ( `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `price` decimal(10,2) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38085,7 +34480,7 @@ CREATE TABLE `routeComplement` ( KEY `fgn_routeActionFk_idx` (`routeActionFk`), CONSTRAINT `fgn_routeActionFk` FOREIGN KEY (`routeActionFk`) REFERENCES `routeAction` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fgn_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38117,7 +34512,7 @@ CREATE TABLE `routeConfig` ( `distributionM3Category2` decimal(5,2) DEFAULT NULL, `plusCategory1Concept` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `plusCategory2Concept` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `defaultCompanyFk` smallint(5) unsigned DEFAULT 442, + `defaultCompanyFk` smallint(5) unsigned DEFAULT '442', PRIMARY KEY (`id`), KEY `routeConfig_FK` (`defaultCompanyFk`), CONSTRAINT `routeConfig_FK` FOREIGN KEY (`defaultCompanyFk`) REFERENCES `company` (`id`) @@ -38125,30 +34520,30 @@ CREATE TABLE `routeConfig` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `routeGate` +-- Table structure for table `routeGate__` -- -DROP TABLE IF EXISTS `routeGate`; +DROP TABLE IF EXISTS `routeGate__`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `routeGate` ( +CREATE TABLE `routeGate__` ( `deviceId` varchar(30) CHARACTER SET utf8 NOT NULL, `displayText` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `status` set('idle','doing','done','') CHARACTER SET utf8 DEFAULT 'idle', - `gateAreaFk` int(11) NOT NULL DEFAULT 1, + `gateAreaFk` int(11) NOT NULL DEFAULT '1', `routeFk` int(11) NOT NULL, `freeTickets` int(11) DEFAULT NULL, `expeditions` int(11) DEFAULT NULL, `scanned` int(11) DEFAULT NULL, - `flag` blob DEFAULT NULL, + `flag` blob, `pallets` int(11) DEFAULT NULL, `lastScanned` datetime DEFAULT NULL, - `ready` tinyint(4) NOT NULL DEFAULT 0, + `ready` tinyint(4) NOT NULL DEFAULT '0', `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`), UNIQUE KEY `routeFk_UNIQUE` (`routeFk`), KEY `routeGate_fk1_idx` (`gateAreaFk`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -38160,8 +34555,7 @@ CREATE TABLE `routeGate` ( /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`routeGateBeforeUpdate` - BEFORE UPDATE ON `routeGate` - FOR EACH ROW + BEFORE UPDATE ON `routeGate__` FOR EACH ROW BEGIN IF (NOT (NEW.expeditions <=> OLD.expeditions) OR NOT (NEW.scanned <=> OLD.scanned)) @@ -38213,11 +34607,11 @@ CREATE TABLE `routeLog` ( `originFk` int(10) 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 DEFAULT 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 DEFAULT NULL, - `newInstance` text 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`), @@ -38225,7 +34619,7 @@ CREATE TABLE `routeLog` ( KEY `userFk` (`userFk`), CONSTRAINT `routeLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `route` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `routeLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38256,7 +34650,7 @@ CREATE TABLE `routeUserPercentage` ( PRIMARY KEY (`id`), KEY `routeUserPercentageFk_idx` (`workerFk`), CONSTRAINT `routeUserPercentageFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38276,20 +34670,43 @@ CREATE TABLE `routesMonitor` ( `packages` int(11) DEFAULT NULL, `note` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `dated` date DEFAULT NULL, - `dockFk` int(11) DEFAULT NULL, + `dockFk` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `m3` decimal(10,1) DEFAULT NULL, - `priority` int(11) NOT NULL DEFAULT 0, + `priority` int(11) NOT NULL DEFAULT '0', `etd` time DEFAULT NULL, `expeditionTruckFk` int(11) DEFAULT NULL, `m3boxes` decimal(10,1) DEFAULT NULL, `bufferFk` int(11) DEFAULT NULL COMMENT 'Buffer del sorter por el que se quiere sacar esa ruta', - `isPickingAllowed` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Los tickets de esta ruta se pueden preparar', + `isPickingAllowed` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Los tickets de esta ruta se pueden preparar', PRIMARY KEY (`routeFk`), KEY `routesMonitor_FK` (`bufferFk`), - CONSTRAINT `routesMonitor_FK` FOREIGN KEY (`bufferFk`) REFERENCES `srt`.`buffer` (`id`) ON DELETE SET NULL ON UPDATE CASCADE + KEY `routesMonitor_FK_2` (`beachFk`), + KEY `routesMonitor_FK_1` (`dockFk`), + CONSTRAINT `routesMonitor_FK` FOREIGN KEY (`bufferFk`) REFERENCES `srt`.`buffer` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `routesMonitor_FK_1` FOREIGN KEY (`dockFk`) REFERENCES `dock` (`code`) ON UPDATE CASCADE, + CONSTRAINT `routesMonitor_FK_2` FOREIGN KEY (`beachFk`) REFERENCES `beach` (`code`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `routesReduced` +-- + +DROP TABLE IF EXISTS `routesReduced`; +/*!50001 DROP VIEW IF EXISTS `routesReduced`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `routesReduced` ( + `description` tinyint NOT NULL, + `name` tinyint NOT NULL, + `routeFk` tinyint NOT NULL, + `ETD` tinyint NOT NULL, + `bufferFk` tinyint NOT NULL, + `beachFk` tinyint NOT NULL, + `itempackingTypeFk` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `sale` -- @@ -38302,16 +34719,16 @@ CREATE TABLE `sale` ( `itemFk` int(11) NOT NULL, `ticketFk` int(11) NOT NULL, `concept` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `quantity` decimal(10,2) NOT NULL DEFAULT 0.00, + `quantity` decimal(10,2) NOT NULL DEFAULT '0.00', `originalQuantity` double(9,1) DEFAULT NULL, - `price` decimal(10,2) DEFAULT 0.00, - `discount` tinyint(2) unsigned NOT NULL DEFAULT 0, - `priceFixed` decimal(10,2) NOT NULL DEFAULT 0.00, - `reserved` tinyint(1) NOT NULL DEFAULT 0, - `isPicked` tinyint(1) NOT NULL DEFAULT 0, - `isPriceFixed` tinyint(1) NOT NULL DEFAULT 0, - `created` timestamp NOT NULL DEFAULT current_timestamp(), - `isAdded` tinyint(1) NOT NULL DEFAULT 0, + `price` decimal(10,2) DEFAULT '0.00', + `discount` tinyint(2) unsigned NOT NULL DEFAULT '0', + `priceFixed` decimal(10,2) NOT NULL DEFAULT '0.00', + `reserved` tinyint(1) NOT NULL DEFAULT '0', + `isPicked` tinyint(1) NOT NULL DEFAULT '0', + `isPriceFixed` tinyint(1) NOT NULL DEFAULT '0', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `isAdded` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `Id_Ticket` (`ticketFk`), KEY `itemFk_ticketFk` (`itemFk`,`ticketFk`), @@ -38356,7 +34773,7 @@ BEGIN JOIN vn.route r ON r.id = t.routeFk WHERE r.isOk = FALSE AND s.id = NEW.id - AND r.created >= util.VN_CURDATE() + AND r.created >= vn.VN_CURDATE() GROUP BY r.id; END IF; @@ -38483,7 +34900,7 @@ BEGIN JOIN vn.route r ON r.id = t.routeFk WHERE r.isOk = FALSE AND s.id = NEW.id - AND r.created >= util.VN_CURDATE() + AND r.created >= vn.VN_CURDATE() GROUP BY r.id; END IF; @@ -38529,7 +34946,7 @@ BEGIN JOIN vn.route r ON r.id = t.routeFk WHERE r.isOk = FALSE AND s.id = OLD.id - AND r.created >= util.VN_CURDATE() + AND r.created >= vn.VN_CURDATE() GROUP BY r.id; END IF; END */;; @@ -38605,7 +35022,7 @@ DROP TABLE IF EXISTS `saleBuy`; CREATE TABLE `saleBuy` ( `saleFk` int(11) NOT NULL, `buyFk` int(11) NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `workerFk` int(11) DEFAULT NULL, PRIMARY KEY (`saleFk`), KEY `saleBuy_FK` (`buyFk`), @@ -38670,7 +35087,7 @@ DROP TABLE IF EXISTS `saleChecked`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `saleChecked` ( `saleFk` int(11) NOT NULL, - `isChecked` int(11) NOT NULL DEFAULT 0, + `isChecked` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`saleFk`), CONSTRAINT `fk_Movimientos_checked_1` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -38704,8 +35121,8 @@ CREATE TABLE `saleComponent` ( `saleFk` int(11) NOT NULL, `componentFk` int(11) NOT NULL, `value` double NOT NULL, - `isGreuge` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'Indica si ya se ha tenido en cuenta para calcular el greuge', - `created` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `isGreuge` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Indica si ya se ha tenido en cuenta para calcular el greuge', + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`saleFk`,`componentFk`), KEY `fk_mov_comp_idx` (`componentFk`), CONSTRAINT `mc_fk1` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, @@ -38750,7 +35167,7 @@ CREATE TABLE `saleGoal` ( `goal` decimal(10,2) DEFAULT NULL, `goalType` smallint(6) DEFAULT NULL COMMENT 'grado', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38762,12 +35179,12 @@ DROP TABLE IF EXISTS `saleGroup`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `saleGroup` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `userFk` int(11) DEFAULT NULL, `parkingFk` int(11) DEFAULT NULL, `sectorFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='agrupa lineas de venta'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='agrupa lineas de venta'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38779,7 +35196,7 @@ DROP TABLE IF EXISTS `saleGroupDetail`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `saleGroupDetail` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `saleFk` int(11) NOT NULL, `saleGroupFk` int(11) NOT NULL, PRIMARY KEY (`id`), @@ -38787,7 +35204,7 @@ CREATE TABLE `saleGroupDetail` ( KEY `saleGroupDetail_FK_1` (`saleGroupFk`), CONSTRAINT `saleGroupDetail_FK` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `saleGroupDetail_FK_1` FOREIGN KEY (`saleGroupFk`) REFERENCES `saleGroup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='relaciona sale y saleGroup'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='relaciona sale y saleGroup'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38801,14 +35218,30 @@ CREATE TABLE `saleItemShelving__` ( `id` int(11) NOT NULL AUTO_INCREMENT, `saleFk` int(11) NOT NULL, `itemShelvingFk` int(10) unsigned NOT NULL, - `quantity` int(11) NOT NULL DEFAULT 0, - `isPicked` tinyint(4) NOT NULL DEFAULT 0, + `quantity` int(11) NOT NULL DEFAULT '0', + `isPicked` tinyint(4) NOT NULL DEFAULT '0', `ubication` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `saleItemShelving_fk1_idx` (`itemShelvingFk`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `saleLabel` +-- + +DROP TABLE IF EXISTS `saleLabel`; +/*!50001 DROP VIEW IF EXISTS `saleLabel`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `saleLabel` ( + `saleFk` tinyint NOT NULL, + `label` tinyint NOT NULL, + `stem` tinyint NOT NULL, + `created` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `saleMistake` -- @@ -38821,7 +35254,7 @@ CREATE TABLE `saleMistake` ( `saleFk` int(11) NOT NULL, `userFk` int(10) unsigned NOT NULL COMMENT 'Controlador', `typeFk` int(11) NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `saleMistake_fk1_idx` (`saleFk`), KEY `saleMistake_fk2_idx` (`userFk`), @@ -38829,7 +35262,7 @@ CREATE TABLE `saleMistake` ( CONSTRAINT `saleMistake_fk1` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `saleMistake_fk2` FOREIGN KEY (`userFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `saleMistake_fk3` FOREIGN KEY (`typeFk`) REFERENCES `mistakeType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38851,24 +35284,6 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; --- --- Temporary table structure for view `saleMistake_list__` --- - -DROP TABLE IF EXISTS `saleMistake_list__`; -/*!50001 DROP VIEW IF EXISTS `saleMistake_list__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `saleMistake_list__` ( - `saleFk` tinyint NOT NULL, - `sacador` tinyint NOT NULL, - `created` tinyint NOT NULL, - `revisador` tinyint NOT NULL, - `description` tinyint NOT NULL, - `controlled` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - -- -- Temporary table structure for view `saleMistake_list__2` -- @@ -38899,14 +35314,14 @@ CREATE TABLE `saleParking__` ( `id` int(11) NOT NULL AUTO_INCREMENT, `saleFk` int(11) NOT NULL, `parkingFk` int(11) NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `userFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `saleParking_FK` (`saleFk`), KEY `saleParking_FK_1` (`parkingFk`), CONSTRAINT `saleParking_FK` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `saleParking_FK_1` FOREIGN KEY (`parkingFk`) REFERENCES `parking` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='ubica las lineas de venta preparadas previamente'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='ubica las lineas de venta preparadas previamente'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -38948,11 +35363,11 @@ DROP TABLE IF EXISTS `saleTracking`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `saleTracking` ( `saleFk` int(11) NOT NULL, - `isChecked` tinyint(3) unsigned NOT NULL DEFAULT 0, - `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `isChecked` tinyint(3) unsigned NOT NULL DEFAULT '0', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `originalQuantity` double DEFAULT NULL, `workerFk` int(11) NOT NULL, - `actionFk` int(11) NOT NULL, + `actionFk` int(11) DEFAULT NULL, `id` int(11) NOT NULL AUTO_INCREMENT, `stateFk` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`id`), @@ -38962,7 +35377,8 @@ CREATE TABLE `saleTracking` ( KEY `saleTracking_idx5` (`created`), KEY `saleTracking_fk2_idx` (`actionFk`), CONSTRAINT `fgnStateFk` FOREIGN KEY (`stateFk`) REFERENCES `state` (`id`) ON UPDATE CASCADE, - CONSTRAINT `saleTracking_FK` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `saleTracking_FK` FOREIGN KEY (`saleFk`) REFERENCES `sale` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `saleTracking_FK_1` FOREIGN KEY (`actionFk`) REFERENCES `vncontrol`.`accion` (`accion_id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -39185,10 +35601,10 @@ CREATE TABLE `sample` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `code` varchar(25) CHARACTER SET utf8 NOT NULL, `description` varchar(105) COLLATE utf8_unicode_ci NOT NULL, - `isVisible` tinyint(1) unsigned NOT NULL DEFAULT 1, - `hasCompany` tinyint(1) unsigned NOT NULL DEFAULT 0, - `hasPreview` tinyint(1) unsigned NOT NULL DEFAULT 1, - `datepickerEnabled` tinyint(1) NOT NULL DEFAULT 0, + `isVisible` tinyint(1) unsigned NOT NULL DEFAULT '1', + `hasCompany` tinyint(1) unsigned NOT NULL DEFAULT '0', + `hasPreview` tinyint(1) unsigned NOT NULL DEFAULT '1', + `datepickerEnabled` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -39203,28 +35619,30 @@ DROP TABLE IF EXISTS `sector`; CREATE TABLE `sector` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, - `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT 1, - `isPreviousPreparedByPacking` tinyint(4) NOT NULL DEFAULT 1, + `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT '1', + `isPreviousPreparedByPacking` tinyint(4) NOT NULL DEFAULT '1', `code` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, - `pickingPlacement` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, - `path` int(11) DEFAULT NULL, - `isPreviousPrepared` tinyint(1) NOT NULL DEFAULT 0, - `isPackagingArea` tinyint(1) NOT NULL DEFAULT 0, - `labelReportFk` tinyint(3) unsigned DEFAULT NULL, + `pickingPlacement__` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, + `path__` int(11) DEFAULT NULL, + `isPreviousPrepared` tinyint(1) NOT NULL DEFAULT '0', + `isPackagingArea` tinyint(1) NOT NULL DEFAULT '0', + `reportFk` tinyint(3) unsigned DEFAULT NULL, `sonFk` int(11) DEFAULT NULL, - `isMain` tinyint(1) NOT NULL DEFAULT 0, + `isMain` tinyint(1) NOT NULL DEFAULT '0', `itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `workerFk` int(11) DEFAULT NULL, `labelReport__` tinyint(3) DEFAULT NULL, `printerFk` tinyint(3) unsigned DEFAULT NULL, - `isHideForPickers` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'sector a ocultar a los sacadores', - `isReserve` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Sectores de reserva, como Albenfruit o Fuentes', + `isHideForPickers` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'sector a ocultar a los sacadores', + `isReserve` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Sectores de reserva, como Albenfruit o Fuentes', PRIMARY KEY (`id`,`warehouseFk`), UNIQUE KEY `code_UNIQUE` (`code`), KEY `sector_fk1_idx` (`warehouseFk`), - KEY `sector_labelReport` (`labelReportFk`), + KEY `sector_report` (`reportFk`), + KEY `sector_FK` (`sonFk`,`warehouseFk`), + CONSTRAINT `sector_FK` FOREIGN KEY (`sonFk`, `warehouseFk`) REFERENCES `sector` (`id`, `warehouseFk`) ON UPDATE CASCADE, CONSTRAINT `sector_fk1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `sector_labelReport` FOREIGN KEY (`labelReportFk`) REFERENCES `labelReport` (`id`) + CONSTRAINT `sector_report` FOREIGN KEY (`reportFk`) REFERENCES `report` (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -39237,7 +35655,7 @@ DROP TABLE IF EXISTS `sectorCollection`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `sectorCollection` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `userFk` int(10) unsigned NOT NULL, `sectorFk` int(11) NOT NULL, PRIMARY KEY (`id`), @@ -39245,7 +35663,7 @@ CREATE TABLE `sectorCollection` ( KEY `sectorCollection_FK_2` (`sectorFk`), CONSTRAINT `sectorCollection_FK` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `sectorCollection_FK_1` FOREIGN KEY (`sectorFk`) REFERENCES `sector` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Las lineas de preparacion de pedidos por sectores se agrupan bajo el identificador de esta tabla'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Las lineas de preparacion de pedidos por sectores se agrupan bajo el identificador de esta tabla'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39257,7 +35675,7 @@ DROP TABLE IF EXISTS `sectorCollectionSaleGroup`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `sectorCollectionSaleGroup` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `sectorCollectionFk` int(11) NOT NULL, `saleGroupFk` int(11) NOT NULL, PRIMARY KEY (`id`), @@ -39265,7 +35683,7 @@ CREATE TABLE `sectorCollectionSaleGroup` ( KEY `sectorCollectionSaleGroup_FK_1` (`saleGroupFk`), CONSTRAINT `sectorCollectionSaleGroup_FK` FOREIGN KEY (`sectorCollectionFk`) REFERENCES `sectorCollection` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `sectorCollectionSaleGroup_FK_1` FOREIGN KEY (`saleGroupFk`) REFERENCES `saleGroup` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona las lineas de venta con la coleccion del sector'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona las lineas de venta con la coleccion del sector'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39288,7 +35706,7 @@ CREATE TABLE `sectorProductivity` ( `hourWorked` decimal(10,2) DEFAULT NULL, `dated` date DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39304,13 +35722,13 @@ CREATE TABLE `sharingCart` ( `started` date NOT NULL, `ended` date NOT NULL, `workerSubstitute` int(10) unsigned NOT NULL, - `created` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `workerFk_UNIQUE` (`workerFk`,`started`,`ended`,`workerSubstitute`), KEY `Suplent` (`workerSubstitute`), CONSTRAINT `Suplent_key` FOREIGN KEY (`workerSubstitute`) REFERENCES `worker` (`id`) ON UPDATE CASCADE, CONSTRAINT `Trabajador_key` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -39408,7 +35826,7 @@ CREATE TABLE `sharingCartDaily` ( `ownerFk` int(10) unsigned NOT NULL, `substituteFk` int(10) unsigned NOT NULL, `dated` date NOT NULL, - `created` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `sharingCartDailyWorker_idx` (`ownerFk`,`dated`), KEY `sharingCartDailySubstitute_idx` (`substituteFk`), @@ -39435,7 +35853,7 @@ CREATE TABLE `sharingClient` ( KEY `Client` (`clientFk`), CONSTRAINT `Clients_key` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE, CONSTRAINT `Trabajadores_key` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -39450,8 +35868,8 @@ DELIMITER ;; BEFORE INSERT ON `sharingClient` FOR EACH ROW BEGIN - SET NEW.ended = GREATEST(util.VN_CURDATE(),NEW.ended); - SET NEW.started = GREATEST(util.VN_CURDATE(),NEW.started); + SET NEW.ended = GREATEST(vn.VN_CURDATE(),NEW.ended); + SET NEW.started = GREATEST(vn.VN_CURDATE(),NEW.started); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -39471,8 +35889,8 @@ DELIMITER ;; BEFORE UPDATE ON `sharingClient` FOR EACH ROW BEGIN - SET NEW.ended = GREATEST(util.VN_CURDATE(),NEW.ended); - SET NEW.started = GREATEST(util.VN_CURDATE(),NEW.started); + SET NEW.ended = GREATEST(vn.VN_CURDATE(),NEW.ended); + SET NEW.started = GREATEST(vn.VN_CURDATE(),NEW.started); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -39490,12 +35908,12 @@ DROP TABLE IF EXISTS `shelving`; CREATE TABLE `shelving` ( `code` varchar(10) CHARACTER SET utf8 NOT NULL, `parkingFk` int(11) DEFAULT NULL, - `isPrinted` tinyint(4) NOT NULL DEFAULT 0, - `priority` int(11) NOT NULL DEFAULT 0, - `parked` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `isPrinted` tinyint(4) NOT NULL DEFAULT '0', + `priority` int(11) NOT NULL DEFAULT '0', + `parked` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `userFk` int(10) unsigned DEFAULT NULL, - `isSpam` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'señala las matrículas con producto que se puede llevar a la reserva', - `isRecyclable` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'las matrículas marcadas como reciclables se liberan cada noche desde vn.shelving_clean para poder volver a utilizarlas', + `isSpam` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'señala las matrículas con producto que se puede llevar a la reserva', + `isRecyclable` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'las matrículas marcadas como reciclables se liberan cada noche desde vn.shelving_clean para poder volver a utilizarlas', PRIMARY KEY (`code`), KEY `shelving_fk1_idx` (`parkingFk`), KEY `shelving_fk2_idx` (`userFk`), @@ -39542,17 +35960,6 @@ DELIMITER ;; BEFORE UPDATE ON `shelving` FOR EACH ROW BEGIN - - IF OLD.parkingFk != NEW.parkingFk THEN - - UPDATE item i - JOIN itemShelving ish ON ish.itemFk = i.id - JOIN shelving sh ON sh.code = ish.shelvingFk - JOIN parking p ON p.id = sh.parkingFk - SET i.sectorFk = p.sectorFk - WHERE sh.`code` = OLD.`code`; - - END IF; IF NEW.code = "" THEN @@ -39579,11 +35986,11 @@ CREATE TABLE `shelvingLog` ( `originFk` varchar(10) CHARACTER SET utf8 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 DEFAULT 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 DEFAULT NULL, - `newInstance` text 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`), @@ -39591,7 +35998,7 @@ CREATE TABLE `shelvingLog` ( KEY `originFk` (`originFk`), CONSTRAINT `shelvingLog_FK_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `shelving` (`code`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `shelvingLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39607,8 +36014,8 @@ CREATE TABLE `silexACL` ( `method` varchar(50) NOT NULL, `role` varchar(20) NOT NULL, PRIMARY KEY (`id`), - UNIQUE KEY `module_UNIQUE` (`module`,`method`,`role`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; + UNIQUE KEY `module_UNIQUE` (`module`,`method`) USING BTREE +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39623,9 +36030,9 @@ CREATE TABLE `sinister` ( `supplierFk` int(11) NOT NULL, `clientFk` int(11) NOT NULL, `amount` decimal(10,2) NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), - `insureRate` decimal(3,2) NOT NULL DEFAULT 0.75, - `isBooked` tinyint(4) NOT NULL DEFAULT 0, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `insureRate` decimal(3,2) NOT NULL DEFAULT '0.75', + `isBooked` tinyint(4) NOT NULL DEFAULT '0', `workerFk` int(10) unsigned NOT NULL, `companyFk` smallint(5) unsigned NOT NULL, PRIMARY KEY (`id`), @@ -39650,10 +36057,10 @@ DROP TABLE IF EXISTS `sinisterDetail`; CREATE TABLE `sinisterDetail` ( `id` int(11) NOT NULL, `sinisterFk` int(11) NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `amountIn` decimal(10,2) DEFAULT NULL, `amountOut` decimal(10,2) DEFAULT NULL, - `isConciliated` tinyint(1) NOT NULL DEFAULT 0, + `isConciliated` tinyint(1) NOT NULL DEFAULT '0', `workerFk` int(10) unsigned NOT NULL, `bankFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`), @@ -39692,16 +36099,18 @@ DROP TABLE IF EXISTS `sms`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `sms` ( `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, - `senderFk` int(11) NOT NULL, - `destinationFk` int(11) DEFAULT NULL, + `senderFk` int(10) unsigned NOT NULL, + `destinationFk__` int(11) DEFAULT NULL, `sender` varchar(15) CHARACTER SET utf8 NOT NULL DEFAULT '693474205', `destination` varchar(15) CHARACTER SET utf8 NOT NULL, `message` varchar(160) COLLATE utf8_unicode_ci NOT NULL, - `statusCode` smallint(9) DEFAULT 0, + `statusCode` smallint(9) DEFAULT '0', `status` varchar(255) COLLATE utf8_unicode_ci DEFAULT 'OK', - `created` timestamp NOT NULL DEFAULT current_timestamp(), - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + KEY `sms_FK` (`senderFk`), + CONSTRAINT `sms_FK` FOREIGN KEY (`senderFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39824,25 +36233,42 @@ DROP TABLE IF EXISTS `sorter`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `sorter` ( - `id` int(11) NOT NULL DEFAULT 0, + `id` int(11) NOT NULL DEFAULT '0', `created` datetime NOT NULL, `routeFk` int(10) unsigned NOT NULL, `ticketFk` int(10) NOT NULL, - `isBox` int(11) DEFAULT 1, + `isBox` int(11) DEFAULT '1', `itemFk` int(11) DEFAULT NULL, - `width` decimal(10,2) DEFAULT 0.00, - `depth` decimal(10,2) DEFAULT 0.00, - `height` decimal(10,2) DEFAULT 0.00, - `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT 1, - `weight` decimal(5,2) NOT NULL DEFAULT 0.00, - `buildingOrder` int(5) NOT NULL DEFAULT 0, + `width` decimal(10,2) DEFAULT '0.00', + `depth` decimal(10,2) DEFAULT '0.00', + `height` decimal(10,2) DEFAULT '0.00', + `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT '1', + `weight` decimal(5,2) NOT NULL DEFAULT '0.00', + `buildingOrder` int(5) NOT NULL DEFAULT '0', `ETD` time NOT NULL DEFAULT '23:59:00', `palletOrder` int(5) DEFAULT NULL, - `lungGrow` int(11) DEFAULT 0, + `lungGrow` int(11) DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `specialLabels` +-- + +DROP TABLE IF EXISTS `specialLabels`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `specialLabels` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL, + `reportName` varchar(100) COLLATE utf8_unicode_ci NOT NULL, + `isVisible` tinyint(1) NOT NULL DEFAULT '0', + `image` blob, + PRIMARY KEY (`id`) +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `specialPrice` -- @@ -39852,18 +36278,16 @@ DROP TABLE IF EXISTS `specialPrice`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `specialPrice` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `clientFk` int(11) NOT NULL DEFAULT 0, - `itemFk` int(11) NOT NULL DEFAULT 0, - `value` double NOT NULL DEFAULT 0, + `clientFk` int(11) NOT NULL DEFAULT '0', + `itemFk` int(11) NOT NULL DEFAULT '0', + `value` double NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `Id_Cliente_2` (`clientFk`,`itemFk`), KEY `Id_Article` (`itemFk`), KEY `Id_Cliente` (`clientFk`), CONSTRAINT `sp_article_id` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON UPDATE CASCADE, - CONSTRAINT `sp_customer_id` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE, - CONSTRAINT `{01A99AF1-3D3F-4B15-AC0C-C7A834F319A3}` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `{EE4ADEF6-0AC6-401F-B7C4-D797972FC065}` FOREIGN KEY (`itemFk`) REFERENCES `item` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + CONSTRAINT `sp_customer_id` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39933,7 +36357,7 @@ CREATE TABLE `specieGeoInvasive` ( `genusFk` int(11) NOT NULL, `specieFk` int(11) NOT NULL, `zoneGeofk` int(11) NOT NULL, - `isForbidden` tinyint(1) NOT NULL DEFAULT 1, + `isForbidden` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), KEY `specieGeoInvasive_FK` (`genusFk`), KEY `specieGeoInvasive_FK_1` (`specieFk`), @@ -39941,7 +36365,29 @@ CREATE TABLE `specieGeoInvasive` ( 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=InnoDB DEFAULT 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'; +) 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 `splitFilter` +-- + +DROP TABLE IF EXISTS `splitFilter`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `splitFilter` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `autonomyFk` int(11) DEFAULT NULL, + `clientFk` int(11) DEFAULT NULL, + `nickname` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `splitFilter_UN` (`autonomyFk`), + UNIQUE KEY `splitFilter_UN1` (`clientFk`), + KEY `splitFilter_FK` (`autonomyFk`), + KEY `splitFilter_FK_1` (`clientFk`), + CONSTRAINT `splitFilter_FK` FOREIGN KEY (`autonomyFk`) REFERENCES `autonomy` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `splitFilter_FK_1` FOREIGN KEY (`clientFk`) REFERENCES `client` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='define los clientes que tienen split y el nombre a mostrar en la etiqueta'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39961,7 +36407,7 @@ CREATE TABLE `starredModule` ( KEY `starred_moduleFk` (`moduleFk`), CONSTRAINT `starred_moduleFk` FOREIGN KEY (`moduleFk`) REFERENCES `salix`.`module` (`code`) ON UPDATE CASCADE, CONSTRAINT `starred_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -39973,12 +36419,12 @@ DROP TABLE IF EXISTS `state`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `state` ( `id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT, - `name` varchar(15) COLLATE utf8_unicode_ci NOT NULL, + `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `order` tinyint(3) unsigned DEFAULT NULL, - `alertLevel` int(11) NOT NULL DEFAULT 0, + `alertLevel` int(11) NOT NULL DEFAULT '0', `code` varchar(45) CHARACTER SET utf8 NOT NULL, `sectorProdPriority` tinyint(3) DEFAULT NULL, - `nextStateFk` tinyint(4) NOT NULL COMMENT 'Estado al que tiene que cambiar el ticket despues de preparacion previa', + `nextStateFk` tinyint(3) unsigned NOT NULL COMMENT 'Estado al que tiene que cambiar el ticket despues de preparacion previa', `isPreviousPreparable` tinyint(1) NOT NULL DEFAULT '0', `isPicked` tinyint(1) NOT NULL DEFAULT '0', `isPreparable` tinyint(1) NOT NULL DEFAULT '0', @@ -39992,6 +36438,8 @@ CREATE TABLE `state` ( UNIQUE KEY `code_UNIQUE` (`code`), KEY `state_id3` (`semaphore`), KEY `alertLevel` (`alertLevel`), + KEY `state_FK` (`nextStateFk`), + CONSTRAINT `state_FK` FOREIGN KEY (`nextStateFk`) REFERENCES `state` (`id`) ON UPDATE CASCADE, CONSTRAINT `state_ibfk_1` FOREIGN KEY (`alertLevel`) REFERENCES `alertLevel` (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -40008,14 +36456,14 @@ CREATE TABLE `stockBuyed` ( `user` int(10) unsigned DEFAULT NULL, `buyed` decimal(10,2) DEFAULT NULL, `date` date DEFAULT NULL, - `creationDate` timestamp NULL DEFAULT current_timestamp(), + `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `reserved` decimal(10,2) DEFAULT NULL, `requested` decimal(10,2) DEFAULT NULL, `description` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `stockBuyed_user_idx` (`user`), CONSTRAINT `stockBuyedUserFk` FOREIGN KEY (`user`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -40028,7 +36476,7 @@ DROP TABLE IF EXISTS `stowaway`; CREATE TABLE `stowaway` ( `id` int(11) NOT NULL COMMENT 'ticket pequeño', `shipFk` int(11) NOT NULL COMMENT 'ticket grande', - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tickets polizones y sus naves de embarque'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -40049,30 +36497,30 @@ CREATE TABLE `supplier` ( `provinceFk` smallint(5) unsigned DEFAULT NULL, `countryFk` mediumint(8) unsigned DEFAULT NULL, `nif` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `isOfficial` tinyint(1) NOT NULL DEFAULT 1, - `isFarmer` tinyint(1) NOT NULL DEFAULT 0, + `isOfficial` tinyint(1) NOT NULL DEFAULT '1', + `isFarmer` tinyint(1) NOT NULL DEFAULT '0', `retAccount` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar(16) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `Fax__` varchar(16) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `commission` float NOT NULL DEFAULT 0, + `commission` float NOT NULL DEFAULT '0', `nickname` varchar(45) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, `payMethodFk` tinyint(3) unsigned NOT NULL, `payDay` tinyint(4) unsigned DEFAULT NULL, - `payDemFk` tinyint(3) unsigned NOT NULL DEFAULT 7, - `created` timestamp NOT NULL DEFAULT current_timestamp(), - `isSerious` tinyint(1) unsigned NOT NULL DEFAULT 1, - `note` text CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, + `payDemFk` tinyint(3) unsigned NOT NULL DEFAULT '7', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `isSerious` tinyint(1) unsigned NOT NULL DEFAULT '1', + `note` text CHARACTER SET utf8 COLLATE utf8_unicode_ci, `postcodeFk` int(11) unsigned DEFAULT NULL, - `postCode` char(5) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, - `isActive` tinyint(4) DEFAULT 1, + `postCode` char(8) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, + `isActive` tinyint(4) DEFAULT '1', `taxTypeSageFk` smallint(6) DEFAULT NULL COMMENT 'Tipo de IVA SAGE', `withholdingSageFk` smallint(6) DEFAULT NULL COMMENT 'Tipos de retención SAGE', `transactionTypeSageFk` tinyint(4) DEFAULT NULL COMMENT 'Ti po de transacción SAGE', - `isTrucker` tinyint(1) NOT NULL DEFAULT 0, + `isTrucker` tinyint(1) NOT NULL DEFAULT '0', `workerFk` int(10) unsigned DEFAULT NULL COMMENT 'Responsible for approving invoices', `supplierActivityFk` varchar(45) NOT NULL DEFAULT 'flowersPlants', `healthRegister` varchar(45) DEFAULT NULL, - `isPayMethodChecked` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'Se ha validado la forma de pago', + `isPayMethodChecked` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Se ha validado la forma de pago', PRIMARY KEY (`id`), UNIQUE KEY `cuenta` (`account`), UNIQUE KEY `NIF` (`nif`), @@ -40143,20 +36591,22 @@ DROP TABLE IF EXISTS `supplierAccount`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `supplierAccount` ( `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, - `supplierFk` int(11) NOT NULL, + `supplierFk` int(11) DEFAULT NULL, `iban` varchar(30) CHARACTER SET utf8 DEFAULT NULL, `office` varchar(4) CHARACTER SET utf8 DEFAULT NULL, `DC` varchar(2) CHARACTER SET utf8 DEFAULT NULL, `number` varchar(10) CHARACTER SET utf8 DEFAULT NULL, `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'obsoleta(comprobar)', `bicSufix` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT '', - `bankEntityFk` int(10) DEFAULT NULL, + `bankEntityFk` int(10) unsigned DEFAULT NULL, `bankFk` int(11) DEFAULT NULL COMMENT 'obsoleta(comprobar)', `beneficiary` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `fk_proveedores_proveedores_account_idx` (`supplierFk`), KEY `fk_Proveedores_account_entity1_idx` (`bankEntityFk`), - KEY `fk_banco_prov_account_idx` (`bankFk`) + KEY `fk_banco_prov_account_idx` (`bankFk`), + CONSTRAINT `supplierAccount_FK` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE, + CONSTRAINT `supplierAccount_FK_1` FOREIGN KEY (`bankEntityFk`) REFERENCES `bankEntity` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -40168,23 +36618,23 @@ CREATE TABLE `supplierAccount` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER supplierAccount_afterUpdate - AFTER UPDATE ON supplierAccount - FOR EACH ROW -BEGIN - DECLARE vPayMethodHasVerified BOOL; - - SELECT pm.hasVerified INTO vPayMethodHasVerified - FROM vn.supplier s - JOIN vn.payMethod pm ON pm.id = s.payMethodFk - WHERE s.id = OLD.supplierFk; - - IF OLD.iban <> NEW.iban OR OLD.bankEntityFk <> NEW.bankEntityFk AND vPayMethodHasVerified THEN - UPDATE vn.supplier - SET isPayMethodChecked = FALSE - WHERE id = OLD.supplierFk; - END IF; - +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER supplierAccount_afterUpdate + AFTER UPDATE ON supplierAccount + FOR EACH ROW +BEGIN + DECLARE vPayMethodHasVerified BOOL; + + SELECT pm.hasVerified INTO vPayMethodHasVerified + FROM vn.supplier s + JOIN vn.payMethod pm ON pm.id = s.payMethodFk + WHERE s.id = OLD.supplierFk; + + IF OLD.iban <> NEW.iban OR OLD.bankEntityFk <> NEW.bankEntityFk AND vPayMethodHasVerified THEN + UPDATE vn.supplier + SET isPayMethodChecked = FALSE + WHERE id = OLD.supplierFk; + END IF; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -40226,30 +36676,6 @@ CREATE TABLE `supplierAddress` ( PRIMARY KEY (`id`), KEY `supplierAddress_province_fk` (`provinceFk`), CONSTRAINT `supplierAddress_province_fk` FOREIGN KEY (`provinceFk`) REFERENCES `province` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `supplierAgencyTerm` --- - -DROP TABLE IF EXISTS `supplierAgencyTerm`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `supplierAgencyTerm` ( - `agencyFk` smallint(5) unsigned NOT NULL, - `supplierFk` int(11) DEFAULT NULL, - `minimumPackages` int(11) NOT NULL DEFAULT 0 COMMENT 'numero minimo de bultos', - `kmPrice` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT 'precio extra por km', - `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,2) NOT NULL DEFAULT 0.00, - `m3Price` decimal(10,2) NOT NULL DEFAULT 0.00, - PRIMARY KEY (`agencyFk`), - KEY `agencyTerm_FK_1` (`supplierFk`), - CONSTRAINT `agencyTerm_FK` FOREIGN KEY (`agencyFk`) REFERENCES `agency` (`id`) ON UPDATE CASCADE, - CONSTRAINT `agencyTerm_FK_1` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -40290,7 +36716,7 @@ CREATE TABLE `supplierContact` ( `phone` varchar(16) COLLATE utf8_unicode_ci DEFAULT NULL, `mobile` varchar(16) COLLATE utf8_unicode_ci DEFAULT NULL, `email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `observation` text COLLATE utf8_unicode_ci DEFAULT NULL, + `observation` text COLLATE utf8_unicode_ci, `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `supplier_id` (`supplierFk`), @@ -40309,13 +36735,13 @@ CREATE TABLE `supplierExpense` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `dated` date NOT NULL, `supplierFk` int(11) NOT NULL, - `currencyFk` tinyint(3) unsigned NOT NULL DEFAULT 2, - `amount` decimal(10,2) NOT NULL DEFAULT 0.00, + `currencyFk` tinyint(3) unsigned NOT NULL DEFAULT '2', + `amount` decimal(10,2) NOT NULL DEFAULT '0.00', `description` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `companyFk` smallint(5) unsigned NOT NULL DEFAULT 442, + `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', `dmsFk` int(11) DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), - `isConciliated` tinyint(1) unsigned zerofill NOT NULL DEFAULT 0, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `isConciliated` tinyint(1) unsigned zerofill NOT NULL DEFAULT '0', `dueDated` date NOT NULL, PRIMARY KEY (`id`), KEY `empresa_id` (`companyFk`), @@ -40328,7 +36754,7 @@ CREATE TABLE `supplierExpense` ( CONSTRAINT `pago_ibfk_1` FOREIGN KEY (`companyFk`) REFERENCES `company` (`id`) ON UPDATE CASCADE, CONSTRAINT `pago_moneda` FOREIGN KEY (`currencyFk`) REFERENCES `currency` (`id`) ON UPDATE CASCADE, CONSTRAINT `proveedor_pago` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -40343,11 +36769,11 @@ CREATE TABLE `supplierLog` ( `originFk` int(11) NOT NULL, `userFk` int(10) unsigned NOT NULL, `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL, - `creationDate` timestamp NULL DEFAULT current_timestamp(), - `description` text CHARACTER SET utf8 DEFAULT 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 DEFAULT NULL, - `newInstance` text 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`), @@ -40355,7 +36781,7 @@ CREATE TABLE `supplierLog` ( KEY `supplierLog_ibfk_2` (`userFk`), CONSTRAINT `supplierLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `supplier` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `supplierLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -40424,8 +36850,8 @@ CREATE TABLE `tag` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code` varchar(45) CHARACTER SET utf8 DEFAULT NULL, `name` varchar(25) COLLATE utf8_unicode_ci NOT NULL, - `isFree` tinyint(1) NOT NULL DEFAULT 1, - `isQuantitatif` tinyint(4) NOT NULL DEFAULT 0, + `isFree` tinyint(1) NOT NULL DEFAULT '1', + `isQuantitatif` tinyint(4) NOT NULL DEFAULT '0', `sourceTable` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `unit` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `ediTypeFk` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, @@ -40563,16 +36989,16 @@ CREATE TABLE `taxCode` ( `dated` date NOT NULL, `code` varchar(10) CHARACTER SET utf8 NOT NULL, `taxTypeFk` tinyint(2) NOT NULL, - `rate` decimal(4,1) NOT NULL DEFAULT 0.0, - `equalizationTax` decimal(4,1) NOT NULL DEFAULT 0.0, + `rate` decimal(4,1) NOT NULL DEFAULT '0.0', + `equalizationTax` decimal(4,1) NOT NULL DEFAULT '0.0', `type` char(1) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Solo rellenar si en el asiento ira en el DEBE', - `link` tinyint(4) unsigned DEFAULT 0 COMMENT 'las que tienen el mismo valor se contabilizan emparejadas', - `isActive` tinyint(2) NOT NULL DEFAULT 1, - `updated` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `link` tinyint(4) unsigned DEFAULT '0' COMMENT 'las que tienen el mismo valor se contabilizan emparejadas', + `isActive` tinyint(2) NOT NULL DEFAULT '1', + `updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `transactionCode` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Código de Transacción de SAGE', `operationCode` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Código de operaciones de SAGE', `taxCode` int(4) DEFAULT NULL COMMENT 'Código de IVA SAGE', - `isIntracommunity` tinyint(2) DEFAULT 0, + `isIntracommunity` tinyint(2) DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `taxCode_dated_IDX` (`dated`,`taxTypeFk`,`type`,`link`) USING BTREE, KEY `iva_tipo_id` (`taxTypeFk`), @@ -40592,7 +37018,7 @@ DROP TABLE IF EXISTS `taxType`; CREATE TABLE `taxType` ( `id` tinyint(2) NOT NULL AUTO_INCREMENT, `nickname` varchar(6) COLLATE utf8_unicode_ci NOT NULL, - `isAccrued` tinyint(4) NOT NULL DEFAULT 0, + `isAccrued` tinyint(4) NOT NULL DEFAULT '0', `serial` char(1) COLLATE utf8_unicode_ci DEFAULT NULL, `TIPOOPE` varchar(1) COLLATE utf8_unicode_ci NOT NULL DEFAULT ' ' COMMENT 'respetar el nombre de la columna, se utiliza en contaplus', `description` varchar(100) COLLATE utf8_unicode_ci NOT NULL, @@ -40613,7 +37039,7 @@ DROP TABLE IF EXISTS `temperature`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `temperature` ( `code` varchar(10) CHARACTER SET utf8 NOT NULL, - `description` text COLLATE utf8_unicode_ci DEFAULT 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; @@ -40642,34 +37068,34 @@ DROP TABLE IF EXISTS `ticket`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `ticket` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `clientFk` int(11) NOT NULL DEFAULT 0, - `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT 1, + `clientFk` int(11) NOT NULL DEFAULT '0', + `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT '1', `shipped` datetime NOT NULL, `nickname` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - `notes` longtext COLLATE utf8_unicode_ci DEFAULT NULL, + `notes__` longtext COLLATE utf8_unicode_ci, `refFk` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `invoiceOutFk` int(10) unsigned DEFAULT NULL COMMENT 'eliminar', - `isBooked` tinyint(1) NOT NULL DEFAULT 0, - `addressFk` int(11) NOT NULL DEFAULT 0, + `invoiceOutFk__` int(10) unsigned DEFAULT NULL COMMENT 'eliminar', + `isBooked__` tinyint(1) NOT NULL DEFAULT '0', + `addressFk` int(11) NOT NULL DEFAULT '0', `workerFk` int(11) DEFAULT NULL, `observations` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'eliminar', - `isSigned` tinyint(1) NOT NULL DEFAULT 0, - `isLabeled` tinyint(1) NOT NULL DEFAULT 0, - `isPrinted` tinyint(1) NOT NULL DEFAULT 0, - `packages` smallint(10) unsigned DEFAULT 0, + `isSigned` tinyint(1) NOT NULL DEFAULT '0', + `isLabeled` tinyint(1) NOT NULL DEFAULT '0', + `isPrinted` tinyint(1) NOT NULL DEFAULT '0', + `packages` smallint(10) unsigned DEFAULT '0', `location` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, - `hour` int(11) DEFAULT 0, - `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), - `isBlocked` tinyint(1) NOT NULL DEFAULT 1, + `hour` int(11) DEFAULT '0', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `isBlocked` tinyint(1) NOT NULL DEFAULT '1', `solution` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, `routeFk` int(10) unsigned DEFAULT NULL, `priority` tinyint(3) unsigned DEFAULT NULL, - `hasPriority` tinyint(1) unsigned NOT NULL DEFAULT 1, - `companyFk` smallint(5) unsigned NOT NULL DEFAULT 442, + `hasPriority` tinyint(1) unsigned NOT NULL DEFAULT '1', + `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', `agencyModeFk` int(11) DEFAULT NULL, `landed` date DEFAULT NULL, - `isBoxed` tinyint(2) NOT NULL DEFAULT 0, - `isDeleted` tinyint(2) NOT NULL DEFAULT 0, + `isBoxed` tinyint(2) NOT NULL DEFAULT '0', + `isDeleted` tinyint(2) NOT NULL DEFAULT '0', `zoneFk` int(11) DEFAULT NULL, `collectionFk__` int(11) DEFAULT NULL, `zonePrice` decimal(10,2) DEFAULT NULL, @@ -40742,8 +37168,8 @@ BEGIN WHERE c.id = NEW.clientFk; INSERT INTO bs.clientNewBorn(clientFk, firstShipped, lastShipped) - VALUES(NEW.clientFk, IFNULL(vTransferorFirstShipped, util.VN_CURDATE()), util.VN_CURDATE()) - ON DUPLICATE KEY UPDATE lastShipped = util.VN_CURDATE(); + VALUES(NEW.clientFk, IFNULL(vTransferorFirstShipped, vn.VN_CURDATE()), vn.VN_CURDATE()) + ON DUPLICATE KEY UPDATE lastShipped = vn.VN_CURDATE(); END IF; @@ -40774,7 +37200,7 @@ BEGIN FROM vn.route r WHERE r.isOk = FALSE AND r.id IN (OLD.routeFk,NEW.routeFk) - AND r.created >= util.VN_CURDATE() + AND r.created >= vn.VN_CURDATE() GROUP BY r.id; call util.debugAdd(NEW.id,CONCAT(OLD.routeFk,' ',NEW.routeFk)); END IF; @@ -40798,7 +37224,7 @@ BEGIN JOIN vn.route r ON r.id = t.routeFk WHERE r.isOk = FALSE AND t.id = NEW.id - AND r.created >= util.VN_CURDATE() + AND r.created >= vn.VN_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'); @@ -40871,9 +37297,17 @@ BEGIN 'jgallego@verdnatura.es', 'jgallego@verdnatura.es', 'Modificado ticket al cliente 2067', - CONCAT(account.myUserGetName(), ' ha modificado el ticket ',NEW.id) + CONCAT(account.myUser_getName(), ' ha modificado el ticket ',NEW.id) ); END IF; + + IF NEW.routeFk <> OLD.routeFk THEN + + UPDATE expedition + SET hasNewRoute = TRUE + WHERE ticketFk = NEW.id; + + END IF; END */;; DELIMITER ; @@ -40899,7 +37333,7 @@ BEGIN FROM vn.route r WHERE r.isOk = FALSE AND r.id = OLD.routeFk - AND r.created >= util.VN_CURDATE() + AND r.created >= vn.VN_CURDATE() GROUP BY r.id; DELETE FROM sale WHERE ticketFk = OLD.id; @@ -40923,10 +37357,10 @@ CREATE TABLE `ticketCollection` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ticketFk` int(11) NOT NULL, `collectionFk` int(11) NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `level` int(11) DEFAULT NULL, - `wagon` int(11) NOT NULL DEFAULT 0, - `smartTagFk` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, + `wagon` int(11) NOT NULL DEFAULT '0', + `smartTagFk` varchar(12) CHARACTER SET utf8 DEFAULT NULL, `usedShelves` int(11) DEFAULT NULL COMMENT 'número de bandejas que ocupa un ticket en el carro', `itemCount` int(11) DEFAULT NULL COMMENT 'número de productos distintos en el pedido', `liters` int(11) DEFAULT NULL COMMENT 'volumen del pedido en litros', @@ -40936,6 +37370,7 @@ CREATE TABLE `ticketCollection` ( KEY `ticketCollection_fk2_idx` (`ticketFk`), KEY `ticketCollection_smartTagFk_IDX` (`smartTagFk`) USING BTREE, KEY `ticketCollection_created_IDX` (`created`) USING BTREE, + CONSTRAINT `ticketCollection_FK` FOREIGN KEY (`smartTagFk`) REFERENCES `smartTag` (`code`) ON UPDATE CASCADE, CONSTRAINT `ticketCollection_fk1` FOREIGN KEY (`collectionFk`) REFERENCES `collection` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketCollection_fk2` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -40949,31 +37384,31 @@ CREATE TABLE `ticketCollection` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER ticketCollection_afterDelete -AFTER DELETE -ON ticketCollection FOR EACH ROW -BEGIN - - DECLARE vSalesRemaining INT; - - SELECT count(*) INTO vSalesRemaining - FROM vn.ticketCollection tc - JOIN sale s ON s.ticketFk = tc.ticketFk - WHERE collectionFk = OLD.collectionFk - AND tc.id != OLD.id; - - IF NOT vSalesRemaining THEN - - DELETE FROM vn.collection WHERE id = OLD.collectionFk; - - ELSE - - UPDATE vn.collection - SET saleTotalCount = vSalesRemaining - WHERE id = OLD.collectionFk; - - END IF; - +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER ticketCollection_afterDelete +AFTER DELETE +ON ticketCollection FOR EACH ROW +BEGIN + + DECLARE vSalesRemaining INT; + + SELECT count(*) INTO vSalesRemaining + FROM vn.ticketCollection tc + JOIN sale s ON s.ticketFk = tc.ticketFk + WHERE collectionFk = OLD.collectionFk + AND tc.id != OLD.id; + + IF NOT vSalesRemaining THEN + + DELETE FROM vn.collection WHERE id = OLD.collectionFk; + + ELSE + + UPDATE vn.collection + SET saleTotalCount = vSalesRemaining + WHERE id = OLD.collectionFk; + + END IF; + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -40991,7 +37426,7 @@ DROP TABLE IF EXISTS `ticketConfig`; CREATE TABLE `ticketConfig` ( `id` int(11) NOT NULL AUTO_INCREMENT, `scopeDays` tinyint(3) DEFAULT NULL, - `pickingDelay` int(11) NOT NULL DEFAULT 10 COMMENT 'minutos de cortesia desde que se crea un ticket hasta que se puede preparar', + `pickingDelay` int(11) NOT NULL DEFAULT '10' COMMENT 'minutos de cortesia desde que se crea un ticket hasta que se puede preparar', PRIMARY KEY (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -41063,8 +37498,8 @@ DROP TABLE IF EXISTS `ticketDown`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `ticketDown` ( `ticketFk` int(11) NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), - `selected` int(11) NOT NULL DEFAULT 0, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `selected` int(11) NOT NULL DEFAULT '0', `collectionFk` int(11) NOT NULL, `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`), @@ -41073,7 +37508,7 @@ CREATE TABLE `ticketDown` ( KEY `ticketDown_FK` (`collectionFk`), CONSTRAINT `ticketDown_FK` FOREIGN KEY (`collectionFk`) REFERENCES `collection` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketDown_fk1` FOREIGN KEY (`selected`) REFERENCES `ticketDown_SelectionType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Cola de impresion para los tickets que se van a solicitar al altillo'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Cola de impresion para los tickets que se van a solicitar al altillo'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41091,28 +37526,6 @@ CREATE TABLE `ticketDown_SelectionType` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 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` -- @@ -41121,7 +37534,7 @@ DROP TABLE IF EXISTS `ticketLastState`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `ticketLastState` ( - `ticketFk` int(11) NOT NULL DEFAULT 0, + `ticketFk` int(11) NOT NULL DEFAULT '0', `ticketTrackingFk` int(11) NOT NULL, `name` varchar(15) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`ticketFk`), @@ -41159,6 +37572,21 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `ticketLocation` +-- + +DROP TABLE IF EXISTS `ticketLocation`; +/*!50001 DROP VIEW IF EXISTS `ticketLocation`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `ticketLocation` ( + `ticketFk` tinyint NOT NULL, + `longitude` tinyint NOT NULL, + `latitude` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Table structure for table `ticketLog` -- @@ -41171,11 +37599,11 @@ CREATE TABLE `ticketLog` ( `originFk` int(11) NOT NULL, `userFk` int(10) unsigned DEFAULT NULL, `action` set('insert','update','delete','select') COLLATE utf8_unicode_ci NOT NULL, - `creationDate` timestamp NULL DEFAULT current_timestamp(), - `description` text CHARACTER SET utf8 DEFAULT 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 DEFAULT NULL, - `newInstance` text 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`), @@ -41183,9 +37611,37 @@ CREATE TABLE `ticketLog` ( KEY `logTicketuserFk` (`userFk`), CONSTRAINT `ticketLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketLog_user` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Temporary table structure for view `ticketMRW` +-- + +DROP TABLE IF EXISTS `ticketMRW`; +/*!50001 DROP VIEW IF EXISTS `ticketMRW`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE TABLE `ticketMRW` ( + `id_Agencia` tinyint NOT NULL, + `empresa_id` tinyint NOT NULL, + `Consignatario` tinyint NOT NULL, + `DOMICILIO` tinyint NOT NULL, + `POBLACION` tinyint NOT NULL, + `CODPOSTAL` tinyint NOT NULL, + `telefono` tinyint NOT NULL, + `movil` tinyint NOT NULL, + `IF` tinyint NOT NULL, + `Id_Ticket` tinyint NOT NULL, + `warehouse_id` tinyint NOT NULL, + `Id_Consigna` tinyint NOT NULL, + `CodigoPais` tinyint NOT NULL, + `Fecha` tinyint NOT NULL, + `province_id` tinyint NOT NULL, + `landing` tinyint NOT NULL +) ENGINE=MyISAM */; +SET character_set_client = @saved_cs_client; + -- -- Temporary table structure for view `ticketNotInvoiced` -- @@ -41233,7 +37689,7 @@ DROP TABLE IF EXISTS `ticketPackage`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `ticketPackage` ( `ticket` int(11) NOT NULL, - `counter` int(10) unsigned NOT NULL DEFAULT 0, + `counter` int(10) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`ticket`), CONSTRAINT `ticketPackage_ticketFk` FOREIGN KEY (`ticket`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -41250,8 +37706,8 @@ CREATE TABLE `ticketPackaging` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ticketFk` int(11) NOT NULL, `packagingFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL, - `quantity` int(10) DEFAULT 0, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `quantity` int(10) DEFAULT '0', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `pvp` double DEFAULT NULL, `workerFk` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), @@ -41299,7 +37755,7 @@ CREATE TABLE `ticketPackagingStartingStock` ( `itemFk` int(11) NOT NULL, `sent` int(11) DEFAULT NULL, `returned` int(11) DEFAULT NULL, - `isForgetable` tinyint(1) NOT NULL DEFAULT 0, + `isForgetable` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`clientFk`,`packagingFk`), KEY `ticketPackagingStartingStock_fk2_idx` (`packagingFk`), KEY `ticketPackagingStartingStock_fk3_idx` (`itemFk`), @@ -41342,7 +37798,7 @@ CREATE TABLE `ticketParking` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ticketFk` int(11) NOT NULL, `parkingFk` int(11) NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `workerFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `ticketParking_idx1` (`ticketFk`,`parkingFk`), @@ -41350,7 +37806,7 @@ CREATE TABLE `ticketParking` ( KEY `ticketParking_fk1_idx` (`parkingFk`), CONSTRAINT `ticketParking_fk1` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketParking_fk2` FOREIGN KEY (`parkingFk`) REFERENCES `parking` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los distintos lugares donde puede estar aparcado cada uno de los prepedidos'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena los distintos lugares donde puede estar aparcado cada uno de los prepedidos'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -41431,29 +37887,17 @@ CREATE TABLE `ticketRefund` ( /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRefund_beforeInsert` BEFORE INSERT ON `ticketRefund` FOR EACH ROW BEGIN - DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE; - - IF NEW.refundTicketFk = NEW.originalTicketFk THEN - CALL util.throw('Original ticket and refund ticket has same id'); - END IF; - - SELECT COUNT(*) INTO vAlreadyExists - FROM ticketRefund - WHERE refundTicketFk = NEW.originalTicketFk; - - IF vAlreadyExists > 0 THEN - CALL util.throw('This ticket is already a refund'); - END IF; + CALL ticketRefund_beforeUpsert(NEW.refundTicketFk, NEW.originalTicketFk); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -41463,29 +37907,17 @@ 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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vn`.`ticketRefund_beforeUpdate` BEFORE UPDATE ON `ticketRefund` FOR EACH ROW BEGIN - DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE; - - IF NEW.refundTicketFk = NEW.originalTicketFk THEN - CALL util.throw('Original ticket and refund ticket has same id'); - END IF; - - SELECT COUNT(*) INTO vAlreadyExists - FROM ticketRefund - WHERE refundTicketFk = NEW.originalTicketFk; - - IF vAlreadyExists > 0 THEN - CALL util.throw('This ticket is already a refund'); - END IF; + CALL ticketRefund_beforeUpsert(NEW.refundTicketFk, NEW.originalTicketFk); END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -41512,13 +37944,13 @@ CREATE TABLE `ticketRequest` ( `price__` double DEFAULT NULL, `itemFk` double DEFAULT NULL, `clientFk` int(11) DEFAULT NULL, - `response` longtext COLLATE utf8_unicode_ci DEFAULT NULL, - `ok__` tinyint(1) NOT NULL DEFAULT 0, + `response` longtext COLLATE utf8_unicode_ci, + `ok__` tinyint(1) NOT NULL DEFAULT '0', `total` int(11) DEFAULT NULL, `buyed` datetime DEFAULT NULL, - `ko__` tinyint(1) NOT NULL DEFAULT 0, + `ko__` tinyint(1) NOT NULL DEFAULT '0', `saleFk` int(11) DEFAULT NULL, - `created` timestamp NULL DEFAULT current_timestamp(), + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `isOk` tinyint(1) DEFAULT NULL, `requesterFk` int(10) unsigned DEFAULT NULL, `attenderFk` int(10) unsigned DEFAULT NULL, @@ -41610,9 +38042,9 @@ DROP TABLE IF EXISTS `ticketService`; CREATE TABLE `ticketService` ( `id` int(11) NOT NULL AUTO_INCREMENT, `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `quantity` int(11) NOT NULL DEFAULT 0, - `price` decimal(10,2) NOT NULL DEFAULT 0.00, - `taxClassFk` tinyint(3) unsigned NOT NULL DEFAULT 2, + `quantity` int(11) NOT NULL DEFAULT '0', + `price` decimal(10,2) NOT NULL DEFAULT '0.00', + `taxClassFk` tinyint(3) unsigned NOT NULL DEFAULT '2', `ticketFk` int(11) NOT NULL, `ticketServiceTypeFk` int(11) NOT NULL, PRIMARY KEY (`id`), @@ -41781,7 +38213,7 @@ DROP TABLE IF EXISTS `ticketTrolley`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `ticketTrolley` ( `ticket` int(11) NOT NULL, - `labelCount` int(11) NOT NULL DEFAULT 0, + `labelCount` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ticket`), CONSTRAINT `fk_ticketTrolley_vs_ticket` FOREIGN KEY (`ticket`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -41830,20 +38262,20 @@ DROP TABLE IF EXISTS `till`; CREATE TABLE `till` ( `id` int(11) NOT NULL AUTO_INCREMENT, `dated` date NOT NULL, - `isAccountable` tinyint(1) NOT NULL DEFAULT 0, + `isAccountable` tinyint(1) NOT NULL DEFAULT '0', `serie` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL, `number` int(11) DEFAULT NULL, `concept` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `in` decimal(10,2) DEFAULT NULL, `out` decimal(10,2) DEFAULT NULL, - `bankFk` int(11) DEFAULT 1, + `bankFk` int(11) DEFAULT '1', `workerFk` int(10) unsigned DEFAULT NULL, - `companyFk` smallint(5) unsigned DEFAULT 442 COMMENT 'kakear', - `isLinked` tinyint(4) DEFAULT 0, - `created` timestamp NOT NULL DEFAULT current_timestamp(), - `isOk` tinyint(4) NOT NULL DEFAULT 0, - `warehouseFk` smallint(5) unsigned NOT NULL DEFAULT 1 COMMENT 'to kak\\n', - `isConciliate` tinyint(4) NOT NULL DEFAULT 0, + `companyFk` smallint(5) unsigned DEFAULT '442' COMMENT 'kakear', + `isLinked` tinyint(4) DEFAULT '0', + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `isOk` tinyint(4) NOT NULL DEFAULT '0', + `warehouseFk` smallint(5) unsigned NOT NULL DEFAULT '1' COMMENT 'to kak\\n', + `isConciliate` tinyint(4) NOT NULL DEFAULT '0', `supplierAccountFk` mediumint(8) unsigned NOT NULL, `calculatedCode` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `InForeignValue` decimal(10,2) DEFAULT NULL, @@ -41858,7 +38290,7 @@ CREATE TABLE `till` ( KEY `fk_Cajas_Proveedores_account1_idx` (`supplierAccountFk`), CONSTRAINT `till_ibfk_2` FOREIGN KEY (`bankFk`) REFERENCES `accounting` (`id`) ON UPDATE CASCADE, CONSTRAINT `till_ibfk_3` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) 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 */ ; @@ -41893,7 +38325,7 @@ DROP TABLE IF EXISTS `tillConfig`; CREATE TABLE `tillConfig` ( `id` int(11) NOT NULL, `openingBalance` decimal(10,2) NOT NULL, - `updated` timestamp NOT NULL DEFAULT current_timestamp(), + `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -41940,7 +38372,7 @@ BEGIN `sender` = 'jgallego@verdnatura.es', `replyTo` = 'jgallego@verdnatura.es', `subject` = 'tabla time modificada', - `body` = CONCAT(account.myUserGetName(), ' ha modificado la tabla time ', + `body` = CONCAT(account.myUser_getName(), ' ha modificado la tabla time ', NEW.`dated`);*/ END */;; DELIMITER ; @@ -42148,7 +38580,7 @@ CREATE TABLE `trainingCenter` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42167,9 +38599,9 @@ CREATE TABLE `trainingCourse` ( `ended` datetime NOT NULL, `invoice` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, `amount` double DEFAULT NULL, - `remark` longtext COLLATE utf8_unicode_ci DEFAULT NULL, - `hasDiscount` tinyint(1) NOT NULL DEFAULT 0, - `hasDiploma` tinyint(1) NOT NULL DEFAULT 0, + `remark` longtext COLLATE utf8_unicode_ci, + `hasDiscount` tinyint(1) NOT NULL DEFAULT '0', + `hasDiploma` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `frgnWorker_idx` (`workerFk`), KEY `frgnCenter_idx` (`centerFk`), @@ -42177,7 +38609,7 @@ CREATE TABLE `trainingCourse` ( CONSTRAINT `frgnCenter` FOREIGN KEY (`centerFk`) REFERENCES `trainingCenter` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `frgnTrainingCourseType` FOREIGN KEY (`trainingCourseTypeFk`) REFERENCES `trainingCourseType` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `frgnWorker` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de trabajadores que han realizado una formación'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de trabajadores que han realizado una formación'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42191,7 +38623,7 @@ CREATE TABLE `trainingCourseType` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de las formaciones'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de las formaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42211,12 +38643,12 @@ CREATE TABLE `travel` ( `warehouseOutFk` smallint(6) unsigned DEFAULT NULL, `agencyFk` int(11) DEFAULT NULL, `ref` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `isDelivered` tinyint(1) NOT NULL DEFAULT 0, - `isReceived` tinyint(1) NOT NULL DEFAULT 0, + `isDelivered` tinyint(1) NOT NULL DEFAULT '0', + `isReceived` tinyint(1) NOT NULL DEFAULT '0', `m3` decimal(10,2) unsigned DEFAULT NULL, `kg` decimal(10,0) unsigned DEFAULT NULL, `cargoSupplierFk` int(11) DEFAULT NULL, - `totalEntries` tinyint(4) unsigned DEFAULT 0, + `totalEntries` tinyint(4) unsigned DEFAULT '0', `appointment` datetime DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `shipment_2` (`shipped`,`landed`,`warehouseInFk`,`warehouseOutFk`,`agencyFk`,`ref`), @@ -42342,7 +38774,7 @@ CREATE TABLE `travelClonedWeekly` ( CONSTRAINT `travelClonedWeekly_FK_2` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON UPDATE CASCADE, CONSTRAINT `travelClonedWeekly_FK_3` FOREIGN KEY (`supplierFk`) REFERENCES `supplier` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `travelClonedWeekly_FK_4` FOREIGN KEY (`travelFk`) REFERENCES `travel` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42357,11 +38789,11 @@ CREATE TABLE `travelLog` ( `originFk` int(10) 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 DEFAULT 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 DEFAULT NULL, - `newInstance` text 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`), @@ -42369,7 +38801,7 @@ CREATE TABLE `travelLog` ( KEY `userFk` (`userFk`), CONSTRAINT `travelLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `travel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `travelLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42384,9 +38816,9 @@ CREATE TABLE `travelObservation` ( `originFk` int(11) NOT NULL, `userFk` int(11) NOT NULL, `description` text COLLATE utf8_unicode_ci NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de travel'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de travel'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42443,11 +38875,11 @@ DROP TABLE IF EXISTS `trolley`; CREATE TABLE `trolley` ( `id` int(11) NOT NULL AUTO_INCREMENT, `workerFk` int(10) unsigned DEFAULT NULL, - `coupled` timestamp NOT NULL DEFAULT current_timestamp(), + `coupled` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `trolley_FK` (`workerFk`), CONSTRAINT `trolley_FK` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42480,8 +38912,9 @@ CREATE TABLE `userConfig` ( `userFk` int(10) unsigned NOT NULL, `warehouseFk` smallint(6) DEFAULT NULL, `companyFk` smallint(5) unsigned DEFAULT NULL, - `created` timestamp NULL DEFAULT current_timestamp(), - `updated` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `created` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `darkMode` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Salix interface dark mode', PRIMARY KEY (`userFk`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Configuración de usuario en Salix'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -42498,11 +38931,11 @@ CREATE TABLE `userLog` ( `originFk` int(10) 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 DEFAULT 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 DEFAULT NULL, - `newInstance` text 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`), @@ -42559,9 +38992,9 @@ CREATE TABLE `vehicle` ( `numberPlate` varchar(10) COLLATE utf8_unicode_ci NOT NULL, `model` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `tradeMark` varchar(20) COLLATE utf8_unicode_ci NOT NULL, - `companyFk` smallint(5) unsigned NOT NULL DEFAULT 442, + `companyFk` smallint(5) unsigned NOT NULL DEFAULT '442', `m3` double DEFAULT NULL, - `isActive` tinyint(4) NOT NULL DEFAULT 1, + `isActive` tinyint(4) NOT NULL DEFAULT '1', `warehouseFk` smallint(6) unsigned DEFAULT NULL, `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `deliveryPointFk` int(11) DEFAULT '6' COMMENT 'Direccion para Buscaman', @@ -42600,7 +39033,7 @@ CREATE TABLE `vehicleDms` ( KEY `vehicleDms_FK_1` (`dmsFk`), CONSTRAINT `vehicleDms_FK` FOREIGN KEY (`vehicleFk`) REFERENCES `vehicle` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `vehicleDms_FK_1` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Gestion documental de vehicle'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Gestion documental de vehicle'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42623,7 +39056,7 @@ CREATE TABLE `vehicleEvent` ( KEY `vehicleEvent_FK_1` (`userFk`), CONSTRAINT `vehicleEvent_FK` FOREIGN KEY (`vehicleStateFk`) REFERENCES `vehicleState` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `vehicleEvent_FK_1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42643,7 +39076,7 @@ CREATE TABLE `vehicleInvoiceIn` ( KEY `vehicleInvoiceIn_FK_1` (`invoiceInFk`), CONSTRAINT `vehicleInvoiceIn_FK` FOREIGN KEY (`vehicleFk`) REFERENCES `vehicle` (`id`), CONSTRAINT `vehicleInvoiceIn_FK_1` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42656,7 +39089,7 @@ DROP TABLE IF EXISTS `vehicleNotes`; CREATE TABLE `vehicleNotes` ( `id` int(11) NOT NULL AUTO_INCREMENT, `vehicleFk` int(10) unsigned NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `note` text COLLATE utf8_unicode_ci NOT NULL, `userFk` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), @@ -42691,15 +39124,15 @@ DROP TABLE IF EXISTS `volumeConfig`; CREATE TABLE `volumeConfig` ( `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, + `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', - `ccLength` int(11) NOT NULL DEFAULT 130 COMMENT 'longitud útil para la carga de un CC, en cm', - `ccWidth` int(11) NOT NULL DEFAULT 60 COMMENT 'ancho útil para la carga en un CC, en cm', - `sorterPallet_m3` decimal(5,1) NOT NULL DEFAULT 2.0 COMMENT 'volumen minimo para extraer pallet del sorter', - `minTicketVolume` int(11) NOT NULL DEFAULT 75 COMMENT 'volumen mínimo, en litros, para que un pedido sea preparable', - `shelveVolume` int(11) DEFAULT 200 COMMENT 'volumen en litros de una bandeja standard, a efectos de los sacadores', - `minTicketValue` int(11) NOT NULL DEFAULT 50 + `minCompressionRate` decimal(10,2) DEFAULT '0.30' COMMENT 'minimo permitido por la empresa', + `ccLength` int(11) NOT NULL DEFAULT '130' COMMENT 'longitud útil para la carga de un CC, en cm', + `ccWidth` int(11) NOT NULL DEFAULT '60' COMMENT 'ancho útil para la carga en un CC, en cm', + `sorterPallet_m3` decimal(5,1) NOT NULL DEFAULT '2.0' COMMENT 'volumen minimo para extraer pallet del sorter', + `minTicketVolume` int(11) NOT NULL DEFAULT '75' COMMENT 'volumen mínimo, en litros, para que un pedido sea preparable', + `shelveVolume` int(11) DEFAULT '200' COMMENT 'volumen en litros de una bandeja standard, a efectos de los sacadores', + `minTicketValue` int(11) NOT NULL DEFAULT '50' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='almacena el valor standard para volumenes convencionales de Verdnatura, en metros cúbicos'; /*!40101 SET character_set_client = @saved_cs_client */; @@ -42712,10 +39145,10 @@ DROP TABLE IF EXISTS `wagon`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `wagon` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `volume` int(11) NOT NULL DEFAULT 150 COMMENT 'Volumen en litros', + `volume` int(11) NOT NULL DEFAULT '150' COMMENT 'Volumen en litros', `plate` varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Matrícula', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42727,15 +39160,15 @@ DROP TABLE IF EXISTS `wagonVolumetry`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `wagonVolumetry` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `level` int(10) unsigned NOT NULL DEFAULT 0, - `lines` int(10) unsigned NOT NULL DEFAULT 1, - `liters` int(10) unsigned NOT NULL DEFAULT 0, - `height` int(10) unsigned NOT NULL DEFAULT 20, + `level` int(10) unsigned NOT NULL DEFAULT '0', + `lines` int(10) unsigned NOT NULL DEFAULT '1', + `liters` int(10) unsigned NOT NULL DEFAULT '0', + `height` int(10) unsigned NOT NULL DEFAULT '20', `wagonFk` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `wagonVolumetry_FK` (`wagonFk`), CONSTRAINT `wagonVolumetry_FK` FOREIGN KEY (`wagonFk`) REFERENCES `wagon` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42749,38 +39182,40 @@ CREATE TABLE `warehouse` ( `id` smallint(6) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `code` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, - `isFeedStock` tinyint(1) unsigned NOT NULL DEFAULT 0, + `isFeedStock` tinyint(1) unsigned NOT NULL DEFAULT '0', `addressName` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `delay` double NOT NULL DEFAULT 0.004, - `hasAvailable` tinyint(4) NOT NULL DEFAULT 0, - `isForTicket` tinyint(2) unsigned zerofill NOT NULL DEFAULT 00, - `countryFk` mediumint(8) unsigned NOT NULL DEFAULT 1, - `labelZone` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'almacenes donde hay produccion', - `hasComission` tinyint(4) NOT NULL DEFAULT 0, - `isInventory` tinyint(2) NOT NULL DEFAULT 0, - `isComparative` tinyint(2) NOT NULL DEFAULT 0 COMMENT 'Si esta a true,en la comparativa muestra el stock de este almacen, cuando no se especifica almacen.', - `valuatedInventory` tinyint(2) NOT NULL DEFAULT 0 COMMENT 'Determina si se incluye en el informe de inventario valorado', - `isManaged` tinyint(2) NOT NULL DEFAULT 0 COMMENT 'Se añaden los cubos de expedition a la tabla ticketPackaging', - `hasConfectionTeam` tinyint(1) unsigned NOT NULL DEFAULT 0, - `hasStowaway` tinyint(1) NOT NULL DEFAULT 0, - `hasDms` tinyint(1) NOT NULL DEFAULT 0, + `delay` double NOT NULL DEFAULT '0.004', + `hasAvailable` tinyint(4) NOT NULL DEFAULT '0', + `isForTicket` tinyint(2) unsigned zerofill NOT NULL DEFAULT '00', + `countryFk` mediumint(8) unsigned NOT NULL DEFAULT '1', + `labelZone` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'almacenes donde hay produccion', + `hasComission` tinyint(4) NOT NULL DEFAULT '0', + `isInventory` tinyint(2) NOT NULL DEFAULT '0', + `isComparative` tinyint(2) NOT NULL DEFAULT '0' COMMENT 'Si esta a true,en la comparativa muestra el stock de este almacen, cuando no se especifica almacen.', + `valuatedInventory` tinyint(2) NOT NULL DEFAULT '0' COMMENT 'Determina si se incluye en el informe de inventario valorado', + `isManaged` tinyint(2) NOT NULL DEFAULT '0' COMMENT 'Se añaden los cubos de expedition a la tabla ticketPackaging', + `hasConfectionTeam` tinyint(1) unsigned NOT NULL DEFAULT '0', + `hasStowaway` tinyint(1) NOT NULL DEFAULT '0', + `hasDms` tinyint(1) NOT NULL DEFAULT '0', `pickUpAgencyModeFk` int(11) DEFAULT NULL, - `isBuyerToBeEmailed` tinyint(2) NOT NULL DEFAULT 0, + `isBuyerToBeEmailed` tinyint(2) NOT NULL DEFAULT '0', `aliasFk` smallint(5) unsigned DEFAULT NULL, `labelReport` int(11) DEFAULT NULL, - `hasUbications` tinyint(1) NOT NULL DEFAULT 1, - `hasProduction` tinyint(1) NOT NULL DEFAULT 0, + `hasUbications` tinyint(1) NOT NULL DEFAULT '1', + `hasProduction` tinyint(1) NOT NULL DEFAULT '0', `addressFk` int(11) DEFAULT NULL, - `hasMachine` tinyint(1) NOT NULL DEFAULT 0, - `isLogiflora` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Este almacén acepta productos de Logiflora', - `isBionic` tinyint(1) NOT NULL DEFAULT 1, + `hasMachine` tinyint(1) NOT NULL DEFAULT '0', + `isLogiflora` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Este almacén acepta productos de Logiflora', + `isBionic` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `name_UNIQUE` (`name`), KEY `Id_Paises` (`countryFk`), KEY `isComparativeIdx` (`isComparative`), KEY `warehouse_ibfk_1_idx` (`aliasFk`), KEY `warehouse_FK` (`addressFk`), + KEY `warehouse_FK_1` (`pickUpAgencyModeFk`), CONSTRAINT `warehouse_FK` FOREIGN KEY (`addressFk`) REFERENCES `address` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `warehouse_FK_1` FOREIGN KEY (`pickUpAgencyModeFk`) REFERENCES `agencyMode` (`id`) ON UPDATE CASCADE, CONSTRAINT `warehouse_ibfk_1` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`), CONSTRAINT `warehouse_ibfk_2` FOREIGN KEY (`aliasFk`) REFERENCES `warehouseAlias` (`id`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -42857,9 +39292,9 @@ DROP TABLE IF EXISTS `workCenter`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `workCenter` ( - `id` int(11) NOT NULL DEFAULT 0, + `id` int(11) NOT NULL DEFAULT '0', `name` varchar(255) DEFAULT NULL, - `payrollCenterFk` int(11) DEFAULT NULL, + `payrollCenterFk` int(11) DEFAULT NULL COMMENT 'Campo workcenter en A3', `counter` bigint(20) DEFAULT NULL, `warehouseFk` smallint(6) DEFAULT NULL, `street` varchar(255) DEFAULT NULL, @@ -42907,19 +39342,19 @@ CREATE TABLE `worker` ( `started__` datetime DEFAULT NULL, `ended__` datetime DEFAULT NULL, `notes__` varchar(254) COLLATE utf8_unicode_ci DEFAULT NULL, - `photo` blob DEFAULT NULL, + `photo` blob, `fi__` varchar(9) COLLATE utf8_unicode_ci DEFAULT NULL, `address__` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `birthed__` date NOT NULL, `phone` varchar(9) COLLATE utf8_unicode_ci NOT NULL, `clientFk__` int(11) DEFAULT NULL, `userFk` int(10) unsigned DEFAULT NULL, - `bossFk` int(11) NOT NULL DEFAULT 103, + `bossFk` int(11) NOT NULL DEFAULT '103', `fiDueDate` datetime DEFAULT NULL, - `hasMachineryAuthorized` tinyint(2) DEFAULT 0, + `hasMachineryAuthorized` tinyint(2) DEFAULT '0', `seniority` date DEFAULT NULL, - `isTodayRelative` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Para el F11. Calcula los problemas de visiblidad en funcion del dia actual', - `isF11Allowed` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Usuario autorizado para abrir el F11', + `isTodayRelative` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Para el F11. Calcula los problemas de visiblidad en funcion del dia actual', + `isF11Allowed` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Usuario autorizado para abrir el F11', `sectorFk` int(11) DEFAULT NULL COMMENT 'Sector que tiene asociado el trabajador.', `maritalStatus` enum('S','M') COLLATE utf8_unicode_ci NOT NULL, `labelerFk` tinyint(3) unsigned DEFAULT NULL, @@ -42944,6 +39379,21 @@ CREATE TABLE `worker` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `workerAppTester` +-- + +DROP TABLE IF EXISTS `workerAppTester`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `workerAppTester` ( + `workerFk` int(10) unsigned NOT NULL, + PRIMARY KEY (`workerFk`), + KEY `workerAppTester_FK` (`workerFk`), + CONSTRAINT `workerAppTester_FK_1` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='La tabla incluye usuarios testers que actualizarán a una versión diferente que el resto para testear los cambios nuevos en las app'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `workerBosses` -- @@ -42961,7 +39411,7 @@ CREATE TABLE `workerBosses` ( KEY `fg_bossFk_worker_idx` (`bossFk`), CONSTRAINT `fg_bossFk_worker` FOREIGN KEY (`bossFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fg_workerFk_worker` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42989,9 +39439,9 @@ DROP TABLE IF EXISTS `workerBusinessType`; CREATE TABLE `workerBusinessType` ( `id` int(11) NOT NULL, `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL, - `isFullTime` tinyint(1) NOT NULL DEFAULT 1, - `isPermanent` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Contrato fijo', - `hasHolidayEntitlement` tinyint(1) DEFAULT 1 COMMENT 'Tiene derecho a vacaciones', + `isFullTime` tinyint(1) NOT NULL DEFAULT '1', + `isPermanent` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Contrato fijo', + `hasHolidayEntitlement` tinyint(1) DEFAULT '1' COMMENT 'Tiene derecho a vacaciones', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -43024,7 +39474,7 @@ CREATE TABLE `workerClockLog` ( `originFk` int(11) NOT NULL, `userFk` int(10) unsigned NOT NULL, `action` set('insert','update','delete','select') COLLATE utf8_unicode_ci NOT NULL, - `creationDate` timestamp NULL DEFAULT current_timestamp(), + `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `description` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), KEY `logWorkerClockoriginFk` (`originFk`), @@ -43105,7 +39555,7 @@ CREATE TABLE `workerDistributionCategory` ( PRIMARY KEY (`id`), KEY `workerDistributionCategory_workerFk_idx` (`workerFk`), CONSTRAINT `workerDistributionCategory_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43119,12 +39569,12 @@ CREATE TABLE `workerDocument` ( `id` int(11) NOT NULL AUTO_INCREMENT, `worker` int(10) unsigned DEFAULT NULL, `document` int(11) DEFAULT NULL, - `isReadableByWorker` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Indica si el empleado tiene permiso para acceder al documento', + `isReadableByWorker` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Indica si el empleado tiene permiso para acceder al documento', PRIMARY KEY (`id`), KEY `workerDocument_ibfk_1` (`worker`), KEY `workerDocument_ibfk_2` (`document`), CONSTRAINT `workerDocument_ibfk_1` FOREIGN KEY (`worker`) REFERENCES `worker` (`userFk`) ON UPDATE CASCADE, - CONSTRAINT `workerDocument_ibfk_2` FOREIGN KEY (`document`) REFERENCES `dms` (`id`) ON UPDATE CASCADE + CONSTRAINT `workerDocument_ibfk_2` FOREIGN KEY (`document`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -43140,7 +39590,7 @@ CREATE TABLE `workerEmergencyBoss` ( `name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `value` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Table to save all responsible people phones', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43157,7 +39607,7 @@ CREATE TABLE `workerHourPrice` ( `nightInc` decimal(4,2) DEFAULT NULL, `extraInc` decimal(4,2) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Recoge los acuerdos de los distintos convenios'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Recoge los acuerdos de los distintos convenios'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43172,14 +39622,14 @@ CREATE TABLE `workerIrpf` ( `spouseNif` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `geographicMobilityDate` date DEFAULT NULL, `disabilityGradeFk` int(11) DEFAULT NULL, - `isDependend` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Acredita la necesidad de ayuda de terceras personas o movilidad reducida', + `isDependend` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Acredita la necesidad de ayuda de terceras personas o movilidad reducida', `familySituation` enum('1','2','3') COLLATE utf8_unicode_ci DEFAULT '1', `spousePension` decimal(10,2) DEFAULT NULL COMMENT 'Apartado 4 - Pensión compensatoria en favor del conyuge ', `childPension` decimal(10,2) DEFAULT NULL COMMENT 'Apartado 4 - Anualidades por alimentos en favor de los hijos', - `hasHousingPaymentBefore` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Apartado 5 - Pagos por adquisición o rehabilitación de la vivienda habitual utilizando financiación ajena, con derecho a deducción del IRPF', - `hasHousingPaymentAfter` tinyint(1) NOT NULL DEFAULT 0, - `hasExtendedWorking` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Aprtado 1 - prolongar la actividad laboral', - `updated` timestamp NULL DEFAULT current_timestamp(), + `hasHousingPaymentBefore` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Apartado 5 - Pagos por adquisición o rehabilitación de la vivienda habitual utilizando financiación ajena, con derecho a deducción del IRPF', + `hasHousingPaymentAfter` tinyint(1) NOT NULL DEFAULT '0', + `hasExtendedWorking` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Aprtado 1 - prolongar la actividad laboral', + `updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`workerFk`), KEY `workerIrpf_disabilityGradeFk` (`disabilityGradeFk`), CONSTRAINT `workerIrpf_disabilityGradeFk` FOREIGN KEY (`disabilityGradeFk`) REFERENCES `disabilityGrade` (`id`) ON UPDATE CASCADE, @@ -43198,21 +39648,21 @@ CREATE TABLE `workerJourney` ( `id` int(11) NOT NULL AUTO_INCREMENT, `userFk` int(10) unsigned NOT NULL, `dated` date NOT NULL, - `total` decimal(5,2) NOT NULL DEFAULT 0.00, - `priceOrdinaryHour` decimal(5,2) NOT NULL DEFAULT 0.00, - `nocturn` decimal(5,2) NOT NULL DEFAULT 0.00, - `priceNocturnHour` decimal(5,2) NOT NULL DEFAULT 0.00, - `holiday` decimal(5,2) NOT NULL DEFAULT 0.00, - `priceHolidayHour` decimal(5,2) NOT NULL DEFAULT 0.00, - `lunch` decimal(5,2) NOT NULL DEFAULT 0.00, - `priceExtraHour` decimal(5,2) NOT NULL DEFAULT 0.00, - `extra` decimal(5,2) NOT NULL DEFAULT 0.00, - `contractJourney` decimal(5,2) NOT NULL DEFAULT 0.00, - `priceExtraHoliday` decimal(5,2) NOT NULL DEFAULT 0.00, + `total` decimal(5,2) NOT NULL DEFAULT '0.00', + `priceOrdinaryHour` decimal(5,2) NOT NULL DEFAULT '0.00', + `nocturn` decimal(5,2) NOT NULL DEFAULT '0.00', + `priceNocturnHour` decimal(5,2) NOT NULL DEFAULT '0.00', + `holiday` decimal(5,2) NOT NULL DEFAULT '0.00', + `priceHolidayHour` decimal(5,2) NOT NULL DEFAULT '0.00', + `lunch` decimal(5,2) NOT NULL DEFAULT '0.00', + `priceExtraHour` decimal(5,2) NOT NULL DEFAULT '0.00', + `extra` decimal(5,2) NOT NULL DEFAULT '0.00', + `contractJourney` decimal(5,2) NOT NULL DEFAULT '0.00', + `priceExtraHoliday` decimal(5,2) NOT NULL DEFAULT '0.00', `businessFk` int(11) DEFAULT NULL, - `isPaid` tinyint(1) NOT NULL DEFAULT 0, - `isUpdated` tinyint(1) NOT NULL DEFAULT 0, - `permission` decimal(5,2) NOT NULL DEFAULT 0.00, + `isPaid` tinyint(1) NOT NULL DEFAULT '0', + `isUpdated` tinyint(1) NOT NULL DEFAULT '0', + `permission` decimal(5,2) NOT NULL DEFAULT '0.00', PRIMARY KEY (`id`), UNIQUE KEY `userFk_UNIQUE` (`userFk`,`dated`), KEY `fk_workerJourney_user_idx` (`userFk`), @@ -43220,7 +39670,7 @@ CREATE TABLE `workerJourney` ( 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 DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43254,11 +39704,11 @@ CREATE TABLE `workerLog` ( `originFk` int(10) unsigned NOT NULL, `userFk` int(10) unsigned NOT NULL, `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL, - `creationDate` timestamp NULL DEFAULT current_timestamp(), + `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `description` text COLLATE utf8_unicode_ci NOT NULL, `changedModel` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, - `oldInstance` text COLLATE utf8_unicode_ci DEFAULT NULL, - `newInstance` text 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`), @@ -43266,7 +39716,7 @@ CREATE TABLE `workerLog` ( KEY `userFk_idx` (`userFk`), CONSTRAINT `userFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `workerFk` FOREIGN KEY (`originFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43278,12 +39728,12 @@ DROP TABLE IF EXISTS `workerMana`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `workerMana` ( `workerFk` int(10) unsigned NOT NULL, - `size` int(11) NOT NULL DEFAULT 300, - `amount` int(11) NOT NULL DEFAULT 0, - `pricesModifierRate` double NOT NULL DEFAULT 0, - `isPricesModifierActivated` tinyint(1) NOT NULL DEFAULT 1, - `minRate` decimal(3,2) NOT NULL DEFAULT -0.05, - `maxRate` decimal(3,2) NOT NULL DEFAULT 0.05, + `size` int(11) NOT NULL DEFAULT '300', + `amount` int(11) NOT NULL DEFAULT '0', + `pricesModifierRate` double NOT NULL DEFAULT '0', + `isPricesModifierActivated` tinyint(1) NOT NULL DEFAULT '1', + `minRate` decimal(3,2) NOT NULL DEFAULT '-0.05', + `maxRate` decimal(3,2) NOT NULL DEFAULT '0.05', PRIMARY KEY (`workerFk`), KEY `fk_mana_spellers_Trabajadores_idx` (`workerFk`), CONSTRAINT `fk_mana_spellers_Trabajadores` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE @@ -43304,25 +39754,6 @@ CREATE TABLE `workerManaExcluded` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Usuarios que tienen que estar excluidos del cálculo del maná'; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Temporary table structure for view `workerMana__` --- - -DROP TABLE IF EXISTS `workerMana__`; -/*!50001 DROP VIEW IF EXISTS `workerMana__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `workerMana__` ( - `workerFk` tinyint NOT NULL, - `size` tinyint NOT NULL, - `amount` tinyint NOT NULL, - `pricesModifierRate` tinyint NOT NULL, - `isPricesModifierActivated` tinyint NOT NULL, - `minRate` tinyint NOT NULL, - `maxRate` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - -- -- Temporary table structure for view `workerMedia` -- @@ -43348,13 +39779,13 @@ CREATE TABLE `workerMistake` ( `id` int(11) NOT NULL AUTO_INCREMENT, `userFk` int(10) unsigned NOT NULL, `workerMistakeTypeFk` varchar(10) COLLATE utf8_unicode_ci NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `workerMistake_fk1_idx` (`userFk`), KEY `workerMistake_fk2_idx` (`workerMistakeTypeFk`), CONSTRAINT `workerMistake_fk1` FOREIGN KEY (`userFk`) REFERENCES `worker` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `workerMistake_fk2` FOREIGN KEY (`workerMistakeTypeFk`) REFERENCES `workerMistakeType` (`code`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43381,19 +39812,19 @@ DROP TABLE IF EXISTS `workerRelatives`; CREATE TABLE `workerRelatives` ( `id` int(11) NOT NULL AUTO_INCREMENT, `workerFk` int(10) unsigned NOT NULL, - `isDescendant` tinyint(1) DEFAULT 1 COMMENT 'Descendientes - Ascendientes', + `isDescendant` tinyint(1) DEFAULT '1' COMMENT 'Descendientes - Ascendientes', `disabilityGradeFk` int(11) DEFAULT NULL, `birthed` int(4) NOT NULL, `adoptionYear` int(4) DEFAULT NULL COMMENT 'Solo en el caso de descendientes', - `isDependend` tinyint(1) DEFAULT 0, - `isJointCustody` tinyint(1) DEFAULT 0 COMMENT 'Solo en el caso de descendientes', - `updated` timestamp NULL DEFAULT current_timestamp(), + `isDependend` tinyint(1) DEFAULT '0', + `isJointCustody` tinyint(1) DEFAULT '0' COMMENT 'Solo en el caso de descendientes', + `updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `workerRelatives_disabilityGradeFk` (`disabilityGradeFk`), KEY `workerRelatives_workerFk` (`workerFk`), CONSTRAINT `workerRelatives_disabilityGradeFk` FOREIGN KEY (`disabilityGradeFk`) REFERENCES `disabilityGrade` (`id`) ON UPDATE CASCADE, CONSTRAINT `workerRelatives_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `workerIrpf` (`workerFk`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Modelo 145 IRPF apartado 2 y 3'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Modelo 145 IRPF apartado 2 y 3'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43408,7 +39839,7 @@ CREATE TABLE `workerShelving` ( `workerFk` int(10) unsigned NOT NULL, `shelvingFk` varchar(10) CHARACTER SET utf8 NOT NULL, `collectionFk` int(11) DEFAULT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `workerShelving_shelving_fk` (`shelvingFk`), KEY `workerShelving_FK` (`workerFk`), @@ -43416,7 +39847,7 @@ CREATE TABLE `workerShelving` ( 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 */; -- @@ -43502,14 +39933,15 @@ CREATE TABLE `workerTimeControl` ( `id` int(11) NOT NULL AUTO_INCREMENT, `userFk` int(10) unsigned NOT NULL, `timed` datetime NOT NULL, - `manual` tinyint(4) NOT NULL DEFAULT 0, + `manual` tinyint(4) NOT NULL DEFAULT '0', `order` int(11) DEFAULT NULL, `warehouseFk` smallint(6) unsigned DEFAULT NULL, `direction` enum('in','out','middle') COLLATE utf8_unicode_ci DEFAULT 'middle', - `isSendMail` tinyint(4) NOT NULL DEFAULT 0 COMMENT 'Fichadas generadas autómaticamente con el procedimiento vn.workerTimeControl_sendMail', + `isSendMail` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Fichadas generadas autómaticamente con el procedimiento vn.workerTimeControl_sendMail', PRIMARY KEY (`id`), UNIQUE KEY `userFk_Timed_uniq` (`userFk`,`timed`), KEY `warehouseFkfk1_idx` (`warehouseFk`), + KEY `timed_idx` (`timed`), CONSTRAINT `warehouseFk_1` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `workerTimeControl_fk1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Fichadas'; @@ -43527,7 +39959,7 @@ DELIMITER ;; AFTER INSERT ON `workerTimeControl` FOR EACH ROW BEGIN - IF NEW.timed > DATE_ADD(util.VN_NOW(), INTERVAL 1 DAY) THEN + IF NEW.timed > DATE_ADD(vn.VN_NOW(), INTERVAL 1 DAY) THEN CALL util.throw('date in the future'); END IF; END */;; @@ -43565,8 +39997,10 @@ CREATE TABLE `workerTimeControlConfig` ( `breakTime` int(11) DEFAULT NULL COMMENT 'Tiempo de descanso expresado en segundos', `timeToBreakTime` int(11) DEFAULT NULL COMMENT 'Tiempo mínimo que se debe trabajar para añadir descanso, expresado en segundos', `dayMaxTime` int(11) DEFAULT NULL COMMENT 'Tiempo máximo desde la entrada hasta la salida, expresado en segundos', + `shortWeekDays` int(11) DEFAULT NULL COMMENT 'Días a tener en cuenta para calcular el descanso corto', + `longWeekDays` int(11) DEFAULT NULL COMMENT 'Días a tener en cuenta para calcular el descanso largo', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='All values in seconds'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='All values in seconds'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43583,7 +40017,7 @@ CREATE TABLE `workerTimeControlConfig_` ( PRIMARY KEY (`id`), KEY `warehouseFk_1_idx` (`warehouseFk`), CONSTRAINT `warehouseFk_2` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43596,7 +40030,7 @@ DROP TABLE IF EXISTS `workerTimeControlLog`; CREATE TABLE `workerTimeControlLog` ( `id` int(11) NOT NULL AUTO_INCREMENT, `userFk` int(10) NOT NULL, - `created` datetime NOT NULL DEFAULT current_timestamp(), + `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `description` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Log de fichadas, se rellena cuando el fichador(tablet) no autoriza el fichaje (PROC:vn.workerTimeControl_check)'; @@ -43615,14 +40049,14 @@ CREATE TABLE `workerTimeControlMail` ( `year` int(4) NOT NULL, `week` int(2) NOT NULL, `state` enum('SENDED','CONFIRMED','REVISE') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'SENDED', - `updated` datetime NOT NULL DEFAULT current_timestamp() COMMENT 'Fecha/hora último cambio de estado', - `sendedCounter` int(3) NOT NULL DEFAULT 1 COMMENT 'Número de veces que se ha enviado el correo', - `emailResponse` text COLLATE utf8_unicode_ci DEFAULT NULL, + `updated` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Fecha/hora último cambio de estado', + `sendedCounter` int(3) NOT NULL DEFAULT '1' COMMENT 'Número de veces que se ha enviado el correo', + `emailResponse` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`), UNIQUE KEY `workerFk_UNIQUE` (`workerFk`,`year`,`week`), KEY `workerFk_idx` (`workerFk`), CONSTRAINT `workerTimeControlMail_workerFk` FOREIGN KEY (`workerFk`) REFERENCES `worker` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Guarda las respuestas de mail de los correos generados automáticamente por la procedimiento workerTimeControl_sendMail'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Guarda las respuestas de mail de los correos generados automáticamente por la procedimiento workerTimeControl_sendMail'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43678,7 +40112,7 @@ CREATE TABLE `workerTimeControlSchedule` ( `time` time DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `punique_trhf` (`time`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43722,24 +40156,6 @@ SET character_set_client = utf8; ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; --- --- Temporary table structure for view `workerTimeControl_Journey__` --- - -DROP TABLE IF EXISTS `workerTimeControl_Journey__`; -/*!50001 DROP VIEW IF EXISTS `workerTimeControl_Journey__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `workerTimeControl_Journey__` ( - `userFk` tinyint NOT NULL, - `dated` tinyint NOT NULL, - `Journey` tinyint NOT NULL, - `dayName` tinyint NOT NULL, - `name` tinyint NOT NULL, - `firstname` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - -- -- Temporary table structure for view `workerTimeJourneyNG` -- @@ -43758,21 +40174,6 @@ 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` -- @@ -43797,8 +40198,8 @@ DROP TABLE IF EXISTS `workers20190711`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `workers20190711` ( - `person_id` int(11) NOT NULL DEFAULT 0, - `business_id` int(11) NOT NULL DEFAULT 0, + `person_id` int(11) NOT NULL DEFAULT '0', + `business_id` int(11) NOT NULL DEFAULT '0', `Apellidos` varchar(60) CHARACTER SET utf8 NOT NULL, `Nombre` varchar(20) CHARACTER SET utf8 DEFAULT NULL, `nif` varchar(15) CHARACTER SET utf8 DEFAULT NULL, @@ -43823,7 +40224,7 @@ DROP TABLE IF EXISTS `workers20190711_FichadasAbril`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `workers20190711_FichadasAbril` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `person_id` int(11) NOT NULL DEFAULT 0, + `person_id` int(11) NOT NULL DEFAULT '0', `nif` varchar(15) CHARACTER SET utf8 DEFAULT NULL, `Apellidos` varchar(60) CHARACTER SET utf8 NOT NULL, `Nombre` varchar(20) CHARACTER SET utf8 DEFAULT NULL, @@ -43831,9 +40232,9 @@ CREATE TABLE `workers20190711_FichadasAbril` ( `Hora` int(2) DEFAULT NULL, `Minuto` int(2) DEFAULT NULL, `sumable` double DEFAULT NULL, - `jornada` decimal(5,2) NOT NULL DEFAULT 8.00, + `jornada` decimal(5,2) NOT NULL DEFAULT '8.00', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43845,7 +40246,7 @@ DROP TABLE IF EXISTS `workers20190711_FichadasJulio11`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `workers20190711_FichadasJulio11` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `person_id` int(11) NOT NULL DEFAULT 0, + `person_id` int(11) NOT NULL DEFAULT '0', `nif` varchar(15) CHARACTER SET utf8 DEFAULT NULL, `Apellidos` varchar(60) CHARACTER SET utf8 NOT NULL, `Nombre` varchar(20) CHARACTER SET utf8 DEFAULT NULL, @@ -43853,9 +40254,9 @@ CREATE TABLE `workers20190711_FichadasJulio11` ( `Hora` int(2) DEFAULT NULL, `Minuto` int(2) DEFAULT NULL, `sumable` double DEFAULT NULL, - `jornada` decimal(5,2) NOT NULL DEFAULT 8.00, + `jornada` decimal(5,2) NOT NULL DEFAULT '8.00', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43867,7 +40268,7 @@ DROP TABLE IF EXISTS `workers20190711_FichadasJunio`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `workers20190711_FichadasJunio` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `person_id` int(11) NOT NULL DEFAULT 0, + `person_id` int(11) NOT NULL DEFAULT '0', `nif` varchar(15) CHARACTER SET utf8 DEFAULT NULL, `Apellidos` varchar(60) CHARACTER SET utf8 NOT NULL, `Nombre` varchar(20) CHARACTER SET utf8 DEFAULT NULL, @@ -43875,9 +40276,9 @@ CREATE TABLE `workers20190711_FichadasJunio` ( `Hora` int(2) DEFAULT NULL, `Minuto` int(2) DEFAULT NULL, `sumable` double DEFAULT NULL, - `jornada` decimal(5,2) NOT NULL DEFAULT 8.00, + `jornada` decimal(5,2) NOT NULL DEFAULT '8.00', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43889,7 +40290,7 @@ DROP TABLE IF EXISTS `workers20190711_FichadasMayo`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `workers20190711_FichadasMayo` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `person_id` int(11) NOT NULL DEFAULT 0, + `person_id` int(11) NOT NULL DEFAULT '0', `nif` varchar(15) CHARACTER SET utf8 DEFAULT NULL, `Apellidos` varchar(60) CHARACTER SET utf8 NOT NULL, `Nombre` varchar(20) CHARACTER SET utf8 DEFAULT NULL, @@ -43897,9 +40298,9 @@ CREATE TABLE `workers20190711_FichadasMayo` ( `Hora` int(2) DEFAULT NULL, `Minuto` int(2) DEFAULT NULL, `sumable` double DEFAULT NULL, - `jornada` decimal(5,2) NOT NULL DEFAULT 8.00, + `jornada` decimal(5,2) NOT NULL DEFAULT '8.00', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43911,7 +40312,7 @@ DROP TABLE IF EXISTS `workers20190711_FichadasOctubre`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `workers20190711_FichadasOctubre` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `person_id` int(11) NOT NULL DEFAULT 0, + `person_id` int(11) NOT NULL DEFAULT '0', `nif` varchar(15) CHARACTER SET utf8 DEFAULT NULL, `Apellidos` varchar(60) CHARACTER SET utf8 NOT NULL, `Nombre` varchar(20) CHARACTER SET utf8 DEFAULT NULL, @@ -43919,9 +40320,9 @@ CREATE TABLE `workers20190711_FichadasOctubre` ( `Hora` int(2) DEFAULT NULL, `Minuto` int(2) DEFAULT NULL, `sumable` double DEFAULT NULL, - `jornada` decimal(5,2) NOT NULL DEFAULT 8.00, + `jornada` decimal(5,2) NOT NULL DEFAULT '8.00', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43933,7 +40334,7 @@ DROP TABLE IF EXISTS `workers20190711_Garrote`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `workers20190711_Garrote` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `person_id` int(11) NOT NULL DEFAULT 0, + `person_id` int(11) NOT NULL DEFAULT '0', `nif` varchar(15) CHARACTER SET utf8 DEFAULT NULL, `Apellidos` varchar(60) CHARACTER SET utf8 NOT NULL, `Nombre` varchar(20) CHARACTER SET utf8 DEFAULT NULL, @@ -43941,9 +40342,9 @@ CREATE TABLE `workers20190711_Garrote` ( `Hora` int(2) DEFAULT NULL, `Minuto` int(2) DEFAULT NULL, `sumable` double DEFAULT NULL, - `jornada` decimal(5,2) NOT NULL DEFAULT 8.00, + `jornada` decimal(5,2) NOT NULL DEFAULT '8.00', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43961,7 +40362,7 @@ CREATE TABLE `workingHours` ( PRIMARY KEY (`id`), KEY `user_working_hour_idx` (`userId`), CONSTRAINT `user_working_hour` FOREIGN KEY (`userId`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena horas de Entrada y de Salida del personal'; +) 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 */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -43976,7 +40377,7 @@ DELIMITER ;; BEFORE INSERT ON `workingHours` FOR EACH ROW BEGIN - IF (SELECT COUNT(*) FROM workingHours WHERE userId = NEW.userId AND DATE(timeIn) = util.VN_CURDATE()) > 0 THEN + IF (SELECT COUNT(*) FROM workingHours WHERE userId = NEW.userId AND DATE(timeIn) = vn.VN_CURDATE()) > 0 THEN CALL util.throw ('ALREADY_LOGGED'); END IF; END */;; @@ -43999,11 +40400,11 @@ CREATE TABLE `zone` ( `hour` datetime NOT NULL, `warehouseFk__` smallint(6) unsigned DEFAULT NULL, `agencyModeFk` int(11) NOT NULL, - `travelingDays` int(11) NOT NULL DEFAULT 1, - `price` double NOT NULL DEFAULT 0, - `bonus` double NOT NULL DEFAULT 0, - `isVolumetric` tinyint(1) NOT NULL DEFAULT 0, - `inflation` decimal(5,2) NOT NULL DEFAULT 1.00, + `travelingDays` int(11) NOT NULL DEFAULT '1', + `price` double NOT NULL DEFAULT '0', + `bonus` double NOT NULL DEFAULT '0', + `isVolumetric` tinyint(1) NOT NULL DEFAULT '0', + `inflation` decimal(5,2) NOT NULL DEFAULT '1.00', `m3Max` decimal(10,2) unsigned DEFAULT NULL, `itemMaxSize` int(11) DEFAULT NULL COMMENT 'tamaño maximo de los articulos que esa ruta puede transportar', `code` varchar(45) DEFAULT NULL, @@ -44060,7 +40461,7 @@ DROP TABLE IF EXISTS `zoneConfig`; CREATE TABLE `zoneConfig` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `scope` int(10) unsigned NOT NULL, - `forwardDays` int(10) NOT NULL DEFAULT 7 COMMENT 'days forward to show zone_upcomingDeliveries', + `forwardDays` int(10) NOT NULL DEFAULT '7' COMMENT 'days forward to show zone_upcomingDeliveries', PRIMARY KEY (`id`) ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -44122,13 +40523,13 @@ CREATE TABLE `zoneExclusion` ( `id` int(11) NOT NULL AUTO_INCREMENT, `zoneFk` int(11) NOT NULL, `dated` date NOT NULL, - `created` timestamp NOT NULL DEFAULT current_timestamp(), + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `userFk` int(11) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `zoneFk_2` (`zoneFk`,`dated`), KEY `zoneFk` (`zoneFk`), CONSTRAINT `zoneExclusion_ibfk_1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -44175,6 +40576,25 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +-- +-- Table structure for table `zoneExclusionGeo` +-- + +DROP TABLE IF EXISTS `zoneExclusionGeo`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `zoneExclusionGeo` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `zoneExclusionFk` int(11) NOT NULL, + `geoFk` int(11) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `zoneExclusionGeo_UN` (`zoneExclusionFk`,`geoFk`), + KEY `zoneExclusionGeo2_FK_1` (`geoFk`), + CONSTRAINT `zoneExclusionGeo_FK` FOREIGN KEY (`geoFk`) REFERENCES `zoneGeo` (`id`) ON UPDATE CASCADE, + CONSTRAINT `zoneExclusionGeo_FK_1` FOREIGN KEY (`zoneExclusionFk`) REFERENCES `zoneExclusion` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDBDEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `zoneFilter` -- @@ -44192,7 +40612,7 @@ CREATE TABLE `zoneFilter` ( KEY `zoneFilter_FK_1` (`itemTypeFk`), CONSTRAINT `zoneFilter_FK` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `zoneFilter_FK_1` FOREIGN KEY (`itemTypeFk`) REFERENCES `itemType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='recoge los parámetros para filtrar determinados productos según la zona'; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='recoge los parámetros para filtrar determinados productos según la zona'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44210,7 +40630,7 @@ CREATE TABLE `zoneGeo` ( `path` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `lft` int(11) DEFAULT NULL, `rgt` int(11) DEFAULT NULL, - `depth` bigint(22) NOT NULL DEFAULT 0, + `depth` bigint(22) NOT NULL DEFAULT '0', `sons` decimal(10,0) DEFAULT NULL, PRIMARY KEY (`id`), KEY `lft_rgt_depth_idx` (`lft`,`rgt`,`depth`), @@ -44273,7 +40693,7 @@ CREATE TABLE `zoneGeoRecalc` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `isChanged` tinyint(4) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44306,11 +40726,11 @@ CREATE TABLE `zoneLog` ( `originFk` int(10) 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 DEFAULT 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 DEFAULT NULL, - `newInstance` text 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`), @@ -44318,7 +40738,7 @@ CREATE TABLE `zoneLog` ( KEY `userFk` (`userFk`), CONSTRAINT `zoneLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `zoneLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44333,11 +40753,11 @@ CREATE TABLE `zonePromo__` ( `zoneFk` int(11) NOT NULL, `dated` date NOT NULL, `amount` decimal(10,2) NOT NULL, - `isDone` tinyint(4) NOT NULL DEFAULT 0, + `isDone` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `zonePromo_fk1_idx` (`zoneFk`), CONSTRAINT `zonePromo_fk1` FOREIGN KEY (`zoneFk`) REFERENCES `zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44359,26 +40779,6 @@ CREATE TABLE `zoneWarehouse` ( ) ENGINE=InnoDBDEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Temporary table structure for view `zone_ETD__` --- - -DROP TABLE IF EXISTS `zone_ETD__`; -/*!50001 DROP VIEW IF EXISTS `zone_ETD__`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE TABLE `zone_ETD__` ( - `zoneFk` tinyint NOT NULL, - `HoraTeórica` tinyint NOT NULL, - `volumenTotal` tinyint NOT NULL, - `volumenPendiente` tinyint NOT NULL, - `velocidad` tinyint NOT NULL, - `HoraPráctica` tinyint NOT NULL, - `minutesLess` tinyint NOT NULL, - `etc` tinyint NOT NULL -) ENGINE=MyISAM */; -SET character_set_client = @saved_cs_client; - -- -- Dumping events for database 'vn' -- @@ -44481,38 +40881,43 @@ DELIMITER ;; DECLARE vCurrentCount INT; DECLARE vCheckSum INT; - DECLARE vIsAlreadyNotified BOOLEAN; - DECLARE vTableQueue TEXT; + DECLARE vIsAlreadyNotified BOOLEAN; + DECLARE vTableQueue TEXT; DECLARE vLineQueue TEXT; - DECLARE vDone BOOL DEFAULT FALSE; - DECLARE vCur CURSOR FOR - SELECT CONCAT(' + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vPrintQueueLimit INT; + + DECLARE vCur CURSOR FOR + SELECT CONCAT(' ', IFNULL(pq.id, ''), ' ', IFNULL(p.path, ''),' - ', IFNULL(lr.name, ''),' - ', IFNULL(e.Estado, ''),' + ', IFNULL(r.name, ''),' + ', IFNULL(pq.statusCode, ''),' ', IFNULL(w.firstname, ''), " ", IFNULL(w.lastName, ''),' ', IFNULL(pq.`error`, ''),' ') - FROM vn.printingQueue pq - LEFT JOIN vn.worker w ON w.id = pq.worker - LEFT JOIN vn.printer p ON p.id = pq.printer - LEFT JOIN vn.labelReport lr ON lr.id = pq.report - JOIN vn2008.Estados e ON e.Id_Estado = pq.state - LIMIT 30; + FROM printQueue pq + LEFT JOIN worker w ON w.id = pq.workerFk + LEFT JOIN printer p ON p.id = pq.printerFk + LEFT JOIN report r ON r.id = pq.reportFk + JOIN printQueueConfig + LIMIT vPrintQueueLimit; - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + SELECT printQueueLimit INTO vPrintQueueLimit + FROM printQueueConfig; SELECT COUNT(*), IFNULL(SUM(id),0) INTO vCurrentCount, vCheckSum - FROM vn.printingQueue WHERE state = 1; - - SELECT isAlreadyNotified INTO vIsAlreadyNotified - FROM printingQueueCheck; + FROM printQueue WHERE statusCode = 'queued'; + + SELECT isAlreadyNotified INTO vIsAlreadyNotified + FROM printingQueueCheck; IF (SELECT lastCount FROM printingQueueCheck) = vCurrentCount AND (SELECT lastCheckSum FROM printingQueueCheck) = vCheckSum AND - vIsAlreadyNotified = FALSE AND vCurrentCount > 0 + vIsAlreadyNotified = FALSE AND vCurrentCount > 0 THEN SELECT ' @@ -44523,46 +40928,46 @@ DELIMITER ;; - ' INTO vTableQueue; + ' INTO vTableQueue; OPEN vCur; - + l: LOOP SET vDone = FALSE; - + FETCH vCur INTO vLineQueue; - - IF vDone THEN + + IF vDone THEN LEAVE l; END IF; - - SELECT CONCAT(vTableQueue, vLineQueue) INTO vTableQueue; + + SELECT CONCAT(vTableQueue, vLineQueue) INTO vTableQueue; END LOOP; - - CLOSE vCur; - - CALL mail_insert( - 'cau@verdnatura.es', - NULL, + + CLOSE vCur; + + CALL mail_insert( + 'cau@verdnatura.es', + NULL, 'Servidor de impresion parado', - CONCAT('Hay ', vCurrentCount, ' lineas bloqueadas', vTableQueue, '
Estado Trabajador Error
') + CONCAT('Hay ', vCurrentCount, ' lineas bloqueadas', vTableQueue, '') ); - - UPDATE printingQueueCheck SET isAlreadyNotified = TRUE; + + UPDATE printingQueueCheck SET isAlreadyNotified = TRUE; END IF; - - IF (SELECT lastCount FROM printingQueueCheck) > vCurrentCount AND - vIsAlreadyNotified = TRUE + + IF (SELECT lastCount FROM printingQueueCheck) > vCurrentCount AND + vIsAlreadyNotified = TRUE THEN UPDATE printingQueueCheck SET isAlreadyNotified = FALSE; END IF; - + UPDATE printingQueueCheck SET lastCount = vCurrentCount, lastCheckSum = vCheckSum; - + END */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; @@ -44599,7 +41004,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `sale_checkWithoutComponents` ON SCHEDULE EVERY 10 MINUTE STARTS '2020-05-04 11:56:23' ON COMPLETION PRESERVE DISABLE DO call sale_checkNoComponents(DATE_ADD(util.VN_NOW(), INTERVAL -10 MINUTE),DATE_ADD(util.VN_NOW(), INTERVAL -1 MINUTE)) */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `sale_checkWithoutComponents` ON SCHEDULE EVERY 10 MINUTE STARTS '2020-05-04 11:56:23' ON COMPLETION PRESERVE DISABLE DO call sale_checkNoComponents(DATE_ADD(vn.VN_NOW(), INTERVAL -10 MINUTE),DATE_ADD(vn.VN_NOW(), INTERVAL -1 MINUTE)) */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44617,7 +41022,7 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `ticketClosure` ON SCHEDULE EVERY 1 DAY STARTS '2017-09-18 00:30:00' ON COMPLETION NOT PRESERVE DISABLE COMMENT 'Realiza el cierre de todos los almacenes del dia actual' DO CALL ticketClosureMultiWarehouse(DATE_ADD(util.VN_CURDATE(), INTERVAL -1 DAY)) */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `ticketClosure` ON SCHEDULE EVERY 1 DAY STARTS '2017-09-18 00:30:00' ON COMPLETION NOT PRESERVE DISABLE COMMENT 'Realiza el cierre de todos los almacenes del dia actual' DO CALL ticketClosureMultiWarehouse(DATE_ADD(vn.VN_CURDATE(), INTERVAL -1 DAY)) */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; @@ -44671,16 +41076,16 @@ DELIMITER ;; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;; /*!50003 SET @saved_time_zone = @@time_zone */ ;; /*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `workerTimeControl_sendMail` ON SCHEDULE EVERY 1 WEEK STARTS '2020-11-25 08:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN - DECLARE vWeek,vYear INT; - - SELECT week,year INTO vWeek,vYear - FROM vn.time - WHERE dated IN (DATE_ADD(util.VN_CURDATE(), INTERVAL -10 DAY), DATE_ADD(util.VN_CURDATE(), INTERVAL -4 DAY)) - GROUP BY year,week - LIMIT 1; - - CALL vn.workerTimeControl_sendMail(vWeek, vYear, NULL); +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `workerTimeControl_sendMail` ON SCHEDULE EVERY 1 WEEK STARTS '2020-11-25 08:00:00' ON COMPLETION NOT PRESERVE ENABLE DO BEGIN + DECLARE vWeek,vYear INT; + + SELECT week,year INTO vWeek,vYear + FROM vn.time + WHERE dated IN (DATE_ADD(vn.VN_CURDATE(), INTERVAL -10 DAY), DATE_ADD(vn.VN_CURDATE(), INTERVAL -4 DAY)) + GROUP BY year,week + LIMIT 1; + + CALL vn.workerTimeControl_sendMail(vWeek, vYear, NULL); END */ ;; /*!50003 SET time_zone = @saved_time_zone */ ;; /*!50003 SET sql_mode = @saved_sql_mode */ ;; @@ -44711,6 +41116,8 @@ DELIMITER ; -- -- Dumping routines for database 'vn' -- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `addressTaxArea` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -44718,8 +41125,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `addressTaxArea`(vAddresId INT, vCompanyId INT) RETURNS varchar(25) CHARSET utf8 DETERMINISTIC @@ -44769,6 +41174,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `address_getGeo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -44776,8 +41183,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `address_getGeo`(vSelf INT) RETURNS int(11) DETERMINISTIC @@ -44805,6 +41210,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `barcodeToItem` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -44812,8 +41219,6 @@ DELIMITER ; /*!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`@`localhost` FUNCTION `barcodeToItem`(vBarcode VARCHAR(22)) RETURNS int(11) DETERMINISTIC @@ -44868,111 +41273,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 FUNCTION IF EXISTS `bionicCalcReverse__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `bionicCalcReverse__`(vWarehouse INT, - vMargin DECIMAL(10,3), - vRetailedPrice DECIMAL(10,3), - vM3 DECIMAL(10,3), - vAddress INT, - vAgencyMode INT) RETURNS decimal(10,3) - DETERMINISTIC -BEGIN - - -- OBSOLETO usar catalog_componentReverse JGF 2020-02-26 - DECLARE vGeneralInflationCoeficient INT; - DECLARE vVerdnaturaVolumeBox BIGINT; - DECLARE vClientFk INT; - DECLARE vComponentRecovery VARCHAR(50) DEFAULT 'debtCollection'; - DECLARE vComponentMana VARCHAR(50) DEFAULT 'autoMana'; - DECLARE vComponentPort VARCHAR(50) DEFAULT 'delivery'; - DECLARE vComponentMargin VARCHAR(50) DEFAULT 'margin'; - DECLARE vComponentCost VARCHAR(50) DEFAULT 'purchaseValue'; - DECLARE vComponentCostValue DECIMAL(10,2); - DECLARE vItem INT DEFAULT 98; - DECLARE vItemCarryBox INT; - - CALL util.throw('Obsoleto hablar con Informática'); - - SELECT generalInflationCoeFicient, verdnaturaVolumeBox, itemCarryBox - INTO vGeneralInflationCoeficient, vVerdnaturaVolumeBox, vItemCarryBox - FROM bionicConfig; - - SELECT clientFk INTO vClientFk FROM address WHERE id = vAddress; - - -- Creamos la tabla tmp.bionicComponent - DROP TEMPORARY TABLE IF EXISTS tmp.bionicComponent; - CREATE TEMPORARY TABLE tmp.bionicComponent( - `warehouseFk` smallint(5) unsigned NOT NULL, - `itemFk` int(11) NOT NULL, - `componentFk` int(10) unsigned NOT NULL, - `value` decimal(10,4) NOT NULL, - UNIQUE KEY `itemWarehouseComponent` (`itemFk`,`warehouseFk`,`componentFk`) USING HASH, - KEY `itemWarehouse` (`itemFk`,`warehouseFk`) USING BTREE - ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - - -- Margin - INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`) - SELECT vWarehouse, vItem, id, vMargin - FROM component - WHERE code = vComponentMargin; - - -- Recobro - INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`) - SELECT vWarehouse, vItem, c.id, ROUND(LEAST(cr.recobro,0.25), 3) - FROM bi.claims_ratio cr - JOIN component c ON c.code = vComponentRecovery - WHERE cr.Id_Cliente = vClientFk AND cr.recobro > 0.009; - - -- Componente de maná automático, en función del maná acumulado por el comercial. - INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`) - SELECT vWarehouse, vItem, co.id, ROUND(ms.prices_modifier_rate, 3) - FROM client c - JOIN bs.mana_spellers ms ON c.salesPersonFk = ms.Id_Trabajador - JOIN component co ON co.code = vComponentMana - WHERE ms.prices_modifier_activated AND c.id = vClientFk LIMIT 1; - - -- Reparto - INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`) - SELECT vWarehouse, vItem, co.id, vGeneralInflationCoeficient - * ROUND( - vM3 - * az.price - * az.inflation - / vVerdnaturaVolumeBox, 4 - ) - FROM agencyMode ag - JOIN address a ON a.id = vAddress AND ag.id = vAgencyMode - JOIN agencyProvince ap ON ap.agencyFk = ag.agencyFk - AND ap.warehouseFk = vWarehouse AND ap.provinceFk = a.provinceFk - JOIN agencyModeZone az ON az.agencyModeFk = vAgencyMode - AND az.zone = ap.zone AND az.itemFk = 71 AND az.warehouseFk = vWarehouse - JOIN component co ON co.code = vComponentPort; - - -- Coste - SELECT vRetailedPrice - SUM(`value`) INTO vComponentCostValue - FROM tmp.bionicComponent; - - INSERT INTO tmp.bionicComponent (warehouseFk, itemFk, componentFk, `value`) - SELECT vWarehouse, vItem, id,vComponentCostValue - FROM component - WHERE code = vComponentCost; - - RETURN vComponentCostValue; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 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 `botanicExport_isUpdatable` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -44980,8 +41282,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `botanicExport_isUpdatable`(vEdiGenusFk MEDIUMINT,vEdiSpecieFk MEDIUMINT, vCountryFk MEDIUMINT,vRestriction MEDIUMINT) RETURNS int(11) @@ -45001,6 +41301,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `buy_getUnitVolume` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45008,8 +41310,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `buy_getUnitVolume`(vSelf INT) RETURNS int(11) DETERMINISTIC @@ -45036,6 +41336,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `buy_getVolume` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45043,8 +41345,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `buy_getVolume`(vSelf INT) RETURNS int(11) DETERMINISTIC @@ -45069,50 +41369,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 FUNCTION IF EXISTS `buy_hasNotifyPassport__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `buy_hasNotifyPassport__`(vBuyFk INT, vItemFk INT) RETURNS tinyint(1) - READS SQL DATA -BEGIN - DECLARE vHasPassport BOOL; - DECLARE vIsAlreadySent BOOL; - DECLARE vItemCategoryFk INT; - SELECT id INTO vItemCategoryFk FROM itemCategory WHERE code = 'plant'; - - SELECT COUNT(*) INTO vHasPassport - FROM botanicExport be - JOIN itemBotanical ib - ON be.ediGenusFk = ib.genusFk - AND IFNULL(be.ediSpecieFk, ib.specieFk) = ib.specieFk - AND be.`code` = 'phytosanitaryPassport' - JOIN item i ON i.id = ib.itemFk - JOIN itemType it ON it.id = i.typeFk - WHERE ib.itemFk = vItemFk - AND it.categoryFk = vItemCategoryFk; - - IF vHasPassport THEN - SELECT COUNT(*) INTO vIsAlreadySent - FROM mail m - JOIN buy b ON b.id = vBuyFk - WHERE m.`body` LIKE CONCAT('%', b.ektFk, '%') - LIMIT 1; - END IF; - - RETURN vHasPassport AND NOT vIsAlreadySent; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 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 `catalog_componentReverse` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45120,8 +41378,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `catalog_componentReverse`(vWarehouse INT, vCost DECIMAL(10,3), @@ -45169,58 +41425,59 @@ BEGIN INSERT INTO tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) SELECT vWarehouse, vItem, vComponentCost, vCost FROM vn.rate - WHERE dated <= util.VN_CURDATE() + WHERE dated <= vn.VN_CURDATE() AND warehouseFk = vWarehouse ORDER BY dated DESC - LIMIT 1; - - -- Margen - -- No se aplica margen, cau 12589 + LIMIT 1; + + -- Margen + -- No se aplica margen, cau 12589 /* INSERT INTO tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) SELECT vWarehouse, vItem, vComponentMargin, (vCost / ((100 - rate2) / 100)) - vCost FROM vn.rate - WHERE dated <= util.VN_CURDATE() + WHERE dated <= vn.VN_CURDATE() AND warehouseFk = vWarehouse ORDER BY dated DESC - LIMIT 1; - */ - -- Recobro + LIMIT 1; + */ + -- Recobro INSERT INTO tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) SELECT vWarehouse, vItem, vComponentRecovery, ROUND(LEAST(recobro,0.25), 3) FROM bi.claims_ratio WHERE Id_Cliente = vCustomer AND recobro > 0.009; - + -- Componente de maná automático, en función del maná acumulado por el comercial. INSERT INTO tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) - SELECT vWarehouse, vItem, vComponentMana, ROUND(prices_modifier_rate, 3) - FROM client c - JOIN bs.mana_spellers ms ON c.salesPersonFk = ms.Id_Trabajador - WHERE ms.prices_modifier_activated AND c.id = vCustomer LIMIT 1; - + SELECT vWarehouse, vItem, vComponentMana, ROUND(wm.pricesModifierRate, 3) + FROM client c + JOIN vn.workerMana wm ON c.salesPersonFk = wm.workerFk + WHERE wm.isPricesModifierActivated AND c.id = vCustomer LIMIT 1; + -- Reparto INSERT INTO tmp.catalog_component (warehouseFk, itemFk, componentFk, cost) SELECT vWarehouse, vItem, vDeliveryComponent, ROUND( - vM3 + vM3 * (z.price - z.bonus) * z.inflation / vBoxVolume, 4 ) - FROM zone z + FROM zone z WHERE z.id = vZoneFk; - + -- Precio de venta SELECT SUM(cost) INTO vRetailedPrice FROM tmp.catalog_component; - RETURN vRetailedPrice; - + RETURN vRetailedPrice; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `clientGetDebt` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45228,68 +41485,68 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `clientGetDebt`(`vClient` INT, `vDate` DATE) RETURNS decimal(10,2) READS SQL DATA -BEGIN -/** - * Devuelve el saldo de un cliente. - * - * @param vClient Identificador del cliente - * @param vDate Fecha hasta la que tener en cuenta - * @return Saldo del cliente - */ - DECLARE vDateEnd DATETIME; - DECLARE vDateIni DATETIME; - DECLARE vDebt DECIMAL(10,2); - DECLARE vHasDebt BOOLEAN; - - SELECT COUNT(*) INTO vHasDebt - FROM `client` c - WHERE c.id = vClient AND c.typeFk = 'normal'; - - IF NOT vHasDebt THEN - RETURN 0; - END IF; - - SET vDate = IFNULL(vDate, util.VN_CURDATE()); - - SET vDateIni = TIMESTAMPADD(MONTH, -2, util.VN_CURDATE()); - SET vDateEnd = TIMESTAMP(vDate, '23:59:59'); - - SELECT IFNULL(SUM(t.amount), 0) INTO vDebt - FROM ( - SELECT SUM(IFNULL(totalWithVat,0)) amount - FROM ticket - WHERE clientFk = vClient - AND refFk IS NULL - AND shipped BETWEEN vDateIni AND vDateEnd - UNION ALL - SELECT SUM(amountPaid) amount - FROM receipt - WHERE clientFk = vClient - AND payed > vDateEnd - UNION ALL - SELECT SUM(amount) - FROM clientRisk - WHERE clientFk = vClient - UNION ALL - SELECT CAST(-SUM(amount) / 100 AS DECIMAL(10,2)) - FROM hedera.tpvTransaction - WHERE clientFk = vClient - AND receiptFk IS NULL - AND `status` = 'ok' - ) t; - - RETURN vDebt; +BEGIN +/** + * Devuelve el saldo de un cliente. + * + * @param vClient Identificador del cliente + * @param vDate Fecha hasta la que tener en cuenta + * @return Saldo del cliente + */ + DECLARE vDateEnd DATETIME; + DECLARE vDateIni DATETIME; + DECLARE vDebt DECIMAL(10,2); + DECLARE vHasDebt BOOLEAN; + + SELECT COUNT(*) INTO vHasDebt + FROM `client` c + WHERE c.id = vClient AND c.typeFk = 'normal'; + + IF NOT vHasDebt THEN + RETURN 0; + END IF; + + SET vDate = IFNULL(vDate, vn.VN_CURDATE()); + + SET vDateIni = TIMESTAMPADD(MONTH, -2, vn.VN_CURDATE()); + SET vDateEnd = TIMESTAMP(vDate, '23:59:59'); + + SELECT IFNULL(SUM(t.amount), 0) INTO vDebt + FROM ( + SELECT SUM(IFNULL(totalWithVat,0)) amount + FROM ticket + WHERE clientFk = vClient + AND refFk IS NULL + AND shipped BETWEEN vDateIni AND vDateEnd + UNION ALL + SELECT SUM(amountPaid) amount + FROM receipt + WHERE clientFk = vClient + AND payed > vDateEnd + UNION ALL + SELECT SUM(amount) + FROM clientRisk + WHERE clientFk = vClient + UNION ALL + SELECT CAST(-SUM(amount) / 100 AS DECIMAL(10,2)) + FROM hedera.tpvTransaction + WHERE clientFk = vClient + AND receiptFk IS NULL + AND `status` = 'ok' + ) t; + + RETURN vDebt; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `clientGetMana` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45297,8 +41554,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `clientGetMana`(vClient INT) RETURNS decimal(10,2) DETERMINISTIC @@ -45348,7 +41603,7 @@ BEGIN JOIN saleComponent sc on sc.saleFk = s.id WHERE sc.componentFk IN (vManaComponent, vAutoManaComponent) AND t.shipped > vFromDated - AND t.shipped < TIMESTAMPADD(DAY,1,util.VN_CURDATE()) + AND t.shipped < TIMESTAMPADD(DAY,1,vn.VN_CURDATE()) AND a.clientFk = vClient UNION ALL SELECT - amountPaid @@ -45356,7 +41611,7 @@ BEGIN JOIN `client` c ON c.id = r.clientFk WHERE r.bankFk = vManaBank AND r.payed > vFromDated - AND r.payed <= util.VN_CURDATE() + AND r.payed <= vn.VN_CURDATE() AND c.id = vClient UNION ALL SELECT g.amount @@ -45364,7 +41619,7 @@ BEGIN JOIN `client` c ON c.id = g.clientFk WHERE g.greugeTypeFk = vManaGreugeType AND g.shipped > vFromDated - AND g.shipped <= util.VN_CURDATE() + AND g.shipped <= vn.VN_CURDATE() AND c.id = vClient ) sub; RETURN IFNULL(vMana,0); @@ -45374,6 +41629,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `clientGetSalesPerson` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45381,8 +41638,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `clientGetSalesPerson`(vClientFk INT, vDated DATE) RETURNS int(11) DETERMINISTIC @@ -45397,6 +41652,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `clientTaxArea` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45404,8 +41661,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `clientTaxArea`(vClientId INT, vCompanyId INT) RETURNS varchar(25) CHARSET utf8 READS SQL DATA @@ -45445,6 +41700,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `client_getFromPhone` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45452,8 +41709,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `client_getFromPhone`(vPhone VARCHAR(255)) RETURNS int(11) DETERMINISTIC @@ -45481,11 +41736,9 @@ BEGIN WHERE phone = vPhone OR mobile = vPhone UNION - SELECT r.id_cliente - FROM vn2008.Relaciones r - JOIN vn2008.Contactos c ON r.Id_Contacto = c.Id_Contacto - WHERE c.telefono = vPhone - OR c.movil = vPhone; + SELECT clientFk + FROM vn.clientContact + WHERE phone = vPhone; SELECT t.clientFk INTO vClient FROM tClient t @@ -45502,6 +41755,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `client_getSalesPerson` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45509,8 +41764,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `client_getSalesPerson`(vClientFk INT, vDated DATE) RETURNS int(11) DETERMINISTIC @@ -45556,7 +41809,7 @@ BEGIN l: LOOP SELECT workerSubstitute INTO vWorkerSubstituteFk FROM sharingCart - WHERE util.VN_CURDATE() BETWEEN started AND ended + WHERE vn.VN_CURDATE() BETWEEN started AND ended AND workerFk = vSalesPersonFk ORDER BY id LIMIT 1; @@ -45588,6 +41841,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `client_getSalesPersonByTicket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45595,8 +41850,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `client_getSalesPersonByTicket`(vTicketFk INT) RETURNS int(11) DETERMINISTIC @@ -45623,6 +41876,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `client_getSalesPersonCode` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45630,8 +41885,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `client_getSalesPersonCode`(vClientFk INT, vDated DATE) RETURNS varchar(3) CHARSET utf8 DETERMINISTIC @@ -45661,6 +41914,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `client_getSalesPersonCodeByTicket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45668,8 +41923,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `client_getSalesPersonCodeByTicket`(vTicketFk INT) RETURNS varchar(3) CHARSET utf8 DETERMINISTIC @@ -45696,6 +41949,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `collectionExpeditionLacks` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45703,40 +41958,40 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `collectionExpeditionLacks`(vCollectionFk INT) RETURNS varchar(100) CHARSET utf8 COLLATE utf8_unicode_ci DETERMINISTIC -BEGIN - - DECLARE vExpeditionLacks BOOL; - DECLARE vAnswer VARCHAR(100) DEFAULT ''; - - SELECT (COUNT(*) > 0) INTO vExpeditionLacks - FROM vn.ticketCollection tc - LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk - WHERE tc.collectionFk = vCollectionFk - AND ISNULL(e.id); - - IF vExpeditionLacks THEN - - SELECT CONCAT('Colección: ',tc.collectionFk,' Tickets: ' , GROUP_CONCAT(tc.ticketFk) ) INTO vAnswer - FROM vn.ticketCollection tc - LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk - WHERE tc.collectionFk = vCollectionFk - AND ISNULL(e.id); - - END IF; - - RETURN vAnswer; - +BEGIN + + DECLARE vExpeditionLacks BOOL; + DECLARE vAnswer VARCHAR(100) DEFAULT ''; + + SELECT (COUNT(*) > 0) INTO vExpeditionLacks + FROM vn.ticketCollection tc + LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND ISNULL(e.id); + + IF vExpeditionLacks THEN + + SELECT CONCAT('Colección: ',tc.collectionFk,' Tickets: ' , GROUP_CONCAT(tc.ticketFk) ) INTO vAnswer + FROM vn.ticketCollection tc + LEFT JOIN vn.expedition e ON e.ticketFk = tc.ticketFk + WHERE tc.collectionFk = vCollectionFk + AND ISNULL(e.id); + + END IF; + + RETURN vAnswer; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `currentRate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45744,8 +41999,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `currentRate`(vCurrencyFk INT, vDated DATE) RETURNS decimal(10,4) READS SQL DATA @@ -45768,6 +42021,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `deviceProductionUser_accessGranted` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45775,8 +42030,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `deviceProductionUser_accessGranted`(vUserFK INT(10) , android_id VARCHAR(50)) RETURNS tinyint(1) DETERMINISTIC @@ -45809,6 +42062,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `duaTax_getRate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45816,8 +42071,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `duaTax_getRate`(vDua INT, vTaxClass INT) RETURNS decimal(5,2) DETERMINISTIC @@ -45833,10 +42086,11 @@ BEGIN FROM (SELECT taxClassFk, rate FROM invoiceInTaxBookingAccount - WHERE effectived <= util.VN_CURDATE() + WHERE effectived <= vn.VN_CURDATE() AND countryFk = vCountryFk AND taxClassFk = vTaxClass ORDER BY effectived DESC + LIMIT 10000000000000000000 ) ba1 GROUP BY taxClassFk); END ;; @@ -45845,6 +42099,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `ekt_getEntry` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45852,90 +42108,90 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ekt_getEntry`(vEktFk INT) RETURNS int(11) READS SQL DATA -BEGIN - - /** - * Devuelve el numero de entrada para el ekt - * - * @param vEktFk Identificador de edi.ekt - */ - - DECLARE vTravelFk INT; - DECLARE vEntryFk INT DEFAULT 0; - DECLARE vEntryAssignFk INT; - - SET vTravelFk = vn.ekt_getTravel(vEktFk); - - IF vTravelFk THEN - - SELECT ea.id INTO vEntryAssignFk - FROM edi.ekt e - JOIN vn.travel tr ON tr.id = vTravelFk - JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk - AND ea.warehouseInFk = tr.warehouseInFk - AND ea.agencyModeFk = tr.agencyFk - AND IFNULL(ea.sub, e.sub) <=> e.sub - AND IFNULL(ea.kop, e.kop) <=> e.kop - AND IFNULL(ea.pro, e.pro) <=> e.pro - WHERE e.id = vEktFk - ORDER BY ea.sub <=> e.sub AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC, - ea.sub <=> e.sub AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC, - ea.sub <=> e.sub AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC, - ea.sub <=> e.sub AND ISNULL(ea.kop) AND ISNULL(ea.pro) DESC, - ISNULL(ea.sub) AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC, - ISNULL(ea.sub) AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC, - ISNULL(ea.sub) AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC - LIMIT 1; - - SELECT MAX(e.id) INTO vEntryFk - FROM vn.entry e - JOIN vn.ektEntryAssign ea ON ea.id = vEntryAssignFk - WHERE e.travelFk = vTravelFk - AND e.sub <=> ea.sub - AND e.kop <=> ea.kop - AND e.pro <=> ea.pro; - - - IF IFNULL(vEntryFk,0) = 0 THEN - - INSERT INTO vn.entry(travelFk, supplierFk, companyFk, currencyFk, kop, sub, ref, pro) - SELECT vTravelFk, ea.supplierFk, c.id, cu.id, ea.kop, ea.sub, ea.ref, ea.pro - FROM vn.ektEntryAssign ea - JOIN vn.company c ON c.code = 'VNL' - JOIN vn.currency cu ON cu.code = 'EUR' - WHERE ea.id = vEntryAssignFk; - - SELECT MAX(id) INTO vEntryFk - FROM vn.entry - WHERE travelFk = vTravelFk; - - END IF; - - UPDATE vn.ektEntryAssign - SET entryFk = vEntryFk - WHERE id = vEntryAssignFk; - - ELSE - - SELECT ec.defaultEntry INTO vEntryFk - FROM vn.entryConfig ec; - - INSERT IGNORE INTO vn.entry(id) VALUES(vEntryFk); - - END IF; - - RETURN vEntryFk; +BEGIN + + /** + * Devuelve el numero de entrada para el ekt + * + * @param vEktFk Identificador de edi.ekt + */ + + DECLARE vTravelFk INT; + DECLARE vEntryFk INT DEFAULT 0; + DECLARE vEntryAssignFk INT; + + SET vTravelFk = vn.ekt_getTravel(vEktFk); + + IF vTravelFk THEN + + SELECT ea.id INTO vEntryAssignFk + FROM edi.ekt e + JOIN vn.travel tr ON tr.id = vTravelFk + JOIN vn.ektEntryAssign ea ON ea.warehouseOutFk = tr.warehouseOutFk + AND ea.warehouseInFk = tr.warehouseInFk + AND ea.agencyModeFk = tr.agencyFk + AND IFNULL(ea.sub, e.sub) <=> e.sub + AND IFNULL(ea.kop, e.kop) <=> e.kop + AND IFNULL(ea.pro, e.pro) <=> e.pro + WHERE e.id = vEktFk + ORDER BY ea.sub <=> e.sub AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC, + ea.sub <=> e.sub AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC, + ea.sub <=> e.sub AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC, + ea.sub <=> e.sub AND ISNULL(ea.kop) AND ISNULL(ea.pro) DESC, + ISNULL(ea.sub) AND ea.kop <=> e.kop AND ea.pro <=> e.pro DESC, + ISNULL(ea.sub) AND ea.kop <=> e.kop AND ISNULL(ea.pro) DESC, + ISNULL(ea.sub) AND ISNULL(ea.kop) AND ea.pro <=> e.pro DESC + LIMIT 1; + + SELECT MAX(e.id) INTO vEntryFk + FROM vn.entry e + JOIN vn.ektEntryAssign ea ON ea.id = vEntryAssignFk + WHERE e.travelFk = vTravelFk + AND e.sub <=> ea.sub + AND e.kop <=> ea.kop + AND e.pro <=> ea.pro; + + + IF IFNULL(vEntryFk,0) = 0 THEN + + INSERT INTO vn.entry(travelFk, supplierFk, companyFk, currencyFk, kop, sub, ref, pro) + SELECT vTravelFk, ea.supplierFk, c.id, cu.id, ea.kop, ea.sub, ea.ref, ea.pro + FROM vn.ektEntryAssign ea + JOIN vn.company c ON c.code = 'VNL' + JOIN vn.currency cu ON cu.code = 'EUR' + WHERE ea.id = vEntryAssignFk; + + SELECT MAX(id) INTO vEntryFk + FROM vn.entry + WHERE travelFk = vTravelFk; + + END IF; + + UPDATE vn.ektEntryAssign + SET entryFk = vEntryFk + WHERE id = vEntryAssignFk; + + ELSE + + SELECT ec.defaultEntry INTO vEntryFk + FROM vn.entryConfig ec; + + INSERT IGNORE INTO vn.entry(id) VALUES(vEntryFk); + + END IF; + + RETURN vEntryFk; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `ekt_getTravel` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45943,8 +42199,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ekt_getTravel`(vEktFk INT) RETURNS int(11) READS SQL DATA @@ -46035,46 +42289,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 FUNCTION IF EXISTS `entry_calcCommission__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `entry_calcCommission__`(vCurrentCommission INT, - vTravelFk INT, - vCurrencyFk INT -) RETURNS int(11) - READS SQL DATA -BEGIN - -- DEPRECATED: use entry_getComission - DECLARE vCommission INT; - - IF vCurrencyFk != 2 /* Dollar */ THEN - RETURN vCurrentCommission; - END IF; - - SELECT ROUND(-100 * (1 - (1 / r.rate))) INTO vCommission - FROM travel t - LEFT JOIN vn2008.reference_min r - ON r.moneda_id = vCurrencyFk AND r.`date` <= t.shipped - WHERE t.id = vTravelFk - ORDER BY r.`date` DESC - LIMIT 1; - - SET vCommission = IFNULL(vCommission, 0); - - RETURN vCommission; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 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 `entry_getCommission` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46082,10 +42298,9 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `entry_getCommission`(vTravelFk INT, +CREATE DEFINER=`root`@`localhost` FUNCTION `entry_getCommission`( + vTravelFk INT, vCurrencyFk INT, vSupplierFk INT ) RETURNS int(11) @@ -46144,52 +42359,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 FUNCTION IF EXISTS `entry_getCommission__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `entry_getCommission__`(vTravelFk INT, - vCurrencyFk INT, - vSupplierFk INT -) RETURNS int(11) - READS SQL DATA -BEGIN - -- bernat: working in this file - DECLARE vCommission INT; - DECLARE vCurrentCommission INT; - DECLARE vIsCurrencyUsd INT; - - SELECT count(*) INTO vIsCurrencyUsd - FROM currency c - WHERE c.code = 'USD' AND id = vCurrencyFk; - - IF NOT vIsCurrencyUsd THEN - SELECT commission INTO vCurrentCommission - FROM supplier s - WHERE s.id = vSupplierFk; - RETURN vCurrentCommission; - END IF; - - SELECT ROUND(-100 * (1 - (1 / r.rate))) INTO vCommission - FROM travel t - LEFT JOIN vn2008.reference_min r ON r.moneda_id = vCurrencyFk AND r.`date` <= t.shipped - WHERE t.id = vTravelFk - ORDER BY r.`date` DESC - LIMIT 1; - - RETURN IFNULL(vCommission, 0); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `entry_getCurrency` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46197,10 +42368,9 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `entry_getCurrency`(vCurrency INT, +CREATE DEFINER=`root`@`localhost` FUNCTION `entry_getCurrency`( + vCurrency INT, vSupplierFk INT ) RETURNS int(11) READS SQL DATA @@ -46221,6 +42391,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `entry_getForLogiflora` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46228,8 +42400,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `entry_getForLogiflora`(vLanded DATE, vWarehouseFk INT) RETURNS int(11) READS SQL DATA @@ -46292,6 +42462,38 @@ 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP FUNCTION IF EXISTS `entry_isInventoryOrPrevious` */; +/*!50003 SET @saved_cs_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` FUNCTION `entry_isInventoryOrPrevious`(vSelf INT) RETURNS int(11) + DETERMINISTIC +BEGIN + DECLARE vIsInventoryOrPrevious BOOL; + + SELECT ec.inventorySupplierFk = e.supplierFk OR t.landed < c.inventoried + INTO vIsInventoryOrPrevious + FROM entry e + JOIN travel t ON e.travelFk = t.id + JOIN entryConfig ec + JOIN config c + WHERE e.id = vSelf; + + RETURN vIsInventoryOrPrevious; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `expedition_checkRoute` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46299,43 +42501,43 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `expedition_checkRoute`(vPalletFk INT,vExpeditionFk INT) RETURNS tinyint(1) DETERMINISTIC -BEGIN -/** -* Comprueba si las expediciones del pallet son todas -* de la misma ruta. -* -* @param vExpeditionFk numero de expedition a comprobar -* @param vPalletFk numero de pallet -* @return vHasDistinctRoutes -*/ - DECLARE vRouteFk INT; - DECLARE vHasDistinctRoutes BOOL; - - SELECT t.routeFk INTO vRouteFk - FROM vn.expedition e - JOIN vn.ticket t ON e.ticketFk = t.id - WHERE e.id = vExpeditionFk; - - SELECT COUNT(*) > 0 INTO vHasDistinctRoutes - FROM vn.expeditionScan es - JOIN vn.expedition e ON es.expeditionFk = e.id - JOIN vn.ticket t ON e.ticketFk = t.id - WHERE es.palletFk = vPalletFk - AND t.routeFk <> vRouteFk; - - RETURN vHasDistinctRoutes; - +BEGIN +/** +* Comprueba si las expediciones del pallet son todas +* de la misma ruta. +* +* @param vExpeditionFk numero de expedition a comprobar +* @param vPalletFk numero de pallet +* @return vHasDistinctRoutes +*/ + DECLARE vRouteFk INT; + DECLARE vHasDistinctRoutes BOOL; + + SELECT t.routeFk INTO vRouteFk + FROM vn.expedition e + JOIN vn.ticket t ON e.ticketFk = t.id + WHERE e.id = vExpeditionFk; + + SELECT COUNT(*) > 0 INTO vHasDistinctRoutes + FROM vn.expeditionScan es + JOIN vn.expedition e ON es.expeditionFk = e.id + JOIN vn.ticket t ON e.ticketFk = t.id + WHERE es.palletFk = vPalletFk + AND t.routeFk <> vRouteFk; + + RETURN vHasDistinctRoutes; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `firstDayOfWeek` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46343,8 +42545,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `firstDayOfWeek`(vYear INT, vWeek INT) RETURNS date DETERMINISTIC @@ -46372,6 +42572,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `getAlert3State` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46379,8 +42581,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getAlert3State`(vTicket INT) RETURNS varchar(45) CHARSET utf8 COLLATE utf8_unicode_ci READS SQL DATA @@ -46422,6 +42622,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `getAlert3StateTest` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46429,8 +42631,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getAlert3StateTest`(vTicket INT) RETURNS varchar(45) CHARSET latin1 READS SQL DATA @@ -46473,56 +42673,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 FUNCTION IF EXISTS `getAlert3State__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `getAlert3State__`(vTicket INT) RETURNS varchar(45) CHARSET utf8 COLLATE utf8_unicode_ci - READS SQL DATA -BEGIN - DECLARE vDeliveryType INTEGER DEFAULT 0; - DECLARE isWaitingForPickUp BOOLEAN DEFAULT FALSE; - DECLARE vCode VARCHAR(45); - - SELECT a.Vista - INTO vDeliveryType - FROM vn2008.Tickets t - JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia - WHERE Id_Ticket = vTicket; - - CASE vDeliveryType - WHEN 1 THEN -- AGENCIAS - SET vCode = 'DELIVERED'; - - WHEN 2 THEN -- REPARTO - SET vCode = 'ON_DELIVERY'; - - ELSE -- MERCADO, OTROS - SELECT MIN(t.warehouse_id <> w.warehouse_id) INTO isWaitingForPickUp - FROM vn2008.Tickets t - LEFT JOIN vn2008.warehouse_pickup w - ON w.agency_id = t.Id_Agencia - WHERE t.Id_Ticket = vTicket; - - IF isWaitingForPickUp THEN - SET vCode = 'WAITING_FOR_PICKUP'; - ELSE - SET vCode = 'DELIVERED'; - END IF; - END CASE; - RETURN vCode; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `getDueDate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46530,8 +42682,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getDueDate`(vDated DATE, vDayToPay INT) RETURNS date NO SQL @@ -46551,19 +42701,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 FUNCTION IF EXISTS `getEnvironment` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_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 sql_mode = @saved_sql_mode */ ; -/*!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 sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `getInventoryDate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46571,8 +42710,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getInventoryDate`() RETURNS date DETERMINISTIC @@ -46584,6 +42721,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `getNewItemId` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46591,8 +42730,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getNewItemId`() RETURNS int(11) READS SQL DATA @@ -46613,6 +42750,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `getNextDueDate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46620,68 +42759,41 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getNextDueDate`(vDated DATE, vGapDays INT, vPayDay INT) RETURNS date NO SQL -BEGIN - - DECLARE vReturn DATE; - DECLARE vDuaDate DATE; - DECLARE vDuaDateDay INT; - - SELECT TIMESTAMPADD(DAY, vGapDays, vDated) INTO vDuaDate; - - IF vDuaDate = CONCAT(YEAR(vDuaDate), '-03-01') THEN - SET vDuaDate = TIMESTAMPADD (DAY , -1, vDuaDate); - ELSEIF vDuaDate = CONCAT(YEAR(vDuaDate), '-02-29') THEN - SET vDuaDate = TIMESTAMPADD (DAY , -2, vDuaDate); - END IF; - - IF MONTH(vDuaDate) = 2 AND vPayDay = 30 THEN - IF util.isLeapYear(YEAR(vDuaDate)) THEN - SET vPayDay = 29; - ELSE - SET vPayDay = 28; - END IF; - END IF; - - SELECT DAY(vDuaDate) INTO vDuaDateDay; - RETURN TIMESTAMPADD(MONTH, (vDuaDateDay > vPayDay), DATE_FORMAT(vDuaDate, CONCAT('%y/%m/', vPayDay))); +BEGIN + + DECLARE vReturn DATE; + DECLARE vDuaDate DATE; + DECLARE vDuaDateDay INT; + + SELECT TIMESTAMPADD(DAY, vGapDays, vDated) INTO vDuaDate; + + IF vDuaDate = CONCAT(YEAR(vDuaDate), '-03-01') THEN + SET vDuaDate = TIMESTAMPADD (DAY , -1, vDuaDate); + ELSEIF vDuaDate = CONCAT(YEAR(vDuaDate), '-02-29') THEN + SET vDuaDate = TIMESTAMPADD (DAY , -2, vDuaDate); + END IF; + + IF MONTH(vDuaDate) = 2 AND vPayDay = 30 THEN + IF util.isLeapYear(YEAR(vDuaDate)) THEN + SET vPayDay = 29; + ELSE + SET vPayDay = 28; + END IF; + END IF; + + SELECT DAY(vDuaDate) INTO vDuaDateDay; + RETURN TIMESTAMPADD(MONTH, (vDuaDateDay > vPayDay), DATE_FORMAT(vDuaDate, CONCAT('%y/%m/', vPayDay))); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 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 `getPlacementReserve` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `getPlacementReserve`(vItemFk INT, vWarehouseFk INT) RETURNS varchar(25) CHARSET utf8 - READS SQL DATA -BEGIN - DECLARE vPlacementReserve VARCHAR(25); - - SELECT CONCAT(IFNULL(`code`,'--'), ' / ', IFNULL(reserve,'--')) INTO vPlacementReserve - FROM itemPlacement - WHERE itemFk = vItemFk - AND warehouseFk = vWarehouseFk; - - RETURN vPlacementReserve; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 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 `getShipmentHour` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46689,8 +42801,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getShipmentHour`(vTicket INT) RETURNS int(11) READS SQL DATA @@ -46727,6 +42837,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `getSpecialPrice` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46734,8 +42846,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getSpecialPrice`(vItemFk int(11),vClientFk int(11)) RETURNS decimal(10,2) READS SQL DATA @@ -46745,7 +42855,7 @@ BEGIN SELECT rate3 INTO price FROM vn.priceFixed WHERE itemFk = vItemFk - AND util.VN_CURDATE() BETWEEN started AND ended ORDER BY created DESC LIMIT 1; + AND vn.VN_CURDATE() BETWEEN started AND ended ORDER BY created DESC LIMIT 1; SELECT `value` INTO price FROM vn.specialPrice @@ -46758,6 +42868,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `getTicketToPrepare` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46765,8 +42877,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getTicketToPrepare`(`vWorker` INT, `vWarehouse` INT) RETURNS int(11) READS SQL DATA @@ -46782,7 +42892,7 @@ BEGIN * #PENDING REVIEW **/ - DECLARE vToday DATETIME DEFAULT util.VN_CURDATE(); + DECLARE vToday DATETIME DEFAULT vn.VN_CURDATE(); DECLARE vYesterday DATETIME; DECLARE vTodayvMidniight DATETIME DEFAULT midnight(vToday); DECLARE vTicket INT DEFAULT NULL; @@ -46799,10 +42909,10 @@ BEGIN FROM vn.sale s JOIN vn.saleTracking st ON st.saleFk = s.id JOIN vn.ticketStateToday tst ON tst.ticket = s.ticketFk - WHERE st.created > util.VN_CURDATE() + WHERE st.created > vn.VN_CURDATE() -- AND tst.`code` = 'ON_PREPARATION' ) sub ON sub.ticketFk = i.Id_Ticket - WHERE odbc_date > util.VN_CURDATE() + WHERE odbc_date > vn.VN_CURDATE() AND s.`code` = 'ON_PREPARATION' AND i.Id_Trabajador = vWorker AND sub.ticketFk IS NULL @@ -46888,6 +42998,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `getTicketTrolleyLabelCount` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46895,8 +43007,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getTicketTrolleyLabelCount`(vTicket INT) RETURNS int(11) READS SQL DATA @@ -46919,6 +43029,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `getUser` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46926,8 +43038,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getUser`() RETURNS int(11) DETERMINISTIC @@ -46935,13 +43045,15 @@ BEGIN /** * @deprecated Use account.userGetId() */ - RETURN account.userGetId(); + RETURN account.myUser_getId(); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `getUserId` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46949,8 +43061,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getUserId`(userName varchar(30)) RETURNS int(11) READS SQL DATA @@ -46969,6 +43079,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `getWorkerCode` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -46976,8 +43088,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `getWorkerCode`() RETURNS varchar(3) CHARSET utf8 READS SQL DATA @@ -46986,7 +43096,7 @@ BEGIN SELECT code INTO vUserCode FROM worker - WHERE userFk = account.userGetId(); + WHERE userFk = account.myUser_getId(); RETURN vUserCode; END ;; @@ -46995,35 +43105,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 FUNCTION IF EXISTS `getWorker__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `getWorker__`() RETURNS int(11) - DETERMINISTIC -BEGIN -/** - * @deprecated Use myWorker_getId() - */ - DECLARE vUser INT; - - SELECT id INTO vUser - FROM worker - WHERE userFk = account.userGetId(); - - RETURN vUser; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `hasAnyNegativeBase` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47031,8 +43114,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `hasAnyNegativeBase`() RETURNS tinyint(1) DETERMINISTIC @@ -47073,56 +43154,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 FUNCTION IF EXISTS `hasAnyNegativeBase__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `hasAnyNegativeBase__`() RETURNS tinyint(1) - DETERMINISTIC -BEGIN - -/* Calcula si existe alguna base imponible negativa -* Requiere la tabla temporal vn.ticketToInvoice(id) -* -* returns BOOLEAN -*/ - - DECLARE vCountry INT; - DECLARE hasAnyNegativeBase BOOLEAN; - - SELECT s.countryFk - INTO vCountry - FROM supplier s - JOIN ticket t ON t.companyFk = s.id - JOIN vn.ticketToInvoice tl ON tl.id = t.id - LIMIT 1; - - SELECT COUNT(*) INTO hasAnyNegativeBase - FROM ( - SELECT SUM(ROUND(s.quantity * s.price * (100 - s.discount)/100,2)) taxableBase - FROM sale s - JOIN item i ON i.id = s.itemFk - JOIN itemTaxCountry itc - ON itc.itemFk = i.id AND itc.countryFk = vCountry - JOIN vn.ticketToInvoice tl ON tl.id = s.ticketFk - GROUP BY itc.taxClassFk - HAVING taxableBase < 0 - ) t1 ; - - RETURN hasAnyNegativeBase; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `hasItemsInSector` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47130,8 +43163,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `hasItemsInSector`(vTicketFk INT, vSectorFk INT) RETURNS tinyint(1) DETERMINISTIC @@ -47155,6 +43186,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `hasSomeNegativeBase` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47162,8 +43195,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `hasSomeNegativeBase`(vTicket INT) RETURNS tinyint(1) READS SQL DATA @@ -47196,6 +43227,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `invoiceOutAmount` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47203,8 +43236,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `invoiceOutAmount`(vInvoiceRef VARCHAR(15)) RETURNS decimal(10,2) READS SQL DATA @@ -47231,6 +43262,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `invoiceOut_getPath` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47238,8 +43271,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `invoiceOut_getPath`(vSelf INT) RETURNS varchar(255) CHARSET utf8 DETERMINISTIC @@ -47264,6 +43295,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `invoiceSerial` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47271,8 +43304,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `invoiceSerial`(vClientFk INT, vCompanyFk INT, vType CHAR(1)) RETURNS char(1) CHARSET utf8 DETERMINISTIC @@ -47302,6 +43333,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `invoiceSerialArea` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47309,8 +43342,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `invoiceSerialArea`(vType CHAR(1), vTaxArea VARCHAR(25)) RETURNS char(1) CHARSET utf8 COLLATE utf8_unicode_ci DETERMINISTIC @@ -47361,6 +43392,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `isIntrastatEntry` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47368,8 +43401,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `isIntrastatEntry`(vEntryFk INT) RETURNS int(11) READS SQL DATA @@ -47404,6 +43435,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `isLogifloraDay` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47411,30 +43444,30 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `isLogifloraDay`(vShipped DATE, vWarehouse INT) RETURNS tinyint(1) DETERMINISTIC -BEGIN - - DECLARE vIsLogifloraDay BOOLEAN; - - SELECT COUNT(*) INTO vIsLogifloraDay - FROM edi.warehouseFloramondo wf - JOIN vn.floramondoConfig fc - WHERE wf.warehouseFk = vWarehouse - AND vShipped BETWEEN DATE(TIMESTAMPADD(DAY, wf.travellingDays , fc.nextLanded)) - AND DATE(TIMESTAMPADD(DAY, wf.travellingDays + wf.dayRange , fc.nextLanded)); - - RETURN vIsLogifloraDay; - +BEGIN + + DECLARE vIsLogifloraDay BOOLEAN; + + SELECT COUNT(*) INTO vIsLogifloraDay + FROM edi.warehouseFloramondo wf + JOIN vn.floramondoConfig fc + WHERE wf.warehouseFk = vWarehouse + AND vShipped BETWEEN DATE(TIMESTAMPADD(DAY, wf.travellingDays , fc.nextLanded)) + AND DATE(TIMESTAMPADD(DAY, wf.travellingDays + wf.dayRange , fc.nextLanded)); + + RETURN vIsLogifloraDay; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `isPalletHomogeneus` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47442,8 +43475,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `isPalletHomogeneus`(vExpedition INT) RETURNS tinyint(1) READS SQL DATA @@ -47473,6 +43504,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `itemPacking` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47480,8 +43513,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `itemPacking`(vBarcode VARCHAR(22), vWarehouseFk INT) RETURNS int(11) DETERMINISTIC @@ -47526,34 +43557,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 FUNCTION IF EXISTS `itemPlacementGet` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `itemPlacementGet`(vItemFk INT, vWarehouseFk INT) RETURNS varchar(25) CHARSET utf8 - READS SQL DATA -BEGIN - DECLARE vPlacementReserve VARCHAR(25); - - SELECT CONCAT(IFNULL(`code`,'--'), ' / ', IFNULL(reserve,'--')) - INTO vPlacementReserve - FROM itemPlacement - WHERE itemFk = vItemFk - AND warehouseFk = vWarehouseFk; - - RETURN vPlacementReserve; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 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 `itemShelvingPlacementSupply_ClosestGet` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47561,8 +43566,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `itemShelvingPlacementSupply_ClosestGet`(vParkingFk INT) RETURNS int(11) READS SQL DATA @@ -47598,6 +43601,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `itemsInSector_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47605,8 +43610,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `itemsInSector_get`(vTicketFk INT, vSectorFk INT) RETURNS int(11) READS SQL DATA @@ -47630,6 +43633,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `itemTag_getIntValue` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47637,8 +43642,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `itemTag_getIntValue`(vValue VARCHAR(255)) RETURNS int(11) DETERMINISTIC @@ -47654,6 +43657,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `item_getFhImage` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47661,28 +43666,28 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `item_getFhImage`(itemFk INT) RETURNS varchar(255) CHARSET utf8 COLLATE utf8_unicode_ci DETERMINISTIC -BEGIN - DECLARE vImageUrl VARCHAR(255); - SELECT sr.PictureReference INTO vImageUrl - FROM vn.buy b - JOIN edi.ekt e ON b.ektFk = e.id - JOIN edi.supplyResponse sr ON sr.Item_ArticleCode =e.`ref` - JOIN vn.item i ON i.id = b.itemFk - WHERE b.itemFk = itemFk - ORDER BY (sr.EmbalageCode = e.package) DESC - LIMIT 1; - RETURN vImageUrl; +BEGIN + DECLARE vImageUrl VARCHAR(255); + SELECT sr.PictureReference INTO vImageUrl + FROM vn.buy b + JOIN edi.ekt e ON b.ektFk = e.id + JOIN edi.supplyResponse sr ON sr.Item_ArticleCode =e.`ref` + JOIN vn.item i ON i.id = b.itemFk + WHERE b.itemFk = itemFk + ORDER BY (sr.EmbalageCode = e.package) DESC + LIMIT 1; + RETURN vImageUrl; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `item_getPackage` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47690,41 +43695,41 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `item_getPackage`(vItemFk INT) RETURNS varchar(50) CHARSET utf8 COLLATE utf8_unicode_ci DETERMINISTIC -BEGIN - - DECLARE vDiameter INT; - DECLARE vPackageFk VARCHAR(50); - DECLARE vCoeficient DOUBLE DEFAULT 1.08; - - SELECT MAX(LEFT(value,3)) INTO vDiameter - FROM vn.itemTag it - JOIN vn.tag t ON t.id = it.tagFk - WHERE it.itemFk = vItemFk - AND t.overwrite = 'diameter'; - - SELECT 8000 + FLOOR(vc.ccLength * vc.ccWidth / (vCoeficient * PI() * (vDiameter / 2) * (vDiameter / 2))) - INTO vPackageFk - FROM vn.volumeConfig vc; - - INSERT IGNORE INTO vn.packaging(id, width, `depth`) - SELECT vPackageFk, - FLOOR(vc.ccWidth / FLOOR(vc.ccWidth / vDiameter)), - FLOOR(vc.ccLength / FLOOR(vc.ccLength / vDiameter)) - FROM vn.volumeConfig vc; - - RETURN vPackageFk; - +BEGIN + + DECLARE vDiameter INT; + DECLARE vPackageFk VARCHAR(50); + DECLARE vCoeficient DOUBLE DEFAULT 1.08; + + SELECT MAX(LEFT(value,3)) INTO vDiameter + FROM vn.itemTag it + JOIN vn.tag t ON t.id = it.tagFk + WHERE it.itemFk = vItemFk + AND t.overwrite = 'diameter'; + + SELECT 8000 + FLOOR(vc.ccLength * vc.ccWidth / (vCoeficient * PI() * (vDiameter / 2) * (vDiameter / 2))) + INTO vPackageFk + FROM vn.volumeConfig vc; + + INSERT IGNORE INTO vn.packaging(id, width, `depth`) + SELECT vPackageFk, + FLOOR(vc.ccWidth / FLOOR(vc.ccWidth / vDiameter)), + FLOOR(vc.ccLength / FLOOR(vc.ccLength / vDiameter)) + FROM vn.volumeConfig vc; + + RETURN vPackageFk; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `item_getVolume` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47732,8 +43737,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `item_getVolume`(vSelf INT, vPackaging VARCHAR(10)) RETURNS int(11) DETERMINISTIC @@ -47764,6 +43767,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `lastDayOfWeek` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47771,8 +43776,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `lastDayOfWeek`(vYear INT, vWeek INT) RETURNS date DETERMINISTIC @@ -47800,41 +43803,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 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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` 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,util.VN_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 */ ; @@ -47842,34 +43812,34 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` 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; +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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `messageSend` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47877,8 +43847,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `messageSend`(vRecipient VARCHAR(255) CHARSET utf8, vMessage TEXT CHARSET utf8) RETURNS int(11) READS SQL DATA @@ -47887,7 +43855,7 @@ BEGIN DECLARE vSenderFk INT; SELECT id INTO vSenderFk - FROM account.user WHERE `name` = account.userGetName(); + FROM account.user WHERE `name` = account.myUser_getName(); RETURN (SELECT messageSendWithUser(vSenderFk, vRecipient, vMessage)); END ;; @@ -47896,6 +43864,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `messageSendWithUser` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47903,8 +43873,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `messageSendWithUser`(vSenderFK INT, vRecipient VARCHAR(255) CHARSET utf8, vMessage TEXT CHARSET utf8) RETURNS int(11) DETERMINISTIC @@ -47912,7 +43880,7 @@ BEGIN DECLARE vCount INT; DECLARE vUuid VARCHAR(255); - DECLARE vSendDate DATETIME DEFAULT util.VN_NOW(); + DECLARE vSendDate DATETIME DEFAULT vn.VN_NOW(); DECLARE vSender VARCHAR(255) CHARSET utf8; SELECT `name` INTO vSender @@ -47961,6 +43929,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `MIDNIGHT` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -47968,8 +43938,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `MIDNIGHT`(vDate DATE) RETURNS datetime DETERMINISTIC @@ -47981,38 +43949,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 FUNCTION IF EXISTS `myWorker_getId__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `myWorker_getId__`() RETURNS int(11) - DETERMINISTIC -BEGIN -/** - * Returns the current worker id or the default worker id - * if current user cannot be retrieved. - * - * @return The worker id - */ - DECLARE vWorker INT; - - SELECT w.id INTO vWorker - FROM worker w, workerConfig__ c - WHERE w.userFk = account.userGetId(); - - RETURN vWorker; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `nz` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48020,8 +43958,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `nz`(vQuantity DOUBLE) RETURNS double DETERMINISTIC @@ -48039,6 +43975,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `orderTotalVolume` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48046,8 +43984,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `orderTotalVolume`(vOrderId INT) RETURNS decimal(10,3) READS SQL DATA @@ -48070,6 +44006,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `orderTotalVolumeBoxes` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48077,8 +44015,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `orderTotalVolumeBoxes`(vOrderId INT) RETURNS decimal(10,3) READS SQL DATA @@ -48106,6 +44042,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `phytoPassport` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48113,8 +44051,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `phytoPassport`(vRef VARCHAR(15)) RETURNS text CHARSET utf8 DETERMINISTIC @@ -48161,6 +44097,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `routeProposal` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48168,8 +44106,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `routeProposal`(vTicketFk INT) RETURNS int(11) READS SQL DATA @@ -48227,6 +44163,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `routeProposal_` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48234,8 +44172,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `routeProposal_`(vTicketFk INT) RETURNS int(11) READS SQL DATA @@ -48268,6 +44204,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `routeProposal_beta` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48275,8 +44213,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `routeProposal_beta`(vTicketFk INT) RETURNS int(11) READS SQL DATA @@ -48334,6 +44270,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `specie_IsForbidden` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48341,38 +44279,38 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` 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); - +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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `testCIF` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48380,8 +44318,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `testCIF`(vCIF VARCHAR(9)) RETURNS varchar(10) CHARSET utf8 COLLATE utf8_unicode_ci DETERMINISTIC @@ -48458,6 +44394,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `testNIE` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48465,66 +44403,66 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` 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; - +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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `testNIF` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48532,40 +44470,40 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` 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; - +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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `ticketGetTotal` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48573,8 +44511,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticketGetTotal`(vTicketId INT) RETURNS decimal(10,2) READS SQL DATA @@ -48609,6 +44545,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `ticketPositionInPath` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48616,90 +44554,90 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticketPositionInPath`(vTicketId INT) RETURNS varchar(10) CHARSET utf8 DETERMINISTIC -BEGIN - - DECLARE vRestTicketsMaxOrder INT; - DECLARE vRestTicketsMinOrder INT; - DECLARE vRestTicketsPacking INT; - DECLARE vMyProductionOrder INT; - DECLARE vPosition VARCHAR(10) DEFAULT 'MID'; - DECLARE vMyPath INT; - DECLARE vMyWarehouse INT; - DECLARE PACKING_ORDER INT; - DECLARE vExpeditionsCount INT; - DECLARE vIsValenciaPath BOOLEAN DEFAULT FALSE; - -SELECT `order` - INTO PACKING_ORDER - FROM state - WHERE code = 'PACKING'; - -SELECT t.routeFk, t.warehouseFk, IFNULL(ts.productionOrder,0) - INTO vMyPath, vMyWarehouse, vMyProductionOrder - FROM ticket t - LEFT JOIN ticketState ts on ts.ticket = t.id - WHERE t.id = vTicketId; - -SELECT (ag.`name` = 'VN_VALENCIA') - INTO vIsValenciaPath - FROM vn2008.Rutas r - JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia - JOIN vn2008.agency ag on ag.agency_id = a.agency_id - WHERE r.Id_Ruta = vMyPath; - -IF vIsValenciaPath THEN -- Rutas Valencia - - SELECT COUNT(*) - INTO vExpeditionsCount - FROM expedition e - JOIN ticket t ON t.id = e.ticketFk - WHERE t.routeFk = vMyPath; - - SELECT MAX(ts.productionOrder), MIN(ts.productionOrder) - INTO vRestTicketsMaxOrder, vRestTicketsMinOrder - FROM ticket t - LEFT JOIN ticketState ts on t.id = ts.ticket - WHERE t.routeFk = vMyPath - AND t.warehouseFk = vMyWarehouse - AND t.id != vTicketid; - - SELECT COUNT(*) - INTO vRestTicketsPacking - FROM ticket t - LEFT JOIN ticketState ts on t.id = ts.ticket - WHERE ts.productionOrder = PACKING_ORDER - AND t.routeFk = vMyPath - AND t.warehouseFk = vMyWarehouse - AND t.id != vTicketid; - - IF vExpeditionsCount = 1 THEN - SET vPosition = 'FIRST'; - ELSEIF vRestTicketsMinOrder > PACKING_ORDER THEN - SET vPosition = 'LAST'; - ELSEIF vRestTicketsPacking THEN - SET vPosition = 'SHARED'; - ELSE - SET vPosition = 'MID'; - END IF; - -ELSE - SET vPosition = 'MID'; - -END IF; - -RETURN vPosition; - +BEGIN + + DECLARE vRestTicketsMaxOrder INT; + DECLARE vRestTicketsMinOrder INT; + DECLARE vRestTicketsPacking INT; + DECLARE vMyProductionOrder INT; + DECLARE vPosition VARCHAR(10) DEFAULT 'MID'; + DECLARE vMyPath INT; + DECLARE vMyWarehouse INT; + DECLARE PACKING_ORDER INT; + DECLARE vExpeditionsCount INT; + DECLARE vIsValenciaPath BOOLEAN DEFAULT FALSE; + +SELECT `order` + INTO PACKING_ORDER + FROM state + WHERE code = 'PACKING'; + +SELECT t.routeFk, t.warehouseFk, IFNULL(ts.productionOrder,0) + INTO vMyPath, vMyWarehouse, vMyProductionOrder + FROM ticket t + LEFT JOIN ticketState ts on ts.ticket = t.id + WHERE t.id = vTicketId; + +SELECT (ag.`name` = 'VN_VALENCIA') + INTO vIsValenciaPath + FROM vn2008.Rutas r + JOIN vn2008.Agencias a on a.Id_Agencia = r.Id_Agencia + JOIN vn2008.agency ag on ag.agency_id = a.agency_id + WHERE r.Id_Ruta = vMyPath; + +IF vIsValenciaPath THEN -- Rutas Valencia + + SELECT COUNT(*) + INTO vExpeditionsCount + FROM expedition e + JOIN ticket t ON t.id = e.ticketFk + WHERE t.routeFk = vMyPath; + + SELECT MAX(ts.productionOrder), MIN(ts.productionOrder) + INTO vRestTicketsMaxOrder, vRestTicketsMinOrder + FROM ticket t + LEFT JOIN ticketState ts on t.id = ts.ticket + WHERE t.routeFk = vMyPath + AND t.warehouseFk = vMyWarehouse + AND t.id != vTicketid; + + SELECT COUNT(*) + INTO vRestTicketsPacking + FROM ticket t + LEFT JOIN ticketState ts on t.id = ts.ticket + WHERE ts.productionOrder = PACKING_ORDER + AND t.routeFk = vMyPath + AND t.warehouseFk = vMyWarehouse + AND t.id != vTicketid; + + IF vExpeditionsCount = 1 THEN + SET vPosition = 'FIRST'; + ELSEIF vRestTicketsMinOrder > PACKING_ORDER THEN + SET vPosition = 'LAST'; + ELSEIF vRestTicketsPacking THEN + SET vPosition = 'SHARED'; + ELSE + SET vPosition = 'MID'; + END IF; + +ELSE + SET vPosition = 'MID'; + +END IF; + +RETURN vPosition; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `ticketSplitCounter` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48707,18 +44645,16 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticketSplitCounter`(vTicketFk INT) RETURNS varchar(15) CHARSET utf8 READS SQL DATA BEGIN DECLARE vSplitCounter VARCHAR(15); - SELECT CONCAT(OK,'/',Total, IF(OK = Total ,' LS','')) INTO vSplitCounter + SELECT CONCAT(printedStickers,'/',Total, IF(printedStickers = Total ,' LS','')) INTO vSplitCounter FROM ( - SELECT count(l.Id_Movimiento) as OK, COUNT(*) as Total + SELECT count(l.Id_Movimiento) as printedStickers, COUNT(*) as Total FROM vn.sale s LEFT JOIN vn2008.movement_label l ON l.Id_Movimiento = s.id WHERE ticketFk = vTicketFk @@ -48732,6 +44668,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `ticketTotalVolume` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48739,8 +44677,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticketTotalVolume`(vTicketId INT) RETURNS decimal(10,3) READS SQL DATA @@ -48760,6 +44696,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `ticketTotalVolumeBoxes` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48767,8 +44705,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticketTotalVolumeBoxes`(vTicketId INT) RETURNS decimal(10,1) DETERMINISTIC @@ -48797,6 +44733,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `ticketWarehouseGet` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48804,8 +44742,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticketWarehouseGet`(vTicketFk INT) RETURNS int(11) READS SQL DATA @@ -48823,6 +44759,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `ticket_CC_volume` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48830,32 +44768,32 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_CC_volume`(vTicketFk INT) RETURNS decimal(10,1) READS SQL DATA -BEGIN - - DECLARE vCC DECIMAL(10,1); - - SELECT sum(sv.volume * IF(i.itemPackingTypeFk = 'H', vc.dutchCompressionRate, 1)) / (p.volume / 1000000) - INTO vCC - FROM vn.saleVolume sv - JOIN vn.sale s ON s.id = sv.saleFk - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.packaging p ON p.id = 'CC' - JOIN vn.volumeConfig vc - WHERE sv.ticketFk = vTicketFk; - - RETURN vCC; - +BEGIN + + DECLARE vCC DECIMAL(10,1); + + SELECT sum(sv.volume * IF(i.itemPackingTypeFk = 'H', vc.dutchCompressionRate, 1)) / (p.volume / 1000000) + INTO vCC + FROM vn.saleVolume sv + JOIN vn.sale s ON s.id = sv.saleFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.packaging p ON p.id = 'CC' + JOIN vn.volumeConfig vc + WHERE sv.ticketFk = vTicketFk; + + RETURN vCC; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `ticket_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48863,8 +44801,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_get`(vParamFk INT) RETURNS int(11) READS SQL DATA @@ -48884,7 +44820,7 @@ proc:BEGIN JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id JOIN vn.saleGroup sg ON sg.id = sgd.saleGroupFk WHERE sg.id = vParamFk - AND sg.created > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()) + AND sg.created > TIMESTAMPADD(WEEK,-1, vn.VN_CURDATE()) LIMIT 1; IF vValidFk THEN @@ -48899,7 +44835,7 @@ proc:BEGIN SELECT c.id INTO vValidFk FROM vn.collection c WHERE c.id = vParamFk - AND c.created > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()); + AND c.created > TIMESTAMPADD(WEEK,-1, vn.VN_CURDATE()); IF vValidFk THEN @@ -48913,7 +44849,7 @@ proc:BEGIN SELECT t.id INTO vValidFk FROM vn.ticket t WHERE t.id = vParamFk - AND t.shipped > TIMESTAMPADD(WEEK,-1, util.VN_CURDATE()); + AND t.shipped > TIMESTAMPADD(WEEK,-1, vn.VN_CURDATE()); IF vValidFk THEN @@ -48931,6 +44867,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `ticket_getFreightCost` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48938,8 +44876,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_getFreightCost`(vTicketFk INT) RETURNS decimal(10,2) DETERMINISTIC @@ -48971,6 +44907,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `ticket_getWeight` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48978,32 +44916,32 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_getWeight`(vTicketFk INT) RETURNS decimal(10,3) READS SQL DATA -BEGIN -/** - * Devuelve el peso total del ticket - * - * @return Total peso - */ - - DECLARE vWeight DECIMAL(10,3); - - SELECT sum(weight) INTO vWeight - FROM saleVolume - WHERE ticketFk = vTicketFk; - - RETURN vWeight; - +BEGIN +/** + * Devuelve el peso total del ticket + * + * @return Total peso + */ + + DECLARE vWeight DECIMAL(10,3); + + SELECT sum(weight) INTO vWeight + FROM saleVolume + WHERE ticketFk = vTicketFk; + + RETURN vWeight; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `ticket_getWithParameters` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49011,8 +44949,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_getWithParameters`(vClientFk INT, vWarehouseFk INT, vShipped DATE, vAddressFk INT, vCompanyFk INT, vAgencyModeFk INT) RETURNS int(11) DETERMINISTIC @@ -49043,7 +44979,7 @@ BEGIN IF vTicket IS NULL THEN CALL vn.ticket_add( vClientFk, - IFNULL(vShipped, util.VN_CURDATE()), + IFNULL(vShipped, vn.VN_CURDATE()), vWarehouseFk, vCompanyFk, vAddressFk, @@ -49063,6 +44999,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `ticket_HasUbication` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49070,29 +45008,29 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `ticket_HasUbication`(vTicketFk INT) RETURNS tinyint(1) READS SQL DATA -BEGIN - - DECLARE hasUbication BOOL; - - SELECT COUNT(*) INTO hasUbication - FROM vn.ticket t - JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk - WHERE rm.beachFk - AND t.id = vTicketFk; - - RETURN hasUbication; - +BEGIN + + DECLARE hasUbication BOOL; + + SELECT COUNT(*) INTO hasUbication + FROM vn.ticket t + JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk + WHERE rm.beachFk + AND t.id = vTicketFk; + + RETURN hasUbication; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `till_new` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49100,10 +45038,9 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `till_new`(vClient INT +CREATE DEFINER=`root`@`localhost` FUNCTION `till_new`( + vClient INT ,vBank INT ,vAmount DOUBLE ,vConcept VARCHAR(25) @@ -49184,6 +45121,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `timeWorkerControl_getDirection` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49191,8 +45130,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `timeWorkerControl_getDirection`(vUserFk INT, vTimed DATETIME) RETURNS varchar(6) CHARSET utf8 COLLATE utf8_unicode_ci READS SQL DATA @@ -49260,6 +45197,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `time_getSalesYear` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49267,8 +45206,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `time_getSalesYear`(vMonth INT, vYear INT) RETURNS int(11) DETERMINISTIC @@ -49285,6 +45222,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `travel_getForLogiflora` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49292,8 +45231,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `travel_getForLogiflora`(vLanded DATE, vWarehouseFk INT) RETURNS int(11) READS SQL DATA @@ -49324,7 +45261,7 @@ BEGIN IF NOT vTravelFk THEN INSERT INTO vn.travel(landed, shipped, warehouseInFk, warehouseOutFk, agencyFk) - SELECT vLanded, util.VN_CURDATE(), vWarehouseFk, wOut.id, am.id + SELECT vLanded, vn.VN_CURDATE(), vWarehouseFk, wOut.id, am.id FROM vn.warehouse wOut JOIN vn.agencyMode am ON am.name = 'LOGIFLORA' WHERE wOut.name = 'Holanda'; @@ -49348,6 +45285,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `validationCode` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49355,8 +45294,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `validationCode`(vString VARCHAR(255)) RETURNS int(11) DETERMINISTIC @@ -49389,6 +45326,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `validationCode_beta` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49396,8 +45335,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `validationCode_beta`(vString VARCHAR(255)) RETURNS int(11) DETERMINISTIC @@ -49430,45 +45367,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 FUNCTION IF EXISTS `VN_CURDATE` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_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 sql_mode = @saved_sql_mode */ ; -/*!50003 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 `VN_CURTIME` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_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 sql_mode = @saved_sql_mode */ ; -/*!50003 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 `VN_NOW` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_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 sql_mode = @saved_sql_mode */ ; -/*!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 sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `workerIsBoss` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49476,8 +45376,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `workerIsBoss`(vUserId INT) RETURNS int(11) DETERMINISTIC @@ -49528,6 +45426,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `workerMachinery_isRegistered` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49535,35 +45435,35 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `workerMachinery_isRegistered`(vWorkerFk VARCHAR(10)) RETURNS tinyint(1) READS SQL DATA -BEGIN -/** - * Comprueba si existen registros en las últimas horas (maxHours de machineWorkerConfig) 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 TRUE/FALSE en caso de que haya o no registros - */ - - IF (SELECT COUNT(*) - FROM machineWorker m - WHERE m.workerFk = vWorkerFk - AND m.inTimed >= TIMESTAMPADD(HOUR , -(SELECT maxHours from machineWorkerConfig), util.VN_NOW()) AND ISNULL(m.outTimed)) - THEN - RETURN TRUE; - ELSE - RETURN FALSE; - END IF; - +BEGIN +/** + * Comprueba si existen registros en las últimas horas (maxHours de machineWorkerConfig) 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 TRUE/FALSE en caso de que haya o no registros + */ + + IF (SELECT COUNT(*) + FROM machineWorker m + WHERE m.workerFk = vWorkerFk + AND m.inTimed >= TIMESTAMPADD(HOUR , -(SELECT maxHours from machineWorkerConfig), vn.VN_NOW()) AND ISNULL(m.outTimed)) + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `workerNigthlyHours_calculate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49571,8 +45471,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `workerNigthlyHours_calculate`(vTimeIn DATETIME, vTimeOut DATETIME) RETURNS decimal(5,2) READS SQL DATA @@ -49603,6 +45501,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `workerTimeControl_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49610,10 +45510,8 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `workerTimeControl_add`(vUserFk INT, vWarehouseFk INT, vTimed DATETIME, vIsManual BOOL) RETURNS int(11) +CREATE DEFINER=`root`@`localhost` FUNCTION `workerTimeControl_add`( vUserFk INT, vWarehouseFk INT, vTimed DATETIME, vIsManual BOOL) RETURNS int(11) DETERMINISTIC BEGIN DECLARE vDirection VARCHAR(6); @@ -49672,6 +45570,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `workerTimeControl_addDirection` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49679,10 +45579,8 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `workerTimeControl_addDirection`(vUserFk INT, vWarehouseFk INT, vTimed DATETIME, vIsManual BOOL) RETURNS int(11) +CREATE DEFINER=`root`@`localhost` FUNCTION `workerTimeControl_addDirection`( vUserFk INT, vWarehouseFk INT, vTimed DATETIME, vIsManual BOOL) RETURNS int(11) DETERMINISTIC BEGIN DECLARE vDirection VARCHAR(6); @@ -49741,6 +45639,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `worker_isWorking` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49748,8 +45648,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `worker_isWorking`(vWorkerFk INT) RETURNS tinyint(1) READS SQL DATA @@ -49780,6 +45678,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `xdiario_new` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49787,10 +45687,9 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` FUNCTION `xdiario_new`(vAsiento INT, +CREATE DEFINER=`root`@`localhost` FUNCTION `xdiario_new`( + vAsiento INT, vDated DATE, vSubaccount VARCHAR(12), vAccount VARCHAR(12), @@ -49835,6 +45734,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP FUNCTION IF EXISTS `zoneGeo_new` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49842,8 +45743,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` FUNCTION `zoneGeo_new`(vType VARCHAR(255), vName VARCHAR(255), vParentFk INT) RETURNS int(11) NO SQL @@ -49875,6 +45774,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `addNoteFromDelivery` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49882,8 +45783,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `addNoteFromDelivery`(idTicket INT,nota TEXT) BEGIN @@ -49901,6 +45800,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `addressTaxArea` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49908,8 +45809,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `addressTaxArea`() READS SQL DATA @@ -49949,6 +45848,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `agencyHourGetFirstShipped` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -49956,8 +45857,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `agencyHourGetFirstShipped`(vAgencyMode INT, vAddress INT, vWarehouse INT) BEGIN @@ -49972,7 +45871,7 @@ BEGIN */ DECLARE vAgency INT; DECLARE vShipped DATE; -DECLARE vLanded DATE DEFAULT util.VN_CURDATE(); +DECLARE vLanded DATE DEFAULT vn.VN_CURDATE(); SELECT agencyFk INTO vAgency FROM agencyMode WHERE id= vAgencyMode; l: LOOP @@ -49997,6 +45896,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `agencyHourGetLanded` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50004,8 +45905,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `agencyHourGetLanded`(vDated DATE, vAddress INT, vAgency INT, vWarehouse INT) BEGIN @@ -50039,7 +45938,7 @@ BEGIN ) t LIMIT 1 ) t - WHERE IF(vDated = util.VN_CURDATE(), t.maxHour > HOUR(util.VN_NOW()), TRUE) AND t.substractDay < 225; + WHERE IF(vDated = vn.VN_CURDATE(), t.maxHour > HOUR(vn.VN_NOW()), TRUE) AND t.substractDay < 225; END ;; DELIMITER ; @@ -50047,6 +45946,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `agencyHourGetWarehouse` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50054,8 +45955,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `agencyHourGetWarehouse`(vAddress INT, vDate DATE, vWarehouse INT) BEGIN @@ -50115,8 +46014,8 @@ BEGIN AND (ah.provinceFk = a.provinceFk OR ah.provinceFk IS NULL OR vAddress IS NULL) - AND TIMESTAMPADD(DAY, -ah.substractDay, vDate) >= util.VN_CURDATE() - AND IF(TIMESTAMPADD(DAY, -ah.substractDay, vDate) = util.VN_CURDATE(), ah.maxHour > HOUR(util.VN_NOW()), TRUE) + AND TIMESTAMPADD(DAY, -ah.substractDay, vDate) >= vn.VN_CURDATE() + AND IF(TIMESTAMPADD(DAY, -ah.substractDay, vDate) = vn.VN_CURDATE(), ah.maxHour > HOUR(vn.VN_NOW()), TRUE) ORDER BY ( (ah.weekDay IS NOT NULL) + (ah.agencyFk IS NOT NULL) + @@ -50138,6 +46037,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `agencyHourListGetShipped` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50145,8 +46046,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `agencyHourListGetShipped`(vDate DATE, vAddress INT, vAgency INT) BEGIN @@ -50164,40 +46063,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 `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 = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `agencyVolume__`(vDated DATE, vAgency INT) -BEGIN - - SELECT ELT(it.temperature + 1,'Calientes','Frios','Secos') AS Temp, - 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 carros , - 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 - FROM vn.buy b - INNER JOIN vn.entry e ON e.id = b.entryFk - INNER JOIN vn.travel tr ON tr.id = e.travelFk - INNER JOIN vn.volumeConfig vc - INNER JOIN vn.item i ON i.id = b.itemFk - INNER JOIN vn.itemType it ON it.id = i.typeFk - WHERE tr.landed = vDated - AND tr.agencyFk IN (0, vAgency) - 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 `available_calc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50205,8 +46072,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `available_calc`( vDate DATE, @@ -50268,76 +46133,40 @@ 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 `available_calc__` */; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `bankEntity_checkBic` */; /*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `available_calc__`( - vDate DATE, - vAddress INT, - vAgencyMode INT) +CREATE DEFINER=`root`@`localhost` PROCEDURE `bankEntity_checkBic`(vBic VARCHAR(255)) BEGIN -/** - * Calculates the available for all available stores - * according to the given parameters. - * - * @param vDate The delivery date - * @param vAddress The delivery address id - * @param vAgencyMode The shipping agency - * @return tmp.availableCalc(calcFk) The available cache ids - */ - DECLARE vCalcFk INT; - DECLARE vShipment DATE; - DECLARE vWarehouse INT; - DECLARE vDone BOOL; + /** + * If the bic length is Incorrect throw exception + * + * @param vBic bic code + */ - DECLARE cWarehouses CURSOR FOR - SELECT warehouseFk, shipped FROM tmp.zoneGetShipped; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; + DECLARE vConfigBicLenght INT; - -- Establecemos los almacenes y las fechas que van a entrar al disponible - - CALL vn.zone_getShippedWarehouse(vDate, vAddress, vAgencyMode); - - DROP TEMPORARY TABLE IF EXISTS tmp.availableCalc; - CREATE TEMPORARY TABLE tmp.availableCalc( - calcFk INT UNSIGNED, - PRIMARY KEY (calcFk) - ) - ENGINE = MEMORY; - - OPEN cWarehouses; - - l: LOOP - SET vDone = FALSE; - FETCH cWarehouses INTO vWarehouse, vShipment; - - IF vDone THEN - LEAVE l; - END IF; - - CALL `cache`.available_refresh(vCalcFk, FALSE, vWarehouse, vShipment); - - INSERT IGNORE INTO tmp.availableCalc - SET calcFk = vCalcFk; - END LOOP; - - CLOSE cWarehouses; - DROP TEMPORARY TABLE tmp.zoneGetShipped; + SELECT bicLength INTO vConfigBicLenght + FROM vn.bankEntityConfig bec; + + IF LENGTH(vBic) <> vConfigBicLenght THEN + CALL util.throw(CONCAT('bic must be of length ', vConfigBicLenght )); + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `bankPolicy_notifyExpired` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50345,8 +46174,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `bankPolicy_notifyExpired`() BEGIN @@ -50366,13 +46193,15 @@ BEGIN ON s.id = bp.supplierFk LEFT JOIN vn.bank b ON b.id = bp.bankFk - WHERE bp.insuranceExpired = util.VN_CURDATE(); + WHERE bp.insuranceExpired = vn.VN_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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `buyUltimate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50380,49 +46209,49 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buyUltimate`(vWarehouseFk SMALLINT, vDated DATE) -BEGIN -/** - * Calcula las últimas compras realizadas hasta una fecha - * - * @param vWarehouseFk Id del almacén - * @param vDated Compras hasta fecha - * @return tmp.buyUltimate - */ - CALL cache.last_buy_refresh (FALSE); - - DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate; - CREATE TEMPORARY TABLE tmp.buyUltimate - (PRIMARY KEY (itemFk, warehouseFk), - INDEX(itemFk)) - ENGINE = MEMORY - SELECT item_id itemFk, buy_id buyFk, warehouse_id warehouseFk, landing - FROM cache.last_buy - WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL; - - CALL buyUltimateFromInterval(vWarehouseFk, util.VN_CURDATE(), vDated); - - REPLACE INTO tmp.buyUltimate - SELECT itemFk, buyFk, warehouseFk, landed landing - FROM tmp.buyUltimateFromInterval - WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) - AND landed <= vDated; - - INSERT IGNORE INTO tmp.buyUltimate - SELECT itemFk, buyFk, warehouseFk, landed landing - FROM tmp.buyUltimateFromInterval - WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) - AND landed > vDated; - +BEGIN +/** + * Calcula las últimas compras realizadas hasta una fecha + * + * @param vWarehouseFk Id del almacén + * @param vDated Compras hasta fecha + * @return tmp.buyUltimate + */ + CALL cache.last_buy_refresh (FALSE); + + DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate; + CREATE TEMPORARY TABLE tmp.buyUltimate + (PRIMARY KEY (itemFk, warehouseFk), + INDEX(itemFk)) + ENGINE = MEMORY + SELECT item_id itemFk, buy_id buyFk, warehouse_id warehouseFk, landing + FROM cache.last_buy + WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL; + + CALL buyUltimateFromInterval(vWarehouseFk, vn.VN_CURDATE(), vDated); + + REPLACE INTO tmp.buyUltimate + SELECT itemFk, buyFk, warehouseFk, landed landing + FROM tmp.buyUltimateFromInterval + WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) + AND landed <= vDated; + + INSERT IGNORE INTO tmp.buyUltimate + SELECT itemFk, buyFk, warehouseFk, landed landing + FROM tmp.buyUltimateFromInterval + WHERE (warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL) + AND landed > vDated; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `buyUltimateFromInterval` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50430,187 +46259,136 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buyUltimateFromInterval`(vWarehouseFk SMALLINT, vStarted DATE, vEnded DATE) -BEGIN -/** - * Calcula las últimas compras realizadas - * desde un rango de fechas. - * - * @param vWarehouseFk Id del almacén si es NULL se actualizan todos - * @param vStarted Fecha inicial - * @param vEnded Fecha fin - * @return tmp.buyUltimateFromInterval - */ - IF vEnded IS NULL THEN - SET vEnded = vStarted; - END IF; - - IF vEnded < vStarted THEN - SET vStarted = TIMESTAMPADD(MONTH, -1, vEnded); - END IF; - - -- Item - - DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval; - CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval - (PRIMARY KEY (itemFk, warehouseFk), INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk)) - ENGINE = MEMORY - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - MULTIMAX(t.landed, b.id) buyFk, - MAX(t.landed) landed - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vStarted AND vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.price2 > 0 - AND NOT b.isIgnored - AND b.quantity > 0 - GROUP BY itemFk, warehouseInFk; - - INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed > vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.price2 > 0 - AND NOT b.isIgnored - GROUP BY itemFk, warehouseInFk; - - INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vStarted AND vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.quantity = 0 - GROUP BY itemFk, warehouseInFk; - - - - -- ItemOriginal - - INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - MULTIMAX(t.landed, b.id) buyFk, - MAX(t.landed) landed - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vStarted AND vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.price2 > 0 - AND NOT b.isIgnored - AND b.quantity > 0 - AND itemOriginalFk - GROUP BY itemOriginalFk, warehouseInFk; - - INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed > vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.price2 > 0 - AND NOT b.isIgnored - AND itemOriginalFk - GROUP BY itemOriginalFk, warehouseInFk; - - INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) - SELECT - b.itemFk, - t.warehouseInFk warehouseFk, - b.id buyFk, - t.landed - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vStarted AND vEnded - AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) - AND b.quantity = 0 - AND itemOriginalFk - GROUP BY itemOriginalFk, warehouseInFk; - +BEGIN +/** + * Calcula las últimas compras realizadas + * desde un rango de fechas. + * + * @param vWarehouseFk Id del almacén si es NULL se actualizan todos + * @param vStarted Fecha inicial + * @param vEnded Fecha fin + * @return tmp.buyUltimateFromInterval + */ + IF vEnded IS NULL THEN + SET vEnded = vStarted; + END IF; + + IF vEnded < vStarted THEN + SET vStarted = TIMESTAMPADD(MONTH, -1, vEnded); + END IF; + + -- Item + + DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval; + CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval + (PRIMARY KEY (itemFk, warehouseFk), INDEX(buyFk), INDEX(landed), INDEX(warehouseFk), INDEX(itemFk)) + ENGINE = MEMORY + SELECT + b.itemFk, + t.warehouseInFk warehouseFk, + MULTIMAX(t.landed, b.id) buyFk, + MAX(t.landed) landed + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + AND b.quantity > 0 + GROUP BY itemFk, warehouseInFk; + + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + SELECT + b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed > vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + GROUP BY itemFk, warehouseInFk; + + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + SELECT + b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.quantity = 0 + GROUP BY itemFk, warehouseInFk; + + + + -- ItemOriginal + + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + SELECT + b.itemFk, + t.warehouseInFk warehouseFk, + MULTIMAX(t.landed, b.id) buyFk, + MAX(t.landed) landed + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + AND b.quantity > 0 + AND itemOriginalFk + GROUP BY itemOriginalFk, warehouseInFk; + + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + SELECT + b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed > vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.price2 > 0 + AND NOT b.isIgnored + AND itemOriginalFk + GROUP BY itemOriginalFk, warehouseInFk; + + INSERT IGNORE INTO tmp.buyUltimateFromInterval(itemFk, warehouseFk, buyFk, landed) + SELECT + b.itemFk, + t.warehouseInFk warehouseFk, + b.id buyFk, + t.landed + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vStarted AND vEnded + AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk) + AND b.quantity = 0 + AND itemOriginalFk + GROUP BY itemOriginalFk, warehouseInFk; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_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 = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `buyUltimate__`(vWarehouseFk SMALLINT, vDated DATE) -BEGIN -/** - * Calcula las �ltimas compras realizadas hasta una fecha - * - * @param vWarehouseFk Id del almacén - * @param vDated Compras hasta fecha - * @return tmp.buyUltimate - */ - CALL cache.last_buy_refresh (FALSE); - - DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate; - CREATE TEMPORARY TABLE tmp.buyUltimate - (PRIMARY KEY (itemFk, warehouseFk), - INDEX(itemFk)) - ENGINE = MEMORY - SELECT item_id itemFk, buy_id buyFk, warehouse_id warehouseFk - FROM cache.last_buy - WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL; - - CALL buyUltimateFromInterval(vWarehouseFk, util.VN_CURDATE(), vDated); - - REPLACE INTO tmp.buyUltimate - SELECT itemFk, buyFk, warehouseFk - FROM tmp.buyUltimateFromInterval - 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 ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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_afterUpsert` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50618,77 +46396,77 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_afterUpsert`(vSelf INT) -BEGIN -/** - * Triggered actions when a buy is updated or inserted. - * - * @param vSelf The buy reference - */ - DECLARE vEntryFk INT; - DECLARE vItemFk INT; - DECLARE vPackingOut DECIMAL(10,2); - DECLARE vWarehouse INT; - DECLARE vStandardFlowerBox INT; - DECLARE vWarehouseOut INT; - DECLARE vIsMerchandise BOOL; - DECLARE vIsFeedStock BOOL; - - SELECT b.entryFk, b.itemFk, i.packingOut, ic.merchandise, vc.standardFlowerBox - INTO vEntryFk, vItemFk, vPackingOut, vIsMerchandise, vStandardFlowerBox - FROM buy b - LEFT JOIN item i ON i.id = b.itemFk - LEFT JOIN itemType it ON it.id = i.typeFk - LEFT JOIN itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN packaging p ON p.id = b.packageFk AND NOT p.isBox - JOIN volumeConfig vc ON TRUE - WHERE b.id = vSelf; - - SELECT t.warehouseInFk, t.warehouseOutFk - INTO vWarehouse, vWarehouseOut - FROM entry e - JOIN travel t ON t.id = e.travelFk - WHERE e.id = vEntryFk; - - IF vIsMerchandise THEN - - REPLACE itemCost SET - itemFk = vItemFk, - warehouseFk = vWarehouse, - cm3 = buy_getUnitVolume(vSelf), - cm3Delivery = IFNULL((vStandardFlowerBox * 1000) / vPackingOut, buy_getUnitVolume(vSelf)); - - UPDATE vn.itemCost ic - JOIN cache.last_buy lb ON lb.item_id = ic.itemFk AND lb.warehouse_id = ic.warehouseFk - JOIN vn.buy b ON b.id = lb.buy_id - SET ic.grams = b.weight * 1000 / b.packing - WHERE ic.itemFk = vItemFk AND - ic.warehouseFk = vWarehouse; - - END IF; - - SELECT isFeedStock INTO vIsFeedStock - FROM warehouse WHERE id = vWarehouseOut AND id <> 13; - - IF vIsFeedStock THEN - INSERT IGNORE INTO producer(`name`) - SELECT es.company_name - FROM buy b - JOIN edi.ekt be ON be.id = b.ektFk - JOIN edi.supplier es ON es.supplier_id = be.pro - WHERE b.id = vSelf; - - END IF; - +BEGIN +/** + * Triggered actions when a buy is updated or inserted. + * + * @param vSelf The buy reference + */ + DECLARE vEntryFk INT; + DECLARE vItemFk INT; + DECLARE vPackingOut DECIMAL(10,2); + DECLARE vWarehouse INT; + DECLARE vStandardFlowerBox INT; + DECLARE vWarehouseOut INT; + DECLARE vIsMerchandise BOOL; + DECLARE vIsFeedStock BOOL; + + SELECT b.entryFk, b.itemFk, i.packingOut, ic.merchandise, vc.standardFlowerBox + INTO vEntryFk, vItemFk, vPackingOut, vIsMerchandise, vStandardFlowerBox + FROM buy b + LEFT JOIN item i ON i.id = b.itemFk + LEFT JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN packaging p ON p.id = b.packageFk AND NOT p.isBox + JOIN volumeConfig vc ON TRUE + WHERE b.id = vSelf; + + SELECT t.warehouseInFk, t.warehouseOutFk + INTO vWarehouse, vWarehouseOut + FROM entry e + JOIN travel t ON t.id = e.travelFk + WHERE e.id = vEntryFk; + + IF vIsMerchandise THEN + + REPLACE itemCost SET + itemFk = vItemFk, + warehouseFk = vWarehouse, + cm3 = buy_getUnitVolume(vSelf), + cm3Delivery = IFNULL((vStandardFlowerBox * 1000) / vPackingOut, buy_getUnitVolume(vSelf)); + + UPDATE vn.itemCost ic + JOIN cache.last_buy lb ON lb.item_id = ic.itemFk AND lb.warehouse_id = ic.warehouseFk + JOIN vn.buy b ON b.id = lb.buy_id + SET ic.grams = b.weight * 1000 / b.packing + WHERE ic.itemFk = vItemFk AND + ic.warehouseFk = vWarehouse; + + END IF; + + SELECT isFeedStock INTO vIsFeedStock + FROM warehouse WHERE id = vWarehouseOut AND id <> 13; + + IF vIsFeedStock THEN + INSERT IGNORE INTO producer(`name`) + SELECT es.company_name + FROM buy b + JOIN edi.ekt be ON be.id = b.ektFk + JOIN edi.supplier es ON es.supplier_id = be.pro + WHERE b.id = vSelf; + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_checkGrouping` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50696,8 +46474,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_checkGrouping`(vGrouping INT) BEGIN @@ -50716,6 +46492,138 @@ 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buy_getSplit` */; +/*!50003 SET @saved_cs_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_getSplit`(vSelf INT, vDated DATE) +BEGIN +/** + * Devuelve las ventas de una compra + * + * @param vSelf Identificador de vn.buy + */ + DECLARE vItemFk INT; + DECLARE vPacking INT; + DECLARE vRemaining INT; + DECLARE vLabels INT; + DECLARE vSaleFk INT; + DECLARE vAmount INT; + DECLARE vDone BOOL DEFAULT FALSE; + + DECLARE cur CURSOR FOR + SELECT s.id, s.quantity - IFNULL(l.stem, 0) + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + LEFT JOIN vn.saleLabel l ON l.saleFk = s.id + WHERE s.itemFk = vItemFk + AND t.shipped >= vDated + AND w.isLogiflora + AND IFNULL(l.stem, 0) < s.quantity + LOCK IN SHARE MODE; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + START TRANSACTION; + + -- Obtiene los datos de la compra + + SELECT itemFk, packing, quantity + INTO vItemFk, vPacking, vRemaining + FROM vn.buy WHERE id = vSelf; + + -- Crea splits de los tickets + + DROP TEMPORARY TABLE IF EXISTS tmp.split; + CREATE TEMPORARY TABLE tmp.split + ( + id INT, + labels INT + ) + ENGINE = MEMORY; + + OPEN cur; + + l: LOOP + SET vDone = FALSE; + + FETCH cur INTO vSaleFk, vAmount; + + IF vDone OR vRemaining = 0 THEN + LEAVE l; + END IF; + + SET vAmount = LEAST(vAmount, vRemaining); + + SET vRemaining = vRemaining - vAmount; + + SET vLabels = vAmount DIV vPacking; + + INSERT INTO tmp.split + VALUES (vSaleFk, vLabels); + + INSERT INTO vn.saleLabel + SET + saleFk = vSaleFk, + stem = vAmount, + label = vLabels + ON DUPLICATE KEY UPDATE + stem = stem + VALUES(stem), + label = label + VALUES(label); + + END LOOP; + + CLOSE cur; + + -- Devuelve los splits creados + SELECT + sp.labels, + COALESCE(sfc.nickname, sfa.nickname, a.nickname) destination, + s.itemFk, + i.longName, + i.`size`, + vn.ticketSplitCounter(t.id) counter, + IF(sfa.id OR sfc.id, + a.nickname, + CONCAT(a.id, ' ', p.`name`,' (', c.`code`,')')) destination2 + FROM tmp.split sp + JOIN vn.sale s ON sp.id = s.id + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.country c ON c.id = p.countryFk + LEFT JOIN vn.splitFilter sfa ON sfa.autonomyFk = p.autonomyFk + LEFT JOIN vn.splitFilter sfc ON sfc.clientFk = t.clientFk; + + -- Limpia y confirma cambios + + DROP TEMPORARY TABLE + tmp.split; + + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_getVolume` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50723,8 +46631,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_getVolume`() BEGIN @@ -50750,6 +46656,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_getVolumeByAgency` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50757,8 +46665,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_getVolumeByAgency`(vDated DATE, vAgencyFk INT) BEGIN @@ -50783,6 +46689,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_getVolumeByEntry` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50790,8 +46698,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_getVolumeByEntry`(vEntryFk INT) BEGIN @@ -50814,49 +46720,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 `buy_notifyPassport__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_notifyPassport__`( - IN vBuyFk INT, - IN vItemFk INT, - IN vStickers SMALLINT, - IN vPacking SMALLINT -) -BEGIN - /*INSERT INTO vn.mail(`subject`,`body`,`sender`) - SELECT 'Solicitar pasaporte', - CONCAT( - 'Etiquetas: ', IFNULL(vStickers, 0), - ', Packing: ', IFNULL(vPacking, 0), - ', Nombre: ', IFNULL(i.`name`, 0), - ', buy_edi: ', IFNULL(e.id, 0), - ', Nombre botánico: ', IFNULL(g.latin_genus_name, ''), ' ', IFNULL(s.latin_species_name, ''), - ', Productor: ',IFNULL(es.company_name, IFNULL(p.`name`, '')) - ) - ,'ekt@verdnatura.es' - FROM item i - LEFT JOIN itemBotanical ib ON ib.itemFk = i.id - LEFT JOIN edi.genus g ON g.genus_id = ib.genusFk - LEFT JOIN edi.specie s ON IFNULL(s.specie_id, ib.specieFk) = ib.specieFk - LEFT JOIN producer p ON p.id = i.producerFk - LEFT JOIN buy b ON b.id = vBuyFk - LEFT JOIN edi.ekt e ON b.ektFk = e.id - LEFT JOIN edi.supplier es ON es.supplier_id = e.pro - WHERE i.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 `buy_recalcPrices` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50864,8 +46729,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_recalcPrices`() BEGIN @@ -50937,6 +46800,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_updateGrouping` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50944,34 +46809,34 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_updateGrouping`(vWarehouseFk INT, vItemFk INT, vGrouping INT) -BEGIN -/** - * Actualiza el grouping de las últimas compras de un artículo - * - * @param vWarehouseFk Id del almacén - * @param vItemFk Id del Artículo - * @param vGrouping Cantidad de grouping - */ - - CALL vn.buyUltimate(vWarehouseFk, util.VN_CURDATE()); - - UPDATE vn.buy b - JOIN tmp.buyUltimate bu ON b.id = bu.buyFk - SET b.`grouping` = vGrouping - WHERE bu.warehouseFk = vWarehouseFk - AND bu.itemFk = vItemFk; - - DROP TEMPORARY TABLE tmp.buyUltimate; +BEGIN +/** + * Actualiza el grouping de las últimas compras de un artículo + * + * @param vWarehouseFk Id del almacén + * @param vItemFk Id del Artículo + * @param vGrouping Cantidad de grouping + */ + + CALL vn.buyUltimate(vWarehouseFk, vn.VN_CURDATE()); + + UPDATE vn.buy b + JOIN tmp.buyUltimate bu ON b.id = bu.buyFk + SET b.`grouping` = vGrouping + WHERE bu.warehouseFk = vWarehouseFk + AND bu.itemFk = vItemFk; + + DROP TEMPORARY TABLE tmp.buyUltimate; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `buy_updatePacking` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -50979,8 +46844,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_updatePacking`(vWarehouseFk INT, vItemFk INT, vPacking INT) BEGIN @@ -50991,7 +46854,7 @@ BEGIN * @param vItemFk id del item * @param vPacking packing a actualizar */ - CALL buyUltimate(vWarehouseFk, util.VN_CURDATE()); + CALL buyUltimate(vWarehouseFk, vn.VN_CURDATE()); UPDATE buy b JOIN tmp.buyUltimate bu ON b.id = bu.buyFk @@ -51007,281 +46870,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 `camaraFutureVolume__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `camaraFutureVolume__`(vWarehouseFk INT, vDateStart DATE, vDateEnd DATE) -BEGIN - - DECLARE vDated DATE; - DECLARE vSectorVolume INT; - DECLARE vLastDayVolume INT; - DECLARE vMinCamara INT; - - SET vDated = vDateStart; - - DROP TEMPORARY TABLE IF EXISTS tmp.camara; - - IF vDateStart = util.VN_CURDATE() THEN - - CREATE TEMPORARY TABLE tmp.camara - SELECT vDated as dated, - CONCAT('sector ', sectorFk) as place, - FLOOR(SUM(ish.visible * r.cm3)/1000000) as m3 - FROM vn.itemShelving ish - JOIN bi.rotacion r ON r.Id_Article = ish.itemFk AND r.warehouse_id = vWarehouseFk - JOIN vn.shelving sh ON sh.code = ish.shelvingFk - JOIN vn.parking p ON p.id = sh.parkingFk - JOIN vn.sector s ON s.id = p.sectorFk - WHERE s.warehouseFk = vWarehouseFk - GROUP BY p.sectorFk; - - SELECT m3 - INTO vSectorVolume - FROM tmp.camara - WHERE place LIKE 'sector%'; - - CALL cache.visible_refresh(@calc_id, FALSE, 1); - - INSERT INTO tmp.camara(dated, place, m3) - SELECT vDated, 'nicho', - FLOOR((SUM(v.visible * r.cm3) / 1000000) - vSectorVolume ) as m3 - FROM cache.visible v - JOIN bi.rotacion r ON r.Id_Article = v.item_id AND r.warehouse_id = vWarehouseFk - JOIN vn.item i ON i.id = v.item_id - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - WHERE calc_id = @calc_id - AND ic.display; - - INSERT INTO tmp.camara(dated, place, m3) - SELECT vDated, 'entradas', FLOOR(SUM(iei.amount * r.cm3) / 1000000) as m3 - FROM vn2008.item_entry_in iei - JOIN bi.rotacion r ON r.Id_Article = iei.item_id AND r.warehouse_id = vWarehouseFk - JOIN vn.item i ON i.id = iei.item_id - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - WHERE ic.display - AND dat = vDated - AND NOT received - AND NOT isVirtualStock - AND iei.warehouse_id = vWarehouseFk; - - INSERT INTO tmp.camara(dated, place, m3) - SELECT vDated, 'salidas', FLOOR(SUM(ieo.amount * r.cm3) / 1000000) as m3 - FROM vn2008.item_entry_out ieo - JOIN bi.rotacion r ON r.Id_Article = ieo.item_id AND r.warehouse_id = vWarehouseFk - JOIN vn.item i ON i.id = ieo.item_id - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - WHERE ic.display - AND dat = vDated - AND NOT delivered - AND NOT isVirtualStock - AND ieo.warehouse_id = vWarehouseFk; - - INSERT INTO tmp.camara(dated, place, m3) - SELECT vDated, 'ventas', FLOOR(SUM(io.amount * r.cm3) / 1000000) as m3 - FROM vn2008.item_out io - JOIN bi.rotacion r ON r.Id_Article = io.item_id AND r.warehouse_id = vWarehouseFk - JOIN vn.item i ON i.id = io.item_id - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - JOIN vn.ticketStateToday tst ON tst.ticket = io.ticketFk - JOIN vn.ticket t ON t.id = io.ticketFk - WHERE ic.display - AND ic.id != 7 - AND t.clientFk NOT IN (200,400,50,450) - AND dat BETWEEN vDated AND util.dayend(vDated) - AND NOT tst.isPicked - AND io.warehouse_id = vWarehouseFk; - - ELSE - - CREATE TEMPORARY TABLE tmp.camara - SELECT vDated as dated, - 'entradas' as place, - FLOOR(SUM(iei.amount * r.cm3) / 1000000) as m3 - FROM vn2008.item_entry_in iei - JOIN bi.rotacion r ON r.Id_Article = iei.item_id AND r.warehouse_id = vWarehouseFk - JOIN vn.item i ON i.id = iei.item_id - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - WHERE ic.display - AND dat = vDated - AND NOT isVirtualStock - AND iei.warehouse_id = vWarehouseFk; - - INSERT INTO tmp.camara(dated, place, m3) - SELECT vDated, 'salidas', FLOOR(SUM(ieo.amount * r.cm3) / 1000000) as m3 - FROM vn2008.item_entry_out ieo - JOIN bi.rotacion r ON r.Id_Article = ieo.item_id AND r.warehouse_id = vWarehouseFk - JOIN vn.item i ON i.id = ieo.item_id - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - WHERE ic.display - AND dat = vDated - AND ieo.warehouse_id = vWarehouseFk; - - INSERT INTO tmp.camara(dated, place, m3) - SELECT vDated, 'ventas', FLOOR(SUM(io.amount * r.cm3) / 1000000) as m3 - FROM vn2008.item_out io - JOIN bi.rotacion r ON r.Id_Article = io.item_id AND r.warehouse_id = vWarehouseFk - JOIN vn.item i ON i.id = io.item_id - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - JOIN vn.ticket t ON t.id = io.ticketFk - WHERE ic.display - AND dat BETWEEN vDated AND util.dayend(vDated) - AND ic.id != 7 - AND t.clientFk NOT IN (200,400,50,450) - AND io.warehouse_id = vWarehouseFk; - - END IF; - - -- Resto de dias - WHILE vDated < vDateEnd DO - - SELECT SUM(IFNULL(m3,0)) INTO vLastDayVolume - FROM tmp.camara - WHERE dated = vDated; - - SET vDated = TIMESTAMPADD(DAY, 1, vDated); - - INSERT INTO tmp.camara(dated, place, m3) - VALUES( vDated, 'camara', vLastDayVolume); - - INSERT INTO tmp.camara(dated, place, m3) - SELECT vDated, 'entradas', FLOOR(SUM(iei.amount * r.cm3) / 1000000) as m3 - FROM vn2008.item_entry_in iei - JOIN bi.rotacion r ON r.Id_Article = iei.item_id AND r.warehouse_id = vWarehouseFk - JOIN vn.item i ON i.id = iei.item_id - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - WHERE ic.display - AND dat = vDated - AND NOT isVirtualStock - AND iei.warehouse_id = vWarehouseFk; - - INSERT INTO tmp.camara(dated, place, m3) - SELECT vDated, 'salidas', FLOOR(SUM(ieo.amount * r.cm3) / 1000000) as m3 - FROM vn2008.item_entry_out ieo - JOIN bi.rotacion r ON r.Id_Article = ieo.item_id AND r.warehouse_id = vWarehouseFk - JOIN vn.item i ON i.id = ieo.item_id - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - WHERE ic.display - AND dat = vDated - AND ieo.warehouse_id = vWarehouseFk; - - INSERT INTO tmp.camara(dated, place, m3) - SELECT vDated, 'ventas', FLOOR(SUM(io.amount * r.cm3) / 1000000) as m3 - FROM vn2008.item_out io - JOIN bi.rotacion r ON r.Id_Article = io.item_id AND r.warehouse_id = vWarehouseFk - JOIN vn.item i ON i.id = io.item_id - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - JOIN vn.ticket t ON t.id = io.ticketFk - WHERE ic.display - AND dat BETWEEN vDated AND util.dayend(vDated) - AND ic.id != 7 - AND t.clientFk NOT IN (200,400,50,450) - AND io.warehouse_id = vWarehouseFk; - - END WHILE; - - SELECT min(m3) INTO vMinCamara - FROM - (SELECT dated, sum(m3) m3 - FROM tmp.camara - GROUP BY dated) sub; - - UPDATE tmp.camara - SET m3 = m3 - vMinCamara - WHERE place = 'camara'; - - SELECT camara.* FROM tmp.camara; - - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `carrosOficialesANoOficiales__` */; -/*!50003 SET @saved_cs_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`@`localhost` PROCEDURE `carrosOficialesANoOficiales__`() -BEGIN - -DECLARE done BOOL DEFAULT FALSE; -DECLARE vClientFk INT; -DECLARE vQuantity INT; -DECLARE vTicketFk INT; -DECLARE vAgencyTypeFk INT DEFAULT 628; - - -DECLARE rs CURSOR FOR - SELECT clientFk, sum(quantity) as carros - FROM `ticketPackaging` tp - JOIN ticket t ON t.id = tp.ticketFk - WHERE packagingFk = 'cc' - and t.shipped between '2017-10-30' AND '2019-01-06 23:59:59' - group by clientFk - having carros != 0; - -DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - -OPEN rs; - -FETCH rs INTO vClientFk, vQuantity; - --- WHILE NOT done DO - - CALL vn.ticketCreate(vClientFk, '2019-01-06', 13, 442, NULL, vAgencyTypeFk, NULL, '2019-01-01', vTicketFk); - - INSERT INTO vn.ticketPackaging(ticketFk, packagingFk, quantity) - VALUES (vTicketFk, 'cc', - VQuantity); - - INSERT INTO vn.ticketPackaging(ticketFk, packagingFk, quantity) - VALUES (vTicketFk, 'dc', VQuantity); - - INSERT INTO vn.sale(ticketFk, itemFk, concept) - VALUES (vTicketFk, 90, 'Regularización CCs 2019'); - - CALL vn.`ticketStateUpdate`(vTicketFk, 'DELIVERED'); -- entregado - --- FETCH rs INTO vClientFk, vQuantity; - --- END WHILE; - - -CLOSE rs; - -SELECT vTicketFk; - - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `catalog_calcFromItem` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -51289,8 +46879,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_calcFromItem`( vLanded DATE, @@ -51321,6 +46909,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `catalog_calculate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -51328,8 +46918,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_calculate`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT) BEGIN @@ -51500,6 +47088,7 @@ BEGIN FROM tmp.ticketComponentPrice WHERE warehouseFk = vWarehouseFk ORDER BY (rate = 2) DESC + LIMIT 10000000000000000000 ) sub GROUP BY itemFk ) bl ON bl.itemFk = tl.itemFk @@ -51517,6 +47106,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `catalog_componentCalculate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -51524,8 +47115,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_componentCalculate`( vZoneFk INT, vAddressFk INT, @@ -51549,7 +47138,6 @@ BEGIN DECLARE vIsFrenchVNHBuyer BOOLEAN DEFAULT FALSE; DECLARE vVNHWarehouseFk INT DEFAULT 7; DECLARE vFrenchDiscount DECIMAL(3,2) DEFAULT 0.12; - DECLARE visAnyVolumeAllowed BOOL; SELECT clientFk INTO vClientFK FROM address @@ -51562,25 +47150,6 @@ BEGIN JOIN vn.address a ON a.provinceFk = p.id WHERE a.id = vAddressFk; - - -- Se eliminan los productos de tamaños no convencionales, salvo agencias que lo permitan - SELECT a.isAnyVolumeAllowed INTO visAnyVolumeAllowed - FROM vn.agency a - JOIN vn.agencyMode am ON am.agencyFk = a.id - JOIN vn.`zone`z ON z.agencyModeFk = am.id - WHERE z.id = vZoneFk; - - IF NOT vIsAnyVolumeAllowed THEN - - DELETE tl.* - FROM tmp.ticketLot tl - JOIN vn.item i ON i.id = tl.itemFk - JOIN vn.itemType it ON it.id = i.typeFk - WHERE it.isUnconventionalSize; - - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentCalculate; CREATE TEMPORARY TABLE tmp.ticketComponentCalculate @@ -51590,11 +47159,8 @@ BEGIN tl.itemFk, tl.warehouseFk, tl.available, - -- IF((@rate2 := IFNULL(pf.rate2, b.price2)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate2) rate2, IF(i.hasMinPrice, GREATEST(i.minPrice,IFNULL(pf.rate2, b.price2)),IFNULL(pf.rate2, b.price2)) rate2, IF(i.hasMinPrice, GREATEST(i.minPrice,IFNULL(pf.rate3, b.price3)),IFNULL(pf.rate3, b.price3)) rate3, - -- @minPrice := IF((@rate3 := IFNULL(pf.rate3, b.price3)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate3) rate3, - -- TRUE AS minPrice, IFNULL(pf.packing, GREATEST(b.grouping, b.packing)) packing, IFNULL(pf.`grouping`, b.`grouping`) `grouping`, ABS(IFNULL(pf.box, b.groupingMode)) groupingMode, @@ -51622,6 +47188,7 @@ BEGIN AND zw.warehouseFk IN (pf.warehouseFk,0) WHERE vShipped BETWEEN pf.started AND pf.ended ORDER BY pf.itemFk, pf.warehouseFk DESC + LIMIT 10000000000000000000 ) tpf GROUP BY tpf.itemFk, tpf.warehouseFk ) pf ON pf.itemFk = tl.itemFk @@ -51684,10 +47251,11 @@ BEGIN IFNULL(cr1.priceIncreasing,0), IFNULL(cr2.priceIncreasing,0)) ), - 0.25), + cc.maxPriceIncreasingRatio), 3) FROM tmp.ticketComponentBase tcb JOIN vn.component c2 ON c2.code = 'debtCollection' + JOIN vn.clientConfig cc JOIN claimRatio cr ON cr.clientFk = vClientFk LEFT JOIN clientYoke cy1 ON cy1.leftOx = cr.clientFk LEFT JOIN claimRatio cr1 ON cr1.clientFk = cy1.rightOx @@ -51757,15 +47325,6 @@ BEGIN HAVING cost <> 0; DROP TEMPORARY TABLE tmp.zoneOption; - /* - -- Extra reparto - INSERT INTO tmp.ticketComponent(warehouseFk, itemFk, componentFk, cost) - SELECT tcc.warehouseFk, tcc.itemFk, c2.id, ap.packagingValue cost - FROM tmp.ticketComponentCalculate tcc - JOIN vn.addressForPackaging ap - JOIN vn.component c2 ON c2.code = 'bagged' - WHERE ap.addressFk = vAddressFk; - */ DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentCopy; CREATE TEMPORARY TABLE tmp.ticketComponentCopy ENGINE = MEMORY @@ -51855,7 +47414,7 @@ BEGIN INSERT INTO tmp.ticketComponentPrice (warehouseFk, itemFk, rate, `grouping`, price, priceKg) SELECT * FROM ( - SELECT * FROM tmp.ticketComponentRate ORDER BY price + SELECT * FROM tmp.ticketComponentRate ORDER BY price LIMIT 10000000000000000000 ) t GROUP BY itemFk, warehouseFk, `grouping`; @@ -51872,6 +47431,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `catalog_componentPrepare` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -51879,8 +47440,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_componentPrepare`() BEGIN @@ -51912,6 +47471,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `catalog_componentPurge` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -51919,8 +47480,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_componentPurge`() BEGIN @@ -51934,6 +47493,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `catalog_test` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -51941,8 +47502,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `catalog_test`() proc: BEGIN @@ -51960,7 +47519,7 @@ proc: BEGIN * @return tmp.ticketComponentPrice * @return tmp.zoneGetShipped */ - DECLARE vLanded DATE DEFAULT DATE_ADD(util.VN_CURDATE(),INTERVAL 2 DAY); + DECLARE vLanded DATE DEFAULT DATE_ADD(vn.VN_CURDATE(),INTERVAL 2 DAY); DECLARE vAddressFk INT DEFAULT 24526; DECLARE vAgencyModeFk INT DEFAULT 639; DECLARE vAvailableCalc INT; @@ -52078,7 +47637,8 @@ SELECT 6; FROM (SELECT price, itemFk, priceKg FROM tmp.ticketComponentPrice WHERE warehouseFk = vWarehouseFk - ORDER BY (rate = 2) DESC) sub + ORDER BY (rate = 2) DESC + LIMIT 10000000000000000000) sub GROUP BY itemFk ) bl ON bl.itemFk = tl.itemFk WHERE tl.zoneFk = vZoneFk AND tl.warehouseFk = vWarehouseFk @@ -52097,15 +47657,15 @@ 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!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 = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clean`() BEGIN @@ -52117,37 +47677,37 @@ BEGIN DECLARE v3Month DATE; DECLARE vTrashId varchar(15); - SET vDateShort = TIMESTAMPADD(MONTH, -2, util.VN_CURDATE()); - SET vOneYearAgo = TIMESTAMPADD(YEAR,-1,util.VN_CURDATE()); - SET vFourYearsAgo = TIMESTAMPADD(YEAR,-4,util.VN_CURDATE()); - SET v18Month = TIMESTAMPADD(MONTH, -18,util.VN_CURDATE()); - SET v26Month = TIMESTAMPADD(MONTH, -26,util.VN_CURDATE()); - SET v3Month = TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()); + SET vDateShort = TIMESTAMPADD(MONTH, -2, vn.VN_CURDATE()); + SET vOneYearAgo = TIMESTAMPADD(YEAR,-1,vn.VN_CURDATE()); + SET vFourYearsAgo = TIMESTAMPADD(YEAR,-4,vn.VN_CURDATE()); + SET v18Month = TIMESTAMPADD(MONTH, -18,vn.VN_CURDATE()); + SET v26Month = TIMESTAMPADD(MONTH, -26,vn.VN_CURDATE()); + SET v3Month = TIMESTAMPADD(MONTH, -3, vn.VN_CURDATE()); DELETE FROM ticketParking WHERE created < vDateShort; - DELETE FROM routesMonitor WHERE dated < vDateShort; - DELETE FROM workerTimeControlLog WHERE created < vDateShort; + DELETE FROM routesMonitor WHERE dated < vDateShort; + DELETE FROM workerTimeControlLog WHERE created < vDateShort; DELETE FROM `message` WHERE sendDate < vDateShort; DELETE FROM messageInbox WHERE sendDate < vDateShort; DELETE FROM messageInbox WHERE sendDate < vDateShort; DELETE FROM workerTimeControl WHERE timed < vFourYearsAgo; - DELETE FROM itemShelving WHERE created < util.VN_CURDATE() AND visible = 0; - DELETE FROM ticketDown WHERE created < TIMESTAMPADD(DAY,-1,util.VN_CURDATE()); - DELETE FROM entryLog WHERE creationDate < vDateShort; - DELETE IGNORE FROM expedition WHERE created < v26Month; - DELETE FROM sms WHERE created < v18Month; - DELETE FROM saleTracking WHERE created < vOneYearAgo; - DELETE tobs FROM ticketObservation tobs - JOIN ticket t ON tobs.ticketFk = t.id WHERE t.shipped < TIMESTAMPADD(YEAR,-2,util.VN_CURDATE()); + DELETE FROM itemShelving WHERE created < vn.VN_CURDATE() AND visible = 0; + DELETE FROM ticketDown WHERE created < TIMESTAMPADD(DAY,-1,vn.VN_CURDATE()); + DELETE FROM entryLog WHERE creationDate < vDateShort; + DELETE IGNORE FROM expedition WHERE created < v26Month; + DELETE FROM sms WHERE created < v18Month; + DELETE FROM saleTracking WHERE created < vOneYearAgo; + DELETE tobs FROM ticketObservation tobs + JOIN ticket t ON tobs.ticketFk = t.id WHERE t.shipped < TIMESTAMPADD(YEAR,-2,vn.VN_CURDATE()); DELETE sc.* FROM saleCloned sc JOIN sale s ON s.id = sc.saleClonedFk JOIN ticket t ON t.id = s.ticketFk WHERE t.shipped < vOneYearAgo; DELETE FROM sharingCart where ended < vDateShort; - DELETE FROM sharingClient where ended < vDateShort; - DELETE tw.* FROM ticketWeekly tw + DELETE FROM sharingClient where ended < vDateShort; + DELETE tw.* FROM ticketWeekly tw LEFT JOIN sale s ON s.ticketFk = tw.ticketFk WHERE s.itemFk IS NULL; DELETE FROM claim WHERE ticketCreated < vFourYearsAgo; DELETE FROM message WHERE sendDate < vDateShort; - -- Robert ubicacion anterior de trevelLog comentario para debug - DELETE sc FROM saleChecked sc + -- Robert ubicacion anterior de trevelLog comentario para debug + DELETE sc FROM saleChecked sc JOIN sale s ON sc.saleFk = s.id WHERE s.created < vDateShort; DELETE FROM zoneEvent WHERE `type` = 'day' AND dated < v3Month; DELETE bm @@ -52157,10 +47717,11 @@ BEGIN JOIN travel t ON t.id = e.travelFk WHERE t.landed <= vDateShort; DELETE FROM stowaway WHERE created < v3Month; - DELETE FROM vn.buy WHERE created < vDateShort AND entryFk = 9200; - DELETE FROM vn.itemShelvingLog WHERE created < vDateShort; - DELETE FROM vn.stockBuyed WHERE creationDate < vDateShort; - + DELETE FROM vn.buy WHERE created < vDateShort AND entryFk = 9200; + DELETE FROM vn.itemShelvingLog WHERE created < vDateShort; + DELETE FROM vn.stockBuyed WHERE creationDate < vDateShort; + + -- Equipos duplicados DELETE w.* FROM workerTeam w @@ -52169,36 +47730,36 @@ BEGIN GROUP BY team,workerFk HAVING duplicated ) d ON d.team = w.team AND d.workerFk = w.workerFk AND d.id != w.id; - - DELETE sc + + DELETE sc FROM saleComponent sc JOIN sale s ON s.id= sc.saleFk JOIN ticket t ON t.id= s.ticketFk WHERE t.shipped < v18Month; - - DELETE c + + DELETE c FROM vn.claim c JOIN vn.claimState cs ON cs.id = c.claimStateFk WHERE cs.description = "Anulado" AND - c.created < vDateShort; + c.created < vDateShort; DELETE FROM vn.expeditionTruck - WHERE ETD < v3Month; - - -- borrar travels sin entradas + WHERE ETD < v3Month; + + -- borrar travels sin entradas DROP TEMPORARY TABLE IF EXISTS tmp.thermographToDelete; CREATE TEMPORARY TABLE tmp.thermographToDelete SELECT th.id,th.dmsFk FROM vn.travel t LEFT JOIN vn.entry e ON e.travelFk = t.id JOIN vn.travelThermograph th ON th.travelFk = t.id - WHERE t.shipped < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND e.travelFk IS NULL; - - SELECT dt.id into vTrashId - FROM vn.dmsType dt - WHERE dt.code = 'trash'; + WHERE t.shipped < TIMESTAMPADD(MONTH, -3, vn.VN_CURDATE()) AND e.travelFk IS NULL; - UPDATE tmp.thermographToDelete th + SELECT dt.id into vTrashId + FROM vn.dmsType dt + WHERE dt.code = 'trash'; + + UPDATE tmp.thermographToDelete th JOIN vn.dms d ON d.id = th.dmsFk SET d.dmsTypeFk = vTrashId; @@ -52209,27 +47770,32 @@ BEGIN DELETE t FROM vn.travel t LEFT JOIN vn.entry e ON e.travelFk = t.id - WHERE t.shipped < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND e.travelFk IS NULL; + WHERE t.shipped < TIMESTAMPADD(MONTH, -3, vn.VN_CURDATE()) AND e.travelFk IS NULL; - -- borrar entradas sin compras - DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete; + UPDATE dms d + JOIN dmsType dt ON dt.id = d.dmsTypeFk + SET d.dmsTypeFk = vTrashId + WHERE created < TIMESTAMPADD(MONTH, -dt.monthToDelete, vn.VN_CURDATE()); + + -- borrar entradas sin compras + DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete; CREATE TEMPORARY TABLE tmp.entryToDelete SELECT e.* FROM vn.entry e LEFT JOIN vn.buy b ON b.entryFk = e.id JOIN vn.entryConfig ec ON e.id != ec.defaultEntry - WHERE e.dated < TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()) AND b.entryFK IS NULL; + WHERE e.dated < TIMESTAMPADD(MONTH, -3, vn.VN_CURDATE()) AND b.entryFK IS NULL; DELETE e FROM vn.entry e JOIN tmp.entryToDelete tmp ON tmp.id = e.id; - - -- borrar de route registros menores a 4 años - DROP TEMPORARY TABLE IF EXISTS tmp.routeToDelete; + + -- borrar de route registros menores a 4 años + DROP TEMPORARY TABLE IF EXISTS tmp.routeToDelete; CREATE TEMPORARY TABLE tmp.routeToDelete SELECT * FROM vn.route r - WHERE created < TIMESTAMPADD(YEAR,-4,util.VN_CURDATE()); + WHERE created < TIMESTAMPADD(YEAR,-4,vn.VN_CURDATE()); UPDATE tmp.routeToDelete tmp JOIN vn.dms d ON d.id = tmp.gestdocFk @@ -52238,13 +47804,13 @@ BEGIN DELETE r FROM tmp.routeToDelete tmp JOIN vn.route r ON r.id = tmp.id; - - -- borrar registros de dua y awb menores a 2 años - DROP TEMPORARY TABLE IF EXISTS tmp.duaToDelete; + + -- borrar registros de dua y awb menores a 2 años + DROP TEMPORARY TABLE IF EXISTS tmp.duaToDelete; CREATE TEMPORARY TABLE tmp.duaToDelete SELECT * - FROM vn.dua - WHERE operated < TIMESTAMPADD(YEAR,-2,util.VN_CURDATE()); + FROM vn.dua + WHERE operated < TIMESTAMPADD(YEAR,-2,vn.VN_CURDATE()); UPDATE tmp.duaToDelete tm JOIN vn.dms d ON d.id = tm.gestdocFk @@ -52253,29 +47819,31 @@ BEGIN DELETE d FROM tmp.duaToDelete tmp JOIN vn.dua d ON d.id = tmp.id; - - DELETE FROM vn.awb WHERE created < TIMESTAMPADD(YEAR,-2,util.VN_CURDATE()); - - -- Borra los ficheros gestDoc - INSERT INTO vn.printServerQueue(priorityFk, labelReportFk)VALUES(1,11); - - -- Borra los registros de collection y ticketcollection - DELETE FROM vn.collection WHERE created < vDateShort; - - DROP TEMPORARY TABLE IF EXISTS tmp.thermographToDelete; - DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete; + + DELETE FROM vn.awb WHERE created < TIMESTAMPADD(YEAR,-2,vn.VN_CURDATE()); + + -- Borra los ficheros gestDoc + INSERT INTO vn.printServerQueue(priorityFk, labelReportFk)VALUES(1,11); + + -- Borra los registros de collection y ticketcollection + DELETE FROM vn.collection WHERE created < vDateShort; + + DROP TEMPORARY TABLE IF EXISTS tmp.thermographToDelete; + DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete; DROP TEMPORARY TABLE IF EXISTS tmp.duaToDelete; - - DELETE FROM travelLog WHERE creationDate < v3Month; - + + DELETE FROM travelLog WHERE creationDate < v3Month; + CALL shelving_clean; - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clean_logiflora` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -52283,97 +47851,97 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clean_logiflora`() -BEGIN - /* partir en 2 procedimientos, uno que borre compras y otro articulos - * item_clean, buy_clean - * */ - - DECLARE vMaxDated DATE DEFAULT TIMESTAMPADD(DAY, - 7, util.VN_CURDATE()); - DECLARE vDone INT DEFAULT FALSE; - DECLARE vBuyFk INT; - DECLARE cur1 CURSOR FOR SELECT id FROM tmp.buy; - DECLARE cur2 CURSOR FOR SELECT id FROM tmp.item; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - DROP TEMPORARY TABLE IF EXISTS tmp.buy; - - CREATE TEMPORARY TABLE tmp.buy - ENGINE = MEMORY - SELECT b.id - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - JOIN vn.agencyMode am ON am.id = tr.agencyFk - WHERE b.quantity = 0 - AND am.name = 'LOGIFLORA' - AND e.isRaid; - - OPEN cur1; - - read_loop: LOOP - - SET vDone = FALSE; - - FETCH cur1 INTO vBuyFk; - - IF vDone THEN - LEAVE read_loop; - END IF; - - DELETE FROM vn.buy WHERE id = vBuyFk; - - END LOOP; - - CLOSE cur1; - - DROP TEMPORARY TABLE tmp.buy; - - DROP TEMPORARY TABLE IF EXISTS tmp.item; - - CREATE TEMPORARY TABLE tmp.item - ENGINE = MEMORY - SELECT DISTINCT i.id - FROM vn.item i - LEFT JOIN hedera.orderRow o ON o.itemFk = i.id - LEFT JOIN vn.sale s ON s.itemFk = i.id - LEFT JOIN vn.buy b ON b.itemFk = i.id - WHERE i.supplyResponseFk - AND o.id IS NULL - AND b.id IS NULL - AND s.id IS NULL - AND i.created < vMaxDated; - - OPEN cur2; - - read_loop: LOOP - - SET vDone = FALSE; - - FETCH cur2 INTO vBuyFk; - - IF vDone THEN - LEAVE read_loop; - END IF; - - DELETE FROM vn.item WHERE id = vBuyFk; - - END LOOP; - - CLOSE cur2; - - DROP TEMPORARY TABLE tmp.item; - +BEGIN + /* partir en 2 procedimientos, uno que borre compras y otro articulos + * item_clean, buy_clean + * */ + + DECLARE vMaxDated DATE DEFAULT TIMESTAMPADD(DAY, - 7, vn.VN_CURDATE()); + DECLARE vDone INT DEFAULT FALSE; + DECLARE vBuyFk INT; + DECLARE cur1 CURSOR FOR SELECT id FROM tmp.buy; + DECLARE cur2 CURSOR FOR SELECT id FROM tmp.item; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DROP TEMPORARY TABLE IF EXISTS tmp.buy; + + CREATE TEMPORARY TABLE tmp.buy + ENGINE = MEMORY + SELECT b.id + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel tr ON tr.id = e.travelFk + JOIN vn.agencyMode am ON am.id = tr.agencyFk + WHERE b.quantity = 0 + AND am.name = 'LOGIFLORA' + AND e.isRaid; + + OPEN cur1; + + read_loop: LOOP + + SET vDone = FALSE; + + FETCH cur1 INTO vBuyFk; + + IF vDone THEN + LEAVE read_loop; + END IF; + + DELETE FROM vn.buy WHERE id = vBuyFk; + + END LOOP; + + CLOSE cur1; + + DROP TEMPORARY TABLE tmp.buy; + + DROP TEMPORARY TABLE IF EXISTS tmp.item; + + CREATE TEMPORARY TABLE tmp.item + ENGINE = MEMORY + SELECT DISTINCT i.id + FROM vn.item i + LEFT JOIN hedera.orderRow o ON o.itemFk = i.id + LEFT JOIN vn.sale s ON s.itemFk = i.id + LEFT JOIN vn.buy b ON b.itemFk = i.id + WHERE i.supplyResponseFk + AND o.id IS NULL + AND b.id IS NULL + AND s.id IS NULL + AND i.created < vMaxDated; + + OPEN cur2; + + read_loop: LOOP + + SET vDone = FALSE; + + FETCH cur2 INTO vBuyFk; + + IF vDone THEN + LEAVE read_loop; + END IF; + + DELETE FROM vn.item WHERE id = vBuyFk; + + END LOOP; + + CLOSE cur2; + + DROP TEMPORARY TABLE 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clearShelvingList` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -52381,22 +47949,20 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clearShelvingList`(vShelvingFk VARCHAR(8)) BEGIN - - UPDATE vn.itemShelving - SET visible = 0, available = 0 - WHERE shelvingFk COLLATE utf8_unicode_ci =vShelvingFk COLLATE utf8_unicode_ci; - + UPDATE vn.itemShelving + SET visible = 0 + WHERE shelvingFk COLLATE utf8_unicode_ci = vShelvingFk COLLATE utf8_unicode_ci; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientCreate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -52404,85 +47970,85 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `clientCreate`( - vFirstname VARCHAR(50), - vSurnames VARCHAR(50), - vFi VARCHAR(9), - vAddress TEXT, - vPostcode CHAR(5), - vCity VARCHAR(25), - vProvinceFk SMALLINT(5), - vCompanyFk SMALLINT(5), - vPhone VARCHAR(11), - vEmail VARCHAR(255), +CREATE DEFINER=`root`@`localhost` PROCEDURE `clientCreate`( + vFirstname VARCHAR(50), + vSurnames VARCHAR(50), + vFi VARCHAR(9), + vAddress TEXT, + vPostcode CHAR(5), + vCity VARCHAR(25), + vProvinceFk SMALLINT(5), + vCompanyFk SMALLINT(5), + vPhone VARCHAR(11), + vEmail VARCHAR(255), vUserFk INT) -BEGIN -/** - * Create new client - * - */ - DECLARE vPayMethodFk INT DEFAULT 4; - DECLARE vDueDay INT DEFAULT 5; - DECLARE vDefaultCredit DECIMAL(10, 2) DEFAULT 300.00; - DECLARE vIsTaxDataChecked TINYINT(1) DEFAULT 1; - DECLARE vHasCoreVnl BOOLEAN DEFAULT TRUE; - DECLARE vMandateTypeFk INT DEFAULT 2; - - INSERT INTO `client` ( - id, - name, - street, - fi, - phone, - email, - provinceFk, - city, - postcode, - socialName, - payMethodFk, - dueDay, - credit, - isTaxDataChecked, - hasCoreVnl, - isEqualizated) - VALUES ( - vUserFk, - CONCAT('TR ', vFirstname, ' ', vSurnames), - vAddress, - TRIM(vFi), - vPhone, - vEmail, - vProvinceFk, - vCity, - vPostcode, - CONCAT(vSurnames, ' ', vFirstname), - vPayMethodFk, - vDueDay, - vDefaultCredit, - vIsTaxDataChecked, - vHasCoreVnl, - FALSE - ) ON duplicate key update - payMethodFk = vPayMethodFk, - dueDay = vDueDay, - credit = vDefaultCredit, - isTaxDataChecked = vIsTaxDataChecked, - hasCoreVnl = vHasCoreVnl, - isActive = TRUE; - - IF (SELECT COUNT(*) FROM mandate WHERE clientFk = vUserFk AND companyFk = vCompanyFk AND mandateTypeFk = vMandateTypeFk) = 0 THEN - INSERT INTO mandate (clientFk, companyFk, mandateTypeFk) - VALUES (vUserFk, vCompanyFk, vMandateTypeFk); - END IF; +BEGIN +/** + * Create new client + * + */ + DECLARE vPayMethodFk INT DEFAULT 4; + DECLARE vDueDay INT DEFAULT 5; + DECLARE vDefaultCredit DECIMAL(10, 2) DEFAULT 300.00; + DECLARE vIsTaxDataChecked TINYINT(1) DEFAULT 1; + DECLARE vHasCoreVnl BOOLEAN DEFAULT TRUE; + DECLARE vMandateTypeFk INT DEFAULT 2; + + INSERT INTO `client` ( + id, + name, + street, + fi, + phone, + email, + provinceFk, + city, + postcode, + socialName, + payMethodFk, + dueDay, + credit, + isTaxDataChecked, + hasCoreVnl, + isEqualizated) + VALUES ( + vUserFk, + CONCAT('TR ', vFirstname, ' ', vSurnames), + vAddress, + TRIM(vFi), + vPhone, + vEmail, + vProvinceFk, + vCity, + vPostcode, + CONCAT(vSurnames, ' ', vFirstname), + vPayMethodFk, + vDueDay, + vDefaultCredit, + vIsTaxDataChecked, + vHasCoreVnl, + FALSE + ) ON duplicate key update + payMethodFk = vPayMethodFk, + dueDay = vDueDay, + credit = vDefaultCredit, + isTaxDataChecked = vIsTaxDataChecked, + hasCoreVnl = vHasCoreVnl, + isActive = TRUE; + + IF (SELECT COUNT(*) FROM mandate WHERE clientFk = vUserFk AND companyFk = vCompanyFk AND mandateTypeFk = vMandateTypeFk) = 0 THEN + INSERT INTO mandate (clientFk, companyFk, mandateTypeFk) + VALUES (vUserFk, vCompanyFk, vMandateTypeFk); + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientDebtSpray` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -52490,8 +48056,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clientDebtSpray`(vClientFk INT) BEGIN @@ -52503,15 +48067,15 @@ BEGIN DECLARE vClientDebt DOUBLE; - SELECT vn.clientGetDebt(vClientFk, util.VN_CURDATE()) INTO vClientDebt; + SELECT vn.clientGetDebt(vClientFk, vn.VN_CURDATE()) INTO vClientDebt; INSERT INTO vn.greuge(clientFk, description, amount, shipped, greugeTypeFk) - VALUES (vClientFk, 'Saldo pendiente', vClientDebt, util.VN_CURDATE(), 5); + VALUES (vClientFk, 'Saldo pendiente', vClientDebt, vn.VN_CURDATE(), 5); CALL vn.clientGreugeSpray(vClientFk, TRUE, '', TRUE); INSERT INTO vn.greuge(clientFk, description, amount, shipped, greugeTypeFk) - SELECT vClientFk, 'Liquidación cliente', sum(amount), util.VN_CURDATE(), 5 + SELECT vClientFk, 'Liquidación cliente', sum(amount), vn.VN_CURDATE(), 5 FROM vn.greuge WHERE clientFk = vClientFk; @@ -52525,6 +48089,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientFreeze` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -52532,60 +48098,60 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clientFreeze`() -BEGIN -/** - * Congela diariamente aquellos clientes que son morosos sin recobro, - * pero que no sean trabajadores, - * y que el riesgo no sea menor que cero - * hasta que no se gire la remesa no se congelan a los clientes de giro - */ - - DECLARE vIsRemittanced BOOLEAN; - - SELECT id into vIsRemittanced - FROM receipt - WHERE invoiceFk LIKE 'REMESA%' - AND payed > util.firstDayOfMonth(util.VN_CURDATE()) - limit 1; - - DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; - CREATE TEMPORARY TABLE tmp.clientGetDebt - SELECT clientFk - FROM bs.defaulter - WHERE created = util.VN_CURDATE() - AND amount; - - CALL clientGetDebt(util.VN_CURDATE()); - - UPDATE client c - JOIN bi.defaulters d ON d.client = c.id AND d.date = util.VN_CURDATE() - JOIN config ON TRUE - LEFT JOIN account.`user` u ON u.id = c.id AND u.active - LEFT JOIN worker w ON w.id = u.id - LEFT JOIN recovery r ON r.clientFk = c.id AND r.finished IS NULL - LEFT JOIN payMethod pm ON pm.id = c.payMethodFk - LEFT JOIN tmp.risk rk ON rk.clientFk = c.id - SET c.isFreezed = TRUE, - d.frozened = util.VN_CURDATE(), - u.active = FALSE - WHERE (d.amount > config.defaultersMaxAmount - AND rk.risk > 0) - AND c.typeFk = 'normal' - AND r.id IS NULL - AND w.id IS NULL - AND (vIsRemittanced OR pm.code <> 'bankDraft'); - - DROP TEMPORARY TABLE tmp.clientGetDebt; +BEGIN +/** + * Congela diariamente aquellos clientes que son morosos sin recobro, + * pero que no sean trabajadores, + * y que el riesgo no sea menor que cero + * hasta que no se gire la remesa no se congelan a los clientes de giro + */ + + DECLARE vIsRemittanced BOOLEAN; + + SELECT id into vIsRemittanced + FROM receipt + WHERE invoiceFk LIKE 'REMESA%' + AND payed > util.firstDayOfMonth(vn.VN_CURDATE()) + limit 1; + + DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; + CREATE TEMPORARY TABLE tmp.clientGetDebt + SELECT clientFk + FROM bs.defaulter + WHERE created = vn.VN_CURDATE() + AND amount; + + CALL clientGetDebt(vn.VN_CURDATE()); + + UPDATE client c + JOIN bi.defaulters d ON d.client = c.id AND d.date = vn.VN_CURDATE() + JOIN config ON TRUE + LEFT JOIN account.`user` u ON u.id = c.id AND u.active + LEFT JOIN worker w ON w.id = u.id + LEFT JOIN recovery r ON r.clientFk = c.id AND r.finished IS NULL + LEFT JOIN payMethod pm ON pm.id = c.payMethodFk + LEFT JOIN tmp.risk rk ON rk.clientFk = c.id + SET c.isFreezed = TRUE, + d.frozened = vn.VN_CURDATE(), + u.active = FALSE + WHERE (d.amount > config.defaultersMaxAmount + AND rk.risk > 0) + AND c.typeFk = 'normal' + AND r.id IS NULL + AND w.id IS NULL + AND (vIsRemittanced OR pm.code <> 'bankDraft'); + + DROP TEMPORARY TABLE tmp.clientGetDebt; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientGetDebt` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -52593,69 +48159,69 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clientGetDebt`(vDate DATE) -BEGIN -/** - * Calcula el riesgo para los clientes activos - * - * @table tmp.clientGetDebt(clientFk) - * @param vDate Fecha maxima de los registros - * @return tmp.risk - */ - DECLARE vStarted DATETIME DEFAULT TIMESTAMPADD(DAY, -35, util.VN_CURDATE()); - DECLARE vEnded DATETIME; - - SET vEnded = TIMESTAMP(IFNULL(vDate, util.VN_CURDATE()), '23:59:59'); - - DROP TEMPORARY TABLE IF EXISTS tClientRisk; - CREATE TEMPORARY TABLE tClientRisk - ENGINE = MEMORY - SELECT cr.clientFk, SUM(cr.amount) amount - FROM clientRisk cr - JOIN tmp.clientGetDebt c ON c.clientFk = cr.clientFk - GROUP BY cr.clientFk; - - INSERT INTO tClientRisk - SELECT c.clientFk, SUM(r.amountPaid) - FROM receipt r - JOIN tmp.clientGetDebt c ON c.clientFk = r.clientFk - WHERE r.payed > vEnded - GROUP BY c.clientFk; - - INSERT INTO tClientRisk - SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2)) - FROM hedera.tpvTransaction t - JOIN tmp.clientGetDebt c ON c.clientFk = t.clientFk - WHERE t.receiptFk IS NULL - AND t.status = 'ok' - GROUP BY t.clientFk; - - INSERT INTO tClientRisk - SELECT t.clientFk, totalWithVat - FROM ticket t - JOIN tmp.clientGetDebt c ON c.clientFk = t.clientFk - WHERE refFk IS NULL - AND shipped BETWEEN vStarted AND vEnded; - - DROP TEMPORARY TABLE IF EXISTS tmp.risk; - CREATE TEMPORARY TABLE tmp.risk - (PRIMARY KEY (clientFk)) - ENGINE = MEMORY - SELECT clientFk, SUM(amount) risk - FROM client c - JOIN tClientRisk cr ON cr.clientFk = c.id - GROUP BY c.id; - - DROP TEMPORARY TABLE tClientRisk; +BEGIN +/** + * Calcula el riesgo para los clientes activos + * + * @table tmp.clientGetDebt(clientFk) + * @param vDate Fecha maxima de los registros + * @return tmp.risk + */ + DECLARE vStarted DATETIME DEFAULT TIMESTAMPADD(DAY, -35, vn.VN_CURDATE()); + DECLARE vEnded DATETIME; + + SET vEnded = TIMESTAMP(IFNULL(vDate, vn.VN_CURDATE()), '23:59:59'); + + DROP TEMPORARY TABLE IF EXISTS tClientRisk; + CREATE TEMPORARY TABLE tClientRisk + ENGINE = MEMORY + SELECT cr.clientFk, SUM(cr.amount) amount + FROM clientRisk cr + JOIN tmp.clientGetDebt c ON c.clientFk = cr.clientFk + GROUP BY cr.clientFk; + + INSERT INTO tClientRisk + SELECT c.clientFk, SUM(r.amountPaid) + FROM receipt r + JOIN tmp.clientGetDebt c ON c.clientFk = r.clientFk + WHERE r.payed > vEnded + GROUP BY c.clientFk; + + INSERT INTO tClientRisk + SELECT t.clientFk, CAST(-SUM(t.amount) / 100 AS DECIMAL(10,2)) + FROM hedera.tpvTransaction t + JOIN tmp.clientGetDebt c ON c.clientFk = t.clientFk + WHERE t.receiptFk IS NULL + AND t.status = 'ok' + GROUP BY t.clientFk; + + INSERT INTO tClientRisk + SELECT t.clientFk, totalWithVat + FROM ticket t + JOIN tmp.clientGetDebt c ON c.clientFk = t.clientFk + WHERE refFk IS NULL + AND shipped BETWEEN vStarted AND vEnded; + + DROP TEMPORARY TABLE IF EXISTS tmp.risk; + CREATE TEMPORARY TABLE tmp.risk + (PRIMARY KEY (clientFk)) + ENGINE = MEMORY + SELECT clientFk, SUM(amount) risk + FROM client c + JOIN tClientRisk cr ON cr.clientFk = c.id + GROUP BY c.id; + + DROP TEMPORARY TABLE tClientRisk; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientGetDebtDiary` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -52663,8 +48229,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clientGetDebtDiary`(vClientFK INT, vCompanyFk INT) BEGIN @@ -52786,6 +48350,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientGreugeSpray` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -52793,8 +48359,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clientGreugeSpray`(IN vClientFk INT, IN onlyForHisOwner BOOL, IN vWorkerCode VARCHAR(3), IN vWithMana BOOLEAN) BEGIN @@ -52803,25 +48367,25 @@ BEGIN DECLARE vOwner INT; DECLARE vTotalSale INT; DECLARE vGreugeTypeFk INT DEFAULT 5; -- HERENCIA - DECLARE vGreugeTypeMana INT DEFAULT 3;-- Maná - DECLARE vMana DECIMAL(10,2); - - SELECT vn.clientGetMana(vClientFk) INTO vMana; - - IF vWithMana AND vMana THEN - + DECLARE vGreugeTypeMana INT DEFAULT 3;-- Maná + DECLARE vMana DECIMAL(10,2); + + SELECT vn.clientGetMana(vClientFk) INTO vMana; + + IF vWithMana AND vMana THEN + INSERT INTO vn.greuge( clientFk, description, - amount, - shipped, - greugeTypeFk) - VALUES( vClientFk, + amount, + shipped, + greugeTypeFk) + VALUES( vClientFk, 'Desasignación', - -1 * vMana, - util.VN_CURDATE(), - vGreugeTypeMana); - - END IF; + -1 * vMana, + vn.VN_CURDATE(), + vGreugeTypeMana); + + END IF; SELECT sum(amount) INTO vGreuge FROM vn.greuge @@ -52845,13 +48409,13 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.clientList; CREATE TEMPORARY TABLE tmp.clientList - SELECT DISTINCT t.clientFk, floor(cr.yearSale / 12) AS monthSale + SELECT DISTINCT t.clientFk, floor(cr.yearSale / 12) monthSale FROM vn.ticket t JOIN vn.client c ON c.id = t.clientFk - JOIN vn.manaSpellers ms ON ms.worker = c.salesPersonFk + JOIN vn.workerMana wm ON wm.workerFk = c.salesPersonFk JOIN vn.claimRatio cr ON cr.clientFk = c.id - WHERE ms.worker = IF(onlyForHisOwner, vOwner, ms.worker) - AND t.shipped >= TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()) + WHERE wm.workerFk = IF(onlyForHisOwner, vOwner, wm.workerFk) + AND t.shipped >= TIMESTAMPADD(MONTH,-1,vn.VN_CURDATE()) AND c.id != vClientFk HAVING monthSale > 100; @@ -52859,11 +48423,11 @@ BEGIN FROM tmp.clientList; INSERT INTO vn.greuge(clientFk, description, amount, shipped, greugeTypeFk) - SELECT clientFk, CONCAT('Cliente: ',vClientFk), vGreuge * monthSale / vTotalSale, util.VN_CURDATE(), vGreugeTypeFk + SELECT clientFk, CONCAT('Cliente: ',vClientFk), vGreuge * monthSale / vTotalSale, vn.VN_CURDATE(), vGreugeTypeFk FROM tmp.clientList UNION ALL - SELECT vClientFk, 'Reparto greuge', -vGreuge, util.VN_CURDATE(), vGreugeTypeFk; - + SELECT vClientFk, 'Reparto greuge', -vGreuge, vn.VN_CURDATE(), vGreugeTypeFk; + END IF; END ;; @@ -52872,6 +48436,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientPackagingOverstock` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -52879,8 +48445,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clientPackagingOverstock`(vClientFk INT, vGraceDays INT ) BEGIN @@ -52953,7 +48517,7 @@ BEGIN IFNULL(pe.equivalentFk, p.itemFk) itemFk, NULL, NULL, - IF(tp.quantity > 0 AND t.shipped <= TIMESTAMPADD(DAY, - vGraceDays, util.VN_CURDATE()), tp.quantity, NULL) SenttoClient, + IF(tp.quantity > 0 AND t.shipped <= TIMESTAMPADD(DAY, - vGraceDays, vn.VN_CURDATE()), tp.quantity, NULL) SenttoClient, IF(tp.quantity < 0, -tp.quantity, NULL) GotfromClient, NULL AS refFk, NULL, @@ -52969,6 +48533,7 @@ BEGIN GROUP BY x.id, x.itemFk ) t ORDER BY itemFk, shipped DESC + LIMIT 10000000000000000000 ) t2 GROUP BY itemFk; END ;; @@ -52977,6 +48542,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientPackagingOverstockReturn` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -52984,8 +48551,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clientPackagingOverstockReturn`(vClientFk INT, vGraceDays INT ) BEGIN @@ -53002,13 +48567,13 @@ BEGIN CALL vn.ticket_add( vClientFk - ,util.VN_CURDATE() + ,vn.VN_CURDATE() ,vWarehouseFk -- Algemesi ,442 -- Verdnatura ,NULL -- address ,NULL -- agencia ,NULL -- route - ,util.VN_CURDATE() + ,vn.VN_CURDATE() ,account.myUser_getId() ,TRUE ,vNewTicket); @@ -53034,62 +48599,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 `clientRandomSelection__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `clientRandomSelection__`(vNumero INT) -BEGIN - - DECLARE vClient INT; - - SET @vIndex := 0; - - DROP TEMPORARY TABLE IF EXISTS tmp.client; - - CREATE TEMPORARY TABLE tmp.client - SELECT io.clientFk, - FALSE as isSelected, - @vIndex := @vIndex + 1 id - FROM vn.client c - JOIN vn.invoiceOut io ON io.clientFk = c.id - JOIN vn.address a ON a.clientFk = c.id - JOIN vn.province p ON p.id = a.provinceFk - WHERE p.name = 'MADRID' - AND io.issued = '2019-01-31' - AND a.isDefaultAddress - AND c.name NOT LIKE 'TR %'; - - WHILE vNumero DO - - SET vClient = FLOOR(RAND() * @vIndex + 1); - - IF (SELECT isSelected FROM tmp.client WHERE id = vClient) = FALSE THEN - - UPDATE tmp.client - SET isSelected = TRUE - WHERE id = vClient; - - SET vNumero = vNumero - 1; - - END IF; - - END WHILE; - - SELECT * FROM tmp.client JOIN vn.client c ON c.id = 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 `clientRemoveWorker` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -53097,8 +48608,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clientRemoveWorker`() BEGIN @@ -53132,7 +48641,7 @@ BEGIN CALL vn.clientGreugeSpray(vClientFk, TRUE, '',TRUE); UPDATE vn.client SET salesPersonFk = NULL WHERE id = vClientFk; INSERT INTO vn.clientLog (originFk, userFk, `action`, description) - VALUES (vClientFk, account.userGetId(), 'update', CONCAT('Se ha desasignado el cliente por que no ha comprado en 3 meses')); + VALUES (vClientFk, account.myUser_getId(), 'update', CONCAT('Se ha desasignado el cliente por que no ha comprado en 3 meses')); FETCH rs INTO vClientFk; END WHILE; CLOSE rs; @@ -53143,6 +48652,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clientRisk_update` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -53150,8 +48661,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clientRisk_update`(vClientId INT, vCompanyId INT, vAmount DECIMAL(10,2)) BEGIN @@ -53171,6 +48680,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `client_checkBalance` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -53178,8 +48689,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `client_checkBalance`(IN vDateTo DATETIME, IN vIsConciliated BOOL) BEGIN @@ -53221,6 +48730,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `client_RandomList` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -53228,8 +48739,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `client_RandomList`(vNumber INT) BEGIN @@ -53251,7 +48760,7 @@ BEGIN INSERT INTO tmp.client(clientFk) SELECT DISTINCT clientFk FROM vn.invoiceOut - WHERE issued > TIMESTAMPADD(MONTH, -2, util.VN_CURDATE()); + WHERE issued > TIMESTAMPADD(MONTH, -2, vn.VN_CURDATE()); SELECT max(id) INTO maxClientFk FROM tmp.client; @@ -53293,152 +48802,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 `clonTravelComplete__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` 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 - * @param vDateStart fecha de salida del nuevo travel - * @param vDateEnd fecha de llegada del nuevo travel - * @param vRef referencia del nuevo travel -*/ - DECLARE vTravelNew INT; - 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 vRsBuy CURSOR FOR - SELECT b.* - FROM buy b - JOIN entry e ON b.entryFk = e.id - WHERE e.travelFk = vTravelNew and b.entryFk = entryNew - ORDER BY e.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - START TRANSACTION; - - INSERT INTO travel (shipped,landed, warehouseInFk, warehouseOutFk, agencyFk, ref, isDelivered, isReceived, m3, kg) - SELECT vDateStart, vDateEnd,warehouseInFk, warehouseOutFk, agencyFk, vRef, isDelivered, isReceived, m3, kg - FROM travel - WHERE id = vTravelFk; - - SET vTravelNew = LAST_INSERT_ID(); - SET vDone = FALSE; - 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, - vTravelNew, - currencyFk, - companyFk, - gestDocFk, - invoiceInFk - FROM entry - WHERE id = vAuxEntryFk; - - SET vEntryNew = LAST_INSERT_ID(); - - 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; - 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 `cmr_getByTicket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -53446,16 +48811,14 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `cmr_getByTicket`(vTicketFk INT) BEGIN - DECLARE vLandingDays INT; + DECLARE vLanded DATE; - SELECT landingDays INTO vLandingDays - FROM vn.cmrConfig; + SELECT DATE_ADD(vn.VN_CURDATE(), INTERVAL landingDays DAY) INTO vLanded + FROM vn.cmrConfig; IF vTicketFk THEN @@ -53465,11 +48828,9 @@ BEGIN ELSE - INSERT INTO vn.cmr(ticketFk, companyFk, addressFromFk, addressToFk, supplierFk, ead) - SELECT vTicketFk, t.companyFk, a.id, t.addressFk, ag.supplierFk, vLandingDays + INSERT INTO vn.cmr(ticketFk, companyFk, addressFromFk, addressToFk, ead) + SELECT vTicketFk, t.companyFk, a.id, t.addressFk, vLanded FROM vn.ticket t - JOIN vn.agencyMode am ON am.id = t.agencyModeFk - JOIN vn.agency ag ON ag.id = am.agencyFk JOIN vn.warehouse w ON w.id = t.warehouseFk JOIN vn.address a ON a.id = w.addressFk WHERE t.id = vTicketFk; @@ -53480,7 +48841,7 @@ BEGIN ELSE - INSERT INTO vn.cmr(created, ead) VALUES(util.VN_NOW(), util.VN_NOW() + INTERVAL vLandingDays DAY); + INSERT INTO vn.cmr(ead) VALUES(vLanded); SELECT LAST_INSERT_ID(); @@ -53491,55 +48852,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 `cmr_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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `cmr_new__`(vTicketFk INT) -BEGIN - - IF vTicketFk THEN - - IF (SELECT count(ticketFk) FROM vn.cmr WHERE ticketFk = vTicketFk) THEN - - SELECT id FROM vn.cmr WHERE ticketFk = vTicketFk; - - ELSE - - INSERT INTO vn.cmr(ticketFk, companyFk, addressFromFk, addressToFk, supplierFk) - SELECT vTicketFk, t.companyFk, a.id, t.addressFk, ag.supplierFk - FROM vn.ticket t - JOIN vn.agencyMode am ON am.id = t.agencyModeFk - JOIN vn.agency ag ON ag.id = am.agencyFk - JOIN vn.company cm ON cm.id = t.companyFk - JOIN vn.client c ON c.id = cm.clientFk - JOIN vn.address a ON a.clientFk = c.id AND a.isDefaultAddress - WHERE t.id = vTicketFk; - - SELECT LAST_INSERT_ID(); - - END IF; - - ELSE - - INSERT INTO vn.cmr(created) VALUES(util.VN_NOW()); - - SELECT LAST_INSERT_ID(); - - END IF; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `cmr_sendOverview` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -53547,8 +48861,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `cmr_sendOverview`() BEGIN @@ -53557,7 +48869,7 @@ BEGIN */ SET SESSION group_concat_max_len = 1000000; --- IF (DAY(util.VN_CURDATE()) = 5) THEN +-- IF (DAY(vn.VN_CURDATE()) = 5) THEN INSERT INTO vn.mail (receiver, replyTo, @@ -53574,7 +48886,7 @@ BEGIN Estimado cliente,
- A continuación le enviamos el resumen menual de CMR ',UPPER(MONTHNAME(util.VN_CURDATE() - INTERVAL 1 MONTH)),' ', YEAR(util.VN_CURDATE() - INTERVAL 1 MONTH), '.

+ A continuación le enviamos el resumen menual de CMR ',UPPER(MONTHNAME(vn.VN_CURDATE() - INTERVAL 1 MONTH)),' ', YEAR(vn.VN_CURDATE() - INTERVAL 1 MONTH), '.

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


@@ -53593,8 +48905,8 @@ BEGIN 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(util.VN_CURDATE() - INTERVAL 1 MONTH) - AND YEAR(c.created) = YEAR(util.VN_CURDATE() - INTERVAL 1 MONTH) + AND MONTH(c.created) = MONTH(vn.VN_CURDATE() - INTERVAL 1 MONTH) + AND YEAR(c.created) = YEAR(vn.VN_CURDATE() - INTERVAL 1 MONTH) AND c2.email IS NOT NULL -- No cogemos los CMRs dirigidos a 'Verdnatura' GROUP BY c2.id; @@ -53602,8 +48914,8 @@ BEGIN UPDATE vn.cmr c SET c.state = 'Sent' WHERE c.state = 'Pending' - AND MONTH(c.created) = MONTH(util.VN_CURDATE() - INTERVAL 1 MONTH) - AND YEAR(c.created) = YEAR(util.VN_CURDATE() - INTERVAL 1 MONTH); + AND MONTH(c.created) = MONTH(vn.VN_CURDATE() - INTERVAL 1 MONTH) + AND YEAR(c.created) = YEAR(vn.VN_CURDATE() - INTERVAL 1 MONTH); -- END IF; END ;; DELIMITER ; @@ -53611,50 +48923,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 `collectionOrTicket_printSticker` */; -/*!50003 SET @saved_cs_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`@`localhost` PROCEDURE `collectionOrTicket_printSticker`(vParam INT, vSectorFk INT) -BEGIN - - /*Imprime una etiqueta amarilla a partir de una colección o ticket - * - * @param vParam colección o ticket a imprimir - * @param vSectorFk id del sector - */ - - DECLARE vLabelReport INT; - - SELECT labelReportFk INTO vLabelReport - FROM sector - WHERE id = vSectorFk; - - IF vLabelReport THEN - - INSERT INTO ticketTrolley(ticket, labelCount) - SELECT ticketFk, 1 - FROM ticketCollection - WHERE collectionFk = vParam OR ticketFK = vParam - ON DUPLICATE KEY UPDATE labelCount = labelCount + 1; - - INSERT INTO printServerQueue(labelReportFk, param1, workerFk) - SELECT vLabelReport, vParam, getUser(); - - 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 sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `collectionPlacement_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -53662,8 +48932,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `collectionPlacement_get`(vParamFk INT(11), vIsPicker bool) BEGIN @@ -53677,7 +48945,7 @@ BEGIN DECLARE vCalcFk INT; DECLARE vWarehouseFk INT; DECLARE vWarehouseAliasFk INT; - DECLARE vCurrentYear INT DEFAULT YEAR(util.VN_NOW()); + DECLARE vCurrentYear INT DEFAULT YEAR(vn.VN_NOW()); DROP TEMPORARY TABLE IF EXISTS tmp.sale; CREATE TEMPORARY TABLE tmp.sale @@ -53751,7 +49019,7 @@ BEGIN ts.itemFk, CAST(0 AS DECIMAL(10,0)) as saleOrder, IF(ts.isStowaway, - 100000, IF(ish.visible > 0 OR iss.id, 1, 100000)) * p.pickingOrder as `order`, - IF(iss.id, TO_SECONDS(TIMESTAMPADD(YEAR,-vCurrentYear,iss.created)), TO_SECONDS(TIMESTAMPADD(YEAR,- year(ish.created),ish.created)) /* + TO_SECONDS(TIMESTAMPADD(YEAR,-vCurrentYear,util.VN_NOW())) */ ) as priority, + IF(iss.id, TO_SECONDS(TIMESTAMPADD(YEAR,-vCurrentYear,iss.created)), TO_SECONDS(TIMESTAMPADD(YEAR,- year(ish.created),ish.created)) /* + TO_SECONDS(TIMESTAMPADD(YEAR,-vCurrentYear,vn.VN_NOW())) */) as priority, CONCAT( IF( iss.id, CONCAT('< ', IFNULL(wk.`code`, '---'),' > '), @@ -53798,6 +49066,7 @@ BEGIN IF(visible > 0 OR itemShelvingSaleFk,1,2), IFNULL(shelvingPriority,0) DESC, priority + LIMIT 10000000000000000000 ) sub GROUP BY saleFk; @@ -53839,46 +49108,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 `collectionSticker_print` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `collectionSticker_print`(vCollectionFk INT, vSectorFk INT) -BEGIN - - /*@deprecated :utilizar collectionOrTicket_printSticker*/ - - DECLARE vLabelReport INT; - - SELECT labelReportFk INTO vLabelReport - FROM vn.sector - WHERE id = vSectorFk; - - IF vLabelReport THEN - - INSERT INTO vn.ticketTrolley(ticket, labelCount) - SELECT ticketFk, 1 - FROM vn.ticketCollection - WHERE collectionFk = vCollectionFk - ON DUPLICATE KEY UPDATE labelCount = labelCount + 1; - - INSERT INTO vn.printServerQueue(labelReportFk, param1, workerFk) - SELECT vLabelReport, vCollectionFk, getUser(); - - 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 `collection_addItem` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -53886,8 +49117,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_addItem`(vItemFk INT, vQuantity INT, vTicketFk INT) BEGIN @@ -53900,7 +49129,7 @@ BEGIN SELECT barcodeToItem(vItemFk) INTO itemFk; - SELECT CONCAT(vn.getUser()," ",DATE_FORMAT(util.VN_NOW( ), "%H:%i" )," ",i.name) INTO vConcept FROM vn.item i WHERE i.id = itemFk; + SELECT CONCAT(vn.getUser()," ",DATE_FORMAT(vn.VN_NOW( ), "%H:%i" )," ",i.name) INTO vConcept FROM vn.item i WHERE i.id = itemFk; SELECT name INTO vItemName FROM vn.item WHERE id = vItemFk; SELECT CONCAT("Añadido articulo ", vItemName, " cantidad:", vQuantity) INTO vDescription; @@ -53921,6 +49150,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `collection_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -53928,8 +49159,6 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `collection_get`(vWorkerFk INT) BEGIN @@ -53946,7 +49175,7 @@ BEGIN JOIN vn.state ss on ss.code = 'PREPARED' LEFT JOIN vn.saleTracking st on st.saleFk = s.id AND st.stateFk = ss.id WHERE c.workerFk = vWorkerFk - AND c.created >= TIMESTAMPADD(HOUR , -6,util.VN_NOW()) + AND c.created >= TIMESTAMPADD(HOUR , -6,vn.VN_NOW()) AND s.quantity != 0 GROUP BY c.id HAVING totalRow > pickedRow; @@ -53957,6 +49186,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `collection_getTickets` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -53964,8 +49195,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_getTickets`(vParamFk INT) BEGIN @@ -54030,6 +49259,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `collection_get_` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -54037,30 +49268,30 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_get_`(vWorkerFk INT) -BEGIN - - /* Obtiene colección del sacador si tiene líneas pendientes - * - * @param vWorkerFk id del worker - */ - - 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,util.VN_NOW()); - - +BEGIN + + /* Obtiene colección del sacador si tiene líneas pendientes + * + * @param vWorkerFk id del worker + */ + + 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,vn.VN_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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `collection_kill` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -54068,31 +49299,31 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_kill`(vSelf INT) -BEGIN - - /* Elimina una coleccion y coloca sus tickets en OK - * - */ - - INSERT INTO vncontrol.inter(state_id, Id_Ticket) - SELECT s.id, ticketFk - FROM vn.ticketCollection tc - JOIN vn.state s ON s.code = 'OK' - WHERE tc.collectionFk = vSelf; - - DELETE FROM vn.collection - WHERE id = vSelf; - +BEGIN + + /* Elimina una coleccion y coloca sus tickets en OK + * + */ + + INSERT INTO vncontrol.inter(state_id, Id_Ticket) + SELECT s.id, ticketFk + FROM vn.ticketCollection tc + JOIN vn.state s ON s.code = 'OK' + WHERE tc.collectionFk = vSelf; + + DELETE FROM vn.collection + WHERE id = vSelf; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `collection_missingTrash` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -54100,8 +49331,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_missingTrash`(vSaleFk BIGINT, vQuantity INT, vIsTrash BOOLEAN, vWarehouseFk INT, vNewQuantity INT) BEGIN @@ -54125,7 +49354,7 @@ BEGIN INSERT INTO vn.ticketLog (originFk, userFk, action , description) VALUES(vOrigin, vn.getUser(), 'update', vDescription); - SELECT t.id INTO vTicketFk FROM vn.ticket t WHERE t.created > DATE_SUB(util.VN_NOW(), INTERVAL 1 DAY) AND t.clientFk = vClientFk AND t.warehouseFk = vWarehouseFk LIMIT 1; + SELECT t.id INTO vTicketFk FROM vn.ticket t WHERE t.created > DATE_SUB(vn.VN_NOW(), INTERVAL 1 DAY) AND t.clientFk = vClientFk AND t.warehouseFk = vWarehouseFk LIMIT 1; IF vTicketFk IS NULL THEN SELECT c.name , co.id INTO vClientName,vConsignatario @@ -54135,22 +49364,22 @@ BEGIN LIMIT 1; CALL ticket_add(vClientFk, - util.VN_NOW(), vWarehouseFk, + vn.VN_NOW(), vWarehouseFk, 442, vConsignatario, NULL, NULL, NULL, - account.userGetId(), + account.myUser_getId(), TRUE, vTicketFk); - SELECT t.id INTO vTicketFk FROM vn.ticket t WHERE t.created > DATE_SUB(util.VN_NOW(), INTERVAL 1 DAY) AND t.clientFk = vClientFk AND t.warehouseFk = vWarehouseFk LIMIT 1; + SELECT t.id INTO vTicketFk FROM vn.ticket t WHERE t.created > DATE_SUB(vn.VN_NOW(), INTERVAL 1 DAY) AND t.clientFk = vClientFk AND t.warehouseFk = vWarehouseFk LIMIT 1; END IF; INSERT INTO vn.sale (itemFk, ticketFk, concept, quantity, originalQuantity, price, discount, priceFixed, reserved, isPicked, isPriceFixed, created, isAdded) - SELECT itemFk, vTicketFk, CONCAT(concept," ",vn.getWorkerCode(), " ",LEFT(CAST(util.VN_NOW() AS TIME),5)), vQuantity, originalQuantity, price, discount, priceFixed, reserved, isPicked, isPriceFixed, created, isAdded + SELECT itemFk, vTicketFk, CONCAT(concept," ",vn.getWorkerCode(), " ",LEFT(CAST(vn.VN_NOW() AS TIME),5)), vQuantity, originalQuantity, price, discount, priceFixed, reserved, isPicked, isPriceFixed, created, isAdded FROM vn.sale s WHERE s.id = vSaleFk; SELECT quantity INTO vOriginalQuantity FROM vn.sale WHERE id = vSaleFk; @@ -54162,6 +49391,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `collection_newSmartTag` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -54169,523 +49400,61 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` 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 vWorkerFk INT; DECLARE vWagons INT; - - SELECT w.code, w.id INTO vWorkerCode, vWorker + DECLARE vCollectionFk INT; + + SELECT w.id INTO vWorkerFk 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,util.VN_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; + SELECT COUNT(ws.id) INTO vWagons + FROM workerShelving ws + WHERE ws.workerFk = vWorkerFk + AND ws.collectionFk IS NULL; - -- 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; + CALL collection_newWithWagon(vSectorFk, vWagons); - 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 = util.VN_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 = util.VN_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, util.VN_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; + SELECT id INTO vCollectionFk + FROM collection + WHERE workerFk = vWorkerFk + ORDER BY created DESC + LIMIT 1; - -- 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 + UPDATE workerShelving ws + SET ws.collectionFk = vCollectionFk + WHERE ws.workerFk = vWorkerFk + AND ws.collectionFk IS NULL; + + SET @wagon := 0; + + DROP TEMPORARY TABLE IF EXISTS tmp.smartTags; + CREATE TEMPORARY TABLE tmp.smartTags + SELECT s.code, sub.wagon, s.level 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 + 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; + WHERE ws.collectionFk = vCollectionFk) sub + JOIN smartTag s ON s.shelvingFk = sub.shelvingFk + ORDER BY wagon ASC, level ASC; - -- 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; - + UPDATE vn.ticketCollection tc + JOIN tmp.smartTags ts ON tc.wagon = ts.wagon AND tc.level = ts.level + SET tc.smartTagFk = ts.code + WHERE tc.collectionFk = vCollectionFk; + + DROP TEMPORARY TABLE tmp.smartTags; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `collection_newWithWagon` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -54693,8 +49462,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_newWithWagon`(vSectorFk INT, vWagons INT) proc:BEGIN @@ -54734,7 +49501,7 @@ proc:BEGIN SELECT w.code, w.id INTO vWorkerCode, vUserFk FROM vn.worker w - WHERE w.id =account.userGetId(); + WHERE w.id =account.myUser_getId(); -- 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 @@ -54762,7 +49529,7 @@ proc:BEGIN JOIN vn.state ss ON ss.code = 'PREPARED' LEFT JOIN vn.saleTracking st ON st.saleFk = s.id AND st.stateFk = ss.id WHERE c.workerFk = vUserFk - AND c.created >= TIMESTAMPADD(HOUR , -6,util.VN_NOW()) + AND c.created >= TIMESTAMPADD(HOUR , -6,vn.VN_NOW()) AND s.quantity != 0 GROUP BY c.id HAVING totalRow > pickedRow) sub; @@ -54881,7 +49648,7 @@ proc:BEGIN JOIN vn.agencyMode am ON am.id = pb.agencyModeFk JOIN vn.agency a ON a.id = am.agencyFk JOIN vn.productionConfig pc - WHERE pb.shipped = util.VN_CURDATE() + WHERE pb.shipped = vn.VN_CURDATE() AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) AND s.isPreparable @@ -54907,7 +49674,7 @@ proc:BEGIN JOIN vn.ticket t ON t.id = pb.ticketFk JOIN vn.ticketConfig tc JOIN vn.productionConfig pc - WHERE pb.shipped = util.VN_CURDATE() + WHERE pb.shipped = vn.VN_CURDATE() AND (LENGTH(pb.problem) = 0 OR (pb.problem = 'PEQUEÑO' AND vTrainFk = 2)) AND (pb.ubicacion IS NOT NULL @@ -54919,7 +49686,7 @@ proc:BEGIN OR (pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV)) OR (pb.H = 0 AND pb.V = 0 AND pb.N > 0 AND ISNULL(pb.collectionH) AND ISNULL(pb.collectionV)) ) - AND t.created < TIMESTAMPADD(MINUTE, - tc.pickingDelay , util.VN_NOW()) + AND t.created < TIMESTAMPADD(MINUTE, - tc.pickingDelay , vn.VN_NOW()) AND (pc.isPreviousPreparationRequired = FALSE OR pb.previousWithoutParking = FALSE) ORDER BY HH, @@ -55290,6 +50057,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `collection_newWithWagon_beta` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -55297,8 +50066,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_newWithWagon_beta`(vUserFk INT, vSectorFk INT, vWagons INT) proc:BEGIN @@ -55326,7 +50093,7 @@ proc:BEGIN DECLARE vTrainFk INT DEFAULT 1; DECLARE vNow DATETIME; - SELECT ticketPrintedMax * vWagons, ticketTrolleyMax * vWagons, pc.maxNotReadyCollections , util.VN_NOW() + SELECT ticketPrintedMax * vWagons, ticketTrolleyMax * vWagons, pc.maxNotReadyCollections , vn.VN_NOW() INTO vMaxTicketPrinted, vMaxTickets, vMaxNotReadyCollections, vNow FROM vn.productionConfig pc; @@ -55359,7 +50126,7 @@ proc:BEGIN JOIN vn.state ss ON ss.code = 'PREPARED' LEFT JOIN vn.saleTracking st ON st.saleFk = s.id AND st.stateFk = ss.id WHERE c.workerFk = vUserFk - AND c.created >= TIMESTAMPADD(HOUR , -6,util.VN_NOW()) + AND c.created >= TIMESTAMPADD(HOUR , -6,vn.VN_NOW()) AND s.quantity != 0 GROUP BY c.id HAVING totalRow > pickedRow) sub; @@ -55480,7 +50247,7 @@ call util.debugAdd('wargo',CONCAT('vNotReadyCollections ',vNotReadyCollections)) JOIN vn.agencyMode am ON am.id = pb.agencyModeFk JOIN vn.agency a ON a.id = am.agencyFk JOIN vn.productionConfig pc - WHERE pb.shipped = util.VN_CURDATE() + WHERE pb.shipped = vn.VN_CURDATE() AND (pb.ubicacion IS NOT NULL OR a.isOwn = FALSE ) AND s.isPreparable @@ -55509,7 +50276,7 @@ call util.debugAdd('wargo',CONCAT('vPrintedTickets ',vPrintedTickets)); JOIN vn.ticket t ON t.id = pb.ticketFk JOIN vn.ticketConfig tc JOIN vn.productionConfig pc - WHERE pb.shipped = util.VN_CURDATE() + WHERE pb.shipped = vn.VN_CURDATE() AND (LENGTH(pb.problem) = 0 OR (pb.problem = 'PEQUEÑO' AND vTrainFk = 2)) AND (pb.ubicacion IS NOT NULL @@ -55521,7 +50288,7 @@ call util.debugAdd('wargo',CONCAT('vPrintedTickets ',vPrintedTickets)); OR (pb.V > 0 AND vItemPackingTypeFk = 'V' AND ISNULL(pb.collectionV)) OR (pb.N > 0 AND ISNULL(pb.collectionH) AND ISNULL(pb.collectionV)) ) - AND t.created < TIMESTAMPADD(MINUTE, - tc.pickingDelay , util.VN_NOW()) + AND t.created < TIMESTAMPADD(MINUTE, - tc.pickingDelay , vn.VN_NOW()) AND (pc.isPreviousPreparationRequired = FALSE OR pb.previousWithoutParking = FALSE) ORDER BY HH, @@ -55923,6 +50690,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `collection_printSticker` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -55930,47 +50699,68 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_printSticker`(vCollection INT) +CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_printSticker`(vSelf INT) BEGIN +/** + * Imprime una etiqueta amarilla a partir de una colección + * + * @param vSelf colección + * @param vPrinterFk id de la impresora + */ + DECLARE vReportFk INT; + DECLARE vPrinterFk INT; - /*Imprime una etiqueta amarilla a partir de una colección - * - * @param vCollection colección - * @param vPrinterFk id de la impresora - */ - - DECLARE vLabelReportFk INT; - DECLARE vLabelerFk INT; - - - SELECT s.labelReportFk, w.labelerFk INTO vLabelReportFk, vLabelerFk + SELECT s.reportFk, w.labelerFk INTO vReportFk, vPrinterFk FROM worker w LEFT JOIN sector s ON s.id= w.sectorFk - WHERE w.id=account.myUser_getId() ; - - - IF vLabelReportFk AND vLabelerFk THEN + WHERE w.id = account.myUser_getId() ; + IF vReportFk AND vPrinterFk THEN INSERT INTO ticketTrolley(ticket, labelCount) SELECT ticketFk, 1 FROM ticketCollection - WHERE collectionFk = vCollection + WHERE collectionFk = vSelf ON DUPLICATE KEY UPDATE labelCount = labelCount + 1; - INSERT INTO printServerQueue(labelReportFk, param1, workerFk,printerFk) - SELECT vLabelReportFk, vCollection, getUser(),vLabelerFk; - + INSERT INTO printQueue(priorityFk, reportFk, workerFk,printerFk) + SELECT qp.id, vReportFk, account.myUser_getId(), vPrinterFk + FROM queuePriority qp + WHERE qp.`code`= 'high'; + + INSERT INTO printQueueArgs (printQueueFk, `name`, `value` ) + SELECT LAST_INSERT_ID(), 'param', vSelf; 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `collection_setParking` */; +/*!50003 SET @saved_cs_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_setParking`(IN `vCollectionFk` VARCHAR(8), IN `vParkingFk` INT) +proc: BEGIN + REPLACE vn.ticketParking(ticketFk, parkingFk) + SELECT tc.ticketFk, vParkingFk + FROM vn.ticketCollection tc + WHERE tc.collectionFk = vCollectionFk; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `collection_updateSale` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -55978,8 +50768,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `collection_updateSale`( vSaleFk INT, @@ -56022,6 +50810,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `company_getFiscaldata` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56029,37 +50819,37 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `company_getFiscaldata`(workerFk INT) -BEGIN - -DECLARE vCompanyFk INT; - - SELECT IFNULL(uc.companyFk, rc.defaultCompanyFk) - INTO vCompanyFk - FROM vn.routeConfig rc - LEFT JOIN userConfig uc ON uc.userFk = workerFk; - - - SELECT - s.name AS name , - s.NIF AS nif , - s.street AS street , - s.city AS city , - s.postCode AS postCode - - FROM vn.company c - JOIN vn.worker w ON w.id = c.workerManagerFk - JOIN vn.supplier s ON s.id = c.id - WHERE c.id = vCompanyFk; +BEGIN + +DECLARE vCompanyFk INT; + + SELECT IFNULL(uc.companyFk, rc.defaultCompanyFk) + INTO vCompanyFk + FROM vn.routeConfig rc + LEFT JOIN userConfig uc ON uc.userFk = workerFk; + + + SELECT + s.name AS name , + s.NIF AS nif , + s.street AS street , + s.city AS city , + s.postCode AS postCode + + FROM vn.company c + JOIN vn.worker w ON w.id = c.workerManagerFk + JOIN vn.supplier s ON s.id = c.id + WHERE c.id = vCompanyFk; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `conveyorExpedition_Add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56067,8 +50857,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `conveyorExpedition_Add`(vStarted DATETIME, vEnded DATETIME) BEGIN @@ -56125,6 +50913,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `copyComponentsFromSaleList` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56132,8 +50922,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `copyComponentsFromSaleList`(vTargetTicketFk INT) BEGIN @@ -56172,6 +50960,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `createPedidoInterno` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56179,8 +50969,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `createPedidoInterno`(vItemFk INT,vQuantity INT) BEGIN @@ -56194,115 +50982,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 `cristalBall__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `cristalBall__`() -BEGIN -/* -*se utiliza en campaña -* sirve para tener un control del stock en Silla y fuentes -* -*/ - -DECLARE vLastDate DATETIME DEFAULT '2019-10-30 23:59'; -DECLARE vWarehouse INT DEFAULT 1; -DECLARE vPalletVolume INT DEFAULT 2200000; - -SELECT date(sub2.dat) dat, - sub2.longName, - sub2.size, - sub2.subName, - cast(sub2.entra as decimal(10,1)) as entra, - cast(sub2.sale as decimal(10,1)) as sale, - sub2.itemFk, - @saldo := entra + sale + ifnull(fue.pal,0) + IF(sub2.itemFk = @item, @saldo, 0) as saldo, - @item := sub2.itemFk as kk, - cast(fue.pal as decimal(10,1)) as pal -FROM -( - SELECT * FROM - ( - SELECT e.dat, - e.item_id as itemFk, - i.longName, - i.size, - i.subName, - sum(e.amount * r.cm3) / vPalletVolume as entra, - 0 as sale - FROM vn2008.item_entry_in e - JOIN vn.item i ON i.id = e.item_id - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - JOIN bi.rotacion r ON r.Id_Article = e.item_id AND r.warehouse_id = e.warehouse_id - WHERE e.dat BETWEEN util.VN_CURDATE() AND vLastDate - AND e.warehouse_id = vWarehouse - AND ic.display - AND e.isVirtualStock is FALSE - GROUP BY e.dat, e.item_id - - UNION ALL - - SELECT s.dat, - s.item_id as itemFk, - i.longName, - i.size, - i.subName, - 0 as entra, - sum(s.amount * r.cm3) / vPalletVolume as sale - FROM vn2008.item_out s - JOIN vn.item i ON i.id = s.item_id - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - JOIN bi.rotacion r ON r.Id_Article = s.item_id AND r.warehouse_id = s.warehouse_id - WHERE s.dat BETWEEN util.VN_CURDATE() AND vLastDate - AND s.warehouse_id = vWarehouse - AND ic.display - GROUP BY date(s.dat), s.item_id - - UNION ALL - - SELECT util.yesterday(), - @item := st.item_id as itemFk, - i.longName, - i.size, - i.subName, - st.amount * r.cm3 / vPalletVolume , - @saldo := 0 - FROM cache.stock st - JOIN vn.item i ON i.id = st.item_id - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - JOIN bi.rotacion r ON r.Id_Article = st.item_id AND r.warehouse_id = st.warehouse_id - WHERE st.warehouse_id = vWarehouse - AND ic.display - - ) sub - ORDER BY itemFk, dat, entra DESC) sub2 - LEFT JOIN - ( - SELECT itemFk, - - sum(ish.visible ) * r.cm3 / vPalletVolume as pal - FROM vn.itemShelving ish - JOIN bi.rotacion r ON r.Id_Article = ish.itemFk AND r.warehouse_id = 1 - LEFT JOIN vn.shelving sh ON sh.code = ish.shelvingFk - LEFT JOIN vn.parking p ON p.id = sh.parkingFk - WHERE (sh.code = 'FUE' OR p.code = 'FUE-PI') - GROUP BY itemFk) fue ON fue.itemFk = sub2.itemFk AND sub2.dat = util.yesterday() - ; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `crypt` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56310,8 +50991,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `crypt`(vText VARCHAR(255), vKey VARCHAR(255), OUT vResult VARCHAR(255) ) BEGIN @@ -56373,6 +51052,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `cryptOff` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56380,8 +51061,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `cryptOff`(vText VARCHAR(255), vKey VARCHAR(255), OUT vResult VARCHAR(255)) BEGIN @@ -56440,6 +51119,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `dayMinuteWorker` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56447,8 +51128,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `dayMinuteWorker`(vDateFrom DATETIME, vDateTo DATETIME) BEGIN @@ -56462,26 +51141,26 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.dayMinuteWorker; CREATE TEMPORARY TABLE tmp.dayMinuteWorker SELECT sub3.id, - sub3.hh AS `Hour`, - sub3.mm AS Minut, + sub3.hh `Hour`, + sub3.mm Minut, sub3.userFk, - sub3.code AS workerCode, - sub3.firstname AS name, - sub3.lastName AS surnames, - sub3.workcenterFk AS center, - w.name AS centerName, - w2.name AS warehouseName, - w2.hasProduction AS production - FROM postgresql.workcenter w + sub3.code workerCode, + sub3.firstname name, + sub3.lastName surnames, + sub3.workcenterFk center, + w.name centerName, + w2.name warehouseName, + w2.hasProduction production + FROM vn.workCenter w JOIN(SELECT id, hh, mm, userFk, code, firstname, - lastName, + lastName, @ordr := IF(@user != userFk,0,@ordr), - IF(@ordr MOD 2, 'presente','--') AS state, + IF(@ordr MOD 2, 'presente','--') state, @ordr := IFNULL(sub2.`order`,@ordr), @user := IFNULL(sub2.`userFk`,@user), workcenterFk @@ -56503,7 +51182,7 @@ BEGIN FROM vn.workerTimeControl wtc JOIN vn.worker w ON w.userFk = wtc.userFk JOIN vn.workerLabour wl ON wl.workerFK = w.id - AND wtc.timed BETWEEN wl.started AND IFNULL(wl.ended, util.VN_CURDATE()) + AND wtc.timed BETWEEN wl.started AND IFNULL(wl.ended, vn.VN_CURDATE()) WHERE wtc.timed BETWEEN vDateStart AND vDateEnd ) users LEFT JOIN(SELECT `order`, @@ -56515,7 +51194,7 @@ BEGIN ) sub ON sub.dayMinuteFk = dm.id AND sub.userFk = users.userFk ORDER BY userFk,dm.id ) sub2 - ) sub3 ON sub3.workcenterFk = w.workcenter_id + ) sub3 ON sub3.workcenterFk = w.id JOIN vn.warehouse w2 ON w2.id = w.warehouseFk WHERE state = 'presente' AND sub3.id BETWEEN HOUR(vDateFrom) *100 + MINUTE(vDateFrom) @@ -56527,6 +51206,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `department_calcTree` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56534,8 +51215,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `department_calcTree`() BEGIN @@ -56571,6 +51250,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `department_calcTreeRec` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56578,8 +51259,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `department_calcTreeRec`( vSelf INT, @@ -56653,6 +51332,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `department_doCalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56660,8 +51341,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `department_doCalc`() proc: BEGIN @@ -56695,6 +51374,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `department_getHasMistake` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56702,28 +51383,28 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `department_getHasMistake`() -BEGIN - -/** - * Obtiene los sectores a los cuales les ponemos errores - * - */ - - SELECT id, name - FROM department - WHERE hasToMistake <> FALSE; - - +BEGIN + +/** + * Obtiene los sectores a los cuales les ponemos errores + * + */ + + SELECT id, name + FROM department + WHERE hasToMistake <> 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `department_getLeaves` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56731,8 +51412,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `department_getLeaves`( vParentFk INT, @@ -56815,6 +51494,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `deviceLog_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56822,28 +51503,28 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `deviceLog_add`(vWorkerFk INT, vAppName VARCHAR(45), vAppVersion VARCHAR(45), vAndroid_id VARCHAR(100)) -BEGIN -/* - * Inserta registro en tabla devicelog el log del usuario conectado - * @param vAppName es el nombre de la app - * @param vAppVersion es la versión de la app - * @param vAndroid_id es el android_id del dispositivo que se ha logueado - */ - - INSERT INTO deviceLog (userFK, nameApp, versionApp, android_id) - VALUES(vWorkerFk, vAppName, vAppVersion, vAndroid_id); - - +BEGIN +/* + * Inserta registro en tabla devicelog el log del usuario conectado + * @param vAppName es el nombre de la app + * @param vAppVersion es la versión de la app + * @param vAndroid_id es el android_id del dispositivo que se ha logueado + */ + + INSERT INTO deviceLog (userFK, nameApp, versionApp, android_id) + VALUES(vWorkerFk, vAppName, vAppVersion, 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `deviceProductionUser_exists` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56851,8 +51532,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `deviceProductionUser_exists`(vUserFk INT) BEGIN @@ -56868,6 +51547,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `deviceProductionUser_getWorker` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56875,29 +51556,29 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` 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 103; -/* SELECT account.user_getNameFromId(dpu.userFk) - FROM deviceProductionUser dpu - JOIN deviceProduction dp ON dpu.deviceProductionFk = dp.id - WHERE dp.android_id = vAndroid_id;*/ - +BEGIN +/** + * Selecciona si hay registrado un device con un android_id + * + * @param vAndroid_id el número android_id del dispositivo + * + */ + SELECT 103; +/* 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `deviceProduction_getnameDevice` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56905,28 +51586,28 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` 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; - +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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `device_checkLogin` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -56934,8 +51615,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `device_checkLogin`(vUserFk INT, vAndroidID VARCHAR(50)) BEGIN @@ -56983,61 +51662,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 `device_checkLogin__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `device_checkLogin__`(vUserFk INT, vAndroidID VARCHAR(50)) -BEGIN - -/* - * Comprueba si está registrado el dispositivo mediante su androidId - * - * @param vUSerFk el id del user - * @param vAndroidID es el identificador android_id del dispositivo - */ - DECLARE vIsAuthorized BOOL DEFAULT TRUE; - DECLARE vIsDepartment BOOL; - DECLARE vMessage VARCHAR(200); - - SELECT COUNT(*) INTO vIsDepartment - FROM vn.workerDepartment dp - JOIN department d ON d.id = dp.departmentFk - WHERE dp.workerFk = vUserFk AND d.name = "PRODUCCION"; - - IF vIsDepartment THEN - - SELECT COUNT(*) INTO vIsAuthorized - FROM vn.deviceProductionUser dpu - JOIN vn.deviceProduction dp ON dp.id = dpu.deviceProductionFk - WHERE dpu.userFk = vUserFk - AND dp.android_id = vAndroidID; - - - IF NOT vIsAuthorized THEN - - SET vMessage = 'Usuario no autorizado'; - - END IF; - - END IF; - - - #vIsAuthorized = TRUE; #Descomentar esta linea si se quiere quitar la comprobación de autorizacion - SELECT vIsAuthorized,vMessage; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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 */ ; @@ -57045,8 +51671,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `duaEntryValueUpdate`(vDuaFk INT) BEGIN @@ -57079,6 +51703,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `duaInvoiceInBooking` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -57086,8 +51712,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `duaInvoiceInBooking`(vDuaFk INT) BEGIN @@ -57162,88 +51786,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 `duaInvoiceInBooking__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `duaInvoiceInBooking__`(vDuaFk INT) -BEGIN - DECLARE done BOOL DEFAULT FALSE; - DECLARE vInvoiceFk INT; - DECLARE vASIEN BIGINT DEFAULT 0; - DECLARE vCounter INT DEFAULT 0; - - DECLARE rs CURSOR FOR - SELECT e.invoiceInFk - FROM entry e - JOIN duaEntry de ON de.entryFk = e.id - JOIN invoiceIn ii ON ii.id = e.invoiceInFk - WHERE de.duaFk = vDuaFk - AND de.customsValue - AND ii.isBooked = FALSE; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - OPEN rs; - - UPDATE invoiceIn ii - JOIN entry e ON e.invoiceInFk = ii.id - JOIN duaEntry de ON de.entryFk = e.id - JOIN dua d ON d.id = de.duaFk - SET ii.isBooked = TRUE, - ii.booked = IFNULL(ii.booked,d.booked), - ii.operated = IFNULL(ii.operated,d.operated), - ii.issued = IFNULL(ii.issued,d.issued), - ii.bookEntried = IFNULL(ii.bookEntried,d.bookEntried), - e.isConfirmed = TRUE - WHERE d.id = vDuaFk; - - SELECT IFNULL(ASIEN,0) INTO vASIEN - FROM dua - WHERE id = vDuaFk; - - FETCH rs INTO vInvoiceFk; - - WHILE NOT done DO - - CALL invoiceInBookingMain(vInvoiceFk); - - IF vCounter > 0 OR vASIEN > 0 THEN - - UPDATE XDiario x - JOIN config c ON c.ASIEN = x.ASIEN - SET x.ASIEN = vASIEN; - - ELSE - - SELECT ASIEN INTO vASIEN FROM config; - - END IF; - - SET vCounter = vCounter + 1; - - FETCH rs INTO vInvoiceFk; - - END WHILE; - - CLOSE rs; - - UPDATE dua - SET ASIEN = vASIEN - WHERE id = vDuaFk; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `duaParcialMake` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -57251,8 +51795,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `duaParcialMake`(vDuaFk INT) BEGIN @@ -57278,6 +51820,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `duaTaxBooking` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -57285,8 +51829,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `duaTaxBooking`(vDuaFk INT) BEGIN @@ -57295,7 +51837,7 @@ BEGIN DECLARE vDiff DECIMAL(10,2); DECLARE vApunte BIGINT; - SELECT ASIEN, IFNULL(bookEntried, util.VN_CURDATE()) INTO vBookNumber, vBookDated + SELECT ASIEN, IFNULL(bookEntried, vn.VN_CURDATE()) INTO vBookNumber, vBookDated FROM dua WHERE id = vDuaFk; @@ -57399,6 +51941,7 @@ BEGIN WHERE ta.effectived <= vBookDated AND taxAreaFk = 'WORLD' ORDER BY ta.effectived DESC + LIMIT 10000000000000000000 ) tba GROUP BY rate ) tr ON tr.rate = dt.rate @@ -57425,250 +51968,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 `duaTaxBooking__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `duaTaxBooking__`(vDuaFk INT) -BEGIN - DECLARE vBookNumber INT; - DECLARE vBookDated DATE; - DECLARE vDiff DECIMAL(10,2); - DECLARE vApunte BIGINT; - - SELECT ASIEN, IFNULL(bookEntried, util.VN_CURDATE()) INTO vBookNumber, vBookDated - FROM dua - WHERE id = vDuaFk; - - IF vBookNumber IS NULL OR NOT vBookNumber THEN - CALL ledger_next(vBookNumber); - END IF; - - -- Apunte de la aduana - - INSERT INTO XDiario( - ASIEN, - FECHA, - SUBCTA, - CONCEPTO, - EUROHABER, - SERIE, - empresa_id, - CLAVE, - FACTURA) - - SELECT - vBookNumber, - d.bookEntried, - '4700000999', - CONCAT('DUA ',d.code), - sum(di.amount * tr.rate / 100) EUROHABER, - 'R', - d.companyFk, - vDuaFk, - vDuaFk - FROM duaIntrastat di - JOIN intrastat ist ON ist.id = di.intrastatFk - JOIN (SELECT rate, taxClassFk - FROM - (SELECT rate, taxClassFk - FROM invoiceInTaxBookingAccount ta - WHERE ta.effectived <= vBookDated - ORDER BY ta.effectived DESC - ) tba - GROUP BY taxClassFk - ) tr ON tr.taxClassFk = ist.taxClassFk - JOIN dua d ON d.id = di.duaFk - WHERE di.duaFk = vDuaFk; - - -- Apuntes por tipo de IVA y proveedor - - INSERT INTO XDiario( - ASIEN, - FECHA, - SUBCTA, - CONTRA, - EURODEBE, - BASEEURO, - CONCEPTO, - FACTURA, - IVA, - AUXILIAR, - SERIE, - FECHA_EX, - FECHA_OP, - FACTURAEX, - NFACTICK, - L340, - LDIFADUAN, - TIPOCLAVE, - TIPOEXENCI, - TIPONOSUJE, - TIPOFACT, - TIPORECTIF, - TERIDNIF, - TERNIF, - TERNOM, - empresa_id, - FECREGCON - ) - - SELECT - vBookNumber ASIEN, - vBookDated FECHA, - tr.account SUBCTA, - '4330002067' CONTRA, - sum(dt.tax) EURODEBE, - sum(dt.base) BASEEURO, - CONCAT('DUA nº',d.code) CONCEPTO, - d.id FACTURA, - dt.rate IVA, - '*' AUXILIAR, - 'D' SERIE, - d.issued FECHA_EX, - d.operated FECHA_OP, - d.code FACTURAEX, - 1 NFACTICK, - 1 L340, - TRUE LDIFADUAN, - 1 TIPOCLAVE, - 1 TIPOEXENCI, - 1 TIPONOSUJE, - 5 TIPOFACT, - 1 TIPORECTIF, - IF(s.countryFk IN (30, 1), 1, 4) TERIDNIF, - s.nif TERNIF, - s.name TERNOM, - d.companyFk, - d.booked FECREGCON - FROM duaTax dt - JOIN dua d ON dt.duaFk = d.id - JOIN (SELECT account, rate - FROM - (SELECT rate, account - FROM invoiceInTaxBookingAccount ta - WHERE ta.effectived <= vBookDated - AND taxAreaFk = 'WORLD' - ORDER BY ta.effectived DESC - ) tba - GROUP BY rate - ) tr ON tr.rate = dt.rate - JOIN supplier s ON s.id = d.companyFk - WHERE d.id = vDuaFk - GROUP BY dt.rate; - - SELECT SUM(EURODEBE) -SUM(EUROHABER), MAX(id) INTO vDiff, vApunte - FROM XDiario - WHERE ASIEN = vBookNumber; - - UPDATE XDiario - SET BASEEURO = 100 * (EURODEBE - vDiff) / IVA, - EURODEBE = EURODEBE - vDiff - WHERE id = vApunte; - - UPDATE dua - SET ASIEN = vBookNumber - WHERE id = vDuaFk; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `duaTaxUpdate__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `duaTaxUpdate__`(vDuaFk INT) -BEGIN - - DECLARE vSPAIN INT DEFAULT 1; - DECLARE vDated DATE; - DECLARE vTotalDUABase DECIMAL(10,2); - - SELECT IFNULL(operated, util.VN_CURDATE()) INTO vDated - FROM dua - WHERE id = vDuaFk; - - SELECT sum(amount) INTO vTotalDUABase - FROM duaIntrastat - WHERE duaFk = vDuaFk; - - DELETE FROM duaTax - WHERE duaFk = vDuaFk; - - INSERT INTO duaTax(duaFk, supplierFk, taxClassFk, base) - SELECT vDuaFk, supplierFk, taxClassFk, sum(sub.Base) as Base - FROM intrastat ist - JOIN - (SELECT - e.supplierFk, - i.intrastatFk, - CAST(sum(b.quantity * b.buyingValue * de.customsValue / de.value) * di.amount/ tei.Base AS DECIMAL(10,2)) as Base - FROM buy b - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN duaEntry de ON de.entryFk = e.id - JOIN - ( - SELECT i.intrastatFk, - CAST(sum(b.quantity * b.buyingValue * de.customsValue / de.value) AS DECIMAL(10,2)) as Base - FROM buy b - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN duaEntry de ON de.entryFk = e.id - WHERE de.duaFk = vDuaFk - GROUP BY i.intrastatFk - - ) tei ON tei.intrastatFk = i.intrastatFk - JOIN - ( - SELECT intrastatFk, sum(amount) as amount - FROM duaIntrastat - WHERE duaFk = vDuaFk - GROUP BY intrastatFK - ) di ON di.intrastatFk = i.intrastatFk - WHERE de.duaFk = vDuaFk - GROUP BY e.supplierFk, i.intrastatFk - HAVING Base - ) sub ON ist.id = sub.intrastatFk - GROUP BY ist.taxClassFk, sub.supplierFk; - - UPDATE duaTax dt - JOIN - (SELECT taxClassFk, rate - FROM - (SELECT taxClassFk, rate - FROM invoiceInTaxBookingAccount - WHERE effectived <= vDated - AND countryFk = vSPAIN - ORDER BY effectived DESC - ) ba1 - GROUP BY taxClassFk - ) ba2 ON dt.taxClassFk = ba2.taxClassFk - SET dt.rate = ba2.rate, - dt.tax = dt.base * ba2.rate / 100; - - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `duaTax_doRecalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -57676,8 +51977,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `duaTax_doRecalc`(vDuaFk INT) BEGIN @@ -57731,6 +52030,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ediTables_Update` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -57738,25 +52039,25 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ediTables_Update`() -BEGIN - - INSERT IGNORE INTO vn.genus(name) - SELECT latin_genus_name - FROM edi.genus ; - - INSERT IGNORE INTO vn.specie(name) - SELECT LCASE(latin_species_name) - FROM edi.specie ; +BEGIN + + INSERT IGNORE INTO vn.genus(name) + SELECT latin_genus_name + FROM edi.genus ; + + INSERT IGNORE INTO vn.specie(name) + SELECT LCASE(latin_species_name) + FROM edi.specie ; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ektEntryAssign_setEntry` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -57764,8 +52065,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ektEntryAssign_setEntry`() BEGIN @@ -57774,13 +52073,13 @@ DECLARE done INT DEFAULT FALSE; DECLARE vEntryFk INT; DECLARE vTravelFk INT; DECLARE vId INT; -DECLARE vLanded DATE DEFAULT util.VN_CURDATE(); +DECLARE vLanded DATE DEFAULT vn.VN_CURDATE(); DECLARE cur1 CURSOR FOR SELECT id FROM vn.ektEntryAssign; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - IF HOUR(util.VN_NOW()) > 12 THEN + IF HOUR(vn.VN_NOW()) > 12 THEN SET vLanded = TIMESTAMPADD(DAY,1,vLanded); @@ -57882,82 +52181,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 `ekt_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ekt_add__`(vPutOrderFk INT) -BEGIN - -/** - * Añade ekt para las ordenes de compra de proveedores que no envian el ekt por email - * - * @param vPutOrderFk PutOrderId de donde coger los datos - **/ - - INSERT INTO edi.ekt(entryYear, - deliveryNumber, - fec, - hor, - item, - pac, - qty, - ori, - cat, - pro, - pri, - package, - s1, - s2, - s3, - s4, - s5, - s6, - putOrderFk, - `ref`, - kop) - SELECT year(curdate()) entryYear, - p.id deliveryNumber , - util.VN_CURDATE() fec, - CURTIME() hor, - i.longName item, - sr.NumberOfItemsPerCask pac, - p.quantity qty, - o.code ori, - i.category cat, - mp.supplierFk pro, - sr.Price pri, - sr.EmbalageCode package, - i.value5 s1, - i.value6 s2, - i.value7 s3, - i.value8 s4, - i.value9 s5, - i.value10 s6, - p.id putOrderFk, - sr.Item_ArticleCode, - sr.vmpID - FROM edi.putOrder p - JOIN edi.supplyResponse sr ON sr.ID = p.supplyResponseID - JOIN edi.marketPlace mp ON mp.id = sr.MarketPlaceID - JOIN vn.item i ON i.supplyResponseFk = sr.ID - JOIN vn.origin o ON o.id = i.originFk - WHERE p.id = vPutOrderFk; - - CALL edi.ekt_load(LAST_INSERT_ID()); - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `energyMeter_record` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -57965,8 +52190,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `energyMeter_record`(vInput INT, vActiveTime INT) BEGIN @@ -57979,7 +52202,7 @@ BEGIN INSERT INTO vn.energyMeter SET `input` = vInput, - `period` = DATE_FORMAT(util.VN_NOW(), '%Y-%m-%d %H:00:00'), + `period` = DATE_FORMAT(vn.VN_NOW(), '%Y-%m-%d %H:00:00'), `activeTime` = vActiveTime, `consumption` = CAST(IFNULL((vConsumption / 3600) * vActiveTime, 0) AS DECIMAL(10,2)) ON DUPLICATE KEY UPDATE @@ -57991,233 +52214,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 `entryConverter__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `entryConverter__`(IN `vEntry` INT) -BEGIN - - DECLARE vWarehouseIn INT; - DECLARE vWarehouseOut INT; - DECLARE vTravel INT; - - DECLARE done BOOL DEFAULT FALSE; - - DECLARE vId_Entrada INT; - DECLARE vId_Article INT; - DECLARE vEtiquetas INT; - DECLARE vId_Cubo VARCHAR(10); - DECLARE vPacking INT; - DECLARE vGrouping INT; - DECLARE vCantidad INT; - DECLARE vCostefijo DECIMAL(10,3); - DECLARE vPortefijo DECIMAL(10,3); - DECLARE vEmbalajefijo DECIMAL(10); - DECLARE vComisionfija DECIMAL(10,3); - DECLARE vCaja INT; - DECLARE vNicho VARCHAR(5); - DECLARE vTarifa1 DECIMAL(10,2); - DECLARE vTarifa2 DECIMAL(10,2); - DECLARE vTarifa3 DECIMAL(10,2); - DECLARE vPVP DECIMAL(10,2); - DECLARE vCompra INT; - - DECLARE rs CURSOR FOR - SELECT - b.Id_Entrada, - b.Id_Article, - b.Etiquetas, - b.Id_Cubo, - b.Packing, - b.`grouping`, - b.Cantidad, - b.Costefijo, - b.Portefijo, - b.Embalajefijo, - b.Comisionfija, - b.caja, - b.Nicho, - b.Tarifa1, - b.Tarifa2, - b.Tarifa3, - b.PVP - FROM vn2008.Compres b - JOIN vn.itemConversor ic ON ic.espItemFk = b.Id_Article - WHERE Id_Entrada = vEntry; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - SELECT warehouseInFk, warehouseOutFk, tr.id - INTO vWarehouseIn, vWarehouseOut, vTravel - FROM travel tr - JOIN entry e ON e.travelFk = tr.id - WHERE e.id = vEntry; - - UPDATE travel - SET warehouseInFk = vWarehouseOut, - warehouseOutFk = vWarehouseIn - WHERE id = vTravel; - - UPDATE vn2008.Compres c - LEFT JOIN vn.itemConversor ic ON ic.espItemFk = c.Id_Article - SET Etiquetas = 0, Cantidad = 0 - WHERE c.Id_Entrada = vEntry - AND ic.espItemFk IS NULL; - - OPEN rs; - - DELETE FROM vn2008.Compres WHERE Id_Entrada = vEntry; - - FETCH rs INTO - vId_Entrada, - vId_Article, - vEtiquetas, - vId_Cubo, - vPacking, - vGrouping, - vCantidad, - vCostefijo, - vPortefijo, - vEmbalajefijo, - vComisionfija, - vCaja, - vNicho, - vTarifa1, - vTarifa2, - vTarifa3, - vPVP; - - WHILE NOT done DO - - -- Primero la linea original con las cantidades invertidas - INSERT INTO vn2008.Compres - ( - Id_Entrada, - Id_Article, - Etiquetas, - Id_Cubo, - Packing, - `grouping`, - Cantidad, - Costefijo, - Portefijo, - Embalajefijo, - Comisionfija, - caja, - Nicho, - Tarifa1, - Tarifa2, - Tarifa3, - PVP - ) - VALUES - ( - vId_Entrada, - vId_Article, - - vEtiquetas, - vId_Cubo, - vPacking, - vGrouping, - - vCantidad, - vCostefijo, - vPortefijo, - vEmbalajefijo, - vComisionfija, - vCaja, - vNicho, - vTarifa1, - vTarifa2, - vTarifa3, - vPVP); - - -- Ahora la linea nueva, con el item genérico - INSERT INTO vn2008.Compres - ( - Id_Entrada, - Id_Article, - Etiquetas, - Id_Cubo, - Packing, - `grouping`, - Cantidad, - Costefijo, - Portefijo, - Embalajefijo, - Comisionfija, - caja, - Nicho, - Tarifa1, - Tarifa2, - Tarifa3, - PVP - ) - SELECT - vId_Entrada, - genItemFk as Id_Article, - vEtiquetas, - vId_Cubo, - vPacking, - vGrouping, - vCantidad, - vCostefijo, - vPortefijo, - vEmbalajefijo, - vComisionfija, - vCaja, - vNicho, - vTarifa1, - vTarifa2, - vTarifa3, - vPVP - FROM itemConversor - WHERE espItemFk = vId_Article; - - SELECT LAST_INSERT_ID() - INTO vCompra; - - REPLACE vn2008.Compres_mark(Id_Compra,`comment`) - SELECT vCompra, vId_Article; - - - FETCH rs INTO - vId_Entrada, - vId_Article, - vEtiquetas, - vId_Cubo, - vPacking, - vGrouping, - vCantidad, - vCostefijo, - vPortefijo, - vEmbalajefijo, - vComisionfija, - vCaja, - vNicho, - vTarifa1, - vTarifa2, - vTarifa3, - vPVP; - - END WHILE; - - - CLOSE rs; - - - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `entryDelivered` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -58225,8 +52223,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `entryDelivered`(vDated DATE, vEntryFk INT) BEGIN @@ -58245,7 +52241,7 @@ BEGIN ELSE INSERT INTO vn.travel(shipped, landed, warehouseInFk, warehouseOutFk, agencyFk, ref, isDelivered, isReceived) - SELECT LEAST(shipped, vDated), vDated, warehouseInFk, warehouseOutFk, agencyFk, CONCAT(account.userGetName(),' ', vEntryFk), TRUE, TRUE + SELECT LEAST(shipped, vDated), vDated, warehouseInFk, warehouseOutFk, agencyFk, CONCAT(account.myUser_getName(),' ', vEntryFk), TRUE, TRUE FROM vn.travel WHERE id = vTravelFk; SELECT LAST_INSERT_ID() INTO vTravelFk; @@ -58262,125 +52258,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 `entryPrepare__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `entryPrepare__`(IN `idE` BIGINT) -BEGIN - SELECT - b.quantity / b.packing AS Paquetes, - b.packing AS `Grouping`, - barcode, - 'ASEGURADO' AS asegurado, - ic.name, - ic.order, - s.name AS Consignatario, - e.supplierFk AS Id_Cliente, - e.isOrdered, - e.isConfirmed, - 10 AS Calidad, - LPAD(IFNULL(cpd.id, ip.code), - 5, - '0') AS path, - b.entryFk AS Id_Ticket, - t.landed AS Fecha, - b.itemFk, - b.quantity, - i.name AS Concepte, - i.size, - i.inkFk, - i.category, - o.code AS Origen, - 0 AS Bultos, - wIn.`name` AS Tipo, - 0 AS OK, - 0 AS Reservado, - i.stems, - b.id AS Id_Movimiento, - ip.code, - 'PEDIDO ASEGURADO' AS MSG, - 0 AS Seguro, - i.image, - pr.name AS producer - FROM vn.buy b - JOIN vn.entry e ON b.entryFk = e.id - JOIN vn.travel t ON t.id = e.travelFk - JOIN vn.warehouse wIn ON wIn.id = t.warehouseInFk - JOIN vn.warehouse wOut ON wOut.id = t.warehouseOutFk - JOIN vn.item i ON i.id = b.itemFk - JOIN vn.itemType it ON it.id =i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - JOIN vn.packaging pkg ON pkg.id = b.packageFk - LEFT JOIN vn.itemPlacement ip ON i.id = ip.itemFk AND ip.warehouseFk = wIn.id AND ip.warehouseFk = t.warehouseOutFk - LEFT JOIN (SELECT itemFk, code AS barcode FROM vn.itemBarcode GROUP BY itemFk) ib ON ib.itemFk = b.itemFk - LEFT JOIN vn.origin o ON o.id = i.originFk - LEFT JOIN vn.supplier s ON s.id = e.supplierFk - LEFT JOIN vn.producer pr on pr.id = i.producerFk - LEFT JOIN vn.coolerPathDetail cpd ON LEFT(ip.code, 3) = cpd.hallway - WHERE - NOT wIn.isFeedStock AND NOT e.isInventory AND NOT e.isRaid - AND e.id = 158772 - AND i.typeFk IS NOT NULL - AND ic.display IS NOT FALSE; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `entrySplit_move__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `entrySplit_move__`() -BEGIN - - /* CREATED PAK 08/09/2019 - * PENDING REVIEW - * - * - */ - - DROP TEMPORARY TABLE IF EXISTS itemList; - - CREATE TEMPORARY TABLE itemList - SELECT DISTINCT b.itemFk, es.delayedFk, es.receivedFk - FROM vn.buy b - JOIN vn.entrySplit es ON es.delayedFk = b.entryFk - JOIN vn.itemPlacement ip ON ip.itemFk = b.itemFk - WHERE ip.modificationDate > util.VN_CURDATE(); - - INSERT INTO itemList - SELECT DISTINCT ish.itemFk, es.delayedFk, es.receivedFk - FROM vn.buy b - JOIN vn.entrySplit es ON es.delayedFk = b.entryFk - JOIN vn.itemShelving ish ON ish.itemFk = b.itemFk - WHERE ish.created > util.VN_CURDATE(); - - - UPDATE vn.buy b - JOIN vn.itemList il ON il.delayedFk = b.entryFk AND b.itemFk = il.itemFk - SET b.entryFk = il.receivedFk; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `entryToTicket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -58388,8 +52267,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `entryToTicket`(vEntryFk INT, vTicketFk INT) BEGIN @@ -58408,39 +52285,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 `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 = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `entryVolume__`(vEntryFk INT) -BEGIN - - SELECT ELT(it.temperature + 1,'Calientes','Frios','Secos') AS Temp, - 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 carros , - 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 - FROM vn.buy b - INNER JOIN vn.entry e ON e.id = b.entryFk - INNER JOIN vn.travel tr ON tr.id = e.travelFk - INNER JOIN vn.volumeConfig vc - INNER JOIN vn.item i ON i.id = b.itemFk - INNER JOIN vn.itemType it ON it.id = i.typeFk - WHERE e.id = vEntryFk - 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 `entryWithItem` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -58448,8 +52294,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `entryWithItem`(vShipmentWarehouse INT, vLandingWarehouse INT,vSale INT, vVolume INT, netCost DECIMAL(10,2), vInOutDate DATE) BEGIN @@ -58508,75 +52352,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 `entryWithItem__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `entryWithItem__`(IN `vShipmentWarehouse` INT, IN `vLandingWarehouse` INT, IN `vSale` INT, IN `vVolume` INT, IN netCost DECIMAL(10,2), IN `vInOutDate` DATE) -BEGIN - - DECLARE vTravel INT; - DECLARE vEntry INT; - DECLARE vBucket VARCHAR(10); - DECLARE vAgencyDirectFromProvider INT DEFAULT 15; - DECLARE vSupplierFk INT DEFAULT 963; - - - -- seleccionamos travel - SELECT t.id, e.id INTO vTravel, vEntry - FROM travel t LEFT JOIN entry e ON t.id = e.travelFk - WHERE t.landed = vInOutDate AND t.shipped = vInOutDate AND t.warehouseOutFk = vShipmentWarehouse - AND t.warehouseInFk = vLandingWarehouse AND t.agencyFk = vAgencyDirectFromProvider AND e.supplierFk = vSupplierFk - LIMIT 1; - - -- creamos el travel si es necesario - IF IFNULL(vTravel, FALSE) = FALSE THEN - INSERT INTO travel (shipped, landed, warehouseInFk, warehouseOutFk, agencyFk) - VALUES (vInOutDate, vInOutDate, vLandingWarehouse, vShipmentWarehouse, vAgencyDirectFromProvider); - SELECT LAST_INSERT_ID() INTO vTravel; - END IF; - - -- creamos la Entrada si es necesario - IF IFNULL(vEntry, FALSE) = FALSE THEN - INSERT INTO entry (supplierFk, travelFk) - VALUES (vSupplierFk, vTravel); -- proveedor 'CONFECCION ARTIFICIAL' - SELECT LAST_INSERT_ID() INTO vEntry; - END IF; - - -- creamos el cubo si es necesario - SELECT id INTO vBucket FROM packaging WHERE volume = vVolume LIMIT 1; - IF vBucket IS NULL THEN - INSERT INTO packaging (id, volume) - VALUES (CONCAT('dm',vVolume/1000), vVolume); - -- SELECT LAST_INSERT_ID() INTO vBucket; - SELECT id INTO vBucket FROM packaging WHERE volume = vVolume LIMIT 1; - END IF; - - INSERT INTO buy(itemFk,quantity, entryFk, packageFk, packing, `grouping`, stickers, buyingValue, price2, price3) - SELECT itemFk, - quantity, - vEntry, - vBucket, - 1 packing, - 1 `grouping`, - quantity, - netCost, - s.price, - s.price - FROM sale s - WHERE s.id = vSale; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!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 sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `entry_clone` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -58584,77 +52361,77 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `entry_clone`(vSelf INT) -BEGIN - -/* - * Clona una entrada - * - * @param vSelf Identificador de vn.entry - */ - - DECLARE vNewEntryFk INT; - - CALL vn.entry_cloneWithoutBuy(vSelf, vNewEntryFk); - - INSERT INTO vn.buy( entryFk, - itemFk, - quantity, - buyingValue, - freightValue, - isIgnored, - stickers, - packing, - `grouping`, - groupingMode, - containerFk, - comissionValue, - packageValue, - packageFk, - price1, - price2, - price3, - minPrice, - producer, - workerFk, - weight, - itemOriginalFk) - SELECT vNewEntryFk, - itemFk, - quantity, - buyingValue, - freightValue, - isIgnored, - stickers, - packing, - `grouping`, - groupingMode, - containerFk, - comissionValue, - packageValue, - packageFk, - price1, - price2, - price3, - minPrice, - producer, - workerFk, - weight, - itemOriginalFk - FROM vn.buy b - WHERE b.entryFk = vSelf; - - SELECT vNewEntryFk; - +BEGIN + +/* + * Clona una entrada + * + * @param vSelf Identificador de vn.entry + */ + + DECLARE vNewEntryFk INT; + + CALL vn.entry_cloneWithoutBuy(vSelf, vNewEntryFk); + + INSERT INTO vn.buy( entryFk, + itemFk, + quantity, + buyingValue, + freightValue, + isIgnored, + stickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + packageFk, + price1, + price2, + price3, + minPrice, + producer, + workerFk, + weight, + itemOriginalFk) + SELECT vNewEntryFk, + itemFk, + quantity, + buyingValue, + freightValue, + isIgnored, + stickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + packageFk, + price1, + price2, + price3, + minPrice, + producer, + workerFk, + weight, + itemOriginalFk + FROM vn.buy b + WHERE b.entryFk = vSelf; + + SELECT vNewEntryFk; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `entry_cloneWithoutBuy` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -58662,55 +52439,55 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `entry_cloneWithoutBuy`(vSelf INT, OUT vNewEntryFk INT) -BEGIN - -/** - * Clona una entrada sin compras - * - * @param vSelf Identificador de vn.entry - * - * @return vNewEntryFk Identificador de la nueva entrada - */ - - START TRANSACTION; - - INSERT INTO vn.entry(supplierFk, - dated, - isInventory, - notes, - isRaid, - commission, - travelFk, - currencyFk, - companyFk, - loadPriority) - SELECT supplierFk, - dated, - isInventory, - notes, - isRaid, - commission, - travelFk, - currencyFk, - companyFk, - loadPriority - FROM vn.entry e - WHERE e.id = vSelf; - - SET vNewEntryFk = LAST_INSERT_ID(); - - COMMIT; - +BEGIN + +/** + * Clona una entrada sin compras + * + * @param vSelf Identificador de vn.entry + * + * @return vNewEntryFk Identificador de la nueva entrada + */ + + START TRANSACTION; + + INSERT INTO vn.entry(supplierFk, + dated, + isInventory, + notes, + isRaid, + commission, + travelFk, + currencyFk, + companyFk, + loadPriority) + SELECT supplierFk, + dated, + isInventory, + notes, + isRaid, + commission, + travelFk, + currencyFk, + companyFk, + loadPriority + FROM vn.entry e + WHERE e.id = vSelf; + + SET vNewEntryFk = LAST_INSERT_ID(); + + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `entry_fixMisfit` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -58718,72 +52495,72 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_fixMisfit`(vSelf INT) -BEGIN -/** - * Arregla el descuadre de una entrada, agregando registros en vn.buy - * para compensar la diferencia * entre las etiquetas impresas y las esperadas - * - * @param vSelf Identificador de la entrada - */ - INSERT INTO vn.buy(entryFk, itemFk) - SELECT vSelf, i.id - FROM vn.item i - WHERE i.description = 'MISFIT' - LIMIT 1; - - INSERT INTO vn.buy(entryFk, - itemFk, - quantity, - buyingValue, - freightValue, - isIgnored, - stickers, - packing, - `grouping`, - groupingMode, - containerFk, - comissionValue, - packageValue, - location, - packageFk, - price1, - price2, - price3, - minPrice, - producer) - SELECT vSelf, - itemFk, - (printedStickers - stickers) * packing quantity, - buyingValue, - freightValue, - TRUE isIgnored, - printedStickers - stickers, - packing, - `grouping`, - groupingMode, - containerFk, - comissionValue, - packageValue, - location, - packageFk, - price1, - price2, - price3, - minPrice, - producer - FROM vn.buy b - WHERE b.entryFk = vSelf - AND b.printedStickers != b.stickers; +BEGIN +/** + * Arregla el descuadre de una entrada, agregando registros en vn.buy + * para compensar la diferencia * entre las etiquetas impresas y las esperadas + * + * @param vSelf Identificador de la entrada + */ + INSERT INTO vn.buy(entryFk, itemFk) + SELECT vSelf, i.id + FROM vn.item i + WHERE i.description = 'MISFIT' + LIMIT 1; + + INSERT INTO vn.buy(entryFk, + itemFk, + quantity, + buyingValue, + freightValue, + isIgnored, + stickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + location, + packageFk, + price1, + price2, + price3, + minPrice, + producer) + SELECT vSelf, + itemFk, + (printedStickers - stickers) * packing quantity, + buyingValue, + freightValue, + TRUE isIgnored, + printedStickers - stickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + location, + packageFk, + price1, + price2, + price3, + minPrice, + producer + FROM vn.buy b + WHERE b.entryFk = vSelf + AND b.printedStickers != b.stickers; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `entry_getRate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -58791,8 +52568,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_getRate`(vEntry INT) BEGIN @@ -58834,6 +52609,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `entry_moveNotPrinted` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -58841,8 +52618,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_moveNotPrinted`(vSelf INT, vDays INT, vChangeEntry BOOL, OUT vNewEntryFk INT) BEGIN @@ -58877,29 +52652,31 @@ BEGIN AND b.entryFk = vSelf; END IF; - INSERT INTO vn.buy( entryFk, - itemFk, - quantity, - buyingValue, - freightValue, - isIgnored, - stickers, - packing, - `grouping`, - groupingMode, - containerFk, - comissionValue, - packageValue, - packageFk, - price1, - price2, - price3, - minPrice, - producer, - workerFk, - weight, - itemOriginalFk) - SELECT vNewEntryFk, + INSERT INTO vn.buy( + entryFk, + itemFk, + quantity, + buyingValue, + freightValue, + isIgnored, + stickers, + packing, + `grouping`, + groupingMode, + containerFk, + comissionValue, + packageValue, + packageFk, + price1, + price2, + price3, + minPrice, + producer, + workerFk, + weight, + itemOriginalFk + ) + SELECT vNewEntryFk, itemFk, ((stickers - printedStickers) * packing) quantity, buyingValue, @@ -58981,12 +52758,71 @@ BEGIN WHERE entryFk = vSelf AND printedStickers != stickers; END IF; + + INSERT INTO entryLog + SET action = 'update', + description = CONCAT('Se ha creado la entrada ', vNewEntryFk,' transferida desde la ', vSelf), + userFk = account.myUser_getId(), + originFk = vSelf; + + INSERT INTO entryLog + SET action = 'update', + description = CONCAT('Se ha creado la entrada ', vNewEntryFk,' transferida desde la ', vSelf), + userFk = account.myUser_getId(), + originFk = vNewEntryFk; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `entry_notifyChanged` */; +/*!50003 SET @saved_cs_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_notifyChanged`(vSelf INT, vBuyFk INT, vOldValues VARCHAR(512), vNewValues VARCHAR(512)) +BEGIN + DECLARE vEmail VARCHAR(255); + DECLARE vFields VARCHAR(100); + DECLARE vMessage TEXT; + + SELECT e.mailToNotify INTO vEmail + FROM entryConfig e + LIMIT 1; + + SET vFields = CONCAT_WS(',', + 'entryFk', + 'itemFk', + 'quantity', + 'price1', + 'price2', + 'price3' + ); + SET vMessage = util.formatTable(vFields, vOldValues, vNewValues); + + CALL mail_insert( + vEmail, + NULL, + CONCAT( + 'Se ha modificado una línea de la entrada ', vSelf + ,' siendo inventario o anterior al mismo' + ), + vMessage + ); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `entry_recalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -58994,8 +52830,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_recalc`() BEGIN @@ -59034,6 +52868,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `entry_splitByShelving` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59041,8 +52877,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_splitByShelving`(vShelvingFk VARCHAR(3), vFromEntryFk INT, vToEntryFk INT) BEGIN @@ -59066,7 +52900,8 @@ BEGIN JOIN (SELECT b.id, b.itemFk, b.stickers FROM vn.buy b WHERE b.entryFk = vFromEntryFk - ORDER BY b.stickers DESC) bb ON bb.itemFk = ish.itemFk + ORDER BY b.stickers DESC + LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk AND bb.stickers >= FLOOR(ish.visible / ish.packing) WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci GROUP BY ish.id; @@ -59083,7 +52918,8 @@ BEGIN LEFT JOIN (SELECT b.id, b.itemFk, b.stickers FROM vn.buy b WHERE b.entryFk = vFromEntryFk - ORDER BY b.stickers DESC) bb ON bb.itemFk = ish.itemFk + ORDER BY b.stickers DESC + LIMIT 10000000000000000000) bb ON bb.itemFk = ish.itemFk WHERE shelvingFk = vShelvingFk COLLATE utf8_general_ci AND IFNULL(bb.stickers,0) < FLOOR(ish.visible / ish.packing) GROUP BY ish.id; @@ -59179,6 +53015,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `entry_splitMisfit` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59186,46 +53024,46 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `entry_splitMisfit`(vSelf INT) -BEGIN - - /* Divide una entrada, pasando los registros que ha insertado vn.entry_fixMisfit de la entrada original - * a la nueva - */ - - DECLARE vNewEntryFk INT; - DECLARE vBuyFk INT; - - SELECT MAX(b.id) INTO vBuyFk - FROM vn.buy b - JOIN vn.item i ON i.id = b.itemFk - WHERE b.entryFk = vSelf - AND i.description = 'MISFIT'; - - INSERT INTO vn.entry(supplierFk, dated, notes, travelFk, currencyFk, companyFk) - SELECT supplierFk, dated, CONCAT('E:',vSelf), travelFk, currencyFk, companyFk - FROM vn.entry e - WHERE e.id = vSelf; - - SET vNewEntryFk = LAST_INSERT_ID(); - - UPDATE vn.buy b - SET b.entryFk = vNewEntryFk - WHERE b.entryFk = vSelf - AND b.id > vBuyFk; - - SELECT vNewEntryFk; - - +BEGIN + + /* Divide una entrada, pasando los registros que ha insertado vn.entry_fixMisfit de la entrada original + * a la nueva + */ + + DECLARE vNewEntryFk INT; + DECLARE vBuyFk INT; + + SELECT MAX(b.id) INTO vBuyFk + FROM vn.buy b + JOIN vn.item i ON i.id = b.itemFk + WHERE b.entryFk = vSelf + AND i.description = 'MISFIT'; + + INSERT INTO vn.entry(supplierFk, dated, notes, travelFk, currencyFk, companyFk) + SELECT supplierFk, dated, CONCAT('E:',vSelf), travelFk, currencyFk, companyFk + FROM vn.entry e + WHERE e.id = vSelf; + + SET vNewEntryFk = LAST_INSERT_ID(); + + UPDATE vn.buy b + SET b.entryFk = vNewEntryFk + WHERE b.entryFk = vSelf + AND b.id > vBuyFk; + + SELECT vNewEntryFk; + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `errorProduction_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59233,8 +53071,6 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `errorProduction_add`(vAction VARCHAR(25), vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN @@ -59383,6 +53219,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `errorProduction_addLauncher` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59390,15 +53228,13 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `errorProduction_addLauncher`() BEGIN DECLARE vDatedFrom DATETIME; DECLARE vDatedTo DATETIME; - SELECT DATE_SUB(util.VN_CURDATE(),INTERVAL 1 DAY), CONCAT(DATE_SUB(util.VN_CURDATE(),INTERVAL 1 DAY),' 23:59:59') INTO vDatedFrom, vDatedTo; + SELECT DATE_SUB(vn.VN_CURDATE(),INTERVAL 1 DAY), CONCAT(DATE_SUB(vn.VN_CURDATE(),INTERVAL 1 DAY),' 23:59:59') INTO vDatedFrom, vDatedTo; CALL vn.errorProduction_add('SACAR', vDatedFrom, vDatedTo); CALL vn.errorProduction_add('ENCAJAR', vDatedFrom, vDatedTo); @@ -59409,128 +53245,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 `errorProduction_addLauncher__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `errorProduction_addLauncher__`() -BEGIN - DECLARE vDatedFrom DATETIME; - DECLARE vDatedTo DATETIME; - - IF (DAY(util.VN_CURDATE()) = 5) THEN - SELECT util.firstDayOfMonth(DATE_SUB(util.VN_CURDATE(),INTERVAL 1 MONTH)), CONCAT(LAST_DAY(DATE_SUB(util.VN_CURDATE(),INTERVAL 1 MONTH)),' 23:59:59') INTO vDatedFrom, vDatedTo; - - CALL vn.errorProduction_add('SACAR' ,'Sacadores','PREPARED', vDatedFrom, vDatedTo); - CALL vn.errorProduction_add('ENCAJAR' ,'Encajadores','PACKED', vDatedFrom, vDatedTo); - CALL vn.errorProduction_add('CONTROLAR' ,'Revisadores','CHECKED', vDatedFrom, vDatedTo); - 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 `errorProduction_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `errorProduction_add__`(vAction VARCHAR(25), vDepartment VARCHAR(25), vStateCode VARCHAR(25) CHARSET utf8, vDatedFrom DATETIME, vDatedTo DATETIME) -BEGIN - /** - * Fill in the errorProduction table. - */ - 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; - - - INSERT INTO errorProduction(userFk, firstname, lastname, rol, ticketNumber, error, ratio, volume, month, year) - SELECT sub1.id, sub1.firstName, sub1.lastName, - CASE - WHEN vDepartment = 'Encajadores' THEN 'Encajador' - WHEN vDepartment = 'Sacadores' THEN 'Sacador' - ELSE 'Revisador' - END AS rol, - CAST(sub1.totalTickets AS DECIMAL(10,0)) AS totalTickets, - CAST(IFNULL(sub1.errors,0) + IFNULL(sub2.errors,0) AS DECIMAL(10,0)) AS errors, - ((IFNULL(sub1.errors,0) + IFNULL(sub2.errors,0))/sub1.totalTickets)*100 AS ratio, - IF(vDepartment = 'Revisadores', NULL, volume) AS volume, - MONTH(vDatedFrom) AS month, - YEAR(vDatedFrom) AS year - FROM( - SELECT w.id, w.code, w.firstName, w.lastName, t.ticketCount AS totalTickets, sub.errors, sub2.volume - 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 - LEFT JOIN ( -- Añadir volume - SELECT SUM(w.volume) AS volume, w.workerFk - FROM bs.workerProductivity w - INNER JOIN vn.`role` r ON r.id=w.roleFk - WHERE IF(vDepartment = 'Encajadores', r.name='packager', r.name='itemPicker') AND w.dated BETWEEN vDatedFrom AND vDatedTo - GROUP BY w.workerFk) sub2 ON w.id = sub2.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 `expeditionGetFromRoute` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59538,8 +53254,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionGetFromRoute`( vExpeditionFk INT) @@ -59547,27 +53261,37 @@ BEGIN /** * Get all expeditions from route */ - DECLARE vRouteFk INT DEFAULT 0; - - SELECT t.routeFk INTO vRouteFk - FROM vn.expedition exp - INNER JOIN ticket t on t.id = exp.ticketFk - WHERE exp.id = vExpeditionFk; - -SELECT exp.id, exp.ticketFk, exp.checked, t.routeFk,t.packages AS bultos , ts.alertLevel, a.street, a.city,a.postalCode,a.id AS addressFk,w.name AS warehouse - FROM vn.expedition exp - INNER JOIN ticket t ON t.id = exp.ticketFk - INNER JOIN vn.ticketState ts ON ts.ticketFk = exp.ticketFk - LEFT JOIN vn.address a ON t.addressFk = a.id - LEFT JOIN vn.warehouse w ON t.warehouseFk = w.id - WHERE t.routeFk = vRouteFk AND exp.isBox > 0; - + DECLARE vRouteFk INT DEFAULT 0; + + SELECT t.routeFk INTO vRouteFk + FROM vn.expedition exp + INNER JOIN ticket t on t.id = exp.ticketFk + WHERE exp.id = vExpeditionFk; + + SELECT exp.id, + exp.ticketFk, + t.routeFk, + t.packages bultos, + ts.alertLevel, + a.street, + a.city, + a.postalCode, + a.id addressFk, + w.name warehouse + FROM vn.expedition exp + INNER JOIN ticket t ON t.id = exp.ticketFk + INNER JOIN vn.ticketState ts ON ts.ticketFk = exp.ticketFk + LEFT JOIN vn.address a ON t.addressFk = a.id + LEFT JOIN vn.warehouse w ON t.warehouseFk = w.id + WHERE t.routeFk = vRouteFk AND exp.isBox > 0; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionPallet_Del` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59575,8 +53299,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionPallet_Del`(vPalletFk INT) BEGIN @@ -59590,6 +53312,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionPallet_List` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59597,8 +53321,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionPallet_List`(vTruckFk INT) BEGIN @@ -59619,6 +53341,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionPallet_printLabel` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59626,74 +53350,37 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionPallet_printLabel`(vPalletFk INT) +CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionPallet_printLabel`(vSelf INT) BEGIN - DECLARE vLabel INT; + DECLARE vReport INT; DECLARE vPrinterFk INT; UPDATE vn.expeditionPallet - SET isPrint = FALSE - WHERE id = vPalletFk; + SET isPrint = FALSE + WHERE id = vSelf; - SELECT s.labelReportFk, w.labelerFk INTO vLabel, vPrinterFK + SELECT s.reportFk, w.labelerFk INTO vReport, vPrinterFk FROM worker w LEFT JOIN sector s ON s.id= w.sectorFk - WHERE w.id=account.myUser_getId() ; + WHERE w.id = account.myUser_getId(); - INSERT INTO printServerQueue (printerFk, labelReportFk, statusFk, param1, workerFk) - VALUES(vPrinterFK, vLabel, 1, vPalletFk, account.myUser_getId()); + INSERT INTO printQueue (printerFk, priorityFk, reportFk, workerFk) + SELECT vPrinterFk, qp.id, vReport, account.myUser_getId() + FROM queuePriority qp + WHERE qp.`code`= 'high'; + + INSERT INTO printQueueArgs (printQueueFk, `name`, `value` ) + SELECT LAST_INSERT_ID(), 'palletFk', vSelf; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `expeditionPallet_PrintSet` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionPallet_PrintSet`(vPalletFk INT,vSectorFk INT) -BEGIN - - DECLARE vLabel INT; - DECLARE vPrinterFk INT; - - UPDATE vn.expeditionPallet - SET isPrint = FALSE - WHERE id = vPalletFk; - - SELECT labelReportFk - INTO vLabel - FROM sector - WHERE id=vSectorFk; - - SELECT printerFk - INTO vPrinterFk - FROM sector - WHERE id=vSectorFk; - - - INSERT INTO vn2008.Colas -(Id_Cola, Id_Impresora, Id_Prioridad, Id_Informe, Id_Estado, Hora_Inicio, Hora_Fin, Cola, Id_Trabajador, Cola2, Cola3, error) -VALUES(NULL, vPrinterFK, NULL, vLabel, 1, NULL, NULL, vPalletFk, NULL, vSectorFk, NULL, NULL); - - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionPallet_View` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59701,8 +53388,6 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionPallet_View`(vPalletFk INT) BEGIN @@ -59723,6 +53408,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionScan_Add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59730,8 +53417,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionScan_Add`(vPalletFk INT, vTruckFk INT) BEGIN @@ -59763,6 +53448,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionScan_Del` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59770,8 +53457,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionScan_Del`(vScanFk INT) BEGIN @@ -59785,6 +53470,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionScan_List` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59792,8 +53479,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionScan_List`(vPalletFk INT) BEGIN @@ -59815,6 +53500,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionScan_Put` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59822,8 +53509,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionScan_Put`(vPalletFk INT, vExpeditionFk INT) BEGIN @@ -59839,6 +53524,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionState_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59846,43 +53533,43 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_add`(vParam INT, vStateCode VARCHAR(100)) -BEGIN - - /** - * Inserta nuevos registros en la tabla vn.expeditionState, segun el parámetro - * - * @param vParam Identificador de vn.expedition o de vn.route - * @param vStateCode Corresponde a vn.expeditionStateType.code - */ - - IF (SELECT COUNT(*) FROM vn.route r WHERE r.id = vParam) THEN - - INSERT INTO vn.expeditionState(expeditionFk, typeFk) - SELECT e.id, est.id - FROM vn.expedition e - JOIN vn.ticket t ON t.id = e.ticketFk - JOIN vn.expeditionStateType est ON est.code = vStateCode - WHERE t.routeFk = vParam; - - ELSE - - INSERT INTO vn.expeditionState(expeditionFk, typeFk) - SELECT vParam, est.id - FROM vn.expeditionStateType est - WHERE est.code = vStateCode; - - END IF; - +BEGIN + + /** + * Inserta nuevos registros en la tabla vn.expeditionState, segun el parámetro + * + * @param vParam Identificador de vn.expedition o de vn.route + * @param vStateCode Corresponde a vn.expeditionStateType.code + */ + + IF (SELECT COUNT(*) FROM vn.route r WHERE r.id = vParam) THEN + + INSERT INTO vn.expeditionState(expeditionFk, typeFk) + SELECT e.id, est.id + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.expeditionStateType est ON est.code = vStateCode + WHERE t.routeFk = vParam; + + ELSE + + INSERT INTO vn.expeditionState(expeditionFk, typeFk) + SELECT vParam, est.id + FROM vn.expeditionStateType est + WHERE est.code = vStateCode; + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionState_addByAdress` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59890,33 +53577,33 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `expeditionState_addByAdress`(vAdressFk INT, vRouteFk INT, vStateCode VARCHAR(100)) -BEGIN - - /** - * Inserta nuevos registros en la tabla vn.expeditionState - * - * @param vAdressFk Identificador de vn.ticket - * @param vRouteFk Identificador de vn.route - * @param vStateCode Corresponde a vn.expeditionStateType.code - */ - - INSERT INTO vn.expeditionState(expeditionFk, typeFk) - SELECT e.id, est.id - FROM vn.expedition e - JOIN vn.expeditionStateType est ON est.code = vStateCode - JOIN vn.ticket t ON t.id = e.ticketFk - WHERE t.addressFk = vAdressFk AND t.routeFk = vRouteFk; - +BEGIN + + /** + * Inserta nuevos registros en la tabla vn.expeditionState + * + * @param vAdressFk Identificador de vn.ticket + * @param vRouteFk Identificador de vn.route + * @param vStateCode Corresponde a vn.expeditionStateType.code + */ + + INSERT INTO vn.expeditionState(expeditionFk, typeFk) + SELECT e.id, est.id + FROM vn.expedition e + JOIN vn.expeditionStateType est ON est.code = vStateCode + JOIN vn.ticket t ON t.id = e.ticketFk + WHERE t.addressFk = vAdressFk AND t.routeFk = vRouteFk; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionState_addByExpedition` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59924,30 +53611,30 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_addByExpedition`(vExpeditionFk INT, vStateCode VARCHAR(100)) -BEGIN - - /** - * Inserta nuevos registros en la tabla vn.expeditionState - * - * @param vExpeditionFk Identificador de vn.expedition - * @param vStateCode Corresponde a vn.expeditionStateType.code - */ - - INSERT INTO vn.expeditionState(expeditionFk, typeFk) - SELECT vExpeditionFk, est.id - FROM vn.expeditionStateType est - WHERE est.code = vStateCode; - +BEGIN + + /** + * Inserta nuevos registros en la tabla vn.expeditionState + * + * @param vExpeditionFk Identificador de vn.expedition + * @param vStateCode Corresponde a vn.expeditionStateType.code + */ + + INSERT INTO vn.expeditionState(expeditionFk, typeFk) + SELECT vExpeditionFk, est.id + FROM vn.expeditionStateType est + WHERE est.code = vStateCode; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionState_addByPallet` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59955,8 +53642,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_addByPallet`(vPalletFk INT, vStateCode VARCHAR(100)) BEGIN @@ -59984,6 +53669,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionState_addByRoute` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59991,32 +53678,32 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionState_addByRoute`(vRouteFk INT, vStateCode VARCHAR(100)) -BEGIN - - /** - * Inserta nuevos registros en la tabla vn.expeditionState, por rutas - * - * @param vRouteFk Identificador de vn.route - * @param vStateCode Corresponde a vn.expeditionStateType.code - */ - - INSERT INTO vn.expeditionState(expeditionFk, typeFk) - SELECT e.id, est.id - FROM vn.expedition e - JOIN vn.ticket t ON t.id = e.ticketFk - JOIN vn.expeditionStateType est ON est.code = vStateCode - WHERE t.routeFk = vRouteFk; - +BEGIN + + /** + * Inserta nuevos registros en la tabla vn.expeditionState, por rutas + * + * @param vRouteFk Identificador de vn.route + * @param vStateCode Corresponde a vn.expeditionStateType.code + */ + + INSERT INTO vn.expeditionState(expeditionFk, typeFk) + SELECT e.id, est.id + FROM vn.expedition e + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.expeditionStateType est ON est.code = vStateCode + WHERE t.routeFk = vRouteFk; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionTruck_Add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60024,14 +53711,12 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionTruck_Add`(vHour VARCHAR(5), vDescription VARCHAR(45)) BEGIN INSERT INTO vn.expeditionTruck(ETD,description) - VALUES(CONCAT(util.VN_CURDATE(), ' ', vHour), vDescription); + VALUES(CONCAT(vn.VN_CURDATE(), ' ', vHour), vDescription); END ;; DELIMITER ; @@ -60039,6 +53724,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expeditionTruck_List` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60046,8 +53733,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionTruck_List`() BEGIN @@ -60056,7 +53741,7 @@ BEGIN ETD, description Destino FROM vn.expeditionTruck - WHERE ETD BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + WHERE ETD BETWEEN vn.VN_CURDATE() AND util.dayend(vn.VN_CURDATE()) ORDER BY ETD; END ;; DELIMITER ; @@ -60064,33 +53749,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 `expeditionUpdateChecked` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `expeditionUpdateChecked`( - vExpeditionFk INT, vChecked INT) -BEGIN -/** - * Get all expeditions from route - */ - - UPDATE vn.expedition exp - 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_getFromRoute` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60098,8 +53758,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_getFromRoute`(vRouteFk INT) BEGIN @@ -60107,19 +53765,17 @@ BEGIN * Obtiene las expediciones a partir de una ruta * @param vRouteFk Id de la ruta */ - - SELECT e.id, - e.ticketFk, - e.checked, + SELECT e.id, + e.ticketFk, t.routeFk, - ts.alertLevel, - a.street, + ts.alertLevel, + a.street, a.city, a.postalCode, - t.addressFk, + t.addressFk, a.nickname, sub2.itemPackingTypeConcat, - est.code + est.code FROM expedition e JOIN ticket t ON t.id = e.ticketFk JOIN ticketState ts ON ts.ticketFk = e.ticketFk @@ -60137,13 +53793,14 @@ BEGIN ) sub2 ON sub2.ticketFk = t.id LEFT JOIN expeditionStateType est ON est.id = e.stateTypeFk WHERE t.routeFk = vRouteFk AND e.isBox <> 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expedition_getState` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60151,8 +53808,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_getState`(vExpeditionFk INT) BEGIN @@ -60214,6 +53869,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `expedition_StateGet` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60221,8 +53878,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `expedition_StateGet`(vExpeditionFk INT) BEGIN @@ -60301,6 +53956,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `faultsReview` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60308,8 +53965,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `faultsReview`(vWarehouseFk INT) BEGIN @@ -60346,7 +54001,7 @@ BEGIN JOIN vn.client c ON c.id = t.clientFk WHERE c.typeFk = 'loses' COLLATE utf8_unicode_ci AND s.isPicked = FALSE - AND date(t.shipped) = util.VN_CURDATE() + AND date(t.shipped) = vn.VN_CURDATE() AND t.warehouseFk = vWarehouseFk ) sub ON sub.itemFk = ishr.itemFk ; @@ -60358,6 +54013,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `faultsReview_isChecked` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60365,8 +54022,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `faultsReview_isChecked`(vItemFk INT, vWarehouseFk INT) BEGIN @@ -60376,7 +54031,7 @@ BEGIN JOIN vn.client c ON c.id = t.clientFk SET s.isPicked = TRUE WHERE c.typeFk = 'loses' COLLATE utf8_unicode_ci - AND date(t.shipped) = util.VN_CURDATE() + AND date(t.shipped) = vn.VN_CURDATE() AND t.warehouseFk = vWarehouseFk AND s.itemFk = vItemFk; @@ -60386,6 +54041,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `freelance_getInfo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60393,25 +54050,26 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `freelance_getInfo`(workerFk INT) BEGIN - SELECT s.name, s.street, s.city, s.nif, s.postCode + SELECT s.name, s.street, s.city, s.nif, s.postCode FROM route r - JOIN agencyMode am ON r.agencyModeFk = am.id - JOIN agency a ON am.agencyFk = a.id - JOIN supplier s ON a.supplierFk = s.id - WHERE r.workerFk = workerFk - ORDER BY r.id DESC - LIMIT 1; + JOIN agencyMode am ON r.agencyModeFk = am.id + JOIN agency a ON am.agencyFk = a.id + JOIN supplierAgencyTerm sat ON a.id = sat.agencyFk + JOIN supplier s ON sat.supplierFk = s.id + WHERE r.workerFk = workerFk + ORDER BY r.id DESC + LIMIT 1; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `fustControl` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60419,91 +54077,91 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `fustControl`(vFromDated DATE, vToDated DATE) -BEGIN - - DECLARE vSijsnerClientFk INT DEFAULT 19752; - - DECLARE vDateStart DATETIME; - DECLARE vDateEnd DATETIME; - - SET vDateStart = vFromDated; - SET vDateEnd = util.Dayend(vToDated); - - SELECT p.id FustCode, - CAST(sent.stucks AS DECIMAL(10,0)) FH, - CAST(tp.stucks AS DECIMAL(10,0)) Tickets, - CAST(-sj.stucks AS DECIMAL(10,0)) Sijsner, - CAST(IFNULL(sent.stucks,0) - IFNULL(tp.stucks,0) + IFNULL(sj.stucks,0) AS DECIMAL(10,0)) saldo - FROM vn.packaging p - LEFT JOIN ( - SELECT FustCode, sum(fustQuantity) stucks - FROM ( - SELECT IFNULL(pe.equivalentFk ,b.packageFk) FustCode, s.quantity / b.packing AS fustQuantity - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk - 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.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 - WHERE t.shipped BETWEEN vDateStart AND vDateEnd - AND wa.name = 'VNH' - AND p.isPackageReturnable - AND c.country = 'FRANCIA') sub - GROUP BY FustCode) sent ON sent.FustCode = p.id - LEFT JOIN ( - SELECT FustCode, sum(quantity) stucks - FROM ( - SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity - FROM vn.ticketPackaging tp - JOIN vn.ticket t ON t.id = tp.ticketFk - 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.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 - WHERE t.shipped BETWEEN vDateStart AND vDateEnd - AND wa.name = 'VNH' - AND p.isPackageReturnable - AND c.country = 'FRANCIA' - AND t.clientFk != vSijsnerClientFk - AND tp.quantity > 0) sub - GROUP BY FustCode) tp ON tp.FustCode = p.id - LEFT JOIN ( - SELECT FustCode, sum(quantity) stucks - FROM ( - SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity - FROM vn.ticketPackaging tp - JOIN vn.ticket t ON t.id = tp.ticketFk - 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.packagingFk = p.id - WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, 1, vDateStart ) AND TIMESTAMPADD(DAY, 1, vDateEnd ) - AND wa.name = 'VNH' - AND p.isPackageReturnable - AND t.clientFk = vSijsnerClientFk) sub - GROUP BY FustCode) sj ON sj.FustCode = p.id - WHERE sent.stucks - OR tp.stucks - OR sj.stucks; - +BEGIN + + DECLARE vSijsnerClientFk INT DEFAULT 19752; + + DECLARE vDateStart DATETIME; + DECLARE vDateEnd DATETIME; + + SET vDateStart = vFromDated; + SET vDateEnd = util.Dayend(vToDated); + + SELECT p.id FustCode, + CAST(sent.stucks AS DECIMAL(10,0)) FH, + CAST(tp.stucks AS DECIMAL(10,0)) Tickets, + CAST(-sj.stucks AS DECIMAL(10,0)) Sijsner, + CAST(IFNULL(sent.stucks,0) - IFNULL(tp.stucks,0) + IFNULL(sj.stucks,0) AS DECIMAL(10,0)) saldo + FROM vn.packaging p + LEFT JOIN ( + SELECT FustCode, sum(fustQuantity) stucks + FROM ( + SELECT IFNULL(pe.equivalentFk ,b.packageFk) FustCode, s.quantity / b.packing AS fustQuantity + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.warehouse w ON w.id = t.warehouseFk + JOIN vn.warehouseAlias wa ON wa.id = w.aliasFk + 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.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 + WHERE t.shipped BETWEEN vDateStart AND vDateEnd + AND wa.name = 'VNH' + AND p.isPackageReturnable + AND c.country = 'FRANCIA') sub + GROUP BY FustCode) sent ON sent.FustCode = p.id + LEFT JOIN ( + SELECT FustCode, sum(quantity) stucks + FROM ( + SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + 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.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 + WHERE t.shipped BETWEEN vDateStart AND vDateEnd + AND wa.name = 'VNH' + AND p.isPackageReturnable + AND c.country = 'FRANCIA' + AND t.clientFk != vSijsnerClientFk + AND tp.quantity > 0) sub + GROUP BY FustCode) tp ON tp.FustCode = p.id + LEFT JOIN ( + SELECT FustCode, sum(quantity) stucks + FROM ( + SELECT IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, tp.quantity + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + 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.packagingFk = p.id + WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, 1, vDateStart ) AND TIMESTAMPADD(DAY, 1, vDateEnd ) + AND wa.name = 'VNH' + AND p.isPackageReturnable + AND t.clientFk = vSijsnerClientFk) sub + GROUP BY FustCode) sj ON sj.FustCode = p.id + WHERE sent.stucks + OR tp.stucks + OR sj.stucks; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `fustControlDetail` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60511,48 +54169,48 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `fustControlDetail`(vFromDated DATE, vToDated DATE) -BEGIN - - DECLARE vSijsnerClientFk INT DEFAULT 19752; - - DECLARE vDateStart DATETIME; - DECLARE vDateEnd DATETIME; - - SET vDateStart = vFromDated; - SET vDateEnd = util.Dayend(vToDated); - - SELECT a.nickname shopName, - a.city , - IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, - tp.quantity, - tp.ticketFk, - CONCAT('From ', vFromDated,' to ', vToDated) AS dateRange - FROM vn.ticketPackaging tp - JOIN vn.ticket t ON t.id = tp.ticketFk - 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.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 - WHERE t.shipped BETWEEN vFromDated AND util.dayend(vToDated) - AND wa.name = 'VNH' - AND p.isPackageReturnable - AND c.country = 'FRANCIA' - AND t.clientFk != vSijsnerClientFk - AND tp.quantity > 0; - +BEGIN + + DECLARE vSijsnerClientFk INT DEFAULT 19752; + + DECLARE vDateStart DATETIME; + DECLARE vDateEnd DATETIME; + + SET vDateStart = vFromDated; + SET vDateEnd = util.Dayend(vToDated); + + SELECT a.nickname shopName, + a.city , + IFNULL(pe.equivalentFk ,tp.packagingFk) FustCode, + tp.quantity, + tp.ticketFk, + CONCAT('From ', vFromDated,' to ', vToDated) AS dateRange + FROM vn.ticketPackaging tp + JOIN vn.ticket t ON t.id = tp.ticketFk + 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.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 + WHERE t.shipped BETWEEN vFromDated AND util.dayend(vToDated) + AND wa.name = 'VNH' + AND p.isPackageReturnable + AND c.country = 'FRANCIA' + AND t.clientFk != vSijsnerClientFk + AND tp.quantity > 0; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `fv_pca` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60560,8 +54218,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `fv_pca`() BEGIN @@ -60667,6 +54323,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `getDayExpeditions` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60674,8 +54332,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `getDayExpeditions`() BEGIN @@ -60687,7 +54343,7 @@ BEGIN t.routeFk as routeFk FROM vn2008.expeditions e INNER JOIN vn.ticket t ON t.id = e.ticket_id - WHERE DATE(odbc_date) = util.VN_CURDATE(); + WHERE DATE(odbc_date) = vn.VN_CURDATE(); END ;; DELIMITER ; @@ -60695,43 +54351,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 `getDeliveryWorkers` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `getDeliveryWorkers`() -BEGIN -SELECT w.id, - concat(p.firstname," ",p.name) AS fullName, - w.code AS workerCode, - pwc.name, - rl.routeFk as routeLoader - FROM postgresql.person AS p - LEFT JOIN vn.worker AS w ON p.id_trabajador=w.id - LEFT JOIN (SELECT MIN(profile_id) AS pid, person_id FROM postgresql.profile GROUP BY person_id) AS pp ON p.person_id=pp.person_id - LEFT JOIN vn2008.profile_labour_payroll AS plp ON pp.pid=plp.profile_id - LEFT JOIN (SELECT MAX(business_id) AS bimax, client_id FROM postgresql.business GROUP BY client_id) AS pbv ON pbv.client_id = plp.profile_id - LEFT JOIN postgresql.business_labour AS pbl ON pbl.business_id = pbv.bimax - LEFT JOIN vn.department AS pd ON pd.id = pbl.department_id - LEFT JOIN postgresql.workcenter AS pwc ON pwc.workcenter_id=pbl.workcenter_id - LEFT JOIN vn.user u ON u.id=w.userFK - LEFT JOIN vn.routeLoadWorker rl ON rl.workerFk = w.id - WHERE p.id_trabajador Is Not Null - AND pd.name='REPARTO' - AND u.active<>0 - ORDER BY pwc.name ASC,p.firstname ASC; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `getInfoDelivery` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60739,8 +54360,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `getInfoDelivery`(vRouteFk INT) BEGIN @@ -60755,6 +54374,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `getItemUbication` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60762,8 +54383,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `getItemUbication`(vItemFk VARCHAR(22)) BEGIN @@ -60781,30 +54400,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 `getItemVisibleAvailable__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `getItemVisibleAvailable__`( - vItem INT, - vDate DATE, - vWarehouse TINYINT, - vRefresh BOOL) -BEGIN - -- DEPRECADO - UTILIZAR vn.item_getVisibleAvailable() - JSB - 2019-11-20 - CALL item_getVisibleAvailable(vItem, vDate, vWarehouse, vRefresh); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `getPedidosInternos` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60812,8 +54409,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `getPedidosInternos`() BEGIN @@ -60826,6 +54421,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `intrastat_data_neto_Update` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60833,35 +54430,35 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `intrastat_data_neto_Update`(IN vInvoiceInFk INT) -BEGIN - - UPDATE vn2008.intrastat_data id - JOIN ( - SELECT i.intrastatFk, - LEAST(SUM(b.quantity) * IFNULL(it.gramsMax,100000) / 1000, - SUM(ic.cm3 * b.quantity) * IF(i.density, i.density, it.density) / 1000000) as neto - FROM entry e - JOIN travel tr ON tr.id = e.travelFk - JOIN buy b ON b.entryFk = e.id - JOIN item i ON i.id = b.itemFk - join itemType it ON it.id = i.typeFk - JOIN itemCost ic ON ic.itemFk = i.id AND tr.warehouseInFk = ic.warehouseFk - WHERE e.invoiceInFk = vinvoiceInFk - GROUP BY i.intrastatFk) sub ON sub.intrastatFk = id.intrastat_id - SET id.neto = ROUND(sub.neto, 1) - WHERE id.recibida_id = vInvoiceInFk; - - +BEGIN + + UPDATE vn2008.intrastat_data id + JOIN ( + SELECT i.intrastatFk, + LEAST(SUM(b.quantity) * IFNULL(it.gramsMax,100000) / 1000, + SUM(ic.cm3 * b.quantity) * IF(i.density, i.density, it.density) / 1000000) as neto + FROM entry e + JOIN travel tr ON tr.id = e.travelFk + JOIN buy b ON b.entryFk = e.id + JOIN item i ON i.id = b.itemFk + join itemType it ON it.id = i.typeFk + JOIN itemCost ic ON ic.itemFk = i.id AND tr.warehouseInFk = ic.warehouseFk + WHERE e.invoiceInFk = vinvoiceInFk + GROUP BY i.intrastatFk) sub ON sub.intrastatFk = id.intrastat_id + SET id.neto = ROUND(sub.neto, 1) + WHERE id.recibida_id = vInvoiceInFk; + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `inventoryFailureAdd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60869,8 +54466,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `inventoryFailureAdd`() BEGIN @@ -60923,6 +54518,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `inventoryMake` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60930,28 +54527,27 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `inventoryMake`(vDate DATE, vWh INT) proc: BEGIN /** - * Recalcula los inventarios de todos los almacenes, si vWh = 0 - * - * @param vDate Fecha de los nuevos inventarios - * @param vWh almacen al cual hacer el inventario - */ - +* Recalcula los inventarios de todos los almacenes, si vWh = 0 +* +* @param vDate Fecha de los nuevos inventarios +* @param vWh almacen al cual hacer el inventario +*/ + DECLARE vDone BOOL; DECLARE vEntryFk INT; DECLARE vTravelFk INT; - DECLARE vDateLastInventory DATE; - DECLARE vDateYesterday DATETIME DEFAULT TIMESTAMPADD(SECOND,-1,vDate); + DECLARE vDateLastInventory DATE; + DECLARE vDateYesterday DATETIME DEFAULT TIMESTAMPADD(SECOND,-1,vDate); DECLARE cWarehouses CURSOR FOR - SELECT id - FROM warehouse - WHERE isInventory AND vWh IN (0,id); + SELECT id + FROM warehouse + WHERE isInventory + AND vWh IN (0,id); DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; @@ -60971,32 +54567,32 @@ proc: BEGIN SELECT MAX(landed) INTO vDateLastInventory FROM travel tr - JOIN entry e ON e.travelFk = tr.id - JOIN buy b ON b.entryFk = e.id + JOIN entry e ON e.travelFk = tr.id + JOIN buy b ON b.entryFk = e.id WHERE warehouseOutFk = 13 AND landed < vDate - AND e.supplierFk = 4 + AND e.supplierFk = 4 AND warehouseInFk = vWh - AND NOT isRaid; - + AND NOT isRaid; + IF vDateLastInventory IS NULL THEN SELECT inventoried INTO vDateLastInventory FROM config; - END IF; - - -- Generamos travel, si no existe. - SET vTravelFK = 0; - - SELECT id INTO vTravelFk + END IF; + + -- Generamos travel, si no existe. + SET vTravelFK = 0; + + SELECT id INTO vTravelFk FROM travel - WHERE warehouseOutFk = 13 + WHERE warehouseOutFk = 13 AND warehouseInFk = vWh - AND landed = vDate - AND agencyFk = 53 - AND ref = 'inventario' + AND landed = vDate + AND agencyFk = 53 + AND ref = 'inventario' LIMIT 1; - - IF NOT vTravelFK THEN - + + IF NOT vTravelFK THEN + INSERT INTO travel SET warehouseOutFk = 13, warehouseInFk = vWh, @@ -61007,17 +54603,17 @@ proc: BEGIN isDelivered = TRUE, isReceived = TRUE; - SELECT LAST_INSERT_ID() INTO vTravelFk; - + SELECT LAST_INSERT_ID() INTO vTravelFk; + END IF; - - -- Generamos entrada si no existe, o la vaciamos. - SET vEntryFk = 0; - - SELECT id INTO vEntryFk + + -- Generamos entrada si no existe, o la vaciamos. + SET vEntryFk = 0; + + SELECT id INTO vEntryFk FROM entry - WHERE supplierFk = 4 - AND travelFk = vTravelFk; + WHERE supplierFk = 4 + AND travelFk = vTravelFk; IF NOT vEntryFk THEN @@ -61028,82 +54624,82 @@ proc: BEGIN travelFk = vTravelFk; SELECT LAST_INSERT_ID() INTO vEntryFk; - + ELSE - + DELETE FROM buy WHERE entryFk = vEntryFk; - + END IF; -- Preparamos tabla auxilar DROP TEMPORARY TABLE IF EXISTS tmp.inventory; - - CREATE TEMPORARY TABLE tmp.inventory + + CREATE TEMPORARY TABLE tmp.inventory ( - itemFk INT(11) NOT NULL PRIMARY KEY, - quantity int(11) DEFAULT '0', - buyingValue decimal(10,3) DEFAULT '0.000', - freightValue decimal(10,3) DEFAULT '0.000', - packing int(11) DEFAULT '0', - `grouping` smallint(5) unsigned NOT NULL DEFAULT '1', - groupingMode tinyint(4) NOT NULL DEFAULT 0 , - comissionValue decimal(10,3) DEFAULT '0.000', - packageValue decimal(10,3) DEFAULT '0.000', - packageFk varchar(10) COLLATE utf8_unicode_ci DEFAULT '--', - price1 decimal(10,2) DEFAULT '0.00', - price2 decimal(10,2) DEFAULT '0.00', - price3 decimal(10,2) DEFAULT '0.00', - minPrice decimal(10,2) DEFAULT '0.00', - producer varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, + itemFk INT(11) NOT NULL PRIMARY KEY, + quantity int(11) DEFAULT '0', + buyingValue decimal(10,3) DEFAULT '0.000', + freightValue decimal(10,3) DEFAULT '0.000', + packing int(11) DEFAULT '0', + `grouping` smallint(5) unsigned NOT NULL DEFAULT '1', + groupingMode tinyint(4) NOT NULL DEFAULT 0 , + comissionValue decimal(10,3) DEFAULT '0.000', + packageValue decimal(10,3) DEFAULT '0.000', + packageFk varchar(10) COLLATE utf8_unicode_ci DEFAULT '--', + price1 decimal(10,2) DEFAULT '0.00', + price2 decimal(10,2) DEFAULT '0.00', + price3 decimal(10,2) DEFAULT '0.00', + minPrice decimal(10,2) DEFAULT '0.00', + producer varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, INDEX (itemFK)) ENGINE = MEMORY ; -- Compras - INSERT INTO tmp.inventory(itemFk,quantity) + INSERT INTO tmp.inventory(itemFk,quantity) SELECT b.itemFk, sum(b.quantity) FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - WHERE tr.warehouseInFk = vWh + JOIN entry e ON e.id = b.entryFk + JOIN travel tr ON tr.id = e.travelFk + WHERE tr.warehouseInFk = vWh AND tr.landed BETWEEN vDateLastInventory - AND vDateYesterday - AND NOT isRaid + AND vDateYesterday + AND NOT isRaid GROUP BY b.itemFk; - SELECT vDateLastInventory , vDateYesterday; + SELECT vDateLastInventory , vDateYesterday; + -- Traslados - INSERT INTO tmp.inventory(itemFk,quantity) + INSERT INTO tmp.inventory(itemFk,quantity) SELECT itemFk, quantityOut - FROM ( + FROM ( SELECT b.itemFk, -sum(b.quantity) quantityOut FROM buy b JOIN entry e ON e.id = b.entryFk JOIN travel tr ON tr.id = e.travelFk WHERE tr.warehouseOutFk = vWh - AND tr.shipped BETWEEN vDateLastInventory - AND vDateYesterday + AND tr.shipped BETWEEN vDateLastInventory + AND vDateYesterday AND NOT isRaid GROUP BY b.itemFk - ) sub + ) sub ON DUPLICATE KEY UPDATE quantity = IFNULL(quantity,0) + sub.quantityOut; - + -- Ventas - INSERT INTO tmp.inventory(itemFk,quantity) + INSERT INTO tmp.inventory(itemFk,quantity) SELECT itemFk, saleOut - FROM ( + FROM ( SELECT s.itemFk, -sum(s.quantity) saleOut FROM sale s JOIN ticket t ON t.id = s.ticketFk WHERE t.warehouseFk = vWh AND t.shipped BETWEEN vDateLastInventory AND vDateYesterday GROUP BY s.itemFk - ) sub + ) sub ON DUPLICATE KEY UPDATE quantity = IFNULL(quantity,0) + sub.saleOut; -- Actualiza valores de la ultima compra - UPDATE tmp.inventory inv JOIN cache.last_buy lb ON lb.item_id = inv.itemFk AND lb.warehouse_id = vWh - JOIN buy b ON b.id = lb.buy_id + JOIN buy b ON b.id = lb.buy_id SET inv.buyingValue = b.buyingValue, inv.freightValue = b.freightValue, @@ -61135,7 +54731,7 @@ proc: BEGIN price3, minPrice, producer, - entryFk) + entryFk) SELECT itemFk, GREATEST(quantity,0), buyingValue, @@ -61151,19 +54747,25 @@ proc: BEGIN price3, minPrice, producer, - vEntryFk + vEntryFk FROM tmp.inventory; - SELECT vWh, count(*), util.VN_NOW() FROM tmp.inventory; - + SELECT vWh, count(*), vn.VN_NOW() FROM tmp.inventory; + + -- Actualizamos el campo lastUsed de vn.item + UPDATE vn.item i + JOIN tmp.inventory i2 ON i2.itemFk = i.id + SET i.lastUsed = vn.VN_NOW() + WHERE i2.quantity; + -- DROP TEMPORARY TABLE tmp.inventory; - + END LOOP; CLOSE cWarehouses; UPDATE config SET inventoried = vDate; - SET @isModeInventory := FALSE; + SET @isModeInventory := FALSE; DROP TEMPORARY TABLE IF EXISTS tmp.entryToDelete; CREATE TEMPORARY TABLE tmp.entryToDelete @@ -61173,9 +54775,9 @@ proc: BEGIN FROM vn.travel t JOIN vn.entry e ON e.travelFk = t.id WHERE e.supplierFk = 4 - AND t.shipped <= TIMESTAMPADD(DAY, -2, TIMESTAMPADD(DAY, -10, util.VN_CURDATE())) - AND (DAY(t.shipped) <> 1 OR shipped < TIMESTAMPADD(MONTH, -12, util.VN_CURDATE())); - + AND t.shipped <= TIMESTAMPADD(DAY, -2, TIMESTAMPADD(DAY, -10, vn.VN_CURDATE())) + AND (DAY(t.shipped) <> 1 OR shipped < TIMESTAMPADD(MONTH, -12, vn.VN_CURDATE())); + DELETE e FROM vn.entry e JOIN tmp.entryToDelete tmp ON tmp.entryId = e.id; @@ -61189,6 +54791,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `inventoryMakeLauncher` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -61196,8 +54800,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `inventoryMakeLauncher`() BEGIN @@ -61205,7 +54807,7 @@ BEGIN * Recalcula los inventarios de todos los almacenes. */ - call vn.inventoryMake(TIMESTAMPADD(DAY, -10, util.VN_CURDATE()), 0); + call vn.inventoryMake(TIMESTAMPADD(DAY, -10, vn.VN_CURDATE()), 0); END ;; DELIMITER ; @@ -61213,257 +54815,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 `inventoryMake__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `inventoryMake__`(vDate DATE, vWh INT) -proc: BEGIN -/** - * bernat WORKING IN THIS FILE - * Recalcula los inventarios de todos los almacenes, si vWh = 0 - * - * @param vDate Fecha de los nuevos inventarios - */ - - DECLARE vDone BOOL; - DECLARE vEntryFk INT; - DECLARE vTravelFk INT; - DECLARE vDateTime DATETIME DEFAULT TIMESTAMP(vDate, '00:00:00'); - DECLARE vDeleteDate DATE DEFAULT TIMESTAMPADD(DAY, -2, vDate); - DECLARE vDateLastInventory DATE; - DECLARE vDateYesterday DATETIME DEFAULT TIMESTAMPADD(SECOND,-1,vDate); - - DECLARE cWarehouses CURSOR FOR - SELECT id FROM vn.warehouse WHERE isInventory AND vWh IN (0,id); - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - SELECT vDateYesterday; - - OPEN cWarehouses; - SET @isModeInventory := TRUE; - l: LOOP - - SET vDone = FALSE; - FETCH cWarehouses INTO vWh; - - IF vDone THEN - LEAVE l; - END IF; - - SELECT MAX(landed) INTO vDateLastInventory - FROM vn.travel tr - JOIN vn.entry e ON e.travelFk = tr.id - JOIN vn.buy b ON b.entryFk = e.id - WHERE warehouseOutFk = 13 - AND landed < vDate - AND e.supplierFk = 4 - AND warehouseInFk = vWh - AND NOT isRaid; - - -- Generamos travel, si no existe. - SET vTravelFK = 0; - - SELECT id INTO vTravelFk - FROM vn.travel - WHERE warehouseOutFk = 13 - AND warehouseInFk = vWh - AND landed = vDate - AND agencyFk = 53 - AND ref = 'inventario' - LIMIT 1; - - IF NOT vTravelFK THEN - - INSERT INTO vn.travel SET - warehouseOutFk = 13, - warehouseInFk = vWh, - shipped = vDateTime, - landed = vDate, - agencyFk = 53, - ref = 'inventario', - isDelivered = TRUE, - isReceived = TRUE; - - SELECT LAST_INSERT_ID() INTO vTravelFk; - - END IF; - - -- Generamos entrada si no existe, o la vaciamos. - SET vEntryFk = 0; - - SELECT id INTO vEntryFk - FROM vn.entry - WHERE supplierFk = 4 - AND travelFk = vTravelFk; - - IF NOT vEntryFk THEN - - INSERT INTO entry SET - supplierFk = 4, - isConfirmed = TRUE, - isOrdered = TRUE, - travelFk = vTravelFk; - - SELECT LAST_INSERT_ID() INTO vEntryFk; - - ELSE - - DELETE FROM vn.buy WHERE entryFk = vEntryFk; - - END IF; - - -- Preparamos tabla auxilar - DROP TEMPORARY TABLE IF EXISTS tmp.inventory; - - CREATE TEMPORARY TABLE tmp.inventory - ( - itemFk INT(11) NOT NULL PRIMARY KEY, - quantity int(11) DEFAULT '0', - buyingValue decimal(10,3) DEFAULT '0.000', - freightValue decimal(10,3) DEFAULT '0.000', - packing int(11) DEFAULT '0', - `grouping` smallint(5) unsigned NOT NULL DEFAULT '1', - groupingMode tinyint(4) NOT NULL DEFAULT 0 , - comissionValue decimal(10,3) DEFAULT '0.000', - packageValue decimal(10,3) DEFAULT '0.000', - packageFk varchar(10) COLLATE utf8_unicode_ci DEFAULT '--', - price1 decimal(10,2) DEFAULT '0.00', - price2 decimal(10,2) DEFAULT '0.00', - price3 decimal(10,2) DEFAULT '0.00', - minPrice decimal(10,2) DEFAULT '0.00', - producer varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL, - INDEX (itemFK)) - ENGINE = MEMORY ; - - -- Compras - INSERT INTO tmp.inventory(itemFk,quantity) - SELECT b.itemFk, sum(b.quantity) - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - WHERE tr.warehouseInFk = vWh - AND tr.landed BETWEEN vDateLastInventory - AND vDateYesterday - AND NOT isRaid - GROUP BY b.itemFk; - SELECT vDateLastInventory , vDateYesterday; - -- Traslados - INSERT INTO tmp.inventory(itemFk,quantity) - SELECT itemFk, quantityOut - FROM ( - SELECT b.itemFk, -sum(b.quantity) quantityOut - FROM vn.buy b - JOIN vn.entry e ON e.id = b.entryFk - JOIN vn.travel tr ON tr.id = e.travelFk - WHERE tr.warehouseOutFk = vWh - AND tr.shipped BETWEEN vDateLastInventory - AND vDateYesterday - AND NOT isRaid - GROUP BY b.itemFk - ) sub - ON DUPLICATE KEY UPDATE quantity = IFNULL(quantity,0) + sub.quantityOut; - - -- Ventas - INSERT INTO tmp.inventory(itemFk,quantity) - SELECT itemFk, saleOut - FROM ( - SELECT s.itemFk, -sum(s.quantity) saleOut - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - WHERE t.warehouseFk = vWh - AND t.shipped BETWEEN vDateLastInventory AND vDateYesterday - GROUP BY s.itemFk - ) sub - ON DUPLICATE KEY UPDATE quantity = IFNULL(quantity,0) + sub.saleOut; - - -- Actualiza valores de la ultima compra - - UPDATE tmp.inventory inv - JOIN cache.last_buy lb ON lb.item_id = inv.itemFk AND lb.warehouse_id = vWh - JOIN vn.buy b ON b.id = lb.buy_id - SET - inv.buyingValue = b.buyingValue, - inv.freightValue = b.freightValue, - inv.packing = b.packing, - inv.`grouping` = b.`grouping`, - inv.groupingMode = b.groupingMode, - inv.comissionValue = b.comissionValue, - inv.packageValue = b.packageValue, - inv.packageFk = b.packageFk, - inv.price1 = b.price1, - inv.price2 = b.price2, - inv.price3 = b.price3, - inv.minPrice = b.minPrice, - inv.producer = b.producer; - - - INSERT INTO vn.buy( itemFk, - quantity, - buyingValue, - freightValue, - packing, - `grouping`, - groupingMode, - comissionValue, - packageValue, - packageFk, - price1, - price2, - price3, - minPrice, - producer, - entryFk) - SELECT itemFk, - quantity, - buyingValue, - freightValue, - packing, - `grouping`, - groupingMode, - comissionValue, - packageValue, - packageFk, - price1, - price2, - price3, - minPrice, - producer, - vEntryFk - FROM tmp.inventory; - - SELECT vWh, count(*), util.VN_NOW() FROM tmp.inventory; - - -- DROP TEMPORARY TABLE tmp.inventory; - - END LOOP; - - CLOSE cWarehouses; - - UPDATE vn2008.tblContadores SET FechaInventario = vDate; - SET @isModeInventory := FALSE; - - DELETE e, t - FROM vn.travel t - JOIN vn.entry e ON e.travelFk = t.id - WHERE e.supplierFk = 4 - AND t.shipped <= vDeleteDate - AND (DAY(t.shipped) <> 1 OR shipped < TIMESTAMPADD(MONTH, -12, util.VN_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 `inventory_repair` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -61471,8 +54824,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `inventory_repair`() BEGIN @@ -61512,7 +54863,7 @@ BEGIN LEFT JOIN origin o ON o.id = i.originFk ) ON it.id = i.typeFk LEFT JOIN edi.ekt ek ON b.ektFk = ek.id - WHERE (b.packageFk = "--" OR b.price2 = 0 OR b.packing = 0 OR b.buyingValue = 0) AND tr.landed > util.firstDayOfMonth(TIMESTAMPADD(MONTH,-1,util.VN_CURDATE())) AND s.name = 'INVENTARIO'; + WHERE (b.packageFk = "--" OR b.price2 = 0 OR b.packing = 0 OR b.buyingValue = 0) AND tr.landed > util.firstDayOfMonth(TIMESTAMPADD(MONTH,-1,vn.VN_CURDATE())) AND s.name = 'INVENTARIO'; DROP TEMPORARY TABLE IF EXISTS tmp.lastEntryOk; CREATE TEMPORARY TABLE tmp.lastEntryOk @@ -61549,7 +54900,7 @@ BEGIN LEFT JOIN origin o ON o.id = i.originFk ) ON it.id = i.typeFk LEFT JOIN edi.ekt ek ON b.ektFk = ek.id - WHERE b.packageFk != "--" AND b.price2 != 0 AND b.packing != 0 AND b.buyingValue > 0 AND tr.landed > util.firstDayOfMonth(TIMESTAMPADD(MONTH,-2,util.VN_CURDATE())) + WHERE b.packageFk != "--" AND b.price2 != 0 AND b.packing != 0 AND b.buyingValue > 0 AND tr.landed > util.firstDayOfMonth(TIMESTAMPADD(MONTH,-2,vn.VN_CURDATE())) ORDER BY tr.landed DESC; DROP TEMPORARY TABLE IF EXISTS tmp.lastEntryOkGroup; @@ -61588,6 +54939,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceExpenceMake` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -61595,8 +54948,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceExpenceMake`(IN vInvoice INT) BEGIN @@ -61631,47 +54982,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 `invoiceExpenceMake__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceExpenceMake__`(IN vInvoice INT) -BEGIN -/* Inserta las partidas de gasto correspondientes a la factura - * REQUIERE tabla ticketToInvoice - * - * @param vInvoice Numero de factura - * - */ - DELETE FROM invoiceOutExpence - WHERE invoiceOutFk = vInvoice; - - INSERT INTO invoiceOutExpence( - invoiceOutFk, - expenceFk, - amount - ) - SELECT - vInvoice, - expenceFk, - SUM(ROUND(quantity * price * (100 - discount)/100,2)) amount - FROM ticketToInvoice t - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - GROUP BY i.expenceFk - HAVING amount != 0; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceFromAddress` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -61679,13 +54991,11 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceFromAddress`(vMaxTicketDate DATETIME,vAddress INT,vCompany INT) BEGIN - DECLARE vMinDateTicket DATE DEFAULT TIMESTAMPADD(MONTH, -3, util.VN_CURDATE()); + DECLARE vMinDateTicket DATE DEFAULT TIMESTAMPADD(MONTH, -3, vn.VN_CURDATE()); SET vMaxTicketDate = vn2008.DAYEND(vMaxTicketDate); @@ -61704,6 +55014,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceFromClient` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -61711,12 +55023,10 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceFromClient`(IN vMaxTicketDate datetime, IN vClientFk INT, IN vCompanyFk INT) BEGIN - DECLARE vMinTicketDate DATE DEFAULT TIMESTAMPADD(YEAR, -3, util.VN_CURDATE()); + DECLARE vMinTicketDate DATE DEFAULT TIMESTAMPADD(YEAR, -3, vn.VN_CURDATE()); SET vMaxTicketDate = util.dayend(vMaxTicketDate); DROP TEMPORARY TABLE IF EXISTS `ticketToInvoice`; @@ -61734,6 +55044,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceFromTicket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -61741,8 +55053,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceFromTicket`(IN vTicket INT) BEGIN @@ -61761,6 +55071,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceInBookingCommon` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -61768,8 +55080,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceInBookingCommon`(vInvoiceInId INT, OUT vSerialNumber INT) BEGIN @@ -61821,6 +55131,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceInBookingMain` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -61828,8 +55140,6 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `invoiceInBookingMain`(vInvoiceInId INT) BEGIN @@ -62079,545 +55389,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 `invoiceInBookingMain__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceInBookingMain__`(vInvoiceInId INT) -BEGIN - DECLARE vTotalAmount,vTotalAmountDivisa DECIMAL(10,2); - DECLARE vBookNumber,vSerialNumber INT; - DECLARE vRate DECIMAL(10,4); - DECLARE vSerial VARCHAR(2); - - CALL invoiceInBookingCommon(vInvoiceInId,vSerialNumber); - - SELECT serial - INTO vSerial - FROM newInvoiceIn; - - SELECT SUM(iit.taxableBase * IF(vSerial = 'R' AND tc.`type` <> 'I', 1 +(tc.rate/100),1)), - SUM(iit.foreignValue * IF(vSerial = 'R', 1 +(tc.rate/100),1)), - iit.taxableBase/iit.foreignValue - INTO vTotalAmount, vTotalAmountDivisa, vRate - FROM newInvoiceIn i - JOIN invoiceInTax iit ON iit.invoiceInFk = i.id - JOIN taxCode tc ON iit.taxCodeFk = tc.id; - - CALL vn.ledger_next(vBookNumber); - - -- Apunte del proveedor - - INSERT INTO vn2008.XDiario( - ASIEN, - FECHA, - SUBCTA, - EUROHABER, - CONCEPTO, - CAMBIO, - HABERME, - NFACTICK, - CLAVE, - empresa_id) - SELECT - vBookNumber, - n.bookEntried, - s.supplierAccount, - vTotalAmount EUROHABER, - n.conceptWithSupplier, - vRate, - vTotalAmountDivisa, - n.invoicesCount, - vInvoiceInId, - n.companyFk - FROM newInvoiceIn n - JOIN newSupplier s; - - -- ----------------------------------------------------------- Linea de Gastos - INSERT INTO vn2008.XDiario (ASIEN, - FECHA, - SUBCTA, - CONTRA, - EURODEBE, - EUROHABER, - CONCEPTO, - CAMBIO, - DEBEME, - HABERME, - NFACTICK, - empresa_id - ) - SELECT vBookNumber ASIEN, - n.bookEntried FECHA, - IF(e.isWithheld , LPAD(RIGHT(s.supplierAccount,5),10,iit.expenceFk),iit.expenceFk) SUBCTA, - s.supplierAccount CONTRA, - IF(e.isWithheld AND iit.taxableBase < 0, NULL, ROUND(SUM(iit.taxableBase),2)) EURODEBE, - IF(e.isWithheld AND iit.taxableBase < 0,ROUND(SUM(-iit.taxableBase),2),NULL) EUROHABER, - n.conceptWithSupplier CONCEPTO, - vRate, - IF(e.isWithheld,NULL,ABS(ROUND(SUM(iit.foreignValue),2))) DEBEME, - IF(e.isWithheld,ABS(ROUND(SUM(iit.foreignValue),2)),NULL) HABERME, - n.invoicesCount NFACTICK, - n.companyFk empresa_id - FROM newInvoiceIn n - JOIN newSupplier s - JOIN invoiceInTax iit ON iit.invoiceInFk = n.id - JOIN taxCode tc ON tc.id = iit.taxCodeFk - JOIN expence e ON e.id = iit.expenceFk AND e.taxTypeFk = tc.taxTypeFk - WHERE iit.expenceFk != 5660000002 - GROUP BY iit.expenceFk; - - -- -------------------------------------------------------------------- - -- ------- Lineas de IVA --------------- - -- -------------------------------------------------------------------- - - INSERT INTO vn2008.XDiario( ASIEN, - FECHA, - SUBCTA, - CONTRA, - EURODEBE, - BASEEURO, - CONCEPTO, - FACTURA, - IVA, - AUXILIAR, - SERIE, - TIPOOPE, - FECHA_EX, - FECHA_OP, - NFACTICK, - FACTURAEX, - L340, - LRECT349, - TIPOCLAVE, - TIPOEXENCI, - TIPONOSUJE, - TIPOFACT, - TIPORECTIF, - TERIDNIF, - TERNIF, - TERNOM, - FECREGCON, - empresa_id - ) - SELECT vBookNumber ASIEN, - n.bookEntried FECHA, - tc.code SUBCTA, - s.supplierAccount CONTRA, - SUM(ROUND(tc.rate * it.taxableBase / 100 /* + 0.0001*/ , 2)) EURODEBE, - SUM(it.taxableBase) BASEEURO, - GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO, - vSerialNumber FACTURA, - tc.rate IVA, - IF(isUeeMember AND eWithheld.id IS NULL,'','*') AUXILIAR, - n.serial SERIE, - tt.TIPOOPE, - n.issued FECHA_EX, - n.operated FECHA_OP, - n.invoicesCount NFACTICK, - n.supplierRef FACTURAEX, - TRUE L340, - (isSameCountry OR NOT isUeeMember) LRECT349, - n.cplusTrascendency472Fk TIPOCLAVE, - n.cplusTaxBreakFk TIPOEXENCI, - n.cplusSubjectOpFk TIPONOSUJE, - n.cplusInvoiceType472Fk TIPOFACT, - n.cplusRectificationTypeFk TIPORECTIF, - iis.cplusTerIdNifFk TERIDNIF, - s.nif AS TERNIF, - s.name AS TERNOM, - n.booked FECREGCON, - n.companyFk - FROM newInvoiceIn n - JOIN newSupplier s - JOIN invoiceInTax it ON n.id = it.invoiceInFk - JOIN taxCode tc ON tc.id = it.taxCodeFk - JOIN taxType tt ON tt.id = tc.taxTypeFk - JOIN invoiceInSerial iis ON iis.code = tt.serial - JOIN expence e ON e.id = it.expenceFk - AND e.taxTypeFk = tc.taxTypeFk - LEFT JOIN (SELECT eWithheld.id - FROM invoiceInTax hold - JOIN expence eWithheld ON eWithheld.id = hold.expenceFk AND eWithheld.isWithheld - WHERE hold.invoiceInFk = vInvoiceInId LIMIT 1 - ) eWithheld ON TRUE - WHERE tc.type != '-' - AND tc.isActive - GROUP BY tc.rate, e.id; - - -- Linea iva inversor sujeto pasivo - - INSERT INTO vn2008.XDiario( ASIEN, - FECHA, - SUBCTA, - CONTRA, - EUROHABER, - BASEEURO, - CONCEPTO, - FACTURA, - IVA, - AUXILIAR, - SERIE, - TIPOOPE, - FECHA_EX, - FECHA_OP, - NFACTICK, - FACTURAEX, - L340, - LRECT349, - TIPOCLAVE, - TIPOEXENCI, - TIPONOSUJE, - TIPOFACT, - TIPORECTIF, - TERIDNIF, - TERNIF, - TERNOM, - empresa_id - ) - - SELECT vBookNumber ASIEN, - n.bookEntried FECHA, - tcLink.code SUBCTA, - s.supplierAccount CONTRA, - SUM(ROUND(tcLink.rate * it.taxableBase / 100,2)) EUROHABER, - ROUND(SUM(it.taxableBase),2) BASEEURO, - GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO, - vSerialNumber FACTURA, - tcLink.rate IVA, - '*' AUXILIAR, - n.serial SERIE, - tt.TIPOOPE, - n.issued FECHA_EX, - n.operated FECHA_OP, - n.invoicesCount NFACTICK, - n.supplierRef FACTURAEX, - FALSE L340, - (isSameCountry OR NOT isUeeMember) LRECT349, - 1 TIPOCLAVE, - n.cplusTaxBreakFk TIPOEXENCI, - n.cplusSubjectOpFk TIPONOSUJE, - n.cplusInvoiceType472Fk TIPOFACT, - n.cplusRectificationTypeFk TIPORECTIF, - iis.cplusTerIdNifFk TERIDNIF, - s.nif AS TERNIF, - s.name AS TERNOM, - n.companyFk - FROM newInvoiceIn n - JOIN newSupplier s - JOIN invoiceInTax it ON n.id = it.invoiceInFk - JOIN taxCode tc ON tc.id = it.taxCodeFk - JOIN taxType tt ON tt.id = tc.taxTypeFk - JOIN invoiceInSerial iis ON iis.code = tt.serial - JOIN taxCode tcLink ON tcLink.link = tc.link - AND tc.id != tcLink.id - AND tc.link - JOIN expence e ON e.id = it.expenceFk - AND e.taxTypeFk = tc.taxTypeFk - WHERE tc.isActive - AND (tc.type in('S','I') OR MID(s.supplierAccount,4,1) = '1') - GROUP BY tcLink.rate, e.id; - - -- Actualización del registro original - UPDATE invoiceIn ii - JOIN newInvoiceIn ni ON ii.id = ni.id - SET ii.serialNumber = vSerialNumber, - ii.isBooked = TRUE; - - -- Problemas derivados de la precisión en los decimales al calcular los impuestos - UPDATE XDiario - SET EURODEBE = EURODEBE - - (SELECT IF(ABS(sub.difference) = 0.01, sub.difference, 0) - FROM(SELECT SUM(IFNULL(ROUND(EURODEBE, 2),0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) difference - FROM XDiario - WHERE ASIEN = vBookNumber - )sub - ) - WHERE ASIEN = vBookNumber - AND EURODEBE <> 0 - ORDER BY id DESC - LIMIT 1; - - /*UPDATE XDiario - SET EURODEBE = EURODEBE - - (SELECT SUM(IFNULL(ROUND(EURODEBE,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0)) difference - FROM XDiario - WHERE ASIEN = vBookNumber - HAVING ABS(difference) = 0.01) - WHERE ASIEN = vBookNumber - AND EURODEBE <> 0 - ORDER BY id DESC - LIMIT 1;*/ - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `invoiceInBookingMain___` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceInBookingMain___`(vInvoiceInId INT) -BEGIN - DECLARE vTotalAmount,vTotalAmountDivisa DECIMAL(10,2); - DECLARE vBookNumber,vSerialNumber INT; - DECLARE vRate DECIMAL(10,4); - DECLARE vSerial VARCHAR(2); - - CALL invoiceInBookingCommon(vInvoiceInId,vSerialNumber); - - SELECT serial - INTO vSerial - FROM newInvoiceIn; - - SELECT SUM(iit.taxableBase * IF(vSerial = 'R' AND tc.`type` <> 'I', 1 +(tc.rate/100),1)), - SUM(iit.foreignValue * IF(vSerial = 'R', 1 +(tc.rate/100),1)), - iit.taxableBase/iit.foreignValue - INTO vTotalAmount, vTotalAmountDivisa, vRate - FROM newInvoiceIn i - JOIN invoiceInTax iit ON iit.invoiceInFk = i.id - JOIN taxCode tc ON iit.taxCodeFk = tc.id; - - CALL vn.ledger_next(vBookNumber); - - -- Apunte del proveedor - - INSERT INTO vn2008.XDiario( - ASIEN, - FECHA, - SUBCTA, - EUROHABER, - CONCEPTO, - CAMBIO, - HABERME, - NFACTICK, - CLAVE, - empresa_id) - SELECT - vBookNumber, - n.bookEntried, - s.supplierAccount, - vTotalAmount EUROHABER, - n.conceptWithSupplier, - vRate, - vTotalAmountDivisa, - n.invoicesCount, - vInvoiceInId, - n.companyFk - FROM newInvoiceIn n - JOIN newSupplier s; - - -- ----------------------------------------------------------- Linea de Gastos - INSERT INTO vn2008.XDiario (ASIEN, - FECHA, - SUBCTA, - CONTRA, - EURODEBE, - EUROHABER, - CONCEPTO, - CAMBIO, - DEBEME, - HABERME, - NFACTICK, - empresa_id - ) - SELECT vBookNumber ASIEN, - n.bookEntried FECHA, - IF(e.isWithheld , LPAD(RIGHT(s.supplierAccount,5),10,iit.expenceFk),iit.expenceFk) SUBCTA, - s.supplierAccount CONTRA, - IF(e.isWithheld AND iit.taxableBase < 0, NULL, ROUND(SUM(iit.taxableBase),2)) EURODEBE, - IF(e.isWithheld AND iit.taxableBase < 0,ROUND(SUM(-iit.taxableBase),2),NULL) EUROHABER, - n.conceptWithSupplier CONCEPTO, - vRate, - IF(e.isWithheld,NULL,ABS(ROUND(SUM(iit.foreignValue),2))) DEBEME, - IF(e.isWithheld,ABS(ROUND(SUM(iit.foreignValue),2)),NULL) HABERME, - n.invoicesCount NFACTICK, - n.companyFk empresa_id - FROM newInvoiceIn n - JOIN newSupplier s - JOIN invoiceInTax iit ON iit.invoiceInFk = n.id - JOIN taxCode tc ON tc.id = iit.taxCodeFk - JOIN expence e ON e.id = iit.expenceFk AND e.taxTypeFk = tc.taxTypeFk - WHERE iit.expenceFk != 5660000002 - GROUP BY iit.expenceFk; - - -- -------------------------------------------------------------------- - -- ------- Lineas de IVA --------------- - -- -------------------------------------------------------------------- - - INSERT INTO vn2008.XDiario( ASIEN, - FECHA, - SUBCTA, - CONTRA, - EURODEBE, - BASEEURO, - CONCEPTO, - FACTURA, - IVA, - AUXILIAR, - SERIE, - TIPOOPE, - FECHA_EX, - FECHA_OP, - NFACTICK, - FACTURAEX, - L340, - LRECT349, - TIPOCLAVE, - TIPOEXENCI, - TIPONOSUJE, - TIPOFACT, - TIPORECTIF, - TERIDNIF, - TERNIF, - TERNOM, - FECREGCON, - empresa_id - ) - SELECT vBookNumber ASIEN, - n.bookEntried FECHA, - tc.code SUBCTA, - s.supplierAccount CONTRA, - SUM(ROUND(tc.rate * it.taxableBase / 100 /* + 0.0001*/ , 2)) EURODEBE, - SUM(it.taxableBase) BASEEURO, - GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO, - vSerialNumber FACTURA, - tc.rate IVA, - IF(isUeeMember AND eWithheld.id IS NULL,'','*') AUXILIAR, - n.serial SERIE, - tt.TIPOOPE, - n.issued FECHA_EX, - n.operated FECHA_OP, - n.invoicesCount NFACTICK, - n.supplierRef FACTURAEX, - TRUE L340, - (isSameCountry OR NOT isUeeMember) LRECT349, - n.cplusTrascendency472Fk TIPOCLAVE, - n.cplusTaxBreakFk TIPOEXENCI, - n.cplusSubjectOpFk TIPONOSUJE, - n.cplusInvoiceType472Fk TIPOFACT, - n.cplusRectificationTypeFk TIPORECTIF, - iis.cplusTerIdNifFk TERIDNIF, - s.nif AS TERNIF, - s.name AS TERNOM, - n.booked FECREGCON, - n.companyFk - FROM newInvoiceIn n - JOIN newSupplier s - JOIN invoiceInTax it ON n.id = it.invoiceInFk - JOIN taxCode tc ON tc.id = it.taxCodeFk - JOIN taxType tt ON tt.id = tc.taxTypeFk - JOIN invoiceInSerial iis ON iis.code = tt.serial - JOIN expence e ON e.id = it.expenceFk - AND e.taxTypeFk = tc.taxTypeFk - LEFT JOIN (SELECT eWithheld.id - FROM invoiceInTax hold - JOIN expence eWithheld ON eWithheld.id = hold.expenceFk AND eWithheld.isWithheld - WHERE hold.invoiceInFk = vInvoiceInId LIMIT 1 - ) eWithheld ON TRUE - WHERE tc.type != '-' - AND tc.isActive - GROUP BY tc.rate, e.id; - - -- Linea iva inversor sujeto pasivo - - INSERT INTO vn2008.XDiario( ASIEN, - FECHA, - SUBCTA, - CONTRA, - EUROHABER, - BASEEURO, - CONCEPTO, - FACTURA, - IVA, - AUXILIAR, - SERIE, - TIPOOPE, - FECHA_EX, - FECHA_OP, - NFACTICK, - FACTURAEX, - L340, - LRECT349, - TIPOCLAVE, - TIPOEXENCI, - TIPONOSUJE, - TIPOFACT, - TIPORECTIF, - TERIDNIF, - TERNIF, - TERNOM, - empresa_id - ) - - SELECT vBookNumber ASIEN, - n.bookEntried FECHA, - tcLink.code SUBCTA, - s.supplierAccount CONTRA, - SUM(ROUND(tcLink.rate * it.taxableBase / 100,2)) EUROHABER, - ROUND(SUM(it.taxableBase),2) BASEEURO, - GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO, - vSerialNumber FACTURA, - tcLink.rate IVA, - '*' AUXILIAR, - n.serial SERIE, - tt.TIPOOPE, - n.issued FECHA_EX, - n.operated FECHA_OP, - n.invoicesCount NFACTICK, - n.supplierRef FACTURAEX, - FALSE L340, - (isSameCountry OR NOT isUeeMember) LRECT349, - 1 TIPOCLAVE, - n.cplusTaxBreakFk TIPOEXENCI, - n.cplusSubjectOpFk TIPONOSUJE, - n.cplusInvoiceType472Fk TIPOFACT, - n.cplusRectificationTypeFk TIPORECTIF, - iis.cplusTerIdNifFk TERIDNIF, - s.nif AS TERNIF, - s.name AS TERNOM, - n.companyFk - FROM newInvoiceIn n - JOIN newSupplier s - JOIN invoiceInTax it ON n.id = it.invoiceInFk - JOIN taxCode tc ON tc.id = it.taxCodeFk - JOIN taxType tt ON tt.id = tc.taxTypeFk - JOIN invoiceInSerial iis ON iis.code = tt.serial - JOIN taxCode tcLink ON tcLink.link = tc.link - AND tc.id != tcLink.id - AND tc.link - JOIN expence e ON e.id = it.expenceFk - AND e.taxTypeFk = tc.taxTypeFk - WHERE tc.isActive - AND (tc.type in('S','I') OR MID(s.supplierAccount,4,1) = '1') - GROUP BY tcLink.rate, e.id; - - -- Actualización del registro original - UPDATE invoiceIn ii - JOIN newInvoiceIn ni ON ii.id = ni.id - SET ii.serialNumber = vSerialNumber, - ii.isBooked = TRUE; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceInDueDay_calculate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -62625,108 +55398,56 @@ DELIMITER ; /*!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`@`localhost` 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, - IF(vn.getNextDueDate(issued, detail, payDay) < DATE_ADD(created, INTERVAL 2 DAY), - DATE_ADD(created, INTERVAL 2 DAY), - vn.getNextDueDate(issued, detail, payDay)), - GREATEST(TIMESTAMPADD(DAY, 2, created), TIMESTAMPADD(DAY, detail, 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.detail)) venc, - SUM(iit.foreignValue)/COUNT(DISTINCT(pdd.detail)) foreignValue, - s.payDemFk, - ii.companyFk, - COUNT(DISTINCT(pdd.detail)) cont, - s.payDay, - ii.issued, - 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 vn.payDemDetail pdd ON pdd.id = s.payDemFk - WHERE ii.id = vInvoiceInFk - GROUP BY ii.id - ) sub - JOIN (SELECT @cont:=0) sub2 - JOIN vn.payDemDetail pdd ON pdd.id = sub.payDemFk - GROUP BY detail; - END IF; - +BEGIN + + IF !(SELECT COUNT(*) + FROM invoiceInDueDay iid + WHERE iid.invoiceInFk = vInvoiceInFk) THEN + + INSERT INTO invoiceInDueDay (invoiceInFk, + dueDated, + amount, + foreignValue) + SELECT vInvoiceInFk, + IF(payDay, + IF(vn.getNextDueDate(issued, detail, payDay) < DATE_ADD(created, INTERVAL 2 DAY), + DATE_ADD(created, INTERVAL 2 DAY), + vn.getNextDueDate(issued, detail, payDay)), + GREATEST(TIMESTAMPADD(DAY, 2, created), TIMESTAMPADD(DAY, detail, 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.detail)) venc, + SUM(iit.foreignValue)/COUNT(DISTINCT(pdd.detail)) foreignValue, + s.payDemFk, + ii.companyFk, + COUNT(DISTINCT(pdd.detail)) cont, + s.payDay, + ii.issued, + 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 vn.payDemDetail pdd ON pdd.id = s.payDemFk + WHERE ii.id = vInvoiceInFk + GROUP BY ii.id + ) sub + JOIN (SELECT @cont:=0) sub2 + JOIN vn.payDemDetail pdd ON pdd.id = sub.payDemFk + GROUP BY detail; + 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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` 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, - COUNT(DISTINCT(pdd.detalle)) cont, - s.payDay, - ii.issued - 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_recalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -62734,8 +55455,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceInDueDay_recalc`(vInvoiceInFk INT) BEGIN @@ -62751,6 +55470,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceInTaxMakeByDua` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -62758,8 +55479,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceInTaxMakeByDua`(vDuaFk INT) BEGIN @@ -62796,6 +55515,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceInTax_getFromDua` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -62803,8 +55524,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceInTax_getFromDua`(vDuaFk INT) BEGIN @@ -62841,6 +55560,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceInTax_getFromEntries` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -62848,8 +55569,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceInTax_getFromEntries`(IN vId INT) BEGIN @@ -62899,6 +55618,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceOutAgain` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -62906,8 +55627,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOutAgain`(IN vInvoiceRef VARCHAR(15), vTaxArea VARCHAR(25)) BEGIN @@ -62969,6 +55688,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceOutBooking` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -62976,8 +55697,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOutBooking`(IN vInvoice INT) BEGIN @@ -63169,7 +55888,7 @@ BEGIN WHERE iot.invoiceOutFk = vInvoice; UPDATE invoiceOut - SET booked = util.VN_CURDATE() + SET booked = vn.VN_CURDATE() WHERE id = vInvoice; END ;; DELIMITER ; @@ -63177,6 +55896,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceOutBookingRange` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -63184,8 +55905,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOutBookingRange`() BEGIN @@ -63237,6 +55956,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceOutDelete` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -63244,8 +55965,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOutDelete`(vRef VARCHAR(15)) BEGIN @@ -63316,126 +56035,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 `invoiceOutDelete__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOutDelete__`(vRef VARCHAR(15)) -BEGIN - - UPDATE ticket - SET refFk = NULL - WHERE refFk = vRef; - - DELETE - FROM invoiceOut - WHERE ref = vRef; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `invoiceOutFix_BI_RE_IVA__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOutFix_BI_RE_IVA__`() -BEGIN - -DECLARE done BOOL DEFAULT FALSE; -DECLARE vInvoice INT; - -DECLARE rs CURSOR FOR - SELECT factura_id - FROM vn2008.Facturas - WHERE Importe != BI7 + BI16 + RE4 + RE1 + IVA7 + IVA16 - AND Fecha >= '2017-07-01'; - -DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - -OPEN rs; - -FETCH rs INTO vInvoice; - -SELECT vInvoice, done; - -WHILE NOT done DO - - UPDATE invoiceOut io - JOIN ( - SELECT SUM(amount) AS total - FROM invoiceOutExpence - WHERE invoiceOutFk = vInvoice - ) base - JOIN ( - SELECT SUM(vat) AS total - FROM invoiceOutTax - WHERE invoiceOutFk = vInvoice - ) vat - SET io.amount = base.total + vat.total - WHERE io.id = vInvoice; - - UPDATE vn2008.Facturas - SET BI16 = 0, - BI7 = 0, - RE1 = 0, - RE4 = 0, - IVA7 = 0, - IVA16 = 0 - WHERE factura_id = vInvoice; - - UPDATE vn2008.Facturas f - JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id - SET f.BI16 = iot.taxableBase, f.IVA16 = iot.vat - WHERE f.factura_id = vInvoice - AND iot.pgcFk IN ('4770000021' ,'4770000215', '4770000002','4771000000','4770000000','4770000020'); - - UPDATE vn2008.Facturas f - JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id - SET f.RE4 = iot.vat - WHERE f.factura_id = vInvoice - AND iot.pgcFk = '4770000521'; - - UPDATE vn2008.Facturas f - JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id - SET f.BI7 = iot.taxableBase, f.IVA7 = iot.vat - WHERE f.factura_id = vInvoice - AND iot.pgcFk IN ('4770000010' ,'4770000101'); - - UPDATE vn2008.Facturas f - JOIN invoiceOutTax iot ON iot.invoiceOutFk = f.factura_id - SET f.RE1 = iot.vat - WHERE f.factura_id = vInvoice - AND iot.pgcFk = '4770000110'; - -FETCH rs INTO vInvoice; - -END WHILE; - - -CLOSE rs; - - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceOutListByCompany` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -63443,8 +56044,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOutListByCompany`(vCompany INT, vStarted DATE, vEnded DATE) BEGIN @@ -63476,6 +56075,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceOutTaxAndExpence` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -63483,8 +56084,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOutTaxAndExpence`() BEGIN @@ -63565,241 +56164,243 @@ 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceOut_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' */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_new`( - vSerial VARCHAR(255), - vInvoiceDate DATETIME, - vTaxArea VARCHAR(25), +CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_new`( + vSerial VARCHAR(255), + vInvoiceDate DATETIME, + vTaxArea VARCHAR(25), OUT vNewInvoiceId INT) -BEGIN - -/* Creación de facturas emitidas. -* requiere previamente tabla ticketToInvoice(id). -* -* @param vSerial serie a la cual se hace la factura -* @param vInvoiceDate fecha de la factura -* @param vTaxArea tipo de iva en relacion a la empresa y al cliente -* @param vNewInvoiceId id de la factura que se acaba de generar -* -* @return vNewInvoiceId -*/ - - DECLARE vSpainCountryCode INT DEFAULT 1; - DECLARE vIsAnySaleToInvoice BOOL; - DECLARE vIsAnyServiceToInvoice BOOL; - DECLARE vNewRef VARCHAR(255); - DECLARE vWorker INT DEFAULT account.myUser_getId(); - DECLARE vCompany INT; - DECLARE vSupplier INT; - DECLARE vClient INT; - DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1; - DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6; - DECLARE vCplusSimplifiedInvoiceTypeFk INT DEFAULT 2; - DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R'; - DECLARE vSimplifiedSerial VARCHAR(1) DEFAULT 'S'; - DECLARE vNewInvoiceInId INT; - DECLARE vIsInterCompany BOOL; - - SET vInvoiceDate = IFNULL(vInvoiceDate,util.VN_CURDATE()); - - SELECT t.clientFk, t.companyFk - INTO vClient, vCompany - FROM ticketToInvoice tt - JOIN ticket t ON t.id = tt.id - LIMIT 1; - - -- Eliminem de ticketToInvoice els tickets que no han de ser facturats - DELETE ti.* - FROM ticketToInvoice ti - JOIN ticket t ON t.id = ti.id - JOIN client c ON c.id = t.clientFk - WHERE YEAR(t.shipped) < 2001 - OR c.isTaxDataChecked = FALSE - OR t.isDeleted - OR c.hasToInvoice = FALSE; - - SELECT SUM(s.quantity * s.price * (100 - s.discount)/100), ts.id - INTO vIsAnySaleToInvoice, vIsAnyServiceToInvoice - FROM ticketToInvoice t - LEFT JOIN sale s ON s.ticketFk = t.id - LEFT JOIN ticketService ts ON ts.ticketFk = t.id; - - IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice) - AND (vCorrectingSerial = vSerial OR NOT hasAnyNegativeBase()) - THEN - - -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial - INSERT INTO invoiceOut - ( - ref, - serial, - issued, - clientFk, - dued, - companyFk, - cplusInvoiceType477Fk - ) - SELECT - 1, - vSerial, - vInvoiceDate, - vClient, - getDueDate(vInvoiceDate, dueDay), - vCompany, - IF(vSerial = vCorrectingSerial, - vCplusCorrectingInvoiceTypeFk, - IF(vSerial = vSimplifiedSerial, - vCplusSimplifiedInvoiceTypeFk, - vCplusStandardInvoiceTypeFk)) - FROM client - WHERE id = vClient; - - - SET vNewInvoiceId = LAST_INSERT_ID(); - - SELECT `ref` - INTO vNewRef - FROM invoiceOut - WHERE id = vNewInvoiceId; - - UPDATE ticket t - JOIN ticketToInvoice ti ON ti.id = t.id - SET t.refFk = vNewRef; - - DROP TEMPORARY TABLE IF EXISTS tmp.updateInter; - CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY - SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador - FROM ticketToInvoice ti - LEFT JOIN vn.ticketState ts ON ti.id = ts.ticket - JOIN state s - WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = vn.getAlert3State(ti.id); - - INSERT INTO vncontrol.inter(state_id,Id_Ticket,Id_Trabajador) - SELECT * FROM tmp.updateInter; - - - INSERT INTO ticketLog (action, userFk,originFk, description) - SELECT 'UPDATE',account.userGetId(),ti.id, CONCAT('Crea factura ',vNewRef) - FROM ticketToInvoice ti; - - CALL invoiceExpenceMake(vNewInvoiceId); - CALL invoiceTaxMake(vNewInvoiceId,vTaxArea); - - UPDATE invoiceOut io - JOIN ( - SELECT SUM(amount) AS total - FROM invoiceOutExpence - WHERE invoiceOutFk = vNewInvoiceId - ) base - JOIN ( - SELECT SUM(vat) AS total - FROM invoiceOutTax - WHERE invoiceOutFk = vNewInvoiceId - ) vat - SET io.amount = base.total + vat.total - WHERE io.id = vNewInvoiceId; - - DROP TEMPORARY TABLE tmp.updateInter; - - SELECT ios.isCEE INTO vIsInterCompany - FROM vn.ticket t - JOIN vn.company c ON c.clientFk = t.clientFk - JOIN vn.invoiceOut io ON io.`ref` = t.refFk - JOIN vn.invoiceOutSerial ios ON ios.code = io.serial - WHERE t.refFk = vNewRef; - - IF (vIsInterCompany) THEN - - SELECT vCompany INTO vSupplier; - SELECT id INTO vCompany FROM company WHERE clientFk = vClient; - - INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk) - SELECT vSupplier, vNewRef, vInvoiceDate, vCompany; - - SET vNewInvoiceInId = LAST_INSERT_ID(); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - (KEY (ticketFk)) - ENGINE = MEMORY - SELECT id ticketFk - FROM ticketToInvoice; - - CALL `ticket_getTax`('NATIONAL'); - - SET @vTaxableBaseServices := 0.00; - SET @vTaxCodeGeneral := NULL; - - INSERT INTO vn.invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk) - SELECT vNewInvoiceInId, @vTaxableBaseServices, sub.expenceFk, sub.taxTypeSageFk , sub.transactionTypeSageFk - FROM ( - SELECT @vTaxableBaseServices := SUM(tst.taxableBase) taxableBase, i.expenceFk, i.taxTypeSageFk , i.transactionTypeSageFk, @vTaxCodeGeneral := i.taxClassCodeFk - FROM tmp.ticketServiceTax tst - JOIN vn.invoiceOutTaxConfig i ON i.taxClassCodeFk = tst.code - WHERE i.isService - HAVING taxableBase - ) sub; - - INSERT INTO vn.invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk) - SELECT vNewInvoiceInId, SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral, @vTaxableBaseServices, 0) taxableBase, i.expenceFk, i.taxTypeSageFk , i.transactionTypeSageFk - FROM tmp.ticketTax tt - JOIN vn.invoiceOutTaxConfig i ON i.taxClassCodeFk = tt.code - WHERE !i.isService - GROUP BY tt.pgcFk - HAVING taxableBase - ORDER BY tt.priority; - - CALL `vn`.`invoiceInDueDay_calculate`(vNewInvoiceInId); - - INSERT INTO vn2008.intrastat_data (recibida_id, intrastat_id, importe, unidades, Paises_Id, neto) - SELECT - vNewInvoiceInId, - i.intrastatFk, - CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100)) AS DECIMAL(10,2)) importe, - CAST(SUM(IFNULL(i.stems, 1) * s.quantity) AS DECIMAL (10 , 2 )) stems, - s2.countryFk, - CAST(SUM(IF(sv.physicalWeight, sv.physicalWeight, i.density * sub.cm3delivery/1000000)) AS DECIMAL(10,2)) neto - FROM vn.sale s - LEFT JOIN (SELECT ic.itemFk, ic.cm3delivery - FROM vn.itemCost ic - WHERE ic.cm3 - GROUP BY ic.itemFk) sub ON s.itemFk = sub.itemFk - LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id - LEFT JOIN vn.ticket t ON s.ticketFk = t.id - LEFT JOIN vn.supplier s2 ON s2.id = t.companyFk - LEFT JOIN vn.item i ON i.id = s.itemFk - LEFT JOIN vn.intrastat it ON it.id = i.intrastatFk - JOIN vn.invoiceOut iOut ON iOut.ref = t.refFk - WHERE iOut.`ref` = vNewRef - GROUP BY i.intrastatFk - ORDER BY i.intrastatFk; - - - DROP TEMPORARY TABLE tmp.ticket; - DROP TEMPORARY TABLE tmp.ticketAmount; - DROP TEMPORARY TABLE tmp.ticketTax; - DROP TEMPORARY TABLE tmp.ticketServiceTax; - - END IF; - - END IF; - - DROP TEMPORARY TABLE `ticketToInvoice`; +BEGIN + +/* Creación de facturas emitidas. +* requiere previamente tabla ticketToInvoice(id). +* +* @param vSerial serie a la cual se hace la factura +* @param vInvoiceDate fecha de la factura +* @param vTaxArea tipo de iva en relacion a la empresa y al cliente +* @param vNewInvoiceId id de la factura que se acaba de generar +* +* @return vNewInvoiceId +*/ + + DECLARE vSpainCountryCode INT DEFAULT 1; + DECLARE vIsAnySaleToInvoice BOOL; + DECLARE vIsAnyServiceToInvoice BOOL; + DECLARE vNewRef VARCHAR(255); + DECLARE vWorker INT DEFAULT account.myUser_getId(); + DECLARE vCompany INT; + DECLARE vSupplier INT; + DECLARE vClient INT; + DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1; + DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6; + DECLARE vCplusSimplifiedInvoiceTypeFk INT DEFAULT 2; + DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R'; + DECLARE vSimplifiedSerial VARCHAR(1) DEFAULT 'S'; + DECLARE vNewInvoiceInId INT; + DECLARE vIsInterCompany BOOL; + + SET vInvoiceDate = IFNULL(vInvoiceDate,vn.VN_CURDATE()); + + SELECT t.clientFk, t.companyFk + INTO vClient, vCompany + FROM ticketToInvoice tt + JOIN ticket t ON t.id = tt.id + LIMIT 1; + + -- Eliminem de ticketToInvoice els tickets que no han de ser facturats + DELETE ti.* + FROM ticketToInvoice ti + JOIN ticket t ON t.id = ti.id + JOIN client c ON c.id = t.clientFk + WHERE YEAR(t.shipped) < 2001 + OR c.isTaxDataChecked = FALSE + OR t.isDeleted + OR c.hasToInvoice = FALSE; + + SELECT SUM(s.quantity * s.price * (100 - s.discount)/100), ts.id + INTO vIsAnySaleToInvoice, vIsAnyServiceToInvoice + FROM ticketToInvoice t + LEFT JOIN sale s ON s.ticketFk = t.id + LEFT JOIN ticketService ts ON ts.ticketFk = t.id; + + IF (vIsAnySaleToInvoice OR vIsAnyServiceToInvoice) + AND (vCorrectingSerial = vSerial OR NOT hasAnyNegativeBase()) + THEN + + -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial + INSERT INTO invoiceOut + ( + ref, + serial, + issued, + clientFk, + dued, + companyFk, + cplusInvoiceType477Fk + ) + SELECT + 1, + vSerial, + vInvoiceDate, + vClient, + getDueDate(vInvoiceDate, dueDay), + vCompany, + IF(vSerial = vCorrectingSerial, + vCplusCorrectingInvoiceTypeFk, + IF(vSerial = vSimplifiedSerial, + vCplusSimplifiedInvoiceTypeFk, + vCplusStandardInvoiceTypeFk)) + FROM client + WHERE id = vClient; + + + SET vNewInvoiceId = LAST_INSERT_ID(); + + SELECT `ref` + INTO vNewRef + FROM invoiceOut + WHERE id = vNewInvoiceId; + + UPDATE ticket t + JOIN ticketToInvoice ti ON ti.id = t.id + SET t.refFk = vNewRef; + + DROP TEMPORARY TABLE IF EXISTS tmp.updateInter; + CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY + SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador + FROM ticketToInvoice ti + LEFT JOIN vn.ticketState ts ON ti.id = ts.ticket + JOIN state s + WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = vn.getAlert3State(ti.id); + + INSERT INTO vncontrol.inter(state_id,Id_Ticket,Id_Trabajador) + SELECT * FROM tmp.updateInter; + + + INSERT INTO ticketLog (action, userFk,originFk, description) + SELECT 'UPDATE',account.myUser_getId(),ti.id, CONCAT('Crea factura ',vNewRef) + FROM ticketToInvoice ti; + + CALL invoiceExpenceMake(vNewInvoiceId); + CALL invoiceTaxMake(vNewInvoiceId,vTaxArea); + + UPDATE invoiceOut io + JOIN ( + SELECT SUM(amount) AS total + FROM invoiceOutExpence + WHERE invoiceOutFk = vNewInvoiceId + ) base + JOIN ( + SELECT SUM(vat) AS total + FROM invoiceOutTax + WHERE invoiceOutFk = vNewInvoiceId + ) vat + SET io.amount = base.total + vat.total + WHERE io.id = vNewInvoiceId; + + DROP TEMPORARY TABLE tmp.updateInter; + + SELECT ios.isCEE INTO vIsInterCompany + FROM vn.ticket t + JOIN vn.company c ON c.clientFk = t.clientFk + JOIN vn.invoiceOut io ON io.`ref` = t.refFk + JOIN vn.invoiceOutSerial ios ON ios.code = io.serial + WHERE t.refFk = vNewRef; + + IF (vIsInterCompany) THEN + + SELECT vCompany INTO vSupplier; + SELECT id INTO vCompany FROM company WHERE clientFk = vClient; + + INSERT INTO invoiceIn(supplierFk, supplierRef, issued, companyFk) + SELECT vSupplier, vNewRef, vInvoiceDate, vCompany; + + SET vNewInvoiceInId = LAST_INSERT_ID(); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + (KEY (ticketFk)) + ENGINE = MEMORY + SELECT id ticketFk + FROM ticketToInvoice; + + CALL `ticket_getTax`('NATIONAL'); + + SET @vTaxableBaseServices := 0.00; + SET @vTaxCodeGeneral := NULL; + + INSERT INTO vn.invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk) + SELECT vNewInvoiceInId, @vTaxableBaseServices, sub.expenceFk, sub.taxTypeSageFk , sub.transactionTypeSageFk + FROM ( + SELECT @vTaxableBaseServices := SUM(tst.taxableBase) taxableBase, i.expenceFk, i.taxTypeSageFk , i.transactionTypeSageFk, @vTaxCodeGeneral := i.taxClassCodeFk + FROM tmp.ticketServiceTax tst + JOIN vn.invoiceOutTaxConfig i ON i.taxClassCodeFk = tst.code + WHERE i.isService + HAVING taxableBase + ) sub; + + INSERT INTO vn.invoiceInTax(invoiceInFk, taxableBase, expenceFk, taxTypeSageFk, transactionTypeSageFk) + SELECT vNewInvoiceInId, SUM(tt.taxableBase) - IF(tt.code = @vTaxCodeGeneral, @vTaxableBaseServices, 0) taxableBase, i.expenceFk, i.taxTypeSageFk , i.transactionTypeSageFk + FROM tmp.ticketTax tt + JOIN vn.invoiceOutTaxConfig i ON i.taxClassCodeFk = tt.code + WHERE !i.isService + GROUP BY tt.pgcFk + HAVING taxableBase + ORDER BY tt.priority; + + CALL `vn`.`invoiceInDueDay_calculate`(vNewInvoiceInId); + + INSERT INTO vn2008.intrastat_data (recibida_id, intrastat_id, importe, unidades, Paises_Id, neto) + SELECT + vNewInvoiceInId, + i.intrastatFk, + CAST(SUM((s.quantity * s.price * (100 - s.discount) / 100)) AS DECIMAL(10,2)) importe, + CAST(SUM(IFNULL(i.stems, 1) * s.quantity) AS DECIMAL (10 , 2 )) stems, + s2.countryFk, + CAST(SUM(IF(sv.physicalWeight, sv.physicalWeight, i.density * sub.cm3delivery/1000000)) AS DECIMAL(10,2)) neto + FROM vn.sale s + LEFT JOIN (SELECT ic.itemFk, ic.cm3delivery + FROM vn.itemCost ic + WHERE ic.cm3 + GROUP BY ic.itemFk) sub ON s.itemFk = sub.itemFk + LEFT JOIN vn.saleVolume sv ON sv.saleFk = s.id + LEFT JOIN vn.ticket t ON s.ticketFk = t.id + LEFT JOIN vn.supplier s2 ON s2.id = t.companyFk + LEFT JOIN vn.item i ON i.id = s.itemFk + LEFT JOIN vn.intrastat it ON it.id = i.intrastatFk + JOIN vn.invoiceOut iOut ON iOut.ref = t.refFk + WHERE iOut.`ref` = vNewRef + GROUP BY i.intrastatFk + ORDER BY i.intrastatFk; + + + DROP TEMPORARY TABLE tmp.ticket; + DROP TEMPORARY TABLE tmp.ticketAmount; + DROP TEMPORARY TABLE tmp.ticketTax; + DROP TEMPORARY TABLE tmp.ticketServiceTax; + + END IF; + + END IF; + + DROP TEMPORARY TABLE `ticketToInvoice`; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceOut_newFromClient` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -63807,8 +56408,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_newFromClient`(IN vClientFk int, IN vSerial char(2), IN vMaxShipped date, IN vCompanyFk int, IN vTaxArea varchar(25), @@ -63838,7 +56437,7 @@ BEGIN END IF; CALL invoiceFromClient(vMaxShipped, vClientFk, vCompanyFk); - CALL invoiceOut_new(vSerial, util.VN_CURDATE(), vTaxArea, vInvoiceId); + CALL invoiceOut_new(vSerial, vn.VN_CURDATE(), vTaxArea, vInvoiceId); UPDATE invoiceOut SET `ref` = vRef @@ -63854,6 +56453,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceOut_newFromTicket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -63861,8 +56462,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_newFromTicket`(IN vTicketFk int, IN vSerial char(2), IN vTaxArea varchar(25), IN vRef varchar(25), OUT vInvoiceId int) @@ -63877,7 +56476,7 @@ BEGIN */ DECLARE vIsRefEditable BOOLEAN; CALL invoiceFromTicket(vTicketFk); - CALL invoiceOut_new(vSerial, util.VN_CURDATE(), vTaxArea, vInvoiceId); + CALL invoiceOut_new(vSerial, vn.VN_CURDATE(), vTaxArea, vInvoiceId); IF vRef IS NOT NULL THEN SELECT isRefEditable INTO vIsRefEditable @@ -63901,158 +56500,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 `invoiceOut_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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceOut_new__`( - vSerial VARCHAR(255), - vInvoiceDate DATETIME, - vTaxArea VARCHAR(25), - OUT vNewInvoiceId INT) -BEGIN - -/* Creación de facturas emitidas. -* REQUIERE previamente tabla ticketToInvoice. -* -* @param vSerial, vInvoiceDate,vTaxArea -* -* @return vNewInvoiceId -*/ - - DECLARE vSpainCountryCode INT DEFAULT 1; - DECLARE vIsAnySaleToInvoice BOOL; - DECLARE vNewRef VARCHAR(255); - DECLARE vWorker INT DEFAULT account.myUser_getId(); - DECLARE vCompany INT; - DECLARE vClient INT; - DECLARE vCplusStandardInvoiceTypeFk INT DEFAULT 1; - DECLARE vCplusCorrectingInvoiceTypeFk INT DEFAULT 6; - DECLARE vCplusSimplifiedInvoiceTypeFk INT DEFAULT 2; - DECLARE vCorrectingSerial VARCHAR(1) DEFAULT 'R'; - DECLARE vSimplifiedSerial VARCHAR(1) DEFAULT 'S'; - - SET vInvoiceDate = IFNULL(vInvoiceDate,util.VN_CURDATE()); - - SELECT t.clientFk, t.companyFk - INTO vClient, vCompany - FROM ticketToInvoice tt - JOIN ticket t ON t.id = tt.id - LIMIT 1; - - -- Elimina tickets sense moviments -/* UPDATE ticket t - JOIN ticketToInvoice ti ON ti.id = t.id - LEFT JOIN sale s ON s.ticketFk = ti.id - LEFT JOIN expedition e ON e.ticketFk = t.id - LEFT JOIN ticketPackaging tp ON tp.ticketFk = t.id - SET t.shipped = '2000-02-01 00:00:00' - WHERE s.ticketFk IS NULL AND e.ticketFk IS NULL AND e.ticketFk IS NULL; -*/ - -- Eliminem de ticketToInvoice els tickets que no han de ser facturats - DELETE ti.* - FROM ticketToInvoice ti - JOIN ticket t ON t.id = ti.id - JOIN client c ON c.id = t.clientFk - WHERE YEAR(t.shipped) < 2001 - OR c.isTaxDataChecked = FALSE - OR t.isDeleted - OR c.hasToInvoice = FALSE; - - SELECT SUM(quantity * price * (100 - discount)/100) - INTO vIsAnySaleToInvoice - FROM sale s - JOIN ticketToInvoice t on t.id = s.ticketFk; - - IF vIsAnySaleToInvoice THEN - - -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial - -- el trigger añade el siguiente Id_Factura correspondiente a la vSerial - INSERT INTO invoiceOut - ( - ref, - serial, - issued, - clientFk, - dued, - companyFk, - cplusInvoiceType477Fk - ) - SELECT - 1, - vSerial, - vInvoiceDate, - vClient, - getDueDate(vInvoiceDate, dueDay), - vCompany, - IF(vSerial = vCorrectingSerial, - vCplusCorrectingInvoiceTypeFk, - IF(vSerial = vSimplifiedSerial, - vCplusSimplifiedInvoiceTypeFk, - vCplusStandardInvoiceTypeFk)) - FROM client - WHERE id = vClient; - - - SET vNewInvoiceId = LAST_INSERT_ID(); - - SELECT ref - INTO vNewRef - FROM invoiceOut - WHERE id = vNewInvoiceId; - - UPDATE ticket t - JOIN ticketToInvoice ti ON ti.id = t.id - SET t.refFk = vNewRef; - - DROP TEMPORARY TABLE IF EXISTS tmp.updateInter; - CREATE TEMPORARY TABLE tmp.updateInter ENGINE = MEMORY - SELECT s.id,ti.id ticket_id,vWorker Id_Trabajador - FROM ticketToInvoice ti - LEFT JOIN vn.ticketState ts ON ti.id = ts.ticket - JOIN state s - WHERE IFNULL(ts.alertLevel,0) < 3 and s.`code` = vn.getAlert3State(ti.id); - - INSERT INTO vncontrol.inter(state_id,Id_Ticket,Id_Trabajador) - SELECT * FROM tmp.updateInter; - - - INSERT INTO ticketLog (action, userFk,originFk, description) - SELECT 'UPDATE',account.userGetId(),ti.id, CONCAT('Crea factura ',vNewRef) - FROM ticketToInvoice ti; - - CALL invoiceExpenceMake(vNewInvoiceId); - CALL invoiceTaxMake(vNewInvoiceId,vTaxArea); - - UPDATE invoiceOut io - JOIN ( - SELECT SUM(amount) AS total - FROM invoiceOutExpence - WHERE invoiceOutFk = vNewInvoiceId - ) base - JOIN ( - SELECT SUM(vat) AS total - FROM invoiceOutTax - WHERE invoiceOutFk = vNewInvoiceId - ) vat - SET io.amount = base.total + vat.total - WHERE io.id = vNewInvoiceId; - - END IF; - - DROP TEMPORARY TABLE `ticketToInvoice`; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `invoiceTaxMake` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -64060,8 +56509,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceTaxMake`(vInvoice INT, vTaxArea VARCHAR(25)) BEGIN @@ -64110,62 +56557,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 `invoiceTaxMake__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceTaxMake__`(vInvoice INT, vTaxArea VARCHAR(25)) -BEGIN -/** - * Factura un conjunto de tickets. - * - * @param vInvoice, vTaxAreaFk - * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular - * @return tmp.ticketAmount - * @return tmp.ticketTax Impuesto desglosado para cada ticket. - */ - DELETE FROM invoiceOutTax - WHERE invoiceOutFk = vInvoice; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - (KEY (ticketFk)) - ENGINE = MEMORY - SELECT id ticketFk - FROM ticketToInvoice; - - CALL ticket_getTax(vTaxArea); - - INSERT INTO invoiceOutTax( - invoiceOutFk, - pgcFk, - taxableBase, - vat - ) - SELECT vInvoice, - pgcFk, - SUM(taxableBase) as BASE, - CAST(SUM(taxableBase) * rate / 100 AS DECIMAL (10,2)) - FROM tmp.ticketTax - GROUP BY pgcFk - HAVING BASE; - - DROP TEMPORARY TABLE tmp.ticket; - DROP TEMPORARY TABLE tmp.ticketTax; - DROP TEMPORARY TABLE tmp.ticketAmount; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemBarcode_update` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -64173,8 +56566,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemBarcode_update`(vItemFk INT,vCode VARCHAR(22), vDelete BOOL) BEGIN @@ -64190,321 +56581,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 `itemCard` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemCard`(IN `vBarcode` VARCHAR(22), IN `vWarehouseFk` INT, IN isBarcode BOOL) -BEGIN - - /* - * @deprecated: Utilizar item_getInfo - */ - - DECLARE vCacheVisibleFk INT; - DECLARE vCacheAvailableFk INT; - DECLARE vVisibleAltillo INT; - DECLARE vItemFk INT; - - IF isBarcode THEN - SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; - ELSE - SELECT i.id INTO vItemFk - FROM vn.item i - WHERE i.name LIKE CONCAT('%',vBarcode,'%') - ORDER BY i.id ASC - LIMIT 1; - END IF; - - IF vItemFk IS NULL THEN - SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; - END IF; - - CALL cache.visible_refresh(vCacheVisibleFk, FALSE,vWarehouseFk); - CALL cache.available_refresh(vCacheAvailableFk, FALSE,vWarehouseFk, util.VN_CURDATE()); - - SELECT SUM(visible) INTO vVisibleAltillo - FROM vn.itemShelvingStock - WHERE itemFk = vItemFk AND warehouseFk = vWarehouseFk; - - CALL vn.buyUltimate(vWarehouseFk, util.VN_CURDATE()); - - SELECT i.id, - i.longName, - i.tag5, - i.value5, - i.tag6, - i.value6, - i.tag7, - i.value7, - i.image, - i.size, - i.stems, - i.category, - i.minimum as min, - i.upToDown as repo, - p.name as producer, - o.code as origin, - ip.code as nicho, - ip.reserve as reserva, - v.visible - IFNULL(vVisibleAltillo,0) as enNicho, - a.available, - vVisibleAltillo as enAltillo, - v.visible as total, - 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, - i.itemPackingTypeFk, - i.comment as referencia - FROM vn.item i - LEFT JOIN vn.producer p ON p.id = i.producerFk - LEFT JOIN vn.origin o ON o.id = i.originFk - LEFT JOIN vn.itemPlacement ip ON ip.itemFk = i.id - LEFT JOIN cache.visible v ON v.calc_id = vCacheVisibleFk AND v.item_id = i.id - LEFT JOIN cache.available a ON a.calc_id = vCacheAvailableFk AND a.item_id = i.id - LEFT JOIN ( - SELECT b.itemFk, b2.`grouping`, b2.packing - FROM tmp.buyUltimate b - JOIN vn.buy b2 ON b2.id = b.buyFk - WHERE b.warehouseFk = vWarehouseFk - ) c ON i.id = c.itemFk - WHERE i.id = vItemFk; - - DROP TEMPORARY TABLE tmp.buyUltimate; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `itemCard__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemCard__`(IN `vBarcode` VARCHAR(22), IN `vWarehouseFk` INT, isBarcode BOOL) -BEGIN - - DECLARE vCacheVisibleFk INT; - DECLARE vCacheAvailableFk INT; - DECLARE vVisibleAltillo INT; - DECLARE vItemFk INT; - - IF isBarcode THEN - SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; - ELSE - SELECT i.id INTO vItemFk - FROM vn.item i - WHERE i.name LIKE CONCAT('%',vBarcode,'%') - ORDER BY i.id ASC - LIMIT 1; - END IF; - - IF vItemFk IS NULL THEN - SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; - END IF; - - CALL cache.visible_refresh(vCacheVisibleFk, TRUE,vWarehouseFk); - CALL cache.available_refresh(vCacheAvailableFk, TRUE,vWarehouseFk, util.VN_CURDATE()); - - SELECT SUM(visible) INTO vVisibleAltillo - FROM vn.itemShelvingStock - WHERE itemFk = vItemFk AND warehouseFk = vWarehouseFk; - - CALL vn2008.item_last_buy_(vWarehouseFk,vItemFk); - - SELECT i.id, - i.longName, - i.tag5, - i.value5, - i.tag6, - i.value6, - i.tag7, - i.value7, - i.image, - i.size, - i.stems, - i.category, - i.minimum as min, - i.upToDown as repo, - p.name as producer, - o.code as origin, - ip.code as nicho, - ip.reserve as reserva, - v.visible - IFNULL(vVisibleAltillo,0) as enNicho, - a.available, - vVisibleAltillo as enAltillo, - v.visible as total, - 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, - 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 - LEFT JOIN vn.itemPlacement ip ON ip.itemFk = i.id - LEFT JOIN cache.visible v ON v.calc_id = vCacheVisibleFk AND v.item_id = i.id - LEFT JOIN cache.available a ON a.calc_id = vCacheAvailableFk AND a.item_id = i.id - LEFT JOIN - (SELECT b.item_id,c.`grouping`,c.Packing - FROM vn2008.t_item_last_buy b - INNER JOIN vn2008.Compres c ON c.Id_Compra = b.buy_id - where b.warehouse_id = vWarehouseFk) c - ON i.id= c.item_id - WHERE i.id = vItemFk; - - DROP TEMPORARY TABLE vn2008.t_item_last_buy; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemDiary__`(IN vItemId INT, IN vWarehouse INT) -BEGIN - DECLARE vDateInventory DATETIME; - DECLARE vCurdate DATE DEFAULT util.VN_CURDATE(); - DECLARE vDayEnd DATETIME DEFAULT util.dayEnd(vCurdate); - - SELECT vn.barcodeToItem(vItemId) INTO vItemId; - - -- traduccion: date, alertLevel, origin, reference, name, In, Out, Balance - SELECT inventoried INTO vDateInventory FROM config; - 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, - `in` as invalue - 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 buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN supplier s ON s.id = e.supplierFk - JOIN alertLevel al ON al.id = - CASE - WHEN tr.isReceived != FALSE THEN 3 - WHEN tr.isDelivered THEN 1 - ELSE 0 - END - JOIN 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 buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN warehouse w ON w.id = tr.warehouseOutFk - JOIN supplier s ON s.id = e.supplierFk - JOIN alertLevel al ON al.id = - CASE - WHEN tr.isReceived != FALSE THEN 3 - WHEN tr.isDelivered THEN 1 - ELSE 0 - END - JOIN 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.id 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 sale s - JOIN ticket t ON t.id = s.ticketFk - LEFT JOIN ticketState ts ON ts.ticket = t.id - LEFT JOIN state st ON st.code = ts.code - JOIN client c ON c.id = t.clientFk - JOIN alertLevel al ON al.id = - CASE - WHEN t.shipped < vCurdate THEN 3 - WHEN t.shipped > vDayEnd THEN 0 - ELSE IFNULL(ts.alertLevel, 0) - END - LEFT JOIN 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 */ ; @@ -64512,8 +56590,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemFreight_Show`(vItemFk INT, vWarehouseFk INT) BEGIN @@ -64545,6 +56621,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemFuentesBalance` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -64552,8 +56630,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemFuentesBalance`(vDaysInFuture INT) BEGIN @@ -64608,14 +56684,14 @@ BEGIN LEFT JOIN ( SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as venta FROM vn2008.item_out - WHERE dat BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(util.VN_CURDATE())) + WHERE dat BETWEEN vn.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(vn.VN_CURDATE())) AND warehouse_id = vWarehouseFk GROUP BY item_id ) sale ON sale.item_id = i.id LEFT JOIN ( SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as compra FROM vn2008.item_entry_in - WHERE dat BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(util.VN_CURDATE())) + WHERE dat BETWEEN vn.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(vn.VN_CURDATE())) AND warehouse_id = vWarehouseFk AND isVirtualStock = FALSE GROUP BY item_id @@ -64623,7 +56699,7 @@ BEGIN LEFT JOIN ( SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as traslado FROM vn2008.item_entry_out - WHERE dat BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(util.VN_CURDATE())) + WHERE dat BETWEEN vn.VN_CURDATE() AND TIMESTAMPADD(DAY,vDaysInFuture , util.dayend(vn.VN_CURDATE())) AND warehouse_id = vWarehouseFk GROUP BY item_id ) mov ON mov.item_id = i.id @@ -64638,80 +56714,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 `itemGetVisibleAvailable__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemGetVisibleAvailable__`( - vItem INT, - vDate DATE, - vWarehouse TINYINT, - vRefresh BOOL) -BEGIN - -- DEPRECADO - UTILIZAR vn.item_getVisibleAvailable() - JSB - 2019-11-20 - CALL item_getVisibleAvailable(vItem, vDate, vWarehouse, vRefresh); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `itemLastEntries__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemLastEntries__`(IN `vItem` INT, IN `vDays` DATE) -BEGIN - SELECT - w.id AS warehouseFk, - w.name AS warehouse, - tr.landed, - b.entryFk, - b.isIgnored, - b.price2, - b.price3, - b.stickers, - b.packing, - b.`grouping`, - b.groupingMode, - b.weight, - i.stems, - b.quantity, - b.buyingValue, - b.packageFk , - s.id AS supplierFk, - s.name AS supplier - FROM itemType it - RIGHT JOIN (entry e - LEFT JOIN supplier s ON s.id = e.supplierFk - RIGHT JOIN buy b ON b.entryFk = e.id - LEFT JOIN item i ON i.id = b.itemFk - LEFT JOIN ink ON ink.id = i.inkFk - LEFT JOIN travel tr ON tr.id = e.travelFk - LEFT JOIN warehouse w ON w.id = tr.warehouseInFk - LEFT JOIN origin o ON o.id = i.originFk - ) ON it.id = i.typeFk - LEFT JOIN edi.ekt ek ON b.ektFk = ek.id - WHERE b.itemFk = vItem And tr.shipped BETWEEN vDays AND DATE_ADD(util.VN_CURDATE(), INTERVAl + 10 DAY) - ORDER BY tr.landed DESC , b.id 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 `itemPlacementFromTicket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -64719,8 +56723,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemPlacementFromTicket`(vTicket INT) BEGIN @@ -64749,106 +56751,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 `itemPlacementReloadVisible` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemPlacementReloadVisible`() -BEGIN -/** - * Reemplaza únicamente el campo itemPlacement.pickable - * restando al cache.visible los valores de las tablas - * itemShelving y los tickets con estado impreso - * que aun no han sido preparados. - */ - - DECLARE vCalc INT; - DECLARE vTodayIni DATE DEFAULT util.VN_CURDATE(); - DECLARE vTodayEnd DATETIME DEFAULT util.dayend(vTodayIni); - DECLARE vproductionOrderPrinted INT DEFAULT 4; - DECLARE vWarehouseSillaFv INT DEFAULT 1; - - UPDATE itemPlacement SET pickable = 0; - - CALL cache.visible_refresh(vCalc, FALSE, vWarehouseSillaFv); --- SELECT * FROM cache.visible v; - DROP TEMPORARY TABLE IF EXISTS tmp.itemShelving; - CREATE TEMPORARY TABLE tmp.itemShelving - SELECT itemFk, IFNULL(SUM(visible),0) visible - FROM itemShelving its - GROUP BY its.itemFk; --- SELECT * FROM tmp.itemShelving; - DROP TEMPORARY TABLE IF EXISTS tmp.itemPlacement; - CREATE TEMPORARY TABLE tmp.itemPlacement - SELECT s.itemFk, cast(SUM(s.quantity) AS UNSIGNED) visible - FROM ticket t - JOIN ticketState ts ON ts.ticketFk = t.id AND productionOrder = vproductionOrderPrinted - JOIN sale s ON s.ticketFk = t.id - WHERE t.shipped BETWEEN vTodayIni AND vTodayEnd - GROUP BY s.itemFk; --- SELECT * FROM tmp.itemPlacement; - -/*SELECT v.item_id, vWarehouseSillaFv, v.visible - IFNULL(tis.visible,0) - IFNULL(tip.visible,0) - FROM cache.visible v - LEFT JOIN tmp.itemShelving tis ON tis.itemFk = v.item_id - LEFT JOIN tmp.itemPlacement tip ON tip.itemFk = v.item_id - WHERE v.calc_id = vCalc; - */ - INSERT INTO itemPlacement(itemFk, warehouseFk, pickable) - SELECT v.item_id, vWarehouseSillaFv, v.visible - IFNULL(tis.visible,0) - IFNULL(tip.visible,0) - FROM cache.visible v - LEFT JOIN tmp.itemShelving tis ON tis.itemFk = v.item_id - LEFT JOIN tmp.itemPlacement tip ON tip.itemFk = v.item_id - WHERE v.calc_id = vCalc - ON DUPLICATE KEY UPDATE pickable = VALUES(pickable); - - DROP TEMPORARY TABLE tmp.itemShelving; - DROP TEMPORARY TABLE tmp.itemPlacement; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `itemPlacementSave` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemPlacementSave`( - vCode VARCHAR(22), - vPlacement VARCHAR(10), - vWarehouseFk INT ) -BEGIN - DECLARE vItemFk INT; - SET vItemFk = barcodeToItem(vCode); - - IF ASCII(vPlacement) > 57 THEN - INSERT INTO itemPlacement(itemFk, warehouseFk, reserve, pickable) - VALUES(vItemFk, vWarehouseFk, vPlacement, 0) - ON DUPLICATE KEY UPDATE reserve = vPlacement, modificationDate = util.VN_NOW(); - ELSE - INSERT INTO itemPlacement(itemFk, warehouseFk, code) - VALUES(vItemFk, vWarehouseFk, vPlacement) - ON DUPLICATE KEY UPDATE code = vPlacement, modificationDate = util.VN_NOW(); - END IF; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemPlacementSupplyAiming` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -64856,8 +56760,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemPlacementSupplyAiming`(vShelvingFk VARCHAR(10), quantity INT, vItemFk INT) BEGIN @@ -64892,6 +56794,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemPlacementSupplyCloseOrder` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -64899,8 +56803,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemPlacementSupplyCloseOrder`(vId INT, vQuantity INT) BEGIN @@ -64915,6 +56817,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemPlacementSupplyGetOrder` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -64922,8 +56826,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemPlacementSupplyGetOrder`(vSector INT ) BEGIN @@ -64965,6 +56867,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemPlacementSupplyStockGetTargetList` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -64972,8 +56876,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemPlacementSupplyStockGetTargetList`(vItemFk INT,vSectorFk INT) BEGIN @@ -65015,84 +56917,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 `itemPlacementUpdateVisible` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemPlacementUpdateVisible`() -BEGIN -/** - * Reemplaza únicamente el campo itemPlacement.pickable - * de los articulos de la tabla temporal tmp.itemPlacement(itemFk) - * restando al cache.visible los valores de las tablas - * itemShelving y los tickets con estado impreso - * que aun no han sido preparados. - */ - DECLARE vCalc INT; - DECLARE vTodayIni DATE DEFAULT util.VN_CURDATE(); - DECLARE vTodayEnd DATETIME DEFAULT util.dayend(vTodayIni); - DECLARE vproductionOrderPrinted INT DEFAULT 4; - DECLARE vWarehouseSillaFv INT DEFAULT 1; - - UPDATE itemPlacement SET pickable = 0; - - CALL cache.visible_refresh(vCalc, FALSE, vWarehouseSillaFv); -SELECT * FROM cache.visible v; - DROP TEMPORARY TABLE IF EXISTS tmp.itemShelving; - CREATE TEMPORARY TABLE tmp.itemShelving - SELECT its.itemFk, IFNULL(SUM(visible),0) visible - FROM itemShelving its - JOIN tmp.itemPlacement tip ON tip.itemFk = its.itemFk - GROUP BY its.itemFk; -SELECT * FROM tmp.itemShelving; - -SELECT s.itemFk, cast(SUM(s.quantity) AS UNSIGNED) visible - FROM ticket t - JOIN ticketState ts ON ts.ticketFk = t.id AND productionOrder = vproductionOrderPrinted - JOIN sale s ON s.ticketFk = t.id - JOIN tmp.itemPlacement tip ON tip.itemFk = s.itemFk - WHERE t.shipped BETWEEN vTodayIni AND vTodayEnd - GROUP BY s.itemFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - SELECT s.itemFk, cast(SUM(s.quantity) AS UNSIGNED) visible - FROM ticket t - JOIN ticketState ts ON ts.ticketFk = t.id AND productionOrder = vproductionOrderPrinted - JOIN sale s ON s.ticketFk = t.id - JOIN tmp.itemPlacement tip ON tip.itemFk = s.itemFk - WHERE t.shipped BETWEEN vTodayIni AND vTodayEnd - GROUP BY s.itemFk; -SELECT * FROM tmp.ticket; - -SELECT v.item_id, vWarehouseSillaFv, v.visible - IFNULL(tis.visible,0) - IFNULL(tik.visible,0) - FROM cache.visible v - LEFT JOIN tmp.itemShelving tis ON tis.itemFk = v.item_id - LEFT JOIN tmp.ticket tik ON tik.itemFk = v.item_id - WHERE v.calc_id = vCalc; - - INSERT INTO itemPlacement(itemFk, warehouseFk, pickable) - SELECT v.item_id, vWarehouseSillaFv, v.visible - IFNULL(tis.visible,0) - IFNULL(tik.visible,0) - FROM cache.visible v - LEFT JOIN tmp.itemShelving tis ON tis.itemFk = v.item_id - LEFT JOIN tmp.ticket tik ON tik.itemFk = v.item_id - WHERE v.calc_id = vCalc - ON DUPLICATE KEY UPDATE pickable = VALUES(pickable); - - DROP TEMPORARY TABLE tmp.itemShelving; - DROP TEMPORARY TABLE tmp.ticket; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemProposal` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -65100,8 +56926,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemProposal`(vItemFk INT, vTicketFk INT,vShowType BOOL) BEGIN @@ -65193,6 +57017,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemProposal_Add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -65200,8 +57026,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemProposal_Add`(vSaleFk INT, vMateFk INT, vQuantity INT) BEGIN @@ -65265,6 +57089,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemProposal_beta` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -65272,8 +57098,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemProposal_beta`(vItemFk INT, vTicketFk INT) BEGIN @@ -65354,180 +57178,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 `itemProposal__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemProposal__`(vItemFk INT, vTicketFk INT) -BEGIN - - DECLARE vWarehouseFk INT; - DECLARE vShipped DATE; - DECLARE vCalcFk INT; - DECLARE vTypeFk INT; - DECLARE vResultsMax INT DEFAULT 10; - - DECLARE vTag5 VARCHAR(25); - DECLARE vTag6 VARCHAR(25); - DECLARE vTag7 VARCHAR(25); - DECLARE vTag8 VARCHAR(25); - - DECLARE vValue5 VARCHAR(50); - DECLARE vValue6 VARCHAR(50); - DECLARE vValue7 VARCHAR(50); - DECLARE vValue8 VARCHAR(50); - - SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped - FROM vn.ticket - WHERE id = vTicketFk; - - SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8 - INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8 - FROM vn.item i - LEFT JOIN vn.tag t5 ON t5.name = i.tag5 COLLATE utf8_general_ci - LEFT JOIN vn.tag t6 ON t6.name = i.tag6 COLLATE utf8_general_ci - LEFT JOIN vn.tag t7 ON t7.name = i.tag7 COLLATE utf8_general_ci - LEFT JOIN vn.tag t8 ON t8.name = i.tag8 COLLATE utf8_general_ci - WHERE i.id = vItemFk; - - CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vShipped); - - SELECT i.id itemFk, - i.longName, - i.subName, - i.tag5, - i.value5, - (i.value5 <=> vValue5 COLLATE utf8_general_ci) match5, - i.tag6, - i.value6, - (i.value6 <=> vValue6 COLLATE utf8_general_ci) match6, - i.tag7, - i.value7, - (i.value7 <=> vValue7 COLLATE utf8_general_ci) match7, - i.tag8, - i.value8, - (i.value8 <=> vValue8 COLLATE utf8_general_ci) match8, - a.available, - IFNULL(ip.counter,0) counter - FROM vn.item i - JOIN cache.available a ON a.item_id = i.id - LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vItemFk - WHERE a.calc_id = vCalcFk - AND available > 0 - AND i.typeFk = vTypeFk - AND i.id != vItemFk - ORDER BY counter DESC, - (i.tag5 = vTag5 COLLATE utf8_general_ci) DESC, - (i.value5 = vValue5 COLLATE utf8_general_ci) DESC, - (i.tag6 = vTag6 COLLATE utf8_general_ci) DESC, - (i.value6 = vValue6 COLLATE utf8_general_ci) DESC, - (i.tag7 = vTag7 COLLATE utf8_general_ci) DESC, - (i.value7 = vValue7 COLLATE utf8_general_ci) DESC, - (i.tag8 = vTag8 COLLATE utf8_general_ci) DESC, - (i.value8 = vValue8 COLLATE utf8_general_ci) DESC - LIMIT vResultsMax; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `itemProposal__2` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemProposal__2`(vItemFk INT, vTicketFk INT) -BEGIN - - DECLARE vWarehouseFk INT; - DECLARE vShipped DATE; - DECLARE vCalcFk INT; - DECLARE vTypeFk INT; - DECLARE vResultsMax INT DEFAULT 10; - - DECLARE vTag1 VARCHAR(25); - DECLARE vTag5 VARCHAR(25); - DECLARE vTag6 VARCHAR(25); - DECLARE vTag7 VARCHAR(25); - DECLARE vTag8 VARCHAR(25); - - DECLARE vValue1 VARCHAR(50); - DECLARE vValue5 VARCHAR(50); - DECLARE vValue6 VARCHAR(50); - DECLARE vValue7 VARCHAR(50); - DECLARE vValue8 VARCHAR(50); - - SELECT warehouseFk, shipped INTO vWarehouseFk, vShipped - FROM vn.ticket - WHERE id = vTicketFk; - - SELECT typeFk, tag5, value5, tag6, value6, tag7, value7, tag8, value8, t1.name, it1.value - INTO vTypeFk, vTag5, vValue5, vTag6, vValue6, vTag7, vValue7, vTag8, vValue8, vTag1, vValue1 - FROM vn.item i - LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 - LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk - WHERE i.id = vItemFk; - - CALL cache.available_refresh(vCalcFk, FALSE, vWarehouseFk, vShipped); - - SELECT i.id itemFk, - i.longName, - i.subName, - i.tag5, - i.value5, - (i.value5 <=> vValue5 COLLATE utf8_general_ci) match5, - i.tag6, - i.value6, - (i.value6 <=> vValue6 COLLATE utf8_general_ci) match6, - i.tag7, - i.value7, - (i.value7 <=> vValue7 COLLATE utf8_general_ci) match7, - i.tag8, - i.value8, - (i.value8 <=> vValue8 COLLATE utf8_general_ci) match8, - a.available, - IFNULL(ip.counter,0) counter - FROM vn.item i - JOIN cache.available a ON a.item_id = i.id - LEFT JOIN vn.itemProposal ip ON ip.mateFk = i.id AND ip.itemFk = vItemFk - LEFT JOIN vn.itemTag it1 ON it1.itemFk = i.id AND it1.priority = 1 - LEFT JOIN vn.tag t1 ON t1.id = it1.tagFk - WHERE a.calc_id = vCalcFk - AND available > 0 - AND i.typeFk = vTypeFk - AND i.id != vItemFk - ORDER BY counter DESC, - (t1.name = vTag1 COLLATE utf8_general_ci) DESC, - (it1.value = vValue1 COLLATE utf8_general_ci) DESC, - (i.tag5 = vTag5 COLLATE utf8_general_ci) DESC, - (i.value5 = vValue5 COLLATE utf8_general_ci) DESC, - (i.tag6 = vTag6 COLLATE utf8_general_ci) DESC, - (i.value6 = vValue6 COLLATE utf8_general_ci) DESC, - (i.tag7 = vTag7 COLLATE utf8_general_ci) DESC, - (i.value7 = vValue7 COLLATE utf8_general_ci) DESC, - (i.tag8 = vTag8 COLLATE utf8_general_ci) DESC, - (i.value8 = vValue8 COLLATE utf8_general_ci) DESC - LIMIT vResultsMax; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemRefreshTags` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -65535,8 +57187,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemRefreshTags`(IN vItem INT) BEGIN @@ -65561,6 +57211,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemSale_byWeek` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -65568,8 +57220,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemSale_byWeek`(vWeek INT, IN vYear INT, vItemFk INT, vWarehouseFk INT) BEGIN @@ -65620,66 +57270,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 `itemSale_byWeek__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemSale_byWeek__`(vWeek INT, IN vYear INT, vItemFk INT, vWarehouseFk INT) -BEGIN - - DECLARE vStarted DATE; - DECLARE vEnded DATETIME; - - SELECT MIN(dated), util.dayEnd(MAX(dated)) INTO vStarted, vEnded - FROM vn.`time` t - WHERE CONCAT(vYear, vWeek) = t.period; - - SELECT - t.shipped, - w.name warehouse, - s.ticketFk, - c.quality, - t.nickname AS client, - am.name AS agencyName, - wk.code AS salesPerson, - s.itemFk, - IFNULL(CONCAT(ig.longName,' ',ig.`size`,' ',ig.subName), s.concept) AS concept, - s.quantity, - s.price, - s.priceFixed, - s.discount, - tls.name stateName, - sb.buyFk, - s.id saleFk, - wk.id salesPersonFk - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - JOIN vn.address a ON a.id = t.addressFk - LEFT JOIN vn.agencyMode am ON am.id = t.agencyModeFk - JOIN vn.client c ON c.id = a.clientFk - LEFT JOIN vn.worker wk ON wk.id = c.salesPersonFk - LEFT JOIN vn.ticketLastState tls ON tls.ticketFk = t.id - LEFT JOIN vn.saleBuy sb ON sb.saleFk = s.id - LEFT JOIN vn.buy b ON b.id = sb.buyFk - LEFT JOIN vn.item ig ON ig.id = b.itemOriginalFk - WHERE s.itemFk = vItemFk - AND t.shipped BETWEEN vStarted and vEnded - AND IF(vWarehouseFk = 0, w.hasComission , t.warehouseFk= vWarehouseFk) - ORDER BY t.shipped, t.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 `itemSaveMin` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -65687,8 +57279,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemSaveMin`(min INT,vBarcode VARCHAR(22)) BEGIN @@ -65706,6 +57296,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemSearchShelving` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -65713,8 +57305,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemSearchShelving`(`vShelvingFk` VARCHAR(3)) BEGIN @@ -65728,6 +57318,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelvingDelete` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -65735,8 +57327,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingDelete`(vId INT) BEGIN @@ -65749,6 +57339,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelvingLog_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -65756,8 +57348,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingLog_get`(vShelvingFk VARCHAR(10) ) BEGIN @@ -65797,6 +57387,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelvingMakeFromDate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -65804,8 +57396,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingMakeFromDate`(IN `vShelvingFk` VARCHAR(8), IN `vBarcode` VARCHAR(22), IN `vShelve` VARCHAR(2), IN `vQuantity` INT, IN `vPackagingFk` VARCHAR(10), IN `vGrouping` INT, IN `vPacking` INT, IN `vWarehouseFk` INT, `vCreated` VARCHAR(22)) BEGIN @@ -65870,6 +57460,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelvingMatch` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -65877,8 +57469,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingMatch`(vEntryFk INT, vAllTravel BOOLEAN, vFromTimed DATETIME, vToTimed DATETIME) BEGIN @@ -65914,6 +57504,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelvingPlacementSupplyAdd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -65921,8 +57513,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingPlacementSupplyAdd`(vItemShelvingFk INT, vItemPlacementSupplyFk INT, vQuantity INT) BEGIN @@ -65947,6 +57537,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelvingProblem` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -65954,8 +57546,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingProblem`(vSectorFk INT) BEGIN @@ -65996,7 +57586,7 @@ BEGIN AND IFNULL(sub3.transit,0) < s.quantity AND s.isPicked = FALSE AND s.reserved = FALSE - AND t.shipped BETWEEN util.VN_CURDATE() AND MIDNIGHT(util.VN_CURDATE()) + AND t.shipped BETWEEN vn.VN_CURDATE() AND MIDNIGHT(vn.VN_CURDATE()) AND tst.isPreviousPreparable = TRUE AND t.warehouseFk = vWarehouseFk AND iss.sectorFk = vSectorFk @@ -66009,6 +57599,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelvingRadar` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66016,8 +57608,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingRadar`(vSectorFk INT) proc:BEGIN @@ -66063,7 +57653,7 @@ proc:BEGIN WHERE id = vSectorFk; CALL cache.visible_refresh(vCalcVisibleFk, TRUE, vWarehouseFk); - CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); + CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, vn.VN_CURDATE()); DROP TEMPORARY TABLE IF EXISTS tmp.itemShelvingRadar; @@ -66140,7 +57730,7 @@ proc:BEGIN SELECT iss.itemFk, 0 `hour`, 0 `minute`, - IFNULL(ip.`code`,'--') itemPlacementCode, + '--' itemPlacementCode, i.longName, i.size, i.subName producer, @@ -66157,7 +57747,6 @@ proc:BEGIN iss.sectorFk FROM vn.itemShelvingStock iss JOIN vn.item i on i.id = iss.itemFk - LEFT JOIN vn.itemPlacement ip ON ip.itemFk = iss.itemFk AND ip.warehouseFk = vWarehouseFk LEFT JOIN cache.last_buy lb ON lb.item_id = iss.itemFk AND lb.warehouse_id = vWarehouseFk LEFT JOIN vn.buy b ON b.id = lb.buy_id LEFT JOIN cache.available a ON a.item_id = iss.itemFk AND a.calc_id = vCalcAvailableFk @@ -66193,15 +57782,15 @@ proc:BEGIN LEFT JOIN vn.zone z ON z.id = t.zoneFk LEFT JOIN (SELECT DISTINCT saleFk FROM vn.saleTracking st - WHERE st.created > util.VN_CURDATE() + WHERE st.created > vn.VN_CURDATE() AND st.isChecked ) stPrevious ON `stPrevious`.`saleFk` = io.saleFk WHERE t.warehouseFk = vWarehouseFk AND s.isPicked = 0 AND NOT io.Reservado AND stPrevious.saleFk IS NULL - AND io.dat >= util.VN_CURDATE() - AND io.dat < util.VN_CURDATE()+1 + AND io.dat >= vn.VN_CURDATE() + AND io.dat < vn.VN_CURDATE()+1 ) sub GROUP BY itemFk, hours, minutes; @@ -66230,6 +57819,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelvingRadar_Entry` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66237,8 +57828,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingRadar_Entry`(vEntryFk INT) BEGIN @@ -66246,10 +57835,10 @@ BEGIN DECLARE vWarehouseFk INT DEFAULT 1; DECLARE vCalcVisibleFk INT; DECLARE vCalcAvailableFk INT; - DECLARE vTodayDayEnd DATETIME DEFAULT util.dayEnd(util.VN_CURDATE()); + DECLARE vTodayDayEnd DATETIME DEFAULT util.dayEnd(vn.VN_CURDATE()); CALL cache.visible_refresh(vCalcVisibleFk, FALSE, 1); - CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); + CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, vn.VN_CURDATE()); DROP TEMPORARY TABLE IF EXISTS tmp.item; CREATE TEMPORARY TABLE tmp.item @@ -66279,7 +57868,7 @@ BEGIN JOIN tmp.item2 ti ON ti.itemFk = s.itemFk JOIN vn.ticket t ON t.id = s.ticketFk LEFT JOIN vn.ticketState tst ON tst.ticketFk = t.id - WHERE t.shipped BETWEEN util.VN_CURDATE() AND vTodayDayEnd + WHERE t.shipped BETWEEN vn.VN_CURDATE() AND vTodayDayEnd AND t.warehouseFk = vWarehouseFk AND IFNULL(tst.productionOrder,0) < 5 GROUP BY s.itemFK @@ -66295,6 +57884,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelvingRadar_Entry_State_beta` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66302,8 +57893,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingRadar_Entry_State_beta`(vEntryFk INT) BEGIN @@ -66311,10 +57900,10 @@ BEGIN DECLARE vWarehouseFk INT DEFAULT 1; DECLARE vCalcVisibleFk INT; DECLARE vCalcAvailableFk INT; - DECLARE vTodayDayEnd DATETIME DEFAULT util.dayEnd(util.VN_CURDATE()); + DECLARE vTodayDayEnd DATETIME DEFAULT util.dayEnd(vn.VN_CURDATE()); CALL cache.visible_refresh(vCalcVisibleFk, FALSE, 1); - CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, util.VN_CURDATE()); + CALL cache.available_refresh(vCalcAvailableFk, FALSE, vWarehouseFk, vn.VN_CURDATE()); DROP TEMPORARY TABLE IF EXISTS tmp.item; CREATE TEMPORARY TABLE tmp.item @@ -66346,6 +57935,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelvingRadar_Urgent` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66353,8 +57944,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingRadar_Urgent`() BEGIN @@ -66399,7 +57988,7 @@ BEGIN LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk JOIN client c on c.id = t.clientFk JOIN clientType ct ON ct.id = c.clientTypeFk - WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + WHERE t.shipped BETWEEN vn.VN_CURDATE() AND util.dayend(vn.VN_CURDATE()) AND ISNULL(st.saleFk) AND ct.code IN ('normal', 'trust') GROUP BY s.itemFk @@ -66426,7 +58015,7 @@ BEGIN LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk JOIN client c on c.id = t.clientFk JOIN clientType ct ON ct.id = c.clientTypeFk - WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + WHERE t.shipped BETWEEN vn.VN_CURDATE() AND util.dayend(vn.VN_CURDATE()) AND ISNULL(st.saleFk) AND ct.code IN ('normal', 'trust') GROUP BY s.itemFk @@ -66442,57 +58031,23 @@ 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 `itemShelvingSaleAdd` */; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `itemShelvingSale_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingSaleAdd`(vItemShelvingFk INT, saleFk INT, vQuantity INT) -BEGIN - - IF saleFk <> 0 THEN - INSERT INTO vn.itemShelvingSale(itemShelvingFk, - saleFk, - quantity, - userFk) - VALUES (vItemShelvingFk, - saleFk, - vQuantity, - getUser()); - - END IF; - - UPDATE vn.itemShelving - SET visible = (visible - vQuantity) - WHERE id = vItemShelvingFk; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `itemShelvingSaleSupplyAdd` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingSaleSupplyAdd`(vItemShelvingFk INT, saleFk INT, vQuantity INT) +CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingSale_Add`(vItemShelvingFk INT, vSaleFk INT, vQuantity INT) BEGIN /** * Añade línea a itemShelvingSale y regulariza el carro * * @param vItemShelvingFk Id itemShelving - * @param saleFk Id de sale + * @param vSaleFk Id de sale * @param vQuantity cantidad a regularizar */ INSERT INTO itemShelvingSale(itemShelvingFk, @@ -66500,7 +58055,7 @@ BEGIN quantity, userFk) VALUES (vItemShelvingFk, - saleFk, + vSaleFk, vQuantity, getUser()); @@ -66508,9 +58063,9 @@ BEGIN SET visible = visible - vQuantity WHERE id = vItemShelvingFk; - UPDATE vn2008.Movimientos_mark - SET valor = 1 - WHERE Id_Movimiento = saleFk; + UPDATE vn.saleTracking + SET isChecked = 1 + WHERE saleFk = vSaleFk; END ;; DELIMITER ; @@ -66518,6 +58073,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelvingTransfer` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66525,8 +58082,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelvingTransfer`(vItemShelvingFk INT,shelvingFkD VARCHAR(22)) BEGIN @@ -66543,6 +58098,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelving_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66550,8 +58107,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_add`(IN vShelvingFk VARCHAR(8), IN vBarcode VARCHAR(22), IN vShelve VARCHAR(2), IN vQuantity INT, IN vPackagingFk VARCHAR(10), IN vGrouping INT, IN vPacking INT, IN vWarehouseFk INT) BEGIN @@ -66622,6 +58177,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelving_addByClaim` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66629,8 +58186,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_addByClaim`(vClaimFk INT, vShelvingFk VARCHAR(3)) BEGIN @@ -66648,7 +58203,7 @@ BEGIN JOIN ticket t ON t.id = c.ticketFk WHERE c.id = vClaimFk; - CALL buyUltimate (vWarehouseFk, util.VN_CURDATE()); + CALL buyUltimate (vWarehouseFk, vn.VN_CURDATE()); INSERT INTO itemShelving (itemFk, shelvingFk, packing, `grouping`, visible) SELECT s.itemFk, vShelvingFk, b.packing, b.`grouping`, cb.quantity AS visible @@ -66665,6 +58220,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelving_BuyerGet` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66672,8 +58229,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_BuyerGet`( ) BEGIN @@ -66686,6 +58241,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelving_BuyerTask` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66693,8 +58250,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_BuyerTask`(vWorkerFk INT ) BEGIN @@ -66725,6 +58280,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelving_filterBuyer` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66732,8 +58289,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_filterBuyer`(vBuyerFk INT, vWarehouseFk INT) proc:BEGIN @@ -66785,7 +58340,7 @@ proc:BEGIN 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 util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + WHERE t.shipped BETWEEN vn.VN_CURDATE() AND util.dayend(vn.VN_CURDATE()) AND ISNULL(st.saleFk) AND ct.code IN ('normal', 'trust') GROUP BY s.itemFk @@ -66810,7 +58365,7 @@ proc:BEGIN 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 util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + WHERE t.shipped BETWEEN vn.VN_CURDATE() AND util.dayend(vn.VN_CURDATE()) AND ISNULL(st.saleFk) AND ct.code IN ('normal', 'trust') GROUP BY s.itemFk @@ -66827,6 +58382,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelving_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66834,8 +58391,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_get`(IN vShelvingFk VARCHAR(8)) BEGIN @@ -66869,6 +58424,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelving_getInfo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66876,8 +58433,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_getInfo`(vItemFk VARCHAR(22)) BEGIN @@ -66906,6 +58461,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelving_getSaleDate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -66913,8 +58470,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_getSaleDate`(vShelvingFk VARCHAR(3)) BEGIN @@ -66957,11 +58512,11 @@ BEGIN FROM ( SELECT * FROM ( SELECT t2.* FROM ( - SELECT item_id itemFk, amount, util.VN_CURDATE() dated + SELECT item_id itemFk, amount, vn.VN_CURDATE() dated FROM cache.stock WHERE warehouse_id = vWarehouseFk UNION ALL - SELECT ish.itemFk, - sum(visible), util.VN_CURDATE() + SELECT ish.itemFk, - sum(visible), vn.VN_CURDATE() FROM vn.itemShelving ish JOIN shelving sh ON sh.code = ish.shelvingFk JOIN parking p ON sh.parkingFk = p.id @@ -66971,21 +58526,21 @@ BEGIN UNION ALL SELECT item_id, sum(iei.amount), dat FROM vn2008.item_entry_in iei - WHERE dat >= util.VN_CURDATE() + WHERE dat >= vn.VN_CURDATE() AND warehouse_id = vWarehouseFk AND isVirtualStock = FALSE GROUP BY item_id, dat UNION ALL SELECT item_id, sum(ieo.amount), dat FROM vn2008.item_entry_out ieo - WHERE dat >= util.VN_CURDATE() + WHERE dat >= vn.VN_CURDATE() AND warehouse_id = vWarehouseFk GROUP BY item_id, dat UNION ALL SELECT i.itemFk, sum(io.amount), dat FROM vn2008.item_out io JOIN tmp.item i ON i.itemFk = io.item_id - WHERE io.dat >= util.VN_CURDATE() + WHERE io.dat >= vn.VN_CURDATE() AND io.warehouse_id = vWarehouseFk GROUP BY io.item_id, io.dat ) t2 @@ -67009,6 +58564,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelving_inventory` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -67016,56 +58573,91 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_inventory`(vParkingFromFk INT, vParkingToFk INT) -BEGIN - - /** - * Devuelve un listado de ubicaciones a revisar - * - * @param vParkingFromFk Parking de partida, identificador de vn.parking - * @param vParkingToFk Parking de llegada, identificador de vn.parking - */ - - DECLARE vSectorFk INT; - DECLARE vPickingOrderFrom INT; - DECLARE vPickingOrderTo INT; - - SELECT p.sectorFk, p.pickingOrder INTO vSectorFk, vPickingOrderFrom - FROM vn.parking p - WHERE p.id = vParkingFromFk; - - SELECT p.pickingOrder INTO vPickingOrderTo - FROM vn.parking p - WHERE p.id = vParkingToFk; - - CALL vn.visible_getMisfit(vSectorFk); - - SELECT p.code parking , - ish.shelvingFk , - ish.itemFk, - i.longName, - ish.visible , - ish.visible / ish.packing packs, - ish.packing, - sm.visible - sm.parked faltan - FROM vn.itemShelving ish - JOIN vn.item i ON i.id = ish.itemFk - JOIN tmp.stockMisfit sm ON sm.itemFk = ish.itemFk - JOIN vn.shelving sh ON sh.code = ish.shelvingFk - JOIN vn.parking p ON p.id = sh.parkingFk - WHERE p.pickingOrder BETWEEN vPickingOrderFrom AND vPickingOrderTo - AND p.sectorFk = vSectorFk - ORDER BY p.pickingOrder ; - +BEGIN + + /** + * Devuelve un listado de ubicaciones a revisar + * + * @param vParkingFromFk Parking de partida, identificador de vn.parking + * @param vParkingToFk Parking de llegada, identificador de vn.parking + */ + + DECLARE vSectorFk INT; + DECLARE vPickingOrderFrom INT; + DECLARE vPickingOrderTo INT; + + SELECT p.sectorFk, p.pickingOrder INTO vSectorFk, vPickingOrderFrom + FROM vn.parking p + WHERE p.id = vParkingFromFk; + + SELECT p.pickingOrder INTO vPickingOrderTo + FROM vn.parking p + WHERE p.id = vParkingToFk; + + CALL vn.visible_getMisfit(vSectorFk); + + SELECT p.code parking , + ish.shelvingFk , + ish.itemFk, + i.longName, + ish.visible , + ish.visible / ish.packing packs, + ish.packing, + sm.visible - sm.parked faltan + FROM vn.itemShelving ish + JOIN vn.item i ON i.id = ish.itemFk + JOIN tmp.stockMisfit sm ON sm.itemFk = ish.itemFk + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + WHERE p.pickingOrder BETWEEN vPickingOrderFrom AND vPickingOrderTo + AND p.sectorFk = vSectorFk + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `itemShelving_return` */; +/*!50003 SET @saved_cs_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_return`(vShelving VARCHAR(10)) +BEGIN +/** + * Devuelve un listado de posibles ubicaciones a ubicar los item de la matricula + * del carro que se le ha pasado. + * + * @param vShelving matricula del carro + */ + SELECT is2.id,is2.shelvingFk , p.code, is2.itemFk , i.longName , is2.visible + FROM vn.itemShelving is2 + JOIN vn.item i ON i.id = is2.itemFk + JOIN vn.shelving sh ON sh.code = is2.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk + LEFT JOIN vn.worker w ON w.sectorFk = s.id AND w.id = account.myUser_getId() + JOIN vn.warehouse wh ON wh.id = s.warehouseFk + JOIN vn.itemShelving is3 ON is3.itemFk = is2.itemFk AND is3.shelvingFk = vShelving COLLATE utf8_unicode_ci + GROUP BY is2.id + ORDER BY p.pickingOrder 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelving_StarsUpdate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -67073,8 +58665,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_StarsUpdate`(vId INT, vStars INT) BEGIN @@ -67089,6 +58679,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemShelving_update` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -67096,8 +58688,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemShelving_update`(vVisible INT, vPacking INT, vShelf INT ,vGrouping INT ) BEGIN @@ -67121,6 +58711,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemStock` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -67128,8 +58720,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemStock`(vWarehouseFk SMALLINT, vDated DATETIME, vItemFk INT) BEGIN @@ -67154,21 +58744,21 @@ BEGIN SELECT itemFk, SUM(quantity) stock, SUM(quantity) visible, SUM(quantity) available FROM ( SELECT itemFk, quantity FROM itemTicketOut - WHERE shipped >= util.VN_CURDATE() AND shipped < vDated + WHERE shipped >= vn.VN_CURDATE() AND shipped < vDated AND warehouseFk = vWarehouseFk AND (vItemFk IS NULL OR itemFk = vItemFk) UNION ALL SELECT itemFk, quantity FROM itemEntryIn i LEFT JOIN edi.warehouseFloramondo wf ON wf.entryFk = i.entryFk - WHERE i.landed >= util.VN_CURDATE() AND i.landed < vDated + WHERE i.landed >= vn.VN_CURDATE() AND i.landed < vDated AND i.warehouseInFk = vWarehouseFk AND (vItemFk IS NULL OR i.itemFk = vItemFk) AND (ISNULL(wf.entryFk) OR vIsLogifloraDay) UNION ALL SELECT itemFk, quantity FROM itemEntryOut - WHERE shipped >= util.VN_CURDATE() AND shipped < vDated + WHERE shipped >= vn.VN_CURDATE() AND shipped < vDated AND warehouseOutFk = vWarehouseFk AND (vItemFk IS NULL OR itemFk = vItemFk) ) t @@ -67190,90 +58780,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 `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`@`localhost` PROCEDURE `itemStockUpdate__`( - vItemFk INT, - vWarehouseFk INT, - vNewVisible INT, - vIsTrash BOOLEAN) -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) = util.VN_CURDATE() - AND a.isDefaultAddress - LIMIT 1; - - IF vTicketFk IS NULL THEN - - CALL ticket_add( - vClientFk, - util.VN_CURDATE(), - vWarehouseFk, - vCompanyVnlFk, - NULL, - NULL, - NULL, - util.VN_CURDATE(), - account.userGetId(), - FALSE, - vTicketFk); - - END IF; - - INSERT INTO sale(ticketFk, itemFk, concept, quantity, price, discount) - SELECT vTicketFk, vItemFk, CONCAT(longName,' ', getWorkerCode(), ' ',LEFT(CAST(util.VN_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 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemTagMake` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -67281,8 +58789,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTagMake`(vItemFk INT) BEGIN @@ -67343,6 +58849,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemTagReorder` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -67350,8 +58858,6 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTagReorder`(itemTypeFk INT) BEGIN @@ -67383,6 +58889,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemTagReorderByName` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -67390,8 +58898,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTagReorderByName`(vName VARCHAR(255)) BEGIN @@ -67423,142 +58929,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 `itemTagReorderByName__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTagReorderByName__`(vName VARCHAR(255)) -BEGIN - -DECLARE vDone BOOL DEFAULT FALSE; - DECLARE vItem INT; - - DECLARE cur CURSOR FOR - SELECT id - FROM upda; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - SET @isTriggerDisabled = TRUE; - - DROP TEMPORARY TABLE IF EXISTS upda; - CREATE TEMPORARY TABLE upda - SELECT DISTINCT i.id - FROM vn.item i - WHERE i.name LIKE CONCAT(vName,'%'); - - UPDATE itemTag it - JOIN item i ON i.id = it.itemFk - JOIN itemTypeTag itt ON itt.itemTypeFk = i.typeFk AND itt.tagFk = it.tagFk - SET it.priority = itt.priority - WHERE itt.itemTypeFk = itemTypeFk; - - OPEN cur; - proc: LOOP - SET vDone = FALSE; - FETCH cur INTO vItem; - IF vDone THEN - LEAVE proc; - END IF; - CALL vn.itemRefreshTags(vItem); - END LOOP; - CLOSE cur; - SET @isTriggerDisabled = FALSE; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `itemTagReorder__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTagReorder__`(itemTypeFk INT) -BEGIN - -DECLARE vDone BOOL DEFAULT FALSE; - DECLARE vItem INT; - - DECLARE cur CURSOR FOR - SELECT id - FROM upda; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - SET @isTriggerDisabled = TRUE; - - DROP TEMPORARY TABLE IF EXISTS upda; - create temporary table upda - SELECT DISTINCT i.id - FROM vn.item i - WHERE i.typeFk = itemTypeFk; - - UPDATE itemTag it - JOIN item i ON i.id = it.itemFk - JOIN itemTypeTag itt ON itt.itemTypeFk = i.typeFk AND itt.tagFk = it.tagFk - SET it.priority = itt.priority - WHERE itt.itemTypeFk = itemTypeFk; - - OPEN cur; - proc: LOOP - SET vDone = FALSE; - FETCH cur INTO vItem; - IF vDone THEN - LEAVE proc; - END IF; - CALL vn.itemRefreshTags(vItem); - END LOOP; - CLOSE cur; - SET @isTriggerDisabled = FALSE; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `itemTagReplace__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTagReplace__`(fromItemFk INT, toItemFk INT) -BEGIN - -/* - * deprecated use itemTag_replace - */ - DELETE FROM itemTag - WHERE itemFk = toItemFk; - - INSERT INTO itemTag(itemFk, tagFk, value, priority) - SELECT toItemFk, tagFk, value, priority - FROM itemTag - WHERE itemFk = fromItemFk; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemTag_replace` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -67566,47 +58938,47 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTag_replace`(vItemFromFk INT, vItemToFk INT, vPicture VARCHAR(100)) -BEGIN - - /* Reemplaza los tags de un artículo por los de otro, así como su imagen - * - * @param vItemFromFk id de vn.item con el artículo del que se toman los tags - * @param vItemToFk id de vn.item con el artículo del que se toman los tags - * @param vPicture imagen del artículo. Opcional. Si no se especifica, hereada la del vItemFromFk - */ - - DELETE FROM vn.itemTag - WHERE itemFk = vItemToFk; - - INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) - SELECT vItemToFk, tagFk, value, priority - FROM vn.itemTag - WHERE itemFk = vItemFromFk; - - IF ISNULL(vPicture) THEN - - SELECT image INTO vPicture - FROM vn.item - WHERE id = vItemFromFk; - - END IF; - - UPDATE vn.item i - SET i.image = vPicture - WHERE i.id = vItemToFk; - - CALL vn.itemRefreshTags(vItemToFk); - +BEGIN + + /* Reemplaza los tags de un artículo por los de otro, así como su imagen + * + * @param vItemFromFk id de vn.item con el artículo del que se toman los tags + * @param vItemToFk id de vn.item con el artículo del que se toman los tags + * @param vPicture imagen del artículo. Opcional. Si no se especifica, hereada la del vItemFromFk + */ + + DELETE FROM vn.itemTag + WHERE itemFk = vItemToFk; + + INSERT INTO vn.itemTag(itemFk, tagFk, value, priority) + SELECT vItemToFk, tagFk, value, priority + FROM vn.itemTag + WHERE itemFk = vItemFromFk; + + IF ISNULL(vPicture) THEN + + SELECT image INTO vPicture + FROM vn.item + WHERE id = vItemFromFk; + + END IF; + + UPDATE vn.item i + SET i.image = vPicture + WHERE i.id = vItemToFk; + + CALL vn.itemRefreshTags(vItemToFk); + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemTopSeller` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -67614,8 +58986,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTopSeller`() BEGIN @@ -67636,7 +59006,7 @@ BEGIN SELECT s.itemFk, SUM(s.quantity) AS total, v.tipo_id typeFk FROM vn.sale s INNER JOIN bs.ventas v ON v.Id_Movimiento = s.id - WHERE v.fecha BETWEEN TIMESTAMPADD(DAY, - 7, util.VN_CURDATE()) AND util.VN_CURDATE() + WHERE v.fecha BETWEEN TIMESTAMPADD(DAY, - 7, vn.VN_CURDATE()) AND vn.VN_CURDATE() GROUP BY s.itemFk; DROP TABLE IF EXISTS tmp.topSeller; @@ -67683,6 +59053,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemTrash` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -67690,71 +59062,71 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTrash`( - vItemFk INT, - vWarehouseFk INT, - vQuantity INT, +CREATE DEFINER=`root`@`localhost` PROCEDURE `itemTrash`( + vItemFk INT, + vWarehouseFk INT, + vQuantity INT, vIsTrash BOOLEAN) -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) = util.VN_CURDATE() - AND a.isDefaultAddress - LIMIT 1; - - CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk); - - IF vTicketFk IS NULL THEN - - CALL ticket_add( - vClientFk, - util.VN_CURDATE(), - vWarehouseFk, - vCompanyVnlFk, - NULL, - NULL, - NULL, - util.VN_CURDATE(), - account.userGetId(), - FALSE, - vTicketFk); - END IF; - - INSERT INTO sale(ticketFk, itemFk, concept, quantity) - SELECT vTicketFk, - vItemFk, - CONCAT(longName,' ',getWorkerCode(), ' ', LEFT(CAST(util.VN_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; - +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) = vn.VN_CURDATE() + AND a.isDefaultAddress + LIMIT 1; + + CALL cache.visible_refresh(vCalc, TRUE, vWarehouseFk); + + IF vTicketFk IS NULL THEN + + CALL ticket_add( + vClientFk, + vn.VN_CURDATE(), + vWarehouseFk, + vCompanyVnlFk, + NULL, + NULL, + NULL, + vn.VN_CURDATE(), + account.myUser_getId(), + FALSE, + vTicketFk); + END IF; + + INSERT INTO sale(ticketFk, itemFk, concept, quantity) + SELECT vTicketFk, + vItemFk, + CONCAT(longName,' ',getWorkerCode(), ' ', LEFT(CAST(vn.VN_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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `itemUpdateTag` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -67762,8 +59134,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `itemUpdateTag`(IN vItem BIGINT) BEGIN @@ -67809,28 +59179,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_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 = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `item_clean`(vItemFrom INT, vItemTo INT) +CREATE DEFINER=`root`@`localhost` PROCEDURE `item_clean`(OUT vHasError BOOL) BEGIN - -/* - * Elimina todos los items repetidos y los sustituye por el que tiene menor id +/** + * Elimina todos los items repetidos y los sustituye + * por el que tiene menor id + * + * @return Si da error devuelve a true vHasError */ - - START TRANSACTION; + DECLARE CONTINUE HANDLER FOR SQLSTATE '40001' + BEGIN + SET vHasError = TRUE; + END; SET @isModeInventory:= TRUE; -- Deletes + START TRANSACTION; UPDATE IGNORE vn.itemCost ic JOIN tmp.itemsToReplace itr ON ic.itemFk = itr.idOld @@ -67875,12 +59250,11 @@ BEGIN DELETE itc.* FROM vn.itemTaxCountry itc JOIN tmp.itemsToReplace itr ON itc.itemFk = itr.idOld; - - DELETE ip.* - FROM vn.itemPlacement ip - JOIN tmp.itemsToReplace itr ON ip.itemFk = itr.idOld; + + COMMIT; -- Updates + START TRANSACTION; UPDATE vn.buy b JOIN tmp.itemsToReplace itr ON b.itemFk = itr.idOld @@ -67929,16 +59303,20 @@ BEGIN UPDATE vn.itemPlacementSupply ips JOIN tmp.itemsToReplace itr ON ips.itemFk = itr.idOld SET ips.itemFk = itr.idNew; + + COMMIT; -- Eliminamos los items repetidos + START TRANSACTION; DELETE i.* FROM vn.item i JOIN tmp.itemsToReplace itr ON i.id = itr.idOld; + + COMMIT; SET @isModeInventory:= FALSE; - - COMMIT; + SET vHasError = FALSE; END ;; DELIMITER ; @@ -67946,73 +59324,87 @@ 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_cleanLauncher` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_cleanLauncher`() BEGIN - +/** + * Inicia el procedimiento vn.item_clean + */ DECLARE vItemTo INT DEFAULT 0; - DECLARE vStep INT DEFAULT 500; + DECLARE vStep INT DEFAULT 0; DECLARE vCounter INT DEFAULT 0; DECLARE vItemFrom INT; DECLARE vItemEnd INT; + DECLARE vQuantity INT; + DECLARE vHasError BOOL; SELECT itemFrom INTO vItemFrom - FROM tmp.itemCleanCount + FROM vn.itemCleanCount ORDER BY created DESC LIMIT 1; + + IF ISNULL(vItemFrom) THEN + SELECT MIN(id) INTO vItemFrom + FROM vn.item i + WHERE isFloramondo; + END IF; + + SELECT quantity, step + INTO vQuantity, vStep + FROM vn.itemCleanConfig; - SET vItemEnd = vItemFrom + 100000; + SET vItemEnd = vItemFrom + vQuantity; DROP TEMPORARY TABLE IF EXISTS tmp.itemsToReplaceSource; CREATE TEMPORARY TABLE tmp.itemsToReplaceSource SELECT i.id idOld, i2.id idNew FROM vn.item i - JOIN ( SELECT i.id, - i.name, - i.subname, - i.value5, - i.value6, - i.value7, - i.value8, - i.value9, - i.value10, - i.NumberOfItemsPerCask, - i.EmbalageCode, - i.quality - FROM vn.item i - LEFT JOIN (SELECT i.id, - sr.NumberOfUnits, - MAX(di.LatestOrderDateTime) lodt - FROM vn.item i - JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk - JOIN edi.deliveryInformation di ON di.supplyResponseID = i.supplyResponseFk - GROUP BY i.id) sub ON sub.id = i.id - WHERE i.id > 170000 - AND (ISNULL(i.supplyResponseFk) - OR sub.NumberOfUnits=0 - OR sub.lodt < util.VN_NOW()) - GROUP BY i.name, - subname, - value5, - value6, - value7, - value8, - value9, - value10, - NumberOfItemsPerCask, - EmbalageCode, - quality - ORDER BY i.id) i2 ON i2.name <=> i.name + JOIN (SELECT i.id, + i.name, + i.subname, + i.value5, + i.value6, + i.value7, + i.value8, + i.value9, + i.value10, + i.NumberOfItemsPerCask, + i.EmbalageCode, + i.quality + FROM vn.item i + LEFT JOIN (SELECT i.id, + sr.NumberOfUnits, + MAX(di.LatestOrderDateTime) lodt + FROM vn.item i + JOIN edi.supplyResponse sr ON sr.ID = i.supplyResponseFk + JOIN edi.deliveryInformation di ON di.supplyResponseID = i.supplyResponseFk + GROUP BY i.id) sub ON sub.id = i.id + WHERE isFloramondo + AND (ISNULL(i.supplyResponseFk) + OR sub.NumberOfUnits = 0 + OR sub.lodt < vn.VN_NOW()) + GROUP BY i.name, + subname, + value5, + value6, + value7, + value8, + value9, + value10, + NumberOfItemsPerCask, + EmbalageCode, + quality + ORDER BY i.id) i2 ON i2.name <=> i.name AND i2.subname <=> i.subname AND i2.value5 <=> i.value5 AND i2.value6 <=> i.value6 @@ -68023,32 +59415,32 @@ BEGIN AND i2.NumberOfItemsPerCask <=> i.NumberOfItemsPerCask AND i2.EmbalageCode <=> i.EmbalageCode AND i2.quality <=> i.quality - WHERE i.id > 170000 - AND i.id <> i2.id + WHERE isFloramondo + AND i.id <> i2.id ORDER BY i2.id; - WHILE vItemTo < vItemEnd AND NOT (SELECT isStop FROM tmp.stoper) DO + WHILE vItemTo < vItemEnd AND NOT (SELECT isStop FROM vn.itemCleanConfig) DO SET vItemTo = LEAST(vItemEnd, vItemFrom + vStep); SELECT COUNT(*) INTO vCounter FROM tmp.itemsToReplaceSource - WHERE idNew BETWEEN vItemFrom - AND vItemTo; + WHERE idNew BETWEEN vItemFrom AND vItemTo; DROP TEMPORARY TABLE IF EXISTS tmp.itemsToReplace; CREATE TEMPORARY TABLE tmp.itemsToReplace SELECT * FROM tmp.itemsToReplaceSource - WHERE idNew BETWEEN vItemFrom - AND vItemTo; + WHERE idNew BETWEEN vItemFrom AND vItemTo; - CALL vn.item_clean(vItemFrom, vItemTo); - - SET vItemFrom = vItemTo; + CALL vn.item_clean(vHasError); + + IF NOT vHasError THEN + SET vItemFrom = vItemTo; + END IF; - INSERT INTO tmp.itemCleanCount(itemFrom, itemDeleted) - VALUES (vItemFrom, vCounter); + INSERT INTO vn.itemCleanCount(itemFrom, itemDeleted) + VALUES (vItemFrom, vCounter); END WHILE; @@ -68061,6 +59453,53 @@ 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `item_deactivateUnused` */; +/*!50003 SET @saved_cs_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `item_deactivateUnused`() +BEGIN +/** + * Cambia a false el campo isActive de la tabla vn.item + * para todos aquellos items que no se han comprado + * en los últimos meses configurados en + * vn.itemConfig.monthToDeactivate + */ + DECLARE vMonthToDeactivate INT; + + SELECT monthToDeactivate INTO vMonthToDeactivate + FROM vn.itemConfig; + + DROP TEMPORARY TABLE IF EXISTS tmp.buyMaxCreated; + CREATE TEMPORARY TABLE tmp.buyMaxCreated + ENGINE = MEMORY + SELECT b.itemFk, + MAX(b.created) created + FROM vn.buy b + JOIN vn.item i ON i.id = b.itemFk + WHERE i.isActive + GROUP BY itemFk; + + UPDATE vn.item i + JOIN tmp.buyMaxCreated bmc ON bmc.itemFk = i.id + SET i.isActive = FALSE + WHERE bmc.created < vn.VN_CURDATE() - INTERVAL vMonthToDeactivate MONTH; + + DROP TEMPORARY TABLE IF EXISTS tmp.buyMaxCreated; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_getBalance` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -68068,13 +59507,11 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getBalance`(IN vItemId int, IN vWarehouse int) BEGIN DECLARE vDateInventory DATETIME; - DECLARE vCurdate DATE DEFAULT util.VN_CURDATE(); + DECLARE vCurdate DATE DEFAULT vn.VN_CURDATE(); DECLARE vDayEnd DATETIME DEFAULT util.dayEnd(vCurdate); SELECT inventoried INTO vDateInventory FROM config; @@ -68092,8 +59529,8 @@ BEGIN `in` AS invalue, `out`, @a := @a + IFNULL(`in`,0) - IFNULL(`out`,0) as balance, - @currentLineFk := IF (@shipped < util.VN_CURDATE() - OR (@shipped = util.VN_CURDATE() AND (isPicked OR alertLevel >= 2)), + @currentLineFk := IF (@shipped < vn.VN_CURDATE() + OR (@shipped = vn.VN_CURDATE() AND (isPicked OR alertLevel >= 2)), lineFk,@currentLineFk) lastPreparedLineFk, isTicket, lineFk, @@ -68122,8 +59559,8 @@ BEGIN JOIN supplier s ON s.id = e.supplierFk JOIN alertLevel al ON al.id = CASE - WHEN tr.landed < util.VN_CURDATE() THEN 3 - WHEN tr.landed = util.VN_CURDATE() AND tr.isReceived = TRUE THEN 3 + WHEN tr.landed < vn.VN_CURDATE() THEN 3 + WHEN tr.landed = vn.VN_CURDATE() AND tr.isReceived = TRUE THEN 3 ELSE 0 END JOIN state st ON st.code = al.code @@ -68156,8 +59593,8 @@ BEGIN JOIN supplier s ON s.id = e.supplierFk JOIN alertLevel al ON al.id = CASE - WHEN tr.shipped < util.VN_CURDATE() THEN 3 - WHEN tr.shipped = util.VN_CURDATE() AND tr.isReceived = TRUE THEN 3 + WHEN tr.shipped < vn.VN_CURDATE() THEN 3 + WHEN tr.shipped = vn.VN_CURDATE() AND tr.isReceived = TRUE THEN 3 ELSE 0 END JOIN state st ON st.code = al.code @@ -68193,8 +59630,8 @@ BEGIN JOIN clientType ct ON ct.id = c.clientTypeFk JOIN alertLevel al ON al.id = CASE - WHEN t.shipped < util.VN_CURDATE() THEN 3 - WHEN t.shipped > util.dayEnd(util.VN_CURDATE()) THEN 0 + WHEN t.shipped < vn.VN_CURDATE() THEN 3 + WHEN t.shipped > util.dayEnd(vn.VN_CURDATE()) THEN 0 ELSE IFNULL(ts.alertLevel, 0) END LEFT JOIN state stPrep ON stPrep.`code` = 'PREPARED' @@ -68212,6 +59649,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_getInfo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -68219,81 +59658,83 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getInfo`(IN `vBarcode` VARCHAR(22), IN `vWarehouseFk` INT) -BEGIN - - /* - * Devuelve información relativa al item correspondiente del vBarcode pasado - * - * @param vBarcode código relativo al ítem - * @param vWarehouseFk código del almacén - */ - - DECLARE vCacheVisibleFk INT; - DECLARE vCacheAvailableFk INT; - DECLARE vVisibleItemShelving INT; - DECLARE vItemFk INT; - - SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; - - CALL cache.visible_refresh(vCacheVisibleFk, FALSE,vWarehouseFk); - CALL cache.available_refresh(vCacheAvailableFk, FALSE,vWarehouseFk, util.VN_CURDATE()); - - SELECT SUM(visible) INTO vVisibleItemShelving - FROM vn.itemShelvingStock - WHERE itemFk = vItemFk AND warehouseFk = vWarehouseFk; - - CALL vn.buyUltimate(vWarehouseFk, util.VN_CURDATE()); - - SELECT i.id, - i.longName, - i.tag5, - i.value5, - i.tag6, - i.value6, - i.tag7, - i.value7, - i.image, - i.size, - i.stems, - i.category, - i.minimum as min, - p.name as producer, - o.code as origin, - v.visible - IFNULL(vVisibleItemShelving,0) as unlocated, - a.available, - vVisibleItemShelving, - v.visible, - c.`grouping`, - c.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, - i.itemPackingTypeFk, - i.comment as reference - FROM vn.item i - LEFT JOIN vn.producer p ON p.id = i.producerFk - LEFT JOIN vn.origin o ON o.id = i.originFk - LEFT JOIN cache.visible v ON v.calc_id = vCacheVisibleFk AND v.item_id = i.id - LEFT JOIN cache.available a ON a.calc_id = vCacheAvailableFk AND a.item_id = i.id - LEFT JOIN ( - SELECT b.itemFk, b2.`grouping`, b2.packing - FROM tmp.buyUltimate b - JOIN vn.buy b2 ON b2.id = b.buyFk - WHERE b.warehouseFk = vWarehouseFk - ) c ON i.id = c.itemFk - WHERE i.id = vItemFk; - - DROP TEMPORARY TABLE tmp.buyUltimate; - +BEGIN + + /* + * Devuelve información relativa al item correspondiente del vBarcode pasado + * + * @param vBarcode código relativo al ítem + * @param vWarehouseFk código del almacén + */ + + DECLARE vCacheVisibleFk INT; + DECLARE vCacheAvailableFk INT; + DECLARE vVisibleItemShelving INT; + DECLARE vItemFk INT; + + SELECT vn.barcodeToItem(vBarcode) INTO vItemFk; + + CALL cache.visible_refresh(vCacheVisibleFk, FALSE,vWarehouseFk); + CALL cache.available_refresh(vCacheAvailableFk, FALSE,vWarehouseFk, vn.VN_CURDATE()); + + SELECT SUM(visible) INTO vVisibleItemShelving + FROM vn.itemShelvingStock + WHERE itemFk = vItemFk AND warehouseFk = vWarehouseFk; + + CALL vn.buyUltimate(vWarehouseFk, vn.VN_CURDATE()); + + SELECT i.id, + i.longName, + i.tag5, + i.value5, + i.tag6, + i.value6, + i.tag7, + i.value7, + i.image, + i.size, + i.stems, + i.category, + i.minimum as min, + p.name as producer, + o.code as origin, + v.visible - IFNULL(vVisibleItemShelving,0) as unlocated, + a.available, + vVisibleItemShelving, + v.visible, + c.`grouping`, + c.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, + i.itemPackingTypeFk, + i.comment reference, + u.name buyer + FROM vn.item i + LEFT JOIN vn.producer p ON p.id = i.producerFk + LEFT JOIN vn.origin o ON o.id = i.originFk + LEFT JOIN cache.visible v ON v.calc_id = vCacheVisibleFk AND v.item_id = i.id + LEFT JOIN cache.available a ON a.calc_id = vCacheAvailableFk AND a.item_id = i.id + LEFT JOIN ( + SELECT b.itemFk, b2.`grouping`, b2.packing + FROM tmp.buyUltimate b + JOIN vn.buy b2 ON b2.id = b.buyFk + WHERE b.warehouseFk = vWarehouseFk + ) c ON i.id = c.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN account.user u ON u.id = it.workerFk + WHERE i.id = vItemFk; + DROP TEMPORARY TABLE tmp.buyUltimate; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_getLack` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -68301,8 +59742,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getLack`(IN vForce BOOLEAN, IN vDays INT) BEGIN @@ -68314,7 +59753,7 @@ BEGIN **/ CALL `cache`.stock_refresh(vForce); - CALL item_getMinacum(NULL, util.VN_CURDATE(), vDays, NULL); + CALL item_getMinacum(NULL, vn.VN_CURDATE(), vDays, NULL); CALL item_getMinETD(); SELECT i.id itemFk, @@ -68345,7 +59784,6 @@ BEGIN JOIN itemCategory ic ON ic.id = it.categoryFk LEFT JOIN tmp.itemMinETD im ON im.itemFk = i.id WHERE w.isForTicket - AND it.making IS NULL AND ic.display <> 0 AND it.code != 'GEN' GROUP BY i.id, w.id @@ -68359,6 +59797,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_getMinacum` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -68366,8 +59806,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getMinacum`(IN vWarehouseFk TINYINT, IN vDatedFrom DATETIME, IN vRange INT, IN vItemFk INT) BEGIN @@ -68447,6 +59885,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_getMinETD` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -68454,8 +59894,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getMinETD`() BEGIN @@ -68476,7 +59914,7 @@ BEGIN FROM ticket t JOIN sale s ON s.ticketFk = t.id LEFT JOIN `zone` z ON z.id = t.zoneFk - WHERE t.shipped BETWEEN util.VN_CURDATE() AND vMidnight + WHERE t.shipped BETWEEN vn.VN_CURDATE() AND vMidnight GROUP BY s.itemFk; END ;; DELIMITER ; @@ -68484,6 +59922,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_getSimilar` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -68491,8 +59931,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getSimilar`(vItemFk INT, vWarehouseFk INT, vDate DATE, vIsShowedByType BOOL) BEGIN @@ -68581,6 +60019,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_GetVisible` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -68588,12 +60028,10 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_GetVisible`(vWarehouse SMALLINT, vItem INT) BEGIN - DECLARE vTomorrow DATETIME DEFAULT TIMESTAMPADD(DAY, 1, util.VN_CURDATE()); + DECLARE vTomorrow DATETIME DEFAULT TIMESTAMPADD(DAY, 1, vn.VN_CURDATE()); INSERT INTO vn2008.tmp_item (item_id, visible) SELECT item_id, SUM(amount) amount @@ -68605,19 +60043,18 @@ BEGIN LEFT JOIN (SELECT DISTINCT saleFk FROM saleTracking st JOIN state s ON s.id = st.stateFk - WHERE st.created > util.VN_CURDATE() + WHERE st.created > vn.VN_CURDATE() AND (s.isPicked OR st.isChecked) ) stPrevious ON `stPrevious`.`saleFk` = i.saleFk WHERE i.warehouseFk = vWarehouse AND (vItem IS NULL OR i.itemFk = vItem) AND (s.isPicked OR i.reserved OR stPrevious.saleFk ) - AND i.shipped >= util.VN_CURDATE() AND i.shipped < vTomorrow + AND i.shipped >= vn.VN_CURDATE() AND i.shipped < vTomorrow UNION ALL SELECT iei.itemFk, quantity FROM itemEntryIn iei - LEFT JOIN itemPlacement ip ON ip.itemFk = iei.itemFk AND ip.warehouseFk = vWarehouse - WHERE (iei.isReceived != FALSE /*OR ip.modificationDate > util.VN_CURDATE()*/ ) - AND iei.landed >= util.VN_CURDATE() AND iei.landed < vTomorrow + WHERE (iei.isReceived != FALSE /*OR ip.modificationDate > vn.VN_CURDATE()*/) + AND iei.landed >= vn.VN_CURDATE() AND iei.landed < vTomorrow AND iei.warehouseInFk = vWarehouse AND (vItem IS NULL OR iei.itemFk = vItem) AND iei.isVirtualStock is FALSE @@ -68625,7 +60062,7 @@ BEGIN SELECT itemFk, quantity FROM itemEntryOut WHERE isDelivered != FALSE - AND shipped >= util.VN_CURDATE() AND shipped < vTomorrow + AND shipped >= vn.VN_CURDATE() AND shipped < vTomorrow AND warehouseOutFk = vWarehouse AND (vItem IS NULL OR itemFk = vItem) ) t @@ -68638,84 +60075,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 `item_getVisibleAvailable__` */; -/*!50003 SET @saved_cs_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`@`localhost` PROCEDURE `item_getVisibleAvailable__`( - vItem INT, - vDate DATE, - vWarehouse TINYINT, - vRefresh BOOL) -BEGIN - DECLARE vVisibleCalc INT; - DECLARE vAvailableCalc INT; - DECLARE vVisibleAltillo INT; - - CALL cache.available_refresh(vAvailableCalc, FALSE /*vRefresh*/ , vWarehouse, vDate); - CALL cache.visible_refresh(vVisibleCalc, FALSE,vWarehouse); - - SELECT SUM(visible) INTO vVisibleAltillo - FROM vn.itemShelvingStock - WHERE itemFk = vItem - AND warehouseFk = vWarehouse; - - IF vRefresh THEN - - DROP TEMPORARY TABLE IF EXISTS vn2008.tmp_item; - CREATE TEMPORARY TABLE vn2008.tmp_item - (PRIMARY KEY (item_id)) - ENGINE = MEMORY - SELECT vItem item_id, 0 stock, 0 visible; - - SELECT i.id, i.longName, i.box, i.typeFk, - i.tag5,i.value5,i.tag6,i.value6,i.tag7,i.value7,i.tag8,i.value8, - ip.code, ip.reserve, - vi.visible - IFNULL(vVisibleAltillo,0) AS visible, - av.available - FROM vn.item i - LEFT JOIN vn.itemPlacement ip - ON i.id = ip.itemFk AND ip.warehouseFk = vWarehouse - LEFT JOIN vn2008.tmp_item v - ON v.item_id = i.id - LEFT JOIN cache.available av - ON av.calc_id = vAvailableCalc AND av.item_id = i.id - LEFT JOIN cache.visible vi - ON vi.calc_id = vVisibleCalc AND vi.item_id = i.id - LEFT JOIN cache.stock st - ON st.warehouse_id = vWarehouse AND st.item_id = i.id - WHERE (vItem IS NULL OR i.id = vItem); - - ELSE - - SELECT i.id, i.longName, i.box, i.typeFk, - i.tag5,i.value5,i.tag6,i.value6,i.tag7,i.value7,i.tag8,i.value8, - ip.code, ip.reserve, - v.visible - IFNULL(vVisibleAltillo,0) AS visible, - av.available - FROM vn.item i - LEFT JOIN vn.itemPlacement ip - ON i.id = ip.itemFk AND ip.warehouseFk = vWarehouse - LEFT JOIN cache.visible v - ON v.item_id = i.id AND v.calc_id = vVisibleCalc - LEFT JOIN cache.available av - ON av.item_id = i.id AND av.calc_id = vAvailableCalc - WHERE (vItem IS NULL OR i.id = vItem); - - 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 sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_refreshTags` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -68723,8 +60084,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_refreshTags`() BEGIN @@ -68869,6 +60228,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_refreshTags_beta` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -68876,8 +60237,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_refreshTags_beta`() BEGIN @@ -69012,135 +60371,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 `item_refreshTags__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `item_refreshTags__`() -BEGIN -/** - * Actualiza la tabla item, los campos "cache" de tags - * Para actualizar mas de un registro, la tabla NO tiene que ser en memoria - * Error Code: 1137. No puedo reabrir tabla: 'tmpI - * - * @param temporary table tmp.item(id) del articulo - **/ - DROP TEMPORARY TABLE IF EXISTS tmp.itemToRefresh; - CREATE TEMPORARY TABLE tmp.itemToRefresh - SELECT id from tmp.item; - - UPDATE item i - JOIN tmp.itemToRefresh tmpI ON tmpI.id = i.id - LEFT JOIN itemTag it1 ON it1.priority = 1 AND it1.itemFk = i.id - LEFT JOIN itemTag it2 ON it2.priority = 2 AND it2.itemFk = i.id - LEFT JOIN itemTag it3 ON it3.priority = 3 AND it3.itemFk = i.id - SET i.longName = CONCAT_WS(' ', it1.`value`, it2.`value`, IF(it3.`value` = 'A1','',it3.`value`)); - - UPDATE item i - JOIN tmp.itemToRefresh tmpI ON tmpI.id = i.id - LEFT JOIN itemTag it1 ON it1.priority = 1 AND it1.itemFk = i.id - LEFT JOIN tagAbbreviation ta1 ON ta1.`value` = it1.`value` - LEFT JOIN itemTag it2 ON it2.priority = 2 AND it2.itemFk = i.id - LEFT JOIN tagAbbreviation ta2 ON ta2.`value` = it2.`value` - LEFT JOIN itemTag it3 ON it3.priority = 3 AND it3.itemFk = i.id - LEFT JOIN tagAbbreviation ta3 ON ta3.`value` = it3.`value` - SET i.`name` = CONCAT_WS(' ', - IFNULL(ta1.abbreviation,it1.`value`), - IFNULL(ta2.abbreviation,it2.`value`), - IF(i.id > 400000,'',IFNULL(ta3.abbreviation,it3.`value`))); - - UPDATE item i - JOIN tmp.itemToRefresh tmpI ON tmpI.id = i.id - LEFT JOIN itemTag it ON it.itemFk = i.id AND it.priority = 4 - SET i.subName = it.`value`; - - UPDATE item i - JOIN tmp.itemToRefresh tmpI ON tmpI.id = i.id - LEFT JOIN itemTag it ON it.itemFk = i.id AND it.priority = 5 - LEFT JOIN tag t ON t.id = it.tagFk - SET tag5 = t.name, value5 = it.`value`; - - UPDATE item i - JOIN tmp.itemToRefresh tmpI ON tmpI.id = i.id - LEFT JOIN itemTag it ON it.itemFk = i.id AND it.priority = 6 - LEFT JOIN tag t ON t.id = it.tagFk - SET tag6 = t.name, value6 = it.`value`; - - UPDATE item i - JOIN tmp.itemToRefresh tmpI ON tmpI.id = i.id - LEFT JOIN itemTag it ON it.itemFk = i.id AND it.priority = 7 - LEFT JOIN tag t ON t.id = it.tagFk - SET i.tag7 = t.name, i.value7 = it.`value`; - - UPDATE item i - JOIN tmp.itemToRefresh tmpI ON tmpI.id = i.id - LEFT JOIN itemTag it ON it.itemFk = i.id AND it.priority = 8 - LEFT JOIN tag t ON t.id = it.tagFk - SET tag8 = t.name, value8 = it.`value`; - - UPDATE item i - JOIN tmp.itemToRefresh tmpI ON tmpI.id = i.id - LEFT JOIN itemTag it ON it.itemFk = i.id AND it.priority = 9 - LEFT JOIN tag t ON t.id = it.tagFk - SET tag9 = t.name, value9 = it.`value`; - - UPDATE item i - JOIN tmp.itemToRefresh tmpI ON tmpI.id = i.id - LEFT JOIN itemTag it ON it.itemFk = i.id AND it.priority = 10 - LEFT JOIN tag t ON t.id = it.tagFk - SET tag10 = t.name, value10 = it.`value`; - - -- Al insertar el tag color se modifica también el antiguo campo color - UPDATE item i - JOIN tmp.itemToRefresh tmpI ON tmpI.id = i.id - JOIN tag t ON t.overwrite = 'inkFk' - JOIN itemTag it ON it.itemFk = i.id AND it.tagFk = t.id - JOIN ink ON ink.`name` = it.`value` - SET i.inkFk = ink.id; - - -- Al insertar el tag origen se modifica también en la tabla item - UPDATE item i - JOIN tmp.itemToRefresh tmpI ON tmpI.id = i.id - JOIN tag t ON t.overwrite = 'originFk' - JOIN itemTag it ON it.itemFk = i.id AND it.tagFk = t.id - JOIN origin o ON o.`name` = it.`value` - SET i.originFk = o.id; - - -- Al insertar el tag medida se modifica también en la tabla item - UPDATE item i - JOIN tmp.itemToRefresh tmpI ON tmpI.id = i.id - JOIN tag t ON t.overwrite = 'size' - JOIN itemTag it ON it.itemFk = i.id AND it.tagFk = t.id - SET i.size = it.`value`; - - -- Al insertar el tag productor se modifica también en la tabla item - UPDATE item i - JOIN tmp.itemToRefresh tmpI ON tmpI.id = i.id - JOIN tag t ON t.overwrite = 'producerFk' - JOIN itemTag it ON it.itemFk = i.id AND it.tagFk = t.id - JOIN producer p ON p.`name` = it.`value` - SET i.producerFk = p.id; - - -- Al insertar el tag tallos se modifica también en la tabla item - UPDATE item i - JOIN tmp.itemToRefresh tmpI ON tmpI.id = i.id - JOIN tag t ON t.overwrite = 'stems' - JOIN itemTag it ON it.itemFk = i.id AND it.tagFk = t.id - SET i.stems = it.`value`; - - DROP TEMPORARY TABLE IF EXISTS tmp.itemToRefresh; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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_saveReference` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -69148,95 +60380,31 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_saveReference`(vBarcode VARCHAR(22), vReference VARCHAR(150)) -BEGIN - -/** - * Actualiza la referencia del item - * - * @param vBarcode del item - * @param vReference referencia a actualizar - */ - - DECLARE vItemFk INT; - - SELECT barcodeToItem(vBarcode) INTO vItemFk; - - UPDATE item SET comment = vReference WHERE id = vItemFk; - +BEGIN + +/** + * Actualiza la referencia del item + * + * @param vBarcode del item + * @param vReference referencia a actualizar + */ + + DECLARE vItemFk INT; + + SELECT barcodeToItem(vBarcode) INTO vItemFk; + + UPDATE item SET comment = vReference WHERE 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 `item_setCompression__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `item_setCompression__`() -BEGIN - /** - * Actualiza la compression de los articulos con un packing.hasCompressionVariations = TRUE - * - */ - DECLARE done INT DEFAULT FALSE; - DECLARE vBuyFk INT; - DECLARE cur1 CURSOR FOR SELECT b.id - FROM vn.item i - JOIN edi.supplyResponse ii ON i.supplyResponseFk = ii.ID - JOIN vn.packaging p ON p.id = ii.EmbalageCode AND hasCompressionVariations - JOIN vn.itemTag diameter ON diameter.itemFk = i.id - JOIN vn.tag tDiameter ON tDiameter.overwrite = 'diameter' AND tDiameter.id = diameter.tagFk - JOIN vn.itemTag size ON size.itemFk = i.id - JOIN vn.tag tSize ON tSize.overwrite = 'size' AND tSize.id = size.tagFk - JOIN vn.buy b ON b.itemFk = i.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - UPDATE vn.item i - JOIN edi.supplyResponse ii ON i.supplyResponseFk = ii.ID - JOIN vn.packaging p ON p.id = ii.EmbalageCode AND hasCompressionVariations - JOIN vn.itemTag diameter ON diameter.itemFk = i.id - JOIN vn.tag tDiameter ON tDiameter.overwrite = 'diameter' AND tDiameter.id = diameter.tagFk - JOIN vn.itemTag size ON size.itemFk = i.id - JOIN vn.tag tSize ON tSize.overwrite = 'size' AND tSize.id = size.tagFk - SET i.`compression` = (PI() * POW(diameter.`value`/ 2, 2) * size.`value`) - / - ((p.width * p.depth * p.height) / ii.NumberOfItemsPerCask) - WHERE (PI() * POW(diameter.`value`/ 2, 2) * size.`value`) - / - ((p.width * p.depth * p.height) / ii.NumberOfItemsPerCask) <> 0; - - OPEN cur1; - - read_loop: LOOP - SET done = FALSE; - FETCH cur1 INTO vBuyFk; - IF done THEN - LEAVE read_loop; - END IF; - - call vn.buy_afterUpsert(vBuyFk); - - END LOOP; - - CLOSE cur1; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_setGeneric` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -69244,57 +60412,57 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_setGeneric`(vSelf INT) -BEGIN -/** - * Asigna el código genérico a un item, salvo que sea un código de item genérico. - * - * @param vSelf identificador de vn.item - */ - DECLARE vGenericFk INT; - - SELECT itemFk INTO vGenericFk - FROM ( - SELECT itemFk, (sum(matches) = maxMatches) `match` - FROM ( - SELECT ga.id gaid, - ga.itemFk, - (it.value <=> ga.origin) - + (it.value <=> ga.color) - + (it.value <=> ga.quality) - + (it.value <=> ga.numFlores) - + (it.value <=> ga.category) - + (it.value <=> ga.productor) matches, - !ISNULL(ga.origin) - +!ISNULL(ga.color) - +!ISNULL(ga.quality) - +!ISNULL(ga.numFlores) - +!ISNULL(ga.category) - +!ISNULL(ga.productor) maxMatches - FROM vn.item i - JOIN vn.itemTag it ON it.itemFk = i.id - JOIN vn.genericAllocation ga - ON (i.typeFk = ga.typeFk OR ga.typeFk IS NULL) - AND (i.longName = ga.longName OR ga.longName IS NULL) - AND (i.`size` = ga.`size` OR ga.`size` IS NULL) - AND i.id != ga.itemFk - WHERE i.id = vSelf - AND NOT i.isFloramondo) sub - GROUP BY gaid - HAVING `match`) sub2; - - UPDATE vn.item - SET genericFk = vGenericFk - WHERE id = vSelf; +BEGIN +/** + * Asigna el código genérico a un item, salvo que sea un código de item genérico. + * + * @param vSelf identificador de vn.item + */ + DECLARE vGenericFk INT; + + SELECT itemFk INTO vGenericFk + FROM ( + SELECT itemFk, (sum(matches) = maxMatches) `match` + FROM ( + SELECT ga.id gaid, + ga.itemFk, + (it.value <=> ga.origin) + + (it.value <=> ga.color) + + (it.value <=> ga.quality) + + (it.value <=> ga.numFlores) + + (it.value <=> ga.category) + + (it.value <=> ga.productor) matches, + !ISNULL(ga.origin) + +!ISNULL(ga.color) + +!ISNULL(ga.quality) + +!ISNULL(ga.numFlores) + +!ISNULL(ga.category) + +!ISNULL(ga.productor) maxMatches + FROM vn.item i + JOIN vn.itemTag it ON it.itemFk = i.id + JOIN vn.genericAllocation ga + ON (i.typeFk = ga.typeFk OR ga.typeFk IS NULL) + AND (i.longName = ga.longName OR ga.longName IS NULL) + AND (i.`size` = ga.`size` OR ga.`size` IS NULL) + AND i.id != ga.itemFk + WHERE i.id = vSelf + AND NOT i.isFloramondo) sub + GROUP BY gaid + HAVING `match`) sub2; + + UPDATE vn.item + SET genericFk = vGenericFk + WHERE id = vSelf; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_updatePackingShelve` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -69302,29 +60470,29 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_updatePackingShelve`(vSelf INT, vPacking INT) -BEGIN - +BEGIN + /** - * Actualiza el valor de item.packingShelve - * - * @param vSelf Identificador de vn.item - * @param vPacking Cantidad de unidades de venta que caben en una bandeja - */ - - UPDATE vn.item i - SET i.packingShelve = vPacking - WHERE i.id = vSelf; - + * Actualiza el valor de item.packingShelve + * + * @param vSelf Identificador de vn.item + * @param vPacking Cantidad de unidades de venta que caben en una bandeja + */ + + UPDATE vn.item i + SET i.packingShelve = vPacking + WHERE i.id = vSelf; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_updatePackingType` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -69332,25 +60500,25 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` 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; - +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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `item_ValuateInventory` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -69358,8 +60526,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `item_ValuateInventory`(IN vDated DATE, IN vIsDetailed BOOLEAN) BEGIN @@ -69435,7 +60601,7 @@ BEGIN JOIN itemType t ON t.id = i.typeFk JOIN warehouse w ON w.id = tr.warehouseInFk WHERE tr.landed BETWEEN vInventoried AND vDateDayEnd - AND IF(tr.landed = util.VN_CURDATE(), tr.isReceived, trUE) + AND IF(tr.landed = vn.VN_CURDATE(), tr.isReceived, trUE) AND NOT e.isRaid AND w.valuatedInventory AND t.isInventory @@ -69468,7 +60634,7 @@ BEGIN AND it.isInventory ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + s.quantity * IF(vHasNotInventory,1,-1); - IF vDated = util.VN_CURDATE() THEN -- volver a poner lo que esta aun en las estanterias + IF vDated = vn.VN_CURDATE() THEN -- volver a poner lo que esta aun en las estanterias INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) SELECT w.id, s.itemFk, s.quantity * IF(vHasNotInventory,0,1), w.`name` @@ -69556,201 +60722,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 `item_ValuateInventory__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `item_ValuateInventory__`(IN vDated DATE, IN vIsDetailed BOOLEAN) -BEGIN - - DECLARE vInventoried DATE; - DECLARE vHasNotInventory BOOLEAN DEFAULT 0; - DECLARE vInventoried2 DATE; - DECLARE vDateDayEnd DATETIME; - - SET vDateDayEnd = util.dayEnd(vDated); - SELECT landed INTO vInventoried - FROM travel tr - JOIN entry E ON E.travelFk = tr.id - WHERE landed <= vDateDayEnd - AND E.supplierFk = 4 - ORDER BY landed DESC - LIMIT 1; - - SET vHasNotInventory = IF (vInventoried is null, TRUE, FALSE); - - IF vHasNotInventory THEN - - SELECT landed INTO vInventoried2 - FROM travel tr - JOIN entry E ON E.travelFk = tr.id - WHERE landed >= vDated - AND E.supplierFk = 4 - ORDER BY landed ASC - LIMIT 1; - - SET vInventoried = TIMESTAMPADD(DAY,1,vDated); - SET vDateDayEnd = vInventoried2; - - END IF; - - DROP TEMPORARY TABLE IF EXISTS inv; - - CREATE TEMPORARY TABLE inv - (warehouseFk SMALLINT, - Id_Article BIGINT, - cantidad INT, - coste DOUBLE DEFAULT 0, - total DOUBLE DEFAULT 0, - Almacen VARCHAR(20), - PRIMARY KEY (Almacen, Id_Article) USING HASH) - ENGINE = MEMORY; - - IF vHasNotInventory = TRUE THEN - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouseInFk, b.itemFk, SUM(b.quantity), w.`name` - FROM buy b - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN itemType t ON t.id = i.typeFk - JOIN warehouse w ON w.id = warehouseInFk - WHERE landed = vDateDayEnd - AND e.supplierFk = 4 - AND w.valuatedInventory - AND t.isInventory - GROUP BY tr.warehouseInFk, b.itemFk; - - END IF; - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouseInFk, b.itemFk, b.quantity * IF(vHasNotInventory,-1,1), w.`name` - FROM buy b - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN itemType t ON t.id = i.typeFk - JOIN warehouse w ON w.id = tr.warehouseInFk - WHERE tr.landed BETWEEN vInventoried AND vDateDayEnd - AND IF(tr.landed = util.VN_CURDATE(), tr.isReceived, trUE) - AND NOT e.isRaid - AND w.valuatedInventory - AND t.isInventory - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (b.quantity * IF(vHasNotInventory,-1,1)); - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouseOutFk, b.itemFk, b.quantity * IF(vHasNotInventory,1,-1), w.`name` - FROM buy b - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN itemType t ON t.id = i.typeFk - JOIN warehouse w ON w.id = tr.warehouseOutFk - WHERE tr.shipped BETWEEN vInventoried AND vDateDayEnd - AND NOT e.isRaid - AND w.valuatedInventory - AND t.isInventory - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (b.quantity * IF(vHasNotInventory,1,-1)); - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT w.id, s.itemFk, s.quantity * IF(vHasNotInventory,1,-1), w.`name` - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN `client` c ON c.id = t.clientFk - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped BETWEEN vInventoried AND vDateDayEnd - AND w.valuatedInventory - AND it.isInventory - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + s.quantity * IF(vHasNotInventory,1,-1); - - IF vDated = util.VN_CURDATE() THEN -- volver a poner lo que esta aun en las estanterias - - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT w.id, s.itemFk, s.quantity * IF(vHasNotInventory,0,1), w.`name` - FROM sale s - JOIN ticket t ON t.id = s.ticketFk - JOIN `client` c ON c.id = t.clientFk - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.shipped BETWEEN vDated AND vDateDayEnd - AND (s.isPicked <> 0 or t.isLabeled <> 0 ) - AND w.valuatedInventory - AND it.isInventory - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + s.quantity * IF(vHasNotInventory,0,1); - - END IF; - - -- Mercancia en transito - INSERT INTO inv(warehouseFk, Id_Article, cantidad, Almacen) - SELECT tr.warehouseInFk, b.itemFk, b.quantity, CONCAT(wOut.`name`,' - ', wIn.`name`) - FROM buy b - JOIN item i ON i.id = b.itemFk - JOIN entry e ON e.id = b.entryFk - JOIN travel tr ON tr.id = e.travelFk - JOIN itemType t ON t.id = i.typeFk - JOIN warehouse wIn ON wIn.id = tr.warehouseInFk - JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk - WHERE vDated >= tr.shipped AND vDated < tr.landed - AND NOT isRaid - AND wIn.valuatedInventory - AND t.isInventory - AND e.isConfirmed - ON DUPLICATE KEY UPDATE inv.cantidad = inv.cantidad + (b.quantity); - - CALL vn.buyUltimate(NULL,vDateDayEnd); - - UPDATE inv i - JOIN tmp.buyUltimate bu ON i.warehouseFk = bu.warehouseFk AND i.Id_Article = bu.itemFk - JOIN buy b ON b.id = bu.buyFk - SET total = i.cantidad * (ifnull(b.buyingValue,0) + IFNULL(b.packageValue,0) + IFNULL(b.freightValue,0) + IFNULL(b.comissionValue,0)), - coste = ifnull(b.buyingValue,0) + IFNULL(b.packageValue,0) + IFNULL(b.freightValue,0) + IFNULL(b.comissionValue,0) - WHERE i.cantidad <> 0; - - DELETE FROM inv WHERE Cantidad IS NULL or Cantidad = 0; - - IF vIsDetailed THEN - - SELECT inv.warehouseFk, i.id, i.name, i.size, inv.Cantidad, tp.code, - tp.categoryFk, inv.coste, cast(inv.total as decimal(10,2)) total,Almacen - FROM inv - JOIN warehouse w on w.id = warehouseFk - JOIN item i ON i.id = inv.Id_Article - JOIN itemType tp ON tp.id = i.typeFk - WHERE w.valuatedInventory - and inv.total > 0 - order by inv.total desc; - - ELSE - - SELECT i.Almacen, ic.name as Reino, cast(i.total as decimal(10,2)) as Euros, w.code as Comprador,it.id - FROM inv i - JOIN warehouse wh on wh.id = warehouseFk - JOIN item it ON it.id = i.Id_Article - JOIN itemType itp ON itp.id = it.typeFk - LEFT JOIN worker w ON w.id = itp.workerFk - JOIN itemCategory ic ON ic.id = itp.categoryFk - WHERE wh.valuatedInventory - AND i.total > 0; - - END IF; - DROP TEMPORARY TABLE tmp.buyUltimate; - DROP TEMPORARY TABLE inv; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `ledger_doCompensation` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -69758,8 +60731,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ledger_doCompensation`(vDated DATE, vCompensationAccount VARCHAR(10) , vBankFk VARCHAR(10), vConcept VARCHAR(255), vAmount DECIMAL(10,2), vCompanyFk INT, vOriginalAccount VARCHAR(10)) BEGIN @@ -69842,6 +60813,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ledger_next` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -69849,8 +60822,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ledger_next`(OUT vNewBookEntry INT) BEGIN @@ -69864,6 +60835,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `logAdd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -69871,8 +60844,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `logAdd`(vOriginFk INT, vActionCode VARCHAR(45), vEntity VARCHAR(45), vDescription TEXT) BEGIN @@ -69885,13 +60856,15 @@ BEGIN * @param descripcion Descripción de la acción realizada por el usuario */ - CALL logAddWithUser(vOriginFk, account.userGetId(), vActionCode, vEntity, vDescription); + CALL logAddWithUser(vOriginFk, account.myUser_getId(), vActionCode, vEntity, vDescription); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `logAddWithUser` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -69899,8 +60872,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `logAddWithUser`(vOriginFk INT, vUserId INT, vActionCode VARCHAR(45), vEntity VARCHAR(45), vDescription TEXT) BEGIN @@ -69933,6 +60904,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `logShow` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -69940,8 +60913,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `logShow`(vOriginFk INT, vEntity VARCHAR(45)) BEGIN @@ -69969,6 +60940,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `lungSize_generator` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -69976,8 +60949,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `lungSize_generator`(vDate DATE) BEGIN @@ -70030,6 +61001,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `machineWorker_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70037,8 +61010,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `machineWorker_add`(vPlate VARCHAR(10), vWorkerFk INT) BEGIN @@ -70051,7 +61022,7 @@ BEGIN */ UPDATE vn.machineWorker mw JOIN vn.machine m ON m.id = mw.machineFk - SET mw.outTimed = util.VN_NOW() + SET mw.outTimed = vn.VN_NOW() WHERE (mw.workerFk = vWorkerFk OR m.plate = vPlate) AND ISNULL(mw.outTimed); @@ -70065,6 +61036,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `machineWorker_getHistorical` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70072,8 +61045,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `machineWorker_getHistorical`(vPlate VARCHAR(20), vWorkerFk INT) BEGIN @@ -70099,6 +61070,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `machineWorker_update` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70106,8 +61079,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `machineWorker_update`(vPlate VARCHAR(10), vWorkerFk INT) BEGIN @@ -70133,12 +61104,12 @@ BEGIN IF (SELECT COUNT(*) FROM machineWorker m WHERE m.workerFk = vWorkerFk - AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) AND ISNULL(m.outTimed)) THEN + AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, vn.VN_NOW()) AND ISNULL(m.outTimed)) THEN UPDATE machineWorker m SET m.outTimed = CURRENT_TIMESTAMP() WHERE m.workerFk = vWorkerFk - AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, util.VN_NOW()) + AND m.inTimed >= TIMESTAMPADD(HOUR , -vMaxHours, vn.VN_NOW()) AND ISNULL(m.outTimed) AND m.machineFk = vMachineFk; @@ -70150,6 +61121,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `machine_getWorkerPlate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70157,32 +61130,32 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` 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,util.VN_NOW()) - AND ISNULL(mw.outTimed) - AND mw.workerFk = vWorkerFk; - +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,vn.VN_NOW()) + AND ISNULL(mw.outTimed) + AND mw.workerFk = vWorkerFk; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `mail_insert` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70190,8 +61163,6 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `mail_insert`( vReceiver VARCHAR(255), @@ -70212,7 +61183,7 @@ BEGIN SELECT COUNT(*) INTO vIsRepeated FROM vn.mail - WHERE creationDate >= util.VN_CURDATE() + WHERE creationDate >= vn.VN_CURDATE() AND `receiver` = vReceiver AND `replyTo` = vReplyTo AND `subject` = vSubject @@ -70234,6 +61205,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `makeNewItem` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70241,8 +61214,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `makeNewItem`() BEGIN @@ -70263,6 +61234,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `makePCSGraf` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70270,8 +61243,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `makePCSGraf`(vDated DATE) BEGIN @@ -70315,15 +61286,15 @@ 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `manaSpellersRequery` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_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 character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `manaSpellersRequery`(vWorkerFk INTEGER) BEGIN @@ -70334,17 +61305,17 @@ BEGIN */ DECLARE vWorkerIsExcluded BOOLEAN; DECLARE vFromDated DATE; - DECLARE vToDated DATE DEFAULT TIMESTAMPADD(DAY,1,util.VN_CURDATE()); + DECLARE vToDated DATE DEFAULT TIMESTAMPADD(DAY,1,vn.VN_CURDATE()); DECLARE vMana INT; - DECLARE vAutoMana INT; - DECLARE vClaimMana INT; - DECLARE vManaBank INT; - DECLARE vManaGreugeType INT; - - SELECT COUNT(*) INTO vWorkerIsExcluded + DECLARE vAutoMana INT; + DECLARE vClaimMana INT; + DECLARE vManaBank INT; + DECLARE vManaGreugeType INT; + + SELECT COUNT(*) INTO vWorkerIsExcluded FROM workerManaExcluded WHERE workerFk = vWorkerFk; - + IF NOT vWorkerIsExcluded THEN SELECT id INTO vMana FROM `component` WHERE code = 'mana'; @@ -70363,8 +61334,8 @@ BEGIN SELECT max(dated) INTO vFromDated FROM clientManaCache; - - REPLACE workerMana (workerFk, amount) + + REPLACE workerMana (workerFk, amount) SELECT vWorkerFk, sum(mana) FROM ( SELECT s.quantity * sc.value as mana @@ -70386,7 +61357,7 @@ BEGIN FROM greuge g JOIN client c ON c.id = g.clientFk WHERE c.salesPersonFk = vWorkerFk AND g.greugeTypeFk = vManaGreugeType - AND g.shipped > vFromDated and g.shipped < util.VN_CURDATE() + AND g.shipped > vFromDated and g.shipped < vn.VN_CURDATE() UNION ALL SELECT cc.mana FROM clientManaCache cc @@ -70400,52 +61371,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 `mergeTicketUnattended` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `mergeTicketUnattended`(IN vMainTicket INT(11), IN hasSameAgency BOOLEAN) -BEGIN - - DECLARE isBilled BOOLEAN; - DECLARE arrayTickets VARCHAR(255); - - SELECT Factura IS NOT NULL INTO isBilled FROM vn2008.Tickets WHERE Id_Ticket = vMainTicket; - - IF NOT isBilled THEN - - SELECT GROUP_CONCAT(distinct T.Id_Ticket) INTO arrayTickets - FROM vn2008.Tickets T LEFT JOIN vn.ticketState ts ON T.Id_Ticket = ts.ticket - JOIN vn2008.Tickets ticketOriginal ON ticketOriginal.Id_Ticket = vMainTicket - AND T.empresa_id = ticketOriginal.empresa_id - AND T.Id_Consigna = ticketOriginal.Id_Consigna - AND DATE(T.Fecha) = DATE(ticketOriginal.Fecha) - AND T.warehouse_id = ticketOriginal.warehouse_id - AND IF(hasSameAgency <> 0,T.Id_Agencia = ticketOriginal.Id_Agencia,TRUE) - LEFT JOIN vn.ticketState tsOriginal ON ticketOriginal.Id_Ticket = tsOriginal.ticket - WHERE ts.alertLevel < 3 - AND T.Factura IS NULL - AND T.Anotadoencaja = FALSE - AND T.Id_Ticket <> vMainTicket - AND ts.alertLevel = tsOriginal.alertLevel; - - CALL mergeTicketWithArray(vMainTicket,arrayTickets); - - END IF; - - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `mergeTicketWithArray` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70453,8 +61380,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `mergeTicketWithArray`(IN vMainTicket INT(11), IN arrayTickets VARCHAR(50)) BEGIN @@ -70470,7 +61395,7 @@ BEGIN IF NOT isBilled THEN - SELECT Id_Trabajador INTO worker from vn2008.Trabajadores where user_id = account.userGetId(); + SELECT Id_Trabajador INTO worker from vn2008.Trabajadores where user_id = account.myUser_getId(); DROP TEMPORARY TABLE IF EXISTS vn2008.Tickets_to_fusion; @@ -70547,6 +61472,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `mysqlConnectionsSorter_kill` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70554,8 +61481,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `mysqlConnectionsSorter_kill`() BEGIN @@ -70597,6 +61522,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `mysqlPreparedCount_check` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70604,8 +61531,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `mysqlPreparedCount_check`() BEGIN @@ -70631,188 +61556,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 `nestAdd__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `nestAdd__`(IN `vScheme` VARCHAR(45), IN `vTable` VARCHAR(45), IN `vParentFk` INT, IN `vChild` VARCHAR(100)) -BEGIN - DECLARE vSql TEXT; - DECLARE vTableClone VARCHAR(45); - - SET vTableClone = CONCAT(vTable, 'Clone'); - - CALL util.exec(CONCAT('DROP TEMPORARY TABLE IF EXISTS tmp.', vTableClone)); - CALL util.exec(CONCAT( - 'CREATE TEMPORARY TABLE tmp.', vTableClone, - ' ENGINE = MEMORY' - ' SELECT * FROM ', vScheme, '.', vTable - )); - - -- Check parent childs - SET vSql = sql_printf(' - SELECT COUNT(c.id) INTO @childs - FROM %t.%t p - LEFT JOIN %t.%t c ON c.lft BETWEEN p.lft AND p.rgt AND c.id != %v - WHERE p.id = %v', - vScheme, vTable, 'tmp', vTableClone, vParentFk, vParentFk); - SET @qrySql := vSql; - - PREPARE stmt FROM @qrySql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - - -- Select left from last child - IF @childs = 0 THEN - SET vSql = sql_printf('SELECT lft INTO @vLeft FROM %t.%t WHERE id = %v', vScheme, vTable, vParentFk); - SET @qrySql := vSql; - ELSE - SET vSql = sql_printf(' - SELECT c.rgt INTO @vLeft - FROM %t.%t p - JOIN %t.%t c ON c.lft BETWEEN p.lft AND p.rgt - WHERE p.id = %v - ORDER BY c.lft - DESC LIMIT 1', - vScheme, vTable, 'tmp', vTableClone, vParentFk); - SET @qrySql := vSql; - END IF; - - PREPARE stmt FROM @qrySql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - - -- Update right - SET vSql = sql_printf('UPDATE %t.%t SET rgt = rgt + 2 WHERE rgt > %v ORDER BY rgt DESC', vScheme, vTable, @vLeft); - SET @qrySql := vSql; - - PREPARE stmt FROM @qrySql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - - SET vSql = sql_printf('UPDATE %t.%t SET lft = lft + 2 WHERE lft > %v ORDER BY lft DESC', vScheme, vTable, @vLeft); - SET @qrySql := vSql; - - PREPARE stmt FROM @qrySql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - - -- Escape character - SET vChild = REPLACE(vChild, "'", "\\'"); - - -- Add child - SET vSql = sql_printf('INSERT INTO %t.%t (name, lft, rgt) VALUES (%v, %v, %v)', vScheme, vTable, vChild, @vLeft + 1, @vLeft + 2); - SET @qrySql := vSql; - - PREPARE stmt FROM @qrySql; - EXECUTE stmt; - DEALLOCATE PREPARE stmt; - - CALL util.exec(CONCAT('DROP TEMPORARY TABLE tmp.', vTableClone)); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `nestLeave__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `nestLeave__`(vScheme VARCHAR(45), vTable VARCHAR(45), vParentFk INT) -BEGIN - DROP TEMPORARY TABLE IF EXISTS tmp.tree; - - CALL util.exec(CONCAT( - 'CREATE TEMPORARY TABLE tmp.tree ', - 'SELECT - node.id, - node.name, - node.lft, - node.rgt, - node.depth, - node.sons - FROM ', - vScheme, '.', vTable, ' AS node, ', - vScheme, '.', vTable, ' AS parent ', - 'WHERE - node.lft BETWEEN parent.lft AND parent.rgt - AND node.depth = parent.depth + 1 - AND parent.id = ', vParentFk, ' ' - 'GROUP BY node.id - ORDER BY node.lft')); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `nestTree__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `nestTree__`( - vSourceSchema VARCHAR(45), - vSourceTable VARCHAR(45), - vDestinationSchema VARCHAR(45), - vDestinationTable VARCHAR(45)) -BEGIN - DECLARE vTableClone VARCHAR(45); - - SET vTableClone = CONCAT(vSourceTable, 'Clone'); - - CALL util.exec(CONCAT('DROP TEMPORARY TABLE IF EXISTS tmp.', vTableClone)); - CALL util.exec(CONCAT( - 'CREATE TEMPORARY TABLE tmp.', vTableClone, - ' ENGINE = MEMORY', - ' SELECT * FROM ', vSourceSchema, '.', vSourceTable - )); - - CALL util.exec(CONCAT( - 'TRUNCATE TABLE ', vDestinationSchema, '.', vDestinationTable)); - CALL util.exec(CONCAT( - 'INSERT INTO ', vDestinationSchema, '.', vDestinationTable, - '(id, name, lft, rgt, depth, sons)', - 'SELECT - node.id, - node.name, - node.lft, - node.rgt, - COUNT(parent.id) - 1 depth, - CAST((node.rgt - node.lft - 1) / 2 as DECIMAL) as sons - FROM ', - vSourceSchema, '.', vSourceTable, ' AS node,', - 'tmp.', vTableClone, ' AS parent ', - 'WHERE node.lft - BETWEEN parent.lft AND parent.rgt - GROUP BY node.id - ORDER BY node.lft')); - - CALL util.exec(CONCAT('DROP TEMPORARY TABLE tmp.', vTableClone)); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `nextShelvingCodeMake` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70820,8 +61565,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `nextShelvingCodeMake`() BEGIN @@ -70867,6 +61610,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `observationAdd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70874,8 +61619,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `observationAdd`(vOriginFk INT, vTableCode VARCHAR(45), vDescription TEXT) BEGIN @@ -70896,7 +61639,7 @@ BEGIN SET @qryLog := CONCAT( 'INSERT INTO ', vTableName, ' (originFk, userFk, description)', - ' VALUES (', vOriginFk, ', ', account.userGetId(), ', "', vDescription, '")' + ' VALUES (', vOriginFk, ', ', account.myUser_getId(), ', "', vDescription, '")' ); PREPARE stmt FROM @qryLog; @@ -70908,6 +61651,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `orderCreate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70915,8 +61660,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `orderCreate`( vLanded DATE, @@ -70948,6 +61691,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `orderDelete` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70955,8 +61700,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `orderDelete`(IN vId INT) BEGIN @@ -70969,6 +61712,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `orderListCreate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -70976,8 +61721,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `orderListCreate`( vLanded DATE, @@ -70996,6 +61739,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `orderListVolume` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -71003,8 +61748,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `orderListVolume`(IN vOrderId INT) BEGIN @@ -71025,6 +61768,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `packageInvoicing` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -71032,8 +61777,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `packageInvoicing`( IN vClient INT, @@ -71106,7 +61849,7 @@ BEGIN NULL, NULL, vDateEnd, - account.userGetId(), + account.myUser_getId(), TRUE, vNewTicket); @@ -71159,6 +61902,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `packingListPrinted` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -71166,8 +61911,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `packingListPrinted`(ticketFk INT) BEGIN @@ -71185,6 +61928,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `packingListSwitch` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -71192,8 +61937,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `packingListSwitch`(saleFk INT) BEGIN @@ -71218,6 +61961,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `parking_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -71225,8 +61970,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `parking_add`(vFromColumn INT, vToColumn INT, vFromRow INT, vToRow INT, vSectorFk INT, vIsLetterMode BOOLEAN) BEGIN @@ -71272,60 +62015,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 `parking_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `parking_add__`(vFromColumn INT, vToColumn INT, vFromRow INT, vToRow INT, vSectorFk INT, vIsLetterMode BOOLEAN) -BEGIN - - DECLARE vColumn INT; - DECLARE vRow INT; - DECLARE vLetters VARCHAR(26) DEFAULT 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; - DECLARE vMaxId INT; - DECLARE vCode VARCHAR(8); - - SET vColumn = vFromColumn; - SET vRow = vFromRow; - SET vCode = CONCAT(LPAD(vColumn,3,'0'),'-',IF(vIsLetterMode, MID(vLetters, vRow, 1), LPAD(vRow, 2,'0'))); - - SELECT MAX(id) INTO vMaxId - FROM vn.parking; - - WHILE vColumn <= vToColumn DO - - WHILE vRow <= vToRow DO - - INSERT IGNORE INTO vn.parking(`column`, `row`, sectorFk, `code`, pickingOrder) - VALUES (vColumn, vRow, vSectorFk, vCode, vColumn * 100 + vRow ) - ON DUPLICATE KEY UPDATE `code` = vCode; - - SET vRow = vRow + 1; - SET vCode = CONCAT(LPAD(vColumn,3,'0'),'-',IF(vIsLetterMode, MID(vLetters, vRow, 1), LPAD(vRow, 2,'0'))); - - END WHILE; - - SET vRow = vFromRow; - SET vColumn = vColumn + 1; - - SET vCode = CONCAT(LPAD(vColumn,3,'0'),'-',IF(vIsLetterMode, MID(vLetters, vRow, 1), LPAD(vRow, 2,'0'))); - - END WHILE; - - SELECT * FROM vn.parking WHERE `column` BETWEEN vFromColumn AND vToColumn; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `parking_algemesi` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -71333,8 +62024,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `parking_algemesi`(vFromRow INT, vToRow INT, vSectorFk INT, vLetter VARCHAR(1), vPickingOrder INT, vTrolleysByLine INT) BEGIN @@ -71401,6 +62090,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `parking_new` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -71408,8 +62099,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `parking_new`(vStart INT, vEnd INT, vSectorFk INT) BEGIN @@ -71446,51 +62135,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 `parking_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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `parking_new__`(vStart INT, vEnd INT, vSectorFk INT) -BEGIN - - DECLARE vRow INT; - DECLARE vColumn INT; - DECLARE vLetters VARCHAR(200); - DECLARE vLettersLength INT; - - SET vColumn = vStart; - SET vRow = 1; - SET vLetters = 'ABCDEF'; - SET vLettersLength = LENGTH(vLetters); - - WHILE vColumn <= vEnd DO - - REPLACE vn.parking(`column`, `row`, `code`, sectorFk) - VALUES(vColumn, vRow, CONCAT(vColumn,MID(vLetters,vRow,1)), vSectorFk); - - SET vRow = vRow + 1; - - IF vRow > vLettersLength THEN - - SET vRow = 1; - SET vColumn = vColumn + 1; - - END IF; - - END WHILE; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `parking_setOrder` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -71498,114 +62144,39 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `parking_setOrder`(vWarehouseFk INT) -BEGIN - - /* - * Ordena el orden de preparacion de los parking de acuerdo con la tabla vn.corridor - */ - - UPDATE vn.parking p - JOIN ( - SELECT code, - @orden := @orden + 10 AS po - FROM ( - SELECT c.prepOrder, - p.code, - @orden := 0, - IF(c.isAscendent, 1,-1) * CAST(SUBSTRING(p.code,3,2) AS DECIMAL(2,0)) subCorridor , - CAST(IF(LENGTH(p.code) > 5, SUBSTRING(p.code,6,2), 0) AS DECIMAL(2,0)) ubication - FROM vn.parking p - JOIN vn.sector s ON s.id = p.sectorFk - JOIN vn.corridor c ON c.code = LEFT(p.code,1) COLLATE utf8_general_ci - WHERE s.warehouseFk = vWarehouseFk) sub - ORDER BY sub.prepOrder, subCorridor, ubication) sub2 ON sub2.code = p.code - SET p.pickingOrder = sub2.po; - +BEGIN + + /* + * Ordena el orden de preparacion de los parking de acuerdo con la tabla vn.corridor + */ + + UPDATE vn.parking p + JOIN ( + SELECT code, + @orden := @orden + 10 AS po + FROM ( + SELECT c.prepOrder, + p.code, + @orden := 0, + IF(c.isAscendent, 1,-1) * CAST(SUBSTRING(p.code,3,2) AS DECIMAL(2,0)) subCorridor , + CAST(IF(LENGTH(p.code) > 5, SUBSTRING(p.code,6,2), 0) AS DECIMAL(2,0)) ubication + FROM vn.parking p + JOIN vn.sector s ON s.id = p.sectorFk + JOIN vn.corridor c ON c.code = LEFT(p.code,1) COLLATE utf8_general_ci + WHERE s.warehouseFk = vWarehouseFk) sub + ORDER BY sub.prepOrder, subCorridor, ubication) sub2 ON sub2.code = p.code + SET p.pickingOrder = sub2.po; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` 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 `placement_test` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -71613,100 +62184,74 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `placement_test`(vParamFk INT(11)) BEGIN - DECLARE vCalcFk INT; - DECLARE vWarehouseFk INT; - DECLARE vWarehouseAliasFk INT; - DECLARE vCurrentYear INT DEFAULT YEAR(util.VN_NOW()); - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - ENGINE = MEMORY + DECLARE vWarehouseFk INT; + DECLARE vWarehouseAliasFk INT; + DECLARE vCurrentYear INT DEFAULT YEAR(vn.VN_NOW()); + + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + ENGINE = MEMORY SELECT 0000000 as ticketFk, 0000000 as saleFk, - 0000000 as itemFk, - FALSE as isStowaway, - 0 as quantity; - - INSERT INTO tmp.sale(ticketFk, saleFk, itemFk, isStowaway) + 0000000 as itemFk, + FALSE as isStowaway, + 0 as quantity; + + INSERT INTO tmp.sale(ticketFk, saleFk, itemFk, isStowaway) SELECT s.ticketFk, s.id, s.itemFk, FALSE FROM vn.ticketCollection tc - JOIN vn.collection c ON c.id = tc.collectionFk + JOIN vn.collection c ON c.id = tc.collectionFk JOIN vn.sale s ON s.ticketFk = tc.ticketFk JOIN vn.item i ON i.id = s.itemFk WHERE tc.collectionFk = vParamFk AND (i.itemPackingTypeFk = c.itemPackingTypeFk OR ISNULL(c.itemPackingTypeFk)) - UNION ALL + UNION ALL SELECT s.ticketFk, s.id, s.itemFk, FALSE FROM vn.sale s WHERE s.ticketFk = vParamFk; - - - /* UNION ALL - SELECT sw.shipFk, s.id, s.itemFk, TRUE - FROM vn.sale s - JOIN vn.stowaway sw ON sw.id = s.ticketFk - JOIN vn.ticketCollection tc ON tc.ticketFk = sw.shipFk - WHERE tc.collectionFk = vParamFk; - - INSERT INTO tmp.sale(ticketFk, saleFk, itemFk, isStowaway) - SELECT s.ticketFk, s.id, s.itemFk, FALSE - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - WHERE s.ticketFk = vParamFk - AND t.shipped > '2020-01-01' - UNION ALL - SELECT sw.shipFk, s.id, s.itemFk, TRUE - FROM vn.sale s - JOIN vn.stowaway sw ON sw.id = s.ticketFk - WHERE sw.shipFk = vParamFk; - - DELETE FROM tmp.sale - WHERE saleFk = 0; - */ - SELECT t.warehouseFk, w.aliasFk + + SELECT t.warehouseFk, w.aliasFk INTO vWarehouseFk, vWarehouseAliasFk - FROM vn.ticket t + FROM vn.ticket t JOIN tmp.sale ts ON ts.ticketFk = t.id - JOIN vn.warehouse w ON w.id = t.warehouseFk - LIMIT 1; - + JOIN vn.warehouse w ON w.id = t.warehouseFk + LIMIT 1; + CALL cache.visible_refresh(vCalcFk,FALSE,vWarehouseFk); - + UPDATE tmp.sale ts JOIN ( SELECT itemFk, sum(visible) as visible - FROM vn.itemShelvingStock iss + FROM vn.itemShelvingStock iss JOIN vn.warehouse w ON w.id = iss.warehouseFk WHERE w.aliasFk = vWarehouseAliasFk GROUP BY iss.itemFk ) iss ON iss.itemFk = ts.itemFk SET ts.quantity = iss.visible; - - DROP TEMPORARY TABLE IF EXISTS tmp.sale2; - CREATE TEMPORARY TABLE tmp.sale2 - ENGINE = MEMORY + + DROP TEMPORARY TABLE IF EXISTS tmp.sale2; + CREATE TEMPORARY TABLE tmp.sale2 + ENGINE = MEMORY SELECT * FROM tmp.sale; - - - DROP TEMPORARY TABLE IF EXISTS tmp.`grouping`; - CREATE TEMPORARY TABLE tmp.`grouping` - (PRIMARY KEY (itemFk)) + + + DROP TEMPORARY TABLE IF EXISTS tmp.`grouping`; + CREATE TEMPORARY TABLE tmp.`grouping` + (PRIMARY KEY (itemFk)) ENGINE = MEMORY SELECT b.itemFk, - CASE b.groupingMode - WHEN 0 THEN 1 - WHEN 2 THEN b.packing - ELSE b.`grouping` + CASE b.groupingMode + WHEN 0 THEN 1 + WHEN 2 THEN b.packing + ELSE b.`grouping` END AS `grouping` FROM buy b JOIN cache.last_buy lb ON lb.buy_id = b.id WHERE lb.warehouse_id = vWarehouseFk ; - + DROP TEMPORARY TABLE IF EXISTS tmp.grouping2; CREATE TEMPORARY TABLE tmp.grouping2 ENGINE = MEMORY @@ -71716,87 +62261,89 @@ BEGIN CREATE TEMPORARY TABLE tmp.salePlacementList ENGINE = MEMORY - SELECT ts.saleFk, + SELECT ts.saleFk, ts.itemFk, CONCAT( - IF( iss.id, - CONCAT('< ', IFNULL(wk.`code`, '---'),' > '), - ''), + IF( iss.id, + CONCAT('< ', IFNULL(wk.`code`, '---'),' > '), + ''), p.`code`) COLLATE utf8_general_ci as placement , sh.code COLLATE utf8_general_ci as shelving, ish.created, ish.visible, IF(ts.isStowaway, - 100000, IF(ish.visible > 0 OR iss.id, 1, 100000)) * p.pickingOrder as `order`, - IFNULL(IF(sc.isPreviousPreparedByPacking, ish.packing, g.`grouping`),1) as `grouping`, - IF(iss.id, TO_SECONDS(TIMESTAMPADD(YEAR,-vCurrentYear,iss.created)), TO_SECONDS(TIMESTAMPADD(YEAR,- year(ish.created),ish.created)) + TO_SECONDS(TIMESTAMPADD(YEAR,-vCurrentYear,util.VN_NOW()))) as priority, - 0 as saleOrder, - sc.isPreviousPrepared, - iss.id as itemShelvingSaleFk, - ts.ticketFk - ,iss.id - , st.saleFk as salePreviousPrepared - , iss.userFk - FROM tmp.sale ts - LEFT JOIN (SELECT DISTINCT saleFk + IFNULL(IF(sc.isPreviousPreparedByPacking, ish.packing, g.`grouping`),1) as `grouping`, + IF(iss.id, TO_SECONDS(TIMESTAMPADD(YEAR,-vCurrentYear,iss.created)), TO_SECONDS(TIMESTAMPADD(YEAR,- year(ish.created),ish.created)) + TO_SECONDS(TIMESTAMPADD(YEAR,-vCurrentYear,vn.VN_NOW()))) as priority, + 0 as saleOrder, + sc.isPreviousPrepared, + iss.id as itemShelvingSaleFk, + ts.ticketFk + ,iss.id + , st.saleFk as salePreviousPrepared + , iss.userFk + FROM tmp.sale ts + LEFT JOIN (SELECT DISTINCT saleFk FROM vn.saleTracking st - JOIN vn.state s ON s.id = st.stateFk + JOIN vn.state s ON s.id = st.stateFk WHERE st.isChecked AND s.semaphore = 1) st ON st.saleFk = ts.saleFk - JOIN vn.itemShelving ish ON ish.itemFk = ts.itemFk - JOIN vn.shelving sh ON sh.code = ish.shelvingFk - JOIN vn.parking p ON p.id = sh.parkingFk - JOIN vn.sector sc ON sc.id = p.sectorFk - JOIN vn.warehouse w ON w.id = sc.warehouseFk - LEFT JOIN tmp.`grouping` g ON g.itemFk = ts.itemFk - LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = ts.saleFk AND iss.itemShelvingFk = ish.id - LEFT JOIN vn.worker wk ON wk.id = iss.userFk + JOIN vn.itemShelving ish ON ish.itemFk = ts.itemFk + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + JOIN vn.sector sc ON sc.id = p.sectorFk + JOIN vn.warehouse w ON w.id = sc.warehouseFk + LEFT JOIN tmp.`grouping` g ON g.itemFk = ts.itemFk + LEFT JOIN vn.itemShelvingSale iss ON iss.saleFk = ts.saleFk AND iss.itemShelvingFk = ish.id + LEFT JOIN vn.worker wk ON wk.id = iss.userFk WHERE w.aliasFk = vWarehouseAliasFk - HAVING (iss.id AND st.saleFk) OR salePreviousPrepared IS NULL - ; - + HAVING (iss.id AND st.saleFk) OR salePreviousPrepared IS NULL + ; + DROP TEMPORARY TABLE IF EXISTS tmp.salePlacementList_2; CREATE TEMPORARY TABLE tmp.salePlacementList_2 ENGINE MEMORY - SELECT saleFk, priority as olderPriority + SELECT saleFk, priority as olderPriority FROM (SELECT saleFk, priority FROM tmp.salePlacementList ORDER BY IF(isPreviousPrepared,2,1), IF(visible > 0 OR itemShelvingSaleFk,1,2), priority - ) sub - GROUP BY saleFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.salePlacementList_3; + LIMIT 10000000000000000000 + ) sub + GROUP BY saleFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.salePlacementList_3; CREATE TEMPORARY TABLE tmp.salePlacementList_3 ENGINE MEMORY - SELECT s1.saleFk, `order`as saleOrder + SELECT s1.saleFk, `order`as saleOrder FROM tmp.salePlacementList s1 - JOIN tmp.salePlacementList_2 s2 ON s2.saleFk = s1.saleFk AND s2.olderPriority = s1.priority; - - UPDATE tmp.salePlacementList s1 + JOIN tmp.salePlacementList_2 s2 ON s2.saleFk = s1.saleFk AND s2.olderPriority = s1.priority; + + UPDATE tmp.salePlacementList s1 JOIN tmp.salePlacementList_3 s3 ON s3.saleFk = s1.saleFk - SET s1.saleOrder = s3.saleOrder; - /* - -- Anula el orden de antigüedad y ordena por ubicación */ - UPDATE tmp.salePlacementList - SET saleOrder = `order`; - - SELECT * + SET s1.saleOrder = s3.saleOrder; + /* + -- Anula el orden de antigüedad y ordena por ubicación */ + UPDATE tmp.salePlacementList + SET saleOrder = `order`; + + SELECT * FROM tmp.salePlacementList - ORDER BY visible <> 0 DESC,saleOrder, IF(isPreviousPrepared,2,1), IF(itemShelvingSaleFk,1,2),priority; - + ORDER BY visible <> 0 DESC,saleOrder, IF(isPreviousPrepared,2,1), IF(itemShelvingSaleFk,1,2),priority; + DROP TEMPORARY TABLE tmp.sale, - tmp.sale2, - tmp.`grouping`, - tmp.grouping2, - tmp.salePlacementList_2, - tmp.salePlacementList_3; - + tmp.sale2, + tmp.`grouping`, + tmp.grouping2, + tmp.salePlacementList_2, + tmp.salePlacementList_3; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `prepareClientList` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -71804,28 +62351,28 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `prepareClientList`() -BEGIN - - /* - * Require la tabla tmp.ticket(id,clientFk) - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.client; - CREATE TEMPORARY TABLE tmp.client - (PRIMARY KEY (id)) - ENGINE = MEMORY - SELECT DISTINCT clientFk id - FROM tmp.ticket; +BEGIN + + /* + * Require la tabla tmp.ticket(id,clientFk) + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.client; + CREATE TEMPORARY TABLE tmp.client + (PRIMARY KEY (id)) + ENGINE = MEMORY + SELECT DISTINCT clientFk id + FROM tmp.ticket; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `prepareTicketList` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -71833,75 +62380,35 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `prepareTicketList`(vStartingDate DATETIME, vEndingDate DATETIME) -BEGIN - - DROP TEMPORARY TABLE IF EXISTS tmp.productionTicket; - CREATE TEMPORARY TABLE tmp.productionTicket - (PRIMARY KEY (ticketFk)) - ENGINE = MEMORY - SELECT t.id ticketFk, t.clientFk - FROM vn.ticket t - LEFT JOIN vn.ticketState ts ON ts.ticket = t.id - JOIN vn.client c ON c.id = t.clientFk - WHERE c.typeFk IN ('normal','handMaking','internalUse') - AND ( - t.shipped BETWEEN util.VN_CURDATE() AND vEndingDate - OR ( - ts.alertLevel < 3 - AND t.shipped >= vStartingDate - AND t.shipped < util.VN_CURDATE() - ) - ); +BEGIN + + DROP TEMPORARY TABLE IF EXISTS tmp.productionTicket; + CREATE TEMPORARY TABLE tmp.productionTicket + (PRIMARY KEY (ticketFk)) + ENGINE = MEMORY + SELECT t.id ticketFk, t.clientFk + FROM vn.ticket t + LEFT JOIN vn.ticketState ts ON ts.ticket = t.id + JOIN vn.client c ON c.id = t.clientFk + WHERE c.typeFk IN ('normal','handMaking','internalUse') + AND ( + t.shipped BETWEEN vn.VN_CURDATE() AND vEndingDate + OR ( + ts.alertLevel < 3 + AND t.shipped >= vStartingDate + AND t.shipped < vn.VN_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 `previousPreparationSticker_get__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `previousPreparationSticker_get__`(vTicketFk INT) -BEGIN - - SELECT t.id ticketFk, - p.code as location, - t.observations, - IF(HOUR(t.shipped), HOUR(t.shipped), HOUR(z.`hour`)) shippingHour, - IF(MINUTE(t.shipped), MINUTE(t.shipped), MINUTE(z.`hour`)) shippingMinute , - i.itemPackingTypeFk , - count(*) items - FROM vn.ticket t - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - -- JOIN vn.itemShelvingStock iss ON iss.itemFk = s.itemFk AND iss.sectorFk = 38 - JOIN vn.saleTracking st ON st.saleFk = s.id - JOIN vn.state ss ON ss.id = st.stateFk - LEFT JOIN vn.zone z ON z.id = t.zoneFk - LEFT JOIN vn.shelving sh ON sh.code = t.id - LEFT JOIN vn.parking p ON p.id = sh.parkingFk - WHERE t.id = vTicketFk - AND ss.code = 'PREVIOUS_PREPARATION' - AND st.isChecked = FALSE - GROUP BY i.itemPackingTypeFk ; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `previousSticker_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -71909,8 +62416,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `previousSticker_get`(vSaleGroupFk INT) BEGIN @@ -71970,290 +62475,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 `printTrolleyLabel` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `printTrolleyLabel`(vTicket INT, vPrinter INT, vReport INT) -BEGIN -/** - * Inserta en la cola de impresion una nueva etiqueta de carro, para el sacador - * - * @param vTicket Numero del ticket - * @param vPrinter Numero de impresora - * @param vReport Numero del informe - **/ - DECLARE vlabelCount INT DEFAULT 0; - DECLARE PRIORITY INT DEFAULT 3; - DECLARE vWorker INT; - DECLARE vShipmentHour VARCHAR(10); - - SELECT getTicketTrolleyLabelCount(vTicket) INTO vLabelCount; - SELECT account.myUser_getId() INTO vWorker; - SELECT CONCAT(getShipmentHour(vTicket),':00') INTO vShipmentHour; - - INSERT INTO printingQueue(printer - , priority - , report - , `text` - , worker - , text2 - , text3) - VALUES (vPrinter - , PRIORITY - , vReport - , vTicket - , vWorker - , vLabelCount - , vShipmentHour); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `prod` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `prod`(vWarehouseFk INT, vScopeDays INT) -proc: BEGIN - - DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,util.dayEnd(util.VN_CURDATE())); - - DECLARE vIsTodayRelative BOOLEAN; - - SELECT isTodayRelative INTO vIsTodayRelative - FROM vn.worker - WHERE userFk = vn.getUser(); - - CALL vn.prepareTicketList(TIMESTAMPADD(DAY,-1,util.VN_CURDATE()), vEndingDate); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - SELECT * FROM tmp.productionTicket; - - CALL vn.prepareClientList(); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketGetProblems; - CREATE TEMPORARY TABLE tmp.ticketGetProblems - (INDEX (ticketFk)) ENGINE = MEMORY - SELECT tt.ticketFk, tt.clientFk, t.warehouseFk, t.shipped - FROM tmp.productionTicket tt - JOIN vn.ticket t ON t.id = tt.ticketFk; - - CALL vn.ticketGetProblems(vIsTodayRelative); - - DROP TEMPORARY TABLE IF EXISTS tmp.productionBuffer; - CREATE TEMPORARY TABLE tmp.productionBuffer - (PRIMARY KEY(ticketFk)) - ENGINE = MEMORY - SELECT tt.ticketFk - , tt.clientFk - , t.warehouseFk - , t.nickname - , t.packages - , IF(HOUR(t.shipped), HOUR(t.shipped), IFNULL(HOUR(zc.hour),HOUR(z.hour))) as HH - , IFNULL(HOUR(zc.hour),HOUR(z.hour)) as Departure - , IF(MINUTE(t.shipped), MINUTE(t.shipped), IFNULL(MINUTE(zc.hour), MINUTE(z.hour))) as mm - , t.routeFk - , IF(am.deliveryMethodFk = 2,z.`id`,0) as zona - , t.nickname addressNickname - , a.postalCode - , a.city - , p.name province - , CONCAT(z.`name`,' ',IFNULL(RIGHT(t.routeFk,3),'')) agency - , am.id agencyModeFk - , 0 AS `lines` - , CAST( 0 AS DECIMAL(5,2)) AS m3 - , CAST( 0 AS DECIMAL(5,2)) AS preparationRate - , "" as problem - , IFNULL(tls.state,2) AS state - , w.code workerCode - , DATE(t.shipped) shipped - , wk.code AS salesPersonCode - , p.id provinceFk - , tls.productionOrder - , ifnull(tls.alertLevel,0) alertLevel - , t.isBoxed as palletized - , rg.deviceId ubicacion - , tlu.lastUpdated - -- , tls.updated lastUpdated - , ifnull(st.graphCategory,0) graphCategory - , pk.code as parking - , 0 AS H - , 0 AS V - , 0 AS F - , 0 AS P - , st.isOk - , ag.isOwn - FROM tmp.productionTicket tt - JOIN vn.ticket t on tt.ticketFk = t.id - LEFT JOIN vn.ticketStateToday tst ON tst.ticket = t.id - LEFT JOIN vn.state st ON st.id = tst.state - LEFT JOIN vn.client c ON c.id = t.clientFk - LEFT JOIN vn.worker wk ON wk.id = c.salesPersonFk - JOIN vn.address a on a.id = t.addressFk - LEFT JOIN vn.province p on p.id = a.provinceFk - JOIN vn.agencyMode am ON am.id = t.agencyModeFk - JOIN vn.agency ag ON ag.id = am.agencyFk - LEFT JOIN vn.ticketState tls on tls.ticket = tt.ticketFk - LEFT JOIN vn.ticketLastUpdated tlu ON tlu.ticketFk = tt.ticketFk - LEFT JOIN vn.worker w on w.id = tls.worker - LEFT JOIN vn.routeGate rg ON rg.routeFk = t.routeFk - LEFT JOIN vn.zone z ON z.id = t.zoneFk - LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk AND date(t.shipped) = zc.dated - LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id - LEFT JOIN vn.parking pk ON pk.id = tp.parkingFk - WHERE t.warehouseFk = vWarehouseFk - AND am.deliveryMethodFk IN (1,2,3); - - ALTER TABLE tmp.productionBuffer - CHANGE COLUMN `problem` `problem` VARCHAR(255), - ADD COLUMN `collectionH` INT, - ADD COLUMN `collectionV` INT, - ADD COLUMN `collectionF` INT, - ADD COLUMN `collectionP` INT; - - -- Líneas y volumen por ticket - UPDATE tmp.productionBuffer pb - JOIN ( - SELECT tt.ticketFk, - COUNT(*) as `lines`, - sum(sv.volume) as m3, - IFNULL(sum(IF(sv.isPicked,sv.volume,0)) / sum(sv.volume),0) as rate - FROM tmp.productionTicket tt - JOIN vn.saleVolume sv on sv.ticketFk = tt.ticketFk - GROUP BY tt.ticketFk - ) m on m.ticketFk = pb.ticketFk - SET pb.`lines` = m.`lines`, - pb.m3 = m.m3, - pb.preparationRate = m.rate; - - DELETE FROM tmp.productionBuffer - WHERE `lines`= 0; - - -- Lineas por linea de encajado - UPDATE tmp.productionBuffer pb - JOIN ( SELECT ticketFk, - sum(sub.H) H, - sum(sub.V) V, - sum(sub.F) F, - sum(sub.P) P - FROM ( - SELECT t.ticketFk, - sum(i.itemPackingTypeFk = 'H') H, - sum(i.itemPackingTypeFk = 'V') V, - sum(i.itemPackingTypeFk = 'F') F, - sum(i.itemPackingTypeFk = 'P') P - FROM tmp.productionTicket t - JOIN vn.sale s ON s.ticketFk = t.ticketFk - JOIN vn.item i ON i.id = s.itemFk - GROUP BY t.ticketFk, i.itemPackingTypeFk) sub - GROUP BY ticketFk - ) sub2 ON sub2.ticketFk = pb.ticketFk - SET pb.H = sub2.H, - pb.V = sub2.V, - pb.F = sub2.F, - pb.P = sub2.P; - - -- Colecciones segun tipo de encajado - UPDATE tmp.productionBuffer pb - JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk - JOIN vn.collection c ON c.id = tc.collectionFk - SET pb.collectionH = c.id - WHERE c.itemPackingTypeFk = 'H' OR ISNULL(c.itemPackingTypeFk); - - UPDATE tmp.productionBuffer pb - JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk - JOIN vn.collection c ON c.id = tc.collectionFk - SET pb.collectionV = c.id - WHERE c.itemPackingTypeFk = 'V' OR ISNULL(c.itemPackingTypeFk); - - UPDATE tmp.productionBuffer pb - JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk - JOIN vn.collection c ON c.id = tc.collectionFk - SET pb.collectionF = c.id - WHERE c.itemPackingTypeFk = 'F' OR ISNULL(c.itemPackingTypeFk); - - UPDATE tmp.productionBuffer pb - JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk - JOIN vn.collection c ON c.id = tc.collectionFk - SET pb.collectionP = c.id - WHERE c.itemPackingTypeFk = 'P' OR ISNULL(c.itemPackingTypeFk); - - -- Cajas - ALTER TABLE tmp.productionBuffer - ADD Cajas DOUBLE DEFAULT NULL; - /* - -- Problemas por ticket - UPDATE tmp.productionBuffer pb - JOIN tmp.ticketProblems tp ON tp.ticketFk = pb.ticketFk - SET pb.problem = CAST(CONCAT( IFNULL(tp.itemShortage,''), - IFNULL(tp.itemDelay,''), - IF(tp.isFreezed,' CONGELADO',''), - IF(tp.risk,' RIESGO',''), - IF(tp.hasTicketRequest, ' COD 100',''), - IF(tp.isTaxDataChecked, '',' FICHA INCOMPLETA'), - IF(tp.componentLack,' COMPONENTES', '') - ) as char(255)); - */ - -- Refresca la caché para el cierre dinámico de agencias - -- CALL cache.departure_timing(vWarehouseFk); -/* - -- Tickets de recogida - REPLACE tmp.productionBuffer( - shipped - , ticketFk - , agency - , clientFk - , addressNickname - , state - , workerCode - , alertLevel - , warehouseFk - ) - SELECT DATE(t.shipped) - , t.id - , am.name - , t.clientFk - , a.nickname - , s.id as state - , w.code - , ifnull(tls.alertLevel,0) alert_level - , vWarehouseFk - FROM vn.ticket t - JOIN vn.address a on a.id = t.addressFk - JOIN vn.agencyMode am ON am.id = t.agencyModeFk - LEFT JOIN vn2008.warehouse_pickup wp ON wp.agency_id = am.id - LEFT JOIN vn.ticketState tls on tls.ticket = t.id - LEFT JOIN vn.state s ON s.id = tls.state - LEFT JOIN vn.worker w on w.id = tls.worker - WHERE t.shipped between TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()) AND util.dayend(TIMESTAMPADD(DAY,-1,util.VN_CURDATE())) - AND wp.warehouse_id = vWarehouseFk; -*/ - DROP TEMPORARY TABLE tmp.productionTicket; - DROP TEMPORARY TABLE tmp.ticket; - DROP TEMPORARY TABLE IF EXISTS tmp.risk; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `productionControl` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -72261,8 +62484,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `productionControl`(vWarehouseFk INT, vScopeDays INT) proc: BEGIN @@ -72276,7 +62497,7 @@ proc: BEGIN * @return Table tmp.productionBuffer */ - DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,util.dayEnd(util.VN_CURDATE())); + DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,util.dayEnd(vn.VN_CURDATE())); DECLARE vIsTodayRelative BOOLEAN; @@ -72284,7 +62505,7 @@ proc: BEGIN FROM vn.worker WHERE userFk = vn.getUser(); - CALL vn.prepareTicketList(TIMESTAMPADD(DAY,-1,util.VN_CURDATE()), vEndingDate); + CALL vn.prepareTicketList(TIMESTAMPADD(DAY,-1,vn.VN_CURDATE()), vEndingDate); DROP TEMPORARY TABLE IF EXISTS tmp.ticket; CREATE TEMPORARY TABLE tmp.ticket @@ -72381,7 +62602,7 @@ proc: BEGIN IF(tp.hasTicketRequest, ' COD 100',''), IF(tp.isTaxDataChecked, '',' FICHA INCOMPLETA'), IF(tp.hasComponentLack,' COMPONENTES', ''), - IF(HOUR(util.VN_NOW()) < pb.HH AND tp.isTooLittle,' PEQUEÑO', '') + IF(HOUR(vn.VN_NOW()) < pb.HH AND tp.isTooLittle,' PEQUEÑO', '') ) as char(255))); -- Clientes Nuevos o Recuperados @@ -72450,7 +62671,7 @@ proc: BEGIN salesInParkingCount INT DEFAULT 0) ENGINE = MEMORY; - -- Insertamos todos los tickets que tienen productos parkineados en sectores de previa, segun el sector +-- Insertamos todos los tickets que tienen productos parkineados en sectores de previa, segun el sector INSERT INTO tmp.ticketWithPrevia(ticketFk, salesCount) SELECT pb.ticketFk, COUNT(DISTINCT s.id) FROM tmp.productionBuffer pb @@ -72460,7 +62681,7 @@ proc: BEGIN JOIN vn.item i ON i.id = iss.itemFk WHERE iss.isPreviousPrepared AND (ISNULL(sc.itemPackingTypeFk) - OR ISNULL(i.itemPackingTypeFk) + OR (ISNULL(i.itemPackingTypeFk) AND NOT pb.V) OR sc.itemPackingTypeFk = i.itemPackingTypeFk ) GROUP BY pb.ticketFk; @@ -72481,42 +62702,6 @@ proc: BEGIN SET pb.previousWithoutParking = TRUE WHERE twp.salesCount > twp.salesInParkingCount; -/* - -- Refresca la caché para el cierre dinámico de agencias - CALL cache.departure_timing(vWarehouseFk); - - -- Tickets de recogida - REPLACE tmp.productionBuffer( - shipped - , ticketFk - , agency - , clientFk - , addressNickname - , state - , workerCode - , alertLevel - , warehouseFk - ) - SELECT DATE(t.shipped) - , t.id - , am.name - , t.clientFk - , a.nickname - , s.id as state - , w.code - , ifnull(tls.alertLevel,0) alert_level - , vWarehouseFk - FROM vn.ticket t - JOIN vn.address a on a.id = t.addressFk - JOIN vn.agencyMode am ON am.id = t.agencyModeFk - LEFT JOIN vn2008.warehouse_pickup wp ON wp.agency_id = am.id - LEFT JOIN vn.ticketState tls on tls.ticket = t.id - LEFT JOIN vn.state s ON s.id = tls.state - LEFT JOIN vn.worker w on w.id = tls.worker - WHERE t.shipped between TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()) AND util.dayend(TIMESTAMPADD(DAY,-1,util.VN_CURDATE())) - AND wp.warehouse_id = vWarehouseFk; -*/ - DROP TEMPORARY TABLE tmp.productionTicket; DROP TEMPORARY TABLE tmp.ticket; DROP TEMPORARY TABLE tmp.risk; @@ -72529,282 +62714,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 `productionControl__` */; -/*!50003 SET @saved_cs_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 = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `productionControl__`(vWarehouseFk INT, vScopeDays INT) -proc: BEGIN - - /** - * Devuelve un listado de tickets con parámetros relativos a la producción de los días en rango - * - * @param vWarehouseFk Identificador de vn.warehouse - * @param vScopeDays Número de días desde hoy en adelante que entran en el cálculo. - * - * @return Table tmp.productionBuffer - */ - - DECLARE vEndingDate DATETIME DEFAULT TIMESTAMPADD(DAY,vScopeDays,util.dayEnd(util.VN_CURDATE())); - - DECLARE vIsTodayRelative BOOLEAN; - - SELECT isTodayRelative INTO vIsTodayRelative - FROM vn.worker - WHERE userFk = vn.getUser(); - - CALL vn.prepareTicketList(TIMESTAMPADD(DAY,-1,util.VN_CURDATE()), vEndingDate); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - SELECT * FROM tmp.productionTicket; - - CALL vn.prepareClientList(); - - DROP TEMPORARY TABLE IF EXISTS tmp.sale_getProblems; - CREATE TEMPORARY TABLE tmp.sale_getProblems - (INDEX (ticketFk)) ENGINE = MEMORY - SELECT tt.ticketFk, tt.clientFk, t.warehouseFk, t.shipped - FROM tmp.productionTicket tt - JOIN vn.ticket t ON t.id = tt.ticketFk; - - CALL vn.ticket_getProblems(vIsTodayRelative); - - DROP TEMPORARY TABLE IF EXISTS tmp.productionBuffer; - CREATE TEMPORARY TABLE tmp.productionBuffer - (PRIMARY KEY(ticketFk)) - ENGINE = MEMORY - SELECT tt.ticketFk - , tt.clientFk - , t.warehouseFk - , t.nickname - , t.packages - , IF(HOUR(t.shipped), HOUR(t.shipped), IFNULL(HOUR(zc.hour),HOUR(z.hour))) as HH - , IFNULL(HOUR(zc.hour),HOUR(z.hour)) as Departure - , IF(MINUTE(t.shipped), MINUTE(t.shipped), IFNULL(MINUTE(zc.hour), MINUTE(z.hour))) as mm - , t.routeFk - , IF(am.deliveryMethodFk = 2,z.`id`,0) as zona - , t.nickname addressNickname - , a.postalCode - , a.city - , p.name province - , CONCAT(z.`name`,' ',IFNULL(RIGHT(t.routeFk,3),'')) agency - , am.id agencyModeFk - , 0 AS `lines` - , CAST( 0 AS DECIMAL(5,2)) AS m3 - , CAST( 0 AS DECIMAL(5,2)) AS preparationRate - , "" as problem - , IFNULL(tls.state,2) AS state - , w.code workerCode - , DATE(t.shipped) shipped - , wk.code AS salesPersonCode - , p.id provinceFk - , tls.productionOrder - , ifnull(tls.alertLevel,0) alertLevel - , t.isBoxed as palletized - , IF(rm.isPickingAllowed ,rm.bufferFk, NULL) ubicacion - , tlu.lastUpdated - , ifnull(st.graphCategory,0) graphCategory - , pk.code as parking - , 0 AS H - , 0 AS V - , 0 AS N - , st.isOk - , ag.isOwn - FROM tmp.productionTicket tt - JOIN vn.ticket t on tt.ticketFk = t.id - LEFT JOIN vn.ticketStateToday tst ON tst.ticket = t.id - LEFT JOIN vn.state st ON st.id = tst.state - LEFT JOIN vn.client c ON c.id = t.clientFk - LEFT JOIN vn.worker wk ON wk.id = c.salesPersonFk - JOIN vn.address a on a.id = t.addressFk - LEFT JOIN vn.province p on p.id = a.provinceFk - JOIN vn.agencyMode am ON am.id = t.agencyModeFk - JOIN vn.agency ag ON ag.id = am.agencyFk - LEFT JOIN vn.ticketState tls on tls.ticket = tt.ticketFk - LEFT JOIN vn.ticketLastUpdated tlu ON tlu.ticketFk = tt.ticketFk - LEFT JOIN vn.worker w on w.id = tls.worker - LEFT JOIN vn.routesMonitor rm ON rm.routeFk = t.routeFk - LEFT JOIN vn.zone z ON z.id = t.zoneFk - LEFT JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk AND date(t.shipped) = zc.dated - LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id - LEFT JOIN vn.parking pk ON pk.id = tp.parkingFk - WHERE t.warehouseFk = vWarehouseFk - AND am.deliveryMethodFk IN (1,2,3); - - -- Problemas por ticket - ALTER TABLE tmp.productionBuffer - CHANGE COLUMN `problem` `problem` VARCHAR(255), - ADD COLUMN `collectionH` INT, - ADD COLUMN `collectionV` INT; - - UPDATE tmp.productionBuffer pb - JOIN tmp.ticket_problems tp ON tp.ticketFk = pb.ticketFk - SET pb.problem = TRIM(CAST(CONCAT( IFNULL(tp.itemShortage,''), - IFNULL(tp.itemDelay,''), - IF(tp.isFreezed,' CONGELADO',''), - IF(tp.hasHighRisk,' RIESGO',''), - IF(tp.hasTicketRequest, ' COD 100',''), - IF(tp.isTaxDataChecked, '',' FICHA INCOMPLETA'), - IF(tp.hasComponentLack,' COMPONENTES', ''), - IF(HOUR(util.VN_NOW()) < pb.HH AND tp.isTooLittle,' PEQUEÑO', '') - ) as char(255))); - - -- Clientes Nuevos o Recuperados - UPDATE tmp.productionBuffer pb - LEFT JOIN bs.clientNewBorn cnb ON cnb.clientFk = pb.clientFk - SET pb.problem = TRIM(CAST(CONCAT('NUEVO ', pb.problem) AS CHAR(255))) - WHERE ISNULL(cnb.clientFk) OR cnb.isRookie ; - - -- Líneas y volumen por ticket - UPDATE tmp.productionBuffer pb - JOIN ( - SELECT tt.ticketFk, - COUNT(*) as `lines`, - sum(sv.volume) as m3, - IFNULL(sum(IF(sv.isPicked,sv.volume,0)) / sum(sv.volume),0) as rate - FROM tmp.productionTicket tt - JOIN vn.saleVolume sv on sv.ticketFk = tt.ticketFk - GROUP BY tt.ticketFk - ) m on m.ticketFk = pb.ticketFk - SET pb.`lines` = m.`lines`, - pb.m3 = m.m3, - pb.preparationRate = m.rate; - - DELETE FROM tmp.productionBuffer - WHERE `lines`= 0; - - -- Lineas por linea de encajado - UPDATE tmp.productionBuffer pb - JOIN ( SELECT ticketFk, - sum(sub.H) H, - sum(sub.V) V, - sum(sub.N) N - FROM ( - SELECT t.ticketFk, - sum(i.itemPackingTypeFk = 'H') H, - sum(i.itemPackingTypeFk = 'V') V, - sum(ISNULL(i.itemPackingTypeFk)) N - FROM tmp.productionTicket t - JOIN vn.sale s ON s.ticketFk = t.ticketFk - JOIN vn.item i ON i.id = s.itemFk - GROUP BY t.ticketFk, i.itemPackingTypeFk) sub - GROUP BY ticketFk - ) sub2 ON sub2.ticketFk = pb.ticketFk - SET pb.H = sub2.H, - pb.V = sub2.V, - pb.N = sub2.N; - - -- Colecciones segun tipo de encajado - UPDATE tmp.productionBuffer pb - JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk - JOIN vn.collection c ON c.id = tc.collectionFk - SET pb.collectionH = c.id - WHERE (c.itemPackingTypeFk = 'H' OR ISNULL(c.itemPackingTypeFk)) - AND pb.H; - - UPDATE tmp.productionBuffer pb - JOIN vn.ticketCollection tc ON pb.ticketFk = tc.ticketFk - JOIN vn.collection c ON c.id = tc.collectionFk - SET pb.collectionV = c.id - WHERE (c.itemPackingTypeFk = 'V' OR ISNULL(c.itemPackingTypeFk)) - AND pb.V; - - -- Previa pendiente - ALTER TABLE tmp.productionBuffer - ADD previousWithoutParking BOOL DEFAULT FALSE; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketWithPrevia; - CREATE TEMPORARY TABLE tmp.ticketWithPrevia - (ticketFk INT PRIMARY KEY, - salesCount INT DEFAULT 0, - salesInParkingCount INT DEFAULT 0) - ENGINE = MEMORY; - - -- Insertamos todos los tickets que tienen productos parkineados en sectores de previa, segun el sector - INSERT INTO tmp.ticketWithPrevia(ticketFk, salesCount) - SELECT pb.ticketFk, COUNT(DISTINCT s.id) - FROM tmp.productionBuffer pb - JOIN vn.sale s ON s.ticketFk = pb.ticketFk - JOIN vn.itemShelvingStock iss ON iss.itemFk = s.itemFk - JOIN vn.sector sc ON sc.id = iss.sectorFk - JOIN vn.item i ON i.id = iss.itemFk - WHERE iss.isPreviousPrepared - AND (ISNULL(sc.itemPackingTypeFk) - OR ISNULL(i.itemPackingTypeFk) - OR sc.itemPackingTypeFk = i.itemPackingTypeFk ) - GROUP BY pb.ticketFk; - - -- Se calcula la cantidad de productos que estan ya preparados porque su saleGroup está aparcado - UPDATE tmp.ticketWithPrevia twp - JOIN ( SELECT pb.ticketFk, count(DISTINCT s.id) salesInParkingCount - FROM tmp.productionBuffer pb - JOIN vn.sale s ON s.ticketFk = pb.ticketFk - JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id - JOIN vn.saleGroup sg ON sg.id = sgd.saleGroupFk - WHERE NOT ISNULL(sg.parkingFk) - GROUP BY pb.ticketFk ) sub ON twp.ticketFk = sub.ticketFk - SET twp.salesInParkingCount = sub.salesInParkingCount; - - -- Marcamos como pendientes aquellos que no coinciden las cantidades - UPDATE tmp.productionBuffer pb - JOIN tmp.ticketWithPrevia twp ON twp.ticketFk = pb.ticketFk - SET pb.previousWithoutParking = TRUE - WHERE twp.salesCount > twp.salesInParkingCount; - -/* - -- Refresca la caché para el cierre dinámico de agencias - CALL cache.departure_timing(vWarehouseFk); - - -- Tickets de recogida - REPLACE tmp.productionBuffer( - shipped - , ticketFk - , agency - , clientFk - , addressNickname - , state - , workerCode - , alertLevel - , warehouseFk - ) - SELECT DATE(t.shipped) - , t.id - , am.name - , t.clientFk - , a.nickname - , s.id as state - , w.code - , ifnull(tls.alertLevel,0) alert_level - , vWarehouseFk - FROM vn.ticket t - JOIN vn.address a on a.id = t.addressFk - JOIN vn.agencyMode am ON am.id = t.agencyModeFk - LEFT JOIN vn2008.warehouse_pickup wp ON wp.agency_id = am.id - LEFT JOIN vn.ticketState tls on tls.ticket = t.id - LEFT JOIN vn.state s ON s.id = tls.state - LEFT JOIN vn.worker w on w.id = tls.worker - WHERE t.shipped between TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()) AND util.dayend(TIMESTAMPADD(DAY,-1,util.VN_CURDATE())) - AND wp.warehouse_id = vWarehouseFk; -*/ - DROP TEMPORARY TABLE tmp.productionTicket; - DROP TEMPORARY TABLE tmp.ticket; - DROP TEMPORARY TABLE tmp.risk; - DROP TEMPORARY TABLE tmp.ticket_problems; - DROP TEMPORARY TABLE tmp.ticketWithPrevia; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!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 sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `productionSectorList` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -72812,8 +62723,6 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `productionSectorList`(vSectorFk INT) BEGIN @@ -72837,7 +62746,7 @@ BEGIN FROM vn.sale s JOIN vn.item i ON i.id = s.itemFk JOIN vn.ticket t ON t.id = s.ticketFk - WHERE t.shipped BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(HOUR, 23, util.VN_CURDATE()) + WHERE t.shipped BETWEEN vn.VN_CURDATE() AND TIMESTAMPADD(HOUR, 23, vn.VN_CURDATE()) GROUP BY s.ticketFk HAVING saleNum = iptNull; @@ -72849,7 +62758,7 @@ BEGIN JOIN vn.item i ON i.id = s.itemFk JOIN vn.ticket t ON t.id = s.ticketFk JOIN vn.sector sc ON sc.id = vSectorFk - WHERE t.shipped BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(HOUR, 23, util.VN_CURDATE()) + WHERE t.shipped BETWEEN vn.VN_CURDATE() AND TIMESTAMPADD(HOUR, 23, vn.VN_CURDATE()) GROUP BY s.ticketFk HAVING iptSector; @@ -72931,6 +62840,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `rangeDateInfo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -72938,8 +62849,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `rangeDateInfo`(vStarted DATE, vEnded DATE) BEGIN @@ -72981,6 +62890,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `rankingTeamByQuarter` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -72988,8 +62899,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `rankingTeamByQuarter`(vYear INT, vQuarter INT) BEGIN @@ -73046,7 +62955,7 @@ BEGIN AND d.name LIKE 'EQUIPO%' AND CEIL(v.mes / 3) = vQuarter GROUP BY wd.departmentFk - ORDER BY SUM(v.importe) DESC) sub2 ON (sub1.name = sub2.name)) + ORDER BY SUM(v.importe) DESC LIMIT 10000000000000000000) sub2 ON (sub1.name = sub2.name)) JOIN (SELECT COUNT(0) AS countPeople, wd.departmentFk AS departmentFk FROM @@ -73062,6 +62971,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `rate_getPrices` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -73069,8 +62980,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `rate_getPrices`(vDated DATE, vWarehouseFk INT) BEGIN @@ -73106,6 +63015,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `rate_getPrices2` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -73113,8 +63024,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `rate_getPrices2`(vLanded DATE, vWarehouseFk INT) BEGIN @@ -73145,47 +63054,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 `rate_getPrices__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `rate_getPrices__`(vLanded DATE, vWarehouseFk INT) -BEGIN - - -- Prepara una tabla con las tarifas aplicables en funcion de la fecha y el almacén - - DROP TEMPORARY TABLE IF EXISTS tmp.rate; - CREATE TEMPORARY TABLE tmp.rate - ENGINE = MEMORY - SELECT * FROM - ( - SELECT * FROM - ( - SELECT DISTINCT rate0, rate1, rate2, rate3 - FROM vn.rate - WHERE dated <= vLanded - AND warehouseFk = vWarehouseFk - ORDER BY dated DESC - - ) sub - UNION ALL - SELECT rate0, rate1, rate2, rate3 - FROM rateConfig - ) sub2 - LIMIT 1; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `recipe_Cook` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -73193,8 +63063,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `recipe_Cook`(vItemFk INT, vBunchesQuantity INT, vDate DATE) BEGIN @@ -73273,6 +63141,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `recipe_Plaster` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -73280,8 +63150,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `recipe_Plaster`(vItemFk INT, vTicketFk INT, vQuantity INT) BEGIN @@ -73370,6 +63238,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `refund` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -73377,8 +63247,6 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `refund`(IN vOriginTicket INT, OUT vNewTicket INT) BEGIN @@ -73430,13 +63298,13 @@ BEGIN ) SELECT vCustomer, - util.VN_CURDATE(), + vn.VN_CURDATE(), vAddress, vRefundAgencyMode, a.nickname, vWarehouse, vCompany, - util.VN_CURDATE(), + vn.VN_CURDATE(), vZoneFk FROM address a WHERE a.id = vAddress; @@ -73470,6 +63338,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `replaceMovimientosMark` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -73477,8 +63347,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `replaceMovimientosMark`( idMovimiento INT, @@ -73509,6 +63377,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `reportLabelCollection_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -73516,62 +63386,61 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `reportLabelCollection_get`(vParam INT) -BEGIN -/** - * Obtiene los datos de etiquetas a partir de de un ticket o colección. - * - * @param vParam Ticket/Colección del que sacar los datos - */ - DECLARE vIsTicket BOOL; - - SELECT IF(id, TRUE, FALSE) INTO vIsTicket - FROM ticket - WHERE created > (CURRENT_DATE() - INTERVAL 1 MONTH) - AND id = vParam; - - SELECT c.itemPackingTypeFk, - CONCAT(tc.collectionFk, ' ', LEFT(cc.code, 4)) color, - CONCAT(tc.collectionFk, ' ', SUBSTRING('ABCDEFGH',tc.wagon, 1), '-', tc.`level`) levelV, - tc.ticketFk, - LEFT(IF(t.routeFk IS NULL, am.name, zo.name ), 12) agencyDescription, - am.name, - t.clientFk, - CONCAT(CAST(SUM(sv.volume) AS DECIMAL(5, 2)), 'm³') m3 , - CAST(IF(ic.code = 'plant', CONCAT(MAX(i.`size`),' cm'), COUNT(*)) AS CHAR) size, - w.code workerCode, - tt.labelCount, - IF(HOUR(t.shipped), TIME(t.shipped), TIME(zo.`hour`)) agencyHour, - t.shipped, - COUNT(*) lineCount, - t.nickName - FROM ticket t - JOIN ticketCollection tc ON tc.ticketFk = t.id - JOIN collection c ON c.id = tc.collectionFk - JOIN collectionColors cc ON cc.shelve = tc.`level` - AND cc.wagon = tc.wagon - AND cc.trainFk = c.trainFk - JOIN sale s ON s.ticketFk = t.id - LEFT JOIN saleVolume sv ON sv.saleFk = s.id - JOIN item i ON i.id = s.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN itemCategory ic ON ic.id = it.categoryFk - JOIN worker w ON w.id = c.workerFk - JOIN agencyMode am ON am.id = t.agencyModeFk - LEFT JOIN ticketTrolley tt ON tt.ticket = t.id - LEFT JOIN `zone` zo ON t.zoneFk = zo.id - WHERE IF(vIsTicket, tc.ticketFk = vParam, tc.collectionFk = vParam) - GROUP BY t.id - ORDER BY cc.`code`; +BEGIN +/** + * Obtiene los datos de etiquetas a partir de de un ticket o colección. + * + * @param vParam Ticket/Colección del que sacar los datos + */ + DECLARE vIsCollection BOOL; + + SELECT IF(id, TRUE, FALSE) INTO vIsCollection + FROM vn.collection c + WHERE id = vParam; + + SELECT c.itemPackingTypeFk, + CONCAT(tc.collectionFk, ' ', LEFT(cc.code, 4)) color, + CONCAT(tc.collectionFk, ' ', SUBSTRING('ABCDEFGH',tc.wagon, 1), '-', tc.`level`) levelV, + tc.ticketFk, + LEFT(IF(t.routeFk IS NULL, am.name, zo.name ), 12) agencyDescription, + am.name, + t.clientFk, + CONCAT(CAST(SUM(sv.volume) AS DECIMAL(5, 2)), 'm³') m3 , + CAST(IF(ic.code = 'plant', CONCAT(MAX(i.`size`),' cm'), COUNT(*)) AS CHAR) size, + w.code workerCode, + tt.labelCount, + IF(HOUR(t.shipped), TIME(t.shipped), TIME(zo.`hour`)) agencyHour, + t.shipped, + COUNT(*) lineCount, + t.nickName + FROM ticket t + JOIN ticketCollection tc ON tc.ticketFk = t.id + JOIN collection c ON c.id = tc.collectionFk + JOIN collectionColors cc ON cc.shelve = tc.`level` + AND cc.wagon = tc.wagon + AND cc.trainFk = c.trainFk + JOIN sale s ON s.ticketFk = t.id + LEFT JOIN saleVolume sv ON sv.saleFk = s.id + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN itemCategory ic ON ic.id = it.categoryFk + JOIN worker w ON w.id = c.workerFk + JOIN agencyMode am ON am.id = t.agencyModeFk + LEFT JOIN ticketTrolley tt ON tt.ticket = t.id + LEFT JOIN `zone` zo ON t.zoneFk = zo.id + WHERE IF(vIsCollection, tc.collectionFk = vParam, tc.ticketFk = vParam) + GROUP BY t.id + ORDER BY cc.`code`; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `riskAllClients` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -73579,8 +63448,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `riskAllClients`(maxRiskDate DATE) BEGIN @@ -73614,134 +63481,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 `routeGateAsign__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `routeGateAsign__`(vDevice VARCHAR(30), vRouteFk INT) -BEGIN - /* - UPDATE routeGate - SET displayText = NULL, - routeFk = NULL, - freeTickets = NULL, - expeditions = NULL, - scanned = NULL, - flag = NULL, - pallets = NULL, - lastScanned = NULL - WHERE routeFk = vRouteFk; - */ - IF ISNULL(vDevice) THEN - - DELETE FROM routeGate - WHERE routeFk = vRouteFk; - - ELSE - - REPLACE routeGate(routeFk, deviceId) - VALUES(vRouteFk, vDevice); - - END IF; - /* - UPDATE vn.route r - JOIN vn.beach b ON b.name = vDevice - SET r.beachFk = b.id - WHERE r.id = vRouteFk; - */ -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `routeGateUpdate` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `routeGateUpdate`() -BEGIN - - UPDATE vn.routeGate rg - LEFT JOIN vn.routesControl rc ON rg.routeFk = rc.routeFk - LEFT JOIN vn.route r ON r.id = rg.routeFk - LEFT JOIN vn.agencyMode a ON a.id = r.agencyModeFk - LEFT JOIN - ( - SELECT Id_Ruta, count(*) AS pedidosLibres - FROM vn2008.Tickets t - JOIN vn2008.Tickets_state ts ON t.Id_Ticket = ts.Id_Ticket - JOIN vncontrol.inter i ON i.inter_id = ts.inter_id - JOIN vn2008.state s ON i.state_id = s.id AND s.alert_level < 2 - WHERE t.Fecha BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) - AND t.warehouse_id IN (1,44) - AND Id_Ruta - GROUP BY Id_Ruta - ) t ON t.Id_Ruta = rg.routeFk - SET rg.scanned = rc.scanned, - rg.expeditions = rc.expeditions, - rg.flag = a.flag, - rg.freeTickets = t.pedidosLibres, - rg.pallets = rc.pallets, - rg.lastScanned = rc.lastScanned, - rg.displayText = IF(rg.routeFk is null, rg.displayText, rg.routeFk MOD 1000), - rg.ready = IF(rg.freeTickets, FALSE, rg.ready); - - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `routeGate_assignDevice` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `routeGate_assignDevice`(vDevice VARCHAR(30), vRouteFk INT) -BEGIN -/** - * Asigna el dispositivo la ruta - * - * @param vDevice Dispositivo a remplazar - * @param vRouteFk Ruta a la cual asignarlo - */ - IF ISNULL(vDevice) THEN - - DELETE FROM routeGate - WHERE routeFk = vRouteFk; - - ELSE - - REPLACE routeGate(routeFk, deviceId) - VALUES(vRouteFk, vDevice); - - 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 `routeGuessPriority` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -73749,8 +63490,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `routeGuessPriority`(IN vRuta INT) BEGIN @@ -73763,7 +63502,7 @@ UPDATE ticket mt SELECT tt.addressFk, ROUND(IFNULL(AVG(t.priority),0),0) AS priority FROM ticket t JOIN ticket tt ON tt.addressFk = t.addressFk - WHERE t.shipped > TIMESTAMPADD(YEAR,-1,util.VN_CURDATE()) + WHERE t.shipped > TIMESTAMPADD(YEAR,-1,vn.VN_CURDATE()) AND tt.routeFk = vRuta GROUP BY addressFk ) sub ON sub.addressFk = mt.addressFk @@ -73775,6 +63514,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `routeInfo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -73782,8 +63523,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `routeInfo`(vRouteFk INT) BEGIN @@ -73821,6 +63560,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `routeMonitor_calculate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -73828,8 +63569,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `routeMonitor_calculate`(vDate DATE) BEGIN @@ -73934,6 +63673,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `routeSetOk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -73941,8 +63682,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `routeSetOk`( vRouteFk INT) @@ -73958,6 +63697,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `routeUpdateM3` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -73965,8 +63706,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `routeUpdateM3`(vRoute INT) BEGIN @@ -73980,6 +63719,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `route_doRecalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -73987,8 +63728,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `route_doRecalc`() proc: BEGIN @@ -74041,6 +63780,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `route_getTickets` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74048,74 +63789,74 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `route_getTickets`(vRouteFk INT) -BEGIN -/** - * Pasado un RouteFk devuelve la información - * de sus tickets. - * - * @param vRouteFk - * - * @select Información de los tickets - */ - - SELECT - t.id AS Id, - t.clientFk AS Client, - a.id AS Address, - a.nickname AS ClientName, - t.packages AS Packages, - a.street AS AddressName, - a.postalCode AS PostalCode, - a.city AS City, - sub2.itemPackingTypeFk AS PackingType, - c.phone AS ClientPhone, - c.mobile AS ClientMobile, - a.phone AS AddressPhone, - a.mobile AS AddressMobile, - tl.longitude AS Longitude, - tl.latitude AS Latitude, - wm.mediaValue AS SalePersonPhone, - tob.Note AS Note, - t.isSigned AS Signed, - st.id AS Polizon - FROM ticket t - JOIN client c ON t.clientFk = c.id - JOIN address a ON t.addressFk = a.id - LEFT JOIN ticketLocation tl ON tl.ticketFk = t.id - LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk - LEFT JOIN - (SELECT tob.description AS Note, t.id - FROM ticketObservation tob - JOIN ticket t ON tob.ticketFk = t.id - JOIN observationType ot ON ot.id = tob.observationTypeFk - WHERE t.routeFk = vRouteFk - AND ot.code = 'delivery' - )tob ON tob.id = t.id - LEFT JOIN stowaway st ON st.shipFk = t.id - LEFT JOIN - (SELECT sub.ticketFk, - CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk - FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN item i ON i.id = s.itemFk - WHERE t.routeFk = vRouteFk - GROUP BY t.id,i.itemPackingTypeFk)sub - GROUP BY sub.ticketFk - ) sub2 ON sub2.ticketFk = t.id - WHERE t.routeFk = vRouteFk - GROUP BY t.id - ORDER BY t.priority; +BEGIN +/** + * Pasado un RouteFk devuelve la información + * de sus tickets. + * + * @param vRouteFk + * + * @select Información de los tickets + */ + + SELECT + t.id AS Id, + t.clientFk AS Client, + a.id AS Address, + a.nickname AS ClientName, + t.packages AS Packages, + a.street AS AddressName, + a.postalCode AS PostalCode, + a.city AS City, + sub2.itemPackingTypeFk AS PackingType, + c.phone AS ClientPhone, + c.mobile AS ClientMobile, + a.phone AS AddressPhone, + a.mobile AS AddressMobile, + tl.longitude AS Longitude, + tl.latitude AS Latitude, + wm.mediaValue AS SalePersonPhone, + tob.Note AS Note, + t.isSigned AS Signed, + st.id AS Polizon + FROM ticket t + JOIN client c ON t.clientFk = c.id + JOIN address a ON t.addressFk = a.id + LEFT JOIN ticketLocation tl ON tl.ticketFk = t.id + LEFT JOIN workerMedia wm ON wm.workerFk = c.salesPersonFk + LEFT JOIN + (SELECT tob.description AS Note, t.id + FROM ticketObservation tob + JOIN ticket t ON tob.ticketFk = t.id + JOIN observationType ot ON ot.id = tob.observationTypeFk + WHERE t.routeFk = vRouteFk + AND ot.code = 'delivery' + )tob ON tob.id = t.id + LEFT JOIN stowaway st ON st.shipFk = t.id + LEFT JOIN + (SELECT sub.ticketFk, + CONCAT('(', GROUP_CONCAT(DISTINCT sub.itemPackingTypeFk ORDER BY sub.items DESC SEPARATOR ','), ') ') itemPackingTypeFk + FROM (SELECT s.ticketFk , i.itemPackingTypeFk, COUNT(*) items + FROM ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN item i ON i.id = s.itemFk + WHERE t.routeFk = vRouteFk + GROUP BY t.id,i.itemPackingTypeFk)sub + GROUP BY sub.ticketFk + ) sub2 ON sub2.ticketFk = t.id + WHERE t.routeFk = vRouteFk + GROUP BY t.id + ORDER BY t.priority; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `route_updateM3` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74123,8 +63864,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `route_updateM3`(vRoute INT) BEGIN @@ -74143,6 +63882,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `rutasAnalyze` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74150,8 +63891,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `rutasAnalyze`(vYear INT, vMonth INT) BEGIN @@ -74321,6 +64060,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `saleBuy_Add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74328,38 +64069,38 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleBuy_Add`(vSaleFk INT, vBuyFk INT) -BEGIN - - /* Añade un registro a la tabla saleBuy en el caso de que sea posible mantener la trazabilidad - * - * @param vSaleFk clave primaria de vn.sale - * @param vBuyFk clave primaria de vn.buy - */ - /*IF (SELECT COUNT(*) - FROM vn.sale s - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - WHERE s.id = vSaleFk - AND ic.code = 'fruit') THEN */ - - IF (SELECT COUNT(*) FROM vn.buy WHERE id = vBuyFk AND itemOriginalFk) THEN - - INSERT INTO vn.saleBuy (saleFk, buyFk) - VALUES(vSaleFk, vBuyFk); - - END IF; - +BEGIN + + /* Añade un registro a la tabla saleBuy en el caso de que sea posible mantener la trazabilidad + * + * @param vSaleFk clave primaria de vn.sale + * @param vBuyFk clave primaria de vn.buy + */ + /*IF (SELECT COUNT(*) + FROM vn.sale s + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + WHERE s.id = vSaleFk + AND ic.code = 'fruit') THEN */ + + IF (SELECT COUNT(*) FROM vn.buy WHERE id = vBuyFk AND itemOriginalFk) THEN + + INSERT INTO vn.saleBuy (saleFk, buyFk) + VALUES(vSaleFk, vBuyFk); + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `saleGroup_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74367,178 +64108,50 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleGroup_add`(vSectorFk INT) -BEGIN -/** - * Añade un nuevo registro a la tabla y devuelve su id. - * - * @param vSectorFk Identificador de vn.sector - */ - INSERT INTO vn.saleGroup(userFk, sectorFk) - VALUES (account.myUser_getId(), vSectorFk); - - SELECT LAST_INSERT_ID(); +BEGIN +/** + * Añade un nuevo registro a la tabla y devuelve su id. + * + * @param vSectorFk Identificador de vn.sector + */ + INSERT INTO vn.saleGroup(userFk, sectorFk) + VALUES (account.myUser_getId(), vSectorFk); + + SELECT LAST_INSERT_ID(); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `saleItemShelvingDelete__` */; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `saleGroup_setParking` */; /*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `saleItemShelvingDelete__`(vSaleFk INT) -BEGIN +CREATE DEFINER=`root`@`localhost` PROCEDURE `saleGroup_setParking`(IN `vSaleGroupFk` VARCHAR(8), IN `vParkingFk` INT) +proc: BEGIN + UPDATE vn.saleGroup sg + SET sg.parkingFk = vParkingFk + WHERE sg.id = vSaleGroupFk + AND sg.created >= TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()); - UPDATE vn.itemShelving ish - JOIN vn.saleItemShelving sis ON sis.itemShelvingFk = ish.id - SET ish.visible = sis.quantity + ish.visible, - ish.available = sis.quantity + ish.visible - WHERE sis.saleFk = vSaleFk; - - DELETE FROM vn.saleItemShelving - WHERE saleFk = vSaleFk; - + CALL vn.ticket_setNextState(vn.ticket_get(vSaleGroupFk)); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `saleItemShelvingIsPicked__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `saleItemShelvingIsPicked__`(vTicketFk INT, vIsPicked BOOL) -BEGIN - - DECLARE vStateFk INT; - - SELECT id INTO vStateFk - FROM state - WHERE code = 'PREVIOUS_PREPARATION'; - - UPDATE vn.sale s - JOIN vn.saleItemShelving sis ON sis.saleFk = s.id - SET s.isPicked = vIsPicked - WHERE s.ticketFk = vTicketFk; - - REPLACE vn2008.Movimientos_mark(Id_Movimiento, Valor, original_quantity, Id_Trabajador, stateFk) - SELECT s.id, s.isPicked, s.quantity, account.myUser_getId(), vStateFk - FROM sale s - JOIN vn.saleItemShelving sis ON sis.saleFk = s.id - WHERE s.ticketFk = vTicketFk; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `saleItemShelvingMake__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `saleItemShelvingMake__`(IN `vTicketFk` INT, IN `vSectorFk` INT) -BEGIN - - SET @rest:= CAST(0 AS DECIMAL(10,0)); - SET @saleFk := CAST(0 AS DECIMAL(10,0)); - SET @reserved := CAST(0 AS DECIMAL(10,0)); - - UPDATE vn.itemShelving ish - JOIN vn.saleItemShelving sis ON sis.itemShelvingFk = ish.id - JOIN sale s ON s.id = sis.saleFk - SET ish.visible = sis.quantity + ish.visible, - ish.available = sis.quantity + ish.visible - WHERE s.ticketFk = vTicketFk; - - DELETE sis.* - FROM saleItemShelving sis - JOIN sale s ON s.id = sis.saleFk - WHERE s.ticketFk = vTicketFk; - - INSERT INTO saleItemShelving( saleFk, - itemShelvingFk, - quantity, - ubication) - SELECT saleFk, - itemShelvingFk, - CAST(Reserved as DECIMAL(10,0)) as Reserved, - ubication - FROM - (SELECT saleFk, - itemShelvingFk, - ubication, - @rest := IF(@saleFk = saleFk, @rest, quantity) as Falta, - @reserved := IF(available < @rest, available, IF(@rest < packing,0,@rest)) as Reserved, - @rest := @rest - @reserved, - @saleFk := saleFk - FROM - ( SELECT s.id as saleFk, - ish.created, - ish.id as itemShelvingFk, - ish.available, - s.quantity, - ish.packing, - CONCAT(p.`column`, '-',p.`row`,': ', sh.code ) as ubication - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.sector sc ON sc.warehouseFk = t.warehouseFk - JOIN vn.parking p ON p.sectorFk = sc.id - JOIN vn.shelving sh ON sh.parkingFk = p.id - JOIN vn.itemShelving ish ON ish.shelvingFk = sh.code AND ish.itemFk = s.itemFk - WHERE t.id = vTicketFk - AND sc.id = vSectorFk - AND s.quantity MOD ish.packing = 0 - AND s.quantity >= ish.packing - ORDER BY s.id, - sh.priority DESC, - ish.packing DESC, - ish.created - ) sub - ) sub2 - WHERE Reserved > 0; - - UPDATE vn.itemShelving ish - JOIN vn.saleItemShelving sis ON sis.itemShelvingFk = ish.id - JOIN vn.sale s ON s.id = sis.saleFk - SET ish.available = ish.visible - sis.quantity, - ish.visible = ish.visible - sis.quantity - WHERE s.ticketFk = vTicketFk - AND s.isPicked = FALSE; - - CALL vn.saleItemShelvingIsPicked(vTicketFk, 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 `saleMistake_Add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74546,8 +64159,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleMistake_Add`(vSaleFk INT, vUserFk INT, vTypeFk INT) BEGIN @@ -74561,6 +64172,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `saleMove` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74568,8 +64181,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleMove`(IN vSaleFk BIGINT, IN vQuantity BIGINT) BEGIN @@ -74652,37 +64263,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 `saleParking_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `saleParking_add__`(vSaleFk INT, vParkingCode VARCHAR(10)) -BEGIN - - /* - * Inserta registro en saleParking - * - * vSaleFk Identificador de vn.sale - * vParkingCode Code de vn.parking - */ - - INSERT INTO vn.saleParking(saleFk, parkingFk, userFk) - SELECT vSaleFk, p.id, account.myUser_getId() - FROM vn.parking p - WHERE p.code = vParkingCode COLLATE utf8_unicode_ci; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `salePreparingList` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74690,59 +64272,52 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `salePreparingList`(IN ticketFk BIGINT) BEGIN -CALL cache.last_buy_refresh(FALSE); + CALL cache.last_buy_refresh(FALSE); - SELECT t.clientFk, + SELECT t.clientFk, t.shipped, - a.nickname, + a.nickname, s.ticketFk, s.itemFk, s.quantity, s.concept, s.reserved, s.id saleFk, - i.size, + i.size, i.inkFk, i.stems, i.image, i.subName, b.`grouping`, - ip.code as placement, - lpad(ifnull(cooler_path_detail_id, ip.code),5,'0') as path, - IF(stPrevious.saleFk,TRUE,FALSE) as isPreviousSelected, + IF(stPrevious.saleFk,TRUE,FALSE) as isPreviousSelected, stPrevious.isChecked as isPrevious, - stPrepared.isChecked as isPrepared, - stControled.isChecked as isControled, - ib.code as barcode - - FROM vn.ticket t - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - LEFT JOIN vn.itemPlacement ip ON i.id = ip.itemFk AND ip.warehouseFk = t.warehouseFk - LEFT JOIN vn2008.cooler_path_detail cpd on left(ip.code,3) = cpd.pasillo - LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = t.warehouseFk - LEFT JOIN vn.buy b ON b.id = lb.buy_id - LEFT JOIN vn.saleTracking stPrevious ON stPrevious.saleFk = s.id AND stPrevious.stateFk = 26 - LEFT JOIN vn.saleTracking stPrepared ON stPrepared.saleFk = s.id AND stPrepared.stateFk = 14 - LEFT JOIN vn.saleTracking stControled ON stControled.saleFk = s.id AND stControled.stateFk = 8 - LEFT JOIN vn.itemBarcode ib ON ib.itemFk = i.id - - WHERE t.id = ticketFk - GROUP BY s.id; - + stPrepared.isChecked as isPrepared, + stControled.isChecked as isControled, + ib.code as barcode + FROM vn.ticket t + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = t.warehouseFk + LEFT JOIN vn.buy b ON b.id = lb.buy_id + LEFT JOIN vn.saleTracking stPrevious ON stPrevious.saleFk = s.id AND stPrevious.stateFk = 26 + LEFT JOIN vn.saleTracking stPrepared ON stPrepared.saleFk = s.id AND stPrepared.stateFk = 14 + LEFT JOIN vn.saleTracking stControled ON stControled.saleFk = s.id AND stControled.stateFk = 8 + LEFT JOIN vn.itemBarcode ib ON ib.itemFk = i.id + WHERE t.id = ticketFk + GROUP BY s.id; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `salesMerge` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74750,8 +64325,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `salesMerge`(vTicketFk INT) BEGIN @@ -74783,6 +64356,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `salesMerge_byCollection` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74790,8 +64365,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `salesMerge_byCollection`(vCollectionFk INT) BEGIN @@ -74833,6 +64406,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `saleSplit` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74840,8 +64415,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleSplit`(vSaleFk INT, vQuantity INT) BEGIN @@ -74889,6 +64462,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `saleTracking_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74896,38 +64471,38 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_add`(vSaleGroupFk INT) -BEGIN - - /* Inserta en vn.saleTracking las lineas de una previa - * - * @param vSaleGroupFk Identificador de vn.saleGroup - */ - - REPLACE vn.saleTracking(saleFk, - isChecked, - workerFk, - actionFk, - stateFk) - SELECT sgd.saleFk , - TRUE, - account.myUser_getId(), - a.accion_id, - s.id - FROM vn.saleGroupDetail sgd - JOIN vncontrol.accion a ON a.accion = 'SACAR' - JOIN vn.state s ON s.code = 'ON_PREPARATION' - WHERE sgd.saleGroupFk = vSaleGroupFk; - +BEGIN + + /* Inserta en vn.saleTracking las lineas de una previa + * + * @param vSaleGroupFk Identificador de vn.saleGroup + */ + + REPLACE vn.saleTracking(saleFk, + isChecked, + workerFk, + actionFk, + stateFk) + SELECT sgd.saleFk , + TRUE, + account.myUser_getId(), + a.accion_id, + s.id + FROM vn.saleGroupDetail sgd + JOIN vncontrol.accion a ON a.accion = 'SACAR' + JOIN vn.state s ON s.code = 'ON_PREPARATION' + WHERE sgd.saleGroupFk = vSaleGroupFk; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `saleTracking_addPreparedSaleGroup` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74935,31 +64510,31 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_addPreparedSaleGroup`(vSaleGroupFk INT) -BEGIN - - /** - * Inserta lineas de vn.saleTracking para un saleGroup (previa) que escanea un sacador - * - * @param vSaleGroupFk Identificador de vn.saleGroup - */ - - REPLACE vn.saleTracking(saleFk, isChecked, workerFk, actionFk, stateFk) - SELECT sgd.saleFk, TRUE, account.myUser_getId(), a.accion_id id, s.id - FROM vn.saleGroupDetail sgd - JOIN vncontrol.accion a ON a.accion = 'SACAR' - JOIN vn.state s ON s.code = 'PREPARED' - WHERE sgd.saleGroupFk = vSaleGroupFk; - +BEGIN + + /** + * Inserta lineas de vn.saleTracking para un saleGroup (previa) que escanea un sacador + * + * @param vSaleGroupFk Identificador de vn.saleGroup + */ + + REPLACE vn.saleTracking(saleFk, isChecked, workerFk, actionFk, stateFk) + SELECT sgd.saleFk, TRUE, account.myUser_getId(), a.accion_id id, s.id + FROM vn.saleGroupDetail sgd + JOIN vncontrol.accion a ON a.accion = 'SACAR' + JOIN vn.state s ON s.code = 'PREPARED' + WHERE sgd.saleGroupFk = vSaleGroupFk; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `saleTracking_addPrevOK` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -74967,41 +64542,41 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_addPrevOK`(vSectorCollectionFk INT) -BEGIN - - /** - * Inserta los registros de la colección de sector con el estado PREVIA OK - * - * @param vSectorCollectionFk Identificador de vn.sectorCollection - */ - - REPLACE vn.saleTracking(saleFk, - isChecked, - workerFk, - actionFk, - stateFk) - SELECT sgd.saleFk, - TRUE, - sc.userFk, - a.accion_id, - s.id - FROM vn.sectorCollection sc - JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id - JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk - JOIN vn.state s ON s.code = 'OK PREVIOUS' - JOIN vncontrol.accion a ON a.accion = 'PRESACAR' - WHERE sc.id = vSectorCollectionFk; - +BEGIN + + /** + * Inserta los registros de la colección de sector con el estado PREVIA OK + * + * @param vSectorCollectionFk Identificador de vn.sectorCollection + */ + + REPLACE vn.saleTracking(saleFk, + isChecked, + workerFk, + actionFk, + stateFk) + SELECT sgd.saleFk, + TRUE, + sc.userFk, + a.accion_id, + s.id + FROM vn.sectorCollection sc + JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id + JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk + JOIN vn.state s ON s.code = 'OK PREVIOUS' + JOIN vncontrol.accion a ON a.accion = 'PRESACAR' + WHERE sc.id = vSectorCollectionFk; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `saleTracking_del` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -75009,8 +64584,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_del`(vSaleFk INT, vState VARCHAR(50)) BEGIN @@ -75030,6 +64603,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `saleTracking_new` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -75037,8 +64612,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_new`( vSaleFK INT, vIsChecked BOOLEAN, @@ -75071,6 +64644,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `saleTracking_Replace` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -75078,8 +64653,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saleTracking_Replace`(vSaleFk INT, vIsChecked INT, vOriginalQuantity INT, vStateFk INT) BEGIN @@ -75091,6 +64664,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `saleTracking_updateIsChecked` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -75098,8 +64673,6 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `saleTracking_updateIsChecked`(vSaleFk INT, vIsChecked BOOL) BEGIN @@ -75131,6 +64704,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sale_calculateComponent` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -75138,8 +64713,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_calculateComponent`(vSale INT, vOption INT) proc: BEGIN @@ -75164,219 +64737,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 `sale_calculateComponent__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_calculateComponent__`(vSale INT, vOption INT) -proc: BEGIN -/** - * Actualiza los componentes - * - * @param vSale Delivery date - * @param vOption indica en que componente pone el descuadre, NULL en casos habituales - * @return tmp.ticketLot(warehouseFk, available, itemFk, buyFk) - * @return tmp.sale(saleFk, warehouseFk) - */ - DECLARE vShipped DATE; - DECLARE vWarehouseFk SMALLINT; - DECLARE vAgencyModeFk INT; - DECLARE vAddressFk INT; - DECLARE vTicket BIGINT; - DECLARE vItem BIGINT; - DECLARE vLanded DATE; - DECLARE vTicketFree BOOLEAN DEFAULT TRUE; - DECLARE vZoneFk INTEGER; - - SELECT NOT (t.refFk IS NOT NULL OR ts.alertLevel > 0) OR s.price = 0, s.ticketFk, s.itemFk , t.zoneFk - INTO vTicketFree, vTicket, vItem, vZoneFk - FROM vn.ticket t - JOIN vn.sale s ON s.ticketFk = t.id - LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id - WHERE s.id = vSale - LIMIT 1; - - SELECT t.warehouseFk, DATE(t.shipped), t.addressFk, t.agencyModeFk, t.landed - INTO vWarehouseFk, vShipped, vAddressFk, vAgencyModeFk, vLanded - FROM agencyMode a - JOIN ticket t ON t.agencyModeFk = a.id - WHERE t.id = vTicket; - - IF IFNULL(vZoneFk,0) = 0 THEN - CALL util.throw('ticket dont have zone'); - END IF; - - CALL buyUltimate (vWarehouseFk, vShipped); - - DELETE FROM tmp.buyUltimate WHERE itemFk != vItem; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouseFk warehouseFk, NULL available, vItem itemFk, buyFk - FROM tmp.buyUltimate - WHERE itemFk = vItem; - - CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped); - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT vSale saleFk,vWarehouseFk warehouseFk; - - IF vOption IS NULL THEN - SET vOption = IF(vTicketFree,1,6); - END IF; - - CALL ticketComponentUpdateSale(vOption); - - INSERT INTO vn.ticketLog (originFk, userFk, `action`, description) - VALUES (vTicket, account.userGetId(), 'update', CONCAT('Bionizo linea id ', vSale)); - - DROP TEMPORARY TABLE tmp.buyUltimate; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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_calculateComponent__2` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_calculateComponent__2`() -proc: BEGIN -/** - * Actualiza los componentes - * - * @param vSale Delivery date - * @param vOption indica en que componente pone el descuadre, NULL en casos habituales - */ - DECLARE vShipped DATE; - DECLARE vWarehouseFk SMALLINT; - DECLARE vAgencyModeFk INT; - DECLARE vAddressFk INT; - DECLARE vTicketFk BIGINT; - DECLARE vItemFk BIGINT; - DECLARE vLanded DATE; - DECLARE vIsEditable BOOLEAN; - DECLARE vZoneFk INTEGER; - - DECLARE vSaleFk INTEGER; - DECLARE v_done BOOL DEFAULT FALSE; - - DECLARE vCur CURSOR FOR - select id from tmp.ticketRose; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE; - - OPEN vCur; - - l: LOOP - SET v_done = FALSE; - FETCH vCur INTO vSaleFk; - - IF v_done THEN - LEAVE l; - END IF; - - SELECT t.refFk IS NULL AND (IFNULL(ts.alertLevel, 0) = 0 OR s.price = 0), - s.ticketFk, - s.itemFk , - t.zoneFk, - t.warehouseFk, - t.shipped, - t.addressFk, - t.agencyModeFk, - t.landed - INTO vIsEditable, - vTicketFk, - vItemFk, - vZoneFk, - vWarehouseFk, - vShipped, - vAddressFk, - vAgencyModeFk, - vLanded - FROM ticket t - JOIN sale s ON s.ticketFk = t.id - LEFT JOIN ticketState ts ON ts.ticketFk = t.id - WHERE s.id = vSaleFk; - - - CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE); - - IF (SELECT COUNT(*) FROM tmp.zoneGetLanded LIMIT 1) > 0 THEN - - IF vLanded IS NULL OR vZoneFk IS NULL THEN - - UPDATE ticket t - SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) - WHERE t.id = vTicketFk AND t.landed IS NULL; - - IF vZoneFk IS NULL THEN - SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; - UPDATE ticket t - SET t.zoneFk = vZoneFk - WHERE t.id = vTicketFk AND t.zoneFk IS NULL; - END IF; - DROP TEMPORARY TABLE tmp.zoneGetLanded; - - END IF; - - -- rellena la tabla buyUltimate con la ultima compra - CALL buyUltimate (vWarehouseFk, vShipped); - - DELETE FROM tmp.buyUltimate WHERE itemFk != vItemFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouseFk warehouseFk, NULL available, vItemFk itemFk, buyFk, vZoneFk zoneFk - FROM tmp.buyUltimate - WHERE itemFk = vItemFk; - - CALL catalog_componentPrepare(); - CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT vSaleFk saleFk,vWarehouseFk warehouseFk; - /* - IF vOption IS NULL THEN - SET vOption = IF(vIsEditable, 1, 6); - END IF; - */ - - CALL ticketComponentUpdateSale(1); - CALL catalog_componentPurge(); - - DROP TEMPORARY TABLE tmp.buyUltimate; - DROP TEMPORARY TABLE tmp.sale; - - ELSE - INSERT INTO tmp.ticketFail (id) values (vSaleFk); - END IF; - - END LOOP; - CLOSE vCur; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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_checkNoComponents` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -75384,8 +64746,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_checkNoComponents`(vCreatedFrom DATETIME, vCreatedTo DATETIME) BEGIN @@ -75461,108 +64821,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 `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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` 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 (receiver,replyTo,subject,body) - SELECT CONCAT(sub.name, '@verdnatura.es') receiver, - '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(util.VN_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(util.VN_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_getForSijsner__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_getForSijsner__`(vDated DATE) -BEGIN - - /** - * Devuelve el listado de ventas que tiene que etiquetar Sijsner para la fecha dada - * - * @param vDated Fecha de preparación de los tickets - */ - - SELECT b.printedStickers OR s.isPicked isPrinted, - t.shipped , - t.nickname , - s.ticketFk , - s.itemFk , - FLOOR(s.quantity / e.pac) stickers, - CONCAT(FLOOR(s.quantity / e.pac) , ' x ', e.pac ) amount, - s.concept, - e.kop, - e.sub, - sp.company_name supplier, - b.id buyFk - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.warehouse w ON w.id = t.warehouseFk - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p ON p.id = a.provinceFk - JOIN vn.country c ON c.id = p.countryFk - JOIN vn.item i ON i.id = s.itemFk - 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 - LEFT JOIN edi.ekt e ON e.id = b.ektFk - LEFT JOIN edi.supplier sp ON sp.supplier_id = e.pro - WHERE t.shipped BETWEEN vDated AND TIMESTAMPADD(HOUR,23,vDated) - AND c.code != 'ES' - AND w.code IN ('FLM','VNH') - AND s.quantity ; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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 */ ; @@ -75570,125 +64830,125 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` 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. - * - * @param vParam Identificador de ticket o collection - */ - DECLARE vItemPackingTypeFk VARCHAR(1); - DECLARE vIsCollection BOOL; - - SELECT COUNT(*) INTO vIsCollection - FROM collection c - WHERE c.id = vParam; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - DROP TEMPORARY TABLE IF EXISTS tmp.ticket2; - - IF vIsCollection THEN - CREATE TEMPORARY TABLE tmp.ticket - (INDEX (id)) - ENGINE = MEMORY - SELECT tc.ticketFk id - FROM ticketCollection tc - JOIN ticket t ON t.id = tc.ticketFk - WHERE tc.collectionFk = vParam; - - CREATE TEMPORARY TABLE tmp.ticket2 - (INDEX (id)) - ENGINE = MEMORY - SELECT tc.ticketFk id - FROM ticketCollection tc - JOIN ticket t ON t.id = tc.ticketFk - WHERE tc.collectionFk = vParam; - ELSE - CREATE TEMPORARY TABLE tmp.ticket - (INDEX (id)) - ENGINE = MEMORY - SELECT vParam id; - - CREATE TEMPORARY TABLE tmp.ticket2 - (INDEX (id)) - ENGINE = MEMORY - SELECT vParam id; - END IF; - - SELECT s.ticketFk, - sgd.saleGroupFk, - 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, - MAX(IF(st.semaphore <=> 4, TRUE, FALSE)) as isPreControlled, - ic.color, - ip.productor, - s.discount, - s.price, - i.stems, - i.category, - o.code origin, - tt.clientFk, - s.originalQuantity, - TRIM(CONCAT(LPAD(s.concept,30,' '), ' ', - RPAD(IFNULL(i.size,''),5,' '))) line1, - '' cel1, - TRIM(CONCAT(LPAD(IFNULL(ip.productor,''),30,' '), ' ',LPAD(IFNULL(o.code,''),4,' '))) line2, - IF(s.quantity MOD IFNULL(b.packing,s.quantity + 1), - CONCAT(CAST(s.quantity/IFNULL(b.`grouping`,1) AS DECIMAL(10,0)),' x ',IFNULL(b.`grouping`,1)), - CONCAT(CAST(s.quantity / IFNULL(b.packing,1) AS DECIMAL(10,0)),' pack de ',IFNULL(b.packing,1))) cel2, - TRIM(CONCAT(ic.color)) line3, - p.code cel3, - s.isAdded, - sub2.originalQuantity as startQuantity, -- eliminar cuando tengamos la nueva apk - IFNULL(c.workerFk,getUser()) as workerFk, - IFNULL(SUM(iss.quantity),0) as pickedQuantity, - i.packingShelve, - MIN(iss.created) picked - FROM tmp.ticket t - JOIN sale s ON s.ticketFk = t.id - JOIN ticket tt ON tt.id = t.id - LEFT JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = tt.warehouseFk - LEFT JOIN buy b ON b.id = lb.buy_id - JOIN item i ON i.id = s.itemFk - LEFT JOIN ticketCollection tc ON tc.ticketFk = t.id - LEFT JOIN collection c ON c.id = tc.collectionFk - LEFT JOIN (SELECT sub.saleFk, sub.isChecked, sub.stateFk, sub.originalQuantity - FROM (SELECT DISTINCT st.id, st.saleFk, st.isChecked, st.stateFk, st.originalQuantity - FROM tmp.ticket2 t - JOIN sale s ON s.ticketFk = t.id - JOIN saleTracking st ON st.saleFk = s.id - ORDER BY st.id DESC) sub - GROUP BY sub.saleFk, sub.stateFK) sub2 ON sub2.saleFk = s.id AND sub2.isChecked = 1 - LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id - LEFT JOIN state st ON st.id = sub2.stateFk - LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk - LEFT JOIN itemProductor ip ON ip.itemFk = s.itemFk - LEFT JOIN origin o ON o.id = i.originFk - LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id - LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk - LEFT JOIN parking p ON p.id = sg.parkingFk - GROUP BY s.id; - - DROP TEMPORARY TABLE - tmp.ticket, - tmp.ticket2; +BEGIN +/** + * Visualizar lineas de la tabla sale a través del parámetro vParam que puede + * ser ticket o collection. + * + * @param vParam Identificador de ticket o collection + */ + DECLARE vIsCollection BOOL; + + SELECT COUNT(*) INTO vIsCollection + FROM collection c + WHERE c.id = vParam; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + DROP TEMPORARY TABLE IF EXISTS tmp.ticket2; + + IF vIsCollection THEN + CREATE TEMPORARY TABLE tmp.ticket + (INDEX (id)) + ENGINE = MEMORY + SELECT tc.ticketFk id + FROM ticketCollection tc + JOIN ticket t ON t.id = tc.ticketFk + WHERE tc.collectionFk = vParam; + + CREATE TEMPORARY TABLE tmp.ticket2 + (INDEX (id)) + ENGINE = MEMORY + SELECT tc.ticketFk id + FROM ticketCollection tc + JOIN ticket t ON t.id = tc.ticketFk + WHERE tc.collectionFk = vParam; + ELSE + CREATE TEMPORARY TABLE tmp.ticket + (INDEX (id)) + ENGINE = MEMORY + SELECT vParam id; + + CREATE TEMPORARY TABLE tmp.ticket2 + (INDEX (id)) + ENGINE = MEMORY + SELECT vParam id; + END IF; + + SELECT s.ticketFk, + sgd.saleGroupFk, + 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, + MAX(IF(st.semaphore <=> 4, TRUE, FALSE)) as isPreControlled, + ic.color, + ip.productor, + s.discount, + s.price, + i.stems, + i.category, + o.code origin, + tt.clientFk, + s.originalQuantity, + TRIM(CONCAT(LPAD(s.concept,30,' '), ' ', + RPAD(IFNULL(i.size,''),5,' '))) line1, + '' cel1, + TRIM(CONCAT(LPAD(IFNULL(ip.productor,''),30,' '), ' ',LPAD(IFNULL(o.code,''),4,' '))) line2, + IF(s.quantity MOD IFNULL(b.packing,s.quantity + 1), + CONCAT(CAST(s.quantity/IFNULL(b.`grouping`,1) AS DECIMAL(10,0)),' x ',IFNULL(b.`grouping`,1)), + CONCAT(CAST(s.quantity / IFNULL(b.packing,1) AS DECIMAL(10,0)),' pack de ',IFNULL(b.packing,1))) cel2, + TRIM(CONCAT(ic.color)) line3, + p.code cel3, + s.isAdded, + sub2.originalQuantity as startQuantity, -- eliminar cuando tengamos la nueva apk + IFNULL(c.workerFk,getUser()) as workerFk, + IFNULL(SUM(iss.quantity),0) as pickedQuantity, + i.packingShelve, + MIN(iss.created) picked + FROM tmp.ticket t + JOIN sale s ON s.ticketFk = t.id + JOIN ticket tt ON tt.id = t.id + LEFT JOIN cache.last_buy lb ON lb.item_id = s.itemFk AND lb.warehouse_id = tt.warehouseFk + LEFT JOIN buy b ON b.id = lb.buy_id + JOIN item i ON i.id = s.itemFk + LEFT JOIN ticketCollection tc ON tc.ticketFk = t.id + LEFT JOIN collection c ON c.id = tc.collectionFk + LEFT JOIN (SELECT sub.saleFk, sub.isChecked, sub.stateFk, sub.originalQuantity + FROM (SELECT DISTINCT st.id, st.saleFk, st.isChecked, st.stateFk, st.originalQuantity + FROM tmp.ticket2 t + JOIN sale s ON s.ticketFk = t.id + JOIN saleTracking st ON st.saleFk = s.id + ORDER BY st.id DESC + LIMIT 10000000000000000000) sub + GROUP BY sub.saleFk, sub.stateFK) sub2 ON sub2.saleFk = s.id AND sub2.isChecked = 1 + LEFT JOIN itemShelvingSale iss ON iss.saleFk = s.id + LEFT JOIN state st ON st.id = sub2.stateFk + LEFT JOIN itemColor ic ON ic.itemFk = s.itemFk + LEFT JOIN itemProductor ip ON ip.itemFk = s.itemFk + LEFT JOIN origin o ON o.id = i.originFk + LEFT JOIN saleGroupDetail sgd ON sgd.saleFk = s.id + LEFT JOIN saleGroup sg ON sg.id = sgd.saleGroupFk + LEFT JOIN parking p ON p.id = sg.parkingFk + GROUP BY s.id; + + DROP TEMPORARY TABLE + tmp.ticket, + tmp.ticket2; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sale_getProblems` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -75696,8 +64956,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_getProblems`(IN vIsTodayRelative tinyint(1)) BEGIN @@ -75716,10 +64974,10 @@ BEGIN DECLARE vComponentCount INT; DECLARE vCursor CURSOR FOR - SELECT DISTINCT tt.warehouseFk, IF(vIsTodayRelative, util.VN_CURDATE(), date(tt.shipped)) + SELECT DISTINCT tt.warehouseFk, IF(vIsTodayRelative, vn.VN_CURDATE(), date(tt.shipped)) FROM tmp.sale_getProblems tt - WHERE DATE(tt.shipped) BETWEEN util.VN_CURDATE() - AND TIMESTAMPADD(DAY, IF(vIsTodayRelative, 9.9, 1.9), util.VN_CURDATE()); + WHERE DATE(tt.shipped) BETWEEN vn.VN_CURDATE() + AND TIMESTAMPADD(DAY, IF(vIsTodayRelative, 9.9, 1.9), vn.VN_CURDATE()); DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1; @@ -75768,12 +65026,12 @@ BEGIN FROM tmp.ticket_list tl JOIN vn.saleVolume sv ON sv.ticketFk = tl.ticketFk JOIN vn.ticket t ON t.id = tl.ticketFk - JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk AND zc.dated = util.VN_CURDATE() + JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk AND zc.dated = vn.VN_CURDATE() JOIN vn.agencyMode am ON am.id = t.agencyModeFk JOIN vn.deliveryMethod dm ON dm.id = am.deliveryMethodFk - WHERE util.VN_NOW() < TIMESTAMPADD(MINUTE,MINUTE(zc.`hour`) ,TIMESTAMPADD(HOUR,HOUR(zc.`hour`),util.VN_CURDATE())) + WHERE vn.VN_NOW() < TIMESTAMPADD(MINUTE,MINUTE(zc.`hour`) ,TIMESTAMPADD(HOUR,HOUR(zc.`hour`),vn.VN_CURDATE())) AND dm.code IN('AGENCY','DELIVERY','PICKUP') - AND t.shipped BETWEEN util.VN_CURDATE() AND util.midnight() + AND t.shipped BETWEEN vn.VN_CURDATE() AND util.midnight() GROUP BY t.addressFk) sub ON sub.addressFk = t.addressFk JOIN vn.volumeConfig vc WHERE sub.litros < vc.minTicketVolume @@ -75808,7 +65066,7 @@ BEGIN SELECT DISTINCT clientFk FROM tmp.ticket_list; - CALL clientGetDebt(util.VN_CURDATE()); + CALL clientGetDebt(vn.VN_CURDATE()); INSERT INTO tmp.sale_problems(ticketFk, risk, hasHighRisk) SELECT DISTINCT tl.ticketFk, r.risk, ((r.risk - cc.riskTolerance) > c.credit + 10) @@ -75885,7 +65143,7 @@ BEGIN AND ic.merchandise = TRUE AND IF(vIsTodayRelative, TRUE, date(t.shipped) = vDate) AND NOT i.generic - AND util.VN_CURDATE() = vDate + AND vn.VN_CURDATE() = vDate AND t.warehouseFk = vWarehouseFk GROUP BY tl.ticketFk) sub ON DUPLICATE KEY UPDATE itemShortage = sub.problem, saleFk = sub.saleFk; @@ -75911,7 +65169,7 @@ BEGIN AND ic.merchandise = TRUE AND IF(vIsTodayRelative, TRUE, date(t.shipped) = vDate) AND NOT i.generic - AND util.VN_CURDATE() = vDate + AND vn.VN_CURDATE() = vDate AND t.warehouseFk = vWarehouseFk GROUP BY tl.ticketFk) sub ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk; @@ -75939,7 +65197,7 @@ BEGIN AND ic.merchandise = TRUE AND IF(vIsTodayRelative, TRUE, date(t.shipped) = vDate) AND NOT i.generic - AND util.VN_CURDATE() = vDate + AND vn.VN_CURDATE() = vDate AND t.warehouseFk = vWarehouseFk GROUP BY tl.ticketFk) sub ON DUPLICATE KEY UPDATE itemDelay = sub.problem, saleFk = sub.saleFk; @@ -75963,6 +65221,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sale_getProblemsByTicket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -75970,8 +65230,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_getProblemsByTicket`(IN vTicketFk INT, IN vIsTodayRelative TINYINT(1)) BEGIN @@ -76002,225 +65260,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 `sale_getProblems__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_getProblems__`(IN vIsTodayRelative tinyint(1)) -BEGIN -/** - * Calcula los problemas de cada venta - * para un conjunto de tickets. - * - * @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Identificadores de los tickets a calcular - * @return tmp.sale_problems - */ - DECLARE vWarehouse INT; - DECLARE vDate DATE; - DECLARE vAvailableCache INT; - DECLARE vDone INT DEFAULT 0; - DECLARE vComponentCount INT; - - DECLARE vCursor CURSOR FOR - SELECT DISTINCT tt.warehouseFk, IF(vIsTodayRelative, util.VN_CURDATE(), date(tt.shipped)) - FROM tmp.sale_getProblems tt - WHERE DATE(tt.shipped) BETWEEN util.VN_CURDATE() - AND TIMESTAMPADD(DAY, IF(vIsTodayRelative, 9.9, 1.9), util.VN_CURDATE()); - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1; - - DROP TEMPORARY TABLE IF EXISTS tmp.sale_problems; - CREATE TEMPORARY TABLE tmp.sale_problems ( - ticketFk INT(11), - saleFk INT(11), - isFreezed INTEGER(1) DEFAULT 0, - risk DECIMAL(10,2) DEFAULT 0, - hasHighRisk TINYINT(1) DEFAULT 0, - hasTicketRequest INTEGER(1) DEFAULT 0, - isAvailable INTEGER(1) DEFAULT 1, - itemShortage VARCHAR(250), - isTaxDataChecked INTEGER(1) DEFAULT 1, - itemDelay VARCHAR(250), - hasComponentLack INTEGER(1), - isTooLittle BOOL DEFAULT FALSE, - PRIMARY KEY (ticketFk, saleFk) - ) ENGINE = MEMORY; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; - CREATE TEMPORARY TABLE tmp.ticket_list - (PRIMARY KEY (ticketFk)) - ENGINE = MEMORY - SELECT tp.ticketFk, c.id clientFk - FROM tmp.sale_getProblems tp - JOIN vn.client c ON c.id = tp.clientFk; - - SELECT COUNT(*) INTO vComponentCount - FROM vn.component c - WHERE c.isRequired; - - INSERT INTO tmp.sale_problems(ticketFk, isTooLittle) - SELECT sub.ticketFk, TRUE - FROM (SELECT tl.ticketFk, SUM(sv.litros) litros - FROM tmp.ticket_list tl - JOIN vn.saleVolume sv ON sv.ticketFk = tl.ticketFk - JOIN vn.ticket t ON t.id = tl.ticketFk - JOIN vn.zoneClosure zc ON zc.zoneFk = t.zoneFk AND zc.dated = util.VN_CURDATE() - WHERE util.VN_NOW() < TIMESTAMPADD(MINUTE,MINUTE(zc.`hour`) ,TIMESTAMPADD(HOUR,HOUR(zc.`hour`),util.VN_CURDATE())) - GROUP BY tl.ticketFk) sub - JOIN vn.volumeConfig vc - WHERE sub.litros < vc.minTicketVolume; - - INSERT INTO tmp.sale_problems(ticketFk, hasComponentLack, saleFk) - SELECT tl.ticketFk, (COUNT(DISTINCT s.id) * vComponentCount > COUNT(c.id)), s.id - FROM tmp.ticket_list tl - 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) - SELECT DISTINCT tl.ticketFk, TRUE - FROM tmp.ticket_list tl - JOIN vn.client c ON c.id = tl.clientFk - WHERE c.isFreezed - ON DUPLICATE KEY UPDATE - isFreezed = c.isFreezed; - - DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; - CREATE TEMPORARY TABLE tmp.clientGetDebt - (PRIMARY KEY (clientFk)) - ENGINE = MEMORY - SELECT DISTINCT clientFk - FROM tmp.ticket_list; - - CALL clientGetDebt(util.VN_CURDATE()); - - INSERT INTO tmp.sale_problems(ticketFk, risk, hasHighRisk) - SELECT DISTINCT tl.ticketFk, r.risk, ((r.risk - cc.riskTolerance) > c.credit + 10) - FROM tmp.ticket_list tl - JOIN vn.ticket t ON t.id = tl.ticketFk - JOIN vn.agencyMode a ON t.agencyModeFk = a.id - 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 > c.credit + 10 - AND a.isRiskFree = FALSE - ON DUPLICATE KEY UPDATE - risk = r.risk, hasHighRisk = ((r.risk - cc.riskTolerance) > c.credit + 10); - - INSERT INTO tmp.sale_problems(ticketFk, hasTicketRequest) - SELECT DISTINCT tl.ticketFk, TRUE - FROM tmp.ticket_list tl - JOIN vn.ticketRequest tr ON tr.ticketFk = tl.ticketFk - WHERE tr.isOK IS NULL - ON DUPLICATE KEY UPDATE - hasTicketRequest = TRUE; - - OPEN vCursor; - - WHILE NOT vDone - DO - FETCH vCursor INTO vWarehouse, vDate; - - CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouse, vDate); - - INSERT INTO tmp.sale_problems(ticketFk, isAvailable, saleFk) - SELECT tl.ticketFk, FALSE, s.id - FROM tmp.ticket_list tl - JOIN vn.ticket t ON t.id = tl.ticketFk - 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 cache.available av ON av.item_id = i.id - AND av.calc_id = vAvailableCache - WHERE date(t.shipped) = vDate - AND it.categoryFk != 6 - AND IFNULL(av.available, 0) < 0 - AND s.isPicked = FALSE - AND NOT i.generic - AND vWarehouse = t.warehouseFk - GROUP BY tl.ticketFk - ON DUPLICATE KEY UPDATE - isAvailable = FALSE, saleFk = VALUES(saleFk); - - INSERT INTO tmp.sale_problems(ticketFk, itemShortage, saleFk) - SELECT ticketFk, problem, saleFk - FROM ( - SELECT tl.ticketFk, CONCAT('F: ',GROUP_CONCAT(i.id, ' ', i.longName, ' ')) problem, s.id AS saleFk - FROM tmp.ticket_list tl - JOIN vn.ticket t ON t.id = tl.ticketFk - 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 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) - AND s.quantity > 0 - AND s.isPicked = FALSE - AND s.reserved = FALSE - AND it.categoryFk != 6 - AND IF(vIsTodayRelative, TRUE, date(t.shipped) = vDate) - AND NOT i.generic - AND util.VN_CURDATE() = vDate - AND t.warehouseFk = vWarehouse - GROUP BY tl.ticketFk LIMIT 1) sub - ON DUPLICATE KEY UPDATE - itemShortage = sub.problem, saleFk = sub.saleFk; - - INSERT INTO tmp.sale_problems(ticketFk, itemDelay, saleFk) - SELECT ticketFk, problem, saleFk - FROM ( - SELECT tl.ticketFk, GROUP_CONCAT('I: ',i.id, ' ', i.longName, ' ') problem, s.id AS saleFk - FROM tmp.ticket_list tl - JOIN vn.ticket t ON t.id = tl.ticketFk - 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 - WHERE s.quantity > IFNULL(issw.visible, 0) - AND s.quantity > 0 - AND s.isPicked = FALSE - AND s.reserved = FALSE - AND it.categoryFk != 6 - AND IF(vIsTodayRelative, TRUE, date(t.shipped) = vDate) - AND NOT i.generic - AND util.VN_CURDATE() = vDate - AND t.warehouseFk = vWarehouse - GROUP BY tl.ticketFk LIMIT 1) sub - ON DUPLICATE KEY UPDATE - itemDelay = sub.problem, saleFk = sub.saleFk; - END WHILE; - - CLOSE vCursor; - - INSERT INTO tmp.sale_problems(ticketFk, isTaxDataChecked) - SELECT DISTINCT tl.ticketFk, FALSE - FROM tmp.ticket_list tl - JOIN vn.client c ON c.id = tl.clientFk - WHERE c.isTaxDataChecked = FALSE - ON DUPLICATE KEY UPDATE - isTaxDataChecked = FALSE; - - DROP TEMPORARY TABLE - tmp.clientGetDebt, - 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 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sale_PriceFix` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -76228,34 +65269,34 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `sale_PriceFix`(vTicketFk INT) -BEGIN - - DELETE sc.* - FROM vn.saleComponent sc - JOIN vn.sale s ON s.id = sc.saleFk - JOIN vn.component c ON c.id = sc.componentFk - JOIN vn.componentType ct ON ct.id = c.typeFk - WHERE s.ticketFk = vTicketFk - AND ct.`type` = 'otros'; - - UPDATE vn.sale s - JOIN ( - SELECT sc.saleFk, sum(sc.value ) price - FROM vn.saleComponent sc - JOIN vn.sale s ON s.id = sc.saleFk - WHERE s.ticketFk = vTicketFk - GROUP BY sc.saleFk) sub ON sub.saleFk = s.id - SET s.price = sub.price; +BEGIN + + DELETE sc.* + FROM vn.saleComponent sc + JOIN vn.sale s ON s.id = sc.saleFk + JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk + WHERE s.ticketFk = vTicketFk + AND ct.`type` = 'otros'; + + UPDATE vn.sale s + JOIN ( + SELECT sc.saleFk, sum(sc.value ) price + FROM vn.saleComponent sc + JOIN vn.sale s ON s.id = sc.saleFk + WHERE s.ticketFk = vTicketFk + GROUP BY sc.saleFk) sub ON sub.saleFk = s.id + SET s.price = sub.price; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sale_recalcComponent` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -76263,8 +65304,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_recalcComponent`(vOption INT) proc: BEGIN @@ -76385,6 +65424,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sale_setQuantity` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -76392,41 +65433,41 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_setQuantity`(vSaleFk INT, vQuantity INT) -BEGIN -/* - * Actualiza la cantidad de la línea de venta - * - * @vSaleFk id de la línea de venta - * @vQuantity cantidad a modificar - * - */ - - DECLARE vDescription VARCHAR(100); - DECLARE vOrigin INT; - - SELECT CONCAT("Cambio cantidad ",concept," de ", quantity," a ", vQuantity) INTO vDescription - FROM sale - WHERE id = vSaleFk; - - SELECT ticketFk INTO vOrigin FROM sale WHERE id = vSaleFk; - - CALL logAdd(vOrigin, 'update', 'ticket', vDescription); - - UPDATE sale - SET originalQuantity = quantity, - quantity = vQuantity - WHERE id = vSaleFk; - +BEGIN +/* + * Actualiza la cantidad de la línea de venta + * + * @vSaleFk id de la línea de venta + * @vQuantity cantidad a modificar + * + */ + + DECLARE vDescription VARCHAR(100); + DECLARE vOrigin INT; + + SELECT CONCAT("Cambio cantidad ",concept," de ", quantity," a ", vQuantity) INTO vDescription + FROM sale + WHERE id = vSaleFk; + + SELECT ticketFk INTO vOrigin FROM sale WHERE id = vSaleFk; + + CALL logAdd(vOrigin, 'update', 'ticket', vDescription); + + UPDATE sale + SET originalQuantity = quantity, + quantity = vQuantity + WHERE id = vSaleFk; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sale_updateOriginalQuantity` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -76434,8 +65475,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sale_updateOriginalQuantity`(vSale INT, vQuantity INT) proc: BEGIN @@ -76451,6 +65490,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `saveLoadWorker` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -76458,8 +65499,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `saveLoadWorker`(routeFk INT, workerFk INT) BEGIN @@ -76474,50 +65513,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 `scanTreeCreate__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `scanTreeCreate__`() -BEGIN - CALL nestTree( - 'vn2008', - 'scan', - 'vn2008', - 'scanTree' - ); - - UPDATE vn2008.scanTree st - JOIN ( - SELECT sl.scan_id, - MAX(sl.odbc_date) lastScanned, - COUNT(DISTINCT t.routeFk) routeCount, - MIN(t.routeFk) mod 1000 as minRoute, - MAX(t.routeFk) mod 1000 as maxRoute, - COUNT(sl.scan_line_id) as scanned - FROM vn2008.scan_line sl - JOIN expedition e ON e.id = sl.`code` - JOIN ticket t ON t.id = e.ticketFk - WHERE t.routeFk - GROUP BY sl.scan_id - ) rs ON rs.scan_id = st.id - SET st.lastScanned = rs.lastScanned, - st.routeCount = rs.routeCount, - st.minRoute = rs.minRoute, - st.maxRoute = IF(rs.minRoute != rs.maxRoute, rs.maxRoute,NULL), - st.scanned = rs.scanned; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!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 sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sectorCollectionSaleGroup_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -76525,8 +65522,6 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `sectorCollectionSaleGroup_add`(vSaleGroupFk INT, vSectorCollectionFk INT) BEGIN @@ -76577,6 +65572,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sectorCollection_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -76584,37 +65581,37 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sectorCollection_get`(vSectorFk INT) -BEGIN - - /** - * Devuelve las colecciones del sector que corresponden al usuario conectado, y que estan incompletas - * - * @param vSectorFk Identificador de vn.sector - */ - - SELECT DISTINCT sc.id collectionFk, sc.created - FROM vn.sectorCollection sc - JOIN vn.state s ON s.code = 'PREVIOUS_PREPARATION' - LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id - LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk +BEGIN + + /** + * Devuelve las colecciones del sector que corresponden al usuario conectado, y que estan incompletas + * + * @param vSectorFk Identificador de vn.sector + */ + + SELECT DISTINCT sc.id collectionFk, sc.created + FROM vn.sectorCollection sc + JOIN vn.state s ON s.code = 'PREVIOUS_PREPARATION' + LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id + LEFT JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = scsg.saleGroupFk LEFT JOIN vn.saleTracking st ON st.saleFk = sgd.saleFk AND st.stateFk = s.id AND st.workerFk = sc.userFk - LEFT JOIN vn.sale sl ON sl.id = st.saleFk - WHERE sc.userFk = account.myUser_getId() - AND (ISNULL(scsg.sectorCollectionFk) + LEFT JOIN vn.sale sl ON sl.id = st.saleFk + WHERE sc.userFk = account.myUser_getId() + AND (ISNULL(scsg.sectorCollectionFk) OR (NOT st.isChecked AND sl.quantity > 0)) - AND sc.created > util.VN_CURDATE(); - + AND sc.created > vn.VN_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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sectorCollection_getSale` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -76622,46 +65619,46 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sectorCollection_getSale`(vSelf INT) -BEGIN - - /** - * Devuelve las lineas de venta correspondientes a esa coleccion de sector - * - * @param vSelf Identificador de vn.sectorCollection - */ - - SELECT s.ticketFk, - s.itemFk, - i.longName, - IFNULL(i.itemPackingTypeFk,' ') itemPackingTypeFk, - IFNULL(i.subName ,' ') subName, - s.quantity, - w.code workerCode, - sgd.saleFk, - IFNULL(iss.quantity,0) pickedQuantity, - c.salesPersonFk - FROM vn.sale s - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id - JOIN vn.sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sgd.saleGroupFk - JOIN vn.saleTracking st ON st.saleFk = s.id - JOIN vn.state stt ON stt.id = st.stateFk AND stt.code = 'PREVIOUS_PREPARATION' - JOIN vn.worker w ON w.id = st.workerFk - JOIN vn.ticket t ON t.id= s.ticketFk - JOIN vn.client c ON c.id=t.clientFk - LEFT JOIN vn.itemShelvingSaleSum iss ON iss.saleFk = s.id - WHERE scsg.sectorCollectionFk = vSelf; - +BEGIN + + /** + * Devuelve las lineas de venta correspondientes a esa coleccion de sector + * + * @param vSelf Identificador de vn.sectorCollection + */ + + SELECT s.ticketFk, + s.itemFk, + i.longName, + IFNULL(i.itemPackingTypeFk,' ') itemPackingTypeFk, + IFNULL(i.subName ,' ') subName, + s.quantity, + w.code workerCode, + sgd.saleFk, + IFNULL(iss.quantity,0) pickedQuantity, + c.salesPersonFk + FROM vn.sale s + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id + JOIN vn.sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sgd.saleGroupFk + JOIN vn.saleTracking st ON st.saleFk = s.id + JOIN vn.state stt ON stt.id = st.stateFk AND stt.code = 'PREVIOUS_PREPARATION' + JOIN vn.worker w ON w.id = st.workerFk + JOIN vn.ticket t ON t.id= s.ticketFk + JOIN vn.client c ON c.id=t.clientFk + LEFT JOIN vn.itemShelvingSaleSum iss ON iss.saleFk = s.id + WHERE scsg.sectorCollectionFk = vSelf; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sectorCollection_new` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -76669,50 +65666,47 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sectorCollection_new`(vSectorFk INT) -BEGIN - -/** - * Inserta una nueva colección, si el usuario no tiene ninguna vacia. - * Esto se hace para evitar que por error se generen colecciones sin sentido. - * - * @param vSectorFk Identificador de vn.sector - */ - DECLARE hasEmptyCollections BOOL; - DECLARE vUserFk INT; - - SET vUserFk = account.myUser_getId(); - - SELECT (COUNT(sc.id) > 0) INTO hasEmptyCollections - FROM vn.sectorCollection sc - LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id - WHERE ISNULL(scsg.id) - AND sc.userFk = vUserFk - AND sc.sectorFk = vSectorFk - AND sc.created >= util.VN_CURDATE(); - - IF NOT hasEmptyCollections THEN - INSERT INTO vn.sectorCollection(userFk, sectorFk) - VALUES(vUserFk, vSectorFk); - END IF; +BEGIN +/** + * Inserta una nueva colección, si el usuario no tiene ninguna vacia. + * Esto se hace para evitar que por error se generen colecciones sin sentido. + * + * @param vSectorFk Identificador de #vn.sector + */ + DECLARE hasEmptyCollections BOOL; + DECLARE vUserFk INT; + + SET vUserFk = account.myUser_getId(); + + SELECT (COUNT(sc.id) > 0) INTO hasEmptyCollections + FROM vn.sectorCollection sc + LEFT JOIN vn.sectorCollectionSaleGroup scsg ON scsg.sectorCollectionFk = sc.id + WHERE ISNULL(scsg.id) + AND sc.userFk = vUserFk + AND sc.sectorFk = vSectorFk + AND sc.created >= vn.VN_CURDATE(); + + IF NOT hasEmptyCollections THEN + INSERT INTO vn.sectorCollection(userFk, sectorFk) + VALUES(vUserFk, vSectorFk); + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sectorProductivity_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' */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sectorProductivity_add`() BEGIN @@ -76720,7 +65714,7 @@ BEGIN DECLARE vDatedFrom DATETIME; DECLARE vDatedTo DATETIME; - SELECT DATE_SUB(util.VN_CURDATE(),INTERVAL 1 DAY), CONCAT(DATE_SUB(util.VN_CURDATE(),INTERVAL 1 DAY),' 23:59:59') INTO vDatedFrom, vDatedTo; + SELECT DATE_SUB(vn.VN_CURDATE(),INTERVAL 1 DAY), CONCAT(DATE_SUB(vn.VN_CURDATE(),INTERVAL 1 DAY),' 23:59:59') INTO vDatedFrom, vDatedTo; DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate; DROP TEMPORARY TABLE IF EXISTS tmp.errorsByChecker; @@ -76730,20 +65724,15 @@ BEGIN CREATE TEMPORARY TABLE tmp.errorsByChecker ENGINE = MEMORY - SELECT sub1.workerFk, COUNT(sub1.id) errorsByChecker - FROM ( - SELECT st.workerFk, t.id - FROM saleMistake sm - JOIN saleTracking st ON sm.saleFk = st.saleFk - JOIN vncontrol.accion a ON a.accion_id = st.actionFk - JOIN sale s ON s.id = sm.saleFk - JOIN ticket t on t.id = s.ticketFk - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.sector se ON se.id = i.sectorFk - WHERE (t.shipped BETWEEN vDatedFrom AND vDatedTo) AND a.accion = 'PRESACAR' AND se.code IN ('ALGEMESI ARTIFI','COMPLEMENTOS') - GROUP BY s.ticketFk - ) sub1 - GROUP BY sub1.workerFk; + SELECT sc.userFk workerFk, COUNT(DISTINCT s.ticketFk) errorsByChecker + FROM saleMistake sm + JOIN vn.saleGroupDetail sgd on sgd.saleFk = sm.saleFk + JOIN vn.sectorCollectionSaleGroup scsg on scsg.saleGroupFk = sgd.saleGroupFk + JOIN vn.sectorCollection sc on sc.id = scsg.sectorCollectionFk + JOIN sale s ON s.id = sm.saleFk + JOIN ticket t on t.id = s.ticketFk + WHERE (t.shipped BETWEEN vDatedFrom AND vDatedTo) + GROUP BY sc.userFk ; CREATE TEMPORARY TABLE tmp.previousErrors -- Errores de previa, derivadores de los revisadores (por reclamación) ENGINE = MEMORY @@ -76757,30 +65746,34 @@ BEGIN WHERE t.shipped BETWEEN vDatedFrom AND vDatedTo AND cr.description = 'Revisadores' AND s.code = 'OK PREVIOUS' GROUP BY workerFk; + DELETE FROM sectorProductivity + WHERE dated = vDatedFrom + AND sector IN ('Algemesi Artificial','Algemesi Complementos'); + INSERT INTO sectorProductivity(workerFk, firstName, lastName, sector, ticketCount, saleCount, error, volume, hourWorked, dated) SELECT w.id workerFk, w.firstName, w.lastName, se.description sector, - COUNT(DISTINCT t.id) ticketCount, - COUNT(st.saleFk) saleCount, + COUNT(DISTINCT s.ticketFk) ticketCount, + COUNT(sgd.id) saleCount, IFNULL(ec2.errorsByChecker,0) + IFNULL(pe.errorsByClaim, 0) errors, wp.volume, IFNULL(CAST(tc.timeWorkDecimal AS DECIMAL (10,2)) , 0) AS hourWorked, DATE(vDatedFrom) dated - FROM vn.saleTracking st - LEFT JOIN vn.worker w ON w.id = st.workerFk - LEFT JOIN vn.sale s ON s.id = st.saleFk - LEFT JOIN vn.item i ON i.id = s.itemFk - LEFT JOIN vn.sector se ON se.id = i.sectorFk - LEFT JOIN vn.ticket t ON s.ticketFk = t.id - LEFT JOIN vncontrol.accion a ON a.accion_id = st.actionFk + FROM vn.saleGroupDetail sgd + JOIN vn.saleGroup sg on sg.id = sgd.saleGroupFk + JOIN vn.sectorCollectionSaleGroup scsg on scsg.saleGroupFk = sgd.saleGroupFk + JOIN vn.sectorCollection sc on sc.id = scsg.sectorCollectionFk + join vn.sector se on se.id = sc.sectorFk + JOIN vn.worker w ON w.id = sc.userFk + LEFT JOIN vn.sale s ON s.id = sgd.saleFk LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = w.id - LEFT JOIN bs.workerProductivity wp ON wp.workerFk = w.id AND a.accion = 'PRESACAR' + LEFT JOIN bs.workerProductivity wp ON wp.workerFk = w.id + LEFT JOIN vncontrol.accion a ON a.accion_id = wp.actionFk AND a.accion = 'PRESACAR' LEFT JOIN tmp.errorsByChecker ec2 ON ec2.workerFk = w.id LEFT JOIN tmp.previousErrors pe ON pe.workerFk = w.id - WHERE DATE(st.created) = vDatedFrom - AND se.code IN ('ALGEMESI ARTIFI','COMPLEMENTOS') + WHERE DATE(sc.created) = vDatedFrom AND wp.dated = vDatedFrom GROUP BY w.id; @@ -76794,6 +65787,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sector_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -76801,8 +65796,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sector_get`() BEGIN @@ -76820,6 +65813,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sector_getWarehouse` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -76827,8 +65822,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sector_getWarehouse`(vSectorFk INT) BEGIN @@ -76843,49 +65836,85 @@ 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 `setPlacementReserve` */; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `setParking` */; /*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `setPlacementReserve`(vItemFk INT, vPlacement VARCHAR(10), vWarehouseFk INT ) -BEGIN +CREATE DEFINER=`root`@`localhost` PROCEDURE `setParking`(IN `vParam` VARCHAR(8), IN `vParkingCode` VARCHAR(8)) +proc: BEGIN - DECLARE vReserve VARCHAR(10); - DECLARE vReserveOLD VARCHAR(10); - DECLARE vPlacementOLD VARCHAR(10); - - SELECT code, reserve INTO vPlacementOLD, vReserveOLD - FROM itemPlacement - WHERE itemFk = vItemFk - AND warehouseFk = vWarehouseFk; - - IF ASCII(vPlacement) > 57 THEN - - SET vReserve = vPlacement; - SET vPlacement = vPlacementOLD; - - ELSE - - SET vReserve = vReserveOLD; - +/* + * Aparca una colección, un ticket, un saleGroup o un shelving en un parking + * + * @param vParam id del ticket, colección, saleGroup o shelving + * @param vParkingCode código del parking + * + */ + + DECLARE vParkingFk INT; + DECLARE vIsSaleGroup BOOL; + DECLARE vIsTicket BOOL; + DECLARE vIsCollection BOOL; + + SET vParkingCode = replace(vParkingCode,' ',''); + + SELECT id INTO vParkingFk + FROM vn.parking + WHERE code = vParkingCode COLLATE utf8_unicode_ci; + + IF vParkingFk IS NULL THEN + CALL util.throw('parkingNotExist'); + LEAVE proc; + END IF; + + -- Se comprueba si es una preparación previa + SELECT COUNT(*) INTO vIsSaleGroup + FROM vn.saleGroup sg + WHERE sg.id = vParam; + + IF vIsSaleGroup THEN + CALL vn.saleGroup_setParking(vParam, vParkingFk); + LEAVE proc; END IF; - - REPLACE itemPlacement(itemFk, warehouseFk, code,reserve) - VALUES(vItemFk, vWarehouseFk, vPlacement, vReserve); + -- Se comprueba si es un ticket + SELECT COUNT(*) INTO vIsTicket + FROM vn.ticket t + WHERE t.id = vParam + AND t.shipped >= TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()); + IF vIsTicket THEN + CALL vn.ticket_setParking(vParam, vParkingFk); + LEAVE proc; + END IF; + + -- Se comprueba si es una coleccion de tickets + SELECT COUNT(*) INTO vIsCollection + FROM vn.collection c + WHERE c.id = vParam + AND c.created >= TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()); + + IF vIsCollection THEN + CALL vn.collection_setParking(vParam, vParkingFk); + LEAVE proc; + END IF; + + -- Por descarte, se considera una matrícula + CALL vn.shelving_setParking(vParam, vParkingFk); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `shelvingChange` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -76893,8 +65922,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `shelvingChange`(IN `vShelvingO` VARCHAR(8), IN `vShelvingD` VARCHAR(8)) BEGIN @@ -76910,185 +65937,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 `shelvingFuture__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `shelvingFuture__`(vSectorFk INT) -BEGIN - - DECLARE vDone BOOL DEFAULT FALSE; - DECLARE vItemFk INT; - DECLARE vItemShelvingRest INT; - DECLARE vItemShelvingFk INT; - DECLARE vItemShelvingCreated DATE; - DECLARE vSaleRest INT; - DECLARE vSaleDated DATE; - DECLARE vWarehouseFk INT; - - DECLARE rsItem CURSOR FOR - SELECT DISTINCT itemFk - FROM vn.itemShelvingStock - WHERE sectorFk = vSectorFk - AND visible > 0; - - DECLARE rsItemShelving CURSOR FOR - SELECT ish.id, - ish.visible, - date(ish.created) - FROM vn.itemShelving ish - JOIN vn.shelving sh ON sh.code = ish.shelvingFk - JOIN vn.parking p ON p.id = sh.parkingFk - WHERE ish.itemFk = vItemFk - AND ish.visible > 0 - AND p.sectorFk = vSectorFk - ORDER BY date(ish.created), ish.visible; - - DECLARE rsSale CURSOR FOR - SELECT - floor(sum(io.amount)) as sold, - date(io.dat) as dated - FROM vn2008.item_out io - LEFT JOIN tmp.ticketFree tf ON tf.ticketFk = io.ticketFk - WHERE (dat BETWEEN util.tomorrow() AND '2019-10-31' - OR - (dat BETWEEN util.VN_CURDATE() AND util.dayEnd(util.VN_CURDATE()) AND tf.ticketFk IS NOT NULL)) - AND item_id = vItemFk - AND io.warehouse_id = vWarehouseFk - GROUP BY dated; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - SELECT warehouseFk INTO vWarehouseFk - FROM vn.sector - WHERE id = vSectorFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketFree; - CREATE TEMPORARY TABLE tmp.ticketFree - SELECT ticket as ticketFk - FROM vn.ticketStateToday tst - JOIN vn.state s ON s.id = tst.state - WHERE s.isPicked = FALSE; - - DROP TEMPORARY TABLE IF EXISTS tmp.result; - CREATE TEMPORARY TABLE tmp.result - SELECT ish.id as itemShelvingFk, - date(ish.created) as created, - ish.visible, - 0 as reserve, - CAST('2019-10-31' AS DATE) as picked, - ish.shelvingFk, - 0 as Litros, - p.code as parkingCode - FROM vn.itemShelving ish - JOIN vn.shelving sh ON sh.code = ish.shelvingFk - JOIN vn.parking p ON p.id = sh.parkingFk - WHERE ish.visible > 0 - AND p.sectorFk = vSectorFk - ORDER BY date(ish.created), ish.visible; - - UPDATE tmp.result r - JOIN (SELECT ish.id, floor(sum(ish.visible * r.cm3) / 1000) as Litros - FROM vn.itemShelving ish - JOIN bi.rotacion r ON r.Id_Article = ish.itemFk AND r.warehouse_id = vWarehouseFk - GROUP BY ish.id) sub ON r.itemShelvingFk = sub.id - SET r.Litros = sub.Litros; - - ALTER TABLE tmp.result - ADD PRIMARY KEY (itemShelvingFk); - - OPEN rsItem; - - FETCH rsItem INTO vItemFk; - - -- TRUNCATE tmp.log; - - WHILE NOT vDone DO - - OPEN rsItemShelving; - OPEN rsSale; - - FETCH rsSale INTO vSaleRest, vSaleDated; - FETCH rsItemShelving INTO vItemShelvingFk, vItemShelvingRest, vItemShelvingCreated; - /* - INSERT INTO tmp.log(vItemFk, vItemShelvingRest, vSaleRest, vSalePicked,ifSide) - VALUES (vItemFk, vItemShelvingRest, vSaleRest, vSaleDated, '0'); - */ - bucle: LOOP - - IF vDone THEN - - LEAVE bucle; - - END IF; - - IF vSaleRest >= vItemShelvingRest THEN - /* - INSERT INTO tmp.log(vItemFk, vItemShelvingRest, vSaleRest, vSalePicked,ifSide) - VALUES (vItemFk, vItemShelvingRest, vSaleRest, vSaleDated, '1'); - */ - SET vSaleRest = vSaleRest - vItemShelvingRest; - - UPDATE tmp.result - SET reserve = reserve + vItemShelvingRest, - picked = LEAST(picked, vSaleDated) - WHERE itemShelvingFk = vItemShelvingFk; - - FETCH rsItemShelving INTO vItemShelvingFk, vItemShelvingRest, vItemShelvingCreated; - - IF vSaleRest = 0 THEN - - FETCH rsSale INTO vSaleRest, vSaleDated; - - END IF; - - ELSE - /* - INSERT INTO tmp.log(vItemFk, vItemShelvingRest, vSaleRest, vSalePicked,ifSide) - VALUES (vItemFk, vItemShelvingRest, vSaleRest, vSaleDated, '2'); - */ - SET vItemShelvingRest = vItemShelvingRest - vSaleRest; - - UPDATE tmp.result - SET reserve = reserve + vSaleRest, - picked = LEAST(picked, vSaleDated) - WHERE itemShelvingFk = vItemShelvingFk; - - FETCH rsSale INTO vSaleRest, vSaleDated; - - END IF; - - END LOOP; - - CLOSE rsItemShelving; - CLOSE rsSale; - /* - INSERT INTO tmp.log(vItemFk, vItemShelvingRest, vSaleRest, vSalePicked,ifSide) - VALUES (vItemFk, vItemShelvingRest, vSaleRest, vSaleDated, '4'); - */ - SET vDone = FALSE; - - FETCH rsItem INTO vItemFk; - - END WHILE; - - CLOSE rsItem; - - SELECT * FROM tmp.result - ORDER BY created, visible; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `shelvingLog_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -77096,8 +65946,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `shelvingLog_get`(shelvingFk VARCHAR(10)) BEGIN @@ -77120,6 +65968,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `shelvingPark` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -77127,8 +65977,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `shelvingPark`(IN `vParam` VARCHAR(8), IN `vParkingCode` VARCHAR(8)) proc: BEGIN @@ -77183,7 +66031,7 @@ proc: BEGIN UPDATE vn.saleGroup sg SET sg.parkingFk = vParkingFk WHERE sg.id = vParam - AND sg.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); + AND sg.created >= TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()); CALL vn.ticket_setNextState(vn.ticket_get(vParam)); @@ -77195,7 +66043,7 @@ proc: BEGIN SELECT COUNT(*) INTO vIsTicket FROM vn.ticket t WHERE t.id = vParam - AND t.shipped >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); + AND t.shipped >= TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()); IF vIsTicket THEN @@ -77230,7 +66078,7 @@ proc: BEGIN SELECT COUNT(*) INTO vIsCollection FROM vn.collection c WHERE c.id = vParam - AND c.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); + AND c.created >= TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()); IF vIsCollection THEN @@ -77245,13 +66093,13 @@ proc: BEGIN -- Por descarte, se considera una matrícula INSERT INTO vn.shelvingLog (originFk, userFk, action , description) - SELECT vParam, account.userGetId(), 'update', CONCAT("Cambio parking ",vParam," de ", p.code," a ", vParkingCode) + SELECT vParam, account.myUser_getId(), 'update', CONCAT("Cambio parking ",vParam," de ", p.code," a ", vParkingCode) FROM parking p JOIN shelving s ON s.parkingFk = p.id WHERE s.code = vParam COLLATE utf8_unicode_ci; UPDATE vn.shelving - SET parkingFk = vParkingFk, parked = util.VN_NOW(), isPrinted = TRUE + SET parkingFk = vParkingFk, parked = vn.VN_NOW(), isPrinted = TRUE WHERE `code` = vParam COLLATE utf8_unicode_ci; END ;; @@ -77260,6 +66108,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `shelvingParking_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -77267,8 +66117,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `shelvingParking_get`(vShelvingFk VARCHAR(10), vWarehouseFk INT, vDayRange INT) BEGIN @@ -77283,7 +66131,7 @@ SELECT s.itemFk, JOIN vn.ticket t ON t.id = s.ticketFk LEFT JOIN vn.itemShelvingStock ist ON ist.itemFk = s.itemFk AND ist.warehouseFk = vWarehouseFk JOIN vn.itemShelving ish ON ish.itemFk = s.itemFk AND ish.shelvingFk = vShelvingFk COLLATE utf8_general_ci - WHERE t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(TIMESTAMPADD(DAY, GREATEST(0,vDayRange), util.VN_CURDATE())) + WHERE t.shipped BETWEEN vn.VN_CURDATE() AND util.dayend(TIMESTAMPADD(DAY, GREATEST(0,vDayRange), vn.VN_CURDATE())) AND iss.saleFk IS NULL AND t.warehouseFk = vWarehouseFk GROUP BY s.itemFk @@ -77296,118 +66144,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 `shelvingPark__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `shelvingPark__`(IN `vParam` VARCHAR(8), IN `vParkingCode` VARCHAR(8)) -proc: BEGIN - - /* Aparca una colección, un ticket, un saleGroup o un shelving en un parking - * - * @param vParam - * - */ - DECLARE vParkingFk INT; - DECLARE vColumn VARCHAR(3); - DECLARE vRow VARCHAR(2); - DECLARE vReturn VARCHAR(50); - DECLARE vIsSaleGroup BOOL; - DECLARE vIsTicket BOOL; - DECLARE vIsCollection BOOL; - - SET vParkingCode = replace(vParkingCode,' ','') ; - - SELECT id INTO vParkingFk - FROM vn.parking - WHERE code = vParkingCode COLLATE utf8_unicode_ci; - - IF vParkingFk IS NULL THEN - - LEAVE proc; - - END IF; - - -- Se comprueba si es una preparación previa - SELECT COUNT(*) INTO vIsSaleGroup - FROM vn.saleGroup sg - WHERE sg.id = vParam; - - IF vIsSaleGroup THEN - - UPDATE vn.saleGroup sg - SET sg.parkingFk = vParkingFk - WHERE sg.id = vParam - AND sg.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); - - CALL vn.ticket_setPreviousState(vn.ticket_get(vParam)); - - LEAVE proc; - - END IF; - - -- Se comprueba si es un ticket - SELECT COUNT(*) INTO vIsTicket - FROM vn.ticket t - WHERE t.id = vParam - AND t.shipped >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); - - IF vIsTicket THEN - - REPLACE vn.ticketParking(ticketFk,parkingFk) - VALUES (vParam, vParkingFk); - - CALL vn.ticket_setPreviousState(vParam); - - LEAVE proc; - - END IF; - - -- Se comprueba si es una coleccion de tickets - SELECT COUNT(*) INTO vIsCollection - FROM vn.collection c - WHERE c.id = vParam - AND c.created >= TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); - - IF vIsCollection THEN - - REPLACE vn.ticketParking(ticketFk,parkingFk) - SELECT tc.ticketFk, vParkingFk - FROM vn.ticketCollection tc - WHERE tc.collectionFk = vParam; - - LEAVE proc; - - END IF; - - -- Por descarte, se considera una matrícula - INSERT INTO vn.shelvingLog (originFk, userFk, action , description) - SELECT vParam, getUser(), 'update', CONCAT("Cambio parking ",vParam," de ", p.code," a ", vParkingCode) - FROM parking p - JOIN shelving s ON s.parkingFk = p.id - WHERE s.code = vParam COLLATE utf8_unicode_ci; - - UPDATE vn.shelving - SET parkingFk = vParkingFk, parked = util.VN_NOW(), isPrinted = 1 - WHERE `code` = vParam COLLATE utf8_unicode_ci; - - SELECT (COUNT(*) > 0) AS IsUpdated - FROM vn.shelving - WHERE parkingFk = vParkingFk - AND `code` = vParam COLLATE utf8_unicode_ci; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `shelvingPriority_update` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -77415,8 +66153,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `shelvingPriority_update`(priority INT,vShelvingFk VARCHAR(10)) BEGIN @@ -77429,6 +66165,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `shelving_clean` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -77436,25 +66174,23 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `shelving_clean`() BEGIN DELETE FROM vn.shelving WHERE length(code) > 3 - AND parked < TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); + AND parked < TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()); DELETE FROM vn.itemShelving WHERE visible <= 0 - AND created < TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()); + AND created < TIMESTAMPADD(MONTH,-1,vn.VN_CURDATE()); DELETE ish.* FROM vn.itemShelving ish JOIN vn.shelving sh ON sh.code = ish.shelvingFk WHERE sh.parkingFk IS NULL - AND ish.created < TIMESTAMPADD(WEEK,-1,util.VN_CURDATE()); + AND ish.created < TIMESTAMPADD(WEEK,-1,vn.VN_CURDATE()); UPDATE vn.shelving sh LEFT JOIN vn.itemShelving its ON its.shelvingFk = sh.`code` @@ -77464,7 +66200,7 @@ BEGIN AND sh.isRecyclable AND ( sh.parked IS NULL OR - sh.parked < TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()) + sh.parked < TIMESTAMPADD(MONTH,-1,vn.VN_CURDATE()) ); END ;; @@ -77473,6 +66209,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `shelving_getSpam` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -77480,231 +66218,134 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `shelving_getSpam`(vDated DATE, vWarehouseFk INT) -BEGIN - - /** - * Devuelve las matrículas con productos que no son necesarios para la venta hasta la fecha señalada - * - * @param vDated Fecha hasta la que se puede pasar sin esos productos. - * @param vWarehouse Identificador único de vn.warehouse - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.stock; - - CALL cache.stock_refresh(FALSE); - - CREATE TEMPORARY TABLE tmp.stock - SELECT i.id itemFk, - v.amount - IFNULL(fue.reserva,0) as visible, - fue.reserva, - sale.venta, - IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) as compra, - IFNULL(v.amount,0) + IFNULL(sale.venta,0) + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) - IFNULL(fue.reserva,0) as saldo - FROM vn.item i - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN ( - SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS reserva - FROM vn.itemShelving ish - JOIN vn.shelving sh ON sh.code = ish.shelvingFk - JOIN vn.parking p ON p.id = sh.parkingFk - JOIN vn.sector s ON s.id = p.sectorFk - WHERE s.code = 'FUENTES_PICASSE' - OR sh.isSpam - GROUP BY ish.itemFk - ) fue ON fue.itemFk = i.id - LEFT JOIN cache.stock v ON i.id = v.item_id AND v.warehouse_id = vWarehouseFk - LEFT JOIN ( - SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as venta - FROM vn2008.item_out - WHERE dat BETWEEN util.VN_CURDATE() AND util.dayend(vDated) - AND warehouse_id = vWarehouseFk - GROUP BY item_id - ) sale ON sale.item_id = i.id - LEFT JOIN ( - SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as compra - FROM vn2008.item_entry_in - WHERE dat BETWEEN util.VN_CURDATE() AND util.dayend(vDated) - AND warehouse_id = vWarehouseFk - AND isVirtualStock = FALSE - GROUP BY item_id - ) buy ON buy.item_id = i.id - LEFT JOIN ( - SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as traslado - FROM vn2008.item_entry_out - WHERE dat BETWEEN util.VN_CURDATE() AND util.dayend(vDated) - AND warehouse_id = vWarehouseFk - GROUP BY item_id - ) mov ON mov.item_id = i.id - WHERE v.amount; - - SELECT ish.shelvingFk matricula, - i.longName articulo, - ish.visible, - count(*) lineas, - sum(ish.visible <= s.saldo) spam, - p.code parking, - s.description sector , - w.name AS almacen, - sh.isSpam - FROM vn.itemShelving ish - JOIN vn.item i ON i.id = ish.itemFk - JOIN vn.shelving sh ON sh.code = ish.shelvingFk - JOIN vn.parking p ON p.id = sh.parkingFk - JOIN vn.sector s ON s.id = p.sectorFk - JOIN vn.warehouse w ON w.id = s.warehouseFk - LEFT JOIN tmp.stock s ON s.itemFk = ish.itemFk - WHERE (w.name = 'Algemesi' - OR (w.name = 'NuncaJamas' AND ish.created < curdate())) - AND ish.visible - GROUP BY ish.shelvingFk - HAVING lineas = spam OR isSpam; - - DROP TEMPORARY TABLE tmp.stock; - +BEGIN + + /** + * Devuelve las matrículas con productos que no son necesarios para la venta hasta la fecha señalada + * + * @param vDated Fecha hasta la que se puede pasar sin esos productos. + * @param vWarehouse Identificador único de vn.warehouse + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.stock; + + CALL cache.stock_refresh(FALSE); + + CREATE TEMPORARY TABLE tmp.stock + SELECT i.id itemFk, + v.amount - IFNULL(fue.reserva,0) as visible, + fue.reserva, + sale.venta, + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) as compra, + IFNULL(v.amount,0) + IFNULL(sale.venta,0) + IFNULL(buy.compra,0) + IFNULL(mov.traslado,0) - IFNULL(fue.reserva,0) as saldo + FROM vn.item i + JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN ( + SELECT ish.itemFk, CAST(SUM(ish.visible) AS DECIMAL(10,0)) AS reserva + FROM vn.itemShelving ish + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk + WHERE s.code = 'FUENTES_PICASSE' + OR sh.isSpam + GROUP BY ish.itemFk + ) fue ON fue.itemFk = i.id + LEFT JOIN cache.stock v ON i.id = v.item_id AND v.warehouse_id = vWarehouseFk + LEFT JOIN ( + SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as venta + FROM vn2008.item_out + WHERE dat BETWEEN vn.VN_CURDATE() AND util.dayend(vDated) + AND warehouse_id = vWarehouseFk + GROUP BY item_id + ) sale ON sale.item_id = i.id + LEFT JOIN ( + SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as compra + FROM vn2008.item_entry_in + WHERE dat BETWEEN vn.VN_CURDATE() AND util.dayend(vDated) + AND warehouse_id = vWarehouseFk + AND isVirtualStock = FALSE + GROUP BY item_id + ) buy ON buy.item_id = i.id + LEFT JOIN ( + SELECT item_id, CAST(sum(amount)AS DECIMAL(10,0)) as traslado + FROM vn2008.item_entry_out + WHERE dat BETWEEN vn.VN_CURDATE() AND util.dayend(vDated) + AND warehouse_id = vWarehouseFk + GROUP BY item_id + ) mov ON mov.item_id = i.id + WHERE v.amount; + + SELECT ish.shelvingFk matricula, + i.longName articulo, + ish.visible, + count(*) lineas, + sum(ish.visible <= s.saldo) spam, + p.code parking, + s.description sector , + w.name AS almacen, + sh.isSpam + FROM vn.itemShelving ish + JOIN vn.item i ON i.id = ish.itemFk + JOIN vn.shelving sh ON sh.code = ish.shelvingFk + JOIN vn.parking p ON p.id = sh.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk + JOIN vn.warehouse w ON w.id = s.warehouseFk + LEFT JOIN tmp.stock s ON s.itemFk = ish.itemFk + WHERE (w.name = 'Algemesi' + OR (w.name = 'NuncaJamas' AND ish.created < vn.VN_CURDATE())) + AND ish.visible + GROUP BY ish.shelvingFk + HAVING lineas = spam OR isSpam; + + DROP TEMPORARY TABLE tmp.stock; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `silla_algemesi__` */; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `shelving_setParking` */; /*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `silla_algemesi__`(vDate DATE, vItemFk INT, vQuantity INT) -BEGIN +CREATE DEFINER=`root`@`localhost` PROCEDURE `shelving_setParking`(IN `vShelvingCode` VARCHAR(8), IN `vParkingFk` INT) +proc: BEGIN -DECLARE done INT DEFAULT FALSE; -DECLARE vWarehouseFk INT DEFAULT 60; -DECLARE vTicketFk INT; -DECLARE vSaleFk INT; -DECLARE vClonTicket INT DEFAULT 0; -DECLARE i INT DEFAULT 0; +/* + * Aparca una matrícula en un parking + * + * @param vShelvingCode code de la matrícula + * @param vParkingFk id del parking + * + */ -DECLARE cur1 CURSOR FOR - select distinct s.ticketFk, s.id - from vn.sale s - join vn.ticket t ON t.id = s.ticketFk - left join vn.ticketStateToday tss ON tss.ticket = t.id - join vn.itemShelving ish ON ish.itemFk = s.itemFk - join vn.shelving sh ON sh.code = ish.shelvingFk - join vn.parking p ON p.id = sh.parkingFk - where t.shipped between vDate and util.dayend(vDate) - and p.sectorFk = 37 - and left(t.nickname,1) != '-' - and t.warehouseFk = 1 - and s.quantity mod ish.packing = 0 - and vItemFk IN (0,s.itemFk) - and IFNULL(tss.alertLevel,0) = 0 - and s.quantity >= ish.packing - and s.quantity >= vQuantity - and s.itemFk NOT IN (1, 130, 60002, 1778, 3899); +INSERT INTO vn.shelvingLog (originFk, userFk, action , description) + SELECT vShelvingCode, account.myUser_getId(), 'update', CONCAT("Cambio parking ",vShelvingCode," de ", p.code," a ", vParkingFk) + FROM parking p + JOIN shelving s ON s.parkingFk = p.id + WHERE s.code = vShelvingCode COLLATE utf8_unicode_ci; - -DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - -OPEN cur1; - -FETCH cur1 INTO vTicketFk, vSaleFk; - - WHILE done = 0 DO - - SELECT t.id INTO vClonTicket - FROM vn.ticket t - JOIN (SELECT t.addressFk, t.shipped - FROM vn.ticket t - LEFT JOIN vn.ticketStateToday tss ON tss.ticket = t.id - WHERE id = vTicketFk - and IFNULL(tss.alertLevel,0) = 0 ) sub USING(addressFk, shipped) - WHERE t.warehouseFk = vWarehouseFk - LIMIT 1; - - -- SELECT vTicketFk, vClonTicket; - - IF vClonTicket = 0 THEN - - INSERT INTO ticket ( - clientFk, - shipped, - addressFk, - agencyModeFk, - nickname, - warehouseFk, - companyFk, - landed, - zoneFk, - zonePrice, - zoneBonus, - routeFk - ) - SELECT - clientFk, - shipped, - addressFk, - agencyModeFk, - nickname, - vWarehouseFk, - companyFk, - landed, - zoneFk, - zonePrice, - zoneBonus, - routeFk - - FROM ticket - WHERE id = vTicketFk; - - SET vClonTicket = LAST_INSERT_ID(); - - -- SELECT 'lstID', vClonTicket; - - INSERT IGNORE INTO ticketObservation(ticketFk, observationTypeFk, description) - SELECT vClonTicket, ao.observationTypeFk, ao.description - FROM addressObservation ao - JOIN ticket t ON t.addressFk = ao.addressFk - WHERE t.id = vTicketFk; - - INSERT IGNORE INTO ticketLog - SET originFk = vClonTicket, userFk = account.myUser_getId(), `action` = 'insert', - description = CONCAT('Ha creado el ticket:', ' ', vClonTicket, ' clonando el ', vTicketFk); - - END IF; - - UPDATE vn.sale - SET ticketFk = vClonTicket - WHERE id = vSaleFk; - -- SELECT vTicketFk, vClonTicket; - - SET vClonTicket = 0; - - SET done = 0; - FETCH cur1 INTO vTicketFk, vSaleFk; - - SET i = i + 1; - - END WHILE; - - CLOSE cur1; - - SELECT i; - + UPDATE vn.shelving + SET parkingFk = vParkingFk, parked = vn.VN_NOW(), isPrinted = TRUE + WHERE code = vShelvingCode COLLATE utf8_unicode_ci; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `sleep_X_min` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -77712,8 +66353,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `sleep_X_min`() BEGIN @@ -77727,6 +66366,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `solunionRiskRequest` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -77734,8 +66375,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `solunionRiskRequest`() BEGIN @@ -77747,9 +66386,10 @@ BEGIN SELECT * FROM (SELECT cc.client Id_Cliente, ci.grade FROM vn.creditClassification cc JOIN vn.creditInsurance ci ON cc.id = ci.creditClassification WHERE dateEnd IS NULL - ORDER BY ci.creationDate DESC) t1 GROUP BY Id_Cliente; + ORDER BY ci.creationDate DESC + LIMIT 10000000000000000000) t1 GROUP BY Id_Cliente; - CALL vn2008.risk_vs_client_list(util.VN_CURDATE()); + CALL vn2008.risk_vs_client_list(vn.VN_CURDATE()); SELECT c.Id_Cliente, c.Cliente, c.Credito credito_vn, c.creditInsurance solunion, cast(r.risk as DECIMAL(10,0)) riesgo_vivo, @@ -77770,6 +66410,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `stockBuyedByWorker` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -77777,8 +66419,6 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `stockBuyedByWorker`(vDate DATE, vWorker INT) BEGIN @@ -77808,41 +66448,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 `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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `stockBuyedByWorkerTest__`(vDate DATE, vWorker INT) -BEGIN - - DECLARE vVolume DECIMAL(10,2); - DECLARE vWarehouse INT DEFAULT 7; - CALL stockTraslationTest(vDate); - - SELECT Volumen INTO vVolume FROM vn2008.Cubos WHERE Id_Cubo = 'cc' LIMIT 1; - - SELECT c.Id_Entrada, a.Id_Article, a.Article, i.amount Cantidad, (0.6 * ( i.amount / c.packing ) * vn.buy_getVolume(Id_Compra))/vVolume buyed - FROM tmp.item i - JOIN vn2008.Articles a ON a.Id_Article = i.item_id - JOIN vn2008.Tipos t ON a.tipo_id = t.tipo_id - JOIN vn2008.reinos r ON r.id = t.reino_id - JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = t.Id_Trabajador - JOIN vn2008.t_item_last_buy ilb ON ilb.item_id = a.Id_Article AND ilb.warehouse_id = vWarehouse - JOIN vn2008.Compres c ON c.Id_compra = ilb.buy_id - WHERE r.display <> 0 AND tr.user_id = vWorker; - DROP TEMPORARY TABLE IF EXISTS tmp_item; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `stockBuyed_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -77850,8 +66457,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `stockBuyed_add`(vDated DATE) BEGIN @@ -77906,6 +66511,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `stockTraslation` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -77913,8 +66520,6 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `stockTraslation`(vDate DATE) BEGIN @@ -77935,7 +66540,7 @@ BEGIN SELECT item_id, SUM(amount) amount FROM vn2008.item_entry_in WHERE dat = vDate - AND vDate >= util.VN_CURDATE() + AND vDate >= vn.VN_CURDATE() AND warehouse_id = vWarehouse AND isVirtualStock is FALSE GROUP BY item_id @@ -77957,202 +66562,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 `stockTraslationTest__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `stockTraslationTest__`(vDate DATE) -BEGIN - /** - * Calcula el stock del vWarehouse desde FechaInventario hasta v_date - sin tener en cuenta las salidas del mismo dia vDate - para ver el transporte a reservar - **/ - - DECLARE vWarehouse INT DEFAULT 7; - - DELETE FROM stockBuyed WHERE `date` = vDate; - DROP TEMPORARY TABLE IF EXISTS tmp.item; - - CREATE TEMPORARY TABLE tmp.item ( - `item_id` INT, - `amount` DECIMAL(10, 2) DEFAULT 0.00, - PRIMARY KEY(item_id) - ) ENGINE = MEMORY; - - - IF vDate >= util.VN_CURDATE() THEN - INSERT INTO tmp.item - SELECT item_id, SUM(amount) amount - FROM vn2008.item_entry_in - WHERE dat = vDate - AND warehouse_id = vWarehouse - GROUP BY item_id HAVING amount != 0; - END IF; - - CALL `cache`.stock_refresh (FALSE); - - INSERT INTO tmp.item (item_id,amount) - SELECT item_id,s.amount FROM `cache`.stock s - WHERE warehouse_id = vWarehouse - ON DUPLICATE KEY UPDATE - amount = tmp.item.amount + VALUES(amount); - - CALL vn2008.item_last_buy_(vWarehouse,vDate); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `stowawayBoarding__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `stowawayBoarding__`(IN vShipFk INT, IN vStowawayFk INT) -BEGIN - - REPLACE stowaway(shipFk, id) - VALUES (vShipFk, vStowawayFk); - - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) - SELECT id, vShipFk, myWorker_getId() - FROM state - WHERE code = 'BOARDING'; - - -- FIXME No crear ticket 98 - INSERT INTO sale(ticketFk, itemFk, quantity, concept) - VALUES(vShipFk, 98,1, CONCAT('POLIZÓN! ',vStowawayFk)); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `stowawayControl__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `stowawayControl__`(vDated DATE) -BEGIN - - SELECT t.id ticketFV, - tst.code as stateFV, - sw.id ticketPCA, - w.code, - w.firstName, - w.lastName, - s.itemFk, - s.concept, - MAX(IF(s.isPicked,'OK',st.code)) situacion - FROM vn.ticket t - LEFT JOIN vn.ticketState tst ON tst.ticketFk = t.id - JOIN vn.stowaway sw ON sw.shipFk = t.id - LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = t.id - LEFT JOIN vn.collection c ON c.id = tc.collectionFk - LEFT JOIN vn.worker w ON w.id = c.workerFk - JOIN vn.sale s ON s.ticketFk = sw.id - LEFT JOIN vn.saleTracking str ON str.saleFk = s.id AND str.isChecked = 1 - LEFT JOIN vn.state st ON st.id = str.stateFk AND st.code = 'PREPARED' - WHERE t.shipped BETWEEN vDated AND util.dayend(vDated) - GROUP BY s.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 `stowaway_launchShip__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `stowaway_launchShip__`(vStowawayFk INT) -BEGIN - - DECLARE myShipFk INT; - - SELECT shipFk INTO myShipFk - FROM vn.stowaway - WHERE id = vStowawayFk; - - IF myShipFk THEN - - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) - SELECT id, myShipFk, account.myUser_getId() - FROM state - WHERE code = 'OK STOWAWAY'; - - 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 `stowaway_unboarding__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `stowaway_unboarding__`(vShipFk INT, vStowawayFk INT) -BEGIN - DECLARE vWorker VARCHAR(255); - - DELETE FROM stowaway - WHERE shipFk = vShipFk AND id = vStowawayFk; - - DELETE tt FROM ticketTracking tt - JOIN state s ON s.id = tt.stateFk - WHERE code = 'BOARDING' AND ticketFk = vShipFk; - - DELETE FROM sale - WHERE ticketFk = vShipFk - AND itemFk = 98 - AND concept = CONCAT('POLIZÓN! ',vStowawayFk); - - SELECT u.`name` INTO vWorker - FROM account.user u JOIN worker w ON w.userFk = u.id - WHERE w.id = client_getSalesPersonByTicket(vStowawayFk); - - SELECT messageSend(vWorker,CONCAT('El ticket: ', vStowawayFk, ' ha dejado de ser un polizón')) INTO @a; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `subordinateGetList` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -78160,8 +66571,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `subordinateGetList`(vBossFk INT) BEGIN @@ -78216,6 +66625,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `supplierExpenses` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -78223,8 +66634,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `supplierExpenses`(vEnded DATE) BEGIN @@ -78308,6 +66717,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `supplierPackaging_ReportSource` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -78315,8 +66726,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `supplierPackaging_ReportSource`(vFromDated DATE, vSupplierFk INT) BEGIN @@ -78470,6 +66879,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `supplier_checkBalance` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -78477,8 +66888,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `supplier_checkBalance`(IN vDateTo DATETIME, IN vIsConciliated BOOL) BEGIN @@ -78525,6 +66934,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `supplier_disablePayMethodChecked` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -78532,8 +66943,6 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `supplier_disablePayMethodChecked`() BEGIN @@ -78549,7 +66958,7 @@ BEGIN FROM vn.payment p LEFT JOIN vn.supplier s ON s.id = p.supplierFk LEFT JOIN vn.payMethod pm ON pm.id = s.payMethodFk - WHERE p.created < (util.VN_CURDATE() - INTERVAL pm.graceMonthsDisableChecked MONTH) + WHERE p.created < (vn.VN_CURDATE() - INTERVAL pm.graceMonthsDisableChecked MONTH) AND pm.graceMonthsDisableChecked AND s.isPayMethodChecked GROUP BY p.supplierFk) sdpmc ON sdpmc.supplierFk = s.id @@ -78561,6 +66970,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `test` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -78568,8 +66979,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `test`() BEGIN @@ -78580,6 +66989,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketBoxesView` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -78587,8 +66998,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketBoxesView`(IN vTicketFk INT) BEGIN @@ -78618,6 +67027,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketBuiltTime` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -78625,8 +67036,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketBuiltTime`(vDate DATE) BEGIN @@ -78653,6 +67062,7 @@ BEGIN vncontrol.inter WHERE odbc_date BETWEEN vDateStart AND vDateEnd ORDER BY Id_Ticket, odbc_date DESC + LIMIT 10000000000000000000 ) sub GROUP BY ticketFk ) sub2 ON sub2.ticketFk = t.id @@ -78668,6 +67078,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketCalculateClon` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -78675,8 +67087,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCalculateClon`(IN vTicketNew INT, vTicketOld INT) BEGIN @@ -78768,102 +67178,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 `ticketCalculateClon__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCalculateClon__`(IN vTicketNew INT, vTicketOld INT) -BEGIN - /* - * @vTicketNew id del nuevo ticket clonado - * @vTicketOld id ticket original, a partir del qual se clonara el nuevo - * Este procedimiento "rebioniza" una linea, eliminando los componentes existentes e insertandolos de nuevo - */ - DECLARE vShipped DATE; - DECLARE vClient INT; - DECLARE vWarehouse SMALLINT; - DECLARE vAgencyMode INT; - DECLARE vAddress INT; - DECLARE vLanded DATE; - DECLARE vAgency INT; - DECLARE vZoneFk INT; - - REPLACE INTO orderTicket(orderFk,ticketFk) - SELECT orderFk, vTicketNew - FROM orderTicket - WHERE ticketFk = vTicketOld; - - SELECT t.clientFk, t.warehouseFk, date(t.shipped), t.addressFk, t.agencyModeFk, t.landed, a.agencyFk, t.zoneFk - INTO vClient, vWarehouse, vShipped, vAddress, vAgencyMode, vLanded, vAgency, vZoneFk - FROM vn.agencyMode a - JOIN vn.ticket t ON t.agencyModeFk = a.id - WHERE t.id = vTicketNew; - - IF vLanded IS NULL THEN - CALL zone_getLanded(vShipped, vAddress, vAgency, vWarehouse); - UPDATE ticket t - JOIN tmp.zoneGetLanded zgl ON t.warehouseFk = zgl.warehouseFk - SET t.landed = zgl.landed, - t.zone = zgl.zoneFk - WHERE t.id = vTicketNew; - - SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; - DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded; - END IF; - - -- rellena la tabla tmp.buyUltimate con la ultima compra - CALL buyUltimate(vWarehouse, vShipped); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouse warehouseFk, NULL available, s.itemFk, bu.buyFk - FROM sale s - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk - WHERE s.ticketFk = vTicketOld GROUP BY s.itemFk; - - CALL catalog_componentCalculate(vZoneFk, vAddress, vAgencyMode); - - -- Bionizamos lineas con Preu = 0 - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT s.id saleFk, vWarehouse warehouseFk - FROM sale s - JOIN ticket t on t.id = s.ticketFk WHERE s.ticketFk = vTicketNew AND s.price = 0; - - CALL ticketComponentUpdateSale(1); - - -- Bionizamos lineas con Preu > 0 - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT s.id saleFk, vWarehouse warehouseFk - FROM sale s - JOIN ticket t on t.id = s.ticketFk WHERE s.ticketFk = vTicketNew - AND s.price > 0; - - CALL ticketComponentUpdateSale(6); - - -- Log - CALL `logAdd`(vTicketNew, 'update', ' ticket' , 'Bioniza Ticket'); - - -- Limpieza - DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate; - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - 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 `ticketCalculateFromType` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -78871,8 +67187,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCalculateFromType`( vLanded DATE, vAddressFk INT, @@ -78895,6 +67209,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketCalculatePurge` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -78902,8 +67218,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCalculatePurge`() BEGIN @@ -78919,231 +67233,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 `ticketCalculateSaleForcePrice2__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCalculateSaleForcePrice2__`(IN vSale BIGINT) -proc: BEGIN - - DECLARE vShipped DATE; - DECLARE vWarehouseFk SMALLINT; - DECLARE vAddressFk INT; - DECLARE vTicket BIGINT; - DECLARE vItem BIGINT; - DECLARE vZoneFk INT; - - SELECT ticketFk, itemFk - INTO vTicket, vItem - FROM sale - WHERE id = vSale; - - SELECT t.warehouseFk, DATE(t.shipped), t.addressFk, t.zoneFk - INTO vWarehouseFk, vShipped, vAddressFk, vZoneFk - FROM agencyMode a - JOIN ticket t ON t.agencyModeFk = a.id - WHERE t.id = vTicket; - - IF vZoneFk IS NULL THEN - CALL util.throw('ticket without zone'); - END IF; - - CALL buyUltimate (vWarehouseFk, vShipped); - - DELETE FROM tmp.buyUltimate WHERE itemFk != vItem; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouseFk warehouseFk, NULL available, vItem itemFk, buyFk - FROM tmp.buyUltimate - WHERE itemFk = vItem; - - CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped); - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT vSale saleFk,vWarehouseFk warehouseFk; - - CALL ticketComponentUpdateSale(1); - - INSERT INTO vn.ticketLog (originFk, userFk, `action`, description) - VALUES (vTicket, account.userGetId(), 'update', CONCAT('Bionizo linea id ', vSale)); - - DROP TEMPORARY TABLE tmp.buyUltimate; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketCalculateSaleForcePrice__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCalculateSaleForcePrice__`(IN vSale BIGINT) -proc: BEGIN - - DECLARE vShipped DATE; - DECLARE vWarehouseFk SMALLINT; - DECLARE vAddressFk INT; - DECLARE vTicket BIGINT; - DECLARE vItem BIGINT; - DECLARE vZoneFk INT; - - SELECT ticketFk, itemFk - INTO vTicket, vItem - FROM sale - WHERE id = vSale; - - SELECT t.warehouseFk, DATE(t.shipped), t.addressFk, t.zoneFk - INTO vWarehouseFk, vShipped, vAddressFk, vZoneFk - FROM agencyMode a - JOIN ticket t ON t.agencyModeFk = a.id - WHERE t.id = vTicket; - - IF vZoneFk IS NULL THEN - CALL util.throw('ticket without zone'); - END IF; - - CALL buyUltimate (vWarehouseFk, vShipped); - - DELETE FROM tmp.buyUltimate WHERE itemFk != vItem; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouseFk warehouseFk, NULL available, vItem itemFk, buyFk - FROM tmp.buyUltimate - WHERE itemFk = vItem; - - CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped); - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT vSale saleFk,vWarehouseFk warehouseFk; - - CALL ticketComponentUpdateSale(1); - - INSERT INTO vn.ticketLog (originFk, userFk, `action`, description) - VALUES (vTicket, account.userGetId(), 'update', CONCAT('Bionizo linea id ', vSale)); - - DROP TEMPORARY TABLE tmp.buyUltimate; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketCalculateSale__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCalculateSale__`(IN vSale BIGINT) -proc: BEGIN --- OBSOLETO USAR: sale_calculateComponent(vSale, NULL) - DECLARE vShipped DATE; - DECLARE vWarehouseFk SMALLINT; - DECLARE vAgencyModeFk INT; - DECLARE vAddressFk INT; - DECLARE vTicket BIGINT; - DECLARE vItem BIGINT; - DECLARE vLanded DATE; - DECLARE vTicketFree BOOLEAN DEFAULT TRUE; - DECLARE vZoneFk INTEGER; - - SELECT NOT (t.refFk IS NOT NULL OR ts.alertLevel > 0) OR s.price = 0, s.ticketFk, s.itemFk , t.zoneFk - INTO vTicketFree, vTicket, vItem, vZoneFk - FROM vn.ticket t - JOIN vn.sale s ON s.ticketFk = t.id - LEFT JOIN vn.ticketState ts ON ts.ticketFk = t.id - WHERE s.id = vSale - LIMIT 1; - - SELECT t.warehouseFk, DATE(t.shipped), t.addressFk, t.agencyModeFk, t.landed - INTO vWarehouseFk, vShipped, vAddressFk, vAgencyModeFk, vLanded - FROM agencyMode a - JOIN ticket t ON t.agencyModeFk = a.id - WHERE t.id = vTicket; - - IF IFNULL(vZoneFk,0) = 0 THEN - CALL util.throw('ticket dont have zone'); - END IF; - - CALL buyUltimate (vWarehouseFk, vShipped); - - DELETE FROM tmp.buyUltimate WHERE itemFk != vItem; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouseFk warehouseFk, NULL available, vItem itemFk, buyFk, vZoneFk zoneFk - FROM tmp.buyUltimate - WHERE itemFk = vItem; - - CALL vn.catalog_componentCalculate; - CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT vSale saleFk,vWarehouseFk warehouseFk; - - CALL ticketComponentUpdateSale(IF(vTicketFree,1,6)); - - INSERT INTO vn.ticketLog (originFk, userFk, `action`, description) - VALUES (vTicket, account.userGetId(), 'update', CONCAT('Bionizo linea id ', vSale)); - - CALL catalog_componentPurge(); - DROP TEMPORARY TABLE tmp.buyUltimate; - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketCalculate__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCalculate__`( - vLanded DATE, - vAddressFk INT, - vAgencyModeFk INT) -proc: BEGIN --- OBSOLETO utilizar catalog_calculate - CALL vn.catalog_calculate(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 `ticketClon` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -79151,8 +67242,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketClon`(vTicketFk INT, vNewShipped DATE) BEGIN @@ -79169,7 +67258,7 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - SET vNewShipped = IFNULL(vNewShipped, util.VN_CURDATE()); + SET vNewShipped = IFNULL(vNewShipped, vn.VN_CURDATE()); CALL vn.ticket_Clone(vTicketFk, vNewTicketFk); @@ -79212,6 +67301,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketClon_OneYear` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -79219,8 +67310,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketClon_OneYear`(vTicketFk INT) BEGIN @@ -79247,170 +67336,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 `ticketClosureAgencyListAdd__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketClosureAgencyListAdd__`(vAgencyModeFk INT) -BEGIN -/** - * Prepara un listado de agencias sobre los que se realizará el cierre. - * Es necesario llamar al procedimiento por cada agencia. - * - * @param vAgencyModeFk Id almacén - */ - CREATE TEMPORARY TABLE IF NOT EXISTS tmp.ticketClosureAgencyList ( - `agencyModeFk` INT, - PRIMARY KEY(agencyModeFk)) ENGINE = MEMORY; - - INSERT INTO tmp.ticketClosureAgencyList(agencyModeFk) VALUES(vAgencyModeFk); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureAgencyList__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketClosureAgencyList__`(vWarehouseFk INT, vDateTo DATE) -BEGIN -/** - * Inserta los tickets de todos los almacenes en la tabla temporal - * para ser cerrados. - * - * @param vWarehouseFk Id del almacén - * @param vDate Fecha del cierre - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; - - CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( - SELECT - t.id AS ticketFk - FROM expedition e - INNER JOIN ticket t ON t.id = e.ticketFk - INNER JOIN tmp.ticketClosureAgencyList al ON al.agencyModeFk = t.agencyModeFk - LEFT JOIN ticketState ts ON ts.ticketFk = t.id - WHERE - ts.alertLevel = 2 - AND t.warehouseFk = vWarehouseFk - AND DATE(t.shipped) BETWEEN DATE_ADD(vDateTo, INTERVAL -2 DAY) AND vDateTo - AND t.refFk IS NULL - GROUP BY e.ticketFk); - - DROP TEMPORARY TABLE tmp.ticketClosureAgencyList; - - CALL ticketClosure(); - - DROP TEMPORARY TABLE tmp.ticketClosure; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureRoute__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketClosureRoute__`( vRouteFk INT) -BEGIN -/** - * Inserta los tickets de la ruta en la tabla temporal - * para ser cerrados. - * - * @param vWarehouseFk Almacén a cerrar - * @param vRouteFk Ruta a cerrar - * @param vDate Fecha del cierre - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; - - CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( - SELECT - t.id AS ticketFk - FROM expedition e - INNER JOIN ticket t ON t.id = e.ticketFk - LEFT JOIN ticketState ts ON ts.ticketFk = t.id - WHERE - ts.alertLevel = 2 - AND t.routeFk = vRouteFk - AND t.refFk IS NULL - GROUP BY e.ticketFk); - - CALL ticketClosure(); - - DROP TEMPORARY TABLE tmp.ticketClosure; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketClosureTicket__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketClosureTicket__`(vTicketFk INT) -BEGIN - -/** - * @deprecated Use ticket_closeByTicket() - * Inserta el ticket en la tabla temporal - * para ser cerrado. - * - * @param vTicketFk Id del ticket - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; - - CREATE TEMPORARY TABLE tmp.ticketClosure ENGINE = MEMORY ( - SELECT - t.id AS ticketFk - FROM expedition e - INNER JOIN ticket t ON t.id = e.ticketFk - LEFT JOIN ticketState ts ON ts.ticketFk = t.id - WHERE - ts.alertLevel = 2 - AND t.id = vTicketFk - AND t.refFk IS NULL - GROUP BY e.ticketFk); - - CALL ticketClosure(); - - DROP TEMPORARY TABLE tmp.ticketClosure; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketCollection_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -79418,8 +67345,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCollection_get`(vTicketFk INT) BEGIN @@ -79434,6 +67359,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketCollection_setUsedShelves` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -79441,29 +67368,29 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCollection_setUsedShelves`(vTicketFk INT, vUsedShelves INT) -BEGIN - - /* - * Inserta número de baldas que ocupa un ticket - * - * @param vTicketFk Identificador de ticket - * @param vUsedShelves Número de baldas - */ - - UPDATE ticketCollection tc - SET tc.usedShelves = vUsedShelves - WHERE tc.ticketFk = vTicketFk; - +BEGIN + + /* + * Inserta número de baldas que ocupa un ticket + * + * @param vTicketFk Identificador de ticket + * @param vUsedShelves Número de baldas + */ + + UPDATE ticketCollection tc + SET tc.usedShelves = vUsedShelves + WHERE tc.ticketFk = vTicketFk; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketComponentUpdate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -79471,8 +67398,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketComponentUpdate`( vTicketFk INT, @@ -79542,6 +67467,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketComponentUpdateSale` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -79549,8 +67476,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketComponentUpdateSale`(vOption INT) BEGIN @@ -79739,6 +67664,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketCreate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -79746,8 +67673,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCreate`( vClientId INT @@ -79760,13 +67685,15 @@ CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCreate`( ,vlanded DATE ,OUT vNewTicket INT) BEGIN - CALL `ticketCreateWithUser`(vClientId, vShipped, vWarehouseId, vCompanyFk, vAddressFk, vAgencyType, vRouteFk, vlanded, account.userGetId(), vNewTicket); + CALL `ticketCreateWithUser`(vClientId, vShipped, vWarehouseId, vCompanyFk, vAddressFk, vAgencyType, vRouteFk, vlanded, account.myUser_getId(), vNewTicket); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketCreateWithUser` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -79774,8 +67701,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketCreateWithUser`( vClientId INT @@ -79808,6 +67733,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketDown_PrintableSelection` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -79815,8 +67742,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketDown_PrintableSelection`(vSectorFk INT) BEGIN @@ -79843,254 +67768,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 `ticketFilter__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketFilter__`() -BEGIN -/** - * Obtiene un listado de tickets - * junto con el precio total y los problemas - * - * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular - * @return Listado de tickets - */ - CALL ticketGetTotal(); - CALL ticketGetProblems(FALSE); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketFilter; - CREATE TEMPORARY TABLE tmp.ticketFilter ENGINE = MEMORY - SELECT t.*, tt.total, tp.problem - FROM tmp.ticket t - JOIN tmp.ticketTotal tt ON tt.ticketFk = t.ticketFk - LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = t.ticketFk; - - DROP TEMPORARY TABLE - tmp.ticket, - tmp.ticketTotal, - tmp.ticketProblems; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketGetProblems__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketGetProblems__`(IN vIsTodayRelative TINYINT(1)) -BEGIN -/** - * @deprecated Use ticket_getProblems() instead - * - * Hay que revisar los dos procesos y unificarlos. No son equivalentes. PAK 04/06/21 - * - */ - DECLARE vWarehouse INT; - DECLARE vDate DATE; - DECLARE vAvailableCache INT; - DECLARE vDone INT DEFAULT 0; - DECLARE vComponentCount INT; - DECLARE vHasUbications BOOL; - - DECLARE vCursor CURSOR FOR - SELECT DISTINCT tt.warehouseFk, IF(vIsTodayRelative, util.VN_CURDATE(), date(tt.shipped)), w.hasUbications - FROM tmp.ticketGetProblems tt - JOIN vn.warehouse w ON w.id = tt.warehouseFk - WHERE DATE(tt.shipped) BETWEEN util.VN_CURDATE() - AND TIMESTAMPADD(DAY, IF(vIsTodayRelative, 9.9, 1.9), util.VN_CURDATE()); - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketProblems; - CREATE TEMPORARY TABLE tmp.ticketProblems ( - ticketFk INT(11) PRIMARY KEY, - isFreezed INTEGER(1) DEFAULT 0, - risk DECIMAL(10,2) DEFAULT 0, - hasTicketRequest INTEGER(1) DEFAULT 0, - isAvailable INTEGER(1) DEFAULT 1, - itemShortage VARCHAR(250), - isTaxDataChecked INTEGER(1) DEFAULT 1, - itemDelay VARCHAR(250), - componentLack INTEGER(1) - ) ENGINE = MEMORY; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketList; - CREATE TEMPORARY TABLE tmp.ticketList - (PRIMARY KEY (ticketFk)) - ENGINE = MEMORY - SELECT tp.ticketFk, c.id clientFk - FROM tmp.ticketGetProblems tp - JOIN vn.client c ON c.id = tp.clientFk; - - SELECT COUNT(*) INTO vComponentCount - FROM vn.component c - WHERE c.isRequired; - - INSERT INTO tmp.ticketProblems(ticketFk, componentLack) - SELECT tl.ticketFk, - (COUNT(DISTINCT s.id) * (vComponentCount - (dm.code = 'PICKUP')) > COUNT(c.id)) - FROM tmp.ticketList tl - JOIN vn.sale s ON s.ticketFk = tl.ticketFk - 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 - LEFT JOIN vn.saleComponent sc ON sc.saleFk = s.id - LEFT JOIN vn.component c ON c.id = sc.componentFk AND c.isRequired - GROUP BY tl.ticketFk; - - INSERT INTO tmp.ticketProblems(ticketFk, isFreezed) - SELECT DISTINCT tl.ticketFk, 1 - FROM tmp.ticketList tl - JOIN vn.client c ON c.id = tl.clientFk - WHERE c.isFreezed - ON DUPLICATE KEY UPDATE - isFreezed = c.isFreezed; - - DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; - CREATE TEMPORARY TABLE tmp.clientGetDebt - (PRIMARY KEY (clientFk)) - ENGINE = MEMORY - SELECT DISTINCT clientFk - FROM tmp.ticketList; - - CALL clientGetDebt(util.VN_CURDATE()); - - INSERT INTO tmp.ticketProblems(ticketFk, risk) - SELECT DISTINCT tl.ticketFk, r.risk - FROM tmp.ticketList tl - JOIN vn.ticket t ON t.id = tl.ticketFk - JOIN vn.agencyMode a ON t.agencyModeFk = a.id - 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 - AND a.isRiskFree = FALSE - ON DUPLICATE KEY UPDATE - risk = r.risk; - - INSERT INTO tmp.ticketProblems(ticketFk, hasTicketRequest) - SELECT DISTINCT tl.ticketFk, 1 - FROM tmp.ticketList tl - JOIN vn.ticketRequest tr ON tr.ticketFk = tl.ticketFk - WHERE tr.isOK IS NULL AND tr.saleFk IS NOT NULL - ON DUPLICATE KEY UPDATE - hasTicketRequest = 1; - - OPEN vCursor; - - WHILE NOT vDone - DO - FETCH vCursor INTO vWarehouse, vDate, vHasUbications; - - CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouse, vDate); - - INSERT INTO tmp.ticketProblems(ticketFk, isAvailable) - SELECT tl.ticketFk, 0 - FROM tmp.ticketList tl - JOIN vn.ticket t ON t.id = tl.ticketFk - 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 cache.available av ON av.item_id = i.id - AND av.calc_id = vAvailableCache - WHERE date(t.shipped) = vDate - AND it.categoryFk != 6 - AND IFNULL(av.available, 0) < 0 - AND s.isPicked = FALSE - AND NOT i.generic - AND vWarehouse = t.warehouseFk - GROUP BY tl.ticketFk - ON DUPLICATE KEY UPDATE - isAvailable = 0; - - IF vHasUbications THEN - - INSERT INTO tmp.ticketProblems(ticketFk, itemShortage) - SELECT ticketFk, problem - FROM ( - SELECT tl.ticketFk, CONCAT('F: ',GROUP_CONCAT(i.id, ' ', i.longName, ' ')) problem - FROM tmp.ticketList tl - JOIN vn.ticket t ON t.id = tl.ticketFk - 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 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) - AND s.quantity > 0 - AND s.isPicked = FALSE - AND s.reserved = FALSE - AND it.categoryFk != 6 - AND IF(vIsTodayRelative, TRUE, date(t.shipped) = vDate) - AND NOT i.generic - AND util.VN_CURDATE() = vDate - AND t.warehouseFk = vWarehouse - GROUP BY tl.ticketFk) sub - ON DUPLICATE KEY UPDATE - itemShortage = sub.problem; - - INSERT INTO tmp.ticketProblems(ticketFk, itemDelay) - SELECT ticketFk, problem - FROM ( - SELECT tl.ticketFk, GROUP_CONCAT('I: ',i.id, ' ', i.longName, ' ') problem - FROM tmp.ticketList tl - JOIN vn.ticket t ON t.id = tl.ticketFk - 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 - WHERE s.quantity > IFNULL(issw.visible, 0) - AND s.quantity > 0 - AND s.isPicked = FALSE - AND s.reserved = FALSE - AND it.categoryFk != 6 - AND IF(vIsTodayRelative, TRUE, date(t.shipped) = vDate) - AND NOT i.generic - AND util.VN_CURDATE() = vDate - AND t.warehouseFk = vWarehouse - GROUP BY tl.ticketFk) sub - ON DUPLICATE KEY UPDATE - itemDelay = sub.problem; - - END IF; - - END WHILE; - - CLOSE vCursor; - - INSERT INTO tmp.ticketProblems(ticketFk, isTaxDataChecked) - SELECT DISTINCT tl.ticketFk, FALSE - FROM tmp.ticketList tl - JOIN vn.client c ON c.id = tl.clientFk - WHERE c.isTaxDataChecked= FALSE - ON DUPLICATE KEY UPDATE - isTaxDataChecked = FALSE; - - DROP TEMPORARY TABLE - tmp.clientGetDebt, - tmp.ticketList; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketGetTaxAdd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -80098,8 +67777,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketGetTaxAdd`(vTicketFk INT) BEGIN @@ -80135,6 +67812,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketGetTax_new` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -80142,8 +67821,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketGetTax_new`() READS SQL DATA @@ -80214,133 +67891,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 `ticketGetTax__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketGetTax__`() - READS SQL DATA -BEGIN -/** - * Calcula la base imponible, el IVA y el recargo de equivalencia para - * un conjunto de tickets. - * - * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular - * @return tmp.ticketAmount - * @return tmp.ticketTax Impuesto desglosado para cada ticket. - - */ - DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; - CREATE TEMPORARY TABLE tmp.addressCompany - (INDEX (addressFk, companyFk)) - ENGINE = MEMORY - SELECT DISTINCT t.addressFk, t.companyFk - FROM tmp.ticket tmpTicket - JOIN ticket t ON t.id = tmpTicket.ticketFk; - - CALL addressTaxArea (); - - - /** Solo se calcula la base imponible (taxableBase) y el impuesto se calculará posteriormente - * No se debería cambiar el sistema por problemas con los decimales - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax; - CREATE TEMPORARY TABLE tmp.ticketTax - (INDEX (ticketFk)) - ENGINE = MEMORY - SELECT tmpTicket.ticketFk, - bp.pgcFk, - SUM(s.quantity * s.price * (100 - s.discount)/100 ) AS taxableBase, - pgc.rate, - tc.code - FROM tmp.ticket tmpTicket - JOIN sale s ON s.ticketFk = tmpTicket.ticketFk - JOIN item i ON i.id = s.itemFk - JOIN ticket t ON t.id = tmpTicket.ticketFk - JOIN supplier su ON su.id = t.companyFk - JOIN tmp.addressTaxArea ata - ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk - JOIN itemTaxCountry itc - ON itc.itemFk = i.id AND itc.countryFk = su.countryFk - JOIN bookingPlanner bp - ON bp.countryFk = su.countryFk - AND bp.taxAreaFk = ata.areaFk - AND bp.taxClassFk = itc.taxClassFk - JOIN pgc ON pgc.code = bp.pgcFk - JOIN taxClass tc ON tc.id = bp.taxClassFk - GROUP BY tmpTicket.ticketFk, pgc.code,pgc.rate - HAVING taxableBase != 0; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketServiceTax; - CREATE TEMPORARY TABLE tmp.ticketServiceTax - (INDEX (ticketFk)) - ENGINE = MEMORY - SELECT tt.ticketFk, - SUM(ts.quantity * ts.price) AS taxableBase, - pgc.rate, - tc.code - FROM tmp.ticketTax tt - JOIN ticketService ts ON ts.ticketFk = tt.ticketFk - JOIN ticket t ON t.id = tt.ticketFk - JOIN supplier su ON su.id = t.companyFk - JOIN tmp.addressTaxArea ata - ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk - JOIN bookingPlanner bp - ON bp.countryFk = su.countryFk - AND bp.taxAreaFk = ata.areaFk - AND bp.taxClassFk = ts.taxClassFk - JOIN pgc ON pgc.code = bp.pgcFk AND pgc.rate = tt.rate - JOIN taxClass tc ON tc.id = bp.taxClassFk - GROUP BY tt.ticketFk, tt.code,tt.rate - HAVING taxableBase != 0; - - UPDATE tmp.ticketTax tt - JOIN tmp.ticketServiceTax ts ON tt.ticketFk = ts.ticketFk AND tt.code = ts.code AND tt.rate = ts.rate - SET tt.taxableBase = tt.taxableBase + ts.taxableBase; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount; - CREATE TEMPORARY TABLE tmp.ticketAmount - (INDEX (ticketFk)) - ENGINE = MEMORY - SELECT ticketFk, taxableBase, SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax,code - FROM tmp.ticketTax - GROUP BY ticketFk, code; - - DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; - DROP TEMPORARY TABLE IF EXISTS tmp.addressTaxArea; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketGetTax__2` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketGetTax__2`() - READS SQL DATA -BEGIN - CALL ticket_getTax(NULL); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketGetTotal` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -80348,8 +67900,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketGetTotal`() BEGIN @@ -80380,6 +67930,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketGetVisibleAvailable` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -80387,8 +67939,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketGetVisibleAvailable`( vTicket INT) @@ -80405,10 +67955,10 @@ BEGIN WHERE t.id = vTicket; IF vAlertLevel IS NULL OR vAlertLevel = 0 THEN - IF vShipped >= util.VN_CURDATE() THEN + IF vShipped >= vn.VN_CURDATE() THEN CALL cache.available_refresh(vAvailableCalc, FALSE, vWarehouse, vShipped); END IF; - IF vShipped = util.VN_CURDATE() THEN + IF vShipped = vn.VN_CURDATE() THEN CALL cache.visible_refresh(vVisibleCalc, FALSE, vWarehouse); END IF; END IF; @@ -80426,6 +67976,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketManaToPromo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -80433,35 +67985,35 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketManaToPromo`(vTicketFk INT) -BEGIN - - DECLARE vManaComponent INT; - - DECLARE vPromoComponent INT; - - SELECT id INTO vManaComponent - FROM vn.component c - WHERE c.code = 'mana'; - - SELECT id INTO vPromoComponent - FROM vn.component c - WHERE c.code = 'floramondoPromo'; - - UPDATE vn.saleComponent sc - JOIN vn.sale s ON s.id = sc.saleFk - SET componentFk = vPromoComponent - WHERE componentFk = vManaComponent - AND s.ticketFk = vTicketFk; +BEGIN + + DECLARE vManaComponent INT; + + DECLARE vPromoComponent INT; + + SELECT id INTO vManaComponent + FROM vn.component c + WHERE c.code = 'mana'; + + SELECT id INTO vPromoComponent + FROM vn.component c + WHERE c.code = 'floramondoPromo'; + + UPDATE vn.saleComponent sc + JOIN vn.sale s ON s.id = sc.saleFk + SET componentFk = vPromoComponent + WHERE componentFk = vManaComponent + AND s.ticketFk = vTicketFk; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketMissed_List` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -80469,8 +68021,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketMissed_List`(vTicketFk INT) BEGIN @@ -80524,6 +68074,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketNotInvoicedByClient` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -80531,8 +68083,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketNotInvoicedByClient`(vClientFk INT) BEGIN @@ -80567,6 +68117,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketObservation_addNewBorn` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -80574,101 +68126,32 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `ticketObservation_addNewBorn`(vTicketFk INT) -BEGIN - - /** - * Inserta observaciones para los tickets con clientes nuevos o recuperados - * - * @param vTicketFk Identificador de vn.ticket - */ - - DECLARE vDescription VARCHAR(20) DEFAULT '¡Cliente NUEVO! '; - +BEGIN + + /** + * Inserta observaciones para los tickets con clientes nuevos o recuperados + * + * @param vTicketFk Identificador de vn.ticket + */ + + DECLARE vDescription VARCHAR(20) DEFAULT '¡Cliente NUEVO! '; + INSERT INTO vn.ticketObservation(ticketFk, observationTypeFk, description) SELECT vTicketFk, ot.id, vDescription FROM vn.observationType ot WHERE ot.hasNewBornMessage ON DUPLICATE KEY UPDATE description = CONCAT(vDescription, ticketObservation.description); - + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketPackagingRecovery__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketPackagingRecovery__`() -BEGIN - - /* Recupera los embalajes que han caido en el cliente 31 */ - - DECLARE done BOOL DEFAULT FALSE; - DECLARE vClientFk INT; - DECLARE vTicketFk INT; - DECLARE vTicketNewFk INT; - DECLARE vWarehouseFk INT; - DECLARE vShipped DATE; - DECLARE vCompanyFk INT; - - DECLARE rs CURSOR FOR - SELECT DISTINCT tp.ticketFk, a.clientFk, t.warehouseFk, t.shipped, t.companyFk - FROM ticket t - JOIN ticketPackaging tp ON t.id = tp.ticketFk - JOIN address a ON a.id = t.addressFk - WHERE t.clientFk = 31 - AND t.shipped > '2001-01-01'; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - OPEN rs; - - FETCH rs INTO vTicketFk, vClientFk, vWarehouseFk, vShipped, vCompanyFk; - - WHILE NOT done DO - - CALL vn.ticket_add(vClientFk, - vShipped, - vWarehouseFk, - vCompanyFk, - NULL, - NULL, - NULL, - vShipped, - account.userGetId(), - TRUE, - vTicketNewFk); - - UPDATE vn.ticketPackaging set ticketFk = vTicketNewFk WHERE ticketFk = vTicketFk; - - CALL vn.ticketStateUpdate(vTicketNewFk, 'DELIVERED'); - - INSERT INTO vn.sale(ticketFk, itemFk, concept) VALUES(vTicketNewFk,90,CONCAT('Embalajes ',vTicketFk)); - - FETCH rs INTO vTicketFk, vClientFk, vWarehouseFk, vShipped, vCompanyFk; - - END WHILE; - - CLOSE rs; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketParking_findSkipped` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -80676,76 +68159,107 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketParking_findSkipped`(vTicketFk INT, vItemPackingTypeFk VARCHAR(1)) -BEGIN - -/** - * Averigua los tickets que se han saltado por un error en el proceso encajado - * @param vTicketFk Ticket - * @param vItemPackingTypeFk Modo de encajado - * @return un select con los tickets afectados - */ - - DECLARE vParkingFk INT; - DECLARE vParked DATETIME; - DECLARE vLevel INT; - DECLARE vWagon INT; - DECLARE vCollectionFk INT; - - SELECT IFNULL(`level`,0), IFNULL(`wagon`,0),IFNULL(collectionFk,0) - INTO vLevel, vWagon, vCollectionFk - FROM vn.ticketCollection tc - JOIN vn.collection c ON c.id = tc.collectionFk AND c.itemPackingTypeFk = vItemPackingTypeFk - WHERE ticketFk = vTicketFk - ORDER BY c.id DESC - LIMIT 1; - - SELECT created, parkingFk - INTO vParked, vParkingFk - FROM vn.ticketParking tp - JOIN vn.parking p ON p.id = tp.parkingFk - JOIN vn.sector s ON s.id = p.sectorFk - WHERE ticketFk = vTicketFk - AND s.itemPackingTypeFk = vItemPackingTypeFk - AND s.isPackagingArea ; - - SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' ', tc.wagon, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia - FROM vn.ticketParking tp - JOIN vn.parking p ON p.id = tp.parkingFk - JOIN vn.sector sc ON sc.id = p.sectorFk - LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk - JOIN vn.ticketStateToday tst ON tst.ticket = tp.ticketFk - JOIN vn.ticket t ON t.id = tp.ticketFk - JOIN vn.zone z ON z.id = t.zoneFk - JOIN vn.agencyMode am ON am.id = z.agencyModeFk - JOIN vn.state s ON s.id = tst.state - WHERE (s.alertLevel < 2 - AND tp.parkingFk = vParkingFk - AND sc.isPackagingArea - AND ( - ( IFNULL(tc.collectionFk,-1) != IFNULL(@vCollectionFk,0) AND tp.created < vParked ) - OR - ( tc.collectionFk = vCollectionFk - AND (LEFT(tc.wagon,1) < LEFT(vWagon,1) - OR (LEFT(tc.wagon,1) = LEFT(vWagon,1) AND LEFT(tc.level,1) < LEFT(vLevel,1))) - ) - ) - ) -- Etiquetas que no se han escaneado y ya estamos con una posterior - OR - (s.alertLevel > 1 - AND tp.parkingFk = vParkingFk - AND sc.isPackagingArea - AND tp.created < vParked - AND t.packages <=> 0); +BEGIN + +/** + * Averigua los tickets que se han saltado por un error en el proceso encajado + * @param vTicketFk Ticket + * @param vItemPackingTypeFk Modo de encajado + * @return un select con los tickets afectados + */ + + DECLARE vParkingFk INT; + DECLARE vParked DATETIME; + DECLARE vLevel INT; + DECLARE vWagon INT; + DECLARE vCollectionFk INT; + + SELECT IFNULL(`level`,0), IFNULL(`wagon`,0),IFNULL(collectionFk,0) + INTO vLevel, vWagon, vCollectionFk + FROM vn.ticketCollection tc + JOIN vn.collection c ON c.id = tc.collectionFk AND c.itemPackingTypeFk = vItemPackingTypeFk + WHERE ticketFk = vTicketFk + ORDER BY c.id DESC + LIMIT 1; + + SELECT created, parkingFk + INTO vParked, vParkingFk + FROM vn.ticketParking tp + JOIN vn.parking p ON p.id = tp.parkingFk + JOIN vn.sector s ON s.id = p.sectorFk + WHERE ticketFk = vTicketFk + AND s.itemPackingTypeFk = vItemPackingTypeFk + AND s.isPackagingArea ; + + SELECT tp.ticketFk, CONCAT(tc.collectionFk, ' ', tc.wagon, ' - ', tc.level) coleccion, tp.created, p.code, am.name as Agencia + FROM vn.ticketParking tp + JOIN vn.parking p ON p.id = tp.parkingFk + JOIN vn.sector sc ON sc.id = p.sectorFk + LEFT JOIN vn.ticketCollection tc ON tc.ticketFk = tp.ticketFk + JOIN vn.ticketStateToday tst ON tst.ticket = tp.ticketFk + JOIN vn.ticket t ON t.id = tp.ticketFk + JOIN vn.zone z ON z.id = t.zoneFk + JOIN vn.agencyMode am ON am.id = z.agencyModeFk + JOIN vn.state s ON s.id = tst.state + WHERE (s.alertLevel < 2 + AND tp.parkingFk = vParkingFk + AND sc.isPackagingArea + AND ( + ( IFNULL(tc.collectionFk,-1) != IFNULL(@vCollectionFk,0) AND tp.created < vParked ) + OR + ( tc.collectionFk = vCollectionFk + AND (LEFT(tc.wagon,1) < LEFT(vWagon,1) + OR (LEFT(tc.wagon,1) = LEFT(vWagon,1) AND LEFT(tc.level,1) < LEFT(vLevel,1))) + ) + ) + ) -- Etiquetas que no se han escaneado y ya estamos con una posterior + OR + (s.alertLevel > 1 + AND tp.parkingFk = vParkingFk + AND sc.isPackagingArea + AND tp.created < vParked + AND t.packages <=> 0); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticketRefund_beforeUpsert` */; +/*!50003 SET @saved_cs_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketRefund_beforeUpsert`(vRefundTicketFk INT, vOriginalTicketFk INT) +BEGIN + DECLARE vAlreadyExists BOOLEAN DEFAULT FALSE; + + IF vRefundTicketFk = vOriginalTicketFk THEN + CALL util.throw('Original ticket and refund ticket has same id'); + END IF; + + SELECT COUNT(*) INTO vAlreadyExists + FROM ticketRefund + WHERE refundTicketFk = vOriginalTicketFk; + + IF vAlreadyExists > 0 THEN + CALL util.throw('This ticket is already a refund'); + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketRequest_Add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -80753,8 +68267,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketRequest_Add`(vDescription VARCHAR(255), vQuantity INT, vPrice DOUBLE, vTicketFk INT, vBuyerCode VARCHAR(3)) BEGIN @@ -80778,181 +68290,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 `ticketSplitCounter` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketSplitCounter`(vTicketFk INT) -BEGIN - -SELECT CONCAT(OK,'/',Total, IF(OK = Total ,' LS','')) - FROM - ( - SELECT sum(if(l.Id_Movimiento != 0,1,0)) as OK, COUNT(*) as Total - FROM vn.sale s - LEFT JOIN movement_label l ON l.Id_Movimiento = s.id - WHERE ticketFk = vTicketFk - ) 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 `ticketStatePrevious__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketStatePrevious__`(vTicketFk INT) -BEGIN - - DECLARE vControlFk INT; - DECLARE vLastWorkerFk INT; - DECLARE vStateId INT; - - SELECT MAX(inter_id) INTO vControlFk - FROM vncontrol.inter - WHERE Id_Ticket = vTicketFk; - - IF (SELECT s.code - FROM vn.state s - JOIN vncontrol.inter i ON i.state_id = s.id - WHERE i.inter_id = vControlFk) - = 'PREVIOUS_PREPARATION' THEN - - SELECT inter_id, Id_Trabajador - INTO vControlFk,vLastWorkerFk - FROM vncontrol.inter i - JOIN vn.state s ON i.state_id = s.id - WHERE Id_Ticket = vTicketFk - AND inter_id < vControlFk - AND s.code != 'PREVIOUS_PREPARATION' - ORDER BY inter_id DESC - LIMIT 1; - /* - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador, Id_Supervisor) - SELECT state_id, Id_Ticket, vLastWorkerFk, vn.getWorker() - FROM vncontrol.inter - WHERE inter_id = vControlFk; - */ - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador, Id_Supervisor) - SELECT s.nextStateFk, i.Id_Ticket, vLastWorkerFk, account.myUser_getId() - FROM vncontrol.inter i - JOIN vn.state s ON i.state_id = s.id - WHERE inter_id = vControlFk; - - SELECT state_id INTO vStateId - FROM vncontrol.inter - WHERE inter_id = vControlFk; - - END IF; - - /*DELETE FROM vn2008.Movimientos_mark - WHERE Id_Movimiento IN (SELECT Id_Movimiento FROM vn2008.Movimientos WHERE Id_Ticket = vTicketFk) - AND valor <> 1 - AND stateFk = 26; */ - - 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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketStateToday_setOnchecking__`(vParamFk INT) -BEGIN - /* - * @deprecated:utilizar ticketStateToday_setState - */ - - 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 */ ; -/*!50003 SET character_set_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_setOnPreviousChecking__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketStateToday_setOnPreviousChecking__`(vParamFk INT) -BEGIN - - /* - * @deprecated:utilizar ticketStateToday_setState - */ - - - /* - * Cambia el estado del ticket al estado de "control previa" - * - * @param vParamFk ticket a cambiar el estado - * - */ - DECLARE vAlertLevel INT; - - SELECT s.alertLevel INTO vAlertLevel - FROM state s - JOIN ticketStateToday tst ON tst.state = s.id - WHERE tst.ticket = vParamFk - LIMIT 1; - - IF vAlertLevel < 2 THEN - - CALL ticketStateUpdate(vParamFk, 'PREVIOUS_CONTROL'); - - 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 `ticketStateToday_setState` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -80960,39 +68299,39 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketStateToday_setState`(vTicketFk INT, vStateCode VARCHAR(45)) -BEGIN - - /* Modifica el estado de un ticket de hoy - * - * @param vTicketFk el id del ticket - * @param vStateCode estado a modificar del ticket - * - */ - - DECLARE vAlertLevel INT; - - SELECT s.alertLevel INTO vAlertLevel - FROM state s - JOIN ticketStateToday tst ON tst.state = s.id - WHERE tst.ticket = vTicketFk - LIMIT 1; - - IF vAlertLevel < 2 THEN - - CALL vn.ticket_setState(vTicketFk, vStateCode); - - END IF; - +BEGIN + + /* Modifica el estado de un ticket de hoy + * + * @param vTicketFk el id del ticket + * @param vStateCode estado a modificar del ticket + * + */ + + DECLARE vAlertLevel INT; + + SELECT s.alertLevel INTO vAlertLevel + FROM state s + JOIN ticketStateToday tst ON tst.state = s.id + WHERE tst.ticket = vTicketFk + LIMIT 1; + + IF vAlertLevel < 2 THEN + + CALL vn.ticket_setState(vTicketFk, vStateCode); + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketStateUpdate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -81000,8 +68339,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketStateUpdate`(vTicketFk INT, vStateCode VARCHAR(45)) BEGIN @@ -81032,6 +68369,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketToInvoiceByAddress` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -81039,8 +68378,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketToInvoiceByAddress`( vStarted DATE, @@ -81068,6 +68405,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketToInvoiceByDate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -81075,8 +68414,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketToInvoiceByDate`( vStarted DATE, @@ -81104,6 +68441,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketToInvoiceByRef` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -81111,8 +68450,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketToInvoiceByRef`(IN vInvoiceRef VARCHAR(15)) BEGIN @@ -81164,170 +68501,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 `ticketToPrePrepare` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketToPrePrepare`(IN vSaleGroupFk INT, IN vSectorFk INT) -BEGIN - -/* Devuelve las lineas de vn.sale para preparación previa según el saleGroup - * - * - * @param vSaleGroupFk Identificador de vn.saleGroup -*/ - DECLARE vIsResetCode BOOLEAN; - - SELECT (vSaleGroupFk = 2000000) INTO vIsResetCode; - - IF vIsResetCode THEN - - UPDATE vn.saleTracking st - JOIN vn.state s ON s.code = 'OK PREVIOUS' - JOIN vn.state s2 ON s2.id = st.stateFk - SET st.stateFk = s.id - WHERE workerFk = vn.getUser() - AND s2.code = 'PREVIOUS_PREPARATION'; - - ELSE - - UPDATE vn.saleTracking st - JOIN vn.saleGroupDetail sgd ON sgd.saleFk = st.saleFk - SET workerFk = vn.getUser() - WHERE sgd.saleGroupFk = vSaleGroupFk; - - UPDATE vn.saleGroup sg - SET sg.userFk = vn.getUser() - WHERE sg.id = vSaleGroupFk; - - SELECT s.ticketFk, - s.itemFk, - i.longName, - IFNULL(i.itemPackingTypeFk,' ') itemPackingTypeFk, - IFNULL(i.subName ,' ') subName, - s.quantity originalQuantity , - s.quantity, - w.code workerCode, - sgd.saleFk, - IFNULL(iss.quantity,0) pickedQuantity, - vSectorFk, - c.salesPersonFk - FROM vn.sale s - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id - JOIN vn.saleTracking st ON st.saleFk = s.id - JOIN vn.state stt ON stt.id = st.stateFk - JOIN vn.worker w ON w.id = st.workerFk - LEFT JOIN vn.itemShelvingSaleSum iss ON iss.saleFk = s.id - JOIN vn.ticket t ON t.id= s.ticketFk - JOIN vn.client c ON c.id=t.clientFk - WHERE st.workerFk = account.myUser_getId() - AND stt.code = 'PREVIOUS_PREPARATION'; - - 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 `ticketToPrePrepare__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketToPrePrepare__`(IN vIdTicket INT, IN viewAll BOOL, IN vSectorFk INT) -BEGIN - -/* Tickets de preparacion previa (artificial) 21/03/2021 PAK -*/ - -/* Tickets de preparacion previa (artificial) 21/03/2021 PAK -*/ - - DECLARE vIsResetCode BOOLEAN; - -IF viewAll IS true THEN - - SELECT (vIdTicket = 2000000) INTO vIsResetCode; - - IF vIsResetCode THEN - - UPDATE vn.saleTracking st - JOIN vn.state s ON s.code = 'OK PREVIOUS' - JOIN vncontrol.accion a ON a.accion_id = st.actionFk - JOIN vn.state s2 ON s2.id = st.stateFk - SET st.stateFk = s.id - WHERE workerFk = vn.getUser() - AND (a.accion = 'PRESACAR') - AND st.created > TIMESTAMPADD(HOUR, -10, util.VN_NOW()); - - ELSE - - UPDATE vn.saleTracking st - JOIN vn.salesToPrePrepare stpp ON stpp.Id_Movimiento_mark = st.id - SET workerFk = vn.getUser() - WHERE stpp.Id_Ticket = vIdTicket - AND stpp.isChecked = FALSE; - - SELECT stpp.Id_Ticket, - stpp.Id_Movimiento, - stpp.Id_Movimiento_mark, - stpp.Id_Trabjador, - stpp.Id_Article, - i.itemPackingTypeFk packingType, - stpp.Concepte Concepte, - stpp.subName, - stpp.Cantidad, - stpp.original_quantity, - stpp.Hora, - stpp.Departure, - stpp.Minuto, - stpp.agency_id, - stpp.warehouse_id, - stpp.province_id, - stpp.picked, - stpp.trabajador, - ispss.created, - ispss.sectorFk - FROM vn.salesToPrePrepare stpp - JOIN vn.worker w ON w.code = stpp.trabajador - LEFT JOIN vn.itemShelvingPlacementSupplyStock ispss - ON ispss.itemShelvingFk = ( SELECT itemShelvingFk - FROM vn.itemShelvingPlacementSupplyStock - WHERE itemFk = stpp.Id_Article - AND sectorFk = vSectorFk - ORDER BY parking ASC - LIMIT 1) - LEFT JOIN vn.parking p ON p.id = ispss.parkingFk - LEFT JOIN vn.item i ON i.id = stpp.Id_Article - JOIN vn.state s ON s.id = stpp.stateFk - WHERE w.id = vn.getUser() - AND stpp.created > util.VN_CURDATE() - AND s.code = 'PREVIOUS_PREPARATION' - ORDER BY p.pickingOrder, p.column ASC; - - END IF; - -END IF; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketTrackingAdd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -81335,8 +68510,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketTrackingAdd`(vTicketFk INT, vState VARCHAR(25) CHARSET UTF8, vWorkerFk INT) BEGIN @@ -81354,120 +68527,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 `ticketVolumeByDate_ventas_Artificial__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketVolumeByDate_ventas_Artificial__`(vDate DATE) -BEGIN - - DECLARE vDateStart DATETIME DEFAULT DATE(vDate); - DECLARE vDateEnd DATETIME DEFAULT util.dayEnd(vDate); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketVolumeByDate_Artificial; - - CREATE TEMPORARY TABLE tmp.ticketVolumeByDate_Artificial - ENGINE = MEMORY - SELECT s.ticketFk, - CAST(SUM(r.cm3 * s.quantity) / 1000000 AS DECIMAL(10,2)) as m3 - FROM sale s - JOIN bs.ventas v ON v.Id_Movimiento = s.id - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.sector sc ON sc.id = i.sectorFk - JOIN vn.ticket t on t.id = s.ticketFk - JOIN bi.rotacion r ON r.Id_Article = s.itemFk AND r.warehouse_id = t.warehouseFk - WHERE sc.description = 'Artificial' - AND t.shipped BETWEEN vDateStart AND vDateEnd - GROUP BY s.ticketFk; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketVolumeByDate_ventas__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketVolumeByDate_ventas__`(vDate DATE) -BEGIN - - DECLARE vDateStart DATETIME DEFAULT DATE(vDate); - DECLARE vDateEnd DATETIME DEFAULT util.dayEnd(vDate); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketVolumeByDate; - - CREATE TEMPORARY TABLE tmp.ticketVolumeByDate - ENGINE = MEMORY - SELECT s.ticketFk, - CAST(SUM(r.cm3 * s.quantity) / 1000000 AS DECIMAL(10,2)) as m3 - FROM sale s - JOIN bs.ventas v ON v.Id_Movimiento = s.id - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - JOIN vn.ticket t on t.id = s.ticketFk - JOIN bi.rotacion r ON r.Id_Article = s.itemFk AND r.warehouse_id = t.warehouseFk - WHERE ic.merchandise - AND t.shipped BETWEEN vDateStart AND vDateEnd - AND it.name NOT IN ('Accesorios Funerarios','Composiciones planta','Composición bajo pedido','Coronas y centros') - GROUP BY s.ticketFk; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `ticketVolumeByDate__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketVolumeByDate__`(vDate DATE) -BEGIN - - DECLARE vDateStart DATETIME DEFAULT DATE(vDate); - DECLARE vDateEnd DATETIME DEFAULT util.dayEnd(vDate); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketVolumeByDate; - - CREATE TEMPORARY TABLE tmp.ticketVolumeByDate - ENGINE = MEMORY - SELECT s.ticketFk, - CAST(SUM(ic.cm3delivery * s.quantity) / 1000000 AS DECIMAL(10,2)) as m3 - FROM sale s - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory c ON c.id = it.categoryFk - JOIN vn.ticket t on t.id = s.ticketFk - JOIN vn.itemCost ic ON ic.itemFk = s.itemFk AND ic.warehouseFk = t.warehouseFk - WHERE c.merchandise - AND t.shipped BETWEEN vDateStart AND vDateEnd - GROUP BY s.ticketFk; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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 */ ; @@ -81475,111 +68536,111 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_add`( - vClientId INT - ,vShipped DATE - ,vWarehouseFk INT - ,vCompanyFk INT - ,vAddressFk INT - ,vAgencyModeFk INT - ,vRouteFk INT - ,vlanded DATE - ,vUserId INT - ,vIsRequiredZone INT +CREATE DEFINER=`root`@`localhost` 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; - - IF (SELECT COUNT(*) FROM bs.clientNewBorn cnb - WHERE cnb.clientFk = vClientId - AND NOT cnb.isRookie) = 0 THEN - - CALL vn.ticketObservation_addNewBorn(vNewTicket); - - END IF; - - 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; +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; + + IF (SELECT COUNT(*) FROM bs.clientNewBorn cnb + WHERE cnb.clientFk = vClientId + AND NOT cnb.isRookie) = 0 THEN + + CALL vn.ticketObservation_addNewBorn(vNewTicket); + + END IF; + + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_administrativeCopy` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -81587,31 +68648,31 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_administrativeCopy`(vOriginalTicket INT, OUT vNewTicket INT) -BEGIN - - INSERT INTO vn.ticket(clientFk, addressFk, shipped, warehouseFk, companyFk, landed) - SELECT t.clientFk , t.addressFk , t.shipped ,w.id, t.companyFk , t.landed - FROM vn.ticket t - JOIN vn.warehouse w ON w.name = 'INVENTARIO' - WHERE t.id = vOriginalTicket; - - SELECT LAST_INSERT_ID() INTO vNewTicket; - - INSERT INTO vn.sale(ticketFk, itemFk, concept, quantity, price, discount) - SELECT vNewTicket, s.itemFk , s.concept , s.quantity , s.price , s.discount - FROM vn.sale s - WHERE s.ticketFk = vOriginalTicket; - +BEGIN + + INSERT INTO vn.ticket(clientFk, addressFk, shipped, warehouseFk, companyFk, landed) + SELECT t.clientFk , t.addressFk , t.shipped ,w.id, t.companyFk , t.landed + FROM vn.ticket t + JOIN vn.warehouse w ON w.name = 'INVENTARIO' + WHERE t.id = vOriginalTicket; + + SELECT LAST_INSERT_ID() INTO vNewTicket; + + INSERT INTO vn.sale(ticketFk, itemFk, concept, quantity, price, discount) + SELECT vNewTicket, s.itemFk , s.concept , s.quantity , s.price , s.discount + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_canAdvance` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -81619,8 +68680,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_canAdvance`(vDated DATE, vWarehouseFk INT) BEGIN @@ -81705,6 +68764,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_canMerge` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -81712,132 +68773,73 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_canMerge`(vDated DATE, vScopeDays INT, vLitersMax INT, vLinesMax INT, vWarehouseFk INT) -BEGIN -/** - * Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro - * - * @param vDated Fecha en cuestión - * @param vScopeDays Dias en el futuro a sondear - * @param vLitersMax Volumen máximo de los tickets a catapultar - * @param vLinesMax Número máximo de lineas de los tickets a catapultar - * @param vWarehouseFk Identificador de vn.warehouse - */ - SELECT sv.ticketFk , - GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt, - CAST(sum(litros) AS DECIMAL(10,0)) liters, - CAST(count(*) AS DECIMAL(10,0)) `lines`, - st.name state, - sub2.id ticketFuture, - sub2.shipped, - sub2.iptd tfIpt, - sub2.state tfState - FROM vn.saleVolume sv - JOIN vn.sale s ON s.id = sv.saleFk - JOIN vn.item i ON i.id = s.itemFk - JOIN vn.ticket t ON t.id = sv.ticketFk - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p ON p.id = a.provinceFk - JOIN vn.country c ON c.id = p.countryFk - JOIN vn.ticketState ts ON ts.ticketFk = t.id - JOIN vn.state st ON st.id = ts.stateFk - JOIN vn.alertLevel al ON al.id = ts.alertLevel - LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id - LEFT JOIN ( - SELECT * FROM ( - SELECT - t.addressFk , - t.id, - t.shipped, - st.name state, - GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) iptd - FROM vn.ticket t - JOIN vn.ticketState ts ON ts.ticketFk = t.id - JOIN vn.state st ON st.id = ts.stateFk - JOIN vn.sale s ON s.ticketFk = t.id - JOIN vn.item i ON i.id = s.itemFk - WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, vScopeDays,vDated) - AND util.dayend(TIMESTAMPADD(DAY, vScopeDays,vDated)) - AND t.warehouseFk = vWarehouseFk - GROUP BY t.id - ) sub - GROUP BY sub.addressFk - ) sub2 ON sub2.addressFk = t.addressFk AND t.id != sub2.id - WHERE t.shipped BETWEEN vDated AND util.dayend(vDated) - AND t.warehouseFk = vWarehouseFk - AND al.code = 'FREE' - AND tp.ticketFk IS NULL - GROUP BY sv.ticketFk - HAVING liters <= vLitersMax AND `lines` <= vLinesMax AND ticketFuture; +BEGIN +/** + * Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro + * + * @param vDated Fecha en cuestión + * @param vScopeDays Dias en el futuro a sondear + * @param vLitersMax Volumen máximo de los tickets a catapultar + * @param vLinesMax Número máximo de lineas de los tickets a catapultar + * @param vWarehouseFk Identificador de vn.warehouse + */ + SELECT sv.ticketFk , + GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) ipt, + CAST(sum(litros) AS DECIMAL(10,0)) liters, + CAST(count(*) AS DECIMAL(10,0)) `lines`, + st.name state, + sub2.id ticketFuture, + sub2.shipped, + sub2.iptd tfIpt, + sub2.state tfState + FROM vn.saleVolume sv + JOIN vn.sale s ON s.id = sv.saleFk + JOIN vn.item i ON i.id = s.itemFk + JOIN vn.ticket t ON t.id = sv.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.country c ON c.id = p.countryFk + JOIN vn.ticketState ts ON ts.ticketFk = t.id + JOIN vn.state st ON st.id = ts.stateFk + JOIN vn.alertLevel al ON al.id = ts.alertLevel + LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id + LEFT JOIN ( + SELECT * + FROM ( + SELECT + t.addressFk , + t.id, + t.shipped, + st.name state, + GROUP_CONCAT(DISTINCT i.itemPackingTypeFk ORDER BY i.itemPackingTypeFk) iptd + FROM vn.ticket t + JOIN vn.ticketState ts ON ts.ticketFk = t.id + JOIN vn.state st ON st.id = ts.stateFk + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, vScopeDays,vDated) + AND util.dayend(TIMESTAMPADD(DAY, vScopeDays,vDated)) + AND t.warehouseFk = vWarehouseFk + GROUP BY t.id + ) sub + GROUP BY sub.addressFk + ) sub2 ON sub2.addressFk = t.addressFk AND t.id != sub2.id + WHERE t.shipped BETWEEN vDated AND util.dayend(vDated) + AND t.warehouseFk = vWarehouseFk + AND al.code = 'FREE' + AND tp.ticketFk IS NULL + GROUP BY sv.ticketFk + HAVING liters <= vLitersMax AND `lines` <= vLinesMax AND ticketFuture; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_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_canMerge__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_canMerge__`(vDated DATE, vScopeDays INT, vLitersMax INT, vLinesMax INT, vWarehouseFk INT) -BEGIN - - /* Devuelve un listado de tickets susceptibles de fusionarse con otros tickets en el futuro - * - * @param vDated Fecha en cuestión - * @param vScopeDays Dias en el futuro a sondear - * @param vLitersMax Volumen máximo de los tickets a catapultar - * @param vLinesMax Número máximo de lineas de los tickets a catapultar - * @param vWarehouseFk Identificador de vn.warehouse - */ - - SELECT sv.ticketFk , - CAST(sum(litros) AS DECIMAL(10,0)) liters, - CAST(count(*) AS DECIMAL(10,0)) `lines`, - sub2.id ticketFuture, - sub2.shipped - FROM vn.saleVolume sv - JOIN vn.ticket t ON t.id = sv.ticketFk - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p ON p.id = a.provinceFk - JOIN vn.country c ON c.id = p.countryFk - JOIN vn.ticketState ts ON ts.ticketFk = t.id - JOIN vn.alertLevel al ON al.id = ts.alertLevel - LEFT JOIN vn.ticketParking tp ON tp.ticketFk = t.id - LEFT JOIN tmp.routeDayMove ra ON ra.routeFk = t.routeFk - LEFT JOIN ( - SELECT * FROM ( - SELECT t.addressFk , t.id, t.shipped - FROM vn.ticket t - WHERE t.shipped BETWEEN TIMESTAMPADD(DAY, vScopeDays,vDated) - AND util.dayend(TIMESTAMPADD(DAY, vScopeDays,vDated)) - AND t.warehouseFk = vWarehouseFk - ) sub - GROUP BY sub.addressFk - ) sub2 ON sub2.addressFk = t.addressFk AND t.id != sub2.id - WHERE t.shipped BETWEEN vDated AND util.dayend(vDated) - AND t.warehouseFk = vWarehouseFk - AND al.code = 'FREE' - AND tp.ticketFk IS NULL - AND ra.routeFk IS NULL - GROUP BY sv.ticketFk - HAVING liters <= vLitersMax AND `lines` <= vLinesMax AND ticketFuture; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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 */ ; @@ -81845,46 +68847,46 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` 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; - +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 */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_checkFullyControlled` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -81892,8 +68894,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_checkFullyControlled`(vWorkerFk INT, vTicketFk INT ) BEGIN @@ -81914,16 +68914,16 @@ BEGIN LEFT JOIN (SELECT tc.collectionFk FROM ticketCollection tc WHERE ticketFk = vTicketFk - AND tc.created >= util.VN_CURDATE() + AND tc.created >= vn.VN_CURDATE() )sub ON sub.collectionFk = tc.collectionFk WHERE ts.workerFk = vWorkerFk AND sub.collectionFk IS NULL - AND tc.created >= util.VN_CURDATE() + AND tc.created >= vn.VN_CURDATE() GROUP BY tc.collectionFk )sub ON sub.collectionFk = tc.collectionFk JOIN ticketState ts ON ts.ticketFk = t.id WHERE ts.code IN ('ON_PREPARATION', 'PREPARED', 'PREVIOUS_PREPARATION', 'OK PREVIOUS') - AND t.shipped >= util.VN_CURDATE() + AND t.shipped >= vn.VN_CURDATE() AND s.quantity <>0 LIMIT 1; @@ -81933,6 +68933,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_checkNoComponents` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -81940,8 +68942,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_checkNoComponents`(vShippedFrom DATETIME, vShippedTo DATETIME) BEGIN @@ -82011,6 +69011,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_Clone` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -82018,8 +69020,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_Clone`(vOriginalTicket INT, OUT vNewTicket INT) BEGIN @@ -82092,6 +69092,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_cloneWeekly` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -82099,8 +69101,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_cloneWeekly`(IN vWeek INT) BEGIN @@ -82124,7 +69124,7 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vIsDone = TRUE; - SET vYear = YEAR(util.VN_CURDATE()) + IF(vWeek < WEEK(util.VN_CURDATE()),1, 0); + SET vYear = YEAR(vn.VN_CURDATE()) + IF(vWeek < WEEK(vn.VN_CURDATE()),1, 0); OPEN rsTicket; myLoop: LOOP @@ -82176,7 +69176,7 @@ BEGIN vAgencyModeFk, NULL, vLanding, - account.userGetId(), + account.myUser_getId(), FALSE, vNewTicket); @@ -82242,6 +69242,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_close` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -82249,8 +69251,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_close`() BEGIN @@ -82358,133 +69358,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 `ticket_closeAll__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_closeAll__`() -BEGIN -/** - * Realiza el cierre de todos los - * tickets de la tabla tmp.ticketClosure. - * - * @param vTicketFk Id del ticket - */ - DECLARE vDone BOOL; - DECLARE vClientFk INT; - DECLARE vCurTicketFk INT; - DECLARE vIsTaxDataChecked BOOL; - DECLARE vCompanyFk INT; - DECLARE vShipped DATE; - DECLARE vNewInvoiceId INT; - DECLARE vHasDailyInvoice BOOL; - DECLARE vWithPackage BOOL; - DECLARE vHasToInvoice BOOL; - - DECLARE cur CURSOR FOR - SELECT ticketFk FROM tmp.ticketClosure; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - RESIGNAL; - END; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure2; - CREATE TEMPORARY TABLE tmp.ticketClosure2 - SELECT ticketFk FROM tmp.ticketClosure; - - INSERT INTO tmp.ticketClosure - SELECT id FROM stowaway s - JOIN tmp.ticketClosure2 tc ON s.shipFk = tc.ticketFk; - OPEN cur; - - proc: LOOP - SET vDone = FALSE; - - FETCH cur INTO vCurTicketFk; - - IF vDone THEN - LEAVE proc; - END IF; - - -- ticketClosure start - SELECT - c.id, - c.isTaxDataChecked, - t.companyFk, - t.shipped, - co.hasDailyInvoice, - w.isManaged, - c.hasToInvoice - INTO vClientFk, - vIsTaxDataChecked, - vCompanyFk, - vShipped, - vHasDailyInvoice, - vWithPackage, - vHasToInvoice - FROM ticket t - JOIN `client` c ON c.id = t.clientFk - JOIN province p ON p.id = c.provinceFk - JOIN country co ON co.id = p.countryFk - JOIN warehouse w ON w.id = t.warehouseFk - WHERE t.id = vCurTicketFk; - - INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity) - (SELECT vCurTicketFk, p.id, COUNT(*) - FROM expedition e - JOIN packaging p ON p.itemFk = e.itemFk - WHERE e.ticketFk = vCurTicketFk AND p.isPackageReturnable - AND vWithPackage - GROUP BY p.itemFk); - - -- No retornables o no catalogados - INSERT INTO sale (itemFk, ticketFk, concept, quantity, price, isPriceFixed) - (SELECT e.itemFk, vCurTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.itemFk, vClientFk), 1 - FROM expedition e - JOIN item i ON i.id = e.itemFk - LEFT JOIN packaging p ON p.itemFk = i.id - WHERE e.ticketFk = vCurTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0 - AND getSpecialPrice(e.itemFk, vClientFk) > 0 - GROUP BY e.itemFk); - - CALL vn.zonePromo_Make(); - - IF(vHasDailyInvoice) AND vHasToInvoice THEN - - -- Facturacion rapida - CALL ticketTrackingAdd(vCurTicketFk, 'DELIVERED', NULL); - -- Facturar si está contabilizado - IF vIsTaxDataChecked THEN - CALL invoiceOut_newFromClient( - vClientFk, - (SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')), - vShipped, - vCompanyFk, - NULL, - NULL, - vNewInvoiceId); - END IF; - ELSE - CALL ticketTrackingAdd(vCurTicketFk, (SELECT vn.getAlert3State(vCurTicketFk)), NULL); - END IF; - END LOOP; - - CLOSE cur; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_closeByTicket` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -82492,8 +69367,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_closeByTicket`(IN vTicketFk int) BEGIN @@ -82528,6 +69401,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_componentMakeUpdate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -82535,8 +69410,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_componentMakeUpdate`(IN vTicketFk INT, IN vClientFk INT, IN vNickname VARCHAR(50), IN vAgencyModeFk INT, @@ -82632,6 +69505,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_componentPreview` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -82639,8 +69514,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_componentPreview`( vTicketFk INT, @@ -82746,213 +69619,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 `ticket_componentPreview__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_componentPreview__`( - vTicketFk INT, - vLanded DATE, - vAddressFk INT, - vZoneFk INT, - vWarehouseFk SMALLINT) -BEGIN -/** - * Calcula los componentes de los articulos de un ticket - * - * @param vTicketFk id del ticket - * @param vLanded nueva fecha de entrega - * @param vAddressFk nuevo consignatario - * @param vZoneFk nueva zona - * @param vWarehouseFk nuevo warehouse - * - * @return tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) - */ - DECLARE vShipped DATE; - DECLARE vBuyOrderItem INT DEFAULT 100; - - DECLARE vHasDataChanged BOOL DEFAULT FALSE; - DECLARE vHasAddressChanged BOOL; - DECLARE vHasZoneChanged BOOL DEFAULT FALSE; - DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE; - - DECLARE vAddressTypeRateFk INT DEFAULT NULL; - DECLARE vAgencyModeTypeRateFk INT DEFAULT NULL; - - DECLARE vHasChangeAll BOOL DEFAULT FALSE; - - SELECT DATE(landed) <> vLanded, - addressFk <> vAddressFk, - zoneFk <> vZoneFk, - warehouseFk <> vWarehouseFk - INTO - vHasDataChanged, - vHasAddressChanged, - vHasZoneChanged, - vHasWarehouseChanged - FROM vn.ticket t - WHERE t.id = vTicketFk; - - IF vHasDataChanged OR vHasWarehouseChanged THEN - SET vHasChangeAll = TRUE; - END IF; - - IF vHasAddressChanged THEN - SET vAddressTypeRateFk = 5; - END IF; - - IF vHasZoneChanged THEN - SET vAgencyModeTypeRateFk = 6; - END IF; - - SELECT TIMESTAMPADD(DAY, -travelingDays, vLanded) INTO vShipped - FROM zone - WHERE id = vZoneFk; - - CALL buyUltimate(vWarehouseFk, vShipped); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY ( - SELECT - vWarehouseFk AS warehouseFk, - NULL AS available, - s.itemFk, - bu.buyFk - FROM sale s - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk - WHERE s.ticketFk = vTicketFk - AND s.itemFk != vBuyOrderItem - GROUP BY bu.warehouseFk, bu.itemFk); - - CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped); - - REPLACE INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) - SELECT t.warehouseFk, s.itemFk, sc.componentFk, sc.value - FROM saleComponent sc - JOIN sale s ON s.id = sc.saleFk - JOIN ticket t ON t.id = s.ticketFk - JOIN `component` c ON c.id = sc.componentFk - WHERE s.ticketFk = vTicketFk - AND (c.isRenewable = FALSE - OR - (NOT vHasChangeAll - AND (NOT (c.typeFk <=> vAddressTypeRateFk - OR c.typeFk <=> vAgencyModeTypeRateFk)))); - - SET @shipped = vShipped; - - DROP TEMPORARY TABLE - tmp.buyUltimate, - tmp.ticketLot; - - IF vShipped IS NULL THEN - CALL util.throw('NO_ZONE_AVAILABLE'); - END IF; - - IF vShipped < util.VN_CURDATE() THEN - CALL util.throw('ERROR_PAST_SHIPMENT'); - 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_componentUpdate__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_componentUpdate__`( - vTicketFk INT, - vClientFk INT, - vAgencyModeFk INT, - vAddressFk INT, - vZoneFk INT, - vWarehouseFk TINYINT, - vCompanyFk SMALLINT, - vShipped DATETIME, - vLanded DATE, - vIsDeleted BOOLEAN, - vHasToBeUnrouted BOOLEAN, - vOption INT) -BEGIN - DECLARE vPrice DECIMAL(10,2); - DECLARE vBonus DECIMAL(10,2); - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - START TRANSACTION; - - IF (SELECT addressFk FROM ticket WHERE id = vTicketFk) <> vAddressFk THEN - - UPDATE ticket t - JOIN address a ON a.id = vAddressFk - SET t.nickname = a.nickname - WHERE t.id = vTicketFk; - - END IF; - - CALL vn.zone_getShippedWarehouse(vlanded, vAddressFk, vAgencyModeFk); - - SELECT zoneFk, price, bonus INTO vZoneFk, vPrice, vBonus - FROM tmp.zoneGetShipped - WHERE shipped = vShipped AND warehouseFk = vWarehouseFk LIMIT 1; - - UPDATE ticket t - SET - t.clientFk = vClientFk, - t.agencyModeFk = vAgencyModeFk, - t.addressFk = vAddressFk, - t.zoneFk = vZoneFk, - t.zonePrice = vPrice, - t.zoneBonus = vBonus, - t.warehouseFk = vWarehouseFk, - t.companyFk = vCompanyFk, - t.landed = vLanded, - t.shipped = vShipped, - t.isDeleted = vIsDeleted - WHERE - t.id = vTicketFk; - - IF vHasToBeUnrouted THEN - UPDATE ticket t SET t.routeFk = NULL - WHERE t.id = vTicketFk; - END IF; - - IF vOption <> 8 THEN - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) - ENGINE = MEMORY - SELECT id AS saleFk, vWarehouseFk warehouseFk - FROM sale s WHERE s.ticketFk = vTicketFk; - - CALL ticketComponentUpdateSale (vOption); - - DROP TEMPORARY TABLE tmp.sale; - END IF; - COMMIT; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_DelayTruck` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -82960,51 +69628,51 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_DelayTruck`(vWarehouserFk INT, vHour INT, vMinute INT) -BEGIN - - DECLARE done INT DEFAULT FALSE; - DECLARE vTicketFk INT; - DECLARE cur1 CURSOR FOR SELECT ticketFk FROM tmp.ticket; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - CALL vn.productionControl(vWarehouserFk,0) ; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - SELECT ticketFk - FROM tmp.productionBuffer - WHERE shipped = curdate() - AND problem LIKE '%I:%' - AND (HH <= vHour OR HH = vHour AND mm < vMinute) - AND alertLevel = 0; - - OPEN cur1; - - read_loop: LOOP - - FETCH cur1 INTO vTicketFk; - - IF done THEN - LEAVE read_loop; - END IF; - - CALL vn.ticket_DelayTruckSplit(vTicketFk); - - END LOOP; - - CLOSE cur1; - +BEGIN + + DECLARE done INT DEFAULT FALSE; + DECLARE vTicketFk INT; + DECLARE cur1 CURSOR FOR SELECT ticketFk FROM tmp.ticket; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + CALL vn.productionControl(vWarehouserFk,0) ; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + SELECT ticketFk + FROM tmp.productionBuffer + WHERE shipped = vn.VN_CURDATE() + AND problem LIKE '%I:%' + AND (HH <= vHour OR HH = vHour AND mm < vMinute) + AND alertLevel = 0; + + OPEN cur1; + + read_loop: LOOP + + FETCH cur1 INTO vTicketFk; + + IF done THEN + LEAVE read_loop; + END IF; + + CALL vn.ticket_DelayTruckSplit(vTicketFk); + + END LOOP; + + CLOSE cur1; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_DelayTruckSplit` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -83012,8 +69680,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_DelayTruckSplit`(vTicketFk INT) BEGIN @@ -83071,6 +69737,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_doRecalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -83078,8 +69746,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_doRecalc`() proc: BEGIN @@ -83157,6 +69823,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_doRefund` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -83164,8 +69832,6 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_doRefund`(IN vOriginTicket INT, OUT vNewTicket INT) BEGIN @@ -83184,10 +69850,17 @@ BEGIN DECLARE vSaleNew INT; DECLARE vSaleMain INT; DECLARE vZoneFk INT; + DECLARE vDescription VARCHAR(50); + DECLARE vTaxClassFk INT; + DECLARE vTicketServiceTypeFk INT; - DECLARE vRsMainTicket CURSOR FOR + DECLARE cSales CURSOR FOR SELECT * FROM tmp.sale; + + DECLARE cTicketServices CURSOR FOR + SELECT * + FROM tmp.ticketService; DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1; @@ -83216,13 +69889,13 @@ BEGIN ) SELECT vCustomer, - util.VN_CURDATE(), + vn.VN_CURDATE(), vAddress, vRefundAgencyMode, a.nickname, vWarehouse, vCompany, - util.VN_CURDATE(), + vn.VN_CURDATE(), vZoneFk FROM address a WHERE a.id = vAddress; @@ -83230,8 +69903,8 @@ BEGIN SET vNewTicket = LAST_INSERT_ID(); SET vDone := 0; - OPEN vRsMainTicket ; - FETCH vRsMainTicket INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount; + OPEN cSales; + FETCH cSales INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount; WHILE NOT vDone DO @@ -83245,10 +69918,24 @@ BEGIN FROM vn.saleComponent WHERE saleFk = vSaleMain; - FETCH vRsMainTicket INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount; + FETCH cSales INTO vSaleMain, vItemFk, vQuantity, vConcept, vPrice, vDiscount; END WHILE; - CLOSE vRsMainTicket; + CLOSE cSales; + + SET vDone := 0; + OPEN cTicketServices; + FETCH cTicketServices INTO vDescription, vQuantity, vPrice, vTaxClassFk, vTicketServiceTypeFk; + + WHILE NOT vDone DO + + INSERT INTO vn.ticketService(description, quantity, price, taxClassFk, ticketFk, ticketServiceTypeFk) + VALUES(vDescription, vQuantity, vPrice, vTaxClassFk, vNewTicket, vTicketServiceTypeFk); + + FETCH cTicketServices INTO vDescription, vQuantity, vPrice, vTaxClassFk, vTicketServiceTypeFk; + + END WHILE; + CLOSE cTicketServices; INSERT INTO vn.ticketRefund(refundTicketFk, originalTicketFk) VALUES(vNewTicket, vOriginTicket); @@ -83259,6 +69946,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_getFromFloramondo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -83266,116 +69955,116 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `ticket_getFromFloramondo`(vDateFrom DATE, vDateTo DATE) -BEGIN - -/** - * Genera una tabla con la lista de tickets de Floramondo para una fecha determinada - * @param vDated Fecha de preparación de los pedidos - * @return tmp.ticketFloramondo(ticketFk, clientName, agencyName, freight, expeditionCount, margin, trolleys, pallets) - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketFloramondo; - CREATE TEMPORARY TABLE tmp.ticketFloramondo - (ticketFk INT PRIMARY KEY, - clientName VARCHAR(50), - agencyName VARCHAR(50), - freight DECIMAL(10,2) DEFAULT 0, - expeditionCount INT, - margin DECIMAL(10,3) DEFAULT 0, - trolleys INT DEFAULT 0, - shipped DATE, - pallets INT DEFAULT 0) - ENGINE = MEMORY; - - INSERT INTO tmp.ticketFloramondo(ticketFk, clientName, agencyName, shipped) - SELECT t.id ticketFk, t.nickname , am.name, t.shipped - FROM vn.ticket t - JOIN vn.agencyMode am ON am.id = t.agencyModeFk - JOIN vn.warehouse w ON w.id = t.warehouseFk AND w.code IN ('VNH','FLM') - AND t.shipped BETWEEN vDateFrom AND TIMESTAMPADD(HOUR, 23, vDateTo); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - (ticketFk INT(11) PRIMARY KEY) - SELECT ticketFk - FROM tmp.ticketFloramondo; - - -- Freight - UPDATE tmp.ticketFloramondo tf - JOIN (SELECT SUM(sc.value * s.quantity) freight, t.ticketFk - FROM vn.saleComponent sc - JOIN vn.component c ON c.id = sc.componentFk - JOIN vn.componentType ct ON ct.id = c.typeFk - JOIN vn.sale s ON s.id = sc.saleFk - JOIN tmp.ticket t ON t.ticketFk = s.ticketFk - WHERE ct.code = 'FREIGHT' - GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk - SET tf.freight = sb.freight; - - -- Freight service - UPDATE tmp.ticketFloramondo tf - JOIN (SELECT SUM(ts.price * ts.quantity) service, t.ticketFk - FROM vn.ticketService ts - JOIN tmp.ticket t ON t.ticketFk = ts.ticketFk - GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk - SET tf.freight = tf.freight + sb.service; - - -- Expedition Count - UPDATE tmp.ticketFloramondo tf - JOIN (SELECT COUNT(e.id) expeditionCount, t.ticketFk - FROM vn.expedition e - RIGHT JOIN tmp.ticket t ON t.ticketFk = e.ticketFk - GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk - SET tf.expeditionCount = sb.expeditionCount; - - -- Margin - UPDATE tmp.ticketFloramondo tf - JOIN (SELECT SUM(IF(ct.code = 'COST',sc.value, 0)) cost, - SUM(IF(ct.isMargin, sc.value, 0)) margin, - t.ticketFk - FROM vn.saleComponent sc - JOIN vn.component c ON c.id = sc.componentFk - JOIN vn.componentType ct ON ct.id = c.typeFk - JOIN vn.sale s ON s.id = sc.saleFk - JOIN tmp.ticket t ON t.ticketFk = s.ticketFk - GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk - SET tf.margin = sb.margin / sb.cost; - - -- Trolleys - UPDATE tmp.ticketFloramondo tf - JOIN (SELECT SUM(tp.quantity) trolleys, t.ticketFk - FROM vn.ticketPackaging tp - JOIN tmp.ticket t ON t.ticketFk = tp.ticketFk - JOIN vn.packaging p ON p.id = tp.packagingFk - WHERE p.isTrolley - GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk - SET tf.trolleys = sb.trolleys; - - -- Pallets - UPDATE tmp.ticketFloramondo tf - JOIN (SELECT SUM(tp.quantity) pallets, t.ticketFk - FROM vn.ticketPackaging tp - JOIN tmp.ticket t ON t.ticketFk = tp.ticketFk - JOIN vn.packaging p ON p.id = tp.packagingFk - WHERE p.isPallet - GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk - SET tf.pallets = sb.pallets; - - SELECT * FROM tmp.ticketFloramondo; - - DROP TEMPORARY TABLE tmp.ticket; - DROP TEMPORARY TABLE tmp.ticketFloramondo; - +BEGIN + +/** + * Genera una tabla con la lista de tickets de Floramondo para una fecha determinada + * @param vDated Fecha de preparación de los pedidos + * @return tmp.ticketFloramondo(ticketFk, clientName, agencyName, freight, expeditionCount, margin, trolleys, pallets) + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketFloramondo; + CREATE TEMPORARY TABLE tmp.ticketFloramondo + (ticketFk INT PRIMARY KEY, + clientName VARCHAR(50), + agencyName VARCHAR(50), + freight DECIMAL(10,2) DEFAULT 0, + expeditionCount INT, + margin DECIMAL(10,3) DEFAULT 0, + trolleys INT DEFAULT 0, + shipped DATE, + pallets INT DEFAULT 0) + ENGINE = MEMORY; + + INSERT INTO tmp.ticketFloramondo(ticketFk, clientName, agencyName, shipped) + SELECT t.id ticketFk, t.nickname , am.name, t.shipped + FROM vn.ticket t + JOIN vn.agencyMode am ON am.id = t.agencyModeFk + JOIN vn.warehouse w ON w.id = t.warehouseFk AND w.code IN ('VNH','FLM') + AND t.shipped BETWEEN vDateFrom AND TIMESTAMPADD(HOUR, 23, vDateTo); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + (ticketFk INT(11) PRIMARY KEY) + SELECT ticketFk + FROM tmp.ticketFloramondo; + + -- Freight + UPDATE tmp.ticketFloramondo tf + JOIN (SELECT SUM(sc.value * s.quantity) freight, t.ticketFk + FROM vn.saleComponent sc + JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk + JOIN vn.sale s ON s.id = sc.saleFk + JOIN tmp.ticket t ON t.ticketFk = s.ticketFk + WHERE ct.code = 'FREIGHT' + GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk + SET tf.freight = sb.freight; + + -- Freight service + UPDATE tmp.ticketFloramondo tf + JOIN (SELECT SUM(ts.price * ts.quantity) service, t.ticketFk + FROM vn.ticketService ts + JOIN tmp.ticket t ON t.ticketFk = ts.ticketFk + GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk + SET tf.freight = tf.freight + sb.service; + + -- Expedition Count + UPDATE tmp.ticketFloramondo tf + JOIN (SELECT COUNT(e.id) expeditionCount, t.ticketFk + FROM vn.expedition e + RIGHT JOIN tmp.ticket t ON t.ticketFk = e.ticketFk + GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk + SET tf.expeditionCount = sb.expeditionCount; + + -- Margin + UPDATE tmp.ticketFloramondo tf + JOIN (SELECT SUM(IF(ct.code = 'COST',sc.value, 0)) cost, + SUM(IF(ct.isMargin, sc.value, 0)) margin, + t.ticketFk + FROM vn.saleComponent sc + JOIN vn.component c ON c.id = sc.componentFk + JOIN vn.componentType ct ON ct.id = c.typeFk + JOIN vn.sale s ON s.id = sc.saleFk + JOIN tmp.ticket t ON t.ticketFk = s.ticketFk + GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk + SET tf.margin = sb.margin / sb.cost; + + -- Trolleys + UPDATE tmp.ticketFloramondo tf + JOIN (SELECT SUM(tp.quantity) trolleys, t.ticketFk + FROM vn.ticketPackaging tp + JOIN tmp.ticket t ON t.ticketFk = tp.ticketFk + JOIN vn.packaging p ON p.id = tp.packagingFk + WHERE p.isTrolley + GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk + SET tf.trolleys = sb.trolleys; + + -- Pallets + UPDATE tmp.ticketFloramondo tf + JOIN (SELECT SUM(tp.quantity) pallets, t.ticketFk + FROM vn.ticketPackaging tp + JOIN tmp.ticket t ON t.ticketFk = tp.ticketFk + JOIN vn.packaging p ON p.id = tp.packagingFk + WHERE p.isPallet + GROUP BY t.ticketFk) sb ON sb.ticketFk = tf.ticketFk + SET tf.pallets = sb.pallets; + + SELECT * FROM tmp.ticketFloramondo; + + DROP TEMPORARY TABLE tmp.ticket; + DROP TEMPORARY TABLE tmp.ticketFloramondo; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_getMovable` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -83383,10 +70072,8 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `ticket_getMovable`(vTicketFk INT, vDatedNew DATETIME, vWarehouseFk INT) +CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_getMovable`(vTicketFk INT, vDatedNew DATETIME, vWarehouseFk INT) BEGIN /** * Cálcula el stock movible para los artículos de un ticket @@ -83433,6 +70120,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_getProblems` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -83440,8 +70129,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_getProblems`(IN vIsTodayRelative tinyint(1)) BEGIN @@ -83498,65 +70185,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 `ticket_getProblems__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_getProblems__`(IN vIsTodayRelative tinyint(1)) -BEGIN -/** - * Calcula los problemas para un conjunto de tickets. - * Agrupados por ticket - * - * @table tmp.sale_getProblems(ticketFk, clientFk, warehouseFk, shipped) Identificadores de los tickets a calcular - * @return tmp.ticket_problems - */ - CALL sale_getProblems(vIsTodayRelative); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket_problems; - CREATE TEMPORARY TABLE tmp.ticket_problems - (PRIMARY KEY (ticketFk)) - ENGINE = MEMORY - SELECT - ticketFk, - MAX(p.isFreezed) AS isFreezed, - MAX(p.risk) AS risk, - MAX(p.hasHighRisk) AS hasHighRisk, - MAX(p.hasTicketRequest) AS hasTicketRequest, - MIN(p.isAvailable) AS isAvailable, - MAX(p.itemShortage) AS itemShortage, - MIN(p.isTaxDataChecked) AS isTaxDataChecked, - MAX(p.hasComponentLack) AS hasComponentLack, - MAX(p.isTooLittle) AS isTooLittle, - 0 AS totalProblems - FROM tmp.sale_problems p - GROUP BY ticketFk; - - UPDATE tmp.ticket_problems tp - SET tp.totalProblems = ( - (tp.isFreezed) + - IF(tp.risk, TRUE, FALSE) + - (tp.hasTicketRequest) + - (tp.isAvailable = 0) + - (tp.isTaxDataChecked = 0) + - (tp.hasComponentLack) + - (tp.isTooLittle) - ); - - DROP TEMPORARY TABLE - tmp.sale_problems; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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_getShip` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -83564,8 +70194,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_getShip`(vTicketFk INT) BEGIN @@ -83577,6 +70205,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_getSplitList` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -83584,8 +70214,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_getSplitList`(vDated DATE, vHour TIME, vWarehouseFk INT) BEGIN @@ -83599,7 +70227,7 @@ BEGIN DECLARE vAvailableCache INT; DECLARE vVisibleCache INT; - CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouseFk, util.VN_CURDATE()); + CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouseFk, vn.VN_CURDATE()); CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouseFk); CALL `vn`.`zoneClosure_recalc`(); @@ -83626,7 +70254,7 @@ BEGIN AND s.isPicked = FALSE AND s.reserved = FALSE AND ic.merchandise = TRUE - AND t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND t.shipped BETWEEN vn.VN_CURDATE() AND util.dayend(vn.VN_CURDATE()) AND NOT i.generic AND t.warehouseFk = vWarehouseFk; @@ -83645,7 +70273,7 @@ BEGIN AND s.isPicked = FALSE AND s.reserved = FALSE AND ic.merchandise = TRUE - AND t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND t.shipped BETWEEN vn.VN_CURDATE() AND util.dayend(vn.VN_CURDATE()) AND NOT i.generic AND t.warehouseFk = vWarehouseFk; @@ -83666,7 +70294,7 @@ BEGIN AND s.isPicked = FALSE AND s.reserved = FALSE AND ic.merchandise = TRUE - AND t.shipped BETWEEN util.VN_CURDATE() AND util.dayend(util.VN_CURDATE()) + AND t.shipped BETWEEN vn.VN_CURDATE() AND util.dayend(vn.VN_CURDATE()) AND NOT i.generic AND t.warehouseFk = vWarehouseFk; @@ -83713,8 +70341,8 @@ BEGIN LEFT JOIN vn.ticketState tst ON tst.ticketFk = t.id LEFT JOIN vn.state st2 ON st2.id = tst.stateFk WHERE (t.id IS NULL - OR (vDated > util.VN_CURDATE()) - OR (vDated = util.VN_CURDATE() AND vHour >= zc.`hour`)) + OR (vDated > vn.VN_CURDATE()) + OR (vDated = vn.VN_CURDATE() AND vHour >= zc.`hour`)) AND ts.etd <= vHour GROUP BY ts.ticketFk, t.id ORDER BY ts.etd, ts.ticketFk; @@ -83727,6 +70355,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_getTax` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -83734,8 +70364,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_getTax`(IN vTaxArea VARCHAR(25)) BEGIN @@ -83843,118 +70471,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 `ticket_getTax__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_getTax__`(vTaxArea VARCHAR(25)) - READS SQL DATA -BEGIN -/** - * Calcula la base imponible, el IVA y el recargo de equivalencia para - * un conjunto de tickets. - * - * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular - * @return tmp.ticketAmount - * @return tmp.ticketTax Impuesto desglosado para cada ticket. - */ - DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; - CREATE TEMPORARY TABLE tmp.addressCompany - (INDEX (addressFk, companyFk)) - ENGINE = MEMORY - SELECT DISTINCT t.addressFk, t.companyFk - FROM tmp.ticket tmpTicket - JOIN ticket t ON t.id = tmpTicket.ticketFk; - - CALL addressTaxArea (); - - IF vTaxArea > '' THEN - UPDATE tmp.addressTaxArea - SET areaFk = vTaxArea; - END IF; - /** Solo se calcula la base imponible (taxableBase) y el impuesto se calculará posteriormente - * No se debería cambiar el sistema por problemas con los decimales - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax; - CREATE TEMPORARY TABLE tmp.ticketTax - (INDEX (ticketFk)) - ENGINE = MEMORY - SELECT * FROM ( - SELECT tmpTicket.ticketFk, - bp.pgcFk, - SUM(s.quantity * s.price * (100 - s.discount)/100 ) AS taxableBase, - pgc.rate, - tc.code, - bp.priority - FROM tmp.ticket tmpTicket - JOIN sale s ON s.ticketFk = tmpTicket.ticketFk - JOIN item i ON i.id = s.itemFk - JOIN ticket t ON t.id = tmpTicket.ticketFk - JOIN supplier su ON su.id = t.companyFk - JOIN tmp.addressTaxArea ata - ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk - JOIN itemTaxCountry itc - ON itc.itemFk = i.id AND itc.countryFk = su.countryFk - JOIN bookingPlanner bp - ON bp.countryFk = su.countryFk - AND bp.taxAreaFk = ata.areaFk - AND bp.taxClassFk = itc.taxClassFk - JOIN pgc ON pgc.code = bp.pgcFk - JOIN taxClass tc ON tc.id = bp.taxClassFk - GROUP BY tmpTicket.ticketFk, pgc.code,pgc.rate - HAVING taxableBase != 0) t - ORDER BY priority; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketServiceTax; - CREATE TEMPORARY TABLE tmp.ticketServiceTax - (INDEX (ticketFk)) - ENGINE = MEMORY - SELECT tt.ticketFk, - SUM(ts.quantity * ts.price) AS taxableBase, - pgc.rate, - tc.code - FROM tmp.ticketTax tt - JOIN ticketService ts ON ts.ticketFk = tt.ticketFk - JOIN ticket t ON t.id = tt.ticketFk - JOIN supplier su ON su.id = t.companyFk - JOIN tmp.addressTaxArea ata - ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk - JOIN bookingPlanner bp - ON bp.countryFk = su.countryFk - AND bp.taxAreaFk = ata.areaFk - AND bp.taxClassFk = ts.taxClassFk - JOIN pgc ON pgc.code = bp.pgcFk AND pgc.rate = tt.rate - JOIN taxClass tc ON tc.id = bp.taxClassFk - GROUP BY tt.ticketFk, tt.code,tt.rate - HAVING taxableBase != 0; - - UPDATE tmp.ticketTax tt - JOIN tmp.ticketServiceTax ts ON tt.ticketFk = ts.ticketFk AND tt.code = ts.code AND tt.rate = ts.rate - SET tt.taxableBase = tt.taxableBase + ts.taxableBase; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount; - CREATE TEMPORARY TABLE tmp.ticketAmount - (INDEX (ticketFk)) - ENGINE = MEMORY - SELECT ticketFk, taxableBase, SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax,code - FROM tmp.ticketTax - GROUP BY ticketFk, code; - - DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; - DROP TEMPORARY TABLE IF EXISTS tmp.addressTaxArea; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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_insertZone` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -83962,8 +70480,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_insertZone`() BEGIN @@ -83998,6 +70514,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_merge` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -84005,34 +70523,34 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_merge`(vSelf INT, vTicketTargetFk INT) -BEGIN - - /** - * Fusiona el primer ticket al segundo - * - * @param vSelf Número de ticket a fusionar - * @param vTicketTargetFk Ticket destino - * - */ - - UPDATE vn.sale s - SET s.ticketFk = vTicketTargetFk - WHERE s.ticketFk = vSelf; - - UPDATE vn.ticket t - SET t.shipped = TIMESTAMPADD(YEAR, - YEAR(util.VN_NOW()) MOD 2000, t.shipped ) - WHERE t.id = vSelf; - +BEGIN + + /** + * Fusiona el primer ticket al segundo + * + * @param vSelf Número de ticket a fusionar + * @param vTicketTargetFk Ticket destino + * + */ + + UPDATE vn.sale s + SET s.ticketFk = vTicketTargetFk + WHERE s.ticketFk = vSelf; + + UPDATE vn.ticket t + SET t.shipped = TIMESTAMPADD(YEAR, - YEAR(vn.VN_NOW()) MOD 2000, t.shipped ) + WHERE t.id = vSelf; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_priceDifference` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -84040,8 +70558,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_priceDifference`( vTicketFk INT, @@ -84090,6 +70606,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_recalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -84097,38 +70615,38 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_recalc`(vTicketId INT) -BEGIN -/** - * Calcula y guarda el total con/sin IVA en un ticket. - * - * @param vTicketId Identificador del ticket - */ - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - ENGINE = MEMORY - SELECT vTicketId ticketFk; - - CALL ticketGetTotal; - - UPDATE ticket t - JOIN tmp.ticketTotal tt ON tt.ticketFk = t.id - SET t.totalWithVat = tt.total, - t.totalWithoutVat = tt.totalWithoutVat; - - DROP TEMPORARY TABLE - tmp.ticket, - tmp.ticketTotal; +BEGIN +/** + * Calcula y guarda el total con/sin IVA en un ticket. + * + * @param vTicketId Identificador del ticket + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + ENGINE = MEMORY + SELECT vTicketId ticketFk; + + CALL ticketGetTotal; + + UPDATE ticket t + JOIN tmp.ticketTotal tt ON tt.ticketFk = t.id + SET t.totalWithVat = tt.total, + t.totalWithoutVat = tt.totalWithoutVat; + + DROP TEMPORARY TABLE + tmp.ticket, + tmp.ticketTotal; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_recalcComponents` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -84136,296 +70654,101 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_recalcComponents`(IN vTicketFk BIGINT, vIsTicketEditable BOOLEAN) -proc: BEGIN - -/** - * Este procedimiento recalcula los componentes de un ticket, - * eliminando los componentes existentes e insertandolos de nuevo - * - * @param vTicketFk Id del ticket - * @param vIsTicketEditable si no se quiere forzar llamar con NULL - */ - DECLARE vShipped DATE; - DECLARE vWarehouseFk SMALLINT; - DECLARE vAgencyModeFk INT; - DECLARE vAddressFk INT; - DECLARE vLanded DATE; - DECLARE vZoneFk INTEGER; - - IF vIsTicketEditable IS NULL THEN - SELECT IFNULL(ts.alertLevel,0) = 0 AND IFNULL(t.refFk,'') = '' - INTO vIsTicketEditable - FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket - WHERE id = vTicketFk; - END IF; - - SELECT t.warehouseFk, - t.shipped, - t.addressFk, - t.agencyModeFk, - t.landed, - t.zoneFk - INTO vWarehouseFk, vShipped, vAddressFk, vAgencyModeFk, vLanded, vZoneFk - FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket - WHERE t.id = vTicketFk; - - CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE); - - IF (SELECT COUNT(*) FROM tmp.zoneGetLanded LIMIT 1) = 0 THEN - CALL util.throw('There is no zone for these parameters'); - END IF; - - IF vLanded IS NULL OR vZoneFk IS NULL THEN - - UPDATE ticket t - SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) - WHERE t.id = vTicketFk AND t.landed IS NULL; - - IF vZoneFk IS NULL THEN - SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; - UPDATE ticket t - SET t.zoneFk = vZoneFk - WHERE t.id = vTicketFk AND t.zoneFk IS NULL; - END IF; - - END IF; - - DROP TEMPORARY TABLE tmp.zoneGetLanded; - - -- rellena la tabla buyUltimate con la ultima compra - CALL buyUltimate (vWarehouseFk, vShipped); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouseFk warehouseFk, NULL available, - s.itemFk, bu.buyFk, vZoneFk zoneFk - FROM sale s - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk - WHERE s.ticketFk = vTicketFk - GROUP BY s.itemFk; - - CALL catalog_componentPrepare(); - CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT id saleFk, vWarehouseFk warehouseFk - FROM sale s - WHERE s.ticketFk = vTicketFk; - - -- si el ticket esta facturado, respeta los precios - CALL ticketComponentUpdateSale(IF(vIsTicketEditable, 1, 6)); - - CALL catalog_componentPurge(); - DROP TEMPORARY TABLE - tmp.buyUltimate, - tmp.sale; +proc: BEGIN + +/** + * Este procedimiento recalcula los componentes de un ticket, + * eliminando los componentes existentes e insertandolos de nuevo + * + * @param vTicketFk Id del ticket + * @param vIsTicketEditable si no se quiere forzar llamar con NULL + */ + DECLARE vShipped DATE; + DECLARE vWarehouseFk SMALLINT; + DECLARE vAgencyModeFk INT; + DECLARE vAddressFk INT; + DECLARE vLanded DATE; + DECLARE vZoneFk INTEGER; + + IF vIsTicketEditable IS NULL THEN + SELECT IFNULL(ts.alertLevel,0) = 0 AND IFNULL(t.refFk,'') = '' + INTO vIsTicketEditable + FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket + WHERE id = vTicketFk; + END IF; + + SELECT t.warehouseFk, + t.shipped, + t.addressFk, + t.agencyModeFk, + t.landed, + t.zoneFk + INTO vWarehouseFk, vShipped, vAddressFk, vAgencyModeFk, vLanded, vZoneFk + FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket + WHERE t.id = vTicketFk; + + CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE); + + IF (SELECT COUNT(*) FROM tmp.zoneGetLanded LIMIT 1) = 0 THEN + CALL util.throw('There is no zone for these parameters'); + END IF; + + IF vLanded IS NULL OR vZoneFk IS NULL THEN + + UPDATE ticket t + SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) + WHERE t.id = vTicketFk AND t.landed IS NULL; + + IF vZoneFk IS NULL THEN + SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; + UPDATE ticket t + SET t.zoneFk = vZoneFk + WHERE t.id = vTicketFk AND t.zoneFk IS NULL; + END IF; + + END IF; + + DROP TEMPORARY TABLE tmp.zoneGetLanded; + + -- rellena la tabla buyUltimate con la ultima compra + CALL buyUltimate (vWarehouseFk, vShipped); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; + CREATE TEMPORARY TABLE tmp.ticketLot + SELECT vWarehouseFk warehouseFk, NULL available, + s.itemFk, bu.buyFk, vZoneFk zoneFk + FROM sale s + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk + WHERE s.ticketFk = vTicketFk + GROUP BY s.itemFk; + + CALL catalog_componentPrepare(); + CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); + + DROP TEMPORARY TABLE IF EXISTS tmp.sale; + CREATE TEMPORARY TABLE tmp.sale + (PRIMARY KEY (saleFk)) ENGINE = MEMORY + SELECT id saleFk, vWarehouseFk warehouseFk + FROM sale s + WHERE s.ticketFk = vTicketFk; + + -- si el ticket esta facturado, respeta los precios + CALL ticketComponentUpdateSale(IF(vIsTicketEditable, 1, 6)); + + CALL catalog_componentPurge(); + DROP TEMPORARY TABLE + tmp.buyUltimate, + tmp.sale; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_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_recalcComponentsForcePrice__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_recalcComponentsForcePrice__`(IN vTicketFk BIGINT, vIsTicketEditable BOOLEAN ) -proc: BEGIN - -/** - * Este procedimiento trata de "rebionizar" un ticket, - * eliminando los componentes existentes e insertandolos de nuevo - * - * @param vTicketFk Id del ticket - * @return tmp.buyUltimate - */ - DECLARE vShipped DATE; - DECLARE vWarehouseFk SMALLINT; - DECLARE vAgencyModeFk INT; - DECLARE vAddressFk INT; - DECLARE vLanded DATE; - DECLARE vZoneFk INTEGER; - - IF vIsTicketEditable IS NULL THEN - SELECT (IFNULL(ts.alertLevel,0) >0 or IFNULL(t.refFk,"") != "") = FALSE, t.zoneFk - INTO vIsTicketEditable, vZoneFk - FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket - WHERE id = vTicketFk; - END IF; - SELECT warehouseFk, date(shipped), addressFk, agencyModeFk, landed - INTO vWarehouseFk, vShipped, vAddressFk, vAgencyModeFk, vLanded - FROM ticket - WHERE id = vTicketFk; - - CALL vn.zone_getShipped (vLanded, vAddressFk, vAgencyModeFk, TRUE); - - CALL vn.buyUltimate (vWarehouseFk, vShipped); -- rellena la tabla buyUltimate con la ultima compra - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouseFk warehouseFk, NULL available, - s.itemFk, bu.buyFk - FROM sale s - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk - WHERE s.ticketFk = vTicketFk - GROUP BY s.itemFk; - - CALL vn.catalog_componentCalculate(vZoneFk, vAddressFk, vShipped); - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT id saleFk, vWarehouseFk warehouseFk - FROM sale s - WHERE s.ticketFk = vTicketFk; - - CALL vn.ticketComponentUpdateSale(IF(vIsTicketEditable,1,6)); -- si el ticket esta facturado, respeta los precios - - IF vLanded IS NULL THEN - - CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk); - - UPDATE vn2008.Tickets t - SET t.landing = (SELECT landed FROM tmp.zoneGetLanded) - WHERE Id_Ticket = vTicketFk; - - DROP TEMPORARY TABLE tmp.zoneGetLanded; - - END IF; - - DROP TEMPORARY TABLE tmp.buyUltimate; - DROP TEMPORARY TABLE tmp.ticketComponentPrice; - DROP TEMPORARY TABLE tmp.ticketComponent; - DROP TEMPORARY TABLE tmp.sale; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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_recalcComponents__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_recalcComponents__`(IN vTicketFk BIGINT, vIsTicketEditable BOOLEAN) -proc: BEGIN - -/** - * Este procedimiento recalcula los componentes de un ticket, - * eliminando los componentes existentes e insertandolos de nuevo - * - * @param vTicketFk Id del ticket - * @param vIsTicketEditable si no se quiere forzar llamar con NULL - */ - DECLARE vShipped DATE; - DECLARE vWarehouseFk SMALLINT; - DECLARE vAgencyModeFk INT; - DECLARE vAddressFk INT; - DECLARE vLanded DATE; - DECLARE vZoneFk INTEGER; - - -- Santos 2021, borrar a partir del dia 31 PAK - IF (SELECT COUNT(*) - FROM tmp.routeDayMove ra - JOIN vn.ticket t ON t.routeFk = ra.routeFk - WHERE t.id = vTicketFk) THEN - - LEAVE proc; - - END IF; - - IF vIsTicketEditable IS NULL THEN - SELECT IFNULL(ts.alertLevel,0) = 0 AND IFNULL(t.refFk,'') = '' - INTO vIsTicketEditable - FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket - WHERE id = vTicketFk; - END IF; - - SELECT t.warehouseFk, - t.shipped, - t.addressFk, - t.agencyModeFk, - t.landed, - t.zoneFk - INTO vWarehouseFk, vShipped, vAddressFk, vAgencyModeFk, vLanded, vZoneFk - FROM ticket t LEFT JOIN ticketState ts ON t.id = ts.ticket - WHERE t.id = vTicketFk; - - IF vLanded IS NULL OR vZoneFk IS NULL THEN - - CALL zone_getLanded(vShipped, vAddressFk, vAgencyModeFk, vWarehouseFk, TRUE); - - IF (SELECT COUNT(*) FROM tmp.zoneGetLanded LIMIT 1) = 0 THEN - CALL util.throw('There is no zone for these parameters'); - END IF; - - UPDATE ticket t - SET t.landed = (SELECT landed FROM tmp.zoneGetLanded LIMIT 1) - WHERE t.id = vTicketFk AND t.landed IS NULL; - - IF vZoneFk IS NULL THEN - SELECT zoneFk INTO vZoneFk FROM tmp.zoneGetLanded LIMIT 1; - UPDATE ticket t - SET t.zoneFk = vZoneFk - WHERE t.id = vTicketFk AND t.zoneFk IS NULL; - END IF; - DROP TEMPORARY TABLE tmp.zoneGetLanded; - - END IF; - - -- rellena la tabla buyUltimate con la ultima compra - CALL buyUltimate (vWarehouseFk, vShipped); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; - CREATE TEMPORARY TABLE tmp.ticketLot - SELECT vWarehouseFk warehouseFk, NULL available, - s.itemFk, bu.buyFk, vZoneFk zoneFk - FROM sale s - LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk - WHERE s.ticketFk = vTicketFk - GROUP BY s.itemFk; - - CALL catalog_componentPrepare(); - CALL catalog_componentCalculate(vZoneFk, vAddressFk, vShipped, vWarehouseFk); - - DROP TEMPORARY TABLE IF EXISTS tmp.sale; - CREATE TEMPORARY TABLE tmp.sale - (PRIMARY KEY (saleFk)) ENGINE = MEMORY - SELECT id saleFk, vWarehouseFk warehouseFk - FROM sale s - WHERE s.ticketFk = vTicketFk; - - -- si el ticket esta facturado, respeta los precios - CALL ticketComponentUpdateSale(IF(vIsTicketEditable, 1, 6)); - - CALL catalog_componentPurge(); - DROP TEMPORARY TABLE - tmp.buyUltimate, - tmp.sale; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!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 sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_requestRecalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -84433,27 +70756,27 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_requestRecalc`(vSelf INT) -proc: BEGIN -/** - * Adds a request to recalculate the ticket total. - * - * @param vSelf The ticket identifier - */ - IF vSelf IS NULL THEN - LEAVE proc; - END IF; - - INSERT IGNORE INTO ticketRecalc SET ticketFk = vSelf; +proc: BEGIN +/** + * Adds a request to recalculate the ticket total. + * + * @param vSelf The ticket identifier + */ + IF vSelf IS NULL THEN + LEAVE proc; + END IF; + + INSERT IGNORE INTO ticketRecalc SET ticketFk = vSelf; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_setNextState` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -84461,37 +70784,88 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_setNextState`(vSelf INT) -BEGIN -/** - * Cambia el estado del ticket al siguiente estado según la tabla state - * - * @param vSelf id dle ticket - */ - DECLARE vStateFk INT; - DECLARE vNewStateFk INT; - - SELECT stateFk INTO vStateFk - FROM ticketState - WHERE ticketFk = vSelf; - - SELECT nextStateFk INTO vNewStateFk - FROM state - WHERE id = vStateFk; - - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) - VALUES (vNewStateFk, vSelf, account.myUser_getId()); - - SELECT TRUE AS IsUpdated; +BEGIN +/** + * Cambia el estado del ticket al siguiente estado según la tabla state + * + * @param vSelf id dle ticket + */ + DECLARE vStateFk INT; + DECLARE vNewStateFk INT; + + SELECT stateFk INTO vStateFk + FROM ticketState + WHERE ticketFk = vSelf; + + SELECT nextStateFk INTO vNewStateFk + FROM state + WHERE id = vStateFk; + + INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) + VALUES (vNewStateFk, vSelf, account.myUser_getId()); + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticket_setParking` */; +/*!50003 SET @saved_cs_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_setParking`(IN `vTicketFk` VARCHAR(8), IN `vParkingFk` INT) +proc: BEGIN + DECLARE vDone INT DEFAULT FALSE; + DECLARE vCollectionTicketFk INT; + DECLARE vCursor CURSOR FOR + + SELECT IFNULL(tc2.ticketFk, t.id) + FROM ticket t + LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id + LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk + WHERE t.id = vTicketFk; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + INSERT INTO vn.ticketParking(ticketFk, parkingFk) + SELECT IFNULL(tc2.ticketFk, t.id), vParkingFk + FROM ticket t + LEFT JOIN ticketCollection tc1 ON tc1.ticketFk = t.id + LEFT JOIN ticketCollection tc2 ON tc2.collectionFk = tc1.collectionFk + WHERE t.id = vTicketFk + ON DUPLICATE KEY UPDATE parkingFk = vParkingFk; + + OPEN vCursor; + l: LOOP + + FETCH vCursor INTO vCollectionTicketFk; + + IF vDone THEN + LEAVE l; + END IF; + + CALL vn.ticket_setNextState(vCollectionTicketFk); + + END LOOP; + + CLOSE vCursor; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_setPreviousState` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -84499,50 +70873,47 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_setPreviousState`(vTicketFk INT) -BEGIN - - DECLARE vControlFk INT; - - SELECT MAX(inter_id) INTO vControlFk - FROM vncontrol.inter - WHERE Id_Ticket = vTicketFk; - - IF (SELECT s.code - FROM vn.state s - JOIN vncontrol.inter i ON i.state_id = s.id - WHERE i.inter_id = vControlFk) - = 'PREVIOUS_PREPARATION' THEN - - SELECT inter_id - INTO vControlFk - FROM vncontrol.inter i - JOIN vn.state s ON i.state_id = s.id - WHERE Id_Ticket = vTicketFk - AND inter_id < vControlFk - AND s.code != 'PREVIOUS_PREPARATION' - ORDER BY inter_id DESC - LIMIT 1; - - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) - SELECT s.nextStateFk, i.Id_Ticket, account.myUser_getId() - FROM vncontrol.inter i - JOIN vn.state s ON i.state_id = s.id - WHERE inter_id = vControlFk; - - END IF; - - SELECT TRUE AS IsUpdated; - +BEGIN + + DECLARE vControlFk INT; + + SELECT MAX(inter_id) INTO vControlFk + FROM vncontrol.inter + WHERE Id_Ticket = vTicketFk; + + IF (SELECT s.code + FROM vn.state s + JOIN vncontrol.inter i ON i.state_id = s.id + WHERE i.inter_id = vControlFk) + = 'PREVIOUS_PREPARATION' THEN + + SELECT inter_id + INTO vControlFk + FROM vncontrol.inter i + JOIN vn.state s ON i.state_id = s.id + WHERE Id_Ticket = vTicketFk + AND inter_id < vControlFk + AND s.code != 'PREVIOUS_PREPARATION' + ORDER BY inter_id DESC + LIMIT 1; + + INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) + SELECT s.nextStateFk, i.Id_Ticket, account.myUser_getId() + FROM vncontrol.inter i + JOIN vn.state s ON i.state_id = s.id + WHERE inter_id = vControlFk; + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_setState` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -84550,40 +70921,40 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_setState`(vTicketFk INT, vStateCode VARCHAR(45)) -BEGIN - - /* Modifica el estado de un ticket - * - * @param vTicketFk el id del ticket - * @param vStateCode estado a modificar del ticket - * - */ - - DECLARE vAlertLevel INT; - - SELECT s.alertLevel INTO vAlertLevel - FROM vn.state s - JOIN vn.ticketState ts ON ts.stateFk = s.id - WHERE ts.ticketFk = vTicketFk; - - IF !(vStateCode = 'ON_CHECKING' AND vAlertLevel > 1) THEN - - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) - SELECT id, vTicketFk, account.myUser_getId() - FROM vn.state - WHERE `code` = vStateCode collate utf8_unicode_ci; - - END IF; +BEGIN + + /* Modifica el estado de un ticket + * + * @param vTicketFk el id del ticket + * @param vStateCode estado a modificar del ticket + * + */ + + DECLARE vAlertLevel INT; + + SELECT s.alertLevel INTO vAlertLevel + FROM vn.state s + JOIN vn.ticketState ts ON ts.stateFk = s.id + WHERE ts.ticketFk = vTicketFk; + + IF !(vStateCode = 'ON_CHECKING' AND vAlertLevel > 1) THEN + + INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) + SELECT id, vTicketFk, account.myUser_getId() + FROM vn.state + WHERE `code` = vStateCode collate utf8_unicode_ci; + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_split` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -84591,8 +70962,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_split`(vTicketFk INT, vTicketFutureFk INT, vDated DATE) proc:BEGIN @@ -84624,7 +70993,7 @@ proc:BEGIN UPDATE vn.ticket SET landed = vDated + 1, shipped = vDated, - nickname = CONCAT('(',DAY(curdate()),') ', nickname ) + nickname = CONCAT('(',DAY(vn.VN_CURDATE()),') ', nickname ) WHERE id = vTicketFk; SELECT CONCAT("Se ha cambiado el ticket ", vTicketFk, " al dia ", vDated); @@ -84674,6 +71043,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_splitItemPackingType` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -84681,8 +71052,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_splitItemPackingType`(vTicketFk INT) proc:BEGIN @@ -84803,6 +71172,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_splitPackingComplete` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -84810,8 +71181,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_splitPackingComplete`(vTicketFk INT, vSectorFk INT) BEGIN @@ -84858,6 +71227,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticket_WeightDeclaration` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -84865,8 +71236,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_WeightDeclaration`(vClientFk INT, vDated DATE) BEGIN @@ -84921,6 +71290,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `timeBusiness_calculate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -84928,12 +71299,9 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeBusiness_calculate`(vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN - /** * Horas que debe trabajar un empleado según contrato y día. * @param vDatedFrom workerTimeControl @@ -84941,7 +71309,6 @@ BEGIN * @table tmp.user(userFk) * @return tmp.timeBusinessCalculate */ - DROP TEMPORARY TABLE IF EXISTS tmp.timeBusinessCalculate; CREATE TEMPORARY TABLE tmp.timeBusinessCalculate @@ -84958,7 +71325,7 @@ BEGIN timeWorkSeconds timeBusinessSeconds, SEC_TO_TIME(timeWorkSeconds) timeBusinessSexagesimal, timeWorkSeconds / 3600 timeBusinessDecimal, - type, + name type, permissionRate, hoursWeek, discountRate, @@ -84971,27 +71338,27 @@ BEGIN IF(j.start = NULL, NULL, GROUP_CONCAT(DISTINCT LEFT(j.end,5) ORDER BY j.end ASC SEPARATOR ' - ')) hourEnd, IF(j.start = NULL, NULL, GROUP_CONCAT(DISTINCT LEFT(j.start,5), " - ", LEFT(j.end,5) ORDER BY j.end ASC SEPARATOR ' - ')) timeTable, IF(j.start = NULL, 0, IFNULL(SUM(TIME_TO_SEC(j.end)) - SUM(TIME_TO_SEC(j.start)),0)) timeWorkSeconds, - cs.type, - cs.permissionRate, - cs.discountRate, + at2.name, + at2.permissionRate, + at2.discountRate, cl.hours_week hoursWeek, - cs.isAllowedToWork + at2.isAllowedToWork FROM vn.time t - LEFT JOIN postgresql.business b ON t.dated BETWEEN b.date_start AND ifnull(b.date_end, vDatedTo ) - LEFT JOIN postgresql.profile AS pr ON b.client_id = pr.profile_id - LEFT JOIN postgresql.person AS p ON pr.person_id = p.person_id - LEFT JOIN vn.worker AS w ON p.id_trabajador = w.id + LEFT JOIN postgresql.business b ON t.dated BETWEEN b.date_start AND IFNULL(b.date_end, vDatedTo ) + LEFT JOIN postgresql.profile pr ON b.client_id = pr.profile_id + LEFT JOIN postgresql.person p ON pr.person_id = p.person_id + LEFT JOIN vn.worker w ON p.id_trabajador = w.id JOIN tmp.`user` u ON u.userFK = w.userFK - JOIN postgresql.business_labour AS bl ON b.business_id = bl.business_id - LEFT JOIN postgresql.business_labour_payroll AS bp ON bl.business_id = bp.business_id - LEFT JOIN postgresql.professional_category AS pc ON bl.professional_category_id = pc.professional_category_id - LEFT JOIN postgresql.workcenter AS wc ON bl.workcenter_id = wc.workcenter_id - LEFT JOIN postgresql.calendar_labour_type AS cl ON bl.calendar_labour_type_id = cl.calendar_labour_type_id - LEFT JOIN postgresql.journey AS j ON j.business_id = b.business_id and j.day_id=WEEKDAY(t.dated)+1 - LEFT JOIN postgresql.calendar_employee ce ON ce.business_id=b.business_id and ce.date = t.dated - LEFT JOIN postgresql.calendar_state cs ON cs.calendar_state_id = ce.calendar_state_id + JOIN postgresql.business_labour bl ON b.business_id = bl.business_id + LEFT JOIN postgresql.business_labour_payroll bp ON bl.business_id = bp.business_id + LEFT JOIN postgresql.professional_category pc ON bl.professional_category_id = pc.professional_category_id + LEFT JOIN vn.workCenter wc ON bl.workcenter_id = wc.id + LEFT JOIN postgresql.calendar_labour_type cl ON bl.calendar_labour_type_id = cl.calendar_labour_type_id + LEFT JOIN postgresql.journey j ON j.business_id = b.business_id AND j.day_id=WEEKDAY(t.dated)+1 + LEFT JOIN postgresql.calendar_employee ce ON ce.business_id=b.business_id AND ce.date = t.dated + LEFT JOIN vn.absenceType at2 ON at2.id = ce.calendar_state_id WHERE t.dated BETWEEN vDatedFrom AND vDatedTo - GROUP BY w.userFk,dated + GROUP BY w.userFk,dated )sub; UPDATE tmp.timeBusinessCalculate t @@ -85026,6 +71393,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `timeBusiness_calculateAll` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -85033,8 +71402,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeBusiness_calculateAll`(vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN @@ -85062,6 +71429,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `timeBusiness_calculateByDepartment` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -85069,8 +71438,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeBusiness_calculateByDepartment`(vDepartmentFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN @@ -85107,6 +71474,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `timeBusiness_calculateByUser` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -85114,8 +71483,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeBusiness_calculateByUser`(vUserFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN @@ -85142,6 +71509,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `timeBusiness_calculateByWorker` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -85149,8 +71518,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeBusiness_calculateByWorker`(vWorkerFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN @@ -85179,123 +71546,15 @@ 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 `timeBusiness_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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `timeBusiness_calculate__`(vDatedFrom DATETIME, vDatedTo DATETIME) -BEGIN - -/** - * Horas que debe trabajar un empleado según contrato y día. - * @param vDatedFrom workerTimeControl - * @param vDatedTo workerTimeControl - * @table tmp.user(userFk) - * @return tmp.timeBusinessCalculate - */ - - DROP TABLE IF EXISTS tmp.timeBusinessCalculate; - DROP TEMPORARY TABLE IF EXISTS tmp.businessFullTime; - - CALL rangeDateInfo(vDatedFrom, vDatedTo); - - CREATE TABLE tmp.timeBusinessCalculate - SELECT dated, - businessFk, - userFk, - departmentFk, - hourStart, - hourEnd, - timeTable, - timeWorkSeconds, - SEC_TO_TIME(timeWorkSeconds) timeWorkSexagesimal, - timeWorkSeconds / 3600 timeWorkDecimal, - timeWorkSeconds timeBusinessSeconds, - SEC_TO_TIME(timeWorkSeconds) timeBusinessSexagesimal, - timeWorkSeconds / 3600 timeBusinessDecimal, - type, - permissionRate, - hoursWeek, - discountRate - FROM(SELECT rd.dated, - b.business_id businessFk, - w.userFk, - bl.department_id departmentFk, - IF(j.start = NULL, NULL, GROUP_CONCAT(DISTINCT LEFT(j.start,5) ORDER BY j.start ASC SEPARATOR ' - ')) hourStart , - IF(j.start = NULL, NULL, GROUP_CONCAT(DISTINCT LEFT(j.end,5) ORDER BY j.end ASC SEPARATOR ' - ')) hourEnd, - IF(j.start = NULL, NULL, GROUP_CONCAT(DISTINCT LEFT(j.start,5), " - ", LEFT(j.end,5) ORDER BY j.end ASC SEPARATOR ' - ')) timeTable, - IF(j.start = NULL, 0, IFNULL(SUM(TIME_TO_SEC(j.end)) - SUM(TIME_TO_SEC(j.start)),0)) timeWorkSeconds, - cs.type, - cs.permissionRate, - cs.discountRate, - cl.hours_week hoursWeek - FROM tmp.rangeDate rd - LEFT JOIN postgresql.business b ON rd.dated BETWEEN b.date_start AND ifnull(b.date_end, vDatedTo ) - LEFT JOIN postgresql.profile AS pr ON b.client_id = pr.profile_id - LEFT JOIN postgresql.person AS p ON pr.person_id = p.person_id - LEFT JOIN vn.worker AS w ON p.id_trabajador = w.id - JOIN tmp.`user` u ON u.userFK = w.userFK - JOIN postgresql.business_labour AS bl ON b.business_id = bl.business_id - LEFT JOIN postgresql.business_labour_payroll AS bp ON bl.business_id = bp.business_id - LEFT JOIN postgresql.professional_category AS pc ON bl.professional_category_id = pc.professional_category_id - LEFT JOIN postgresql.workcenter AS wc ON bl.workcenter_id = wc.workcenter_id - LEFT JOIN postgresql.calendar_labour_type AS cl ON bl.calendar_labour_type_id = cl.calendar_labour_type_id - LEFT JOIN postgresql.journey AS j ON j.business_id = b.business_id and j.day_id=WEEKDAY(rd.dated)+1 - LEFT JOIN postgresql.calendar_employee ce ON ce.business_id=b.business_id and ce.date = rd.dated - LEFT JOIN postgresql.calendar_state cs ON cs.calendar_state_id = ce.calendar_state_id - WHERE rd.dated BETWEEN vDatedFrom AND vDatedTo - GROUP BY w.userFk,dated - )sub; - - - UPDATE tmp.timeBusinessCalculate t - LEFT JOIN postgresql.journey j ON j.business_id = t.businessFk - SET t.timeWorkSeconds = t.hoursWeek / 5 * 3600, - t.timeWorkSexagesimal = SEC_TO_TIME( t.hoursWeek / 5 * 3600), - t.timeWorkDecimal = t.hoursWeek / 5, - t.timeBusinessSeconds = t.hoursWeek / 5 * 3600, - t.timeBusinessSexagesimal = SEC_TO_TIME( t.hoursWeek / 5 * 3600), - t.timeBusinessDecimal = t.hoursWeek / 5 - WHERE DAYOFWEEK(t.dated) IN(2,3,4,5,6) AND j.journey_id IS NULL ; - - UPDATE tmp.timeBusinessCalculate t - SET t.timeWorkSeconds = t.timeWorkSeconds - (t.timeWorkSeconds * permissionRate) , - t.timeWorkSexagesimal = SEC_TO_TIME ((t.timeWorkDecimal - (t.timeWorkDecimal * permissionRate)) * 3600), - t.timeWorkDecimal = t.timeWorkDecimal - (t.timeWorkDecimal * permissionRate) - WHERE permissionRate <> 0; - -UPDATE tmp.timeBusinessCalculate t - JOIN vn.calendarHolidays ch ON ch.dated = t.dated - JOIN postgresql.business_labour bl ON bl.business_id = t.businessFk AND bl.workcenter_id = ch.workcenterFk - SET t.timeWorkSeconds = 0, - t.timeWorkSexagesimal = 0, - t.timeWorkDecimal = 0, - t.permissionrate = 1, - t.type = 'Festivo' - WHERE t.type IS NULL; - -DROP TEMPORARY TABLE IF EXISTS tmp.rangeDate; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `timeControl_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' */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeControl_calculate`(vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN @@ -85427,6 +71686,7 @@ BEGIN wtc.userFk FROM tmp.workerTimeControl wtc ORDER BY wtc.userFk, wtc.timed, wtc.id + LIMIT 10000000000000000000 )sub GROUP BY sub.userFk, sub.dated HAVING SUM(sub.timeWork) >= vTimeToBreakTime; @@ -85472,6 +71732,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `timeControl_calculateAll` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -85479,8 +71741,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeControl_calculateAll`(vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN @@ -85508,6 +71768,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `timeControl_calculateByDepartment` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -85515,8 +71777,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeControl_calculateByDepartment`(vDepartmentFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN @@ -85553,6 +71813,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `timeControl_calculateByUser` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -85560,8 +71822,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeControl_calculateByUser`(vUserFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN @@ -85588,6 +71848,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `timeControl_calculateByWorker` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -85595,8 +71857,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeControl_calculateByWorker`(vWorkerFk INT, vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN @@ -85625,70 +71885,15 @@ 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 `timeControl_calculate__` */; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `timeControl_getError` */; /*!50003 SET @saved_cs_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`@`localhost` PROCEDURE `timeControl_calculate__`(vDatedFrom DATETIME, vDatedTo DATETIME) -BEGIN - SET @vIsOdd := TRUE; - SET @vUser := NULL; - SET @vDated := NULL; - - DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate; - - CREATE TEMPORARY TABLE tmp.timeControlCalculate - SELECT - userFk, - dated, - IF( timeWork >= 18000, @timeWork:=timeWork + 1200, @timeWork:=timeWork) timeWorkSeconds, - SEC_TO_TIME(@timeWork ) timeWorkSexagesimal, - @timeWork / 3600 timeWorkDecimal, - timed - FROM (SELECT SUM(timeWork) timeWork, - userFk, - dated, - GROUP_CONCAT(DATE_FORMAT(sub.timed,"%H:%i") ORDER BY sub.timed ASC SEPARATOR ' - ') timed - FROM (SELECT IF(@vUser = wtc.userFk, @vUser :=@vUser, @vUser := wtc.userFk), - IF(@vIsOdd, @vIsOdd := FALSE, @vIsOdd := TRUE), - IF(direction='in', @vIsOdd := TRUE, @vIsOdd := @vIsOdd), - IF(@vIsOdd, @vLastTimed:=UNIX_TIMESTAMP(timed),@vLastTimed:=@vLastTimed), - IF(@vIsOdd, 0, UNIX_TIMESTAMP(timed)-@vLastTimed) timeWork, - IF(direction='in', @vDated := DATE(wtc.timed), @vDated) dated, - wtc.timed timed, - wtc.userFk, - direction - FROM (SELECT DISTINCT(wtc.id), wtc.userFk, wtc.timed, wtc.direction - FROM workerTimeControl wtc - JOIN tmp.`user` w ON w.userFk = wtc.userFk - WHERE wtc.timed BETWEEN vDatedFrom AND vDatedTo - ORDER BY userFk, timed ASC - ) wtc - WHERE wtc.timed BETWEEN vDatedFrom AND vDatedTo - ) sub - GROUP BY userFk, dated - )sub2; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `timeControl_getError` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_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 collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeControl_getError`(vDatedFrom DATETIME, vDatedTo DATETIME) BEGIN @@ -85736,33 +71941,35 @@ BEGIN DROP TEMPORARY TABLE IF EXISTS tmp.timeControlError; CREATE TEMPORARY TABLE tmp.timeControlError - (INDEX(id)) - ENGINE = MEMORY + (INDEX(id)) + ENGINE = MEMORY SELECT id FROM tmp.timeControlAux tca - JOIN (SELECT journeyCounter, - UNIX_TIMESTAMP(MAX(timed)) - UNIX_TIMESTAMP(MIN(timed)) timeWork, - SUM(direction = 'in') totalIn, - SUM(direction = 'out') totalOut, - timed - FROM tmp.timeControl - GROUP BY journeyCounter - HAVING COUNT(*) MOD 2 = 1 - OR totalIn <> 1 - OR totalOut <> 1 - OR timeWork >= vDayMaxTime - )sub ON sub.journeyCounter = tca.journeyCounter + JOIN ( + SELECT journeyCounter, + UNIX_TIMESTAMP(MAX(timed)) - UNIX_TIMESTAMP(MIN(timed)) timeWork, + SUM(direction = 'in') totalIn, + SUM(direction = 'out') totalOut, + timed + FROM tmp.timeControl + GROUP BY journeyCounter + HAVING COUNT(*) MOD 2 = 1 + OR totalIn <> 1 + OR totalOut <> 1 + OR timeWork >= vDayMaxTime + )sub ON sub.journeyCounter = tca.journeyCounter WHERE sub.timed BETWEEN vDatedFrom AND vDatedTo; - + DROP TEMPORARY TABLE IF EXISTS tmp.timeControl; DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `timeWorkerControl_check` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -85770,8 +71977,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `timeWorkerControl_check`(vUserFk INT, vDated DATE,vTabletFk VARCHAR(100)) proc: BEGIN @@ -85786,6 +71991,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `tpvTransaction_checkStatus` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -85793,37 +72000,37 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `tpvTransaction_checkStatus`() -BEGIN -/** - * - * Envia mail con los cobros web no - * trasladados a la ficha del cliente. - * - */ - INSERT INTO mail (receiver,replyTo,subject,body) - SELECT 'administracion@verdnatura.es', - 'noreply@verdnatura.es', - CONCAT('Cobro web no trasladado a la ficha del cliente ', t.clientFk), - CONCAT('Hay un importe de ', t.amount/100, '€ del cliente ', t.clientFk, ' con fecha ', t.created, - ', que no se ha trasladado a recibos. Si nos ha llegado el importe al banco confirme el pago en - - https://salix.verdnatura.es/#!/client/',t.clientFk,'/web-payment') - FROM hedera.tpvTransaction t - WHERE t.receiptFk IS NULL - AND t.status = 'ok' - AND t.created < DATE_ADD(util.VN_NOW(),INTERVAL - 2 DAY) - GROUP BY t.clientFk; - +BEGIN +/** + * + * Envia mail con los cobros web no + * trasladados a la ficha del cliente. + * + */ + INSERT INTO mail (receiver,replyTo,subject,body) + SELECT 'administracion@verdnatura.es', + 'noreply@verdnatura.es', + CONCAT('Cobro web no trasladado a la ficha del cliente ', t.clientFk), + CONCAT('Hay un importe de ', t.amount/100, '€ del cliente ', t.clientFk, ' con fecha ', t.created, + ', que no se ha trasladado a recibos. Si nos ha llegado el importe al banco confirme el pago en + + https://salix.verdnatura.es/#!/client/',t.clientFk,'/web-payment') + FROM hedera.tpvTransaction t + WHERE t.receiptFk IS NULL + AND t.status = 'ok' + AND t.created < DATE_ADD(vn.VN_NOW(),INTERVAL - 2 DAY) + GROUP BY t.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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `travelVolume` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -85831,8 +72038,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `travelVolume`(vTravelFk INT) BEGIN @@ -85867,6 +72072,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `travelVolume_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -85874,31 +72081,31 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `travelVolume_get`(vFromDated DATE, vToDated DATE, vWarehouseFk INT) -BEGIN - - SELECT tr.landed Fecha, - a.name Agencia, - count(DISTINCT e.id) numEntradas, - FLOOR(sum(item_getVolume(b.itemFk, b.packageFk) * b.stickers / 1000000 )) AS m3 - FROM vn.travel tr - JOIN vn.agencyMode a ON a.id = tr.agencyFk - JOIN vn.entry e ON e.travelFk = tr.id - JOIN vn.buy b ON b.entryFk = e.id - WHERE tr.landed BETWEEN vFromDated AND vToDated - AND e.isRaid = FALSE - AND tr.warehouseInFk = vWarehouseFk - GROUP BY tr.landed , a.name ; - +BEGIN + + SELECT tr.landed Fecha, + a.name Agencia, + count(DISTINCT e.id) numEntradas, + FLOOR(sum(item_getVolume(b.itemFk, b.packageFk) * b.stickers / 1000000 )) AS m3 + FROM vn.travel tr + JOIN vn.agencyMode a ON a.id = tr.agencyFk + JOIN vn.entry e ON e.travelFk = tr.id + JOIN vn.buy b ON b.entryFk = e.id + WHERE tr.landed BETWEEN vFromDated AND vToDated + AND e.isRaid = FALSE + AND tr.warehouseInFk = vWarehouseFk + GROUP BY tr.landed , a.name ; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `travel_checkDates` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -85906,8 +72113,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_checkDates`(vShipped DATE, vLanded DATE) BEGIN @@ -85929,6 +72134,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `travel_clone` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -85936,64 +72143,64 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_clone`(vSelf INT, vDays INT, OUT vNewTravelFk INT) -BEGIN - - /** - * Clona un travel el número de dias indicado y devuelve su Id - * - * @param vSelf Identificador de vn.travel - * @param vDays Número de dias a futuro - * - * @return vNewTravelFk Nuevo número de travel - */ - - SELECT tr.id INTO vNewTravelFk - FROM vn.travel tr - JOIN vn.travel tr2 USING(shipped, warehouseInFk, warehouseOutFk, agencyFk, `ref`) - WHERE tr2.id = vSelf - AND tr.landed = TIMESTAMPADD(DAY, vDays, tr2.landed); - - IF ISNULL(vNewTravelFk) THEN - - START TRANSACTION; - - INSERT INTO vn.travel( shipped, - shipmentHour, - landed, - landingHour, - warehouseInFk, - warehouseOutFk, - agencyFk, - `ref`, - cargoSupplierFk) - SELECT shipped, - shipmentHour, - TIMESTAMPADD(DAY, vDays, landed), - landingHour, - warehouseInFk, - warehouseOutFk, - agencyFk, - `ref`, - cargoSupplierFk - FROM vn.travel - WHERE id = vSelf; - - SELECT LAST_INSERT_ID() INTO vNewTravelFk; - - COMMIT; - - END IF; - +BEGIN + + /** + * Clona un travel el número de dias indicado y devuelve su Id + * + * @param vSelf Identificador de vn.travel + * @param vDays Número de dias a futuro + * + * @return vNewTravelFk Nuevo número de travel + */ + + SELECT tr.id INTO vNewTravelFk + FROM vn.travel tr + JOIN vn.travel tr2 USING(shipped, warehouseInFk, warehouseOutFk, agencyFk, `ref`) + WHERE tr2.id = vSelf + AND tr.landed = TIMESTAMPADD(DAY, vDays, tr2.landed); + + IF ISNULL(vNewTravelFk) THEN + + START TRANSACTION; + + INSERT INTO vn.travel( shipped, + shipmentHour, + landed, + landingHour, + warehouseInFk, + warehouseOutFk, + agencyFk, + `ref`, + cargoSupplierFk) + SELECT shipped, + shipmentHour, + TIMESTAMPADD(DAY, vDays, landed), + landingHour, + warehouseInFk, + warehouseOutFk, + agencyFk, + `ref`, + cargoSupplierFk + FROM vn.travel + WHERE id = vSelf; + + SELECT LAST_INSERT_ID() INTO vNewTravelFk; + + COMMIT; + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `travel_cloneWithEntries` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -86001,297 +72208,155 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` 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, +CREATE DEFINER=`root`@`localhost` 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; +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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_cloneWithEntries__`(IN vTravelFk INT, IN vDateStart DATE, IN vDateEnd DATE, - IN vRef VARCHAR(255), OUT vNewTravelFk INT) -BEGIN - 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 vRsBuy CURSOR FOR - SELECT b.* - FROM buy b - JOIN entry e - ON b.entryFk = e.id - WHERE e.travelFk = vNewTravelFk and b.entryFk=vNewTravelFk - ORDER BY e.id; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - START TRANSACTION; - - INSERT INTO travel (shipped,landed, warehouseInFk, warehouseOutFk, agencyFk, ref, isDelivered, isReceived, m3, kg) - SELECT vDateStart, vDateEnd,warehouseInFk, warehouseOutFk, agencyFk, vRef, isDelivered, isReceived, m3, kg - FROM travel - WHERE id = vTravelFk; - - SET vNewTravelFk = LAST_INSERT_ID(); - SET vDone = FALSE; - 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(); - - - 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; - 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_doRecalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -86299,8 +72364,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_doRecalc`() BEGIN @@ -86345,6 +72408,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `travel_moveRaids` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -86352,8 +72417,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_moveRaids`() BEGIN @@ -86404,7 +72467,7 @@ BEGIN SET tr.landed = TIMESTAMPADD(DAY, 1, tr.landed); INSERT INTO travelLog (originFk, userFk , action, description) - SELECT ttr.id, account.userGetId(), 'update', CONCAT('Se ha cambiado la fecha del travel al dia ', util.tomorrow()) + SELECT ttr.id, account.myUser_getId(), 'update', CONCAT('Se ha cambiado la fecha del travel al dia ', util.tomorrow()) FROM tmp.travel ttr; OPEN vCur; @@ -86434,6 +72497,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `travel_requestRecalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -86441,8 +72506,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_requestRecalc`(vSelf INT) proc: BEGIN @@ -86462,6 +72525,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `travel_weeklyClone` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -86469,8 +72534,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `travel_weeklyClone`(vSinceWeek INT, vToWeek INT) BEGIN @@ -86492,7 +72555,7 @@ BEGIN DECLARE vDone BOOLEAN DEFAULT FALSE; DECLARE vRsTravel CURSOR FOR SELECT travelFk, - @a := TIMESTAMPADD(DAY,vCounter * 7 - WEEKDAY(util.VN_CURDATE()) - 1 + weekDay,util.VN_CURDATE()), + @a := TIMESTAMPADD(DAY,vCounter * 7 - WEEKDAY(vn.VN_CURDATE()) - 1 + weekDay,vn.VN_CURDATE()), @a := TIMESTAMPADD(DAY,duration,@a), warehouseOutFk, warehouseInFk, @@ -86506,7 +72569,7 @@ BEGIN SET vCounter = vSinceWeek; vWeekLoop :LOOP INSERT IGNORE INTO travel (shipped, landed, warehouseOutFk, warehouseInFk, agencyFk, ref, cargoSupplierFk, kg) - SELECT @a := TIMESTAMPADD(DAY, vCounter * 7 - WEEKDAY(util.VN_CURDATE()) - 1 + weekDay,util.VN_CURDATE()), + SELECT @a := TIMESTAMPADD(DAY, vCounter * 7 - WEEKDAY(vn.VN_CURDATE()) - 1 + weekDay,vn.VN_CURDATE()), @a := TIMESTAMPADD(DAY, duration, @a), warehouseOutFk, warehouseInFk, @@ -86538,6 +72601,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `typeTagMake` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -86545,70 +72610,70 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` 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 - WHERE i.typeFk = vTypeFk; - - INSERT INTO itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id, CONCAT(i.size,' cm'), 1 - FROM item i - JOIN tag t ON t.name = 'Longitud' COLLATE utf8_general_ci - WHERE i.typeFk = vTypeFk; - - INSERT INTO itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id, i.category, 5 - FROM item i - JOIN tag t ON t.name = 'Categoria' COLLATE utf8_general_ci - WHERE i.typeFk = vTypeFk; - - INSERT INTO itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id, ink.name, 2 - FROM item i - JOIN tag t ON t.name = 'Color' COLLATE utf8_general_ci - JOIN ink ON ink.id = i.inkFk - WHERE i.typeFk = vTypeFk; - - INSERT INTO itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id, p.name, 3 - FROM item i - JOIN tag t ON t.name = 'Productor' COLLATE utf8_general_ci - JOIN producer p ON p.id = i.producerFk - WHERE i.typeFk = vTypeFk; - - INSERT INTO itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id, o.name, 4 - FROM item i - JOIN tag t ON t.name = 'Origen' COLLATE utf8_general_ci - JOIN origin o ON o.id = i.originFk - WHERE i.typeFk = vTypeFk; - /* - INSERT INTO itemTag(itemFk, tagFk, value, priority) - SELECT i.id, t.id, i.stems, 6 - FROM item i - JOIN tag t ON t.name = 'Tallos' COLLATE utf8_general_ci - WHERE i.typeFk = vTypeFk; - */ --- CALL itemTagArrangedUpdate(NULL); - +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 + WHERE i.typeFk = vTypeFk; + + INSERT INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, CONCAT(i.size,' cm'), 1 + FROM item i + JOIN tag t ON t.name = 'Longitud' COLLATE utf8_general_ci + WHERE i.typeFk = vTypeFk; + + INSERT INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, i.category, 5 + FROM item i + JOIN tag t ON t.name = 'Categoria' COLLATE utf8_general_ci + WHERE i.typeFk = vTypeFk; + + INSERT INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, ink.name, 2 + FROM item i + JOIN tag t ON t.name = 'Color' COLLATE utf8_general_ci + JOIN ink ON ink.id = i.inkFk + WHERE i.typeFk = vTypeFk; + + INSERT INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, p.name, 3 + FROM item i + JOIN tag t ON t.name = 'Productor' COLLATE utf8_general_ci + JOIN producer p ON p.id = i.producerFk + WHERE i.typeFk = vTypeFk; + + INSERT INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, o.name, 4 + FROM item i + JOIN tag t ON t.name = 'Origen' COLLATE utf8_general_ci + JOIN origin o ON o.id = i.originFk + WHERE i.typeFk = vTypeFk; + /* + INSERT INTO itemTag(itemFk, tagFk, value, priority) + SELECT i.id, t.id, i.stems, 6 + FROM item i + JOIN tag t ON t.name = 'Tallos' COLLATE utf8_general_ci + WHERE i.typeFk = vTypeFk; + */ +-- CALL itemTagArrangedUpdate(NULL); + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `updatePedidosInternos` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -86616,8 +72681,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `updatePedidosInternos`(vItemFk INT) BEGIN @@ -86631,6 +72694,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `visible_getMisfit` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -86638,8 +72703,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `visible_getMisfit`(vSectorFk INT) BEGIN @@ -86690,6 +72753,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `warehouseFitting` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -86697,8 +72762,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `warehouseFitting`(IN vWhOrigin INT , IN vWhDestiny INT) BEGIN @@ -86728,6 +72791,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `warehouseFitting_byTravel` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -86735,8 +72800,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `warehouseFitting_byTravel`(IN vTravelFk INT) BEGIN @@ -86756,6 +72819,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerCalculateBoss` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -86763,8 +72828,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerCalculateBoss`(vWorker INT) BEGIN @@ -86797,6 +72860,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerCalendar_calculateBusiness` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -86804,8 +72869,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerCalendar_calculateBusiness`(vYear INT, vBusinessFk INT) BEGIN @@ -86870,79 +72933,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 `workerCalendar_calculateBusiness__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `workerCalendar_calculateBusiness__`(vYear INT, vBusinessFk INT) -BEGIN - -/** - * Calcula los días y horas de vacaciones en función de un contrato y año - * - * @param vYear - * @param vBusinessFk - * @return tmp.workerCalendarCalculateBusiness (days, hours, daysEnjoyed, hoursEnjoyed) - */ - - DECLARE vStarted DATE; - DECLARE vEnded DATE; - DECLARE vDaysHoliday DECIMAL(5,2); - DECLARE vHoursWeek DECIMAL(5,2); - DECLARE vDaysToSubtract DECIMAL(5,2); - DECLARE vDaysHolidayEnjoyed DECIMAL(5,2); - DECLARE vDifDays INT; - - SELECT IF(b.date_start < CONCAT(vYear,"-01-01"), CONCAT(vYear,"-01-01"),b.date_start), - IF(b.date_end IS NULL OR YEAR(b.date_end)>vYear , CONCAT(vYear,"-12-31"), b.date_end), - IF(hasHolidayEntilement, w.days, 0), - c.hours_week - INTO vStarted, - vEnded, - vDaysHoliday, - vHoursWeek - FROM postgresql.business b - JOIN postgresql.business_labour_payroll blp ON blp.business_id = b.business_id - JOIN vn2008.payroll_contratos p ON p.CodContrato = cod_contrato - JOIN postgresql.business_labour bl ON bl.business_id = b.business_id - JOIN workCenterHoliday w ON w.workcenterFk = bl.workcenter_id - LEFT JOIN postgresql.calendar_labour_type c ON c.calendar_labour_type_id=bl.calendar_labour_type_id - WHERE b.business_id= vBusinessFk - AND w.year = vYear; - - DROP TEMPORARY TABLE IF EXISTS tmp.workerCalendarCalculateBusiness; - - IF vStarted < vEnded THEN - SET vDifDays = DAYOFYEAR(vEnded) - DAYOFYEAR(vStarted) + 1; - - SELECT IFNULL(SUM(holidayEntitlementRate), 0) , - SUM(-(discountRate - 1)) - INTO vDaysToSubtract, - vDaysHolidayEnjoyed - FROM workerCalendar w - JOIN absenceType a ON a.id = w.absenceTypeFk - WHERE w.businessFk = vBusinessFk - AND YEAR(dated) = vYear; - END IF; - - CREATE TEMPORARY TABLE tmp.workerCalendarCalculateBusiness - ENGINE = MEMORY - SELECT @days := IFNULL(ROUND((vDaysHoliday * (vDifDays - vDaysToSubtract) / IF(util.isLeapYear(vYear) , 366, 365)), 1), 0) days, - @days * (vHoursWeek / 5) hours, - @daysEnjoyed := IFNULL(ROUND(vDaysHolidayEnjoyed, 1), 0) daysEnjoyed, - @daysEnjoyed * (vHoursWeek / 5) hoursEnjoyed; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerCalendar_calculateYear` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -86950,8 +72942,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerCalendar_calculateYear`(vYear INT, vWorkerFk INT) BEGIN @@ -87018,6 +73008,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerCreate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -87025,8 +73017,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerCreate`( vFirstname VARCHAR(50), @@ -87048,6 +73038,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerCreateExternal` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -87055,8 +73047,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerCreateExternal`( vFirstName VARCHAR(50), @@ -87096,37 +73086,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 `workerCreate__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `workerCreate__`( - vFirstname VARCHAR(50), - vSurnames VARCHAR(50), - vFi VARCHAR(9), - vWorkerCode CHAR(3), - vBossFk INT, - vUserFk INT -) -BEGIN -/** - * Create new worker - * - */ - INSERT INTO worker(code, firstName, lastName, fi, userFk, bossFk) - VALUES (vWorkerCode, vFirstname, vSurnames, vFi, vUserFk, vBossFk); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerDepartmentByDate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -87134,8 +73095,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerDepartmentByDate`(vDate DATE) BEGIN @@ -87173,6 +73132,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerDisable` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -87180,13 +73141,11 @@ DELIMITER ; /*!50003 SET character_set_client = utf8 */ ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerDisable`(vUserId int) mainLabel:BEGIN - IF (SELECT COUNT(*) FROM workerDisableExcluded WHERE workerFk = vUserId AND (dated > util.VN_CURDATE() OR dated IS NULL)) > 0 THEN + IF (SELECT COUNT(*) FROM workerDisableExcluded WHERE workerFk = vUserId AND (dated > vn.VN_CURDATE() OR dated IS NULL)) > 0 THEN LEAVE mainLabel; END IF; DELETE FROM account.account @@ -87213,6 +73172,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerDisableAll` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -87220,8 +73181,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerDisableAll`() BEGIN @@ -87232,7 +73191,8 @@ BEGIN SELECT a.id FROM ((SELECT * FROM (select date_end,date_start,business_id, client_id FROM postgresql.business - ORDER BY client_id, date_end IS NULL DESC , date_end DESC) + ORDER BY client_id, date_end IS NULL DESC , date_end DESC + LIMIT 10000000000000000000) c GROUP BY client_id) c INNER JOIN postgresql.business b ON c.client_id = b.client_id AND c.business_id = b.business_id INNER JOIN postgresql.profile pr ON b.client_id = pr.profile_id @@ -87241,8 +73201,8 @@ BEGIN INNER JOIN vn.worker w ON p.id_trabajador = w.id) INNER JOIN account.account a ON w.userFk = a.id WHERE ((b.date_end) IS NOT NULL - AND (b.date_end) < util.VN_CURDATE() - AND (b.date_end) > TIMESTAMPADD(DAY, -70,util.VN_CURDATE()) ); + AND (b.date_end) < vn.VN_CURDATE() + AND (b.date_end) > TIMESTAMPADD(DAY, -70,vn.VN_CURDATE()) ); DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; @@ -87264,42 +73224,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 `workerDisable__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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`@`localhost` PROCEDURE `workerDisable__`(vUserId int) -mainLabel:BEGIN - - IF vUserId = 14255 THEN - LEAVE mainLabel; - END IF; - DELETE FROM account.account - WHERE id = vUserId; - - UPDATE account.user - SET role = 2 - WHERE id = vUserId; - - DELETE FROM pbx.sip - WHERE user_id = vUserId; - - UPDATE `client` c - JOIN payMethod p ON p.name = 'CONTADO' - SET c.credit = 0, c.payMethodFk = p.id, hasCoreVnl = FALSE - WHERE c.id = vUserId; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerForAllCalculateBoss` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -87307,8 +73233,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerForAllCalculateBoss`() BEGIN @@ -87346,322 +73270,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 `workerJourneyReplaceLauncher__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `workerJourneyReplaceLauncher__`() -BEGIN - - DECLARE vDateStart DATE; - DECLARE vDateEnd DATE; - - SET vDateStart = TIMESTAMPADD(MONTH,-1,util.VN_CURDATE()); - SET vDateEnd = util.yesterday(); - - CALL vn.workerJourneyReplace(vDateStart,vDateEnd,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 `workerJourneyReplace__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `workerJourneyReplace__`(vFromDate DATE, vToDate DATE, vUserFk INT) -BEGIN - - /* Actualiza la tabla workerJourney para que actue como caché permanente revisable de las jornadas laborales. - * vUserFk es opcional. El valor 0 indica que se tenga en cuenta a todos los usuarios. - * - * PAK Julio '18 - */ - - DELETE - FROM workerJourney - WHERE dated BETWEEN vFromDate AND vToDate - AND isPaid = FALSE - AND isUpdated = FALSE - AND vUserFk IN (0,userFk); - - - -- Se inicia la tabla con todas las fechas posibles para cada uno de los trabajadores que han fichado en el rango de fechas. - INSERT IGNORE INTO workerJourney(userFk, dated, businessFk) - SELECT w.userFk, tm.dated, b.business_id - FROM vn.worker w - JOIN postgresql.person pe ON pe.id_trabajador = w.id - JOIN postgresql.profile p ON p.person_id = pe.person_id - JOIN postgresql.business b ON b.client_id = p.profile_id - JOIN postgresql.business_labour bl ON bl.business_id = b.business_id - JOIN vn.time tm ON tm.dated BETWEEN b.date_start AND IFNULL(b.date_end,util.VN_CURDATE()) - WHERE b.date_start <= vToDate - AND IFNULL(b.date_end, util.VN_CURDATE()) >= vFromDate - -- AND bl.porhoras - AND vUserFk IN (0,w.userFk); - - - - - - -- Se actualiza la cantidad total de horas prácticas, así como el tiempo de almuerzo remunerado, si corresponde - - /*UPDATE workerJourney wj - JOIN workerTimeControl_Journey j ON wj.dated = j.dated AND wj.userFk = j.userFk - SET wj.total = j.Journey, - wj.lunch = IF(j.Journey < 5,0,0.33) - WHERE wj.dated BETWEEN vFromDate AND vToDate - AND wj.isPaid = FALSE - AND wj.isUpdated = FALSE - AND vUserFk IN (0,wj.userFk); */ - - - IF vUserFk = 0 THEN - CALL vn.timeControl_calculateAll( vFromDate , CONCAT(REPLACE(vToDate, '00:00:00', ''), ' 23:59:59')); - ELSE - CALL vn.timeControl_calculateByUser( vUserFk, vFromDate , CONCAT(REPLACE(vToDate, '00:00:00', ''), ' 23:59:59')); - END IF; - - UPDATE workerJourney wj - JOIN tmp.timeControlCalculate t ON wj.dated = t.dated AND wj.userFk = t.userFk - SET wj.total = CAST(IF(t.timeWorkDecimal >= 5.33,t.timeWorkDecimal-0.33,t.timeWorkDecimal) AS DECIMAL (10,2)), - wj.lunch = IF(t.timeWorkDecimal >= 5.33,0.33,0) - WHERE wj.dated BETWEEN vFromDate AND vToDate - AND wj.isPaid = FALSE - AND wj.isUpdated = FALSE - AND vUserFk IN (0,wj.userFk); - - DROP TEMPORARY TABLE tmp.timeControlCalculate; - - - - /********** NOCTURNIDAD ************/ - DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControl; - - CREATE TEMPORARY TABLE tmp.workerTimeControl - SELECT w.*, 0 as Non - FROM vn.workerTimeControl w - WHERE timed BETWEEN vFromDate AND vToDate - AND vUserFk IN (0,userFk) - ORDER BY userFk, timed; - - -- Regalamos un segundo para evitar que hayan fichadas en las horas claves de inicio y fin de la nocturnidad. - UPDATE tmp.workerTimeControl - SET timed = TIMESTAMPADD(SECOND,-1,timed) - WHERE TIME(timed) IN ('06:00:00','22:00:00'); - - -- Fichada virtual a las 6:00 h, hora en que empieza la jornada diurna - INSERT INTO tmp.workerTimeControl(userFk, timed) - SELECT userFk, TIMESTAMPADD(HOUR, 6, DATE(timed)) - FROM vn.workerTimeControl - WHERE vUserFk IN (0,userFk) - GROUP BY userFk, DATE(timed); - - -- Fichada virtual a las 22:00 h, momento en que empieza la jornada nocturna. - INSERT INTO tmp.workerTimeControl(userFk, timed) - SELECT userFk, TIMESTAMPADD(HOUR, 22, DATE(timed)) - FROM vn.workerTimeControl - WHERE vUserFk IN (0,userFk) - GROUP BY userFk, DATE(timed); - - -- Establece el orden en que se han de leer las fichadas - CALL vn.workerTimeControlSetOrder; - - -- Marca los impares para facilitar la consulta siguiente - UPDATE tmp.workerTimeControl - SET Non = 1 - WHERE `order` mod 2; - - -- Actualizamos la nocturnidad - UPDATE workerJourney wj - JOIN - ( SELECT userFk, Dia, sum(Nocturnidad) as Nocturnidad FROM - ( - SELECT userFk, - date(timed) as Dia, - (( - IF( TIME(timed) < '06:00:00' OR (TIME(timed) = '06:00:00' AND Non = FALSE ) , IF(Non,-1,1),0) - + - IF(TIME(timed) > '22:00:00' OR (TIME(timed) = '22:00:00' AND Non = TRUE), If(Non,-1,1),0) - ) - * (HOUR(`timed`) + MINUTE(`timed`) / 60) - ) as Nocturnidad - FROM tmp.workerTimeControl - ) sub - GROUP BY Dia, userFk - HAVING Nocturnidad - ) night ON night.userFk = wj.userFk AND night.Dia = wj.dated - SET wj.nocturn = night.Nocturnidad - WHERE wj.isPaid = FALSE AND isUpdated = FALSE; - - -- Horas téoricas y precio de la hora ordinaria - UPDATE vn.workerJourney wj - JOIN postgresql.business_labour_payroll blp ON blp.business_id = wj.businessFk - JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk - JOIN postgresql.calendar_labour_type pclt ON pclt.calendar_labour_type_id = bl.calendar_labour_type_id - SET wj.priceOrdinaryHour = (12 * blp.importepactado) / (52 * pclt.hours_week), - wj.contractJourney = pclt.hours_week/5 - WHERE wj.dated BETWEEN vFromDate AND vToDate - AND vUserFk IN (0,wj.userFk) - AND wj.isPaid = FALSE - AND isUpdated = FALSE; - - -- Precio Extras, Vacaciones y Nocturnas - UPDATE vn.workerJourney wj - JOIN - ( - SELECT dated, hollidayInc, nightInc, extraInc - FROM ( - SELECT tm.dated , hollidayInc, nightInc, extraInc - FROM vn.time tm - JOIN vn.workerHourPrice whp ON tm.dated >= whp.dated - ORDER BY tm.dated, whp.dated DESC - ) sub - GROUP BY dated - ) conv ON conv.dated = wj.dated - SET wj.priceHollydayHour = wj.priceOrdinaryHour * conv.hollidayInc, - wj.priceNocturnHour = wj.priceOrdinaryHour * conv.nightInc, - wj.priceExtraHour = wj.priceOrdinaryHour * conv.extraInc - WHERE wj.dated BETWEEN vFromDate AND vToDate - AND vUserFk IN (0,wj.userFk) - AND wj.isPaid = FALSE - AND wj.isUpdated = FALSE; - - -- Elimina el precio de las horas extras para los contratos parciales. - UPDATE vn.workerJourney wj - JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk - JOIN postgresql.calendar_labour_type clt ON clt.calendar_labour_type_id = bl.calendar_labour_type_id - SET wj.priceExtraHour = 0 - WHERE clt.isPartial - AND wj.dated BETWEEN vFromDate AND vToDate - AND vUserFk IN (0,wj.userFk) - AND wj.isPaid = FALSE - AND wj.isUpdated = FALSE; - - -- Bajas, vacaciones y festivos personales - /* UPDATE vn.workerJourney wj - JOIN postgresql.calendar_employee pce ON pce.date = wj.dated AND pce.business_id = wj.businessFk - JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk - SET wj.permission = IF(pce.calendar_state_id = 6, 0.5, 1) * wj.contractJourney, - wj.contractJourney = IF(pce.calendar_state_id = 6, 0.5, 0) * wj.contractJourney,-- Vacaciones medio dia - wj.hollyday = wj.total - IF(pce.calendar_state_id = 6, 0.5, 0) * wj.contractJourney - WHERE wj.dated BETWEEN vFromDate AND vToDate - AND vUserFk IN (0,wj.userFk) - AND wj.isPaid = FALSE - AND wj.isUpdated = FALSE;*/ - - UPDATE vn.workerJourney wj - JOIN postgresql.calendar_employee pce ON pce.date = wj.dated AND pce.business_id = wj.businessFk - JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk - JOIN postgresql.calendar_state cs ON cs.calendar_state_id = pce.calendar_state_id - SET wj.permission = cs.permissionRate * wj.contractJourney, - wj.contractJourney = IF(cs.permissionRate = 1, 0, cs.permissionRate) * wj.contractJourney, - wj.hollyday = wj.total - IF(cs.permissionRate = 1, 0, cs.permissionRate) * wj.contractJourney - WHERE cs.permissionRate > 0 - AND wj.dated BETWEEN vFromDate AND vToDate - AND vUserFk IN (0,wj.userFk) - AND wj.isPaid = FALSE - AND wj.isUpdated = FALSE; - - - - - -- Festivos por centro de trabajo -UPDATE vn.workerJourney wj - JOIN vn.calendarHolidays ch ON ch.dated = wj.dated - JOIN postgresql.business_labour pbl ON wj.businessFk = pbl.business_id AND pbl.workcenter_id = ch.workcenterFk - SET wj.hollyday = wj.total, - wj.permission = wj.contractJourney, - wj.contractJourney = 0 - WHERE wj.dated BETWEEN vFromDate AND vToDate - AND vUserFk IN (0,wj.userFk) - AND wj.isPaid = FALSE - AND wj.isUpdated = FALSE; - - -- Domingos - UPDATE vn.workerJourney - SET hollyday = total, - contractJourney = 0 - WHERE weekday(dated) = 6 - AND dated BETWEEN vFromDate AND vToDate - AND vUserFk IN (0,userFk) - AND isPaid = FALSE - AND isUpdated = FALSE; - - -- Sábados - UPDATE vn.workerJourney - SET contractJourney = 0 - WHERE weekday(dated) = 5 - AND dated BETWEEN vFromDate AND vToDate - AND vUserFk IN (0,userFk) - AND isPaid = FALSE - AND isUpdated = FALSE; - - - -- Horas extras - UPDATE workerJourney - SET extra = lunch + total - contractJourney - WHERE dated BETWEEN vFromDate AND vToDate - AND vUserFk IN (0,userFk) - AND isPaid = FALSE - AND isUpdated = FALSE; - - -- Contratos NO por horas - INSERT IGNORE INTO workerJourney( userFk, - dated, - businessFk, - priceOrdinaryHour, - contractJourney, - total) - SELECT w.userFk, - tm.dated, - b.business_id, - (12 * blp.importepactado) / (52 * pclt.hours_week) as priceOrdinaryHour, - IF(weekday(tm.dated) IN (5,6),0, pclt.hours_week/5) as contractJourney, - IF(weekday(tm.dated) IN (5,6),0, pclt.hours_week/5) as total - FROM vn.worker w - JOIN postgresql.person pe ON pe.id_trabajador = w.id - JOIN postgresql.profile p ON p.person_id = pe.person_id - JOIN postgresql.business b ON b.client_id = p.profile_id - JOIN postgresql.business_labour bl ON bl.business_id = b.business_id - JOIN postgresql.calendar_labour_type pclt ON pclt.calendar_labour_type_id = bl.calendar_labour_type_id - JOIN postgresql.business_labour_payroll blp ON blp.business_id = b.business_id - JOIN vn.time tm ON tm.dated BETWEEN b.date_start AND IFNULL(b.date_end,util.VN_CURDATE()) - WHERE b.date_start <= vToDate - AND IFNULL(b.date_end, util.VN_CURDATE()) >= vFromDate - AND bl.porhoras = FALSE - AND vUserFk IN (0,w.userFk); - - -- Elimina dias sin fichadas ni contrato - /* DELETE FROM workerJourney - WHERE contractJourney = 0 - AND total = 0 - AND permission = 0 - AND dated BETWEEN vFromDate AND vToDate - AND vUserFk IN (0,userFk) - AND isPaid = FALSE - AND isUpdated = FALSE; -*/ -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerJourney_replace` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -87669,8 +73279,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerJourney_replace`(vDatedFrom DATE, vDatedTo DATE, vWorkerFk INT) BEGIN @@ -87711,7 +73319,7 @@ BEGIN INSERT IGNORE INTO workerJourney(userFk, dated, businessFk) SELECT w.workerFk, t.dated, w.businessFk FROM workerLabour w - JOIN time t ON t.dated BETWEEN w.started AND IFNULL(w.ended,util.VN_CURDATE()) + JOIN time t ON t.dated BETWEEN w.started AND IFNULL(w.ended,vn.VN_CURDATE()) WHERE t.dated BETWEEN vDatedFrom AND vDatedTo AND (vWorkerFk IS NULL OR w.workerFk = vWorkerFk) ORDER BY w.workerFk, t.dated, w.businessFk; @@ -87849,6 +73457,7 @@ BEGIN WHERE wtc.timed BETWEEN vDatedFrom AND util.dayEnd(vDatedToTomorrow) AND tce.id IS NULL ORDER BY userFk, timed ASC + LIMIT 10000000000000000000 ) wtc )sub WHERE sub.dated BETWEEN vDatedFrom AND vDatedTo @@ -87953,194 +73562,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 `workerJourney_replace__` */; -/*!50003 SET @saved_cs_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`@`localhost` PROCEDURE `workerJourney_replace__`(vDatedFrom DATE, vDatedTo DATE, vWorkerFk INT) -BEGIN -/** - * Actualiza la tabla workerJourney para que actue como caché permanente revisable de las jornadas laborales. - * @param vDatedFrom workerTimeControl - * @param vDatedTo workerTimeControl - * @param vWorkerFk, en caso de pasar 0 ó NULL se aplica a todos - */ - - DECLARE vDatedTimeTo DATETIME; - DECLARE vMaxTimePerDay INT; - DECLARE vMinHoursToBreak DECIMAL(10,2); - DECLARE vBreakHours DECIMAL(10,2); - DECLARE vMonthByYear INT; - DECLARE vWeeksByYear INT DEFAULT 52; - DECLARE vMonthsByYear INT DEFAULT 12; - DECLARE vDaysByWeek INT DEFAULT 5; - - SET vDatedTimeTo = util.dayEnd(vDatedTo); - - SELECT minHoursToBreak, breakHours, maxTimePerDay - INTO vMinHoursToBreak, vBreakHours, vMaxTimePerDay - FROM workerTimeControlConfig; - - DELETE FROM workerJourney - WHERE dated BETWEEN vDatedFrom AND vDatedTo - AND NOT isPaid - AND NOT isUpdated - AND (vWorkerFk IS NULL OR userFK = vWorkerFk); - - -- Se inserta todos los días del periodo por worker y business en el rango de fechas. - INSERT IGNORE INTO workerJourney(userFk, dated, businessFk) - SELECT w.workerFk, t.dated, w.businessFk - FROM workerLabour w - JOIN time t ON t.dated BETWEEN w.started AND IFNULL(w.ended,util.VN_CURDATE()) - WHERE t.dated BETWEEN vDatedFrom AND vDatedTo - AND (vWorkerFk IS NULL OR w.workerFk = vWorkerFk) - ORDER BY w.workerFk, t.dated, w.businessFk; - - IF vWorkerFk THEN - CALL timeControl_calculateByUser(vWorkerFk, vDatedFrom , vDatedTimeTo); - ELSE - CALL timeControl_calculateAll(vDatedFrom, vDatedTimeTo); - END IF; - - UPDATE workerJourney wj - JOIN tmp.timeControlCalculate t ON wj.dated = t.dated AND wj.userFk = t.userFk - SET wj.total = CAST(IF(t.timeWorkDecimal >= vMinHoursToBreak, t.timeWorkDecimal - vBreakHours, t.timeWorkDecimal) AS DECIMAL (10,2)), - wj.lunch = IF(t.timeWorkDecimal >= vMinHoursToBreak , vBreakHours , 0) - WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo - AND NOT wj.isPaid - AND NOT wj.isUpdated - AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk); - - -- NOCTURNIDAD - - SET @vIsOdd := TRUE; - SET @vDated := NULL; - CALL vn.workerTimeControl_calculateOddDays(); - - UPDATE workerJourney wj - JOIN (SELECT sub.dated, userFk, SUM(NigthlyHours) NigthlyHours - FROM(SELECT IF(@vIsOdd, @vIsOdd := FALSE, @vIsOdd := TRUE), - IF(direction='in', @vIsOdd := TRUE, @vIsOdd := @vIsOdd), - IF(@vIsOdd, @vLastTimed:=UNIX_TIMESTAMP(timed),@vLastTimed:=@vLastTimed), - IF(direction='in', @vDated := DATE(wtc.timed), @vDated :=@vDated) dated, - wtc.userFk, - IF(UNIX_TIMESTAMP(timed)- @vLastTimed < vMaxTimePerDay, - vn.workerNigthlyHours_calculate(FROM_UNIXTIME(@vLastTimed), wtc.timed), - 0) NigthlyHours - FROM (SELECT DISTINCT(wtc.id), wtc.userFk, wtc.timed, wtc.direction - FROM workerTimeControl wtc - WHERE wtc.timed BETWEEN vDatedFrom AND util.dayEnd(DATE_ADD(vDatedTo, INTERVAL 1 DAY)) - ORDER BY userFk, timed ASC - ) wtc - )sub - LEFT JOIN tmp.workerTimeControlOddDays wo ON wo.workerFk = sub.userFk - AND wo.dated = sub.dated - WHERE sub.dated BETWEEN vDatedFrom AND vDatedTo - AND wo.workerFk IS NULL - GROUP BY userFk, sub.dated - )night ON night.userFk = wj.userFk AND night.dated = wj.dated - SET wj.nocturn = night.NigthlyHours - WHERE NOT wj.isPaid - AND NOT isUpdated - AND night.NigthlyHours <> 0; - - -- Horas téoricas y precio de la hora ordinaria - UPDATE workerJourney wj - JOIN postgresql.business_labour_payroll blp ON blp.business_id = wj.businessFk - JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk - JOIN postgresql.calendar_labour_type cl ON cl.calendar_labour_type_id = bl.calendar_labour_type_id - SET wj.priceOrdinaryHour = (vMonthsByYear * blp.importepactado) / (vWeeksByYear * cl.hours_week), - wj.contractJourney = cl.hours_week / vDaysByWeek - WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo - AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk) - AND NOT wj.isPaid - AND NOT isUpdated; - - -- Precio Extras, Vacaciones y Nocturnas - UPDATE workerJourney wj - JOIN(SELECT MAX(w.dated), t.dated, w.holidayInc, w.nightInc, w.extraInc - FROM time t - JOIN workerHourPrice w ON w.dated <= t.dated - WHERE t.dated BETWEEN vDatedFrom AND vDatedTo - GROUP BY t.dated - ) sub ON sub.dated = wj.dated - SET wj.priceHolidayHour = wj.priceOrdinaryHour * sub.holidayInc, - wj.priceNocturnHour = wj.priceOrdinaryHour * sub.nightInc, - wj.priceExtraHour = wj.priceOrdinaryHour * sub.extraInc - WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo - AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk) - AND NOT wj.isPaid - AND NOT wj.isUpdated; - - -- Elimina el precio de las horas extras para los contratos parciales. - UPDATE workerJourney wj - JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk - JOIN postgresql.calendar_labour_type cl ON cl.calendar_labour_type_id = bl.calendar_labour_type_id - SET wj.priceExtraHour = 0 - WHERE cl.isPartial - AND wj.dated BETWEEN vDatedFrom AND vDatedTo - AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk) - AND NOT wj.isPaid - AND NOT wj.isUpdated; - - -- Ausencias - UPDATE workerJourney wj - JOIN businessCalendar bc ON bc.businessFk = wj.businessFk AND bc.dated = wj.dated - JOIN absenceType ab ON ab.id = bc.absenceTypeFk - JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk - SET wj.permission = ab.permissionRate * wj.contractJourney, - wj.contractJourney = IF(ab.permissionRate = 1, 0, ab.permissionRate) * wj.contractJourney - WHERE ab.permissionRate > 0 - AND wj.dated BETWEEN vDatedFrom AND vDatedTo - AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk) - AND NOT wj.isPaid - AND NOT wj.isUpdated; - - -- Sábados / Domingos - UPDATE workerJourney - SET holiday = IF(DAYNAME(dated)='sábado', 0, total), - contractJourney = 0 - WHERE DAYNAME(dated) IN ('sábado', 'domingo') - AND dated BETWEEN vDatedFrom AND vDatedTo - AND (vWorkerFk IS NULL OR userFk = vWorkerFk) - AND NOT isPaid - AND NOT isUpdated; - - -- Festivos por centro de trabajo - UPDATE workerJourney wj - JOIN calendarHolidays ch ON ch.dated = wj.dated - JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk - AND bl.workcenter_id = ch.workcenterFk - SET wj.holiday = wj.total, - wj.permission = wj.contractJourney, - wj.contractJourney = 0 - WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo - AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk) - AND NOT wj.isPaid - AND NOT wj.isUpdated; - - -- Horas extras - UPDATE workerJourney - SET extra = lunch + total - contractJourney - WHERE dated BETWEEN vDatedFrom AND vDatedTo - AND (vWorkerFk IS NULL OR userFk = vWorkerFk) - AND NOT isPaid - AND NOT isUpdated; - - DROP TEMPORARY TABLE tmp.timeControlCalculate; - DROP TEMPORARY TABLE tmp.workerTimeControlOddDays; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!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 sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerMistakeType_get` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -88148,26 +73571,26 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerMistakeType_get`() -BEGIN - -/** - * Obtiene los tipos de error para los trabajadores - */ - - SELECT code, description - FROM workerMistakeType - ORDER BY description; - +BEGIN + +/** + * Obtiene los tipos de error para los trabajadores + */ + + SELECT code, description + FROM workerMistakeType + ORDER BY description; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerMistake_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -88175,37 +73598,37 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerMistake_add`(vWorkerFk INT, vWorkerMistakeTypeFk VARCHAR(10), vUserFk INT ) -BEGIN - -/** - * Añade error al trabajador - * - * @param vWorkerFk id del trabajador al cual se le va a añadir error - * @param vWorkerMistakeTypeFk code del tipo de error - * @param vUserFk id del usuario que pone el error - * - */ - DECLARE vWorkerName VARCHAR(255) DEFAULT account.user_getNameFromId(vUserFk); - - IF(account.user_hasRole(vWorkerName,'coolerBoss')) - THEN - INSERT INTO vn.workerMistake(userFk, workerMistakeTypeFk) - VALUES(vWorkerFk, vWorkerMistakeTypeFk); - ELSE - CALL util.throw('No tienes permisos para realizar la acción'); - - END IF; - +BEGIN + +/** + * Añade error al trabajador + * + * @param vWorkerFk id del trabajador al cual se le va a añadir error + * @param vWorkerMistakeTypeFk code del tipo de error + * @param vUserFk id del usuario que pone el error + * + */ + DECLARE vWorkerName VARCHAR(255) DEFAULT account.user_getNameFromId(vUserFk); + + IF(account.user_hasRole(vWorkerName,'coolerBoss')) + THEN + INSERT INTO vn.workerMistake(userFk, workerMistakeTypeFk) + VALUES(vWorkerFk, vWorkerMistakeTypeFk); + ELSE + CALL util.throw('No tienes permisos para realizar la acción'); + + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerShelving_Add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -88213,38 +73636,38 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` 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); +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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerShelving_delete` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -88252,42 +73675,42 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerShelving_delete`(vWorkerFk INT, vBarcode VARCHAR(12)) -BEGIN -/* - * Borra de workerShelving el carro o etiqueta insertado por el 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; - - DELETE FROM vn.workerShelving - WHERE shelvingFk = vBarcode COLLATE utf8_general_ci - AND workerFk = vWorkerFk ; - +BEGIN +/* + * Borra de workerShelving el carro o etiqueta insertado por el 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; + + DELETE FROM vn.workerShelving + WHERE shelvingFk = vBarcode COLLATE utf8_general_ci + AND workerFk = vWorkerFk ; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControlAdd` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -88295,8 +73718,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControlAdd`(IN vUserFk INT, IN vWarehouseFk INT, IN vDated DATETIME) BEGIN @@ -88306,7 +73727,7 @@ BEGIN CALL vn.workerTimeControlSOWP(vUserFk , vDated);*/ - CALL vn.workerTimeControl_add(vUserFk,vWarehouseFk,util.VN_NOW(),FALSE); + CALL vn.workerTimeControl_add(vUserFk,vWarehouseFk,vn.VN_NOW(),FALSE); END ;; @@ -88315,45 +73736,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 `workerTimeControlNonDays__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControlNonDays__`() -BEGIN - SET @cont := 0; - SELECT sub2.userFk, sub2.dated Fecha, CONCAT (w.firstName," ", w.lastName) worker, au.name Boss, d.name - FROM (SELECT userFk, - dated, - COUNT(*) cont2 - FROM (SELECT DATE(wtc.timed) dated, - userFk, - IFNULL(@cont, @cont := 0 ), - IF(direction = 'in', @cont:=@cont+1, TRUE), - @cont cont - FROM vn.workerTimeControl wtc - WHERE wtc.timed BETWEEN TIMESTAMPADD(YEAR,-1,util.VN_CURDATE()) AND util.VN_CURDATE() - ORDER BY userFk, timed)sub - GROUP BY cont - HAVING cont2 MOD 2 = 1)sub2 - JOIN worker w ON w.userFk = sub2.userFk - LEFT JOIN worker wb ON wb.id = w.bossFk - LEFT JOIN account.user au ON au.id = wb.userFK - LEFT JOIN workerDepartment wd ON wd.workerFk = w.id - LEFT JOIN department d ON d.id = wd.departmentFk - ORDER BY Boss ASC; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControlPinGenerate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -88361,8 +73745,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControlPinGenerate`( vWorkerFk INT) @@ -88380,6 +73762,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControlSetOrder` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -88387,8 +73771,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControlSetOrder`() BEGIN @@ -88409,6 +73791,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControlSetOrder_by_User_and_dateRange` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -88416,8 +73800,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControlSetOrder_by_User_and_dateRange`(vUserFk INT, vStarted DATE, vFinished DATE) BEGIN @@ -88437,6 +73819,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControlSOWP` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -88444,8 +73828,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControlSOWP`(IN vUserFk INT, IN vDated DATE) BEGIN @@ -88463,6 +73845,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_add` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -88470,8 +73854,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_add`(IN vUserFk INT, IN vWarehouseFk INT, IN vTimed DATETIME, IN vIsManual BOOL) BEGIN @@ -88484,70 +73866,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 `workerTimeControl_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_add__`(IN vUserFk INT, IN vWarehouseFk INT, IN vTimed DATETIME, IN vIsManual BOOL) -BEGIN - - DECLARE vDirection VARCHAR(6); - DECLARE vLastIn DATETIME; - DECLARE vDayStayMax INT; - DECLARE vHasDirectionOut INT; - - SELECT dayStayMax INTO vDayStayMax - FROM vn.workerTimeControlParams; - - SELECT vn.timeWorkerControl_getDirection(vUserFk,vTimed) INTO vDirection; - - IF vDirection = 'out' THEN - - SELECT MAX(timed) INTO vLastIn - FROM vn.workerTimeControl - WHERE userFk = vUserFk - AND direction = 'in' - AND timed < vTimed; - - UPDATE vn.workerTimeControl wtc - SET wtc.direction = 'middle' - WHERE userFk = vUserFk - AND direction = 'out' - AND timed BETWEEN vLastIn AND vTimed; - - ELSE IF vDirection = 'in' THEN - - SELECT COUNT(*) INTO vHasDirectionOut - FROM vn.workerTimeControl wtc - WHERE userFk = vUserFk - AND direction = 'out' - AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); - - UPDATE vn.workerTimeControl wtc - SET wtc.direction = IF (vHasDirectionOut,'middle','out') - WHERE userFk = vUserFk - AND direction = 'in' - AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); - - END IF; - END IF; - - INSERT INTO workerTimeControl(userFk, timed, warehouseFk, direction, manual) - VALUES(vUserFk, vTimed, vWarehouseFk, vDirection, vIsManual); - - CALL vn.workerTimeControlSOWP(vUserFk, vTimed); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_calculateOddDays` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -88555,42 +73875,47 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_calculateOddDays`() BEGIN -/* - * Calculo de las fichadas impares por empleado y dia +/** + * Calculo de las fichadas impares por empleado y dia. + * * @return tmp.workerTimeControlOddDays (userFk, dated) */ SET @cont := FALSE; SET @lastUserFk:= NULL; - DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlOddDays; - CREATE TEMPORARY TABLE tmp.workerTimeControlOddDays + + DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlOddDays; + CREATE TEMPORARY TABLE tmp.workerTimeControlOddDays SELECT sub2.userFk workerFk, sub2.dated - FROM (SELECT userFk, - dated, - COUNT(*) cont2 - FROM (SELECT DATE(wtc.timed) dated, - userFk, - IFNULL(@cont, @cont := TRUE ), - IF(direction = 'in' OR userFk <> @lastUserFk, @cont := @cont+1, TRUE), - @cont cont, - @lastUserFk := userFk + FROM ( + SELECT userFk, + dated, + COUNT(*) cont2 + FROM ( + SELECT DATE(wtc.timed) dated, + userFk, + IFNULL(@cont, @cont := TRUE ), + IF(direction = 'in' OR userFk <> @lastUserFk, @cont := @cont+1, TRUE), + @cont cont, + @lastUserFk := userFk FROM workerTimeControl wtc - WHERE wtc.timed BETWEEN TIMESTAMPADD(YEAR,-1,util.VN_CURDATE()) AND util.dayEnd(util.VN_CURDATE()) - ORDER BY userFk, timed)sub - GROUP BY cont - HAVING cont2 MOD 2 = 1)sub2 - JOIN worker w ON w.userFk = sub2.userFk; - + WHERE wtc.timed BETWEEN TIMESTAMPADD(YEAR,-1,vn.VN_CURDATE()) AND util.dayEnd(vn.VN_CURDATE()) + ORDER BY userFk, timed + LIMIT 10000000000000000000)sub + GROUP BY cont + HAVING cont2 MOD 2 = 1 + )sub2 + JOIN worker w ON w.userFk = sub2.userFk; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_check` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -88598,8 +73923,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_check`(vUserFk INT, vDated DATE,vTabletFk VARCHAR(100)) proc: BEGIN @@ -88610,93 +73933,93 @@ proc: BEGIN * @return Retorna si encuentra un problema 'odd','maxTimeWork','breakDay','breakWeek' ; * En caso de tener algun problema retorna el primero que encuentra */ - DECLARE vLastIn DATETIME ; - DECLARE vLastOut DATETIME ; - DECLARE vDayWorkMax INT; - DECLARE vDayBreak INT; - DECLARE vWeekBreak INT ; + DECLARE vLastIn DATETIME ; + DECLARE vLastOut DATETIME ; + DECLARE vDayWorkMax INT; + DECLARE vDayBreak INT; + DECLARE vWeekBreak INT ; DECLARE vWeekScope INT; - DECLARE vDayStayMax INT; - DECLARE vProblem VARCHAR(20) DEFAULT NULL; - DECLARE vTimedWorked INT; - DECLARE vCalendarStateType VARCHAR(20) DEFAULT NULL; - DECLARE vDepartmentFk INT; - DECLARE vTo VARCHAR(50) DEFAULT NULL; - DECLARE vUserName VARCHAR(50) DEFAULT NULL; - DECLARE vBody VARCHAR(255) DEFAULT NULL; - + DECLARE vDayStayMax INT; + DECLARE vProblem VARCHAR(20) DEFAULT NULL; + DECLARE vTimedWorked INT; + DECLARE vCalendarStateType VARCHAR(20) DEFAULT NULL; + DECLARE vDepartmentFk INT; + DECLARE vTo VARCHAR(50) DEFAULT NULL; + DECLARE vUserName VARCHAR(50) DEFAULT NULL; + DECLARE vBody VARCHAR(255) DEFAULT NULL; + SELECT dayBreak, weekBreak, weekScope, dayWorkMax, dayStayMax INTO vDayBreak, vWeekBreak, vWeekScope, vDayWorkMax, vDayStayMax FROM workerTimeControlParams; - SELECT MAX(timed) INTO vLastIn + SELECT MAX(timed) INTO vLastIn FROM workerTimeControl - WHERE userFk = vUserFk + WHERE userFk = vUserFk AND direction = 'in'; - - SELECT MAX(timed) INTO vLastOut + + SELECT MAX(timed) INTO vLastOut FROM workerTimeControl - WHERE userFk = vUserFk + WHERE userFk = vUserFk AND direction = 'out'; - - SELECT CONCAT(u.name,'@verdnatura.es') INTO vTo + + SELECT CONCAT(u.name,'@verdnatura.es') INTO vTo FROM account.user u - WHERE u.id = (SELECT bossFk FROM worker WHERE id = vUserFk); - + WHERE u.id = (SELECT bossFk FROM worker WHERE id = vUserFk); + SELECT CONCAT(firstName,' ',lastName) INTO vUserName FROM worker w - WHERE w.id = vUserFk; - - - IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastIn) > vDayStayMax THEN -- NUEVA JORNADA - - -- VERIFICAR DESCANSO DIARIO - IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vDayBreak THEN - SELECT "Descansos 12 h" AS problem; - -- ENVIAMOS CORREO AL BOSSFK + WHERE w.id = vUserFk; + + + IF UNIX_TIMESTAMP(vn.VN_NOW()) - UNIX_TIMESTAMP(vLastIn) > vDayStayMax THEN -- NUEVA JORNADA + + -- VERIFICAR DESCANSO DIARIO + IF UNIX_TIMESTAMP(vn.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vDayBreak THEN + SELECT "Descansos 12 h" AS problem; + -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos 12 h") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - END IF; - - -- VERIFICAR FICHADAS IMPARES DEL ÚLTIMO DÍA QUE SE FICHÓ + LEAVE proc; + END IF; + + -- VERIFICAR FICHADAS IMPARES DEL ÚLTIMO DÍA QUE SE FICHÓ IF (SELECT MOD(COUNT(*),2) -- <>0 FROM workerTimeControl WHERE userFk = vUserFk AND timed >= vLastIn ) THEN SELECT "Dias con fichadas impares" AS problem; - -- ENVIAMOS CORREO AL BOSSFK + -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Dias con fichadas impares") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; + LEAVE proc; END IF; - - -- VERIFICAR VACACIONES - SELECT cs.type INTO vCalendarStateType + + -- VERIFICAR VACACIONES + SELECT at2.name INTO vCalendarStateType FROM postgresql.calendar_employee ce JOIN postgresql.business b USING(business_id) JOIN postgresql.profile pr ON pr.profile_id = b.client_id JOIN postgresql.person p ON p.person_id = pr.person_id - JOIN postgresql.calendar_state cs USING(calendar_state_id) + JOIN vn.absenceType at2 ON at2.id = ce.calendar_state_id JOIN worker w ON w.id = p.id_trabajador - WHERE ce.date = util.VN_CURDATE() - AND cs.isAllowedToWork = FALSE + WHERE ce.date = vn.VN_CURDATE() + AND at2.isAllowedToWork = FALSE AND w.userFk = vUserFk LIMIT 1; - - IF(LENGTH(vCalendarStateType)) THEN + + IF(LENGTH(vCalendarStateType)) THEN SELECT vCalendarStateType AS problem; - -- ENVIAMOS CORREO AL BOSSFK + -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Vacaciones") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - - END IF; - - - -- VERIFICAR CONTRATO EN VIGOR - IF (SELECT COUNT(*) + LEAVE proc; + + END IF; + + + -- VERIFICAR CONTRATO EN VIGOR + IF (SELECT COUNT(*) FROM postgresql.business b JOIN postgresql.profile pr ON pr.profile_id = b.client_id JOIN postgresql.person p ON p.person_id = pr.person_id @@ -88705,58 +74028,58 @@ proc: BEGIN AND b.date_start <= vDated AND IFNULL(b.date_end,vDated) >= vDated ) = 0 THEN - SELECT "No hay un contrato en vigor" AS problem; - -- ENVIAMOS CORREO AL BOSSFK + SELECT "No hay un contrato en vigor" AS problem; + -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"No hay un contrato en vigor") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); LEAVE proc; - + END IF; - -- VERIFICAR DESCANSO SEMANAL + -- VERIFICAR DESCANSO SEMANAL SET @vHasBreakWeek:= FALSE; - SET @vLastTimed:= UNIX_TIMESTAMP((util.VN_NOW() - INTERVAL vWeekScope SECOND)); - + SET @vLastTimed:= UNIX_TIMESTAMP((vn.VN_NOW() - INTERVAL vWeekScope SECOND)); + DROP TEMPORARY TABLE IF EXISTS tmp.trash; CREATE TEMPORARY TABLE tmp.trash - SELECT IF(vWeekBreak-(UNIX_TIMESTAMP(timed)-@vLastTimed) <= 0, @vHasBreakWeek:=TRUE, TRUE) alias, + SELECT IF(vWeekBreak-(UNIX_TIMESTAMP(timed)-@vLastTimed) <= 0, @vHasBreakWeek:=TRUE, TRUE) alias, @vLastTimed:= UNIX_TIMESTAMP(timed) FROM workerTimeControl - WHERE timed>= (util.VN_NOW() - INTERVAL vWeekScope SECOND) + WHERE timed>= (vn.VN_NOW() - INTERVAL vWeekScope SECOND) AND userFk= vUserFk AND direction IN ('in','out') ORDER BY timed ASC; - - IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vWeekBreak AND @vHasBreakWeek = FALSE THEN -- REVISA SI EL DESCANSO SE HA REALIZADO DESPUÉS DE LA ÚLTIMA FICHADA + + IF UNIX_TIMESTAMP(vn.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vWeekBreak AND @vHasBreakWeek = FALSE THEN -- REVISA SI EL DESCANSO SE HA REALIZADO DESPUÉS DE LA ÚLTIMA FICHADA SELECT "Descansos 36 h" AS problem; - -- ENVIAMOS CORREO AL BOSSFK + -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos 36 h") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; + LEAVE proc; END IF; - DROP TEMPORARY TABLE tmp.trash; - - ELSE -- DIA ACTUAL + DROP TEMPORARY TABLE tmp.trash; + + ELSE -- DIA ACTUAL -- VERIFICA QUE EL TIEMPO EFECTIVO NO SUPERE EL MÁXIMO - SELECT IFNULL(SUM(if( mod(wtc.order,2)=1, -UNIX_TIMESTAMP(timed), UNIX_TIMESTAMP(timed))),0) - IF( MOD(COUNT(*),2), UNIX_TIMESTAMP(util.VN_NOW()), 0) INTO vTimedWorked + SELECT IFNULL(SUM(if( mod(wtc.order,2)=1, -UNIX_TIMESTAMP(timed), UNIX_TIMESTAMP(timed))),0) - IF( MOD(COUNT(*),2), UNIX_TIMESTAMP(vn.VN_NOW()), 0) INTO vTimedWorked FROM workerTimeControl wtc WHERE userFk = vUserFk AND timed >= vLastIn ORDER BY timed; - IF vTimedWorked > vDayWorkMax THEN - SELECT "Jornadas" AS problem; - -- ENVIAMOS CORREO AL BOSSFK + IF vTimedWorked > vDayWorkMax THEN + SELECT "Jornadas" AS problem; + -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Jornadas") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; + LEAVE proc; END IF; END IF; - - -- VERIFICAR DEPARTAMENTO + + -- VERIFICAR DEPARTAMENTO /* IF vTabletFk IS NOT NULL THEN SELECT wtcu.departmentFk INTO vDepartmentFk FROM workerTimeControlUserInfo wtcu @@ -88766,7 +74089,7 @@ proc: BEGIN WHERE td.tabletFk = vTabletFk AND td.departmentFk = vDepartmentFk ) = 0 THEN SELECT "No perteneces a este departamento." AS problem; - -- ENVIAMOS CORREO AL BOSSFK + -- ENVIAMOS CORREO AL BOSSFK SELECT CONCAT(vUserName,' No a podido fichar por el siguiente problema: ',"No perteneces a este departamento.") INTO vBody; CALL mail_insert(vTo,vTo,'error al fichar',vBody); LEAVE proc; @@ -88779,386 +74102,175 @@ 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 `workerTimeControl_checkTest` */; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_checkBreak` */; /*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_checkTest`(vUserFk INT, vTimed DATETIME, vTabletFk VARCHAR(100)) +CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_checkBreak`(vStarted DATE) BEGIN - /** - * Verifica si el empleado puede fichar en el momento actual, si puede fichar llama a vn.workerTimeControlAdd - * @param vUserFk Identificador del trabajador - * @return Retorna si encuentra un problema 'odd','maxTimeWork','breakDay','breakWeek' ; - * En caso de tener algun problema retorna el primero que encuentra + * Retorna los trabajadores que no han respetado el descanso semanal de 36/72 horas + * El sistema verificará el descanso corto en la siguiente semana + * o el largo en las 2 siguientes semanas a partir de la fecha dada + * @param vStarted día inicio de la semana en el que se quiere verificar + * @return tmp.workerWithoutWeekBreak (workerFk) */ - DECLARE vLastIn DATETIME ; - DECLARE vLastOut DATETIME ; - DECLARE vDayWorkMax INT; - DECLARE vDayBreak INT; - DECLARE vWeekBreak INT ; - DECLARE vWeekMaxBreak INT; - DECLARE vWeekScope INT; - DECLARE vWeekMaxScope INT; - DECLARE vDayStayMax INT; - DECLARE vAskInOut INT; - DECLARE vTimedWorked INT; - DECLARE vCalendarStateType VARCHAR(20) DEFAULT NULL; - DECLARE vDepartmentFk INT; - DECLARE vTo VARCHAR(50) DEFAULT NULL; - DECLARE vUserName VARCHAR(50) DEFAULT NULL; - DECLARE vBody VARCHAR(255) DEFAULT NULL; + DECLARE vShortEnded DATETIME; + DECLARE vLongEnded DATETIME; + DECLARE vShortWeekBreak INT; + DECLARE vLongWeekBreak INT; - IF (vTimed IS NULL) THEN - SET vTimed = util.VN_NOW(); - END IF; + SELECT util.dayEnd(DATE_ADD(vStarted, INTERVAL shortWeekDays DAY)), + util.dayEnd(DATE_ADD(vStarted, INTERVAL longWeekDays DAY)), + shortWeekBreak, + longWeekBreak + INTO vShortEnded, vLongEnded, vShortWeekBreak, vLongWeekBreak + FROM workerTimeControlConfig; - SELECT dayBreak, weekBreak, weekScope, dayWorkMax, dayStayMax, weekMaxBreak, weekMaxScope, askInOut - INTO vDayBreak, vWeekBreak, vWeekScope, vDayWorkMax, vDayStayMax, vWeekMaxBreak, vWeekMaxScope, vAskInOut - FROM vn.workerTimeControlParams; - - SELECT MAX(timed) INTO vLastIn - FROM vn.workerTimeControl - WHERE userFk = vUserFk AND - direction = 'in'; - - SELECT MAX(timed) INTO vLastOut - FROM vn.workerTimeControl - WHERE userFk = vUserFk AND - direction = 'out'; - + SET @previousTimed:= UNIX_TIMESTAMP(vStarted); + SET @lastUserFk := NULL; - SELECT email INTO vTo - FROM account.user w - WHERE w.id = (SELECT bossFk FROM vn.worker WHERE id = vUserFk); - - SELECT CONCAT(firstName,' ',lastName) INTO vUserName - FROM vn.worker w - WHERE w.id = vUserFk; + -- Descanso corto en la semana - -- VERIFICAR CONTRATO EN VIGOR - IF (SELECT COUNT(*) - FROM postgresql.business b - JOIN postgresql.profile pr ON pr.profile_id = b.client_id - JOIN postgresql.person p ON p.person_id = pr.person_id - JOIN vn.worker w ON w.id = p.id_trabajador - WHERE w.userFk = vUserFk AND - b.date_start <= util.VN_CURDATE() AND - IFNULL(b.date_end,util.VN_CURDATE()) >= util.VN_CURDATE() - ) = 0 THEN - -- ENVIAMOS CORREO AL BOSSFK - SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"No hay un contrato en vigor") INTO vBody; - CALL vn.mail_insert(vTo,vTo,'error al fichar',vBody); - CALL util.throw("No hay un contrato en vigor"); - END IF; - - -- VERIFICAR DEPARTAMENTO - /*IF vTabletFk IS NOT NULL THEN - IF ( SELECT COUNT(*) - FROM vn.tabletDepartment td - JOIN vn.workerTimeControlUserInfo wtcu ON wtcu.departmentFk = td.departmentFk - WHERE td.tabletFk = vTabletFk AND wtcu.userFk = vUserFk - ) = 0 THEN - -- ENVIAMOS CORREO AL BOSSFK - SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"No perteneces a este departamento.") INTO vBody; - CALL vn.mail_insert(vTo,vTo,'error al fichar',vBody); - CALL util.throw("No perteneces a este departamento."); - END IF; - END IF;*/ - - SELECT IFNULL(dayBreak, vDayBreak) INTO vDayBreak - FROM postgresql.business b - JOIN postgresql.profile pr ON pr.profile_id = b.client_id - JOIN postgresql.person p ON p.person_id = pr.person_id - JOIN postgresql. business_labour bl ON b.business_id = bl.business_id - JOIN postgresql.professional_category pc ON bl.professional_category_id = pc.professional_category_id - WHERE p.id_trabajador = vUserFk AND - b.date_start <= DATE(vTimed) AND - IFNULL(b.date_end, DATE(vTimed)) >= DATE(vTimed); - -- VERIFICAR DESCANSO DIARIO - -- 12 / 9 horas dependiendo del valor de vDayBreak - IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastOut) < vDayBreak THEN - -- ENVIAMOS CORREO AL BOSSFK - SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos ", FORMAT(vDayBreak/3600,0) ," h") INTO vBody; - CALL vn.mail_insert(vTo,vTo,'error al fichar',vBody); - CALL util.throw(CONCAT("Descansos ", FORMAT(vDayBreak/3600,0) ," h")); - END IF; - - -- VERIFICAR FICHADAS IMPARES DEL ÚLTIMO DÍA QUE SE FICHÓ - IF (SELECT MOD(COUNT(*),2) -- <>0 - FROM vn.workerTimeControl - WHERE userFk = vUserFk AND - timed >= vLastIn - ) THEN - -- ENVIAMOS CORREO AL BOSSFK - SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Dias con fichadas impares") INTO vBody; - CALL vn.mail_insert(vTo,vTo,'error al fichar',vBody); - CALL util.throw("Dias con fichadas impares"); - END IF; - -- VERIFICAR VACACIONES - SELECT cs.type INTO vCalendarStateType - FROM postgresql.calendar_employee ce - JOIN postgresql.business b USING(business_id) - JOIN postgresql.profile pr ON pr.profile_id = b.client_id - JOIN postgresql.person p ON p.person_id = pr.person_id - JOIN postgresql.calendar_state cs USING(calendar_state_id) - JOIN vn.worker w ON w.id = p.id_trabajador - WHERE ce.date = util.VN_CURDATE() AND - cs.isAllowedToWork = FALSE AND - w.userFk = vUserFk - LIMIT 1; - - IF(LENGTH(vCalendarStateType)) THEN - -- ENVIAMOS CORREO AL BOSSFK - SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Vacaciones") INTO vBody; - CALL vn.mail_insert(vTo,vTo,'error al fichar',vBody); - CALL util.throw(vCalendarStateType); - END IF; - - -- VERIFICAR DESCANSO SEMANAL - SET @vHasBreakWeek:= FALSE; - SET @vLastTimed:= UNIX_TIMESTAMP((vTimed - INTERVAL vWeekScope SECOND)); - - DROP TEMPORARY TABLE IF EXISTS tmp.trash; - CREATE TEMPORARY TABLE tmp.trash - SELECT IF(vWeekBreak-(UNIX_TIMESTAMP(timed)-@vLastTimed) <= 0, @vHasBreakWeek:=TRUE, TRUE) alias, - @vLastTimed:= UNIX_TIMESTAMP(timed) + DROP TEMPORARY TABLE IF EXISTS tmp.worker; + CREATE TEMPORARY TABLE tmp.worker + (PRIMARY KEY(workerFk)) + ENGINE = MEMORY + SELECT DISTINCT userFk workerFk FROM workerTimeControl - WHERE timed>= (vTimed - INTERVAL vWeekScope SECOND) AND - userFk= vUserFk AND - direction IN ('in','out') - ORDER BY timed ASC; - - IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastOut) < vWeekBreak AND @vHasBreakWeek = FALSE THEN -- REVISA SI EL DESCANSO SE HA REALIZADO DESPUÉS DE LA ÚLTIMA FICHADA - SET @vHasBreakWeek:= FALSE; - SET @vLastTimed:= UNIX_TIMESTAMP((vTimed - INTERVAL vWeekMaxScope SECOND)); - DROP TEMPORARY TABLE tmp.trash; - CREATE TEMPORARY TABLE tmp.trash - SELECT IF(vWeekMaxBreak-(UNIX_TIMESTAMP(timed)-@vLastTimed) <= 0, @vHasBreakWeek:=TRUE, TRUE) alias, - @vLastTimed:= UNIX_TIMESTAMP(timed) - FROM workerTimeControl - WHERE timed>= (vTimed - INTERVAL vWeekMaxScope SECOND) AND - userFk= vUserFk AND - direction IN ('in','out') - ORDER BY timed ASC; - IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastOut) < vWeekMaxBreak AND @vHasBreakWeek = FALSE THEN -- REVISA SI EL DESCANSO SE HA REALIZADO DESPUÉS DE LA ÚLTIMA FICHADA - -- ENVIAMOS CORREO AL BOSSFK - SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos ", FORMAT(vWeekMaxBreak/3600,0) ," h") INTO vBody; - CALL vn.mail_insert(vTo,vTo,'error al fichar',vBody); - CALL util.throw(CONCAT( "Descansos ", FORMAT(vWeekMaxBreak/3600,0) ," h")); - END IF; - -- ENVIAMOS CORREO AL BOSSFK - SELECT CONCAT(vUserName,' No ha podido fichar por el siguiente problema: ',"Descansos ", FORMAT(vWeekBreak/3600,0) ," h") INTO vBody; - CALL vn.mail_insert(vTo,vTo,'error al fichar',vBody); - CALL util.warn(CONCAT( "Descansos ", FORMAT(vWeekBreak/3600,0) ," h")); - END IF; - DROP TEMPORARY TABLE tmp.trash; + WHERE timed BETWEEN vStarted AND vShortEnded + AND direction IN ('in', 'out'); + + DROP TEMPORARY TABLE IF EXISTS tmp.worker2; + CREATE TEMPORARY TABLE tmp.worker2 + (PRIMARY KEY(workerFk)) + ENGINE = MEMORY + SELECT workerFk + FROM tmp.worker; - -- Preguntar dirección de la fichada - IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastIn) >= vAskInOut AND (SELECT MOD(COUNT(*),2) - FROM vn.workerTimeControl WHERE userFk = vUserFk AND timed >= vLastIn) THEN - CALL util.warn("AskInOut"); - END IF ; + DROP TEMPORARY TABLE IF EXISTS tmp.workerWithoutShortWeekBreak; + CREATE TEMPORARY TABLE tmp.workerWithoutShortWeekBreak + SELECT sub2.userFk workerFk + FROM(SELECT sub.userFk, + IF(sub.userFk <> @lastUserFk, + @previousTimed:= sub.timed, + FALSE), + IF(sub.timed - @previousTimed >= vShortWeekBreak, + TRUE, + FALSE) hasShortWeekBreak, + @previousTimed:= sub.timed, + @lastUserFk:= sub.userFk + FROM ( + SELECT userFk, UNIX_TIMESTAMP(timed) timed + FROM workerTimeControl + WHERE timed BETWEEN vStarted AND vShortEnded + AND direction IN ('in', 'out') + UNION + SELECT w.workerFk, + UNIX_TIMESTAMP(IFNULL( + MIN(wtc.timed), + DATE_ADD(vShortEnded, INTERVAL vShortWeekBreak SECOND))) + FROM tmp.worker w + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND wtc.timed BETWEEN vShortEnded + AND DATE_ADD(vShortEnded, INTERVAL vShortWeekBreak SECOND) + GROUP BY w.workerFk + UNION + SELECT w.workerFk, + UNIX_TIMESTAMP(IFNULL( + MAX(wtc.timed), + DATE_SUB(vStarted, INTERVAL vShortWeekBreak SECOND))) + FROM tmp.worker2 w + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND wtc.timed BETWEEN + DATE_SUB(vStarted, INTERVAL vShortWeekBreak SECOND) + AND vStarted + GROUP BY w.workerFk + ORDER BY userFk, timed + LIMIT 10000000000000000000 + )sub + )sub2 + GROUP BY sub2.userFk + HAVING NOT SUM(hasShortWeekBreak); + + -- Descanso largo en las 2 siguientes semanas + DROP TEMPORARY TABLE tmp.worker; + CREATE TEMPORARY TABLE tmp.worker + (PRIMARY KEY(workerFk)) + ENGINE = MEMORY + SELECT workerFk + FROM tmp.workerWithoutShortWeekBreak; + + DROP TEMPORARY TABLE tmp.worker2; + CREATE TEMPORARY TABLE tmp.worker2 + (PRIMARY KEY(workerFk)) + ENGINE = MEMORY + SELECT workerFk + FROM tmp.workerWithoutShortWeekBreak; + + DROP TEMPORARY TABLE IF EXISTS tmp.workerWithoutWeekBreak; + CREATE TEMPORARY TABLE tmp.workerWithoutWeekBreak + (PRIMARY KEY(workerFk)) + ENGINE = MEMORY + SELECT sub2.userFk workerFk + FROM(SELECT userFk, + IF(userFk <> @lastUserFk, + @previousTimed:= timed, + TRUE), + IF(timed - @previousTimed >= vLongWeekBreak, + TRUE, + FALSE) hasLongWeekBreak, + @previousTimed:= timed, + @lastUserFk:= userFk + FROM (SELECT userFk, UNIX_TIMESTAMP(timed) timed + FROM workerTimeControl wtc + JOIN tmp.workerWithoutShortWeekBreak wws ON wws.workerFk = wtc.userFk + WHERE timed BETWEEN vStarted AND vLongEnded + AND direction IN ('in', 'out') + UNION + SELECT w.workerFk, + UNIX_TIMESTAMP(IFNULL(MIN(wtc.timed), + DATE_ADD(vLongEnded, INTERVAL vLongWeekBreak SECOND))) + FROM tmp.worker w + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND timed BETWEEN vLongEnded + AND DATE_ADD(vLongEnded, INTERVAL vLongWeekBreak SECOND) + GROUP BY w.workerFk + UNION + SELECT w.workerFk, + UNIX_TIMESTAMP(IFNULL(MAX(wtc.timed), + DATE_SUB(vStarted, INTERVAL vLongWeekBreak SECOND))) + FROM tmp.worker2 w + LEFT JOIN workerTimeControl wtc + ON wtc.userFk = w.workerFk + AND timed BETWEEN DATE_SUB(vStarted, INTERVAL vLongWeekBreak SECOND) + AND vStarted + GROUP BY w.workerFk + ORDER BY userFk, timed + LIMIT 10000000000000000000 + )sub + )sub2 + GROUP BY userFk + HAVING NOT SUM(hasLongWeekBreak); + + DROP TEMPORARY TABLE tmp.workerWithoutShortWeekBreak, tmp.worker, tmp.worker2; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_check__` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_check__`(vUserFk INT, vDated DATE,vTabletFk VARCHAR(100)) -proc: BEGIN -/** - * Verifica si el empleado puede fichar en el momento actual, si puede fichar llama a workerTimeControlAdd - * - * @param vUserFk Identificador del trabajador - * @return Retorna si encuentra un problema 'odd','maxTimeWork','breakDay','breakWeek' ; - * En caso de tener algun problema retorna el primero que encuentra - */ - DECLARE vLastIn DATETIME ; - DECLARE vLastOut DATETIME ; - DECLARE vDayWorkMax INT; - DECLARE vDayBreak INT; - DECLARE vWeekBreak INT ; - DECLARE vWeekScope INT; - DECLARE vDayStayMax INT; - DECLARE vProblem VARCHAR(20) DEFAULT NULL; - DECLARE vTimedWorked INT; - DECLARE vCalendarStateType VARCHAR(20) DEFAULT NULL; - DECLARE vDepartmentFk INT; - DECLARE vTo VARCHAR(50) DEFAULT NULL; - DECLARE vUserName VARCHAR(50) DEFAULT NULL; - DECLARE vBody VARCHAR(255) DEFAULT NULL; - - SELECT dayBreak, weekBreak, weekScope, dayWorkMax, dayStayMax - INTO vDayBreak, vWeekBreak, vWeekScope, vDayWorkMax, vDayStayMax - FROM workerTimeControlParams; - - SELECT MAX(timed) INTO vLastIn - FROM workerTimeControl - WHERE userFk = vUserFk - AND direction = 'in'; - - SELECT MAX(timed) INTO vLastOut - FROM workerTimeControl - WHERE userFk = vUserFk - AND direction = 'out'; - - SELECT CONCAT(u.name,'@verdnatura.es') INTO vTo - FROM account.user u - WHERE u.id = (SELECT bossFk FROM worker WHERE id = vUserFk); - - SELECT CONCAT(firstName,' ',lastName) INTO vUserName - FROM worker w - WHERE w.id = vUserFk; - - - IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastIn) > vDayStayMax THEN -- NUEVA JORNADA - - -- VERIFICAR DESCANSO DIARIO - IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vDayBreak THEN - SELECT "Descansos 12 h" AS problem; - -- ENVIAMOS CORREO AL BOSSFK - SELECT CONCAT(vUserName,' No a podido fichar por el siguiente problema: ',"Descansos 12 h") INTO vBody; - CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - END IF; - - -- VERIFICAR FICHADAS IMPARES DEL ÚLTIMO DÍA QUE SE FICHÓ - IF (SELECT MOD(COUNT(*),2) -- <>0 - FROM workerTimeControl - WHERE userFk = vUserFk - AND timed >= vLastIn - ) THEN - SELECT "Dias con fichadas impares" AS problem; - -- ENVIAMOS CORREO AL BOSSFK - SELECT CONCAT(vUserName,' No a podido fichar por el siguiente problema: ',"Dias con fichadas impares") INTO vBody; - CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - END IF; - - -- VERIFICAR VACACIONES - SELECT cs.type INTO vCalendarStateType - FROM postgresql.calendar_employee ce - JOIN postgresql.business b USING(business_id) - JOIN postgresql.profile pr ON pr.profile_id = b.client_id - JOIN postgresql.person p ON p.person_id = pr.person_id - JOIN postgresql.calendar_state cs USING(calendar_state_id) - JOIN worker w ON w.id = p.id_trabajador - WHERE ce.date = util.VN_CURDATE() - AND cs.isAllowedToWork = FALSE - AND w.userFk = vUserFk - LIMIT 1; - - IF(LENGTH(vCalendarStateType)) THEN - SELECT vCalendarStateType AS problem; - -- ENVIAMOS CORREO AL BOSSFK - SELECT CONCAT(vUserName,' No a podido fichar por el siguiente problema: ',"Vacaciones") INTO vBody; - CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - - END IF; - - - -- VERIFICAR CONTRATO EN VIGOR - IF (SELECT COUNT(*) - FROM postgresql.business b - JOIN postgresql.profile pr ON pr.profile_id = b.client_id - JOIN postgresql.person p ON p.person_id = pr.person_id - JOIN worker w ON w.id = p.id_trabajador - WHERE w.userFk = vUserFk - AND b.date_start <= vDated - AND IFNULL(b.date_end,vDated) >= vDated - ) = 0 THEN - SELECT "No hay un contrato en vigor" AS problem; - -- ENVIAMOS CORREO AL BOSSFK - SELECT CONCAT(vUserName,' No a podido fichar por el siguiente problema: ',"No hay un contrato en vigor") INTO vBody; - CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - - END IF; - - -- VERIFICAR DESCANSO SEMANAL - SET @vHasBreakWeek:= FALSE; - SET @vLastTimed:= UNIX_TIMESTAMP((util.VN_NOW() - INTERVAL vWeekScope SECOND)); - - DROP TEMPORARY TABLE IF EXISTS tmp.trash; - CREATE TEMPORARY TABLE tmp.trash - SELECT IF(vWeekBreak-(UNIX_TIMESTAMP(timed)-@vLastTimed) <= 0, @vHasBreakWeek:=TRUE, TRUE) alias, - @vLastTimed:= UNIX_TIMESTAMP(timed) - FROM workerTimeControl - WHERE timed>= (util.VN_NOW() - INTERVAL vWeekScope SECOND) - AND userFk= vUserFk - AND direction IN ('in','out') - ORDER BY timed ASC; - - IF UNIX_TIMESTAMP(util.VN_NOW()) - UNIX_TIMESTAMP(vLastOut) < vWeekBreak AND @vHasBreakWeek = FALSE THEN -- REVISA SI EL DESCANSO SE HA REALIZADO DESPUÉS DE LA ÚLTIMA FICHADA - SELECT "Descansos 36 h" AS problem; - -- ENVIAMOS CORREO AL BOSSFK - SELECT CONCAT(vUserName,' No a podido fichar por el siguiente problema: ',"Descansos 36 h") INTO vBody; - CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - END IF; - - DROP TEMPORARY TABLE tmp.trash; - - ELSE -- DIA ACTUAL - - -- VERIFICA QUE EL TIEMPO EFECTIVO NO SUPERE EL MÁXIMO - SELECT IFNULL(SUM(if( mod(wtc.order,2)=1, -UNIX_TIMESTAMP(timed), UNIX_TIMESTAMP(timed))),0) - IF( MOD(COUNT(*),2), UNIX_TIMESTAMP(util.VN_NOW()), 0) INTO vTimedWorked - FROM workerTimeControl wtc - WHERE userFk = vUserFk - AND timed >= vLastIn - ORDER BY timed; - - IF vTimedWorked > vDayWorkMax THEN - SELECT "Jornadas" AS problem; - -- ENVIAMOS CORREO AL BOSSFK - SELECT CONCAT(vUserName,' No a podido fichar por el siguiente problema: ',"Jornadas") INTO vBody; - CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - END IF; - - END IF; - - -- VERIFICAR DEPARTAMENTO - IF vTabletFk IS NOT NULL THEN - SELECT wtcu.departmentFk INTO vDepartmentFk - FROM workerTimeControlUserInfo wtcu - WHERE wtcu.userFk = vUserFk; - IF (SELECT COUNT(td.tabletFk) - FROM tabletDepartment td - WHERE td.tabletFk = vTabletFk AND td.departmentFk = vDepartmentFk - ) = 0 THEN - SELECT "No perteneces a este departamento." AS problem; - -- ENVIAMOS CORREO AL BOSSFK - SELECT CONCAT(vUserName,' No a podido fichar por el siguiente problema: ',"No perteneces a este departamento.") INTO vBody; - CALL mail_insert(vTo,vTo,'error al fichar',vBody); - LEAVE proc; - END IF; - END IF; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_clockIn` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -89166,324 +74278,344 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_clockIn`(vWorker INT, vTimed DATETIME, vDirection VARCHAR(10)) -BEGIN -/** - * Verifica si el empleado puede fichar - * @param vWorker Identificador del trabajador - * @param vTimed valor de la fichada, IF vTimed IS NULL vTimed = util.VN_NOW() - * @param vDirection solo se pueden pasa los valores del campo workerTimeControl.direction ENUM('in', 'out', 'middle') - * @return Si todo es correcto, retorna el número de id la tabla workerTimeControl. Si hay algún problema, devuelve el mesaje a que se debe mostrar al usuario - * Solo retorna el primer problema, en caso de no ocurrir ningún error se añadirá fichada a la tabla vn.workerTimeControl - */ - DECLARE vLastIn DATETIME; - DECLARE vLastOut DATETIME; - DECLARE vNextIn DATETIME; - DECLARE vLastDirection VARCHAR(6); - DECLARE vNextDirection VARCHAR(6); - DECLARE vDayBreak INT; - DECLARE vShortWeekBreak INT; - DECLARE vLongWeekBreak INT; - DECLARE vWeekScope INT; - DECLARE vGap INT; - DECLARE vMailTo VARCHAR(50) DEFAULT NULL; - DECLARE vUserName VARCHAR(50) DEFAULT NULL; - DECLARE vIsError BOOLEAN DEFAULT FALSE; - DECLARE vErrorMessage VARCHAR(255) DEFAULT NULL; - DECLARE vErrorCode VARCHAR(50); - DECLARE vDated DATE; - DECLARE vIsAllowedToWork VARCHAR(50); - DECLARE vDepartmentFk INT; - DECLARE vTimedLoop INT; - DECLARE vTimedLoopPrevious INT; - DECLARE vHasBreakWeek BOOLEAN DEFAULT FALSE; - DECLARE vManual BOOLEAN DEFAULT TRUE; - DECLARE vDone INT DEFAULT FALSE; - - DECLARE vCursor CURSOR FOR - SELECT UNIX_TIMESTAMP(util.VN_NOW() - INTERVAL vGap SECOND) - UNION - SELECT UNIX_TIMESTAMP(util.VN_NOW()) - UNION - (SELECT UNIX_TIMESTAMP(timed) - FROM workerTimeControl - WHERE timed BETWEEN (vTimed - INTERVAL vGap SECOND) AND vTimed AND - userFk = vWorker AND - direction IN ('in', 'out') - ORDER BY timed ASC); - - DECLARE vCursor2 CURSOR FOR - SELECT UNIX_TIMESTAMP(util.VN_NOW() - INTERVAL vGap SECOND) - UNION - SELECT UNIX_TIMESTAMP(util.VN_NOW()) - UNION - SELECT UNIX_TIMESTAMP(timed) - FROM workerTimeControl - WHERE timed BETWEEN vTimed AND (vTimed - INTERVAL vGap SECOND) AND - userFk = vWorker AND - direction IN ('in', 'out') - ORDER BY timed ASC; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - DECLARE EXIT HANDLER FOR SQLSTATE '45000' - BEGIN - - SELECT CONCAT(u.name, '@verdnatura.es'), CONCAT(w.firstName, ' ', w.lastName) - INTO vMailTo, vUserName - FROM account.user u - JOIN worker w ON w.bossFk = u.id - WHERE w.id = vWorker; - - CASE vErrorCode - WHEN 'IS_NOT_ALLOWED_FUTURE' THEN - SELECT 'No se permite fichar a futuro' INTO vErrorMessage; - WHEN 'INACTIVE_BUSINESS' THEN - SELECT 'No hay un contrato en vigor' INTO vErrorMessage; - WHEN 'IS_NOT_ALLOWED_WORK' THEN - SELECT 'No está permitido trabajar' INTO vErrorMessage; - WHEN 'ODD_WORKERTIMECONTROL' THEN - SELECT 'Fichadas impares' INTO vErrorMessage; - WHEN 'BREAK_DAY' THEN - SELECT CONCAT('Descanso diario ', FORMAT(vDayBreak/3600, 0) , 'h.') INTO vErrorMessage; - WHEN 'BREAK_WEEK' THEN - SELECT CONCAT('Descanso semanal ', - FORMAT(vShortWeekBreak / 3600,0) ,'h. / ', - FORMAT(vLongWeekBreak / 3600, 0) ,'h.') INTO vErrorMessage; - WHEN 'WRONG_DIRECTION' THEN - SELECT 'Dirección incorrecta' INTO vErrorMessage; - ELSE - SELECT 'Error sin definir'INTO vErrorMessage; - END CASE; - - SELECT vErrorMessage `error`; - SELECT CONCAT(vUserName, ' no ha podido fichar por el siguiente problema: ', vErrorMessage) INTO vErrorMessage; - CALL mail_insert( vMailTo, vMailTo, 'Error al fichar', vErrorMessage); - - END; - - IF (vTimed IS NULL) THEN - SET vTimed = util.VN_NOW(); - SET vManual = FALSE; - END IF; - - SET vDated = DATE(vTimed); - - SELECT IF(pc.category_name = 'Conductor +3500kg', wc.dayBreakDriver, wc.dayBreak), - wc.shortWeekBreak, - wc.longWeekBreak, - wc.weekScope - INTO vDayBreak, - vShortWeekBreak, - vLongWeekBreak, - vWeekScope - FROM workerLabour w - JOIN postgresql.business_labour bl ON bl.business_id = w.businessFk - JOIN postgresql.professional_category pc ON pc.professional_category_id = bl.professional_category_id - JOIN workerTimeControlConfig wc ON TRUE - WHERE w.workerFk = vWorker - AND vDated BETWEEN w.started AND IFNULL(w.ended, vDated); - - SELECT timed INTO vLastIn - FROM workerTimeControl - WHERE userFk = vWorker - AND direction = 'in' - AND timed < vTimed - ORDER BY timed DESC - LIMIT 1; - - SELECT timed INTO vLastOut - FROM workerTimeControl - WHERE userFk = vWorker - AND direction = 'out' - AND timed < vTimed - ORDER BY timed DESC - LIMIT 1; - - SELECT timed INTO vNextIn - FROM workerTimeControl - WHERE userFk = vWorker - AND direction = 'in' - AND timed > vTimed - ORDER BY timed ASC - LIMIT 1; - - SELECT direction INTO vNextDirection - FROM workerTimeControl - WHERE userFk = vWorker - AND timed > vTimed - ORDER BY timed ASC - LIMIT 1; - - SELECT direction INTO vLastDirection - FROM workerTimeControl - WHERE userFk = vWorker - AND timed < vTimed - ORDER BY timed DESC - LIMIT 1; - - -- FICHADAS A FUTURO - IF vTimed > DATE_ADD(util.VN_NOW(), INTERVAL 60 SECOND) THEN - SET vErrorCode = 'IS_NOT_ALLOWED_FUTURE'; - CALL util.throw(vErrorCode); - END IF; - - -- CONTRATO EN VIGOR - IF vDayBreak IS NULL THEN - SET vErrorCode = 'INACTIVE_BUSINESS'; - CALL util.throw(vErrorCode); - END IF; - - -- VERIFICAR SI ESTÁ PERMITIDO TRABAJAR - CALL timeBusiness_calculateByWorker(vWorker, vDated, vDated); - SELECT isAllowedToWork INTO vIsAllowedToWork - FROM tmp.timeBusinessCalculate; - DROP TEMPORARY TABLE tmp.timeBusinessCalculate; - - IF NOT vIsAllowedToWork THEN - SET vErrorCode = 'IS_NOT_ALLOWED_WORK'; - CALL util.throw(vErrorCode); - END IF; - - -- DIRECCION CORRECTA - CALL vn.workerTimeControl_direction(vWorker, vTimed); - IF (SELECT IF(IF(option1 IN ('inMiddle', 'outMiddle'), 'middle', option1) <> vDirection - AND IF(option2 IN ('inMiddle', 'outMiddle'), 'middle', IFNULL(option2, '')) <> vDirection, TRUE , FALSE) - FROM tmp.workerTimeControlDirection) THEN - SET vIsError = TRUE; - END IF; - - DROP TEMPORARY TABLE tmp.workerTimeControlDirection; - IF vIsError = TRUE THEN - SET vErrorCode = 'WRONG_DIRECTION'; - CALL util.throw(vErrorCode); - END IF; - - -- FICHADAS IMPARES - IF (SELECT IF(vDirection = 'in', MOD(COUNT(*), 2) , IF (vDirection = 'out', NOT MOD(COUNT(*), 2), FALSE)) - FROM workerTimeControl - WHERE userFk = vWorker - AND timed BETWEEN vLastIn AND vTimed - ) THEN - SET vErrorCode = 'ODD_WORKERTIMECONTROL'; - CALL util.throw(vErrorCode); - END IF; - - -- DESCANSO DIARIO - CASE vDirection - WHEN 'in' THEN - IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastOut) <= vDayBreak THEN - SET vIsError = TRUE; - END IF; - WHEN 'out' THEN - IF UNIX_TIMESTAMP(vNextIn) - UNIX_TIMESTAMP(vTimed) <= vDayBreak THEN - SET vIsError = TRUE; - END IF; - ELSE BEGIN END; - END CASE; - - IF vIsError THEN - SET vErrorCode = 'BREAK_DAY'; - CALL util.throw(vErrorCode); - END IF; - - -- VERIFICAR DESCANSO SEMANAL - IF (vDirection IN('in', 'out')) THEN - -- VERIFICA DESCANSO CORTO EN LA ÚLTIMA SEMANA - SET vGap = vWeekScope; - SET vTimedLoopPrevious = UNIX_TIMESTAMP((vTimed - INTERVAL vGap SECOND)); - SET vDone = FALSE; - OPEN vCursor; - l:LOOP - FETCH vCursor INTO vTimedLoop; - IF vDone THEN - LEAVE l; - END IF; - IF vShortWeekBreak - (vTimedLoop - vTimedLoopPrevious) < 0 THEN - SET vHasBreakWeek = TRUE; - LEAVE l; - END IF; - SET vTimedLoopPrevious = vTimedLoop; - END LOOP l; - CLOSE vCursor; - -- VERIFICA DESCANSO LARGO EN LA ÚLTIMAS 2 SEMANAS - IF NOT vHasBreakWeek THEN - SET vGap = vWeekScope * 2; - SET vTimedLoopPrevious = UNIX_TIMESTAMP((vTimed - INTERVAL vGap SECOND)); - SET vDone = FALSE; - OPEN vCursor; - l:LOOP - FETCH vCursor INTO vTimedLoop; - IF vDone THEN - LEAVE l; - END IF; - IF vLongWeekBreak - (vTimedLoop - vTimedLoopPrevious) < 0 THEN - SET vHasBreakWeek = TRUE; - LEAVE l; - END IF; - SET vTimedLoopPrevious = vTimedLoop; - END LOOP l; - CLOSE vCursor; - END IF; - - IF vManual THEN - -- VERIFICA DESCANSO CORTO EN LA PRÓXIMA SEMANA - SET vGap = vWeekScope; - SET vTimedLoopPrevious = vTimed; - SET vDone = FALSE; - OPEN vCursor; - l:LOOP - FETCH vCursor INTO vTimedLoop; - IF vDone THEN - LEAVE l; - END IF; - IF vShortWeekBreak - (vTimedLoop - vTimedLoopPrevious) < 0 THEN - SET vHasBreakWeek = TRUE; - LEAVE l; - END IF; - SET vTimedLoopPrevious = vTimedLoop; - END LOOP l; - CLOSE vCursor; - -- VERIFICA DESCANSO LARGO EN LAS PRÓXIMAS 2 SEMANAS - IF NOT vHasBreakWeek THEN - SET vGap = vWeekScope * 2; - SET vTimedLoopPrevious = vTimed; - SET vDone = FALSE; - OPEN vCursor; - l:LOOP - FETCH vCursor INTO vTimedLoop; - IF vDone THEN - LEAVE l; - END IF; - IF vShortWeekBreak - (vTimedLoop - vTimedLoopPrevious) < 0 THEN - SET vHasBreakWeek = TRUE; - LEAVE l; - END IF; - SET vTimedLoopPrevious = vTimedLoop; - END LOOP l; - CLOSE vCursor; - END IF; - END IF; - IF NOT vHasBreakWeek THEN - SET vErrorCode = 'BREAK_WEEK'; - CALL util.throw(vErrorCode); - END IF; - END IF; - - -- SE PERMITE FICHAR - INSERT INTO workerTimeControl(userFk, timed, direction, manual) - VALUES(vWorker, vTimed, vDirection, vManual); - - SELECT LAST_INSERT_ID() id; +CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_clockIn`( + vWorker INT, + vTimed DATETIME, + vDirection VARCHAR(10)) +BEGIN +/** + * Verifica si el empleado puede fichar + * @param vWorker Identificador del trabajador + * @param vTimed valor de la fichada, IF vTimed IS NULL vTimed = vn.VN_NOW() + * @param vDirection solo se pueden pasa los valores del campo + * workerTimeControl.direction ENUM('in', 'out', 'middle') + * @return Si todo es correcto, retorna el número de id la tabla workerTimeControl. + * Si hay algún problema, devuelve el mesaje a que se debe mostrar al usuario + * Solo retorna el primer problema, en caso de no ocurrir ningún error se añadirá + * fichada a la tabla vn.workerTimeControl + */ + DECLARE vLastIn DATETIME; + DECLARE vLastOut DATETIME; + DECLARE vNextIn DATETIME; + DECLARE vLastDirection VARCHAR(6); + DECLARE vNextDirection VARCHAR(6); + DECLARE vDayBreak INT; + DECLARE vShortWeekBreak INT; + DECLARE vLongWeekBreak INT; + DECLARE vWeekScope INT; + DECLARE vGap INT; + DECLARE vMailTo VARCHAR(50) DEFAULT NULL; + DECLARE vUserName VARCHAR(50) DEFAULT NULL; + DECLARE vIsError BOOLEAN DEFAULT FALSE; + DECLARE vErrorMessage VARCHAR(255) DEFAULT NULL; + DECLARE vErrorCode VARCHAR(50); + DECLARE vDated DATE; + DECLARE vIsAllowedToWork VARCHAR(50); + DECLARE vDepartmentFk INT; + DECLARE vTimedLoop BIGINT; + DECLARE vTimedLoopPrevious BIGINT; + DECLARE vHasBreakWeek BOOLEAN DEFAULT FALSE; + DECLARE vManual BOOLEAN DEFAULT TRUE; + DECLARE vDone INT DEFAULT FALSE; + + DECLARE vCursor CURSOR FOR + SELECT UNIX_TIMESTAMP(vTimed) timed + UNION + SELECT UNIX_TIMESTAMP(timed) + FROM workerTimeControl + WHERE timed BETWEEN (vTimed - INTERVAL vGap SECOND) AND vTimed + AND userFk = vWorker + AND direction IN ('in', 'out') + ORDER BY timed ASC; + + DECLARE vCursor2 CURSOR FOR + SELECT UNIX_TIMESTAMP(vTimed) timed + UNION + SELECT UNIX_TIMESTAMP(timed) + FROM workerTimeControl + WHERE timed BETWEEN vTimed AND (vTimed + INTERVAL vGap SECOND) + AND userFk = vWorker + AND direction IN ('in', 'out') + ORDER BY timed ASC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLSTATE '45000' + BEGIN + + SELECT CONCAT(u.name, '@verdnatura.es'), + CONCAT(w.firstName, ' ', w.lastName) + INTO vMailTo, vUserName + FROM account.user u + JOIN worker w ON w.bossFk = u.id + WHERE w.id = vWorker; + + CASE vErrorCode + WHEN 'IS_NOT_ALLOWED_FUTURE' THEN + SELECT 'No se permite fichar a futuro' INTO vErrorMessage; + WHEN 'INACTIVE_BUSINESS' THEN + SELECT 'No hay un contrato en vigor' INTO vErrorMessage; + WHEN 'IS_NOT_ALLOWED_WORK' THEN + SELECT 'No está permitido trabajar' INTO vErrorMessage; + WHEN 'ODD_WORKERTIMECONTROL' THEN + SELECT 'Fichadas impares' INTO vErrorMessage; + WHEN 'BREAK_DAY' THEN + SELECT CONCAT('Descanso diario ', FORMAT(vDayBreak/3600, 0), 'h.') + INTO vErrorMessage; + WHEN 'BREAK_WEEK' THEN + SELECT CONCAT('Descanso semanal ', + FORMAT(vShortWeekBreak / 3600,0) ,'h. / ', + FORMAT(vLongWeekBreak / 3600, 0) ,'h.') INTO vErrorMessage; + WHEN 'WRONG_DIRECTION' THEN + SELECT 'Dirección incorrecta' INTO vErrorMessage; + ELSE + SELECT 'Error sin definir'INTO vErrorMessage; + END CASE; + + SELECT vErrorMessage `error`; + SELECT CONCAT(vUserName, + ' no ha podido fichar por el siguiente problema: ', + vErrorMessage) + INTO vErrorMessage; + CALL mail_insert( vMailTo, vMailTo, 'Error al fichar', vErrorMessage); + + END; + + IF (vTimed IS NULL) THEN + SET vTimed = vn.VN_NOW(); + SET vManual = FALSE; + END IF; + + SET vDated = DATE(vTimed); + + SELECT IF(pc.category_name = 'Conductor +3500kg', + wc.dayBreakDriver, + wc.dayBreak), + wc.shortWeekBreak, + wc.longWeekBreak, + wc.weekScope + INTO vDayBreak, + vShortWeekBreak, + vLongWeekBreak, + vWeekScope + FROM workerLabour w + JOIN postgresql.business_labour bl ON bl.business_id = w.businessFk + JOIN postgresql.professional_category pc + ON pc.professional_category_id = bl.professional_category_id + JOIN workerTimeControlConfig wc ON TRUE + WHERE w.workerFk = vWorker + AND vDated BETWEEN w.started AND IFNULL(w.ended, vDated); + + SELECT timed INTO vLastIn + FROM workerTimeControl + WHERE userFk = vWorker + AND direction = 'in' + AND timed < vTimed + ORDER BY timed DESC + LIMIT 1; + + SELECT timed INTO vLastOut + FROM workerTimeControl + WHERE userFk = vWorker + AND direction = 'out' + AND timed < vTimed + ORDER BY timed DESC + LIMIT 1; + + SELECT timed INTO vNextIn + FROM workerTimeControl + WHERE userFk = vWorker + AND direction = 'in' + AND timed > vTimed + ORDER BY timed ASC + LIMIT 1; + + SELECT direction INTO vNextDirection + FROM workerTimeControl + WHERE userFk = vWorker + AND timed > vTimed + ORDER BY timed ASC + LIMIT 1; + + SELECT direction INTO vLastDirection + FROM workerTimeControl + WHERE userFk = vWorker + AND timed < vTimed + ORDER BY timed DESC + LIMIT 1; + + -- FICHADAS A FUTURO + IF vTimed > DATE_ADD(vn.VN_NOW(), INTERVAL 60 SECOND) THEN + SET vErrorCode = 'IS_NOT_ALLOWED_FUTURE'; + CALL util.throw(vErrorCode); + END IF; + + -- CONTRATO EN VIGOR + IF vDayBreak IS NULL THEN + SET vErrorCode = 'INACTIVE_BUSINESS'; + CALL util.throw(vErrorCode); + END IF; + + -- VERIFICAR SI ESTÁ PERMITIDO TRABAJAR + CALL timeBusiness_calculateByWorker(vWorker, vDated, vDated); + SELECT isAllowedToWork INTO vIsAllowedToWork + FROM tmp.timeBusinessCalculate; + DROP TEMPORARY TABLE tmp.timeBusinessCalculate; + + IF NOT vIsAllowedToWork THEN + SET vErrorCode = 'IS_NOT_ALLOWED_WORK'; + CALL util.throw(vErrorCode); + END IF; + + -- DIRECCION CORRECTA + CALL workerTimeControl_direction(vWorker, vTimed); + IF (SELECT + IF(IF(option1 IN ('inMiddle', 'outMiddle'), + 'middle', + option1) <> vDirection + AND IF(option2 IN ('inMiddle', 'outMiddle'), + 'middle', + IFNULL(option2, '')) <> vDirection, + TRUE , + FALSE) + FROM tmp.workerTimeControlDirection + ) THEN + SET vIsError = TRUE; + END IF; + + DROP TEMPORARY TABLE tmp.workerTimeControlDirection; + IF vIsError = TRUE THEN + SET vErrorCode = 'WRONG_DIRECTION'; + CALL util.throw(vErrorCode); + END IF; + + -- FICHADAS IMPARES + IF (SELECT IF(vDirection = 'in', + MOD(COUNT(*), 2) , + IF (vDirection = 'out', NOT MOD(COUNT(*), 2), FALSE)) + FROM workerTimeControl + WHERE userFk = vWorker + AND timed BETWEEN vLastIn AND vTimed + ) THEN + SET vErrorCode = 'ODD_WORKERTIMECONTROL'; + CALL util.throw(vErrorCode); + END IF; + + -- DESCANSO DIARIO + CASE vDirection + WHEN 'in' THEN + IF UNIX_TIMESTAMP(vTimed) - UNIX_TIMESTAMP(vLastOut) <= vDayBreak THEN + SET vIsError = TRUE; + END IF; + WHEN 'out' THEN + IF UNIX_TIMESTAMP(vNextIn) - UNIX_TIMESTAMP(vTimed) <= vDayBreak THEN + SET vIsError = TRUE; + END IF; + ELSE BEGIN END; + END CASE; + + IF vIsError THEN + SET vErrorCode = 'BREAK_DAY'; + CALL util.throw(vErrorCode); + END IF; + + -- VERIFICAR DESCANSO SEMANAL + IF (vDirection IN('in', 'out')) THEN + -- VERIFICA DESCANSO CORTO EN LA ÚLTIMA SEMANA + SET vGap = vWeekScope; + SET vTimedLoopPrevious = UNIX_TIMESTAMP((vTimed - INTERVAL vGap SECOND)); + SET vDone = FALSE; + OPEN vCursor; + l:LOOP + FETCH vCursor INTO vTimedLoop; + IF vDone THEN + LEAVE l; + END IF; + IF vShortWeekBreak - (vTimedLoop - vTimedLoopPrevious) <= 0 THEN + SET vHasBreakWeek = TRUE; + LEAVE l; + END IF; + SET vTimedLoopPrevious = vTimedLoop; + END LOOP l; + CLOSE vCursor; + -- VERIFICA DESCANSO LARGO EN LA ÚLTIMAS 2 SEMANAS + IF NOT vHasBreakWeek THEN + SET vGap = vWeekScope * 2; + SET vTimedLoopPrevious = UNIX_TIMESTAMP(vTimed - INTERVAL vGap SECOND); + SET vDone = FALSE; + OPEN vCursor; + l:LOOP + FETCH vCursor INTO vTimedLoop; + IF vDone THEN + LEAVE l; + END IF; + IF vLongWeekBreak - (vTimedLoop - vTimedLoopPrevious) <= 0 THEN + SET vHasBreakWeek = TRUE; + LEAVE l; + END IF; + SET vTimedLoopPrevious = vTimedLoop; + END LOOP l; + CLOSE vCursor; + END IF; + + IF vManual THEN + -- VERIFICA DESCANSO CORTO EN LA PRÓXIMA SEMANA + SET vGap = vWeekScope; + SET vTimedLoopPrevious = vTimed; + SET vDone = FALSE; + OPEN vCursor2; + l:LOOP + FETCH vCursor2 INTO vTimedLoop; + IF vDone THEN + LEAVE l; + END IF; + IF vShortWeekBreak - (vTimedLoop - vTimedLoopPrevious) <= 0 THEN + SET vHasBreakWeek = TRUE; + LEAVE l; + END IF; + SET vTimedLoopPrevious = vTimedLoop; + END LOOP l; + CLOSE vCursor2; + -- VERIFICA DESCANSO LARGO EN LAS PRÓXIMAS 2 SEMANAS + IF NOT vHasBreakWeek THEN + SET vGap = vWeekScope * 2; + SET vTimedLoopPrevious = vTimed; + SET vDone = FALSE; + OPEN vCursor2; + l:LOOP + FETCH vCursor2 INTO vTimedLoop; + IF vDone THEN + LEAVE l; + END IF; + IF vShortWeekBreak - (vTimedLoop - vTimedLoopPrevious) <= 0 THEN + SET vHasBreakWeek = TRUE; + LEAVE l; + END IF; + SET vTimedLoopPrevious = vTimedLoop; + END LOOP l; + CLOSE vCursor2; + END IF; + END IF; + IF NOT vHasBreakWeek THEN + SET vErrorCode = 'BREAK_WEEK'; + CALL util.throw(vErrorCode); + END IF; + END IF; + + -- SE PERMITE FICHAR + INSERT INTO workerTimeControl(userFk, timed, direction, manual) + VALUES(vWorker, vTimed, vDirection, vManual); + + SELECT LAST_INSERT_ID() id; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_direction` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -89491,8 +74623,6 @@ DELIMITER ; /*!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`@`localhost` PROCEDURE `workerTimeControl_direction`(vWorkerFk VARCHAR(10), vTimed DATETIME) BEGIN @@ -89506,7 +74636,7 @@ BEGIN DECLARE vIsMiddleOdd BOOLEAN ; IF (vTimed IS NULL) THEN - SET vTimed = util.VN_NOW(); + SET vTimed = vn.VN_NOW(); END IF; SELECT timed INTO vLastIn @@ -89521,7 +74651,7 @@ BEGIN FROM workerTimeControl WHERE userFk = vWorkerFk AND direction = 'middle' - AND timed BETWEEN vLastIn AND util.VN_NOW(); + AND timed BETWEEN vLastIn AND vn.VN_NOW(); DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlDirection; CREATE TEMPORARY TABLE tmp.workerTimeControlDirection @@ -89558,77 +74688,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 `workerTimeControl_direction__` */; -/*!50003 SET @saved_cs_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`@`localhost` PROCEDURE `workerTimeControl_direction__`(vWorkerFk VARCHAR(10), vTimed DATETIME) -BEGIN -/** - * Devuelve que direcciones de fichadas son lógicas a partir de la anterior fichada - * @param vWorkerFk Identificador del trabajador - * @return (option1, option2) - * Los valores posibles de retorno son ('in', 'inMiddle', 'outMiddle', 'out') - */ - DECLARE vLastIn DATETIME ; - DECLARE vIsMiddleOdd BOOLEAN ; - - IF (vTimed IS NULL) THEN - SET vTimed = util.VN_NOW(); - END IF; - - SELECT timed INTO vLastIn - FROM workerTimeControl - WHERE userFk = vWorkerFk - AND direction = 'in' - AND timed < vTimed - ORDER BY timed DESC - LIMIT 1; - - SELECT (COUNT(*)mod 2 = 1) INTO vIsMiddleOdd - FROM workerTimeControl - WHERE userFk = vWorkerFk - AND direction = 'middle' - AND timed BETWEEN vLastIn AND util.VN_NOW(); - - DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControlDirection; - - CREATE TEMPORARY TABLE tmp.workerTimeControlDirection - SELECT CASE WHEN w.direction ='in' THEN 'inMiddle' - WHEN w.direction = 'out' THEN 'in' - WHEN w.direction = 'middle' AND vIsMiddleOdd THEN 'outMiddle' - WHEN w.direction IS NULL THEN 'in' - ELSE 'inMiddle' - END option1, - CASE WHEN w.direction ='in' THEN 'out' - WHEN w.direction = 'out' THEN NULL - WHEN w.direction = 'middle' AND vIsMiddleOdd THEN NULL - WHEN w.direction IS NULL THEN NULL - ELSE 'out' - END option2 - FROM workerTimeControl w - WHERE w.timed <= vTimed - AND w.userFk = vWorkerFk - ORDER BY w.timed DESC - LIMIT 1; - - IF (SELECT IF(COUNT(*)=0, TRUE, FALSE) FROM tmp.workerTimeControlDirection ) THEN - INSERT INTO tmp.workerTimeControlDirection (option1, option2) - VALUES('in', NULL); - END IF; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_getClockIn` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -89636,102 +74697,90 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_getClockIn`(vUserFk INT, vDated DATE) +CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_getClockIn`( + vUserFk INT, + vDated DATE) BEGIN - /** * Muestra una tabla con los 7 días inmediatamente anteriores a la fecha proporcionada - * y las fichadas de cada dia, en columnas por día - * + * y las fichadas de cada día, en columnas por día + * @param vUserFk Identificador del trabajador + * @param vDated Fecha proporcionada */ - - CALL workerTimeControl_setOrder(vUserFk,TIMESTAMPADD(DAY,-8,vDated),vDated); - - DROP TEMPORARY TABLE IF EXISTS tmp.workerWeekTiming; - CREATE TEMPORARY TABLE tmp.workerWeekTiming - SELECT orden `orden`, - max(hace7dias) 7_dias_antes, - max(hace6dias) 6_dias_antes, - max(hace5dias) 5_dias_antes, - max(hace4dias) 4_dias_antes, - max(hace3dias) 3_dias_antes, - max(antesdeayer) 2_dias_antes, - max(ayer) 1_dia_antes, - max(hoy) mismo_dia - FROM - ( - SELECT IF(dias = 7, fichada, '') as hace7dias, - IF(dias = 6, fichada, '') as hace6dias, - IF(dias = 5, fichada, '') as hace5dias, - IF(dias = 4, fichada, '') as hace4dias, - IF(dias = 3, fichada, '') as hace3dias, - IF(dias = 2, fichada, '') as antesdeayer, - IF(dias = 1, fichada, '') as ayer, - IF(dias = 0, fichada, '') as hoy, - orden - - FROM - ( - SELECT `order` as orden, datediff(vDated, timed) as dias, date(timed) as fecha, TIME_FORMAT(timed,'%H:%i') as fichada - FROM vn.workerTimeControl wtc - WHERE userFk = vUserFk - AND timed >= TIMESTAMPADD(DAY, -7, vDated) - ) sub - )sub2 - GROUP BY orden; + CALL timeControl_calculateByWorker( + vUserFk, + DATE_SUB(vDated, INTERVAL 6 DAY), util.dayEnd(vDated)); - DROP TEMPORARY TABLE IF EXISTS tmp.workerWeekTiming_Aux; - CREATE TEMPORARY TABLE tmp.workerWeekTiming_Aux - SELECT * FROM tmp.workerWeekTiming; + SET @position := 0; + SET @lastDated := NULL; - INSERT INTO tmp.workerWeekTiming( 7_dias_antes, 6_dias_antes, 5_dias_antes, 4_dias_antes, 3_dias_antes, 2_dias_antes, 1_dia_antes, mismo_dia) - VALUES('total','','','','','','',''); - - INSERT INTO tmp.workerWeekTiming( orden, 7_dias_antes, 6_dias_antes, 5_dias_antes, 4_dias_antes, 3_dias_antes, 2_dias_antes, 1_dia_antes, mismo_dia) - SELECT 0, - IFNULL(DATE_FORMAT(SEC_TO_TIME(SUM(IF(orden MOD 2, - TIME_TO_SEC(7_dias_antes), TIME_TO_SEC(7_dias_antes)))),'%H:%i'),''), - IFNULL(DATE_FORMAT(SEC_TO_TIME(SUM(IF(orden MOD 2, - TIME_TO_SEC(6_dias_antes), TIME_TO_SEC(6_dias_antes)))),'%H:%i'),''), - IFNULL(DATE_FORMAT(SEC_TO_TIME(SUM(IF(orden MOD 2, - TIME_TO_SEC(5_dias_antes), TIME_TO_SEC(5_dias_antes)))),'%H:%i'),''), - IFNULL(DATE_FORMAT(SEC_TO_TIME(SUM(IF(orden MOD 2, - TIME_TO_SEC(4_dias_antes), TIME_TO_SEC(4_dias_antes)))),'%H:%i'),''), - IFNULL(DATE_FORMAT(SEC_TO_TIME(SUM(IF(orden MOD 2, - TIME_TO_SEC(3_dias_antes), TIME_TO_SEC(3_dias_antes)))),'%H:%i'),''), - IFNULL(DATE_FORMAT(SEC_TO_TIME(SUM(IF(orden MOD 2, - TIME_TO_SEC(2_dias_antes), TIME_TO_SEC(2_dias_antes)))),'%H:%i'),''), - IFNULL(DATE_FORMAT(SEC_TO_TIME(SUM(IF(orden MOD 2, - TIME_TO_SEC(1_dia_antes), TIME_TO_SEC(1_dia_antes)))),'%H:%i'),''), - '' - FROM tmp.workerWeekTiming_Aux; - - INSERT INTO tmp.workerWeekTiming_Aux( orden, 1_dia_antes) - SELECT 0, ROUND(( - IFNULL(TIME_TO_SEC(7_dias_antes),0) + - IFNULL(TIME_TO_SEC(6_dias_antes),0) + - IFNULL(TIME_TO_SEC(5_dias_antes),0) + - IFNULL(TIME_TO_SEC(4_dias_antes),0) + - IFNULL(TIME_TO_SEC(3_dias_antes),0) + - IFNULL(TIME_TO_SEC(2_dias_antes),0) + - IFNULL(TIME_TO_SEC(1_dia_antes),0) - ) / 3600,1) - FROM tmp.workerWeekTiming - WHERE orden = 0; - - - INSERT INTO tmp.workerWeekTiming( 7_dias_antes,6_dias_antes,5_dias_antes,4_dias_antes,3_dias_antes,2_dias_antes,1_dia_antes,mismo_dia) - SELECT '','','','','','',1_dia_antes,'' - FROM tmp.workerWeekTiming_Aux - WHERE orden = 0; - - SELECT 7_dias_antes, 6_dias_antes, 5_dias_antes, 4_dias_antes, 3_dias_antes, 2_dias_antes, 1_dia_antes, mismo_dia FROM tmp.workerWeekTiming; - - DROP TEMPORARY TABLE tmp.workerWeekTiming; - DROP TEMPORARY TABLE tmp.workerWeekTiming_Aux; + SELECT * + FROM( SELECT MAX(6daysAgo) 6daysAgo, + MAX(6daysAgoDirection) 6daysAgoDirection, + MAX(5daysAgo) 5daysAgo, + MAX(5daysAgoDirection) 5daysAgoDirection, + MAX(4daysAgo) 4daysAgo, + MAX(4daysAgoDirection) 4daysAgoDirection, + MAX(3daysAgo) 3daysAgo, + MAX(3daysAgoDirection) 3daysAgoDirection, + MAX(2daysAgo) 2daysAgo, + MAX(2daysAgoDirection) 2daysAgoDirection, + MAX(1daysAgo) 1daysAgo, + MAX(1daysAgoDirection) 1daysAgoDirection, + MAX(0daysAgo) 0daysAgo, + MAX(0daysAgoDirection) 0daysAgoDirection + FROM(SELECT IF(daysAgo = 6, timed, '') 6daysAgo, + IF(daysAgo = 5, timed, '') 5daysAgo, + IF(daysAgo = 4, timed, '') 4daysAgo, + IF(daysAgo = 3, timed, '') 3daysAgo, + IF(daysAgo = 2, timed, '') 2daysAgo, + IF(daysAgo = 1, timed, '') 1daysAgo, + IF(daysAgo = 0, timed, '') 0daysAgo, + IF(daysAgo = 6, direction, '') 6daysAgoDirection, + IF(daysAgo = 5, direction, '') 5daysAgoDirection, + IF(daysAgo = 4, direction, '') 4daysAgoDirection, + IF(daysAgo = 3, direction, '') 3daysAgoDirection, + IF(daysAgo = 2, direction, '') 2daysAgoDirection, + IF(daysAgo = 1, direction, '') 1daysAgoDirection, + IF(daysAgo = 0, direction, '') 0daysAgoDirection, + direction, + position + FROM(SELECT DATEDIFF(vDated, timed) daysAgo, + TIME_FORMAT(timed,'%H:%i') timed, + IF(DATE(timed) <> @lastDated, @position := 0, NULL), + @position := @position+1 position, + @lastDated := DATE(timed), + direction + FROM workerTimeControl wtc + WHERE wtc.userFk = vUserFk + AND wtc.timed >= TIMESTAMPADD(DAY, -6,vDated) + ORDER BY wtc.timed + LIMIT 10000000000000000000 + )sub + )sub2 + GROUP BY position) sub3 + JOIN (SELECT MAX(IF(daysAgo = 6, timeWorkSeconds, 0)) 6daysAgoTotal, + MAX(IF(daysAgo = 5, timeWorkSeconds, 0)) 5daysAgoTotal, + MAX(IF(daysAgo = 4, timeWorkSeconds, 0)) 4daysAgoTotal, + MAX(IF(daysAgo = 3, timeWorkSeconds, 0)) 3daysAgoTotal, + MAX(IF(daysAgo = 2, timeWorkSeconds, 0)) 2daysAgoTotal, + MAX(IF(daysAgo = 1, timeWorkSeconds, 0)) 1daysAgoTotal, + MAX(IF(daysAgo = 0, timeWorkSeconds, 0)) 0daysAgoTotal + FROM (SELECT DATEDIFF(vDated, dated) daysAgo, + timeWorkSeconds + FROM tmp.timeControlCalculate) sub4)sub5 ON TRUE; + + DROP TEMPORARY TABLE tmp.timeControlCalculate; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_login` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -89739,8 +74788,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_login`(vWorkerFk VARCHAR(10)) BEGIN @@ -89751,7 +74798,7 @@ BEGIN * @return (name, surname, userFk, departmentFk, button1, button2) * Los valores posibles para button son ('in', 'inMiddle', 'outMiddle', 'out') */ - CALL vn.workerTimeControl_direction(vWorkerFk, util.VN_NOW()); + CALL vn.workerTimeControl_direction(vWorkerFk, vn.VN_NOW()); SELECT wi.name, wi.surname, @@ -89771,6 +74818,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_remove` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -89778,8 +74827,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_remove`(IN vUserFk INT, IN vTimed DATETIME) BEGIN @@ -89833,6 +74880,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_repair` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -89840,8 +74889,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_repair`() proc: BEGIN @@ -89885,6 +74932,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_sendMail` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -89892,8 +74941,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_sendMail`(vWeek INT, vYear INT, vWorkerFk INT) BEGIN @@ -89929,7 +74976,8 @@ BEGIN DECLARE vPermissionRate DECIMAL(5,2); DECLARE vIsTeleworking BOOL; DECLARE vIsTeleworkingOld BOOL; - + DECLARE vError BOOL DEFAULT FALSE; + DECLARE vCursor CURSOR FOR SELECT CONCAT(u.name, '@verdnatura.es'), u.id, tb.dated, tb.timeWorkDecimal, LEFT(tb.timeWorkSexagesimal,5) timeWorkSexagesimal, tb.timeTable, tc.timeWorkDecimal timeWorkedDecimal, LEFT(tc.timeWorkSexagesimal,5) timeWorkedSexagesimal, tb.type, tb.businessFk,tb.permissionRate, d.isTeleworking @@ -89939,6 +74987,8 @@ BEGIN JOIN postgresql.business b ON b.business_id = tb.businessFk JOIN company c ON c.id = b.provider_id LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = tb.userFk AND tc.dated = tb.dated + LEFT JOIN worker w ON w.id = u.id + LEFT JOIN `user` u2 ON u2.id = w.bossFk JOIN (SELECT tb.userFk, SUM(IF(tb.type IS NULL, IF(tc.timeWorkDecimal > 0, FALSE, IF(tb.timeWorkDecimal > 0, TRUE, FALSE)), @@ -89955,12 +75005,23 @@ BEGIN DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + SET vError = TRUE; + + INSERT INTO tmp.error(workerFk) + SELECT vWorkerFk; + END; + DROP TABLE IF EXISTS tmp.timeControlCalculate; DROP TABLE IF EXISTS tmp.timeBusinessCalculate; DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate; DROP TEMPORARY TABLE IF EXISTS tmp.timeBusinessCalculate; DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate1; DROP TEMPORARY TABLE IF EXISTS tmp.timeBusinessCalculate1; + DROP TEMPORARY TABLE IF EXISTS tmp.error; + + CREATE TEMPORARY TABLE tmp.error (workerFk INT); SELECT CONCAT (MIN(dated), ' 00:00:00'), CONCAT (MAX(dated), ' 23:59:59') INTO vStarted, vEnded FROM time @@ -89973,7 +75034,7 @@ BEGIN isSendMail; UPDATE workerTimeControlMail - SET updated = util.VN_NOW(), state = 'SENDED' + SET updated = vn.VN_NOW(), state = 'SENDED' WHERE year = vYear AND week = vWeek AND IFNULL(vWorkerFk, workerFk) = workerFk ; @@ -90003,6 +75064,9 @@ proc: LOOP LEAVE proc; END IF; + START TRANSACTION; + SET vError = FALSE; + IF vTimeWorkDecimal>0 AND vTimeWorkedDecimal IS NULL AND IFNULL(vPermissionRate, TRUE) THEN IF vTimeTable IS NULL THEN INSERT INTO workerTimeControl (userFk, timed, manual, direction, isSendMail) @@ -90132,7 +75196,7 @@ proc: LOOP "); - IF vIsTeleworkingOld THEN + IF vIsTeleworkingOld AND NOT vError THEN CALL mail_insert( vReceiverOld, 'timecontrol@verdnatura.es', @@ -90142,6 +75206,8 @@ proc: LOOP INSERT IGNORE INTO workerTimeControlMail (workerFk, year, week) VALUES(vWorkerFkOld, vYear, vWeek); + ELSE + ROLLBACK; END IF; SET vBody = ''; @@ -90150,19 +75216,32 @@ proc: LOOP SET vIsTeleworkingOld = vIsTeleworking; SET vReceiverOld = vReceiver; END IF; + COMMIT; END LOOP; CLOSE vCursor; - + + INSERT INTO mail (receiver, replyTo, subject, body) + SELECT CONCAT(u.name, '@verdnatura.es'), + CONCAT('Error registro de horas semana ', vWeek, ' año ', vYear) , + CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', GROUP_CONCAT(DISTINCT CONCAT('
', w.id, ' ', w.firstName, ' ', w.lastName))) + FROM tmp.error e + JOIN worker w ON w.id = e.workerFk + JOIN user u ON u.id = w.bossFk + GROUP BY w.bossFk; + DROP TABLE tmp.timeControlCalculate; DROP TABLE tmp.timeBusinessCalculate; DROP TABLE tmp.timeControlCalculate1; DROP TABLE tmp.timeBusinessCalculate1; + DROP TABLE tmp.error; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_sendMailByDepartment` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -90170,8 +75249,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_sendMailByDepartment`(IN vDatedFrom DATETIME, IN vDatedTo DATETIME, IN vWorkerFk INT) BEGIN @@ -90304,6 +75381,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_sendMailByDepartmentLauncher` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -90311,15 +75390,13 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_sendMailByDepartmentLauncher`() BEGIN DECLARE vDatedFrom, vDatedTo DATETIME; - IF (DAYNAME(util.VN_CURDATE()) = 'miércoles') THEN - SELECT DATE_SUB(util.VN_CURDATE(), INTERVAL 9 DAY), CONCAT(DATE_SUB(util.VN_CURDATE(), INTERVAL 3 DAY), ' 23:59:59') INTO vDatedFrom, vDatedTo; + IF (DAYNAME(vn.VN_CURDATE()) = 'miércoles') THEN + SELECT DATE_SUB(vn.VN_CURDATE(), INTERVAL 9 DAY), CONCAT(DATE_SUB(vn.VN_CURDATE(), INTERVAL 3 DAY), ' 23:59:59') INTO vDatedFrom, vDatedTo; CALL vn.workerTimeControl_sendMailByDepartment(vDatedFrom, vDatedTo, NULL); END IF; @@ -90329,6 +75406,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_setOrder` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -90336,8 +75415,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_setOrder`(vUserFk INT, vStarted DATE, vFinished DATE) BEGIN @@ -90357,6 +75434,57 @@ 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `workerTimeControl_weekCheckBreak` */; +/*!50003 SET @saved_cs_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `workerTimeControl_weekCheckBreak`(vStarted DATE, vEnded DATE) +BEGIN +/** + * Retorna los trabajadores que no han respetado el descanso semanal de 36/72 horas + * El sistema verificará el descanso corto en la siguiente semana + * o el largo en las 2 siguientes semanas a partir de las fechas dadas + * @param vStarted día inicio para verificar + * @param vEnded día final para verificar + * @return tmp.workerWithoutWeekBreak (workerFk) + */ + DECLARE vDone INT DEFAULT FALSE; + + IF(vStarted > vEnded) then + CALL util.throw ('Date end can not be greater then start'); + END IF; + + DROP TEMPORARY TABLE IF EXISTS tmp.workerWithoutWeekBreakInWeek; + CREATE TEMPORARY TABLE tmp.workerWithoutWeekBreakInWeek + (workerFk INT, + PRIMARY KEY(workerFk)) + ENGINE = MEMORY; + + + WHILE vStarted <= vEnded DO + + CALL workerTimeControl_checkBreak(vStarted); + INSERT IGNORE INTO tmp.workerWithoutWeekBreakInWeek + SELECT workerFk + FROM tmp.workerWithoutWeekBreak; + DROP TEMPORARY TABLE IF EXISTS tmp.workerWithoutWeekBreak; + SET vStarted = DATE_ADD(vStarted, INTERVAL 1 DAY); + + 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerWeekControl` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -90364,183 +75492,151 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerWeekControl`(vUserFk INT, vDated DATE, vTabletFk VARCHAR(100)) BEGIN - -/* Devuelve la cantidad de descansos de 12h y de 36 horas que ha disfrutado el trabajador -* en la semana inmediatamente anterior a la fecha que pasa como parámetro. -* -* UPDATED PAK 2019/09/02 -* PENDING REVIEW +/* +* Devuelve la cantidad de descansos de 12h y de 36 horas que ha disfrutado el trabajador +* en la semana inmediatamente anterior a la fecha que pasa como parámetro. +* UPDATED PAK 2019/09/02 +* PENDING REVIEW */ + DECLARE vDescansos12h INT; + DECLARE vDescansos36h INT; + DECLARE vJornadas INT; + DECLARE vImpares INT; + DECLARE vHasSignedToday BOOLEAN; + DECLARE v12hoursInMinutes INT DEFAULT 719; + DECLARE v36hoursInMinutes INT DEFAULT 2159; + DECLARE vCantWork VARCHAR(50) DEFAULT ''; + DECLARE vDepartmentFk INT; + DECLARE isEnabled BOOLEAN DEFAULT TRUE; -DECLARE vDescansos12h INT; -DECLARE vDescansos36h INT; -DECLARE vJornadas INT; -DECLARE vImpares INT; -DECLARE vHasSignedToday BOOLEAN; -DECLARE v12hoursInMinutes INT DEFAULT 719; -DECLARE v36hoursInMinutes INT DEFAULT 2159; -DECLARE vCantWork VARCHAR(50) DEFAULT ''; -DECLARE vDepartmentFk INT; -DECLARE isEnabled BOOLEAN DEFAULT TRUE; + SELECT COUNT(*) INTO vHasSignedToday + FROM vn.workerTimeControl WHERE timed >= vDated AND userFk = vUserFk; + SET @day := 0; + SET @lastTimed := vn.VN_NOW(); -SELECT COUNT(*) INTO vHasSignedToday - FROM vn.workerTimeControl WHERE timed >= vDated AND userFk = vUserFk; - -SET @day := 0; -SET @lastTimed := util.VN_NOW(); - -SELECT SUM(IF(interval_in_minutes >= v12hoursInMinutes,1,0)), SUM(FLOOR(interval_in_minutes/ v36hoursInMinutes)) , SUM(jornadas) - INTO vDescansos12h, vDescansos36h, vJornadas - FROM - ( - SELECT fichada_anterior, fichada_actual, interval_in_minutes, jornadas - FROM - ( - SELECT @lastTimed fichada_anterior, - timed, - CAST(time_to_sec(timediff(timed,@lastTimed )) / 60 AS UNSIGNED) as interval_in_minutes, - IF(day(timed) != @day, 1, 0) as jornadas, - @day := day(timed) dia_del_mes, - @lastTimed := timed fichada_actual - FROM - ( - SELECT day(timed) as dayNumber, dayname(timed) as dayName, timed - FROM - (SELECT TIMESTAMPADD(DAY, -11, util.VN_NOW()) as timed, vUserFk as userFk -- Fichada virtual para los en los que no se ha trabajado la semana anterior - UNION ALL - SELECT timed, userFk - FROM vn.workerTimeControl wtc - WHERE userFk = vUserFk - AND timed >= TIMESTAMPADD(DAY, -10,vDated) - UNION ALL - SELECT IF(vHasSignedToday, '2000-01-01 00:00', util.VN_NOW()) as timed, vUserFk - ) sub4 - ORDER BY timed - ) sub - - ) sub2 - WHERE fichada_actual >= TIMESTAMPADD(WEEK, -1, vDated) - ) sub3 ; - -SELECT IFNULL(SUM(impar),0) into vImpares -FROM ( - SELECT day(timed) as dayNumber, - count(*) mod 2 as impar - FROM vn.workerTimeControl wtc - WHERE userFk = vUserFk - AND timed >= TIMESTAMPADD(WEEK, -1,vDated) AND timed < vDated - GROUP BY dayNumber - ) sub; - --- Vacaciones -SELECT cs.type INTO vCantWork - FROM postgresql.calendar_employee ce - JOIN postgresql.business b USING(business_id) - JOIN postgresql.profile pr ON pr.profile_id = b.client_id - JOIN postgresql.person p ON p.person_id = pr.person_id - JOIN postgresql.calendar_state cs USING(calendar_state_id) - JOIN vn.worker w ON w.id = p.id_trabajador - WHERE ce.date = util.VN_CURDATE() - AND cs.isAllowedToWork = FALSE - AND w.userFk = vUserFk - LIMIT 1; - --- Contrato en vigor -SELECT IF(COUNT(*),vCantWork,'Sin contrato') INTO vCantWork - FROM postgresql.business b - JOIN postgresql.profile pr ON pr.profile_id = b.client_id - JOIN postgresql.person p ON p.person_id = pr.person_id - JOIN vn.worker w ON w.id = p.id_trabajador - WHERE w.userFk = vUserFk - AND b.date_start <= vDated - AND IFNULL(b.date_end,vDated) >= vDated; - --- Departamento si vTabletFk es 0 no hacemos comprobacion (Madrid y Vilassar) -IF vTabletFk <> '0' THEN --- 1 Obtener el departamento del usuario - SELECT wtcu.departmentFk INTO vDepartmentFk - FROM vn.workerTimeControlUserInfo wtcu - WHERE wtcu.userFk = vUserFk; --- 2 Comprobar si la tablet pertenece al departamento - SELECT COUNT(td.tabletFk) INTO isEnabled - FROM vn.tabletDepartment td - WHERE td.tabletFk = vTabletFk AND td.departmentFk = vDepartmentFk; - -END IF; - - - -IF vJornadas IS NOT NULL THEN - - SELECT 'Jornadas' as Item, vJornadas as Cantidad, 'Correcto' AS Análisis - - UNION ALL - - SELECT 'Descansos 12 h' as Item, vDescansos12h as Cantidad, IF(vDescansos12h >= vJornadas, 'Correcto','Error: 1 por jornada') as Análisis - - UNION ALL - - SELECT 'Descansos 36 h' as Item, vDescansos36h as Cantidad, IF(vDescansos36h / 2 >= FLOOR(vJornadas/10), 'Correcto','Error: mínimo 2 cada 14 dias') as Análisis - - UNION ALL - - SELECT 'Dias con fichadas impares' as Item, vImpares as Cantidad, IF(vImpares = 0, 'Correcto','Error') as Análisis - - UNION ALL - - SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, - '' as Cantidad, - IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis + SELECT SUM(IF(interval_in_minutes >= v12hoursInMinutes,1,0)), SUM(FLOOR(interval_in_minutes/ v36hoursInMinutes)) , SUM(jornadas) + INTO vDescansos12h, vDescansos36h, vJornadas + FROM + ( + SELECT fichada_anterior, fichada_actual, interval_in_minutes, jornadas + FROM + ( + SELECT @lastTimed fichada_anterior, + timed, + CAST(time_to_sec(timediff(timed,@lastTimed )) / 60 AS UNSIGNED) as interval_in_minutes, + IF(day(timed) != @day, 1, 0) as jornadas, + @day := day(timed) dia_del_mes, + @lastTimed := timed fichada_actual + FROM + ( + SELECT day(timed) as dayNumber, dayname(timed) as dayName, timed + FROM + (SELECT TIMESTAMPADD(DAY, -11, vn.VN_NOW()) as timed, vUserFk as userFk -- Fichada virtual para los en los que no se ha trabajado la semana anterior + UNION ALL + SELECT timed, userFk + FROM vn.workerTimeControl wtc + WHERE userFk = vUserFk + AND timed >= TIMESTAMPADD(DAY, -10,vDated) + UNION ALL + SELECT IF(vHasSignedToday, '2000-01-01 00:00', vn.VN_NOW()) as timed, vUserFk + ) sub4 + ORDER BY timed + ) sub - UNION ALL + ) sub2 + WHERE fichada_actual >= TIMESTAMPADD(WEEK, -1, vDated) + ) sub3 ; - SELECT 'El fichador no pertenece a tu departamento.' as Item, '' as Cantidad, IF(isEnabled, 'Correcto','Error') as Análisis - - ; + SELECT IFNULL(SUM(impar),0) into vImpares + FROM ( + SELECT day(timed) as dayNumber, + count(*) mod 2 as impar + FROM vn.workerTimeControl wtc + WHERE userFk = vUserFk + AND timed >= TIMESTAMPADD(WEEK, -1,vDated) AND timed < vDated + GROUP BY dayNumber + ) sub; -ELSE - - - SELECT 'Jornadas' as Item, vJornadas as Cantidad, 'Correcto' AS Análisis - - UNION ALL - - SELECT 'Descansos 12 h' as Item, vDescansos12h as Cantidad, 'Correcto' as Análisis - - UNION ALL - - SELECT 'Descansos 36 h' as Item, vDescansos36h as Cantidad, 'Correcto' as Análisis - - UNION ALL - - SELECT 'Dias con fichadas impares' as Item, vImpares as Cantidad, 'Correcto' as Análisis + -- Vacaciones + SELECT at2.name INTO vCantWork + FROM postgresql.calendar_employee ce + JOIN postgresql.business b USING(business_id) + JOIN postgresql.profile pr ON pr.profile_id = b.client_id + JOIN postgresql.person p ON p.person_id = pr.person_id + JOIN vn.absenceType at2 ON at2.id = ce.calendar_state_id + JOIN vn.worker w ON w.id = p.id_trabajador + WHERE ce.date = vn.VN_CURDATE() + AND at2.isAllowedToWork = FALSE + AND w.userFk = vUserFk + LIMIT 1; - UNION ALL - - SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, - '' as Cantidad, IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis - - UNION ALL - - SELECT 'El fichador no pertenece a tu departamento.' as Item, '' as Cantidad, IF(isEnabled, 'Correcto','Error') as Análisis - ; - -END IF; + -- Contrato en vigor + SELECT IF(COUNT(*),vCantWork,'Sin contrato') INTO vCantWork + FROM postgresql.business b + JOIN postgresql.profile pr ON pr.profile_id = b.client_id + JOIN postgresql.person p ON p.person_id = pr.person_id + JOIN vn.worker w ON w.id = p.id_trabajador + WHERE w.userFk = vUserFk + AND b.date_start <= vDated + AND IFNULL(b.date_end,vDated) >= vDated; + + -- Departamento si vTabletFk es 0 no hacemos comprobacion (Madrid y Vilassar) + IF vTabletFk <> '0' THEN + -- 1 Obtener el departamento del usuario + SELECT wtcu.departmentFk INTO vDepartmentFk + FROM vn.workerTimeControlUserInfo wtcu + WHERE wtcu.userFk = vUserFk; + -- 2 Comprobar si la tablet pertenece al departamento + SELECT COUNT(td.tabletFk) INTO isEnabled + FROM vn.tabletDepartment td + WHERE td.tabletFk = vTabletFk AND td.departmentFk = vDepartmentFk; + + END IF; + + IF vJornadas IS NOT NULL THEN + + SELECT 'Jornadas' as Item, vJornadas as Cantidad, 'Correcto' AS Análisis + UNION ALL + SELECT 'Descansos 12 h' as Item, vDescansos12h as Cantidad, IF(vDescansos12h >= vJornadas, 'Correcto','Error: 1 por jornada') as Análisis + UNION ALL + SELECT 'Descansos 36 h' as Item, vDescansos36h as Cantidad, IF(vDescansos36h / 2 >= FLOOR(vJornadas/10), 'Correcto','Error: mínimo 2 cada 14 dias') as Análisis + UNION ALL + SELECT 'Dias con fichadas impares' as Item, vImpares as Cantidad, IF(vImpares = 0, 'Correcto','Error') as Análisis + UNION ALL + SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, + '' as Cantidad, + IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis + UNION ALL + SELECT 'El fichador no pertenece a tu departamento.' as Item, '' as Cantidad, IF(isEnabled, 'Correcto','Error') as Análisis; + ELSE + SELECT 'Jornadas' as Item, vJornadas as Cantidad, 'Correcto' AS Análisis + UNION ALL + SELECT 'Descansos 12 h' as Item, vDescansos12h as Cantidad, 'Correcto' as Análisis + UNION ALL + SELECT 'Descansos 36 h' as Item, vDescansos36h as Cantidad, 'Correcto' as Análisis + UNION ALL + SELECT 'Dias con fichadas impares' as Item, vImpares as Cantidad, 'Correcto' as Análisis + UNION ALL + SELECT IF (LENGTH(vCantWork),CONCAT('Dia no laborable: ', vCantWork),'Dia laborable') as Item, + '' as Cantidad, IF(LENGTH(vCantWork),'Error', 'Correcto') as Análisis + UNION ALL + SELECT 'El fichador no pertenece a tu departamento.' as Item, '' as Cantidad, IF(isEnabled, 'Correcto','Error') as Análisis; + 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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workerWeekTiming` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -90548,8 +75644,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workerWeekTiming`(vUserFk INT, vDated DATE) BEGIN @@ -90645,6 +75739,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `worker_calculateCommission` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -90652,8 +75748,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_calculateCommission`(vYear INT, vQuarter INT) BEGIN @@ -90784,141 +75878,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_calculateCommission__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_calculateCommission__`(vYear INT, vQuarter INT) -BEGIN - - DECLARE vQuarterFirstDayLastYear DATE; - DECLARE vQuarterFirstDay DATE; -/* - -- Jerarquia - DROP TEMPORARY TABLE IF EXISTS rankingHierarchy; - CREATE TEMPORARY TABLE rankingHierarchy - SELECT COUNT(*) - 1 teamMembers, wb.bossFk - FROM vn.worker ww - JOIN vn.worker wb ON ww.id = wb.bossFk - GROUP BY wb.bossFk; - */ - - -- Ranking ventas - SELECT MIN(dated) INTO vQuarterFirstDay - FROM `time` t - WHERE QUARTER(dated) = vQuarter AND t.`year` = vYear; - - SET vQuarterFirstDayLastYear = DATE_ADD(vQuarterFirstDay, INTERVAL -1 YEAR); - - SET @position:= 0; - DROP TEMPORARY TABLE IF EXISTS rankingSelling; - CREATE TEMPORARY TABLE rankingSelling - (PRIMARY KEY(userFk)) ENGINE = MEMORY - SELECT userFk, @position:= @position + 1 position - FROM ( - SELECT SUM(`v`.`importe`) AS `importe`, - `u`.`name` AS `name`, - `u`.`id` AS `userFk` - FROM - (`bs`.`vendedores` `v` - JOIN `account`.`user` `u` ON (`u`.`id` = `v`.`Id_Trabajador`)) - WHERE - `v`.`año` = vYear - AND CEIL(`v`.`mes` / 3) = vQuarter - AND `u`.`name` NOT IN ('ismaelalcolea' , 'ruben') - GROUP BY `v`.`Id_Trabajador` - ORDER BY SUM(`v`.`importe`) DESC - LIMIT 10 - ) t; - - CALL rankingTeamByQuarter(vYear, vQuarter); - - -- comerciales que computan / total integrantes - DROP TEMPORARY TABLE IF EXISTS teamNames; - CREATE TEMPORARY TABLE teamNames - (PRIMARY KEY(departmentFk)) ENGINE = MEMORY - SELECT DISTINCT departmentFk, teamPeople - FROM tmp.rankingTeam; - - -- Ranking por equipos - DROP TEMPORARY TABLE IF EXISTS rankingTeam; - CREATE TEMPORARY TABLE rankingTeam - (PRIMARY KEY(departmentFk)) ENGINE = MEMORY - SELECT DISTINCT departmentFk - FROM teamNames - LIMIT 3; - - -- Ranking por nuevos clientes - SET @position:= 0; - DROP TEMPORARY TABLE IF EXISTS rankingNewBorn; - CREATE TEMPORARY TABLE rankingNewBorn - (PRIMARY KEY(userFk)) ENGINE = MEMORY - SELECT userFk, @position:= @position + 1 position - FROM ( - SELECT SUM(amount) AS total, - n.userFk - FROM newBornSales n - WHERE n.dated >= vQuarterFirstDay - AND n.firstShipped >= vQuarterFirstDayLastYear - GROUP BY userFk - ORDER BY SUM(amount) DESC - LIMIT 10 - ) t; - - -- Ventas - DROP TEMPORARY TABLE IF EXISTS rankingSale; - CREATE TEMPORARY TABLE rankingSale - (PRIMARY KEY(workerFk)) ENGINE = MEMORY - SELECT IF(SUM(v.importe) > 120000, - SUM(IFNULL(v.comision,0)),0) as commission, - SUM(v.importe) sales, - v.Id_Trabajador workerFk - FROM bs.vendedores v - WHERE v.año = vYear AND CEIL(mes/3) = vQuarter - GROUP BY v.Id_Trabajador; - - -- Sumatorio de ventas - SELECT uBoss.`name` as team, - u.`name`, - r.commission, - -- IF(rh.bossFk, 200 + (teamMembers * 30), 0) plusResponsibility, - @plusRankingSellers := (11 - rs.position) * 40 plusRankingSellers, - @plusRankingTeam := IF(rt.departmentFk, 800, 0) plusRankingTeam, - @plusRankingNewBorn := (11 - rnb.position) * 40 plusRankingNewBorn, - IFNULL(r.commission,0) + IFNULL(@plusRankingSellers,0) + @plusRankingTeam + IFNULL(@plusRankingNewBorn, 0) total, - sales, rs.position, teamPeople, - vYear year, - vQuarter quarter - FROM rankingSale r - -- LEFT JOIN rankingHierarchy rh ON rh.bossFk = r.workerFk - JOIN account.user u ON u.id = r.workerFk - JOIN vn2008.jerarquia j ON j.worker_id = r.workerFk - LEFT JOIN `account`.`user` uBoss ON uBoss.id = j.boss_id - LEFT JOIN rankingSelling rs ON rs.userFk = r.workerFk - LEFT JOIN workerDepartment wd ON wd.workerFk = r.workerFk - LEFT JOIN rankingTeam rt ON rt.departmentFk = wd.departmentFk AND r.commission - LEFT JOIN teamNames tn ON tn.departmentFk = wd.departmentFk - LEFT JOIN vn.rankingNewBorn rnb ON rnb.userFk = r.workerFk; - - DROP TEMPORARY TABLE tmp.rankingTeam; - DROP TEMPORARY TABLE - rankingSelling, - rankingTeam, - teamNames, - rankingNewBorn, - rankingSale; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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 */ ; @@ -90926,8 +75887,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_calculateSalaryRoleDelivery`(vWorkerFk INTEGER,vDateFrom DATE,vDateTo DATE) BEGIN @@ -91066,7 +76025,7 @@ BEGIN 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, util.VN_CURDATE()) AND wl.workerFk = wdc.workerFk AND a.workCenterFk = wl.workCenterFk + JOIN workerLabour wl ON r.created BETWEEN wl.started AND IFNULL(wl.ended, vn.VN_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 @@ -91093,7 +76052,7 @@ BEGIN ORDER BY dated DESC LIMIT 1 ) sub JOIN routeConfig rc - JOIN workerLabour wl ON r.created BETWEEN wl.started AND IFNULL(wl.ended, util.VN_CURDATE()) AND + JOIN workerLabour wl ON r.created BETWEEN wl.started AND IFNULL(wl.ended, vn.VN_CURDATE()) AND wl.workerFk = sub.workerFk JOIN department v ON v.id = departmentFk WHERE r.m3>0 AND @@ -91177,254 +76136,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_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_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` 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, - w.code, - CAST('' AS CHAR(45)) description, - CAST( 0 AS DECIMAL(10,2)) extra - 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 - SELECT w.id workerFk, - r.created dated, - r.id, - SUM(t.packages) packages, - NULL hours, - r.kmEnd-r.kmStart km, - NULL m3Delivery, - CAST(r.m3/loadWorker AS DECIMAL(10,2)) m3Load, - NULL 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, - NULL amountKm, - w.code, - NULL description, - NULL extra - 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 - SELECT workerFk, - dated, - NULL id, - NULL packages, - NULL hours, - NULL km, - NULL m3Delivery, - NULL m3Load, - NULL amountDelivery, - NULL amountLoad, - NULL amountKm, - NULL workerCode, - GROUP_CONCAT(ra.name) description, - CAST(SUM(rc.price) AS DECIMAL(9,2)) extra - 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 - SELECT w.id workerFk, - tb.dated, - NULL id, - NULL packages, - NULL hours, - NULL km, - NULL m3Delivery, - NULL m3Load, - NULL amountDelivery, - NULL amountLoad, - NULL amountKm, - NULL workerCode, - tb.type COLLATE utf8_general_ci description, - 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)) - END extra - 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') - GROUP BY tb.dated; - - INSERT INTO tmp.workerSalaryRoleDelivery - SELECT sub.workerFk workerFk, - r.created dated, - NULL id, - NULL packages, - NULL hours, - NULL km, - SUM(r.m3) m3Delivery, - NULL m3Load, - NULL amountDelivery, - CAST( (SUM(r.m3)*sub.percentage /100) * rc.m3Management AS DECIMAL (10,2) ) amountLoad, - NULL amountKm, - NULL workerCode, - 'Gestión de la distribución' description, - NULL extra - 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 workerLabour wl ON r.created BETWEEN wl.started AND IFNULL(wl.ended, util.VN_CURDATE()) AND wl.workerFk = sub.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 - SELECT sub.workerFk workerFk, - r.created dated, - NULL id, - NULL packages, - NULL hours, - NULL km, - SUM(r.m3) m3Delivery, - NULL m3Load, - NULL amountDelivery, - CAST( (SUM(r.m3)*sub.percentage /100) * rc.m3Palletization AS DECIMAL (10,2) ) amountLoad, - NULL amountKm, - NULL workerCode, - 'Gestión de paletizado' description, - NULL extra - 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, util.VN_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,code,description, extra) - SELECT workerFk, - dated, - d.id, - packages, - hours, - km, - m3Delivery, - m3Load, - amountDelivery * r.rateHoliday, - amountLoad * r.rateHoliday, - AmountKm * r.rateHoliday, - code, - 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'); - - DELETE d - FROM tmp.workerSalaryRoleDelivery d - JOIN tmp.daysToDelete dd on dd.dated = d.dated - WHERE d.description NOT IN ('Baja enfermedad común'); - - 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_getFromHasMistake` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -91432,31 +76145,31 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_getFromHasMistake`(vDepartmentFk INT) -BEGIN - -/** - * Obtiene los trabajadores de los departamentos que se les puede poner error - * @param vDepartmentFk id del departamento - * - */ - - SELECT w.id,w.firstName, w.lastName,d.name - FROM worker w - JOIN workerDepartment wd ON wd.workerFk = w.id - JOIN department d ON d.id = wd.departmentFk - WHERE d.id = vDepartmentFk - ORDER BY firstName; - +BEGIN + +/** + * Obtiene los trabajadores de los departamentos que se les puede poner error + * @param vDepartmentFk id del departamento + * + */ + + SELECT w.id,w.firstName, w.lastName,d.name + FROM worker w + JOIN workerDepartment wd ON wd.workerFk = w.id + JOIN department d ON d.id = wd.departmentFk + WHERE d.id = vDepartmentFk + ORDER BY 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `worker_getHierarchy` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -91464,8 +76177,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_getHierarchy`(vBoss INT) BEGIN @@ -91513,201 +76224,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 `worker_getHierarch__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_getHierarch__`(vBoss INT) -BEGIN --- eliminar no se usa - -- usar worker_getHierarchy - DECLARE EXIT HANDLER FOR 1062 BEGIN - CALL util.throw('INFINITE_LOOP'); - END; - - DROP TEMPORARY TABLE IF EXISTS workerHierarch; - CREATE TEMPORARY TABLE workerHierarch - (PRIMARY KEY (workerFk)) - ENGINE = MEMORY - SELECT vBoss AS workerFk; - - DROP TEMPORARY TABLE IF EXISTS tmp.workerHierarchList; - CREATE TEMPORARY TABLE tmp.workerHierarchList - (PRIMARY KEY (workerFk)) - ENGINE = MEMORY - SELECT vBoss AS workerFk, 0 AS isChecked; - - - WHILE (SELECT COUNT(*) FROM tmp.workerHierarchList WHERE NOT isChecked) > 0 DO - - INSERT INTO tmp.workerHierarchList - SELECT w.id, 0 - FROM worker w - JOIN workerHierarch wh ON wh.workerFk = w.bossFk; - - UPDATE tmp.workerHierarchList whl - JOIN workerHierarch wh ON wh.workerFk = whl.workerFk - SET whl.isChecked = 1; - - TRUNCATE workerHierarch; - - INSERT INTO workerHierarch - SELECT workerFk - FROM tmp.workerHierarchList - WHERE NOT isChecked; - - END WHILE; - - DROP TEMPORARY TABLE IF EXISTS workerHierarch; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` 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, (IFNULL(sub1.errors,0) + IFNULL(sub2.errors,0))/sub1.totalTickets AS ratio, IF(vDepartment = 'Revisadores', NULL, volume) AS volume - FROM( - SELECT w.id, w.code, w.firstName, w.lastName, t.ticketCount AS totalTickets, sub.errors, sub2.volume - 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 - LEFT JOIN ( -- Añadir volume - SELECT SUM(w.volume) AS volume, w.workerFk - FROM bs.workerProductivity w - INNER JOIN vn.`role` r ON r.id=w.roleFk - WHERE IF(vDepartment = 'Encajadores', r.name='packager', r.name='itemPicker') AND w.dated BETWEEN vDatedFrom AND vDatedTo - GROUP BY w.workerFk) sub2 ON w.id = sub2.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_getSector` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_getSector`() -BEGIN - -/** - * Obtiene el sector del usuario conectado -*/ - - SELECT s.id,s.description,s.warehouseFk - FROM sector s - JOIN worker w ON w.sectorFk = s.id - WHERE w.id = account.userGetId(); - +BEGIN + +/** + * Obtiene el sector del usuario conectado +*/ + + SELECT s.id,s.description,s.warehouseFk + FROM sector s + JOIN worker w ON w.sectorFk = s.id + WHERE w.id = account.myUser_getId(); + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `worker_updateSector` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `worker_updateSector`(vSectorFk INT) -BEGIN - -/** - * ACtualiza el sector del usuario conectado - * - * @param vSectorFk id del sector -*/ - UPDATE worker - SET sectorFk = vSectorFk - WHERE id = account.userGetId(); - - +BEGIN + +/** + * ACtualiza el sector del usuario conectado + * + * @param vSectorFk id del sector +*/ + UPDATE worker + SET sectorFk = vSectorFk + WHERE id = account.myUser_getId(); + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workingHours` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -91715,8 +76290,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workingHours`(username varchar(255), logon boolean) BEGIN @@ -91737,6 +76310,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workingHoursTimeIn` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -91744,19 +76319,19 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workingHoursTimeIn`(vUserId INT(11)) BEGIN INSERT INTO vn.workingHours (timeIn, userId) - VALUES (util.VN_NOW(),vUserId); + VALUES (vn.VN_NOW(),vUserId); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `workingHoursTimeOut` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -91764,21 +76339,21 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `workingHoursTimeOut`(vUserId INT(11)) BEGIN UPDATE vn.workingHours - SET timeOut = util.VN_NOW() + SET timeOut = vn.VN_NOW() WHERE userId = vUserId - AND DATE(timeIn) = util.VN_CURDATE(); + AND DATE(timeIn) = vn.VN_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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `wrongEqualizatedClient` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -91786,8 +76361,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `wrongEqualizatedClient`() BEGIN @@ -91819,46 +76392,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 `xdiarioNextId__` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `xdiarioNextId__`() -BEGIN -/** - * @deprecated Use ledger_next - */ - DECLARE vNewAsien INT; - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - START TRANSACTION; - - SELECT bookFk + 1 INTO vNewAsien FROM config FOR UPDATE; - UPDATE config SET bookFk = vNewAsien; - COMMIT; - - SELECT vNewAsien; - - DROP TEMPORARY TABLE IF EXISTS tmp.xdiarioNextId; - CREATE TEMPORARY TABLE tmp.xdiarioNextId AS - SELECT vNewAsien ; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -91866,8 +76401,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zoneClosure_recalc`() proc: BEGIN @@ -91876,7 +76409,7 @@ proc: BEGIN */ DECLARE vScope INT; DECLARE vCounter INT DEFAULT 0; - DECLARE vShipped DATE DEFAULT util.VN_CURDATE(); + DECLARE vShipped DATE DEFAULT vn.VN_CURDATE(); DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN @@ -91919,72 +76452,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 `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 */ ; -/*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `zoneClosure_recalc_beta__`() -proc: BEGIN -/** - * Recalculates the delivery time (hour) for every zone in days + scope in future - */ - DECLARE vScope INT; - DECLARE vCounter INT DEFAULT 0; - DECLARE vShipped DATE DEFAULT util.VN_CURDATE(); - - DECLARE CONTINUE HANDLER FOR SQLEXCEPTION - BEGIN - DO RELEASE_LOCK('vn.zoneClosure_recalc'); - RESIGNAL; - END; - - IF NOT GET_LOCK('vn.zoneClosure_recalc', 0) THEN - LEAVE proc; - END IF; - - SELECT scope INTO vScope - FROM zoneConfig; - - DROP TEMPORARY TABLE IF EXISTS tmp.zone; - CREATE TEMPORARY TABLE tmp.zone - (INDEX (id)) - ENGINE = MEMORY - SELECT id FROM zone; - - WHILE vCounter <= vScope DO - - DELETE FROM zoneClosure - WHERE dated = vShipped; - - SELECT vShipped; - - CALL zone_getOptionsForShipment_beta(vShipped, TRUE); - - REPLACE zoneClosure(zoneFk, dated, `hour`) - SELECT zoneFk, vShipped, `hour` - FROM tmp.zoneOption; - - SET vCounter = vCounter + 1; - SET vShipped = TIMESTAMPADD(DAY, 1, vShipped); - END WHILE; - - SELECT * - FROM tmp.zoneOption; - - -- DROP TEMPORARY TABLE tmp.zone; - DO RELEASE_LOCK('vn.zoneClosure_recalc'); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `zoneGeo_calcTree` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -91992,8 +76461,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zoneGeo_calcTree`() BEGIN @@ -92029,6 +76496,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zoneGeo_calcTreeRec` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92036,8 +76505,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zoneGeo_calcTreeRec`( vSelf INT, @@ -92111,6 +76578,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zoneGeo_checkName` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92118,8 +76587,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zoneGeo_checkName`(vName VARCHAR(255)) BEGIN @@ -92133,6 +76600,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zoneGeo_delete` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92140,8 +76609,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zoneGeo_delete`(vSelf INT) BEGIN @@ -92159,6 +76626,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zoneGeo_doCalc` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92166,8 +76635,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zoneGeo_doCalc`() proc: BEGIN @@ -92201,6 +76668,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zoneGeo_setParent` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92208,8 +76677,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zoneGeo_setParent`(vSelf INT, vParentFk INT) BEGIN @@ -92230,6 +76697,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zoneGeo_throwNotEditable` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92237,8 +76706,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zoneGeo_throwNotEditable`() BEGIN @@ -92250,69 +76717,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 `zone_doCalcInitialize` */; -/*!50003 SET @saved_cs_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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_doCalcInitialize`() -proc: BEGIN -/** - * Initialize ticket - */ - DECLARE vDone BOOL; - DECLARE vLanded DATE; - DECLARE vZoneFk INT; - - DECLARE cCur CURSOR FOR - SELECT t.landed, t.zoneFk - FROM ticket t - WHERE shipped >= '2020-03-01' - AND zoneFk IS NOT NULL and zonePrice IS NULL - GROUP BY zoneFk, shipped; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - OPEN cCur; - - myLoop: LOOP - SET vDone = FALSE; - FETCH cCur INTO vLanded, vZoneFk; - - IF vDone THEN - LEAVE myLoop; - END IF; - - DROP TEMPORARY TABLE IF EXISTS tmp.zone; - CREATE TEMPORARY TABLE tmp.zone - (INDEX (id)) - ENGINE = MEMORY - SELECT vZoneFk id; - - CALL zone_getOptionsForLanding(vLanded, TRUE); - - UPDATE ticket t - LEFT JOIN tmp.zoneOption zo ON TRUE - SET zonePrice = zo.price, zoneBonus = zo.bonus - WHERE t.zoneFk = vZoneFk AND t.landed = vLanded - AND t.zonePrice IS NULL; - - END LOOP; - - CLOSE cCur; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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_ETD_byTime` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92320,33 +76726,65 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_ETD_byTime`() -BEGIN - - SET @m := 0; - - DROP TEMPORARY TABLE IF EXISTS tmpZone; - CREATE TEMPORARY TABLE tmpZone - SELECT remainingVolume, - hourTheoretical, - @m := @m + minutesLess totalMinutes - FROM zoneEstimatedDelivery ze - WHERE ze.remainingVolume - ORDER BY ze.hourTheoretical DESC; - - SELECT * FROM tmpZone; - - DROP TABLE tmpZone; - +BEGIN + + SET @m := 0; + + DROP TEMPORARY TABLE IF EXISTS tmpZone; + CREATE TEMPORARY TABLE tmpZone + SELECT remainingVolume, + hourTheoretical, + @m := @m + minutesLess totalMinutes + FROM zoneEstimatedDelivery ze + WHERE ze.remainingVolume + ORDER BY ze.hourTheoretical DESC; + + SELECT * FROM tmpZone; + + DROP TABLE tmpZone; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 DROP PROCEDURE IF EXISTS `zone_excludeFromGeo` */; +/*!50003 SET @saved_cs_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 */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_excludeFromGeo`(vZoneGeo INT) +BEGIN +/** + * Excluye zonas a partir un geoFk. + * + * @table tmp.zoneOption(zoneFk, hour, travelingDays, price, bonus, landed, shipped) The computed options + * @param vZoneGeo The zone geo + * @return tmp.zoneOption The computed options + */ + DELETE t FROM tmp.zoneOption t + JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + JOIN zoneGeo zg1 ON zg1.id = eg.geoFk + JOIN zoneGeo zg2 ON zg2.id = vZoneGeo + WHERE zg2.`path` LIKE CONCAT(zg1.`path`,'%'); + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!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_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getAgency` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92354,8 +76792,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getAgency`(vAddress INT, vLanded DATE) BEGIN @@ -92395,6 +76831,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getAvailable` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92402,8 +76840,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getAvailable`(vAddress INT, vLanded DATE) BEGIN @@ -92421,6 +76857,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getClosed` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92428,8 +76866,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getClosed`() proc:BEGIN @@ -92459,7 +76895,7 @@ proc:BEGIN JOIN vn.productionConfig pc WHERE a.isOwn AND pc.isZoneClosedByExpeditionActivated - AND e.created >= util.VN_CURDATE() + AND e.created >= vn.VN_CURDATE() GROUP BY t.zoneFk, t.warehouseFk HAVING numTickets >= minTicketsToCloseZone) sub; END ;; @@ -92468,6 +76904,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getCollisions` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92475,8 +76913,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getCollisions`() BEGIN @@ -92501,7 +76937,7 @@ BEGIN JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk WHERE dm.code IN ('AGENCY','DELIVERY'); - CALL zone_getOptionsForShipment(util.VN_CURDATE(),FALSE); + CALL zone_getOptionsForShipment(vn.VN_CURDATE(),FALSE); DROP TEMPORARY TABLE IF EXISTS tmp.zoneNodes; CREATE TEMPORARY TABLE tmp.zoneNodes ( @@ -92569,7 +77005,7 @@ BEGIN INSERT INTO mail (receiver,replyTo,subject,body) SELECT 'pepe@verdnatura.es' receiver, 'noreply@verdnatura.es' replyTo, - CONCAT('Colisiones en zonas ', util.VN_CURDATE()) subject, + CONCAT('Colisiones en zonas ', vn.VN_CURDATE()) subject, CONCAT(vTableCollisions, GROUP_CONCAT(sub.td SEPARATOR ''), '') body @@ -92606,6 +77042,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getEvents` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92613,8 +77051,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getEvents`( vGeoFk INT, @@ -92670,7 +77106,11 @@ BEGIN SELECT e.zoneFk, e.dated FROM tZone t - JOIN zoneExclusion e ON e.zoneFk = t.id; + JOIN zoneExclusion e ON e.zoneFk = t.id + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + JOIN zoneGeo zg1 ON zg1.id = eg.geoFk + JOIN zoneGeo zg2 ON zg2.id = vGeoFk + WHERE eg.zoneExclusionFk IS NULL OR zg2.`path` LIKE CONCAT(zg1.`path`,'%'); DROP TEMPORARY TABLE tZone; END ;; @@ -92679,6 +77119,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getFromGeo` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92686,8 +77128,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getFromGeo`(vGeoFk INT) BEGIN @@ -92736,6 +77176,7 @@ BEGIN FROM tNodes n JOIN zoneIncluded i ON i.geoFk = n.id ORDER BY zoneFk, n.`level` + LIMIT 10000000000000000000 ) t GROUP BY id HAVING isIncluded ) t; @@ -92747,6 +77188,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getLanded` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92754,8 +77197,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getLanded`(vShipped DATE, vAddressFk INT, vAgencyModeFk INT, vWarehouseFk INT, vShowExpiredZones BOOLEAN) BEGIN @@ -92769,10 +77210,13 @@ BEGIN * @param vWarehouseFk vWarehouseFk * @table tmp.zoneGetLanded Datos de recepción */ - CALL vn.zone_getFromGeo(address_getGeo(vAddressFk)); + DECLARE vZoneGeo INT; + SELECT address_getGeo(vAddressFk) INTO vZoneGeo; + + CALL vn.zone_getFromGeo(vZoneGeo); CALL vn.zone_getOptionsForShipment(vShipped, vShowExpiredZones); - + CALL vn.zone_excludeFromGeo(vZoneGeo); CALL vn.zone_getClosed(); DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded; @@ -92787,7 +77231,7 @@ BEGIN LEFT JOIN tmp.closedZones cz ON cz.warehouseFk = zw.warehouseFk AND cz.zoneFk = zw.zoneFk - AND zo.shipped = util.VN_CURDATE() + AND zo.shipped = vn.VN_CURDATE() WHERE z.agencyModeFk = vAgencyModeFk AND zw.warehouseFk = vWarehouseFk AND (ISNULL(cz.zoneFk) OR vShowExpiredZones); @@ -92802,6 +77246,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getLeaves` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92809,8 +77255,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getLeaves`(vSelf INT, vParentFk INT, vSearch VARCHAR(255)) BEGIN @@ -92911,6 +77355,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getLeaves2` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -92918,220 +77364,116 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getLeaves2`(vSelf INT, vParentFk INT, vSearch VARCHAR(255)) -BEGIN -/** - * 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 - (INDEX(id)) - ENGINE = MEMORY - SELECT id - FROM tNodes; - - DROP TEMPORARY TABLE IF EXISTS tParents; - CREATE TEMPORARY TABLE tParents - (INDEX(id)) - 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; +BEGIN +/** + * 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 + (INDEX(id)) + ENGINE = MEMORY + SELECT id + FROM tNodes; + + DROP TEMPORARY TABLE IF EXISTS tParents; + CREATE TEMPORARY TABLE tParents + (INDEX(id)) + 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 = 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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` 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 */ ; @@ -93139,8 +77481,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getOptionsForLanding`(vLanded DATE, vShowExpiredZones BOOLEAN) BEGIN @@ -93160,6 +77500,7 @@ BEGIN travelingDays, price, bonus, + vLanded landed, TIMESTAMPADD(DAY, -travelingDays, vLanded) shipped FROM ( SELECT t.id zoneFk, @@ -93188,17 +77529,19 @@ BEGIN THEN 2 ELSE 3 END + LIMIT 10000000000000000000 ) t - GROUP BY zoneFk; - + GROUP BY zoneFk; + DELETE t FROM tmp.zoneOption t - JOIN zoneExclusion e - ON e.zoneFk = t.zoneFk AND e.`dated` = vLanded; - + JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + WHERE eg.zoneExclusionFk IS NULL; + IF NOT vShowExpiredZones THEN DELETE FROM tmp.zoneOption - WHERE shipped < util.VN_CURDATE() - OR (shipped = util.VN_CURDATE() AND util.VN_CURTIME() > `hour`); + WHERE shipped < vn.VN_CURDATE() + OR (shipped = vn.VN_CURDATE() AND vn.VN_CURTIME() > `hour`); END IF; END ;; DELIMITER ; @@ -93206,6 +77549,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getOptionsForShipment` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -93213,8 +77558,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getOptionsForShipment`(vShipped DATE, vShowExpiredZones BOOLEAN) BEGIN @@ -93225,7 +77568,7 @@ BEGIN * @param vShipped The shipping date * @return tmp.zoneOption(zoneFk, hour, travelingDays, price, bonus, specificity) The computed options */ - DECLARE vHour TIME DEFAULT TIME(util.VN_NOW()); + DECLARE vHour TIME DEFAULT TIME(vn.VN_NOW()); DROP TEMPORARY TABLE IF EXISTS tLandings; CREATE TEMPORARY TABLE tLandings @@ -93272,19 +77615,21 @@ BEGIN THEN 2 ELSE 3 END + LIMIT 10000000000000000000 ) t GROUP BY zoneFk; DROP TEMPORARY TABLE tLandings; DELETE t FROM tmp.zoneOption t - JOIN zoneExclusion e - ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed; + JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + WHERE eg.zoneExclusionFk IS NULL; IF NOT vShowExpiredZones THEN DELETE FROM tmp.zoneOption - WHERE vShipped < util.VN_CURDATE() - OR (vShipped = util.VN_CURDATE() AND util.VN_CURTIME() > `hour`); + WHERE vShipped < vn.VN_CURDATE() + OR (vShipped = vn.VN_CURDATE() AND vn.VN_CURTIME() > `hour`); END IF; END ;; DELIMITER ; @@ -93292,6 +77637,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getShipped` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -93299,8 +77646,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getShipped`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT, vShowExpiredZones BOOLEAN) BEGIN @@ -93313,8 +77658,13 @@ BEGIN * @param vAgencyModeFk Id de la agencia * @return tmp.zoneGetShipped */ - CALL vn.zone_getFromGeo(address_getGeo(vAddressFk)); + DECLARE vZoneGeo INT; + + SELECT address_getGeo(vAddressFk) INTO vZoneGeo; + + CALL vn.zone_getFromGeo(vZoneGeo); CALL vn.zone_getOptionsForLanding(vLanded, vShowExpiredZones); + CALL vn.zone_excludeFromGeo(vZoneGeo); CALL vn.zone_getClosed(); DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetShipped; @@ -93334,10 +77684,11 @@ BEGIN LEFT JOIN tmp.closedZones cz ON cz.warehouseFk = zw.warehouseFk AND cz.zoneFk = zw.zoneFk - AND zo.shipped = util.VN_CURDATE() + AND zo.shipped = vn.VN_CURDATE() WHERE z.agencyModeFk = vAgencyModeFk AND (ISNULL(cz.zoneFk) OR vShowExpiredZones) - ORDER BY shipped) t + ORDER BY shipped + LIMIT 10000000000000000000) t GROUP BY warehouseFk; DROP TEMPORARY TABLE @@ -93350,6 +77701,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getState` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -93357,8 +77710,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getState`(vDated DATE) BEGIN @@ -93383,7 +77734,7 @@ BEGIN SELECT zo.zoneFk, zo.`hour`etd, - (zo.`hour` <= TIME(now())) isLate, + (zo.`hour` <= TIME(vn.VN_NOW())) isLate, !ISNULL(cz.zoneFk) isFull, zw.warehouseFk, zo.landed @@ -93405,6 +77756,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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_getWarehouse` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -93412,8 +77765,6 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_getWarehouse`(vAddress INT, vLanded DATE, vWarehouse INT) BEGIN @@ -93455,15 +77806,15 @@ 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 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `zone_upcomingDeliveries` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `zone_upcomingDeliveries`() BEGIN @@ -93471,7 +77822,7 @@ BEGIN DECLARE vForwardDays INT; SELECT forwardDays INTO vForwardDays FROM zoneConfig; - CALL util.time_createTable(util.VN_CURDATE(), DATE_ADD(util.VN_CURDATE(), INTERVAL vForwardDays DAY)); + CALL util.time_createTable(vn.VN_CURDATE(), DATE_ADD(vn.VN_CURDATE(), INTERVAL vForwardDays DAY)); DROP TEMPORARY TABLE IF EXISTS tLandings; CREATE TEMPORARY TABLE tLandings @@ -93483,7 +77834,7 @@ BEGIN ti.dated shipped FROM zone z JOIN zoneEvent e ON e.zoneFk = z.id - JOIN tmp.time ti ON ti.dated BETWEEN util.VN_CURDATE() AND TIMESTAMPADD(DAY, vForwardDays, util.VN_CURDATE()); + JOIN tmp.time ti ON ti.dated BETWEEN vn.VN_CURDATE() AND TIMESTAMPADD(DAY, vForwardDays, vn.VN_CURDATE()); DROP TEMPORARY TABLE IF EXISTS tmp.zoneOption; CREATE TEMPORARY TABLE tmp.zoneOption @@ -93518,12 +77869,14 @@ BEGIN THEN 2 ELSE 3 END + LIMIT 10000000000000000000 ) t GROUP BY zoneFk, landed; DELETE t FROM tmp.zoneOption t - JOIN zoneExclusion e - ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed; + JOIN zoneExclusion e ON e.zoneFk = t.zoneFk AND e.`dated` = t.landed + LEFT JOIN zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id + WHERE eg.zoneExclusionFk IS NULL; SELECT MAX(zo.`hour`) `hour`, zg.`name`, zo.shipped, zo.zoneFk FROM tmp.zoneOption zo @@ -93593,9 +77946,9 @@ DROP TABLE IF EXISTS `inter`; CREATE TABLE `inter` ( `inter_id` int(11) NOT NULL AUTO_INCREMENT, `state_id` tinyint(3) unsigned NOT NULL, - `fallo_id` int(10) unsigned NOT NULL DEFAULT 21, + `fallo_id` int(10) unsigned NOT NULL DEFAULT '21', `nota` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - `odbc_date` timestamp NULL DEFAULT current_timestamp(), + `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `Id_Ticket` int(11) DEFAULT NULL, `Id_Trabajador` int(11) DEFAULT NULL, `Id_Supervisor` int(10) unsigned DEFAULT NULL, @@ -93655,19 +78008,19 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vncontrol`.`ticketTracking_afterInsert` - AFTER INSERT ON `inter` - FOR EACH ROW -BEGIN - - DECLARE vNumTicketsPrepared INT; - - REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name) - SELECT NEW.Id_Ticket, NEW.inter_id, `name` - FROM vn.state - WHERE id = NEW.state_id; - - +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`localhost`*/ /*!50003 TRIGGER `vncontrol`.`ticketTracking_afterInsert` + AFTER INSERT ON `inter` + FOR EACH ROW +BEGIN + + DECLARE vNumTicketsPrepared INT; + + REPLACE vn.ticketLastState(ticketFk, ticketTrackingFk, name) + SELECT NEW.Id_Ticket, NEW.inter_id, `name` + FROM vn.state + WHERE id = NEW.state_id; + + END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -93767,6 +78120,8 @@ DELIMITER ; -- -- Dumping routines for database 'vncontrol' -- +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 DROP PROCEDURE IF EXISTS `clean` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -93774,12 +78129,10 @@ DELIMITER ; /*!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 = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `clean`() BEGIN - DECLARE vDate DATETIME DEFAULT TIMESTAMPADD(MONTH, -2, util.VN_CURDATE()); + DECLARE vDate DATETIME DEFAULT TIMESTAMPADD(MONTH, -2, vn.VN_CURDATE()); DELETE i FROM inter i JOIN vn.ticket t ON i.Id_Ticket = t.id WHERE t.shipped <= vDate; END ;; @@ -93809,7 +78162,7 @@ USE `account`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `accountDovecot` AS select `u`.`name` AS `name`,`u`.`password` AS `password` from (`user` `u` join `account` `a` on(`a`.`id` = `u`.`id`)) where `u`.`active` <> 0 */; +/*!50001 VIEW `accountDovecot` AS select `u`.`name` AS `name`,`u`.`password` AS `password` from (`user` `u` join `account` `a` on((`a`.`id` = `u`.`id`))) where `u`.`active` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -93847,7 +78200,7 @@ USE `account`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myRole` AS select `r`.`inheritsFrom` AS `id` from (`roleRole` `r` join `user` `u` on(`u`.`role` = `r`.`role`)) where `u`.`id` = `myUser_getId`() */; +/*!50001 VIEW `myRole` AS select `r`.`inheritsFrom` AS `id` from (`roleRole` `r` join `user` `u` on((`u`.`role` = `r`.`role`))) where (`u`.`id` = `myUser_getId`()) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -93866,7 +78219,7 @@ USE `account`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myUser` AS select `u`.`id` AS `id`,`u`.`name` AS `name`,`u`.`active` AS `active`,`u`.`email` AS `email`,`u`.`nickname` AS `nickname`,`u`.`lang` AS `lang`,`u`.`role` AS `role`,`u`.`recoverPass` AS `recoverPass` from `user` `u` where `u`.`name` = `myUserGetName`() */ +/*!50001 VIEW `myUser` AS select `u`.`id` AS `id`,`u`.`name` AS `name`,`u`.`active` AS `active`,`u`.`email` AS `email`,`u`.`nickname` AS `nickname`,`u`.`lang` AS `lang`,`u`.`role` AS `role`,`u`.`recoverPass` AS `recoverPass` from `user` `u` where (`u`.`name` = `myUser_getName`()) */ /*!50002 WITH CASCADED CHECK OPTION */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; @@ -93892,7 +78245,7 @@ USE `bs`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `bajasLaborales` AS select `p`.`firstname` AS `firstname`,`p`.`name` AS `name`,`b`.`business_id` AS `business_id`,max(`ce`.`date`) AS `lastDate`,max(ifnull(`b`.`date_end`,util.VN_CURDATE())) AS `endContract`,`cs`.`type` AS `type`,cast(count(0) as decimal(10,0)) AS `dias`,`w`.`userFk` AS `userFk` from (((((`postgresql`.`calendar_employee` `ce` join `postgresql`.`business` `b` on(`b`.`business_id` = `ce`.`business_id`)) join `postgresql`.`profile` `pr` on(`pr`.`profile_id` = `b`.`client_id`)) join `postgresql`.`person` `p` on(`p`.`person_id` = `pr`.`person_id`)) join `postgresql`.`calendar_state` `cs` on(`cs`.`calendar_state_id` = `ce`.`calendar_state_id`)) join `vn`.`worker` `w` on(`w`.`id` = `p`.`id_trabajador`)) where `ce`.`date` >= util.VN_CURDATE() + interval -1 year and `cs`.`type` not in ('Vacaciones','Vacaciones 1/2 día','Compensar','Festivo') group by `p`.`firstname`,`p`.`name`,`cs`.`type` having `endContract` >= util.VN_CURDATE() */; +/*!50001 VIEW `bajasLaborales` AS select `p`.`firstname` AS `firstname`,`p`.`name` AS `name`,`b`.`business_id` AS `business_id`,max(`ce`.`date`) AS `lastDate`,max(ifnull(`b`.`date_end`,vn.VN_CURDATE())) AS `endContract`,`at`.`name` AS `type`,cast(count(0) as decimal(10,0)) AS `dias`,`w`.`userFk` AS `userFk` from (((((`postgresql`.`calendar_employee` `ce` join `postgresql`.`business` `b` on((`b`.`business_id` = `ce`.`business_id`))) join `postgresql`.`profile` `pr` on((`pr`.`profile_id` = `b`.`client_id`))) join `postgresql`.`person` `p` on((`p`.`person_id` = `pr`.`person_id`))) join `vn`.`absenceType` `at` on((`at`.`id` = `ce`.`calendar_state_id`))) join `vn`.`worker` `w` on((`w`.`id` = `p`.`id_trabajador`))) where ((`ce`.`date` >= (vn.VN_CURDATE() + interval -(1) year)) and (`at`.`name` not in ('Vacaciones','Vacaciones 1/2 día','Compensar','Festivo'))) group by `p`.`firstname`,`p`.`name`,`at`.`name` having (`endContract` >= vn.VN_CURDATE()) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -93911,102 +78264,7 @@ USE `bs`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `lastIndicators` AS select `i`.`updated` AS `updated`,`i`.`lastYearSales` AS `lastYearSales`,`i`.`lastYearSales` - `yi`.`lastYearSales` AS `incLastYearSales`,`i`.`totalGreuge` AS `totalGreuge`,`i`.`totalGreuge` - `yi`.`totalGreuge` AS `incTotalGreuge`,`i`.`latePaymentRate` AS `latePaymentRate`,`i`.`latePaymentRate` - `yi`.`latePaymentRate` AS `incLatePaymentRate`,`i`.`countEmployee` AS `countEmployee`,`i`.`countEmployee` - `yi`.`countEmployee` AS `incCountEmployee`,`i`.`averageMana` AS `averageMana`,`i`.`averageMana` - `yi`.`averageMana` AS `incAverageMana`,`i`.`bankingPool` AS `bankingPool`,`i`.`bankingPool` - `yi`.`bankingPool` AS `incbankingPool`,`i`.`lastMonthActiveClients` AS `lastMonthActiveClients`,`i`.`lastMonthActiveClients` - `yi`.`lastMonthActiveClients` AS `incLastMonthActiveClients`,`i`.`lastMonthLostClients` AS `lastMonthLostClients`,`i`.`lastMonthLostClients` - `yi`.`lastMonthLostClients` AS `incLastMonthLostClients`,`i`.`lastMonthNewClients` AS `lastMonthNewClients`,`i`.`lastMonthNewClients` - `yi`.`lastMonthNewClients` AS `incLastMonthNewClients`,`i`.`lastMonthWebBuyingRate` AS `lastMonthWebBuyingRate`,`i`.`lastMonthWebBuyingRate` - `yi`.`lastMonthWebBuyingRate` AS `incLastMonthWebBuyingRate`,`i`.`productionHours__` AS `productionHours__`,`i`.`dailyWorkersCost__` AS `dailyWorkersCost__`,`i`.`volumeM3__` AS `volumeM3__`,`i`.`salesValue__` AS `salesValue__`,`i`.`valueM3__` AS `valueM3__`,`i`.`hoursM3__` AS `hoursM3__`,`i`.`workerCostM3__` AS `workerCostM3__`,`i`.`salesWorkersCostRate__` AS `salesWorkersCostRate__`,`i`.`thisWeekSales` AS `thisWeekSales`,`i`.`lastYearWeekSales` AS `lastYearWeekSales` from (`indicators` `i` join `indicators` `yi` on(`yi`.`updated` = (select max(`indicators`.`updated`) + interval -1 day from `indicators`))) where `i`.`updated` = (select max(`indicators`.`updated`) from `indicators`) */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `m3Silla__` --- - -/*!50001 DROP TABLE IF EXISTS `m3Silla__`*/; -/*!50001 DROP VIEW IF EXISTS `m3Silla__`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `m3Silla__` AS select `m3`.`fecha` AS `fecha`,`m3`.`year` AS `year`,`m3`.`month` AS `month`,`m3`.`week` AS `week`,`m3`.`day` AS `day`,`m3`.`dayName` AS `dayName`,cast(sum(`m3`.`m3`) as decimal(10,0)) AS `Volumen`,cast(sum(`m3`.`euros`) as decimal(10,0)) AS `Euros` from `m3` where `m3`.`warehouseFk` in (1,44) group by `m3`.`fecha` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `manaCustomer` --- - -/*!50001 DROP TABLE IF EXISTS `manaCustomer`*/; -/*!50001 DROP VIEW IF EXISTS `manaCustomer`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `manaCustomer` AS select `cmc`.`clientFk` AS `Id_Cliente`,`cmc`.`mana` AS `Mana`,`cmc`.`dated` AS `dated` from `vn`.`clientManaCache` `cmc` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `manaSpellersExcluded` --- - -/*!50001 DROP TABLE IF EXISTS `manaSpellersExcluded`*/; -/*!50001 DROP VIEW IF EXISTS `manaSpellersExcluded`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `manaSpellersExcluded` AS select `m`.`Id_Trabajador` AS `workerFk` from `bs`.`mana_spellers_excluded` `m` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `mana_spellers` --- - -/*!50001 DROP TABLE IF EXISTS `mana_spellers`*/; -/*!50001 DROP VIEW IF EXISTS `mana_spellers`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `mana_spellers` AS select `wm`.`workerFk` AS `Id_Trabajador`,`wm`.`size` AS `size`,`wm`.`amount` AS `used`,`wm`.`pricesModifierRate` AS `prices_modifier_rate`,`wm`.`isPricesModifierActivated` AS `prices_modifier_activated`,`wm`.`minRate` AS `minRate`,`wm`.`maxRate` AS `maxRate` from `vn`.`workerMana` `wm` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `mana_spellers_excluded` --- - -/*!50001 DROP TABLE IF EXISTS `mana_spellers_excluded`*/; -/*!50001 DROP VIEW IF EXISTS `mana_spellers_excluded`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `mana_spellers_excluded` AS select `wme`.`workerFk` AS `Id_Trabajador` from `vn`.`workerManaExcluded` `wme` */; +/*!50001 VIEW `lastIndicators` AS select `i`.`updated` AS `updated`,`i`.`lastYearSales` AS `lastYearSales`,(`i`.`lastYearSales` - `yi`.`lastYearSales`) AS `incLastYearSales`,`i`.`totalGreuge` AS `totalGreuge`,(`i`.`totalGreuge` - `yi`.`totalGreuge`) AS `incTotalGreuge`,`i`.`latePaymentRate` AS `latePaymentRate`,(`i`.`latePaymentRate` - `yi`.`latePaymentRate`) AS `incLatePaymentRate`,`i`.`countEmployee` AS `countEmployee`,(`i`.`countEmployee` - `yi`.`countEmployee`) AS `incCountEmployee`,`i`.`averageMana` AS `averageMana`,(`i`.`averageMana` - `yi`.`averageMana`) AS `incAverageMana`,`i`.`bankingPool` AS `bankingPool`,(`i`.`bankingPool` - `yi`.`bankingPool`) AS `incbankingPool`,`i`.`lastMonthActiveClients` AS `lastMonthActiveClients`,(`i`.`lastMonthActiveClients` - `yi`.`lastMonthActiveClients`) AS `incLastMonthActiveClients`,`i`.`lastMonthLostClients` AS `lastMonthLostClients`,(`i`.`lastMonthLostClients` - `yi`.`lastMonthLostClients`) AS `incLastMonthLostClients`,`i`.`lastMonthNewClients` AS `lastMonthNewClients`,(`i`.`lastMonthNewClients` - `yi`.`lastMonthNewClients`) AS `incLastMonthNewClients`,`i`.`lastMonthWebBuyingRate` AS `lastMonthWebBuyingRate`,(`i`.`lastMonthWebBuyingRate` - `yi`.`lastMonthWebBuyingRate`) AS `incLastMonthWebBuyingRate`,`i`.`productionHours__` AS `productionHours__`,`i`.`dailyWorkersCost__` AS `dailyWorkersCost__`,`i`.`volumeM3__` AS `volumeM3__`,`i`.`salesValue__` AS `salesValue__`,`i`.`valueM3__` AS `valueM3__`,`i`.`hoursM3__` AS `hoursM3__`,`i`.`workerCostM3__` AS `workerCostM3__`,`i`.`salesWorkersCostRate__` AS `salesWorkersCostRate__`,`i`.`thisWeekSales` AS `thisWeekSales`,`i`.`lastYearWeekSales` AS `lastYearWeekSales` from (`indicators` `i` join `indicators` `yi` on((`yi`.`updated` = (select (max(`indicators`.`updated`) + interval -(1) day) from `indicators`)))) where (`i`.`updated` = (select max(`indicators`.`updated`) from `indicators`)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94025,7 +78283,7 @@ USE `bs`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `packingSpeed` AS select hour(`e`.`created`) AS `hora`,minute(`e`.`created`) AS `minuto`,ifnull(`p`.`volume`,`p`.`width` * `p`.`height` * `p`.`depth`) AS `cm3`,`t`.`warehouseFk` AS `warehouse_id`,`e`.`created` AS `odbc_date` from ((`vn`.`expedition` `e` join `vn`.`packaging` `p` on(`p`.`id` = `e`.`packagingFk`)) join `vn`.`ticket` `t` on(`t`.`id` = `e`.`ticketFk`)) where `e`.`created` between util.VN_CURDATE() and `util`.`dayend`(util.VN_CURDATE()) */; +/*!50001 VIEW `packingSpeed` AS select hour(`e`.`created`) AS `hora`,minute(`e`.`created`) AS `minuto`,ifnull(`p`.`volume`,((`p`.`width` * `p`.`height`) * `p`.`depth`)) AS `cm3`,`t`.`warehouseFk` AS `warehouse_id`,`e`.`created` AS `odbc_date` from ((`vn`.`expedition` `e` join `vn`.`packaging` `p` on((`p`.`id` = `e`.`packagingFk`))) join `vn`.`ticket` `t` on((`t`.`id` = `e`.`ticketFk`))) where (`e`.`created` between vn.VN_CURDATE() and `util`.`dayend`(vn.VN_CURDATE())) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94044,7 +78302,7 @@ USE `bs`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `s1_ticketDetail` AS select `s`.`ticketFk` AS `ticketFk`,cast(sum(`s`.`price` * `s`.`quantity`) as decimal(10,2)) AS `ticketAmount`,count(`s`.`id`) AS `ticketLines`,cast(sum(`sv`.`volume`) as decimal(10,2)) AS `ticketM3`,cast(`t`.`shipped` as date) AS `shipped` from ((`vn`.`ticket` `t` join `vn`.`sale` `s` on(`s`.`ticketFk` = `t`.`id`)) join `vn`.`saleVolume` `sv` on(`sv`.`saleFk` = `s`.`id`)) where `t`.`shipped` between '2021-09-01' and '2021-10-31 23:59' group by `s`.`ticketFk` */; +/*!50001 VIEW `s1_ticketDetail` AS select `s`.`ticketFk` AS `ticketFk`,cast(sum((`s`.`price` * `s`.`quantity`)) as decimal(10,2)) AS `ticketAmount`,count(`s`.`id`) AS `ticketLines`,cast(sum(`sv`.`volume`) as decimal(10,2)) AS `ticketM3`,cast(`t`.`shipped` as date) AS `shipped` from ((`vn`.`ticket` `t` join `vn`.`sale` `s` on((`s`.`ticketFk` = `t`.`id`))) join `vn`.`saleVolume` `sv` on((`sv`.`saleFk` = `s`.`id`))) where (`t`.`shipped` between '2021-09-01' and '2021-10-31 23:59') group by `s`.`ticketFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94063,45 +78321,7 @@ USE `bs`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `s21_saleDetail` AS select dayofmonth(`t`.`shipped`) AS `dia`,year(`t`.`shipped`) AS `año`,month(`t`.`shipped`) AS `mes`,`s`.`concept` AS `concepto`,`s`.`quantity` AS `unidades`,`s`.`price` AS `precio`,`s`.`quantity` * `s`.`price` AS `venta`,`it`.`name` AS `familia`,`w`.`code` AS `comprador`,`s`.`itemFk` AS `itemFk`,`s`.`ticketFk` AS `ticketFk`,`sv`.`volume` AS `volume` from ((((((`vn`.`sale` `s` join `vn`.`item` `i` on(`i`.`id` = `s`.`itemFk`)) join `vn`.`itemType` `it` on(`it`.`id` = `i`.`typeFk`)) join `vn`.`worker` `w` on(`w`.`id` = `it`.`workerFk`)) join `vn`.`ticket` `t` on(`t`.`id` = `s`.`ticketFk`)) join `vn`.`client` `c` on(`c`.`id` = `t`.`clientFk`)) join `vn`.`saleVolume` `sv` on(`sv`.`saleFk` = `s`.`id`)) where (`t`.`shipped` between '2020-10-21' and '2020-10-28' or `t`.`shipped` between '2019-10-21' and '2019-10-28' or `t`.`shipped` between '2021-09-1' and '2021-10-28') and `t`.`warehouseFk` in (1,60) and `c`.`isRelevant` <> 0 and `s`.`quantity` > 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 `sale__` --- - -/*!50001 DROP TABLE IF EXISTS `sale__`*/; -/*!50001 DROP VIEW IF EXISTS `sale__`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_general_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `sale__` AS select `v`.`Id_Movimiento` AS `saleFk`,`v`.`importe` AS `amount`,`v`.`recargo` AS `surcharge`,`v`.`fecha` AS `dated`,`v`.`tipo_id` AS `typeFk`,`v`.`Id_Cliente` AS `clientFk`,`v`.`empresa_id` AS `companyFk`,`v`.`margen` AS `margin` from `ventas` `v` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `salesPerson__` --- - -/*!50001 DROP TABLE IF EXISTS `salesPerson__`*/; -/*!50001 DROP VIEW IF EXISTS `salesPerson__`*/; -/*!50001 SET @saved_cs_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`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `salesPerson__` AS select `v`.`Id_Trabajador` AS `workerFk`,`v`.`año` AS `year`,`v`.`mes` AS `month`,`v`.`importe` AS `amount`,`v`.`comision` AS `commission`,`v`.`comisionArrendada` AS `leasedCommission`,`v`.`comisionCedida` AS `cededCommission`,`v`.`comisionNuevos` AS `newCommission`,`v`.`sustitucionArrendada` AS `leasedReplacement`,`v`.`itemTypeBorrowed` AS `itemTypeBorrowed`,`v`.`portfolioWeight` AS `portfolioWeight`,`v`.`updated` AS `updated` from `vendedores` `v` */; +/*!50001 VIEW `s21_saleDetail` AS select dayofmonth(`t`.`shipped`) AS `dia`,year(`t`.`shipped`) AS `año`,month(`t`.`shipped`) AS `mes`,`s`.`concept` AS `concepto`,`s`.`quantity` AS `unidades`,`s`.`price` AS `precio`,(`s`.`quantity` * `s`.`price`) AS `venta`,`it`.`name` AS `familia`,`w`.`code` AS `comprador`,`s`.`itemFk` AS `itemFk`,`s`.`ticketFk` AS `ticketFk`,`sv`.`volume` AS `volume` from ((((((`vn`.`sale` `s` join `vn`.`item` `i` on((`i`.`id` = `s`.`itemFk`))) join `vn`.`itemType` `it` on((`it`.`id` = `i`.`typeFk`))) join `vn`.`worker` `w` on((`w`.`id` = `it`.`workerFk`))) join `vn`.`ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `vn`.`client` `c` on((`c`.`id` = `t`.`clientFk`))) join `vn`.`saleVolume` `sv` on((`sv`.`saleFk` = `s`.`id`))) where (((`t`.`shipped` between '2020-10-21' and '2020-10-28') or (`t`.`shipped` between '2019-10-21' and '2019-10-28') or (`t`.`shipped` between '2021-09-1' and '2021-10-28')) and (`t`.`warehouseFk` in (1,60)) and `c`.`isRelevant` and (`s`.`quantity` > 0)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94144,25 +78364,6 @@ USE `bs`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; --- --- Final view structure for view `workerMana` --- - -/*!50001 DROP TABLE IF EXISTS `workerMana`*/; -/*!50001 DROP VIEW IF EXISTS `workerMana`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerMana` AS select `m`.`Id_Trabajador` AS `workerFk`,`m`.`used` AS `amount` from `bs`.`mana_spellers` `m` */; -/*!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` -- @@ -94189,7 +78390,7 @@ USE `edi`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `errorList` AS select `po`.`id` AS `id`,`c`.`name` AS `name`,`i`.`longName` AS `longName`,`po`.`quantity` AS `quantity`,left(`po`.`error`,4) AS `stock`,`po`.`error` AS `error`,`po`.`deliveryInformationID` AS `deliveryInformationID`,`po`.`supplyResponseID` AS `supplyResponseID`,`po`.`OrderTradeLineDateTime` AS `OrderTradeLineDateTime`,`po`.`EndUserPartyGLN` AS `EndUserPartyGLN` from ((`edi`.`putOrder` `po` left join `vn`.`client` `c` on(`c`.`id` = `po`.`EndUserPartyGLN`)) left join `vn`.`item` `i` on(`i`.`supplyResponseFk` = `po`.`supplyResponseID`)) where `po`.`OrderTradeLineDateTime` > util.VN_CURDATE() + interval -12 hour and `po`.`OrderStatus` = 3 and left(`po`.`error`,4) <> '(0) ' */; +/*!50001 VIEW `errorList` AS select `po`.`id` AS `id`,`c`.`name` AS `name`,`i`.`longName` AS `longName`,`po`.`quantity` AS `quantity`,left(`po`.`error`,4) AS `stock`,`po`.`error` AS `error`,`po`.`deliveryInformationID` AS `deliveryInformationID`,`po`.`supplyResponseID` AS `supplyResponseID`,`po`.`OrderTradeLineDateTime` AS `OrderTradeLineDateTime`,`po`.`EndUserPartyGLN` AS `EndUserPartyGLN` from ((`edi`.`putOrder` `po` left join `vn`.`client` `c` on((`c`.`id` = `po`.`EndUserPartyGLN`))) left join `vn`.`item` `i` on((`i`.`supplyResponseFk` = `po`.`supplyResponseID`))) where ((`po`.`OrderTradeLineDateTime` > (vn.VN_CURDATE() + interval -(12) hour)) and (`po`.`OrderStatus` = 3) and (left(`po`.`error`,4) <> '(0) ')) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94208,7 +78409,7 @@ USE `edi`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `supplyOffer` AS select `sr`.`vmpID` AS `vmpID`,`di`.`ID` AS `diId`,`sr`.`ID` AS `srId`,`sr`.`Item_ArticleCode` AS `Item_ArticleCode`,`sr`.`VBNOmschrijving` AS `product_name`,`s`.`company_name` AS `company_name`,cast(`sr`.`Price` as decimal(10,3)) AS `Price`,`sr`.`Quality` AS `Quality`,`sr`.`s1` AS `s1`,`sr`.`s2` AS `s2`,`sr`.`s3` AS `s3`,`sr`.`s4` AS `s4`,`sr`.`s5` AS `s5`,`sr`.`s6` AS `s6`,`sr`.`NumberOfUnits` AS `NumberOfUnits`,least(if(`sr`.`EmbalageCode` = 800,`sr`.`EmbalageCode` * 10 + `sr`.`NumberOfItemsPerCask`,`sr`.`EmbalageCode`),ifnull(`idt`.`bucket_id`,'999')) AS `EmbalageCode`,`di`.`LatestDeliveryDateTime` AS `LatestDeliveryDateTime`,`di`.`EarliestDespatchDateTime` AS `EarliestDespatchDateTime`,`di`.`FirstOrderDateTime` AS `FirstOrderDateTime`,`di`.`LatestOrderDateTime` AS `LatestOrderDateTime`,`sr`.`NumberOfItemsPerCask` AS `NumberOfItemsPerCask`,`sr`.`NumberOfLayersPerTrolley` AS `NumberOfLayersPerTrolley`,`sr`.`MinimumNumberToOrder` AS `MinimumNumberToOrder`,`sr`.`MaximumNumberToOrder` AS `MaximumNumberToOrder`,`sr`.`IncrementalOrderableQuantity` AS `IncrementalOrderableQuantity`,`sr`.`PackingPrice` AS `PackingPrice`,`sr`.`MarketPlaceID` AS `MarketPlaceID`,`sr`.`PictureReference` AS `PictureReference`,`sr`.`updated` AS `supplyResponseUpdated`,`i`.`group_id` AS `group_id`,`mp`.`name` AS `marketPlace`,`di`.`DeliveryPrice` AS `DeliveryPrice`,`di`.`ChargeAmount` AS `ChargeAmount`,`di`.`MinimumQuantity` AS `MinimumQuantity`,`di`.`MaximumQuantity Integer` AS `MaximumQuantity`,cast(`sr`.`MinimumNumberToOrder` * (case `sr`.`MinimumOrderUnitType` when 1 then 1 when 2 then `sr`.`NumberOfItemsPerCask` / `sr`.`NumberBunchesPerCask` when 3 then `sr`.`NumberOfItemsPerCask` when 4 then floor(128 * 56 / (`b`.`x_size` * `b`.`y_size`)) * `sr`.`NumberOfItemsPerCask` when 5 then floor(128 * 56 / (`b`.`x_size` * `b`.`y_size`)) * `sr`.`NumberOfItemsPerCask` * `sr`.`NumberOfLayersPerTrolley` end) as decimal(10,0)) AS `OrderUnit`,cast(`sr`.`IncrementalOrderableQuantity` * (case `sr`.`IncrementalOrderableQuantityType` when 1 then 1 when 2 then `sr`.`NumberOfItemsPerCask` / `sr`.`NumberBunchesPerCask` when 3 then `sr`.`NumberOfItemsPerCask` when 4 then floor(128 * 56 / (`b`.`x_size` * `b`.`y_size`)) * `sr`.`NumberOfItemsPerCask` when 5 then floor(128 * 56 / (`b`.`x_size` * `b`.`y_size`)) * `sr`.`NumberOfItemsPerCask` * `sr`.`NumberOfLayersPerTrolley` end) as decimal(10,0)) AS `IncrementalOrderUnit`,`mp`.`isEarlyBird` AS `isEarlyBird`,`v`.`isVNHSupplier` AS `isVNHSupplier`,`igo`.`expenseFk` AS `expenseFk`,`igo`.`intrastatFk` AS `intrastatFk`,`igo`.`originFk` AS `originFk`,ifnull(`idt`.`itemTypeFk`,`igo`.`itemTypeFk`) AS `itemTypeFk` from (((((((((`edi`.`deliveryInformation` `di` join `edi`.`supplyResponse` `sr` on(`sr`.`ID` = `di`.`supplyResponseID`)) left join `edi`.`supplier` `s` on(`s`.`glnAddressCode` = `sr`.`SupplierGLN`)) join `edi`.`bucket` `b` on(`b`.`bucket_id` = `sr`.`EmbalageCode`)) join `edi`.`item` `i` on(`i`.`id` = `sr`.`Item_ArticleCode`)) join `edi`.`marketPlace` `mp` on(`mp`.`id` = `sr`.`MarketPlaceID`)) join `vn`.`floramondoConfig` `fm`) left join `edi`.`item_defaultType` `idt` on(`idt`.`item_id` = `i`.`id`)) join `edi`.`VMPSettings` `v` on(`v`.`VMPID` = `sr`.`vmpID`)) join `edi`.`item_groupToOffer` `igo` on(`igo`.`group_code` = `i`.`group_id`)) where `v`.`isBlocked` = 0 and `s`.`isBanned` = 0 and `sr`.`NumberOfUnits` > 0 and current_timestamp() between `di`.`FirstOrderDateTime` and `di`.`LatestOrderDateTime` and `mp`.`isOffered` = 1 and `di`.`LatestDeliveryDateTime` between cast(`fm`.`nextLanded` as date) and concat(cast(`fm`.`nextLanded` as date),' ',`fm`.`MaxLatestDeliveryHour`) group by `sr`.`ID` having `EmbalageCode` <> 999 */; +/*!50001 VIEW `supplyOffer` AS select `sr`.`vmpID` AS `vmpID`,`di`.`ID` AS `diId`,`sr`.`ID` AS `srId`,`sr`.`Item_ArticleCode` AS `Item_ArticleCode`,`sr`.`VBNOmschrijving` AS `product_name`,`s`.`company_name` AS `company_name`,cast(`sr`.`Price` as decimal(10,3)) AS `Price`,`sr`.`Quality` AS `Quality`,`sr`.`s1` AS `s1`,`sr`.`s2` AS `s2`,`sr`.`s3` AS `s3`,`sr`.`s4` AS `s4`,`sr`.`s5` AS `s5`,`sr`.`s6` AS `s6`,`sr`.`NumberOfUnits` AS `NumberOfUnits`,least(if((`sr`.`EmbalageCode` = 800),((`sr`.`EmbalageCode` * 10) + `sr`.`NumberOfItemsPerCask`),`sr`.`EmbalageCode`),ifnull(`idt`.`bucket_id`,'999')) AS `EmbalageCode`,`di`.`LatestDeliveryDateTime` AS `LatestDeliveryDateTime`,`di`.`EarliestDespatchDateTime` AS `EarliestDespatchDateTime`,`di`.`FirstOrderDateTime` AS `FirstOrderDateTime`,`di`.`LatestOrderDateTime` AS `LatestOrderDateTime`,`sr`.`NumberOfItemsPerCask` AS `NumberOfItemsPerCask`,`sr`.`NumberOfLayersPerTrolley` AS `NumberOfLayersPerTrolley`,`sr`.`MinimumNumberToOrder` AS `MinimumNumberToOrder`,`sr`.`MaximumNumberToOrder` AS `MaximumNumberToOrder`,`sr`.`IncrementalOrderableQuantity` AS `IncrementalOrderableQuantity`,`sr`.`PackingPrice` AS `PackingPrice`,`sr`.`MarketPlaceID` AS `MarketPlaceID`,`sr`.`PictureReference` AS `PictureReference`,`sr`.`updated` AS `supplyResponseUpdated`,`i`.`group_id` AS `group_id`,`mp`.`name` AS `marketPlace`,`di`.`DeliveryPrice` AS `DeliveryPrice`,`di`.`ChargeAmount` AS `ChargeAmount`,`di`.`MinimumQuantity` AS `MinimumQuantity`,`di`.`MaximumQuantity Integer` AS `MaximumQuantity`,cast((`sr`.`MinimumNumberToOrder` * (case `sr`.`MinimumOrderUnitType` when 1 then 1 when 2 then (`sr`.`NumberOfItemsPerCask` / `sr`.`NumberBunchesPerCask`) when 3 then `sr`.`NumberOfItemsPerCask` when 4 then (floor(((128 * 56) / (`b`.`x_size` * `b`.`y_size`))) * `sr`.`NumberOfItemsPerCask`) when 5 then ((floor(((128 * 56) / (`b`.`x_size` * `b`.`y_size`))) * `sr`.`NumberOfItemsPerCask`) * `sr`.`NumberOfLayersPerTrolley`) end)) as decimal(10,0)) AS `OrderUnit`,cast((`sr`.`IncrementalOrderableQuantity` * (case `sr`.`IncrementalOrderableQuantityType` when 1 then 1 when 2 then (`sr`.`NumberOfItemsPerCask` / `sr`.`NumberBunchesPerCask`) when 3 then `sr`.`NumberOfItemsPerCask` when 4 then (floor(((128 * 56) / (`b`.`x_size` * `b`.`y_size`))) * `sr`.`NumberOfItemsPerCask`) when 5 then ((floor(((128 * 56) / (`b`.`x_size` * `b`.`y_size`))) * `sr`.`NumberOfItemsPerCask`) * `sr`.`NumberOfLayersPerTrolley`) end)) as decimal(10,0)) AS `IncrementalOrderUnit`,`mp`.`isEarlyBird` AS `isEarlyBird`,`v`.`isVNHSupplier` AS `isVNHSupplier`,`igo`.`expenseFk` AS `expenseFk`,`igo`.`intrastatFk` AS `intrastatFk`,`igo`.`originFk` AS `originFk`,ifnull(`idt`.`itemTypeFk`,`igo`.`itemTypeFk`) AS `itemTypeFk` from (((((((((`edi`.`deliveryInformation` `di` join `edi`.`supplyResponse` `sr` on((`sr`.`ID` = `di`.`supplyResponseID`))) left join `edi`.`supplier` `s` on((`s`.`glnAddressCode` = `sr`.`SupplierGLN`))) join `edi`.`bucket` `b` on((`b`.`bucket_id` = `sr`.`EmbalageCode`))) join `edi`.`item` `i` on((`i`.`id` = `sr`.`Item_ArticleCode`))) join `edi`.`marketPlace` `mp` on((`mp`.`id` = `sr`.`MarketPlaceID`))) join `vn`.`floramondoConfig` `fm`) left join `edi`.`item_defaultType` `idt` on((`idt`.`item_id` = `i`.`id`))) join `edi`.`VMPSettings` `v` on((`v`.`VMPID` = `sr`.`vmpID`))) join `edi`.`item_groupToOffer` `igo` on((`igo`.`group_code` = `i`.`group_id`))) where ((`v`.`isBlocked` = 0) and (`s`.`isBanned` = 0) and (`sr`.`NumberOfUnits` > 0) and (vn.VN_NOW() between `di`.`FirstOrderDateTime` and `di`.`LatestOrderDateTime`) and (`mp`.`isOffered` = 1) and (`di`.`LatestDeliveryDateTime` between cast(`fm`.`nextLanded` as date) and concat(cast(`fm`.`nextLanded` as date),' ',`fm`.`MaxLatestDeliveryHour`))) group by `sr`.`ID` having (`EmbalageCode` <> 999) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94233,7 +78434,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `mainAccountBank` AS select `e`.`name` AS `name`,`a`.`iban` AS `iban` from ((`hedera`.`mainAccount` `c` join `vn`.`supplierAccount` `a` on(`a`.`id` = `c`.`accountFk`)) join `vn`.`bankEntity` `e` on(`e`.`id` = `a`.`bankEntityFk`)) */; +/*!50001 VIEW `mainAccountBank` AS select `e`.`name` AS `name`,`a`.`iban` AS `iban` from ((`hedera`.`mainAccount` `c` join `vn`.`supplierAccount` `a` on((`a`.`id` = `c`.`accountFk`))) join `vn`.`bankEntity` `e` on((`e`.`id` = `a`.`bankEntityFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94252,7 +78453,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myAddress` AS select `t`.`id` AS `id`,`t`.`clientFk` AS `clientFk`,`t`.`street` AS `street`,`t`.`city` AS `city`,`t`.`postalCode` AS `postalCode`,`t`.`provinceFk` AS `provinceFk`,`t`.`nickname` AS `nickname`,`t`.`isDefaultAddress` AS `isDefaultAddress`,`t`.`isActive` AS `isActive`,`t`.`longitude` AS `longitude`,`t`.`latitude` AS `latitude`,`t`.`agencyModeFk` AS `agencyModeFk` from `vn`.`address` `t` where `t`.`clientFk` = `account`.`myUser_getId`() */ +/*!50001 VIEW `myAddress` AS select `t`.`id` AS `id`,`t`.`clientFk` AS `clientFk`,`t`.`street` AS `street`,`t`.`city` AS `city`,`t`.`postalCode` AS `postalCode`,`t`.`provinceFk` AS `provinceFk`,`t`.`nickname` AS `nickname`,`t`.`isDefaultAddress` AS `isDefaultAddress`,`t`.`isActive` AS `isActive`,`t`.`longitude` AS `longitude`,`t`.`latitude` AS `latitude`,`t`.`agencyModeFk` AS `agencyModeFk` from `vn`.`address` `t` where (`t`.`clientFk` = `account`.`myUser_getId`()) */ /*!50002 WITH CASCADED CHECK OPTION */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; @@ -94272,7 +78473,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myBasket` AS select `o`.`id` AS `id`,`o`.`date_make` AS `made`,`o`.`date_send` AS `sent`,`o`.`customer_id` AS `clientFk`,`o`.`delivery_method_id` AS `deliveryMethodFk`,`o`.`agency_id` AS `agencyModeFk`,`o`.`address_id` AS `addressFk`,`o`.`company_id` AS `companyFk`,`o`.`note` AS `notes` from `hedera`.`order` `o` where `o`.`id` = `MYBASKET_GETID`() */ +/*!50001 VIEW `myBasket` AS select `o`.`id` AS `id`,`o`.`date_make` AS `made`,`o`.`date_send` AS `sent`,`o`.`customer_id` AS `clientFk`,`o`.`delivery_method_id` AS `deliveryMethodFk`,`o`.`agency_id` AS `agencyModeFk`,`o`.`address_id` AS `addressFk`,`o`.`company_id` AS `companyFk`,`o`.`note` AS `notes` from `hedera`.`order` `o` where (`o`.`id` = `MYBASKET_GETID`()) */ /*!50002 WITH CASCADED CHECK OPTION */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; @@ -94292,7 +78493,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myBasketDefaults` AS select coalesce(`dm`.`code`,`cm`.`code`) AS `deliveryMethod`,coalesce(`ad`.`agencyModeFk`,`oc`.`defaultAgencyFk`) AS `agencyModeFk`,`c`.`defaultAddressFk` AS `addressFk`,`oc`.`defaultAgencyFk` AS `defaultAgencyFk` from ((((((`hedera`.`orderConfig` `oc` join `vn`.`agencyMode` `ca` on(`ca`.`id` = `oc`.`defaultAgencyFk`)) join `vn`.`deliveryMethod` `cm` on(`cm`.`id` = `ca`.`deliveryMethodFk`)) left join `vn`.`client` `c` on(`c`.`id` = `account`.`myUser_getId`())) left join `vn`.`address` `ad` on(`ad`.`id` = `c`.`defaultAddressFk`)) left join `vn`.`agencyMode` `a` on(`a`.`id` = `ad`.`agencyModeFk`)) left join `vn`.`deliveryMethod` `dm` on(`dm`.`id` = `a`.`deliveryMethodFk`)) */; +/*!50001 VIEW `myBasketDefaults` AS select coalesce(`dm`.`code`,`cm`.`code`) AS `deliveryMethod`,coalesce(`ad`.`agencyModeFk`,`oc`.`defaultAgencyFk`) AS `agencyModeFk`,`c`.`defaultAddressFk` AS `addressFk`,`oc`.`defaultAgencyFk` AS `defaultAgencyFk` from ((((((`hedera`.`orderConfig` `oc` join `vn`.`agencyMode` `ca` on((`ca`.`id` = `oc`.`defaultAgencyFk`))) join `vn`.`deliveryMethod` `cm` on((`cm`.`id` = `ca`.`deliveryMethodFk`))) left join `vn`.`client` `c` on((`c`.`id` = `account`.`myUser_getId`()))) left join `vn`.`address` `ad` on((`ad`.`id` = `c`.`defaultAddressFk`))) left join `vn`.`agencyMode` `a` on((`a`.`id` = `ad`.`agencyModeFk`))) left join `vn`.`deliveryMethod` `dm` on((`dm`.`id` = `a`.`deliveryMethodFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94311,7 +78512,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myBasketItem` AS select `r`.`id` AS `id`,`r`.`orderFk` AS `orderFk`,`r`.`warehouseFk` AS `warehouseFk`,`r`.`itemFk` AS `itemFk`,`r`.`amount` AS `amount`,`r`.`price` AS `price` from `hedera`.`orderRow` `r` where `r`.`orderFk` = `MYBASKET_GETID`() */ +/*!50001 VIEW `myBasketItem` AS select `r`.`id` AS `id`,`r`.`orderFk` AS `orderFk`,`r`.`warehouseFk` AS `warehouseFk`,`r`.`itemFk` AS `itemFk`,`r`.`amount` AS `amount`,`r`.`price` AS `price` from `hedera`.`orderRow` `r` where (`r`.`orderFk` = `MYBASKET_GETID`()) */ /*!50002 WITH CASCADED CHECK OPTION */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; @@ -94331,7 +78532,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myClient` AS select `c`.`id` AS `id`,`c`.`isToBeMailed` AS `isToBeMailed`,`c`.`defaultAddressFk` AS `defaultAddressFk`,`c`.`credit` AS `credit` from `vn`.`client` `c` where `c`.`id` = `account`.`myUser_getId`() */ +/*!50001 VIEW `myClient` AS select `c`.`id` AS `id`,`c`.`isToBeMailed` AS `isToBeMailed`,`c`.`defaultAddressFk` AS `defaultAddressFk`,`c`.`credit` AS `credit` from `vn`.`client` `c` where (`c`.`id` = `account`.`myUser_getId`()) */ /*!50002 WITH CASCADED CHECK OPTION */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; @@ -94351,7 +78552,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myInvoice` AS select `i`.`id` AS `id`,`i`.`ref` AS `ref`,`i`.`issued` AS `issued`,`i`.`amount` AS `amount`,`i`.`hasPdf` AS `hasPdf` from `vn`.`invoiceOut` `i` where `i`.`clientFk` = `account`.`myUser_getId`() */; +/*!50001 VIEW `myInvoice` AS select `i`.`id` AS `id`,`i`.`ref` AS `ref`,`i`.`issued` AS `issued`,`i`.`amount` AS `amount`,`i`.`hasPdf` AS `hasPdf` from `vn`.`invoiceOut` `i` where (`i`.`clientFk` = `account`.`myUser_getId`()) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94370,7 +78571,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myMenu` AS select `t`.`id` AS `id`,`t`.`path` AS `path`,`t`.`description` AS `description`,`t`.`parentFk` AS `parentFk` from (`hedera`.`menu` `t` join `account`.`myRole` `r` on(`r`.`id` = `t`.`roleFk`)) order by `t`.`parentFk`,`t`.`displayOrder`,`t`.`id` */; +/*!50001 VIEW `myMenu` AS select `t`.`id` AS `id`,`t`.`path` AS `path`,`t`.`description` AS `description`,`t`.`parentFk` AS `parentFk` from (`hedera`.`menu` `t` join `account`.`myRole` `r` on((`r`.`id` = `t`.`roleFk`))) order by `t`.`parentFk`,`t`.`displayOrder`,`t`.`id` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94389,7 +78590,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myOrder` AS select `o`.`id` AS `id`,`o`.`date_send` AS `landed`,`o`.`customer_id` AS `clientFk`,`o`.`delivery_method_id` AS `deliveryMethodFk`,`o`.`agency_id` AS `agencyModeFk`,`o`.`address_id` AS `addressFk`,`o`.`company_id` AS `companyFk`,`o`.`note` AS `note`,`o`.`source_app` AS `sourceApp`,`o`.`confirmed` AS `isConfirmed`,`o`.`date_make` AS `created`,`o`.`first_row_stamp` AS `firstRowStamp`,`o`.`confirm_date` AS `confirmed` from `hedera`.`order` `o` where `o`.`customer_id` = `account`.`myUser_getId`() */; +/*!50001 VIEW `myOrder` AS select `o`.`id` AS `id`,`o`.`date_send` AS `landed`,`o`.`customer_id` AS `clientFk`,`o`.`delivery_method_id` AS `deliveryMethodFk`,`o`.`agency_id` AS `agencyModeFk`,`o`.`address_id` AS `addressFk`,`o`.`company_id` AS `companyFk`,`o`.`note` AS `note`,`o`.`source_app` AS `sourceApp`,`o`.`confirmed` AS `isConfirmed`,`o`.`date_make` AS `created`,`o`.`first_row_stamp` AS `firstRowStamp`,`o`.`confirm_date` AS `confirmed` from `hedera`.`order` `o` where (`o`.`customer_id` = `account`.`myUser_getId`()) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94408,7 +78609,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myOrderRow` AS select `orw`.`id` AS `id`,`orw`.`order_id` AS `Fk`,`orw`.`item_id` AS `itemFk`,`orw`.`warehouse_id` AS `warehouseFk`,`orw`.`shipment` AS `shipped`,`orw`.`amount` AS `amount`,`orw`.`price` AS `price`,`orw`.`rate` AS `rate`,`orw`.`created` AS `created`,`orw`.`Id_Movimiento` AS `saleFk` from (`hedera`.`order_row` `orw` join `hedera`.`myOrder` `o` on(`o`.`id` = `orw`.`order_id`)) */ +/*!50001 VIEW `myOrderRow` AS select `orw`.`id` AS `id`,`orw`.`order_id` AS `Fk`,`orw`.`item_id` AS `itemFk`,`orw`.`warehouse_id` AS `warehouseFk`,`orw`.`shipment` AS `shipped`,`orw`.`amount` AS `amount`,`orw`.`price` AS `price`,`orw`.`rate` AS `rate`,`orw`.`created` AS `created`,`orw`.`Id_Movimiento` AS `saleFk` from (`hedera`.`order_row` `orw` join `hedera`.`myOrder` `o` on((`o`.`id` = `orw`.`order_id`))) */ /*!50002 WITH CASCADED CHECK OPTION */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; @@ -94428,7 +78629,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myOrderTicket` AS select `o`.`id` AS `orderFk`,`ot`.`ticketFk` AS `ticketFk` from (`hedera`.`myOrder` `o` join `hedera`.`orderTicket` `ot` on(`ot`.`orderFk` = `o`.`id`)) */; +/*!50001 VIEW `myOrderTicket` AS select `o`.`id` AS `orderFk`,`ot`.`ticketFk` AS `ticketFk` from (`hedera`.`myOrder` `o` join `hedera`.`orderTicket` `ot` on((`ot`.`orderFk` = `o`.`id`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94447,7 +78648,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myTicket` AS select `t`.`id` AS `id`,`t`.`clientFk` AS `clientFk`,`t`.`warehouseFk` AS `warehouseFk`,`t`.`shipped` AS `shipped`,`t`.`landed` AS `landed`,`t`.`nickname` AS `nickname`,`t`.`agencyModeFk` AS `agencyModeFk`,`t`.`refFk` AS `refFk`,`t`.`addressFk` AS `addressFk`,`t`.`location` AS `location`,`t`.`companyFk` AS `companyFk` from `vn`.`ticket` `t` where `t`.`clientFk` = `account`.`myUser_getId`() */; +/*!50001 VIEW `myTicket` AS select `t`.`id` AS `id`,`t`.`clientFk` AS `clientFk`,`t`.`warehouseFk` AS `warehouseFk`,`t`.`shipped` AS `shipped`,`t`.`landed` AS `landed`,`t`.`nickname` AS `nickname`,`t`.`agencyModeFk` AS `agencyModeFk`,`t`.`refFk` AS `refFk`,`t`.`addressFk` AS `addressFk`,`t`.`location` AS `location`,`t`.`companyFk` AS `companyFk` from `vn`.`ticket` `t` where (`t`.`clientFk` = `account`.`myUser_getId`()) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94466,7 +78667,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myTicketRow` AS select `s`.`id` AS `id`,`s`.`itemFk` AS `itemFk`,`s`.`ticketFk` AS `ticketFk`,`s`.`concept` AS `concept`,`s`.`quantity` AS `quantity`,`s`.`price` AS `price`,`s`.`discount` AS `discount`,`s`.`reserved` AS `reserved`,`s`.`isPicked` AS `isPicked` from (`vn`.`sale` `s` join `hedera`.`myTicket` `t` on(`s`.`ticketFk` = `t`.`id`)) */ +/*!50001 VIEW `myTicketRow` AS select `s`.`id` AS `id`,`s`.`itemFk` AS `itemFk`,`s`.`ticketFk` AS `ticketFk`,`s`.`concept` AS `concept`,`s`.`quantity` AS `quantity`,`s`.`price` AS `price`,`s`.`discount` AS `discount`,`s`.`reserved` AS `reserved`,`s`.`isPicked` AS `isPicked` from (`vn`.`sale` `s` join `hedera`.`myTicket` `t` on((`s`.`ticketFk` = `t`.`id`))) */ /*!50002 WITH CASCADED CHECK OPTION */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; @@ -94486,7 +78687,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myTicketService` AS select `s`.`id` AS `id`,`s`.`description` AS `description`,`s`.`quantity` AS `quantity`,`s`.`price` AS `price`,`s`.`taxClassFk` AS `taxClassFk`,`s`.`ticketFk` AS `ticketFk`,`s`.`ticketServiceTypeFk` AS `ticketServiceTypeFk` from (`vn`.`ticketService` `s` join `hedera`.`myTicket` `t` on(`s`.`ticketFk` = `t`.`id`)) */ +/*!50001 VIEW `myTicketService` AS select `s`.`id` AS `id`,`s`.`description` AS `description`,`s`.`quantity` AS `quantity`,`s`.`price` AS `price`,`s`.`taxClassFk` AS `taxClassFk`,`s`.`ticketFk` AS `ticketFk`,`s`.`ticketServiceTypeFk` AS `ticketServiceTypeFk` from (`vn`.`ticketService` `s` join `hedera`.`myTicket` `t` on((`s`.`ticketFk` = `t`.`id`))) */ /*!50002 WITH CASCADED CHECK OPTION */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; @@ -94506,7 +78707,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myTicketState` AS select `t`.`id` AS `id`,`t`.`clientFk` AS `clientFk`,`t`.`warehouseFk` AS `warehouseFk`,`t`.`shipped` AS `shipped`,`t`.`landed` AS `landed`,`t`.`nickname` AS `nickname`,`t`.`agencyModeFk` AS `agencyModeFk`,`t`.`refFk` AS `refFk`,`t`.`addressFk` AS `addressFk`,`t`.`location` AS `location`,`t`.`companyFk` AS `companyFk`,`ts`.`alertLevel` AS `alertLevel`,`ts`.`code` AS `code` from (`vn`.`ticket` `t` left join `vn`.`ticketState` `ts` on(`ts`.`ticketFk` = `t`.`id`)) where `t`.`clientFk` = `account`.`myUser_getId`() */; +/*!50001 VIEW `myTicketState` AS select `t`.`id` AS `id`,`t`.`clientFk` AS `clientFk`,`t`.`warehouseFk` AS `warehouseFk`,`t`.`shipped` AS `shipped`,`t`.`landed` AS `landed`,`t`.`nickname` AS `nickname`,`t`.`agencyModeFk` AS `agencyModeFk`,`t`.`refFk` AS `refFk`,`t`.`addressFk` AS `addressFk`,`t`.`location` AS `location`,`t`.`companyFk` AS `companyFk`,`ts`.`alertLevel` AS `alertLevel`,`ts`.`code` AS `code` from (`vn`.`ticket` `t` left join `vn`.`ticketState` `ts` on((`ts`.`ticketFk` = `t`.`id`))) where (`t`.`clientFk` = `account`.`myUser_getId`()) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94525,7 +78726,7 @@ USE `hedera`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `myTpvTransaction` AS select `t`.`id` AS `id`,`t`.`merchantFk` AS `merchantFk`,`t`.`clientFk` AS `clientFk`,`t`.`receiptFk` AS `receiptFk`,`t`.`amount` AS `amount`,`t`.`response` AS `response`,`t`.`status` AS `status`,`t`.`created` AS `created` from `hedera`.`tpvTransaction` `t` where `t`.`clientFk` = `account`.`myUser_getId`() */; +/*!50001 VIEW `myTpvTransaction` AS select `t`.`id` AS `id`,`t`.`merchantFk` AS `merchantFk`,`t`.`clientFk` AS `clientFk`,`t`.`receiptFk` AS `receiptFk`,`t`.`amount` AS `amount`,`t`.`response` AS `response`,`t`.`status` AS `status`,`t`.`created` AS `created` from `hedera`.`tpvTransaction` `t` where (`t`.`clientFk` = `account`.`myUser_getId`()) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94670,7 +78871,7 @@ USE `pbx`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `queueConf` AS select `q`.`name` AS `name`,`c`.`strategy` AS `strategy`,`c`.`timeout` AS `timeout`,`c`.`retry` AS `retry`,`c`.`weight` AS `weight`,`c`.`maxLen` AS `maxlen`,`c`.`ringInUse` AS `ringinuse` from (`queue` `q` join `queueConfig` `c` on(`q`.`config` = `c`.`id`)) */; +/*!50001 VIEW `queueConf` AS select `q`.`name` AS `name`,`c`.`strategy` AS `strategy`,`c`.`timeout` AS `timeout`,`c`.`retry` AS `retry`,`c`.`weight` AS `weight`,`c`.`maxLen` AS `maxlen`,`c`.`ringInUse` AS `ringinuse` from (`queue` `q` join `queueConfig` `c` on((`q`.`config` = `c`.`id`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94708,7 +78909,7 @@ USE `pbx`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `sipConf` AS select `s`.`user_id` AS `id`,`s`.`extension` AS `name`,NULL AS `callbackextension`,`s`.`md5Secret` AS `md5secret`,`u`.`nickname` AS `callerid`,`c`.`host` AS `host`,`c`.`deny` AS `deny`,`c`.`permit` AS `permit`,`c`.`type` AS `type`,`c`.`context` AS `context`,`c`.`incomingLimit` AS `incominglimit`,`c`.`pickupGroup` AS `pickupgroup`,`c`.`careInvite` AS `careinvite`,`c`.`insecure` AS `insecure`,`c`.`transport` AS `transport`,`c`.`nat` AS `nat`,`r`.`ipAddr` AS `ipaddr`,`r`.`regSeconds` AS `regseconds`,`r`.`port` AS `port`,`r`.`defaultUser` AS `defaultuser`,`r`.`userAgent` AS `useragent`,`r`.`lastMs` AS `lastms`,`r`.`fullContact` AS `fullcontact`,`r`.`regServer` AS `regserver` from (((`pbx`.`sip` `s` join `account`.`user` `u` on(`u`.`id` = `s`.`user_id`)) left join `pbx`.`sipReg` `r` on(`s`.`user_id` = `r`.`userId`)) join `pbx`.`sipConfig` `c`) */; +/*!50001 VIEW `sipConf` AS select `s`.`user_id` AS `id`,`s`.`extension` AS `name`,NULL AS `callbackextension`,`s`.`md5Secret` AS `md5secret`,`u`.`nickname` AS `callerid`,`c`.`host` AS `host`,`c`.`deny` AS `deny`,`c`.`permit` AS `permit`,`c`.`type` AS `type`,`c`.`context` AS `context`,`c`.`incomingLimit` AS `incominglimit`,`c`.`pickupGroup` AS `pickupgroup`,`c`.`careInvite` AS `careinvite`,`c`.`insecure` AS `insecure`,`c`.`transport` AS `transport`,`c`.`nat` AS `nat`,`r`.`ipAddr` AS `ipaddr`,`r`.`regSeconds` AS `regseconds`,`r`.`port` AS `port`,`r`.`defaultUser` AS `defaultuser`,`r`.`userAgent` AS `useragent`,`r`.`lastMs` AS `lastms`,`r`.`fullContact` AS `fullcontact`,`r`.`regServer` AS `regserver` from (((`pbx`.`sip` `s` join `account`.`user` `u` on((`u`.`id` = `s`.`user_id`))) left join `pbx`.`sipReg` `r` on((`s`.`user_id` = `r`.`userId`))) join `pbx`.`sipConfig` `c`) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94752,7 +78953,7 @@ USE `postgresql`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `person` AS select `p`.`id` AS `person_id`,`p`.`surnames` AS `name`,`p`.`nickname` AS `nickname`,`p`.`fi` AS `nif`,`p`.`birth` AS `birth`,`p`.`firstname` AS `firstname`,`p`.`p2` AS `p2`,`p`.`readerId` AS `nis`,`p`.`workerFk` AS `id_trabajador`,`p`.`isDisable` AS `isDisable`,`p`.`isFreelance` AS `isFreelance`,`p`.`isSsDiscounted` AS `isSsDiscounted`,`p`.`sex` AS `sex` from `vn`.`person` `p` */; +/*!50001 VIEW `person` AS select `p`.`id` AS `person_id`,`p`.`surnames` AS `name`,`p`.`nickname` AS `nickname`,`p`.`fi` AS `nif`,`p`.`birth` AS `birth`,`p`.`firstname` AS `firstname`,`p`.`p2` AS `p2`,`p`.`workerFk` AS `id_trabajador`,`p`.`isDisable` AS `isDisable`,`p`.`isFreelance` AS `isFreelance`,`p`.`isSsDiscounted` AS `isSsDiscounted`,`p`.`sex` AS `sex` from `vn`.`person` `p` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94777,7 +78978,7 @@ USE `sage`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `clientLastTwoMonths` AS select `vn`.`invoiceOut`.`clientFk` AS `clientFk`,`vn`.`invoiceOut`.`companyFk` AS `companyFk` from `vn`.`invoiceOut` where `vn`.`invoiceOut`.`issued` > util.VN_CURDATE() - interval 2 month union select `vn`.`receipt`.`clientFk` AS `clientFk`,`vn`.`receipt`.`companyFk` AS `companyFk` from `vn`.`receipt` where `vn`.`receipt`.`payed` > util.VN_CURDATE() - interval 2 month */; +/*!50001 VIEW `clientLastTwoMonths` AS select `vn`.`invoiceOut`.`clientFk` AS `clientFk`,`vn`.`invoiceOut`.`companyFk` AS `companyFk` from `vn`.`invoiceOut` where (`vn`.`invoiceOut`.`issued` > (vn.VN_CURDATE() - interval 2 month)) union select `vn`.`receipt`.`clientFk` AS `clientFk`,`vn`.`receipt`.`companyFk` AS `companyFk` from `vn`.`receipt` where (`vn`.`receipt`.`payed` > (vn.VN_CURDATE() - interval 2 month)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94796,7 +78997,7 @@ USE `sage`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `invoiceInList` AS select `vn`.`invoiceIn`.`id` AS `id`,`vn`.`invoiceIn`.`supplierRef` AS `supplierRef`,`vn`.`invoiceIn`.`serial` AS `serial`,`vn`.`invoiceIn`.`supplierFk` AS `supplierFk`,`vn`.`invoiceIn`.`issued` AS `issued`,if(`vn`.`invoiceIn`.`expenceFkDeductible` > 0,1,0) AS `isVatDeductible`,`vn`.`invoiceIn`.`serialNumber` AS `serialNumber` from `vn`.`invoiceIn` where `vn`.`invoiceIn`.`issued` >= date_format(util.VN_CURDATE(),'%Y-01-01') + interval -1 year union all select `vn`.`dua`.`id` AS `id`,`vn`.`dua`.`code` AS `code`,'D' AS `D`,`c`.`id` AS `supplierFk`,`vn`.`dua`.`issued` AS `issued`,0 AS `FALSE`,`vn`.`dua`.`id` AS `serialNumber` from (`vn`.`dua` join `vn`.`company` `c` on(`c`.`code` = 'VNL')) */; +/*!50001 VIEW `invoiceInList` AS select `vn`.`invoiceIn`.`id` AS `id`,`vn`.`invoiceIn`.`supplierRef` AS `supplierRef`,`vn`.`invoiceIn`.`serial` AS `serial`,`vn`.`invoiceIn`.`supplierFk` AS `supplierFk`,`vn`.`invoiceIn`.`issued` AS `issued`,if((`vn`.`invoiceIn`.`expenceFkDeductible` > 0),1,0) AS `isVatDeductible`,`vn`.`invoiceIn`.`serialNumber` AS `serialNumber` from `vn`.`invoiceIn` where (`vn`.`invoiceIn`.`issued` >= (date_format(vn.VN_CURDATE(),'%Y-01-01') + interval -(1) year)) union all select `vn`.`dua`.`id` AS `id`,`vn`.`dua`.`code` AS `code`,'D' AS `D`,`c`.`id` AS `supplierFk`,`vn`.`dua`.`issued` AS `issued`,0 AS `FALSE`,`vn`.`dua`.`id` AS `serialNumber` from (`vn`.`dua` join `vn`.`company` `c` on((`c`.`code` = 'VNL'))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94815,7 +79016,7 @@ USE `sage`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `providerLastThreeMonths` AS select `vn`.`invoiceIn`.`supplierFk` AS `supplierFk`,`vn`.`invoiceIn`.`companyFk` AS `companyFk` from `vn`.`invoiceIn` where `vn`.`invoiceIn`.`issued` > util.VN_CURDATE() - interval 3 month union select `vn`.`payment`.`supplierFk` AS `supplierFk`,`vn`.`payment`.`companyFk` AS `companyFk` from `vn`.`payment` where `vn`.`payment`.`received` > util.VN_CURDATE() + interval -3 month */; +/*!50001 VIEW `providerLastThreeMonths` AS select `vn`.`invoiceIn`.`supplierFk` AS `supplierFk`,`vn`.`invoiceIn`.`companyFk` AS `companyFk` from `vn`.`invoiceIn` where (`vn`.`invoiceIn`.`issued` > (vn.VN_CURDATE() - interval 3 month)) union select `vn`.`payment`.`supplierFk` AS `supplierFk`,`vn`.`payment`.`companyFk` AS `companyFk` from `vn`.`payment` where (`vn`.`payment`.`received` > (vn.VN_CURDATE() + interval -(3) month)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94878,7 +79079,7 @@ USE `salix`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `RoleMapping` AS select `u`.`id` * 1000 + `r`.`inheritsFrom` AS `id`,'USER' AS `principalType`,`u`.`id` AS `principalId`,`r`.`inheritsFrom` AS `roleId` from (`account`.`user` `u` join `account`.`roleRole` `r` on(`r`.`role` = `u`.`role`)) */; +/*!50001 VIEW `RoleMapping` AS select ((`u`.`id` * 1000) + `r`.`inheritsFrom`) AS `id`,'USER' AS `principalType`,`u`.`id` AS `principalId`,`r`.`inheritsFrom` AS `roleId` from (`account`.`user` `u` join `account`.`roleRole` `r` on((`r`.`role` = `u`.`role`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -94934,17 +79135,17 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `NewView` AS select `c`.`id` AS `clientFk`,max(`t`.`shipped`) AS `lastShipped`,`pc`.`notBuyingMonths` AS `notBuyingMonths` from ((`client` `c` join `productionConfig` `pc`) left join `ticket` `t` on(`c`.`id` = `t`.`clientFk` and `t`.`shipped` < util.VN_CURDATE() + interval (-`pc`.`rookieDays`) day)) group by `c`.`id` having `lastShipped` is null or `lastShipped` < util.VN_CURDATE() + interval (-`notBuyingMonths`) month */; +/*!50001 VIEW `NewView` AS select `c`.`id` AS `clientFk`,max(`t`.`shipped`) AS `lastShipped`,`pc`.`notBuyingMonths` AS `notBuyingMonths` from ((`client` `c` join `productionConfig` `pc`) left join `ticket` `t` on(((`c`.`id` = `t`.`clientFk`) and (`t`.`shipped` < (vn.VN_CURDATE() + interval -(`pc`.`rookieDays`) day))))) group by `c`.`id` having (isnull(`lastShipped`) or (`lastShipped` < (vn.VN_CURDATE() + interval -(`notBuyingMonths`) month))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; -- --- Final view structure for view `absenceType` +-- Final view structure for view `__coolerPathDetail` -- -/*!50001 DROP TABLE IF EXISTS `absenceType`*/; -/*!50001 DROP VIEW IF EXISTS `absenceType`*/; +/*!50001 DROP TABLE IF EXISTS `__coolerPathDetail`*/; +/*!50001 DROP VIEW IF EXISTS `__coolerPathDetail`*/; /*!50001 SET @saved_cs_client = @@character_set_client */; /*!50001 SET @saved_cs_results = @@character_set_results */; /*!50001 SET @saved_col_connection = @@collation_connection */; @@ -94953,26 +79154,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `absenceType` AS select `cs`.`calendar_state_id` AS `id`,`cs`.`type` AS `name`,`cs`.`rgb` AS `rgb`,`cs`.`code` AS `code`,`cs`.`permissionRate` AS `permissionRate`,`cs`.`holidayEntitlementRate` AS `holidayEntitlementRate`,`cs`.`discountRate` AS `discountRate` from `postgresql`.`calendar_state` `cs` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `agencyTerm` --- - -/*!50001 DROP TABLE IF EXISTS `agencyTerm`*/; -/*!50001 DROP VIEW IF EXISTS `agencyTerm`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 SET character_set_results = utf8 */; -/*!50001 SET collation_connection = utf8_general_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `agencyTerm` AS select `sat`.`agencyFk` AS `agencyFk`,`sat`.`minimumPackages` AS `minimumPackages`,`sat`.`kmPrice` AS `kmPrice`,`sat`.`packagePrice` AS `packagePrice`,`sat`.`routePrice` AS `routePrice`,`sat`.`minimumKm` AS `minimumKm`,`sat`.`minimumM3` AS `minimumM3`,`sat`.`m3Price` AS `m3Price` from `supplierAgencyTerm` `sat` */; +/*!50001 VIEW `__coolerPathDetail` AS select `c`.`cooler_path_detail_id` AS `id`,`c`.`cooler_path_id` AS `coolerPathFk`,`c`.`pasillo` AS `hallway` from `vn2008`.`cooler_path_detail` `c` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95015,6 +79197,25 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `awbVolume` +-- + +/*!50001 DROP TABLE IF EXISTS `awbVolume`*/; +/*!50001 DROP VIEW IF EXISTS `awbVolume`*/; +/*!50001 SET @saved_cs_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_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `awbVolume` AS select `d`.`awbFk` AS `awbFk`,(((`b`.`stickers` * `i`.`density`) * if((`p`.`volume` > 0),`p`.`volume`,((`p`.`width` * `p`.`depth`) * if((`p`.`height` = 0),(`i`.`size` + 10),`p`.`height`)))) / 167000) AS `volume`,`b`.`id` AS `buyFk` from (((((((`buy` `b` join `item` `i` on((`b`.`itemFk` = `i`.`id`))) join `itemType` `it` on((`i`.`typeFk` = `it`.`id`))) join `packaging` `p` on((`p`.`id` = `b`.`packageFk`))) join `entry` `e` on((`b`.`entryFk` = `e`.`id`))) join `travel` `t` on((`t`.`id` = `e`.`travelFk`))) join `duaEntry` `de` on((`de`.`entryFk` = `e`.`id`))) join `dua` `d` on((`d`.`id` = `de`.`duaFk`))) where (`t`.`shipped` > makedate((year(vn.VN_CURDATE()) - 1),1)) */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `bank` -- @@ -95034,6 +79235,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_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` 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` -- @@ -95067,7 +79287,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `buyer` AS select distinct `u`.`id` AS `userFk`,`u`.`nickname` AS `nickname` from (`account`.`user` `u` join `vn`.`itemType` `it` on(`it`.`workerFk` = `u`.`id`)) where `u`.`active` <> 0 order by `u`.`nickname` */; +/*!50001 VIEW `buyer` AS select distinct `u`.`id` AS `userFk`,`u`.`nickname` AS `nickname` from (`account`.`user` `u` join `vn`.`itemType` `it` on((`it`.`workerFk` = `u`.`id`))) where `u`.`active` order by `u`.`nickname` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95086,26 +79306,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `buyerSales` AS select `v`.`importe` AS `importe`,`w`.`code` AS `comprador`,`t`.`year` AS `año`,`t`.`week` AS `semana` from (((`bs`.`ventas` `v` join `vn`.`time` `t` on(`t`.`dated` = `v`.`fecha`)) join `vn`.`itemType` `it` on(`it`.`id` = `v`.`tipo_id`)) join `vn`.`worker` `w` on(`w`.`id` = `it`.`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 `calendar__` --- - -/*!50001 DROP TABLE IF EXISTS `calendar__`*/; -/*!50001 DROP VIEW IF EXISTS `calendar__`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `calendar__` AS select `ce`.`id` AS `id`,`ce`.`business_id` AS `businessFk`,`ce`.`calendar_state_id` AS `dayOffTypeFk`,`ce`.`date` AS `dated` from `postgresql`.`calendar_employee` `ce` */; +/*!50001 VIEW `buyerSales` AS select `v`.`importe` AS `importe`,`w`.`code` AS `comprador`,`t`.`year` AS `año`,`t`.`week` AS `semana` from (((`bs`.`ventas` `v` join `vn`.`time` `t` on((`t`.`dated` = `v`.`fecha`))) join `vn`.`itemType` `it` on((`it`.`id` = `v`.`tipo_id`))) join `vn`.`worker` `w` on((`w`.`id` = `it`.`workerFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95124,26 +79325,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `clientLost` AS select `c`.`id` AS `clientFk`,max(`t`.`shipped`) AS `lastShipped`,`pc`.`notBuyingMonths` AS `notBuyingMonths` from ((`client` `c` join `productionConfig` `pc`) left join `ticket` `t` on(`c`.`id` = `t`.`clientFk` and `t`.`shipped` < util.VN_CURDATE() + interval (-`pc`.`rookieDays`) day)) group by `c`.`id` having `lastShipped` is null or `lastShipped` < util.VN_CURDATE() + interval (-`notBuyingMonths`) month */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `clientManaCache__` --- - -/*!50001 DROP TABLE IF EXISTS `clientManaCache__`*/; -/*!50001 DROP VIEW IF EXISTS `clientManaCache__`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `clientManaCache__` AS select `mc`.`Id_Cliente` AS `clientFk`,`mc`.`Mana` AS `mana`,`mc`.`dated` AS `dated` from `bs`.`manaCustomer` `mc` */; +/*!50001 VIEW `clientLost` AS select `c`.`id` AS `clientFk`,max(`t`.`shipped`) AS `lastShipped`,`pc`.`notBuyingMonths` AS `notBuyingMonths` from ((`client` `c` join `productionConfig` `pc`) left join `ticket` `t` on(((`c`.`id` = `t`.`clientFk`) and (`t`.`shipped` < (vn.VN_CURDATE() + interval -(`pc`.`rookieDays`) day))))) group by `c`.`id` having (isnull(`lastShipped`) or (`lastShipped` < (vn.VN_CURDATE() + interval -(`notBuyingMonths`) month))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95162,7 +79344,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `clientPhoneBook` AS select `c`.`id` AS `clientFk`,trim(`c`.`phone`) AS `phone` from `client` `c` where `c`.`phone` <> 0 and `c`.`isActive` <> 0 union select `c`.`id` AS `clientFk`,trim(`c`.`mobile`) AS `phone` from `client` `c` where `c`.`mobile` <> 0 and `c`.`isActive` <> 0 union select `a`.`clientFk` AS `clientFk`,trim(`a`.`phone`) AS `phone` from (`address` `a` join `client` `c` on(`c`.`id` = `a`.`clientFk`)) where `a`.`phone` <> 0 and `c`.`isActive` <> 0 union select `a`.`clientFk` AS `clientFk`,trim(`a`.`mobile`) AS `phone` from (`address` `a` join `client` `c` on(`c`.`id` = `a`.`clientFk`)) where `a`.`mobile` <> 0 and `c`.`isActive` <> 0 union select `cc`.`clientFk` AS `clientFk`,trim(`cc`.`phone`) AS `phone` from (`clientContact` `cc` left join `client` `c` on(`c`.`id` = `cc`.`clientFk`)) where `c`.`phone` <> 0 and `c`.`isActive` <> 0 */; +/*!50001 VIEW `clientPhoneBook` AS select `c`.`id` AS `clientFk`,trim(`c`.`phone`) AS `phone` from `client` `c` where (`c`.`phone` and `c`.`isActive`) union select `c`.`id` AS `clientFk`,trim(`c`.`mobile`) AS `phone` from `client` `c` where (`c`.`mobile` and `c`.`isActive`) union select `a`.`clientFk` AS `clientFk`,trim(`a`.`phone`) AS `phone` from (`address` `a` join `client` `c` on((`c`.`id` = `a`.`clientFk`))) where (`a`.`phone` and `c`.`isActive`) union select `a`.`clientFk` AS `clientFk`,trim(`a`.`mobile`) AS `phone` from (`address` `a` join `client` `c` on((`c`.`id` = `a`.`clientFk`))) where (`a`.`mobile` and `c`.`isActive`) union select `cc`.`clientFk` AS `clientFk`,trim(`cc`.`phone`) AS `phone` from (`clientContact` `cc` left join `client` `c` on((`c`.`id` = `cc`.`clientFk`))) where (`c`.`phone` and `c`.`isActive`) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95181,26 +79363,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` 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`,`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 */; - --- --- Final view structure for view `collectionReportSource` --- - -/*!50001 DROP TABLE IF EXISTS `collectionReportSource`*/; -/*!50001 DROP VIEW IF EXISTS `collectionReportSource`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `collectionReportSource` AS select `tc`.`collectionFk` AS `collectionFk`,`tc`.`ticketFk` AS `ticketFk`,`s`.`itemFk` AS `itemFk`,`s`.`concept` AS `concept`,`i`.`size` AS `size`,`s`.`quantity` AS `quantity`,`ip`.`code` AS `nicho`,`tc`.`level` AS `level` from (((((`collection` `c` join `ticketCollection` `tc` on(`tc`.`collectionFk` = `c`.`id`)) join `ticket` `t` on(`t`.`id` = `tc`.`ticketFk`)) join `sale` `s` on(`s`.`ticketFk` = `t`.`id`)) join `item` `i` on(`i`.`id` = `s`.`itemFk`)) left join `itemPlacement` `ip` on(`ip`.`itemFk` = `s`.`itemFk` and `ip`.`warehouseFk` = `t`.`warehouseFk`)) */; +/*!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 */; @@ -95219,7 +79382,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `collectionSmartTag` 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` from (((((`ticketCollection` `tc` join `smartTag` `st` on(`st`.`code` = `tc`.`smartTagFk` collate utf8_general_ci)) join `ticket` `t` on(`t`.`id` = `tc`.`ticketFk`)) join `collection` `c` on(`c`.`id` = `tc`.`collectionFk`)) join `worker` `w` on(`w`.`id` = `c`.`workerFk`)) join `agencyMode` `am` on(`am`.`id` = `t`.`agencyModeFk`)) */; +/*!50001 VIEW `collectionSmartTag` 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` from (((((`ticketCollection` `tc` join `smartTag` `st` on((`st`.`code` = (`tc`.`smartTagFk` collate utf8_general_ci)))) join `ticket` `t` on((`t`.`id` = `tc`.`ticketFk`))) join `collection` `c` on((`c`.`id` = `tc`.`collectionFk`))) join `worker` `w` on((`w`.`id` = `c`.`workerFk`))) join `agencyMode` `am` on((`am`.`id` = `t`.`agencyModeFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95238,7 +79401,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` 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 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 */; @@ -95276,7 +79439,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `departmentTree` AS select `node`.`id` AS `id`,concat(convert(repeat(repeat(' ',5),count(`parent`.`id`) - 1) using utf8),`node`.`name`) AS `dep` from (`department` `node` join `department` `parent`) where `node`.`lft` between `parent`.`lft` and `parent`.`rgt` group by `node`.`id` order by `node`.`lft` */; +/*!50001 VIEW `departmentTree` AS select `node`.`id` AS `id`,concat(convert(repeat(repeat(' ',5),(count(`parent`.`id`) - 1)) using utf8),`node`.`name`) AS `dep` from (`department` `node` join `department` `parent`) where (`node`.`lft` between `parent`.`lft` and `parent`.`rgt`) group by `node`.`id` order by `node`.`lft` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95333,7 +79496,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `ektSubAddress` AS select `eea`.`sub` AS `sub`,`a`.`clientFk` AS `clientFk`,`a`.`nickname` AS `nickname`,`eea`.`addressFk` AS `addressFk` from (`ektEntryAssign` `eea` join `address` `a` on(`a`.`id` = `eea`.`addressFk`)) group by `eea`.`sub` */; +/*!50001 VIEW `ektSubAddress` AS select `eea`.`sub` AS `sub`,`a`.`clientFk` AS `clientFk`,`a`.`nickname` AS `nickname`,`eea`.`addressFk` AS `addressFk` from (`ektEntryAssign` `eea` join `address` `a` on((`a`.`id` = `eea`.`addressFk`))) group by `eea`.`sub` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95352,7 +79515,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `entryList` AS select `e`.`id` AS `entryFk`,if(`tr`.`isReceived`,' x','') AS `isHere`,`tr`.`landed` AS `landed`,ifnull(`s`.`nickname`,`s`.`name`) AS `supplier`,`e`.`ref` AS `entryRef`,`a`.`name` AS `agency`,`tr`.`ref` AS `travelRef`,`tr`.`appointment` AS `appointment`,`e`.`supplierFk` AS `supplierFk`,`tr`.`warehouseInFk` AS `warehouseInFk` from (((`entry` `e` join `travel` `tr` on(`tr`.`id` = `e`.`travelFk`)) join `supplier` `s` on(`s`.`id` = `e`.`supplierFk`)) left join `agency` `a` on(`tr`.`agencyFk` = `a`.`id`)) where `tr`.`landed` between util.VN_CURDATE() + interval -1 week and util.VN_CURDATE() + interval 3 month order by `tr`.`landed` < util.VN_CURDATE() + interval 2 day desc,`tr`.`landed` desc,ifnull(`s`.`nickname`,`s`.`name`),`e`.`id` desc */; +/*!50001 VIEW `entryList` AS select `e`.`id` AS `entryFk`,if(`tr`.`isReceived`,' x','') AS `isHere`,`tr`.`landed` AS `landed`,ifnull(`s`.`nickname`,`s`.`name`) AS `supplier`,`e`.`ref` AS `entryRef`,`a`.`name` AS `agency`,`tr`.`ref` AS `travelRef`,`tr`.`appointment` AS `appointment`,`e`.`supplierFk` AS `supplierFk`,`tr`.`warehouseInFk` AS `warehouseInFk` from (((`entry` `e` join `travel` `tr` on((`tr`.`id` = `e`.`travelFk`))) join `supplier` `s` on((`s`.`id` = `e`.`supplierFk`))) left join `agency` `a` on((`tr`.`agencyFk` = `a`.`id`))) where (`tr`.`landed` between (vn.VN_CURDATE() + interval -(1) week) and (vn.VN_CURDATE() + interval 3 month)) order by (`tr`.`landed` < (vn.VN_CURDATE() + interval 2 day)) desc,`tr`.`landed` desc,ifnull(`s`.`nickname`,`s`.`name`),`e`.`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 */; @@ -95371,7 +79534,26 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `exchangeInsuranceEntry` AS select max(`tr`.`landed`) AS `dated`,cast(sum((`b`.`buyingValue` + `b`.`freightValue`) * `b`.`quantity`) as decimal(10,2)) AS `Dolares`,cast(sum((`b`.`buyingValue` + `b`.`freightValue`) * `b`.`quantity`) / sum((100 + `e`.`commission`) / 100 * (`b`.`buyingValue` + `b`.`freightValue`) * `b`.`quantity`) as decimal(10,4)) AS `rate` from ((`entry` `e` join `buy` `b` on(`e`.`id` = `b`.`entryFk`)) join `travel` `tr` on(`tr`.`id` = `e`.`travelFk`)) where `tr`.`landed` between '2016-01-31' and util.VN_CURDATE() and `e`.`commission` < 0 and `e`.`currencyFk` = 2 group by month(`tr`.`landed`),year(`tr`.`landed`) */; +/*!50001 VIEW `exchangeInsuranceEntry` AS select max(`tr`.`landed`) AS `dated`,cast(sum(((`b`.`buyingValue` + `b`.`freightValue`) * `b`.`quantity`)) as decimal(10,2)) AS `Dolares`,cast((sum(((`b`.`buyingValue` + `b`.`freightValue`) * `b`.`quantity`)) / sum(((((100 + `e`.`commission`) / 100) * (`b`.`buyingValue` + `b`.`freightValue`)) * `b`.`quantity`))) as decimal(10,4)) AS `rate` from ((`entry` `e` join `buy` `b` on((`e`.`id` = `b`.`entryFk`))) join `travel` `tr` on((`tr`.`id` = `e`.`travelFk`))) where ((`tr`.`landed` between '2016-01-31' and vn.VN_CURDATE()) and (`e`.`commission` < 0) and (`e`.`currencyFk` = 2)) group by month(`tr`.`landed`),year(`tr`.`landed`) */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `exchangeInsuranceIn` +-- + +/*!50001 DROP TABLE IF EXISTS `exchangeInsuranceIn`*/; +/*!50001 DROP VIEW IF EXISTS `exchangeInsuranceIn`*/; +/*!50001 SET @saved_cs_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_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `exchangeInsuranceIn` AS select `exchangeInsuranceInPrevious`.`dated` AS `dated`,sum(`exchangeInsuranceInPrevious`.`amount`) AS `amount`,cast((sum((`exchangeInsuranceInPrevious`.`amount` * `exchangeInsuranceInPrevious`.`rate`)) / sum(`exchangeInsuranceInPrevious`.`amount`)) as decimal(10,4)) AS `rate` from `vn`.`exchangeInsuranceInPrevious` group by `exchangeInsuranceInPrevious`.`dated` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95390,7 +79572,26 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` 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`)) 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 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 */; + +-- +-- Final view structure for view `exchangeReportSourcePrevious` +-- + +/*!50001 DROP TABLE IF EXISTS `exchangeReportSourcePrevious`*/; +/*!50001 DROP VIEW IF EXISTS `exchangeReportSourcePrevious`*/; +/*!50001 SET @saved_cs_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_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `exchangeReportSourcePrevious` AS select `exchangeInsuranceIn`.`dated` AS `dated`,`exchangeInsuranceIn`.`amount` AS `amountIn`,`exchangeInsuranceIn`.`rate` AS `rateIn`,0.00 AS `amountOut`,0.00 AS `rateOut`,0.00 AS `amountEntry`,0.00 AS `rateEntry` from `vn`.`exchangeInsuranceIn` union all select `exchangeInsuranceOut`.`received` AS `received`,0.00 AS `amountIn`,0.00 AS `ratedIn`,`exchangeInsuranceOut`.`divisa` AS `amountOut`,`exchangeInsuranceOut`.`rate` AS `ratedOut`,0.00 AS `amountEntry`,0.00 AS `rateEntry` from `vn`.`exchangeInsuranceOut` union all select `exchangeInsuranceEntry`.`dated` AS `dated`,0.00 AS `amountIn`,0.00 AS `ratedIn`,0.00 AS `amountOut`,0.00 AS `ratedOut`,`exchangeInsuranceEntry`.`Dolares` AS `amountEntry`,`exchangeInsuranceEntry`.`rate` AS `rateEntry` from `vn`.`exchangeInsuranceEntry` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95409,7 +79610,26 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionCommon` AS select `et`.`id` AS `truckFk`,`et`.`ETD` AS `etd`,ifnull(ucase(`et`.`description`),'SIN ESCANEAR') AS `description`,`es`.`palletFk` AS `palletFk`,`t`.`routeFk` AS `routeFk`,`es`.`id` AS `scanFk`,`e`.`id` AS `expeditionFk`,`r`.`expeditionTruckFk` AS `expeditionTruckFk`,`t`.`warehouseFk` AS `warehouseFk`,`e`.`created` AS `lastPacked`,`t`.`id` AS `ticketFk` from (((((`expeditionTruck` `et` left join `routesMonitor` `r` on(`et`.`id` = `r`.`expeditionTruckFk`)) left join `ticket` `t` on(`r`.`routeFk` = `t`.`routeFk`)) left join `expedition` `e` on(`t`.`id` = `e`.`ticketFk`)) left join `expeditionScan` `es` on(`e`.`id` = `es`.`expeditionFk`)) left join `expeditionPallet` `ep` on(`es`.`palletFk` = `ep`.`id`)) where `et`.`ETD` >= util.VN_CURDATE() */; +/*!50001 VIEW `expeditionCommon` AS select `et`.`id` AS `truckFk`,`et`.`ETD` AS `etd`,ifnull(ucase(`et`.`description`),'SIN ESCANEAR') AS `description`,`es`.`palletFk` AS `palletFk`,`t`.`routeFk` AS `routeFk`,`es`.`id` AS `scanFk`,`e`.`id` AS `expeditionFk`,`r`.`expeditionTruckFk` AS `expeditionTruckFk`,`t`.`warehouseFk` AS `warehouseFk`,`e`.`created` AS `lastPacked`,`t`.`id` AS `ticketFk` from (((((`expeditionTruck` `et` left join `routesMonitor` `r` on((`et`.`id` = `r`.`expeditionTruckFk`))) left join `ticket` `t` on((`r`.`routeFk` = `t`.`routeFk`))) left join `expedition` `e` on((`t`.`id` = `e`.`ticketFk`))) left join `expeditionScan` `es` on((`e`.`id` = `es`.`expeditionFk`))) left join `expeditionPallet` `ep` on((`es`.`palletFk` = `ep`.`id`))) where (`et`.`ETD` >= vn.VN_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 `expeditionPallet_Print` +-- + +/*!50001 DROP TABLE IF EXISTS `expeditionPallet_Print`*/; +/*!50001 DROP VIEW IF EXISTS `expeditionPallet_Print`*/; +/*!50001 SET @saved_cs_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_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `expeditionPallet_Print` AS select `et2`.`description` AS `truck`,`t`.`routeFk` AS `routeFk`,`r`.`description` AS `zone`,count(`es`.`id`) AS `eti`,`ep`.`id` AS `palletFk`,(`et`.`id` <=> `rm`.`expeditionTruckFk`) AS `isMatch`,`t`.`warehouseFk` AS `warehouseFk`,if((`r`.`created` > (vn.VN_CURDATE() + interval 1 day)),ucase(dayname(`r`.`created`)),NULL) AS `nombreDia` from (((((((`vn`.`expeditionTruck` `et` join `vn`.`expeditionPallet` `ep` on((`ep`.`truckFk` = `et`.`id`))) join `vn`.`expeditionScan` `es` on((`es`.`palletFk` = `ep`.`id`))) join `vn`.`expedition` `e` on((`e`.`id` = `es`.`expeditionFk`))) join `vn`.`ticket` `t` on((`t`.`id` = `e`.`ticketFk`))) join `vn`.`route` `r` on((`r`.`id` = `t`.`routeFk`))) left join `vn2008`.`Rutas_monitor` `rm` on((`rm`.`Id_Ruta` = `r`.`id`))) left join `vn`.`expeditionTruck` `et2` on((`et2`.`id` = `rm`.`expeditionTruckFk`))) where (`ep`.`isPrint` = 0) group by `ep`.`id`,`t`.`routeFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95428,7 +79648,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionRoute_Monitor` AS select `r`.`id` AS `routeFk`,count(distinct if(`e`.`id` is null,`t`.`id`,NULL)) AS `tickets`,count(distinct `e`.`id`) AS `expeditions`,count(distinct `es`.`id`) AS `scanned`,max(`e`.`created`) AS `lastPacked`,`r`.`created` AS `created` from ((((((`route` `r` left join `routesMonitor` `rm` on(`r`.`id` = `rm`.`routeFk`)) left join `expeditionTruck` `et` on(`et`.`id` = `rm`.`expeditionTruckFk`)) join `ticket` `t` on(`t`.`routeFk` = `r`.`id`)) left join `expedition` `e` on(`e`.`ticketFk` = `t`.`id`)) left join `expeditionScan` `es` on(`es`.`expeditionFk` = `e`.`id`)) left join `stowaway` `st` on(`st`.`id` = `t`.`id`)) where `r`.`created` >= `util`.`yesterday`() and `st`.`id` is null group by `r`.`id` */; +/*!50001 VIEW `expeditionRoute_Monitor` AS select `r`.`id` AS `routeFk`,count(distinct if(isnull(`e`.`id`),`t`.`id`,NULL)) AS `tickets`,count(distinct `e`.`id`) AS `expeditions`,count(distinct `es`.`id`) AS `scanned`,max(`e`.`created`) AS `lastPacked`,`r`.`created` AS `created` from ((((((`route` `r` left join `routesMonitor` `rm` on((`r`.`id` = `rm`.`routeFk`))) left join `expeditionTruck` `et` on((`et`.`id` = `rm`.`expeditionTruckFk`))) join `ticket` `t` on((`t`.`routeFk` = `r`.`id`))) left join `expedition` `e` on((`e`.`ticketFk` = `t`.`id`))) left join `expeditionScan` `es` on((`es`.`expeditionFk` = `e`.`id`))) left join `stowaway` `st` on((`st`.`id` = `t`.`id`))) where ((`r`.`created` >= `util`.`yesterday`()) and isnull(`st`.`id`)) group by `r`.`id` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95447,7 +79667,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionRoute_freeTickets` AS select `t`.`routeFk` AS `routeFk`,`tss`.`ticket` AS `ticket`,`s`.`name` AS `code`,`w`.`name` AS `almacen`,`tss`.`updated` AS `updated`,`p`.`code` AS `parkingCode` from ((((((`vn`.`ticketState` `tss` join `vn`.`ticket` `t` on(`t`.`id` = `tss`.`ticket`)) join `vn`.`warehouse` `w` on(`w`.`id` = `t`.`warehouseFk`)) join `vn`.`state` `s` on(`s`.`id` = `tss`.`state`)) left join `vn`.`stowaway` `st` on(`st`.`id` = `t`.`id`)) left join `vn`.`ticketParking` `tp` on(`tp`.`ticketFk` = `t`.`id`)) left join `vn`.`parking` `p` on(`p`.`id` = `tp`.`parkingFk`)) where ifnull(`t`.`packages`,0) = 0 and `st`.`id` is null */; +/*!50001 VIEW `expeditionRoute_freeTickets` AS select `t`.`routeFk` AS `routeFk`,`tss`.`ticket` AS `ticket`,`s`.`name` AS `code`,`w`.`name` AS `almacen`,`tss`.`updated` AS `updated`,`p`.`code` AS `parkingCode` from ((((((`vn`.`ticketState` `tss` join `vn`.`ticket` `t` on((`t`.`id` = `tss`.`ticket`))) join `vn`.`warehouse` `w` on((`w`.`id` = `t`.`warehouseFk`))) join `vn`.`state` `s` on((`s`.`id` = `tss`.`state`))) left join `vn`.`stowaway` `st` on((`st`.`id` = `t`.`id`))) left join `vn`.`ticketParking` `tp` on((`tp`.`ticketFk` = `t`.`id`))) left join `vn`.`parking` `p` on((`p`.`id` = `tp`.`parkingFk`))) where ((ifnull(`t`.`packages`,0) = 0) and isnull(`st`.`id`)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95466,7 +79686,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionScan_Monitor` AS select `et`.`id` AS `truckFk`,`et`.`ETD` AS `ETD`,`et`.`description` AS `description`,`ep`.`id` AS `palletFk`,`ep`.`position` AS `position`,`ep`.`built` AS `built`,`es`.`id` AS `scanFk`,`es`.`expeditionFk` AS `expeditionFk`,`es`.`scanned` AS `scanned` from ((`expeditionTruck` `et` left join `expeditionPallet` `ep` on(`ep`.`truckFk` = `et`.`id`)) left join `expeditionScan` `es` on(`es`.`palletFk` = `ep`.`id`)) */; +/*!50001 VIEW `expeditionScan_Monitor` AS select `et`.`id` AS `truckFk`,`et`.`ETD` AS `ETD`,`et`.`description` AS `description`,`ep`.`id` AS `palletFk`,`ep`.`position` AS `position`,`ep`.`built` AS `built`,`es`.`id` AS `scanFk`,`es`.`expeditionFk` AS `expeditionFk`,`es`.`scanned` AS `scanned` from ((`expeditionTruck` `et` left join `expeditionPallet` `ep` on((`ep`.`truckFk` = `et`.`id`))) left join `expeditionScan` `es` on((`es`.`palletFk` = `ep`.`id`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95485,26 +79705,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` 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`,3) 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`,`w`.`code` AS `workerCode` 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`)) join `worker` `w` on(`w`.`id` = `e`.`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 `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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` 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 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`,3) 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`,`w`.`code` AS `workerCode` 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`.`code` = `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`))) join `worker` `w` on((`w`.`id` = `e`.`workerFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95523,7 +79724,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionTicket_NoBoxes` AS select `t`.`id` AS `ticketFk`,`t`.`warehouseFk` AS `warehouseFk`,`t`.`routeFk` AS `routeFk`,`et`.`description` AS `description` from (((`ticket` `t` left join `expedition` `e` on(`e`.`ticketFk` = `t`.`id`)) join `routesMonitor` `rm` on(`rm`.`routeFk` = `t`.`routeFk`)) join `expeditionTruck` `et` on(`et`.`id` = `rm`.`expeditionTruckFk`)) where `e`.`id` is null and `et`.`ETD` > util.VN_CURDATE() */; +/*!50001 VIEW `expeditionTicket_NoBoxes` AS select `t`.`id` AS `ticketFk`,`t`.`warehouseFk` AS `warehouseFk`,`t`.`routeFk` AS `routeFk`,`et`.`description` AS `description` from (((`ticket` `t` left join `expedition` `e` on((`e`.`ticketFk` = `t`.`id`))) join `routesMonitor` `rm` on((`rm`.`routeFk` = `t`.`routeFk`))) join `expeditionTruck` `et` on((`et`.`id` = `rm`.`expeditionTruckFk`))) where (isnull(`e`.`id`) and (`et`.`ETD` > vn.VN_CURDATE())) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95542,7 +79743,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionTimeExpended` AS select `e`.`ticketFk` AS `ticketFk`,min(`e`.`created`) AS `started`,max(`e`.`created`) AS `finished`,max(`e`.`counter`) AS `cajas`,`w`.`code` AS `code`,`t`.`warehouseFk` AS `warehouseFk` from ((`expedition` `e` join `worker` `w` on(`w`.`id` = `e`.`workerFk`)) join `ticket` `t` on(`t`.`id` = `e`.`ticketFk`)) where `e`.`created` > util.VN_CURDATE() group by `e`.`ticketFk` */; +/*!50001 VIEW `expeditionTimeExpended` AS select `e`.`ticketFk` AS `ticketFk`,min(`e`.`created`) AS `started`,max(`e`.`created`) AS `finished`,max(`e`.`counter`) AS `cajas`,`w`.`code` AS `code`,`t`.`warehouseFk` AS `warehouseFk` from ((`expedition` `e` join `worker` `w` on((`w`.`id` = `e`.`workerFk`))) join `ticket` `t` on((`t`.`id` = `e`.`ticketFk`))) where (`e`.`created` > vn.VN_CURDATE()) group by `e`.`ticketFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95561,7 +79762,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionTruck_Control` AS select `e`.`truckFk` AS `id`,`e`.`etd` AS `ETD`,`e`.`description` AS `description`,count(distinct if(`e`.`expeditionFk` is null,`e`.`ticketFk`,NULL)) AS `ticketsSinBultos`,count(distinct `e`.`palletFk`) AS `pallets`,count(distinct `e`.`routeFk`) AS `routes`,count(distinct `e`.`scanFk`) AS `scans`,count(distinct `e`.`expeditionFk`) AS `expeditions`,sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`,max(`e`.`lastPacked`) AS `lastPacked` from `expeditionCommon` `e` group by `e`.`truckFk` order by sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) desc,`e`.`etd` */; +/*!50001 VIEW `expeditionTruck_Control` AS select `e`.`truckFk` AS `id`,`e`.`etd` AS `ETD`,`e`.`description` AS `description`,count(distinct if(isnull(`e`.`expeditionFk`),`e`.`ticketFk`,NULL)) AS `ticketsSinBultos`,count(distinct `e`.`palletFk`) AS `pallets`,count(distinct `e`.`routeFk`) AS `routes`,count(distinct `e`.`scanFk`) AS `scans`,count(distinct `e`.`expeditionFk`) AS `expeditions`,sum((`e`.`truckFk` <> `e`.`expeditionTruckFk`)) AS `fallos`,max(`e`.`lastPacked`) AS `lastPacked` from `expeditionCommon` `e` group by `e`.`truckFk` order by `fallos` desc,`e`.`etd` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95580,7 +79781,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionTruck_Control_Detail` AS select `e`.`truckFk` AS `id`,`e`.`etd` AS `ETD`,`e`.`description` AS `destino`,`e`.`palletFk` AS `pallet`,count(distinct `e`.`routeFk`) AS `routes`,count(distinct `e`.`scanFk`) AS `scans`,count(distinct `e`.`expeditionTruckFk`) AS `destinos`,sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`,max(`e`.`lastPacked`) AS `lastPacked` from `expeditionCommon` `e` group by `e`.`truckFk`,`e`.`palletFk` order by sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) desc,`e`.`etd`,`e`.`truckFk` */; +/*!50001 VIEW `expeditionTruck_Control_Detail` AS select `e`.`truckFk` AS `id`,`e`.`etd` AS `ETD`,`e`.`description` AS `destino`,`e`.`palletFk` AS `pallet`,count(distinct `e`.`routeFk`) AS `routes`,count(distinct `e`.`scanFk`) AS `scans`,count(distinct `e`.`expeditionTruckFk`) AS `destinos`,sum((`e`.`truckFk` <> `e`.`expeditionTruckFk`)) AS `fallos`,max(`e`.`lastPacked`) AS `lastPacked` from `expeditionCommon` `e` group by `e`.`truckFk`,`e`.`palletFk` order by `fallos` desc,`e`.`etd`,`e`.`truckFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95599,7 +79800,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `expeditionTruck_Control_Detail_Pallet` AS select `e`.`truckFk` AS `id`,`e`.`etd` AS `ETD`,`e`.`description` AS `destino`,`e`.`palletFk` AS `pallet`,`e`.`routeFk` AS `route`,count(distinct `e`.`scanFk`) AS `scans`,`et`.`description` AS `destinos`,sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) AS `fallos`,`e`.`expeditionTruckFk` AS `expeditionTruckFk`,max(`e`.`lastPacked`) AS `lastPacked` from (`expeditionCommon` `e` left join `expeditionTruck` `et` on(`et`.`id` = `e`.`expeditionTruckFk`)) group by `e`.`truckFk`,`e`.`palletFk`,`e`.`routeFk` order by sum(`e`.`truckFk` <> `e`.`expeditionTruckFk`) desc,`e`.`palletFk` */; +/*!50001 VIEW `expeditionTruck_Control_Detail_Pallet` AS select `e`.`truckFk` AS `id`,`e`.`etd` AS `ETD`,`e`.`description` AS `destino`,`e`.`palletFk` AS `pallet`,`e`.`routeFk` AS `route`,count(distinct `e`.`scanFk`) AS `scans`,`et`.`description` AS `destinos`,sum((`e`.`truckFk` <> `e`.`expeditionTruckFk`)) AS `fallos`,`e`.`expeditionTruckFk` AS `expeditionTruckFk`,max(`e`.`lastPacked`) AS `lastPacked` from (`expeditionCommon` `e` left join `expeditionTruck` `et` on((`et`.`id` = `e`.`expeditionTruckFk`))) group by `e`.`truckFk`,`e`.`palletFk`,`e`.`routeFk` order by `fallos` desc,`e`.`palletFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95618,7 +79819,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `firstTicketShipped` AS select min(`ticket`.`shipped`) AS `shipped`,`ticket`.`clientFk` AS `clientFk` from `ticket` where `ticket`.`shipped` > '2001-01-01' group by `ticket`.`clientFk` */; +/*!50001 VIEW `firstTicketShipped` AS select min(`ticket`.`shipped`) AS `shipped`,`ticket`.`clientFk` AS `clientFk` from `ticket` where (`ticket`.`shipped` > '2001-01-01') group by `ticket`.`clientFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95637,83 +79838,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `floraHollandBuyedItems` AS select `b`.`itemFk` AS `itemFk`,`i`.`longName` AS `longName`,`b`.`quantity` AS `quantity`,`b`.`buyingValue` AS `buyingValue`,`tr`.`landed` AS `landed`,`e`.`companyFk` AS `companyFk` from (((((`buy` `b` join `item` `i` on(`b`.`itemFk` = `i`.`id`)) join `itemType` `it` on(`it`.`id` = `i`.`typeFk`)) join `itemCategory` `ic` on(`ic`.`id` = `it`.`categoryFk`)) join `entry` `e` on(`e`.`id` = `b`.`entryFk`)) join `travel` `tr` on(`tr`.`id` = `e`.`travelFk` and `ic`.`id` not in (8,6) and `b`.`buyingValue` <> 0 and `b`.`quantity` <> 0 and `e`.`supplierFk` in (1664,1665,1666,1465,1433))) */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `holidayDetail__` --- - -/*!50001 DROP TABLE IF EXISTS `holidayDetail__`*/; -/*!50001 DROP VIEW IF EXISTS `holidayDetail__`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `holidayDetail__` AS select `cll`.`calendar_labour_legend_id` AS `id`,`cll`.`descripcion` AS `description` from `postgresql`.`calendar_labour_legend__` `cll` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `holidayLegend__` --- - -/*!50001 DROP TABLE IF EXISTS `holidayLegend__`*/; -/*!50001 DROP VIEW IF EXISTS `holidayLegend__`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `holidayLegend__` AS select `cll`.`calendar_labour_legend_id` AS `id`,`cll`.`descripcion` AS `description` from `postgresql`.`calendar_labour_legend__` `cll` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `holidayType__` --- - -/*!50001 DROP TABLE IF EXISTS `holidayType__`*/; -/*!50001 DROP VIEW IF EXISTS `holidayType__`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `holidayType__` AS select `cf`.`calendar_free_id` AS `id`,`cf`.`type` AS `name`,`cf`.`rgb` AS `rgb` from `postgresql`.`calendar_free__` `cf` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `holiday__` --- - -/*!50001 DROP TABLE IF EXISTS `holiday__`*/; -/*!50001 DROP VIEW IF EXISTS `holiday__`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `holiday__` AS select `cl`.`calendar_labour_legend_id` AS `holidayDetailFk`,`cl`.`calendar_free_id` AS `holidayTypeFk`,`cl`.`workcenter_id` AS `workCenterFk`,`cl`.`day` AS `dated` from `postgresql`.`calendar_labour__` `cl` */; +/*!50001 VIEW `floraHollandBuyedItems` AS select `b`.`itemFk` AS `itemFk`,`i`.`longName` AS `longName`,`b`.`quantity` AS `quantity`,`b`.`buyingValue` AS `buyingValue`,`tr`.`landed` AS `landed`,`e`.`companyFk` AS `companyFk` from (((((`buy` `b` join `item` `i` on((`b`.`itemFk` = `i`.`id`))) join `itemType` `it` on((`it`.`id` = `i`.`typeFk`))) join `itemCategory` `ic` on((`ic`.`id` = `it`.`categoryFk`))) join `entry` `e` on((`e`.`id` = `b`.`entryFk`))) join `travel` `tr` on(((`tr`.`id` = `e`.`travelFk`) and (`ic`.`id` not in (8,6)) and (`b`.`buyingValue` <> 0) and (`b`.`quantity` <> 0) and (`e`.`supplierFk` in (1664,1665,1666,1465,1433))))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95732,7 +79857,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `inkL10n` AS select `k`.`id` AS `id`,ifnull(`i`.`name`,`k`.`name`) AS `name` from (`ink` `k` left join `inkI18n` `i` on(`i`.`inkFk` = `k`.`id` and `i`.`lang` = `util`.`lang`())) */; +/*!50001 VIEW `inkL10n` AS select `k`.`id` AS `id`,ifnull(`i`.`name`,`k`.`name`) AS `name` from (`ink` `k` left join `inkI18n` `i` on(((`i`.`inkFk` = `k`.`id`) and (`i`.`lang` = `util`.`lang`())))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95751,7 +79876,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `invoiceCorrectionDataSource` AS select `s`.`itemFk` AS `itemFk`,`s`.`quantity` AS `quantity`,`s`.`concept` AS `concept`,`s`.`price` AS `price`,`s`.`discount` AS `discount`,`t`.`refFk` AS `refFk`,`s`.`id` AS `saleFk`,`t`.`shipped` AS `shipped` from (`sale` `s` join `ticket` `t` on(`t`.`id` = `s`.`ticketFk`)) where `t`.`shipped` > util.VN_CURDATE() + interval -3 year */; +/*!50001 VIEW `invoiceCorrectionDataSource` AS select `s`.`itemFk` AS `itemFk`,`s`.`quantity` AS `quantity`,`s`.`concept` AS `concept`,`s`.`price` AS `price`,`s`.`discount` AS `discount`,`t`.`refFk` AS `refFk`,`s`.`id` AS `saleFk`,`t`.`shipped` AS `shipped` from (`sale` `s` join `ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) where (`t`.`shipped` > (vn.VN_CURDATE() + interval -(3) year)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95770,7 +79895,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemBotanicalWithGenus` AS select `ib`.`itemFk` AS `itemFk`,concat(`g`.`name`,' ',ifnull(`s`.`name`,'')) AS `ediBotanic` from ((`itemBotanical` `ib` left join `specie` `s` on(`s`.`id` = `ib`.`specieFk`)) left join `genus` `g` on(`g`.`id` = `ib`.`genusFk`)) */; +/*!50001 VIEW `itemBotanicalWithGenus` AS select `ib`.`itemFk` AS `itemFk`,concat(`g`.`name`,' ',ifnull(`s`.`name`,'')) AS `ediBotanic` from ((`itemBotanical` `ib` left join `specie` `s` on((`s`.`id` = `ib`.`specieFk`))) left join `genus` `g` on((`g`.`id` = `ib`.`genusFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95789,7 +79914,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemCategoryL10n` AS select `c`.`id` AS `id`,ifnull(`i`.`name`,`c`.`name`) AS `name` from (`itemCategory` `c` left join `itemCategoryI18n` `i` on(`i`.`categoryFk` = `c`.`id` and `i`.`lang` = `util`.`lang`())) */; +/*!50001 VIEW `itemCategoryL10n` AS select `c`.`id` AS `id`,ifnull(`i`.`name`,`c`.`name`) AS `name` from (`itemCategory` `c` left join `itemCategoryI18n` `i` on(((`i`.`categoryFk` = `c`.`id`) and (`i`.`lang` = `util`.`lang`())))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95808,7 +79933,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemColor` AS select `it`.`itemFk` AS `itemFk`,`it`.`value` AS `color` from (`itemTag` `it` join `tag` `t` on(`t`.`id` = `it`.`tagFk`)) where `t`.`code` = 'COLOR' */; +/*!50001 VIEW `itemColor` AS select `it`.`itemFk` AS `itemFk`,`it`.`value` AS `color` from (`itemTag` `it` join `tag` `t` on((`t`.`id` = `it`.`tagFk`))) where (`t`.`code` = 'COLOR') */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95827,7 +79952,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemEntryIn` AS select `t`.`warehouseInFk` AS `warehouseInFk`,`t`.`landed` AS `landed`,`b`.`itemFk` AS `itemFk`,`b`.`quantity` AS `quantity`,`t`.`isReceived` AS `isReceived`,`e`.`isRaid` AS `isVirtualStock`,`e`.`id` AS `entryFk` from ((`buy` `b` join `entry` `e` on(`b`.`entryFk` = `e`.`id`)) join `travel` `t` on(`e`.`travelFk` = `t`.`id`)) where `e`.`isInventory` = 0 and `b`.`quantity` <> 0 */; +/*!50001 VIEW `itemEntryIn` AS select `t`.`warehouseInFk` AS `warehouseInFk`,`t`.`landed` AS `landed`,`b`.`itemFk` AS `itemFk`,`b`.`quantity` AS `quantity`,`t`.`isReceived` AS `isReceived`,`e`.`isRaid` AS `isVirtualStock`,`e`.`id` AS `entryFk` from ((`buy` `b` join `entry` `e` on((`b`.`entryFk` = `e`.`id`))) join `travel` `t` on((`e`.`travelFk` = `t`.`id`))) where ((`e`.`isInventory` = 0) and (`b`.`quantity` <> 0)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95846,7 +79971,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemEntryOut` AS select `t`.`warehouseOutFk` AS `warehouseOutFk`,`t`.`shipped` AS `shipped`,`b`.`itemFk` AS `itemFk`,-`b`.`quantity` AS `quantity`,`t`.`isDelivered` AS `isDelivered`,`e`.`id` AS `entryFk` from ((`buy` `b` join `entry` `e` on(`b`.`entryFk` = `e`.`id`)) join `travel` `t` on(`e`.`travelFk` = `t`.`id`)) where `e`.`isInventory` = 0 and `e`.`isRaid` = 0 and `b`.`quantity` <> 0 */; +/*!50001 VIEW `itemEntryOut` AS select `t`.`warehouseOutFk` AS `warehouseOutFk`,`t`.`shipped` AS `shipped`,`b`.`itemFk` AS `itemFk`,-(`b`.`quantity`) AS `quantity`,`t`.`isDelivered` AS `isDelivered`,`e`.`id` AS `entryFk` from ((`buy` `b` join `entry` `e` on((`b`.`entryFk` = `e`.`id`))) join `travel` `t` on((`e`.`travelFk` = `t`.`id`))) where ((`e`.`isInventory` = 0) and (`e`.`isRaid` = 0) and (`b`.`quantity` <> 0)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95865,7 +79990,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemInk` AS select `i`.`longName` AS `longName`,`i`.`inkFk` AS `inkFk`,`ink`.`name` AS `color` from (`item` `i` join `ink` on(`ink`.`id` = `i`.`inkFk`)) where `ink`.`isRealColor` <> 0 group by `i`.`longName` */; +/*!50001 VIEW `itemInk` AS select `i`.`longName` AS `longName`,`i`.`inkFk` AS `inkFk`,`ink`.`name` AS `color` from (`item` `i` join `ink` on((`ink`.`id` = `i`.`inkFk`))) where `ink`.`isRealColor` group by `i`.`longName` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95884,7 +80009,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemPlacementSupplyList` AS select `ips`.`id` AS `id`,`ips`.`itemFk` AS `itemFk`,`ips`.`quantity` AS `quantity`,`ips`.`priority` AS `priority`,ifnull(`isps`.`created`,`ips`.`created`) AS `created`,`ips`.`userFk` AS `userFk`,`ips`.`repoUserFk` AS `repoUserFk`,`ips`.`quantity` - sum(ifnull(`isps`.`quantity`,0)) AS `saldo`,concat(`i`.`longName`,' ',`i`.`size`) AS `longName`,`i`.`subName` AS `subName`,`i`.`size` AS `size`,`w`.`code` AS `workerCode`,`rw`.`code` AS `repoCode`,`ips`.`sectorFk` AS `sectorFk` from ((((`itemPlacementSupply` `ips` join `item` `i` on(`i`.`id` = `ips`.`itemFk`)) left join `worker` `w` on(`w`.`userFk` = `ips`.`userFk`)) left join `worker` `rw` on(`rw`.`userFk` = `ips`.`repoUserFk`)) left join `itemShelvingPlacementSupply` `isps` on(`isps`.`itemPlacementSupplyFk` = `ips`.`id`)) where `ips`.`created` >= util.VN_CURDATE() group by `ips`.`priority`,`ips`.`id`,`ips`.`sectorFk` */; +/*!50001 VIEW `itemPlacementSupplyList` AS select `ips`.`id` AS `id`,`ips`.`itemFk` AS `itemFk`,`ips`.`quantity` AS `quantity`,`ips`.`priority` AS `priority`,ifnull(`isps`.`created`,`ips`.`created`) AS `created`,`ips`.`userFk` AS `userFk`,`ips`.`repoUserFk` AS `repoUserFk`,(`ips`.`quantity` - sum(ifnull(`isps`.`quantity`,0))) AS `saldo`,concat(`i`.`longName`,' ',`i`.`size`) AS `longName`,`i`.`subName` AS `subName`,`i`.`size` AS `size`,`w`.`code` AS `workerCode`,`rw`.`code` AS `repoCode`,`ips`.`sectorFk` AS `sectorFk` from ((((`itemPlacementSupply` `ips` join `item` `i` on((`i`.`id` = `ips`.`itemFk`))) left join `worker` `w` on((`w`.`userFk` = `ips`.`userFk`))) left join `worker` `rw` on((`rw`.`userFk` = `ips`.`repoUserFk`))) left join `itemShelvingPlacementSupply` `isps` on((`isps`.`itemPlacementSupplyFk` = `ips`.`id`))) where (`ips`.`created` >= vn.VN_CURDATE()) group by `ips`.`priority`,`ips`.`id`,`ips`.`sectorFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95903,7 +80028,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemProductor` AS select `it`.`itemFk` AS `itemFk`,`it`.`value` AS `productor` from (`itemTag` `it` join `tag` `t` on(`t`.`id` = `it`.`tagFk`)) where `t`.`code` = 'PRODUCER' */; +/*!50001 VIEW `itemProductor` AS select `it`.`itemFk` AS `itemFk`,`it`.`value` AS `productor` from (`itemTag` `it` join `tag` `t` on((`t`.`id` = `it`.`tagFk`))) where (`t`.`code` = 'PRODUCER') */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95922,7 +80047,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` 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 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 */; @@ -95941,7 +80066,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemShelvingAvailable` AS select `s`.`id` AS `saleFk`,`tst`.`updated` AS `Modificado`,`s`.`ticketFk` AS `ticketFk`,0 AS `isPicked`,`s`.`itemFk` AS `itemFk`,`s`.`quantity` AS `quantity`,`s`.`concept` AS `concept`,`i`.`size` AS `size`,`st`.`name` AS `Estado`,`st`.`sectorProdPriority` AS `sectorProdPriority`,`stock`.`visible` AS `available`,`stock`.`sectorFk` AS `sectorFk`,`stock`.`shelvingFk` AS `matricula`,`stock`.`parkingFk` AS `parking`,`stock`.`itemShelvingFk` AS `itemShelving`,`am`.`name` AS `Agency`,`t`.`shipped` AS `shipped`,`stock`.`grouping` AS `grouping`,`stock`.`packing` AS `packing`,`z`.`hour` AS `hour`,`st`.`isPreviousPreparable` AS `isPreviousPreparable`,`sv`.`physicalVolume` AS `physicalVolume`,`t`.`warehouseFk` AS `warehouseFk` from (((((((((`vn`.`sale` `s` join `vn`.`ticket` `t` on(`t`.`id` = `s`.`ticketFk`)) join `vn`.`agencyMode` `am` on(`am`.`id` = `t`.`agencyModeFk`)) join `vn`.`ticketStateToday` `tst` on(`tst`.`ticket` = `t`.`id`)) join `vn`.`state` `st` on(`st`.`id` = `tst`.`state`)) join `vn`.`item` `i` on(`i`.`id` = `s`.`itemFk`)) join `vn`.`itemShelvingStock` `stock` on(`stock`.`itemFk` = `i`.`id`)) left join `vn`.`saleTracking` `stk` on(`stk`.`saleFk` = `s`.`id`)) left join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) left join `vn`.`saleVolume` `sv` on(`sv`.`saleFk` = `s`.`id`)) where `t`.`shipped` between `util`.`yesterday`() and `util`.`dayend`(util.VN_CURDATE()) and `stk`.`id` is null and `stock`.`visible` > 0 and `stk`.`saleFk` is null and `st`.`isPreviousPreparable` <> 0 */; +/*!50001 VIEW `itemShelvingAvailable` AS select `s`.`id` AS `saleFk`,`tst`.`updated` AS `Modificado`,`s`.`ticketFk` AS `ticketFk`,0 AS `isPicked`,`s`.`itemFk` AS `itemFk`,`s`.`quantity` AS `quantity`,`s`.`concept` AS `concept`,`i`.`size` AS `size`,`st`.`name` AS `Estado`,`st`.`sectorProdPriority` AS `sectorProdPriority`,`stock`.`visible` AS `available`,`stock`.`sectorFk` AS `sectorFk`,`stock`.`shelvingFk` AS `matricula`,`stock`.`parkingFk` AS `parking`,`stock`.`itemShelvingFk` AS `itemShelving`,`am`.`name` AS `Agency`,`t`.`shipped` AS `shipped`,`stock`.`grouping` AS `grouping`,`stock`.`packing` AS `packing`,`z`.`hour` AS `hour`,`st`.`isPreviousPreparable` AS `isPreviousPreparable`,`sv`.`physicalVolume` AS `physicalVolume`,`t`.`warehouseFk` AS `warehouseFk` from (((((((((`vn`.`sale` `s` join `vn`.`ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `vn`.`agencyMode` `am` on((`am`.`id` = `t`.`agencyModeFk`))) join `vn`.`ticketStateToday` `tst` on((`tst`.`ticket` = `t`.`id`))) join `vn`.`state` `st` on((`st`.`id` = `tst`.`state`))) join `vn`.`item` `i` on((`i`.`id` = `s`.`itemFk`))) join `vn`.`itemShelvingStock` `stock` on((`stock`.`itemFk` = `i`.`id`))) left join `vn`.`saleTracking` `stk` on((`stk`.`saleFk` = `s`.`id`))) left join `vn`.`zone` `z` on((`z`.`id` = `t`.`zoneFk`))) left join `vn`.`saleVolume` `sv` on((`sv`.`saleFk` = `s`.`id`))) where ((`t`.`shipped` between `util`.`yesterday`() and `util`.`dayend`(vn.VN_CURDATE())) and isnull(`stk`.`id`) and (`stock`.`visible` > 0) and isnull(`stk`.`saleFk`) and `st`.`isPreviousPreparable`) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95960,7 +80085,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemShelvingList` AS select `ish`.`shelvingFk` AS `shelvingFk`,`ish`.`visible` AS `visible`,`ish`.`created` AS `created`,`pk`.`code` AS `parking`,`ish`.`itemFk` AS `itemFk`,`i`.`longName` AS `longName`,`i`.`size` AS `size`,`i`.`subName` AS `subName`,`sh`.`parked` AS `parked`,`pk`.`sectorFk` AS `sectorFk` from (((`itemShelving` `ish` join `shelving` `sh` on(`sh`.`code` = `ish`.`shelvingFk`)) join `item` `i` on(`i`.`id` = `ish`.`itemFk`)) left join `parking` `pk` on(`pk`.`id` = `sh`.`parkingFk`)) order by `ish`.`created` */; +/*!50001 VIEW `itemShelvingList` AS select `ish`.`shelvingFk` AS `shelvingFk`,`ish`.`visible` AS `visible`,`ish`.`created` AS `created`,`pk`.`code` AS `parking`,`ish`.`itemFk` AS `itemFk`,`i`.`longName` AS `longName`,`i`.`size` AS `size`,`i`.`subName` AS `subName`,`sh`.`parked` AS `parked`,`pk`.`sectorFk` AS `sectorFk` from (((`itemShelving` `ish` join `shelving` `sh` on((`sh`.`code` = `ish`.`shelvingFk`))) join `item` `i` on((`i`.`id` = `ish`.`itemFk`))) left join `parking` `pk` on((`pk`.`id` = `sh`.`parkingFk`))) order by `ish`.`created` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -95998,7 +80123,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemShelvingSaleSum` AS select `iss`.`id` AS `id`,`iss`.`itemShelvingFk` AS `itemShelvingFk`,`iss`.`saleFk` AS `saleFk`,sum(`iss`.`quantity`) AS `quantity`,`iss`.`created` AS `created`,`p`.`sectorFk` AS `sectorFk` from (((`itemShelvingSale` `iss` join `itemShelving` `ish` on(`ish`.`id` = `iss`.`itemShelvingFk`)) join `shelving` `sh` on(`sh`.`code` = `ish`.`shelvingFk`)) join `parking` `p` on(`p`.`id` = `sh`.`parkingFk`)) group by `iss`.`saleFk` */; +/*!50001 VIEW `itemShelvingSaleSum` AS select `iss`.`id` AS `id`,`iss`.`itemShelvingFk` AS `itemShelvingFk`,`iss`.`saleFk` AS `saleFk`,sum(`iss`.`quantity`) AS `quantity`,`iss`.`created` AS `created`,`p`.`sectorFk` AS `sectorFk` from (((`itemShelvingSale` `iss` join `itemShelving` `ish` on((`ish`.`id` = `iss`.`itemShelvingFk`))) join `shelving` `sh` on((`sh`.`code` = `ish`.`shelvingFk`))) join `parking` `p` on((`p`.`id` = `sh`.`parkingFk`))) group by `iss`.`saleFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96017,7 +80142,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemShelvingStock` AS select `ish`.`itemFk` AS `itemFk`,sum(`ish`.`visible`) AS `visible`,min(`ish`.`packing`) AS `packing`,min(`ish`.`grouping`) AS `grouping`,`s`.`description` AS `sector`,sum(`ish`.`visible`) AS `visibleOriginal`,0 AS `removed`,`p`.`sectorFk` AS `sectorFk`,`s`.`warehouseFk` AS `warehouseFk`,`ish`.`shelvingFk` AS `shelvingFk`,`p`.`code` AS `parkingCode`,`sh`.`parkingFk` AS `parkingFk`,`ish`.`id` AS `itemShelvingFk`,`ish`.`created` AS `created`,`s`.`isPreviousPrepared` AS `isPreviousPrepared` from (((`itemShelving` `ish` left join `shelving` `sh` on(`sh`.`code` = `ish`.`shelvingFk`)) left join `parking` `p` on(`p`.`id` = `sh`.`parkingFk`)) left join `sector` `s` on(`s`.`id` = `p`.`sectorFk`)) where `ish`.`visible` <> 0 and `p`.`sectorFk` <> 0 group by `ish`.`itemFk`,`p`.`sectorFk` */; +/*!50001 VIEW `itemShelvingStock` AS select `ish`.`itemFk` AS `itemFk`,sum(`ish`.`visible`) AS `visible`,min(`ish`.`packing`) AS `packing`,min(`ish`.`grouping`) AS `grouping`,`s`.`description` AS `sector`,sum(`ish`.`visible`) AS `visibleOriginal`,0 AS `removed`,`p`.`sectorFk` AS `sectorFk`,`s`.`warehouseFk` AS `warehouseFk`,`ish`.`shelvingFk` AS `shelvingFk`,`p`.`code` AS `parkingCode`,`sh`.`parkingFk` AS `parkingFk`,`ish`.`id` AS `itemShelvingFk`,`ish`.`created` AS `created`,`s`.`isPreviousPrepared` AS `isPreviousPrepared` from (((`itemShelving` `ish` left join `shelving` `sh` on((`sh`.`code` = `ish`.`shelvingFk`))) left join `parking` `p` on((`p`.`id` = `sh`.`parkingFk`))) left join `sector` `s` on((`s`.`id` = `p`.`sectorFk`))) where ((`ish`.`visible` <> 0) and `p`.`sectorFk`) group by `ish`.`itemFk`,`p`.`sectorFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96036,7 +80161,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemShelvingStockFull` AS select `ish`.`itemFk` AS `itemFk`,`ish`.`visible` AS `quantity`,`ish`.`packing` AS `packing`,`ish`.`grouping` AS `grouping`,`s`.`description` AS `sector`,`issr`.`removed` AS `removed`,`p`.`sectorFk` AS `sectorFk`,`s`.`warehouseFk` AS `warehouseFk`,`ish`.`shelvingFk` AS `shelvingFk`,`p`.`code` AS `parkingCode`,`sh`.`parkingFk` AS `parkingFk`,`ish`.`id` AS `itemShelvingFk`,`ish`.`created` AS `created` from ((((`itemShelving` `ish` join `shelving` `sh` on(`sh`.`code` = `ish`.`shelvingFk`)) join `parking` `p` on(`p`.`id` = `sh`.`parkingFk`)) join `sector` `s` on(`s`.`id` = `p`.`sectorFk`)) left join `itemShelvingStockRemoved` `issr` on(`issr`.`itemShelvingFk` = `ish`.`id`)) */; +/*!50001 VIEW `itemShelvingStockFull` AS select `ish`.`itemFk` AS `itemFk`,`ish`.`visible` AS `quantity`,`ish`.`packing` AS `packing`,`ish`.`grouping` AS `grouping`,`s`.`description` AS `sector`,`issr`.`removed` AS `removed`,`p`.`sectorFk` AS `sectorFk`,`s`.`warehouseFk` AS `warehouseFk`,`ish`.`shelvingFk` AS `shelvingFk`,`p`.`code` AS `parkingCode`,`sh`.`parkingFk` AS `parkingFk`,`ish`.`id` AS `itemShelvingFk`,`ish`.`created` AS `created` from ((((`itemShelving` `ish` join `shelving` `sh` on((`sh`.`code` = `ish`.`shelvingFk`))) join `parking` `p` on((`p`.`id` = `sh`.`parkingFk`))) join `sector` `s` on((`s`.`id` = `p`.`sectorFk`))) left join `itemShelvingStockRemoved` `issr` on((`issr`.`itemShelvingFk` = `ish`.`id`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96055,7 +80180,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemShelvingStockRemoved` AS select `ish`.`id` AS `itemShelvingFk`,`ish`.`itemFk` AS `itemFk`,0 AS `removed` from ((`itemShelving` `ish` left join `itemShelvingSale` `iss` on(`iss`.`itemShelvingFk` = `ish`.`id`)) left join `itemShelvingPlacementSupply` `isps` on(`isps`.`itemShelvingFk` = `ish`.`id`)) group by `ish`.`id` */; +/*!50001 VIEW `itemShelvingStockRemoved` AS select `ish`.`id` AS `itemShelvingFk`,`ish`.`itemFk` AS `itemFk`,0 AS `removed` from ((`itemShelving` `ish` left join `itemShelvingSale` `iss` on((`iss`.`itemShelvingFk` = `ish`.`id`))) left join `itemShelvingPlacementSupply` `isps` on((`isps`.`itemShelvingFk` = `ish`.`id`))) group by `ish`.`id` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96074,7 +80199,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemShelvingStock_byWarehouse` AS select `ish`.`itemFk` AS `itemFk`,sum(`ish`.`visible`) AS `visible`,`s`.`warehouseFk` AS `warehouseFk` from (((`itemShelving` `ish` join `shelving` `sh` on(`sh`.`code` = `ish`.`shelvingFk`)) join `parking` `p` on(`p`.`id` = `sh`.`parkingFk`)) join `sector` `s` on(`s`.`id` = `p`.`sectorFk`)) group by `ish`.`itemFk`,`s`.`warehouseFk` */; +/*!50001 VIEW `itemShelvingStock_byWarehouse` AS select `ish`.`itemFk` AS `itemFk`,sum(`ish`.`visible`) AS `visible`,`s`.`warehouseFk` AS `warehouseFk` from (((`itemShelving` `ish` join `shelving` `sh` on((`sh`.`code` = `ish`.`shelvingFk`))) join `parking` `p` on((`p`.`id` = `sh`.`parkingFk`))) join `sector` `s` on((`s`.`id` = `p`.`sectorFk`))) group by `ish`.`itemFk`,`s`.`warehouseFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96112,7 +80237,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemTicketOut` AS select `t`.`warehouseFk` AS `warehouseFk`,`t`.`shipped` AS `shipped`,`s`.`itemFk` AS `itemFk`,-`s`.`quantity` AS `quantity`,`s`.`isPicked` AS `isPicked`,`s`.`reserved` AS `reserved`,`t`.`refFk` AS `refFk`,`s`.`id` AS `saleFk`,`s`.`ticketFk` AS `ticketFk` from (`sale` `s` join `ticket` `t` on(`s`.`ticketFk` = `t`.`id`)) where `s`.`quantity` <> 0 */; +/*!50001 VIEW `itemTicketOut` AS select `t`.`warehouseFk` AS `warehouseFk`,`t`.`shipped` AS `shipped`,`s`.`itemFk` AS `itemFk`,-(`s`.`quantity`) AS `quantity`,`s`.`isPicked` AS `isPicked`,`s`.`reserved` AS `reserved`,`t`.`refFk` AS `refFk`,`s`.`id` AS `saleFk`,`s`.`ticketFk` AS `ticketFk` from (`sale` `s` join `ticket` `t` on((`s`.`ticketFk` = `t`.`id`))) where (`s`.`quantity` <> 0) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96131,7 +80256,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemTypeL10n` AS select `t`.`id` AS `id`,ifnull(`i`.`name`,`t`.`name`) AS `name` from (`itemType` `t` left join `itemTypeI18n` `i` on(`i`.`typeFk` = `t`.`id` and `i`.`lang` = `util`.`LANG`())) */; +/*!50001 VIEW `itemTypeL10n` AS select `t`.`id` AS `id`,ifnull(`i`.`name`,`t`.`name`) AS `name` from (`itemType` `t` left join `itemTypeI18n` `i` on(((`i`.`typeFk` = `t`.`id`) and (`i`.`lang` = `util`.`LANG`())))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96150,7 +80275,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `item_Free_Id` AS select `i1`.`id` + 1 AS `newId` from (`item` `i1` left join `item` `i2` on(`i1`.`id` + 1 = `i2`.`id`)) where `i2`.`id` is null and `i1`.`id` > 400000 */; +/*!50001 VIEW `item_Free_Id` AS select (`i1`.`id` + 1) AS `newId` from (`item` `i1` left join `item` `i2` on(((`i1`.`id` + 1) = `i2`.`id`))) where (isnull(`i2`.`id`) and (`i1`.`id` > 400000)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96169,7 +80294,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `labelInfo` AS select `i`.`id` AS `itemId`,`i`.`name` AS `itemName`,`b`.`stickers` AS `stickers`,`b`.`printedStickers` AS `life`,`i`.`inkFk` AS `colorCode`,`i`.`stems` AS `stems`,`i`.`category` AS `category`,`i`.`subName` AS `productor`,`b`.`packing` AS `packing`,`clb`.`warehouse_id` AS `warehouse_id`,`i`.`size` AS `size`,`b`.`isPickedOff` AS `isPickedOff`,`e`.`evaNotes` AS `notes`,`w`.`name` AS `wh_in`,`e`.`id` AS `entryId`,`b`.`id` AS `buyId` from (((((`vn`.`buy` `b` join `vn`.`item` `i` on(`i`.`id` = `b`.`itemFk`)) join `cache`.`last_buy` `clb` on(`clb`.`item_id` = `i`.`id`)) join `vn`.`entry` `e` on(`e`.`id` = `b`.`entryFk`)) left join `vn`.`travel` `tr` on(`tr`.`id` = `e`.`travelFk`)) join `vn`.`warehouse` `w` on(`w`.`id` = `tr`.`warehouseInFk`)) */; +/*!50001 VIEW `labelInfo` AS select `i`.`id` AS `itemId`,`i`.`name` AS `itemName`,`b`.`stickers` AS `stickers`,`b`.`printedStickers` AS `life`,`i`.`inkFk` AS `colorCode`,`i`.`stems` AS `stems`,`i`.`category` AS `category`,`i`.`subName` AS `productor`,`b`.`packing` AS `packing`,`clb`.`warehouse_id` AS `warehouse_id`,`i`.`size` AS `size`,`b`.`isPickedOff` AS `isPickedOff`,`e`.`evaNotes` AS `notes`,`w`.`name` AS `wh_in`,`e`.`id` AS `entryId`,`b`.`id` AS `buyId` from (((((`vn`.`buy` `b` join `vn`.`item` `i` on((`i`.`id` = `b`.`itemFk`))) join `cache`.`last_buy` `clb` on((`clb`.`item_id` = `i`.`id`))) join `vn`.`entry` `e` on((`e`.`id` = `b`.`entryFk`))) left join `vn`.`travel` `tr` on((`tr`.`id` = `e`.`travelFk`))) join `vn`.`warehouse` `w` on((`w`.`id` = `tr`.`warehouseInFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96188,7 +80313,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `lastHourProduction` AS select `t`.`warehouseFk` AS `warehouseFk`,cast(sum(ifnull(`p`.`volume`,`p`.`width` * `p`.`height` * `p`.`depth`) / 1000000) as decimal(5,1)) AS `m3` from (((`warehouse` `w` join `ticket` `t` on(`t`.`warehouseFk` = `w`.`id`)) left join `expedition` `e` on(`t`.`id` = `e`.`ticketFk`)) left join `packaging` `p` on(`p`.`id` = `e`.`packagingFk`)) where `e`.`created` between current_timestamp() - interval 1 hour and current_timestamp() group by `t`.`warehouseFk` */; +/*!50001 VIEW `lastHourProduction` AS select `t`.`warehouseFk` AS `warehouseFk`,cast(sum((ifnull(`p`.`volume`,((`p`.`width` * `p`.`height`) * `p`.`depth`)) / 1000000)) as decimal(5,1)) AS `m3` from (((`warehouse` `w` join `ticket` `t` on((`t`.`warehouseFk` = `w`.`id`))) left join `expedition` `e` on((`t`.`id` = `e`.`ticketFk`))) left join `packaging` `p` on((`p`.`id` = `e`.`packagingFk`))) where (`e`.`created` between (vn.VN_NOW() - interval 1 hour) and vn.VN_NOW()) group by `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 */; @@ -96207,7 +80332,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` 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`,`ek`.`pro` AS `pro`,`ek`.`ref` AS `ektRef`,`ek`.`agj` AS `agj` from (((((`vn`.`buy` `b` join `vn`.`entry` `e` on(`e`.`id` = `b`.`entryFk`)) join `vn`.`item` `i` on(`i`.`id` = `b`.`itemFk`)) join `vn`.`travel` `tr` on(`tr`.`id` = `e`.`travelFk`)) join `vn`.`warehouse` `w` on(`w`.`id` = `tr`.`warehouseInFk`)) left join `edi`.`ekt` `ek` on(`ek`.`id` = `b`.`ektFk`)) where `tr`.`landed` between `util`.`yesterday`() and `util`.`tomorrow`() and `e`.`isRaid` = 0 and `b`.`stickers` > 0 */; +/*!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`,`ek`.`pro` AS `pro`,`ek`.`ref` AS `ektRef`,`ek`.`agj` AS `agj` from (((((`vn`.`buy` `b` join `vn`.`entry` `e` on((`e`.`id` = `b`.`entryFk`))) join `vn`.`item` `i` on((`i`.`id` = `b`.`itemFk`))) join `vn`.`travel` `tr` on((`tr`.`id` = `e`.`travelFk`))) join `vn`.`warehouse` `w` on((`w`.`id` = `tr`.`warehouseInFk`))) left join `edi`.`ekt` `ek` on((`ek`.`id` = `b`.`ektFk`))) 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 */; @@ -96226,7 +80351,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `lastTopClaims` AS select `s`.`itemFk` AS `itemFk`,`i`.`longName` AS `itemName`,`it`.`name` AS `itemTypeName`,count(0) AS `claimsNumber`,round(sum(`cb`.`quantity` * `s`.`price` * (1 - (`c`.`responsibility` - 1) / 4) * (100 - `s`.`discount`) / 100),2) AS `claimedAmount`,round(sum(`cb`.`quantity` * `s`.`price` * (100 - `s`.`discount`) / 100),2) AS `totalAmount` from ((((`claim` `c` join `claimBeginning` `cb` on(`cb`.`claimFk` = `c`.`id`)) join `sale` `s` on(`s`.`id` = `cb`.`saleFk`)) join `item` `i` on(`i`.`id` = `s`.`itemFk`)) join `itemType` `it` on(`it`.`id` = `i`.`typeFk`)) where `c`.`created` >= util.VN_CURDATE() + interval -1 week group by `s`.`itemFk` having `claimedAmount` > 100 and `claimsNumber` > 2 or `claimsNumber` > 4 order by count(0) desc */; +/*!50001 VIEW `lastTopClaims` AS select `s`.`itemFk` AS `itemFk`,`i`.`longName` AS `itemName`,`it`.`name` AS `itemTypeName`,count(0) AS `claimsNumber`,round(sum(((((`cb`.`quantity` * `s`.`price`) * (1 - ((`c`.`responsibility` - 1) / 4))) * (100 - `s`.`discount`)) / 100)),2) AS `claimedAmount`,round(sum((((`cb`.`quantity` * `s`.`price`) * (100 - `s`.`discount`)) / 100)),2) AS `totalAmount` from ((((`claim` `c` join `claimBeginning` `cb` on((`cb`.`claimFk` = `c`.`id`))) join `sale` `s` on((`s`.`id` = `cb`.`saleFk`))) join `item` `i` on((`i`.`id` = `s`.`itemFk`))) join `itemType` `it` on((`it`.`id` = `i`.`typeFk`))) where (`c`.`created` >= (vn.VN_CURDATE() + interval -(1) week)) group by `s`.`itemFk` having (((`claimedAmount` > 100) and (`claimsNumber` > 2)) or (`claimsNumber` > 4)) order by `claimsNumber` desc */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96245,7 +80370,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `mistake` AS select `wr`.`code` AS `revisador`,`s`.`concept` AS `concept`,`w`.`code` AS `sacador`,`w`.`firstName` AS `firstName`,`w`.`lastName` AS `lastName`,`mt`.`description` AS `description`,cast(`iss`.`created` as date) AS `created`,`w`.`id` AS `workerFk` from (((((`saleMistake` `sm` join `mistakeType` `mt` on(`mt`.`id` = `sm`.`typeFk`)) join `worker` `wr` on(`wr`.`id` = `sm`.`userFk`)) join `sale` `s` on(`s`.`id` = `sm`.`saleFk`)) join `itemShelvingSale` `iss` on(`iss`.`saleFk` = `sm`.`saleFk`)) join `worker` `w` on(`w`.`id` = `iss`.`userFk`)) */; +/*!50001 VIEW `mistake` AS select `wr`.`code` AS `revisador`,`s`.`concept` AS `concept`,`w`.`code` AS `sacador`,`w`.`firstName` AS `firstName`,`w`.`lastName` AS `lastName`,`mt`.`description` AS `description`,cast(`iss`.`created` as date) AS `created`,`w`.`id` AS `workerFk` from (((((`saleMistake` `sm` join `mistakeType` `mt` on((`mt`.`id` = `sm`.`typeFk`))) join `worker` `wr` on((`wr`.`id` = `sm`.`userFk`))) join `sale` `s` on((`s`.`id` = `sm`.`saleFk`))) join `itemShelvingSale` `iss` on((`iss`.`saleFk` = `sm`.`saleFk`))) join `worker` `w` on((`w`.`id` = `iss`.`userFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96264,7 +80389,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `mistakeRatio` AS select `wr`.`code` AS `revisador`,`w`.`code` AS `sacador`,`w`.`firstName` AS `firstName`,`w`.`lastName` AS `lastName`,`mt`.`description` AS `description`,cast(`iss`.`created` as date) AS `created`,`w`.`id` AS `workerFk`,`sm`.`saleFk` AS `saleFk` from ((((`itemShelvingSale` `iss` join `worker` `w` on(`w`.`id` = `iss`.`userFk`)) left join `saleMistake` `sm` on(`iss`.`saleFk` = `sm`.`saleFk`)) left join `mistakeType` `mt` on(`mt`.`id` = `sm`.`typeFk`)) left join `worker` `wr` on(`wr`.`id` = `sm`.`userFk`)) */; +/*!50001 VIEW `mistakeRatio` AS select `wr`.`code` AS `revisador`,`w`.`code` AS `sacador`,`w`.`firstName` AS `firstName`,`w`.`lastName` AS `lastName`,`mt`.`description` AS `description`,cast(`iss`.`created` as date) AS `created`,`w`.`id` AS `workerFk`,`sm`.`saleFk` AS `saleFk` from ((((`itemShelvingSale` `iss` join `worker` `w` on((`w`.`id` = `iss`.`userFk`))) left join `saleMistake` `sm` on((`iss`.`saleFk` = `sm`.`saleFk`))) left join `mistakeType` `mt` on((`mt`.`id` = `sm`.`typeFk`))) left join `worker` `wr` on((`wr`.`id` = `sm`.`userFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96283,26 +80408,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `newBornSales` AS select `v`.`importe` AS `amount`,`v`.`Id_Cliente` AS `clientFk`,`c`.`salesPersonFk` AS `userFk`,`v`.`fecha` AS `dated`,`cn`.`firstShipped` AS `firstShipped` from ((((`bs`.`clientNewBorn` `cn` join `bs`.`ventas` `v` on(`cn`.`firstShipped` + interval 1 year > `v`.`fecha` and `v`.`Id_Cliente` = `cn`.`clientFk`)) join `vn`.`client` `c` on(`c`.`id` = `v`.`Id_Cliente`)) join `account`.`user` `u` on(`u`.`id` = `c`.`salesPersonFk`)) join `account`.`role` `r` on(`r`.`id` = `u`.`role`)) where `r`.`name` = 'salesPerson' and `u`.`name` not in ('ismaelalcolea','ruben') */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `newBornSales__` --- - -/*!50001 DROP TABLE IF EXISTS `newBornSales__`*/; -/*!50001 DROP VIEW IF EXISTS `newBornSales__`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `newBornSales__` AS select `v`.`importe` AS `amount`,`v`.`Id_Cliente` AS `clientFk`,`c`.`salesPersonFk` AS `userFk`,`v`.`fecha` AS `dated`,`cn`.`firstShipped` AS `firstShipped` from (((`bs`.`clientNewBorn` `cn` join `bs`.`ventas` `v` on(`cn`.`firstShipped` + interval 1 year > `v`.`fecha` and `v`.`Id_Cliente` = `cn`.`clientFk`)) join `vn`.`client` `c` on(`c`.`id` = `v`.`Id_Cliente`)) join `account`.`user` `u` on(`u`.`id` = `c`.`salesPersonFk`)) where `u`.`role` = 18 and `u`.`name` not in ('ismaelalcolea','ruben') */; +/*!50001 VIEW `newBornSales` AS select `v`.`importe` AS `amount`,`v`.`Id_Cliente` AS `clientFk`,`c`.`salesPersonFk` AS `userFk`,`v`.`fecha` AS `dated`,`cn`.`firstShipped` AS `firstShipped` from ((((`bs`.`clientNewBorn` `cn` join `bs`.`ventas` `v` on((((`cn`.`firstShipped` + interval 1 year) > `v`.`fecha`) and (`v`.`Id_Cliente` = `cn`.`clientFk`)))) join `vn`.`client` `c` on((`c`.`id` = `v`.`Id_Cliente`))) join `account`.`user` `u` on((`u`.`id` = `c`.`salesPersonFk`))) join `account`.`role` `r` on((`r`.`id` = `u`.`role`))) where ((`r`.`name` = 'salesPerson') and (`u`.`name` not in ('ismaelalcolea','ruben'))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96321,7 +80427,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `originL10n` AS select `o`.`id` AS `id`,ifnull(`i`.`name`,`o`.`name`) AS `name` from (`origin` `o` left join `originI18n` `i` on(`i`.`originFk` = `o`.`id` and `i`.`lang` = `util`.`lang`())) */; +/*!50001 VIEW `originL10n` AS select `o`.`id` AS `id`,ifnull(`i`.`name`,`o`.`name`) AS `name` from (`origin` `o` left join `originI18n` `i` on(((`i`.`originFk` = `o`.`id`) and (`i`.`lang` = `util`.`lang`())))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96340,45 +80446,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!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 */; - --- --- Final view structure for view `payDemDetail__` --- - -/*!50001 DROP TABLE IF EXISTS `payDemDetail__`*/; -/*!50001 DROP VIEW IF EXISTS `payDemDetail__`*/; -/*!50001 SET @saved_cs_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`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `payDemDetail__` AS select `pdd`.`id` AS `id`,`pdd`.`detalle` AS `detail` from `vn2008`.`pay_dem_det` `pdd` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `payment__` --- - -/*!50001 DROP TABLE IF EXISTS `payment__`*/; -/*!50001 DROP VIEW IF EXISTS `payment__`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `payment__` AS select `p`.`id` AS `id`,`p`.`fecha` AS `received`,`p`.`dueDated` AS `dueDated`,`p`.`id_proveedor` AS `supplierFk`,`p`.`importe` AS `amount`,`p`.`id_moneda` AS `currencyFk`,`p`.`divisa` AS `divisa`,`p`.`id_banco` AS `bankFk`,`p`.`pay_met_id` AS `payMethodFk`,`p`.`empresa_id` AS `companyFk`,`p`.`pago_sdc_id` AS `exchangeInsuranceFk`,`p`.`conciliado` AS `isConciliated` from `vn2008`.`pago` `p` */; +/*!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 */; @@ -96397,7 +80465,26 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `personMedia` AS select `p`.`id_trabajador` AS `workerFk`,`m`.`value` AS `mediaValue` from ((((`postgresql`.`person` `p` join `postgresql`.`profile` `po` on(`po`.`person_id` = `p`.`person_id`)) join `postgresql`.`profile_media` `pom` on(`pom`.`profile_id` = `po`.`profile_id`)) join `postgresql`.`media` `m` on(`m`.`media_id` = `pom`.`media_id`)) join `postgresql`.`media_type` `mt` on(`mt`.`media_type_id` = `m`.`media_type_id`)) where `mt`.`name` = 'movil personal' */; +/*!50001 VIEW `personMedia` AS select `p`.`id_trabajador` AS `workerFk`,`m`.`value` AS `mediaValue` from ((((`postgresql`.`person` `p` join `postgresql`.`profile` `po` on((`po`.`person_id` = `p`.`person_id`))) join `postgresql`.`profile_media` `pom` on((`pom`.`profile_id` = `po`.`profile_id`))) join `postgresql`.`media` `m` on((`m`.`media_id` = `pom`.`media_id`))) join `postgresql`.`media_type` `mt` on((`mt`.`media_type_id` = `m`.`media_type_id`))) where (`mt`.`name` = 'movil personal') */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `phoneBook` +-- + +/*!50001 DROP TABLE IF EXISTS `phoneBook`*/; +/*!50001 DROP VIEW IF EXISTS `phoneBook`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8mb4 */; +/*!50001 SET character_set_results = utf8mb4 */; +/*!50001 SET collation_connection = utf8mb4_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `phoneBook` AS select 'C' AS `Tipo`,`client`.`id` AS `Id`,`client`.`name` AS `Cliente`,`client`.`phone` AS `Telefono` from `client` where (`client`.`phone` is not null) union select 'C' AS `Tipo`,`client`.`id` AS `Id`,`client`.`name` AS `Cliente`,`client`.`mobile` AS `Movil` from `client` where (`client`.`mobile` is not null) union select 'C' AS `Tipo`,`clientContact`.`clientFk` AS `clientFk`,`clientContact`.`name` AS `name`,`clientContact`.`phone` AS `phone` from `clientContact` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96416,7 +80503,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `productionVolume` AS select hour(`e`.`created`) AS `hora`,minute(`e`.`created`) AS `minuto`,ifnull(`p`.`volume`,ifnull(`p`.`width` * `p`.`height` * `p`.`depth`,94500)) AS `cm3`,`t`.`warehouseFk` AS `warehouseFk`,`e`.`created` AS `created` from (((`expedition` `e` left join `packaging` `p` on(`p`.`itemFk` = `e`.`itemFk`)) join `ticket` `t` on(`t`.`id` = `e`.`ticketFk`)) join `client` `c` on(`c`.`id` = `t`.`clientFk`)) where `e`.`created` between util.VN_CURDATE() and `util`.`dayend`(util.VN_CURDATE()) and `c`.`isRelevant` <> 0 */; +/*!50001 VIEW `productionVolume` AS select hour(`e`.`created`) AS `hora`,minute(`e`.`created`) AS `minuto`,ifnull(`p`.`volume`,ifnull(((`p`.`width` * `p`.`height`) * `p`.`depth`),94500)) AS `cm3`,`t`.`warehouseFk` AS `warehouseFk`,`e`.`created` AS `created` from (((`expedition` `e` left join `packaging` `p` on((`p`.`itemFk` = `e`.`itemFk`))) join `ticket` `t` on((`t`.`id` = `e`.`ticketFk`))) join `client` `c` on((`c`.`id` = `t`.`clientFk`))) where ((`e`.`created` between vn.VN_CURDATE() and `util`.`dayend`(vn.VN_CURDATE())) and `c`.`isRelevant`) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96435,45 +80522,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `productionVolume_LastHour` AS select cast(sum(`productionVolume`.`cm3` / 1000000) as decimal(10,0)) AS `m3`,`productionVolume`.`warehouseFk` AS `warehouseFk` from `productionVolume` where `productionVolume`.`created` > current_timestamp() + interval -1 hour and `productionVolume`.`warehouseFk` in (1,44,60) group by `productionVolume`.`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 `rankingNewBornByQuarter__` --- - -/*!50001 DROP TABLE IF EXISTS `rankingNewBornByQuarter__`*/; -/*!50001 DROP VIEW IF EXISTS `rankingNewBornByQuarter__`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `rankingNewBornByQuarter__` AS select sum(`v`.`importe`) AS `total`,`u`.`name` AS `name`,current_timestamp() AS `time_sec`,`u`.`id` AS `userFk` from (((`bs`.`clientNewBorn` `cn` join `bs`.`ventas` `v` on(`cn`.`firstShipped` + interval 1 year > `v`.`fecha` and `v`.`Id_Cliente` = `cn`.`clientFk`)) join `vn`.`client` `c` on(`c`.`id` = `v`.`Id_Cliente`)) join `account`.`user` `u` on(`u`.`id` = `c`.`salesPersonFk`)) where `v`.`fecha` >= '2020-07-01' and `cn`.`firstShipped` >= '2019-07-01' and `u`.`role` = 18 and `u`.`name` not in ('ismaelalcolea','ruben') group by `u`.`id` order by sum(`v`.`importe`) desc limit 20 */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `rankingSellingByQuarter__` --- - -/*!50001 DROP TABLE IF EXISTS `rankingSellingByQuarter__`*/; -/*!50001 DROP VIEW IF EXISTS `rankingSellingByQuarter__`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `rankingSellingByQuarter__` AS select sum(`v`.`importe`) AS `importe`,`u`.`name` AS `name`,`u`.`id` AS `userFk`,current_timestamp() AS `time_sec` from (`bs`.`vendedores` `v` join `account`.`user` `u` on(`u`.`id` = `v`.`Id_Trabajador`)) where `v`.`año` = year(util.VN_CURDATE()) and quarter(concat(year(util.VN_CURDATE()),'-',`v`.`mes`,'-01')) = quarter(util.VN_CURDATE()) and `u`.`name` not in ('ismaelalcolea','ruben') group by `v`.`Id_Trabajador` order by sum(`v`.`importe`) desc limit 15 */; +/*!50001 VIEW `productionVolume_LastHour` AS select cast(sum((`productionVolume`.`cm3` / 1000000)) as decimal(10,0)) AS `m3`,`productionVolume`.`warehouseFk` AS `warehouseFk` from `productionVolume` where ((`productionVolume`.`created` > (vn.VN_NOW() + interval -(1) hour)) and (`productionVolume`.`warehouseFk` in (1,44,60))) group by `productionVolume`.`warehouseFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96497,6 +80546,25 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `routesReduced` +-- + +/*!50001 DROP TABLE IF EXISTS `routesReduced`*/; +/*!50001 DROP VIEW IF EXISTS `routesReduced`*/; +/*!50001 SET @saved_cs_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_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `routesReduced` AS select `et`.`description` AS `description`,`rm`.`name` AS `name`,`t`.`routeFk` AS `routeFk`,`et`.`ETD` AS `ETD`,`rm`.`bufferFk` AS `bufferFk`,`rm`.`beachFk` AS `beachFk`,`i`.`itemPackingTypeFk` AS `itempackingTypeFk` from (((((((`vn`.`expeditionTruck` `et` join `vn`.`routesMonitor` `rm` on((`rm`.`expeditionTruckFk` = `et`.`id`))) join `vn`.`ticket` `t` on((`t`.`routeFk` = `rm`.`routeFk`))) join `vn`.`ticketState` `ts` on((`ts`.`ticketFk` = `t`.`id`))) join `vn`.`state` `st` on((`st`.`id` = `ts`.`stateFk`))) join `vn`.`sale` `s` on((`s`.`ticketFk` = `t`.`id`))) join `vn`.`item` `i` on((`i`.`id` = `s`.`itemFk`))) join `vn`.`config` `c`) where (`et`.`ETD` > `util`.`yesterday`()) group by `t`.`routeFk` order by `et`.`ETD`,`t`.`routeFk` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `saleCost` -- @@ -96511,7 +80579,26 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `saleCost` AS select `s`.`itemFk` AS `itemFk`,`s`.`ticketFk` AS `ticketFk`,`s`.`concept` AS `concept`,`s`.`quantity` AS `quantity`,`s`.`discount` AS `discount`,`s`.`price` AS `price`,`c`.`name` AS `component`,`sc`.`value` AS `coste` from (((`sale` `s` join `saleComponent` `sc` on(`sc`.`saleFk` = `s`.`id`)) join `component` `c` on(`c`.`id` = `sc`.`componentFk`)) join `componentType` `ct` on(`ct`.`id` = `c`.`typeFk`)) where `ct`.`type` = 'coste' */; +/*!50001 VIEW `saleCost` AS select `s`.`itemFk` AS `itemFk`,`s`.`ticketFk` AS `ticketFk`,`s`.`concept` AS `concept`,`s`.`quantity` AS `quantity`,`s`.`discount` AS `discount`,`s`.`price` AS `price`,`c`.`name` AS `component`,`sc`.`value` AS `coste` from (((`sale` `s` join `saleComponent` `sc` on((`sc`.`saleFk` = `s`.`id`))) join `component` `c` on((`c`.`id` = `sc`.`componentFk`))) join `componentType` `ct` on((`ct`.`id` = `c`.`typeFk`))) where (`ct`.`type` = 'coste') */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `saleLabel` +-- + +/*!50001 DROP TABLE IF EXISTS `saleLabel`*/; +/*!50001 DROP VIEW IF EXISTS `saleLabel`*/; +/*!50001 SET @saved_cs_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_unicode_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `saleLabel` AS select `ml`.`Id_movimiento` AS `saleFk`,`ml`.`label` AS `label`,`ml`.`stem` AS `stem`,`ml`.`created` AS `created` from `vn2008`.`movement_label` `ml` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96530,26 +80617,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `saleMistakeList` AS select `st`.`saleFk` AS `saleFk`,`st`.`workerFk` AS `workerFk`,concat(`w2`.`firstName`,' ',`w2`.`lastName`) AS `sacador`,`st`.`created` AS `created`,concat(`w`.`firstName`,' ',`w`.`lastName`) AS `revisador`,`mt`.`description` AS `description`,`sm`.`created` AS `controlled` from (((((`vn`.`saleTracking` `st` join `vn`.`worker` `w2` on(`w2`.`id` = `st`.`workerFk`)) join `vncontrol`.`accion` `a` on(`a`.`accion_id` = `st`.`actionFk` and `a`.`accion` = 'SACAR')) left join `vn`.`saleMistake` `sm` on(`st`.`saleFk` = `sm`.`saleFk`)) left join `vn`.`mistakeType` `mt` on(`mt`.`id` = `sm`.`typeFk`)) left join `vn`.`worker` `w` on(`w`.`id` = `sm`.`userFk`)) */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `saleMistake_list__` --- - -/*!50001 DROP TABLE IF EXISTS `saleMistake_list__`*/; -/*!50001 DROP VIEW IF EXISTS `saleMistake_list__`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `saleMistake_list__` AS select `st`.`saleFk` AS `saleFk`,concat(`w2`.`firstName`,' ',`w2`.`lastName`) AS `sacador`,`st`.`created` AS `created`,concat(`w`.`firstName`,' ',`w`.`lastName`) AS `revisador`,`mt`.`description` AS `description`,`sm`.`created` AS `controlled` from (((((`vn`.`saleTracking` `st` join `vn`.`worker` `w2` on(`w2`.`id` = `st`.`workerFk`)) join `vncontrol`.`accion` `a` on(`a`.`accion_id` = `st`.`actionFk` and `a`.`accion` = 'SACAR')) left join `vn`.`saleMistake` `sm` on(`st`.`saleFk` = `sm`.`saleFk`)) left join `vn`.`mistakeType` `mt` on(`mt`.`id` = `sm`.`typeFk`)) left join `vn`.`worker` `w` on(`w`.`id` = `sm`.`userFk`)) where `st`.`created` > '2020-10-01' */; +/*!50001 VIEW `saleMistakeList` AS select `st`.`saleFk` AS `saleFk`,`st`.`workerFk` AS `workerFk`,concat(`w2`.`firstName`,' ',`w2`.`lastName`) AS `sacador`,`st`.`created` AS `created`,concat(`w`.`firstName`,' ',`w`.`lastName`) AS `revisador`,`mt`.`description` AS `description`,`sm`.`created` AS `controlled` from (((((`vn`.`saleTracking` `st` join `vn`.`worker` `w2` on((`w2`.`id` = `st`.`workerFk`))) join `vncontrol`.`accion` `a` on(((`a`.`accion_id` = `st`.`actionFk`) and (`a`.`accion` = 'SACAR')))) left join `vn`.`saleMistake` `sm` on((`st`.`saleFk` = `sm`.`saleFk`))) left join `vn`.`mistakeType` `mt` on((`mt`.`id` = `sm`.`typeFk`))) left join `vn`.`worker` `w` on((`w`.`id` = `sm`.`userFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96568,7 +80636,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `saleMistake_list__2` AS select `st`.`saleFk` AS `saleFk`,`st`.`workerFk` AS `workerFk`,concat(`w2`.`firstName`,' ',`w2`.`lastName`) AS `sacador`,`st`.`created` AS `created`,concat(`w`.`firstName`,' ',`w`.`lastName`) AS `revisador`,`mt`.`description` AS `description`,`sm`.`created` AS `controlled` from (((((`vn`.`saleTracking` `st` join `vn`.`worker` `w2` on(`w2`.`id` = `st`.`workerFk`)) join `vncontrol`.`accion` `a` on(`a`.`accion_id` = `st`.`actionFk` and `a`.`accion` = 'SACAR')) left join `vn`.`saleMistake` `sm` on(`st`.`saleFk` = `sm`.`saleFk`)) left join `vn`.`mistakeType` `mt` on(`mt`.`id` = `sm`.`typeFk`)) left join `vn`.`worker` `w` on(`w`.`id` = `sm`.`userFk`)) */; +/*!50001 VIEW `saleMistake_list__2` AS select `st`.`saleFk` AS `saleFk`,`st`.`workerFk` AS `workerFk`,concat(`w2`.`firstName`,' ',`w2`.`lastName`) AS `sacador`,`st`.`created` AS `created`,concat(`w`.`firstName`,' ',`w`.`lastName`) AS `revisador`,`mt`.`description` AS `description`,`sm`.`created` AS `controlled` from (((((`vn`.`saleTracking` `st` join `vn`.`worker` `w2` on((`w2`.`id` = `st`.`workerFk`))) join `vncontrol`.`accion` `a` on(((`a`.`accion_id` = `st`.`actionFk`) and (`a`.`accion` = 'SACAR')))) left join `vn`.`saleMistake` `sm` on((`st`.`saleFk` = `sm`.`saleFk`))) left join `vn`.`mistakeType` `mt` on((`mt`.`id` = `sm`.`typeFk`))) left join `vn`.`worker` `w` on((`w`.`id` = `sm`.`userFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96587,7 +80655,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `saleSaleTracking` AS select distinct `st`.`saleFk` AS `saleFk` from `saleTracking` `st` where `st`.`created` >= util.VN_CURDATE() + interval -1 day */; +/*!50001 VIEW `saleSaleTracking` AS select distinct `st`.`saleFk` AS `saleFk` from `saleTracking` `st` where (`st`.`created` >= (vn.VN_CURDATE() + interval -(1) day)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96606,7 +80674,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `saleValue` AS select `wh`.`name` AS `warehouse`,`c`.`name` AS `client`,`c`.`typeFk` AS `clientTypeFk`,`u`.`name` AS `buyer`,`it`.`id` AS `itemTypeFk`,`it`.`name` AS `family`,`s`.`itemFk` AS `itemFk`,`s`.`concept` AS `concept`,`s`.`quantity` AS `quantity`,`b`.`buyingValue` + `b`.`freightValue` + `b`.`comissionValue` + `b`.`packageValue` AS `cost`,(`b`.`buyingValue` + `b`.`freightValue` + `b`.`comissionValue` + `b`.`packageValue`) * `s`.`quantity` AS `value`,`tm`.`year` AS `year`,`tm`.`week` AS `week` from (((((((((`vn`.`sale` `s` join `vn`.`item` `i` on(`i`.`id` = `s`.`itemFk`)) join `vn`.`itemType` `it` on(`it`.`id` = `i`.`typeFk`)) join `account`.`user` `u` on(`u`.`id` = `it`.`workerFk`)) join `vn`.`ticket` `t` on(`t`.`id` = `s`.`ticketFk`)) join `vn`.`client` `c` on(`c`.`id` = `t`.`clientFk`)) join `vn`.`warehouse` `wh` on(`wh`.`id` = `t`.`warehouseFk`)) join `vn`.`time` `tm` on(`tm`.`dated` = cast(`t`.`shipped` as date))) join `cache`.`last_buy` `lb` on(`lb`.`item_id` = `i`.`id` and `lb`.`warehouse_id` = `wh`.`id`)) join `vn`.`buy` `b` on(`b`.`id` = `lb`.`buy_id`)) where `wh`.`isManaged` <> 0 */; +/*!50001 VIEW `saleValue` AS select `wh`.`name` AS `warehouse`,`c`.`name` AS `client`,`c`.`typeFk` AS `clientTypeFk`,`u`.`name` AS `buyer`,`it`.`id` AS `itemTypeFk`,`it`.`name` AS `family`,`s`.`itemFk` AS `itemFk`,`s`.`concept` AS `concept`,`s`.`quantity` AS `quantity`,(((`b`.`buyingValue` + `b`.`freightValue`) + `b`.`comissionValue`) + `b`.`packageValue`) AS `cost`,((((`b`.`buyingValue` + `b`.`freightValue`) + `b`.`comissionValue`) + `b`.`packageValue`) * `s`.`quantity`) AS `value`,`tm`.`year` AS `year`,`tm`.`week` AS `week` from (((((((((`vn`.`sale` `s` join `vn`.`item` `i` on((`i`.`id` = `s`.`itemFk`))) join `vn`.`itemType` `it` on((`it`.`id` = `i`.`typeFk`))) join `account`.`user` `u` on((`u`.`id` = `it`.`workerFk`))) join `vn`.`ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `vn`.`client` `c` on((`c`.`id` = `t`.`clientFk`))) join `vn`.`warehouse` `wh` on((`wh`.`id` = `t`.`warehouseFk`))) join `vn`.`time` `tm` on((`tm`.`dated` = cast(`t`.`shipped` as date)))) join `cache`.`last_buy` `lb` on(((`lb`.`item_id` = `i`.`id`) and (`lb`.`warehouse_id` = `wh`.`id`)))) join `vn`.`buy` `b` on((`b`.`id` = `lb`.`buy_id`))) where (`wh`.`isManaged` <> 0) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96625,7 +80693,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `saleVolume` AS select `s`.`ticketFk` AS `ticketFk`,`s`.`id` AS `saleFk`,round(`ic`.`cm3delivery` * `s`.`quantity` / 1000,0) AS `litros`,`t`.`routeFk` AS `routeFk`,`t`.`shipped` AS `shipped`,`t`.`landed` AS `landed`,`s`.`quantity` * `ic`.`cm3delivery` / 1000000 AS `volume`,`s`.`quantity` * `ic`.`grams` / 1000 AS `physicalWeight`,`s`.`quantity` * `ic`.`cm3delivery` * greatest(`i`.`density`,167) / 1000000 AS `weight`,`s`.`quantity` * `ic`.`cm3delivery` / 1000000 AS `physicalVolume`,`s`.`quantity` * `ic`.`cm3delivery` * ifnull(`t`.`zonePrice`,`z`.`price`) / (`vc`.`standardFlowerBox` * 1000) AS `freight`,`t`.`zoneFk` AS `zoneFk`,`t`.`clientFk` AS `clientFk`,`s`.`isPicked` AS `isPicked`,`s`.`quantity` * `s`.`price` * (100 - `s`.`discount`) / 100 AS `eurosValue`,`i`.`itemPackingTypeFk` AS `itemPackingTypeFk` from (((((`sale` `s` join `item` `i` on(`i`.`id` = `s`.`itemFk`)) join `ticket` `t` on(`t`.`id` = `s`.`ticketFk`)) join `zone` `z` on(`z`.`id` = `t`.`zoneFk`)) join `volumeConfig` `vc`) join `itemCost` `ic` on(`ic`.`itemFk` = `s`.`itemFk` and `ic`.`warehouseFk` = `t`.`warehouseFk`)) where `s`.`quantity` > 0 */; +/*!50001 VIEW `saleVolume` AS select `s`.`ticketFk` AS `ticketFk`,`s`.`id` AS `saleFk`,round(((`ic`.`cm3delivery` * `s`.`quantity`) / 1000),0) AS `litros`,`t`.`routeFk` AS `routeFk`,`t`.`shipped` AS `shipped`,`t`.`landed` AS `landed`,((`s`.`quantity` * `ic`.`cm3delivery`) / 1000000) AS `volume`,((`s`.`quantity` * `ic`.`grams`) / 1000) AS `physicalWeight`,(((`s`.`quantity` * `ic`.`cm3delivery`) * greatest(`i`.`density`,167)) / 1000000) AS `weight`,((`s`.`quantity` * `ic`.`cm3delivery`) / 1000000) AS `physicalVolume`,(((`s`.`quantity` * `ic`.`cm3delivery`) * ifnull(`t`.`zonePrice`,`z`.`price`)) / (`vc`.`standardFlowerBox` * 1000)) AS `freight`,`t`.`zoneFk` AS `zoneFk`,`t`.`clientFk` AS `clientFk`,`s`.`isPicked` AS `isPicked`,(((`s`.`quantity` * `s`.`price`) * (100 - `s`.`discount`)) / 100) AS `eurosValue`,`i`.`itemPackingTypeFk` AS `itemPackingTypeFk` from (((((`sale` `s` join `item` `i` on((`i`.`id` = `s`.`itemFk`))) join `ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `zone` `z` on((`z`.`id` = `t`.`zoneFk`))) join `volumeConfig` `vc`) join `itemCost` `ic` on(((`ic`.`itemFk` = `s`.`itemFk`) and (`ic`.`warehouseFk` = `t`.`warehouseFk`)))) where (`s`.`quantity` > 0) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96644,7 +80712,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `saleVolume_Today_VNH` AS select `t`.`nickname` AS `Cliente`,`p`.`name` AS `Provincia`,`c`.`country` AS `Pais`,cast(sum(`sv`.`volume`) as decimal(5,1)) AS `volume` from (((((`saleVolume` `sv` join `ticket` `t` on(`t`.`id` = `sv`.`ticketFk`)) join `address` `a` on(`a`.`id` = `t`.`addressFk`)) join `province` `p` on(`p`.`id` = `a`.`provinceFk`)) join `country` `c` on(`c`.`id` = `p`.`countryFk`)) join `warehouse` `w` on(`w`.`id` = `t`.`warehouseFk`)) where `w`.`name` = 'VNH' and `t`.`shipped` between util.VN_CURDATE() and `util`.`dayend`(util.VN_CURDATE()) group by `t`.`nickname`,`p`.`name` */; +/*!50001 VIEW `saleVolume_Today_VNH` AS select `t`.`nickname` AS `Cliente`,`p`.`name` AS `Provincia`,`c`.`country` AS `Pais`,cast(sum(`sv`.`volume`) as decimal(5,1)) AS `volume` from (((((`saleVolume` `sv` join `ticket` `t` on((`t`.`id` = `sv`.`ticketFk`))) join `address` `a` on((`a`.`id` = `t`.`addressFk`))) join `province` `p` on((`p`.`id` = `a`.`provinceFk`))) join `country` `c` on((`c`.`id` = `p`.`countryFk`))) join `warehouse` `w` on((`w`.`id` = `t`.`warehouseFk`))) where ((`w`.`name` = 'VNH') and (`t`.`shipped` between vn.VN_CURDATE() and `util`.`dayend`(vn.VN_CURDATE()))) group by `t`.`nickname`,`p`.`name` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96663,7 +80731,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `sale_freightComponent` AS select `t`.`id` AS `ticketFk`,`sc`.`value` * `s`.`quantity` AS `amount`,`t`.`shipped` AS `shipped` from ((((`ticket` `t` straight_join `sale` `s` on(`t`.`id` = `s`.`ticketFk`)) join `saleComponent` `sc` on(`sc`.`saleFk` = `s`.`id`)) join `component` `c` on(`c`.`id` = `sc`.`componentFk`)) join `componentType` `ct` on(`ct`.`id` = `c`.`typeFk` and `ct`.`type` = 'agencia')) */; +/*!50001 VIEW `sale_freightComponent` AS select `t`.`id` AS `ticketFk`,(`sc`.`value` * `s`.`quantity`) AS `amount`,`t`.`shipped` AS `shipped` from ((((`ticket` `t` straight_join `sale` `s` on((`t`.`id` = `s`.`ticketFk`))) join `saleComponent` `sc` on((`sc`.`saleFk` = `s`.`id`))) join `component` `c` on((`c`.`id` = `sc`.`componentFk`))) join `componentType` `ct` on(((`ct`.`id` = `c`.`typeFk`) and (`ct`.`type` = 'agencia')))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96682,7 +80750,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `salesPersonSince` AS select `p`.`id_trabajador` AS `workerFk`,min(`b`.`date_start`) AS `started` from ((((`postgresql`.`person` `p` join `postgresql`.`profile` `pr` on(`pr`.`person_id` = `p`.`person_id`)) left join `postgresql`.`business` `b` on(`pr`.`profile_id` = `b`.`client_id`)) left join `postgresql`.`business_labour` `bl` on(`b`.`business_id` = `bl`.`business_id`)) join `postgresql`.`professional_category` `pc` on(`pc`.`professional_category_id` = `bl`.`professional_category_id`)) where `pc`.`category_name` = 'Aux ventas' group by `p`.`id_trabajador` */; +/*!50001 VIEW `salesPersonSince` AS select `p`.`id_trabajador` AS `workerFk`,min(`b`.`date_start`) AS `started` from ((((`postgresql`.`person` `p` join `postgresql`.`profile` `pr` on((`pr`.`person_id` = `p`.`person_id`))) left join `postgresql`.`business` `b` on((`pr`.`profile_id` = `b`.`client_id`))) left join `postgresql`.`business_labour` `bl` on((`b`.`business_id` = `bl`.`business_id`))) join `postgresql`.`professional_category` `pc` on((`pc`.`professional_category_id` = `bl`.`professional_category_id`))) where (`pc`.`category_name` = 'Aux ventas') group by `p`.`id_trabajador` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96701,7 +80769,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `salesPreparedLastHour` AS select `t`.`warehouseFk` AS `warehouseFk`,`st`.`saleFk` AS `saleFk`,`st`.`isChecked` AS `isChecked`,`st`.`originalQuantity` AS `originalQuantity`,`a`.`accion` AS `accion`,`st`.`created` AS `created`,`e`.`code` AS `code`,`w`.`firstName` AS `firstname`,`w`.`lastName` AS `lastName`,`w`.`code` AS `workerCode`,`ic`.`cm3delivery` * `s`.`quantity` / 1000 AS `litros`,`s`.`concept` AS `concept`,`d`.`name` AS `departmentName` from (((((((((`vn`.`saleTracking` `st` left join `vn`.`salesPreviousPreparated` `prevPrepSales` on(`prevPrepSales`.`saleFk` = `st`.`saleFk`)) join `vn`.`sale` `s` on(`s`.`id` = `st`.`saleFk`)) join `vn`.`ticket` `t` on(`t`.`id` = `s`.`ticketFk`)) join `vn`.`itemCost` `ic` on(`ic`.`warehouseFk` = `t`.`warehouseFk` and `ic`.`itemFk` = `s`.`itemFk`)) join `vn`.`worker` `w` on(`w`.`id` = `st`.`workerFk`)) join `vn`.`state` `e` on(`e`.`id` = `st`.`stateFk`)) join `vncontrol`.`accion` `a` on(`a`.`accion_id` = `st`.`actionFk`)) join `vn`.`workerDepartment` `wd` on(`wd`.`workerFk` = `st`.`workerFk`)) join `vn`.`department` `d` on(`d`.`id` = `wd`.`departmentFk`)) where `st`.`created` > current_timestamp() + interval -1 hour and `prevPrepSales`.`saleFk` is null and `d`.`name` not like 'EQUIPO%' */; +/*!50001 VIEW `salesPreparedLastHour` AS select `t`.`warehouseFk` AS `warehouseFk`,`st`.`saleFk` AS `saleFk`,`st`.`isChecked` AS `isChecked`,`st`.`originalQuantity` AS `originalQuantity`,`a`.`accion` AS `accion`,`st`.`created` AS `created`,`e`.`code` AS `code`,`w`.`firstName` AS `firstname`,`w`.`lastName` AS `lastName`,`w`.`code` AS `workerCode`,((`ic`.`cm3delivery` * `s`.`quantity`) / 1000) AS `litros`,`s`.`concept` AS `concept`,`d`.`name` AS `departmentName` from (((((((((`vn`.`saleTracking` `st` left join `vn`.`salesPreviousPreparated` `prevPrepSales` on((`prevPrepSales`.`saleFk` = `st`.`saleFk`))) join `vn`.`sale` `s` on((`s`.`id` = `st`.`saleFk`))) join `vn`.`ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `vn`.`itemCost` `ic` on(((`ic`.`warehouseFk` = `t`.`warehouseFk`) and (`ic`.`itemFk` = `s`.`itemFk`)))) join `vn`.`worker` `w` on((`w`.`id` = `st`.`workerFk`))) join `vn`.`state` `e` on((`e`.`id` = `st`.`stateFk`))) join `vncontrol`.`accion` `a` on((`a`.`accion_id` = `st`.`actionFk`))) join `vn`.`workerDepartment` `wd` on((`wd`.`workerFk` = `st`.`workerFk`))) join `vn`.`department` `d` on((`d`.`id` = `wd`.`departmentFk`))) where ((`st`.`created` > (vn.VN_NOW() + interval -(1) hour)) and isnull(`prevPrepSales`.`saleFk`) and (not((`d`.`name` like 'EQUIPO%')))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96720,7 +80788,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `salesPreviousPreparated` AS select `st`.`saleFk` AS `saleFk` from (`saleTracking` `st` join `state` `e` on(`e`.`id` = `st`.`stateFk`)) where `st`.`created` > util.VN_CURDATE() and `e`.`code` like 'PREVIOUS_PREPARATION' */; +/*!50001 VIEW `salesPreviousPreparated` AS select `st`.`saleFk` AS `saleFk` from (`saleTracking` `st` join `state` `e` on((`e`.`id` = `st`.`stateFk`))) where ((`st`.`created` > vn.VN_CURDATE()) and (`e`.`code` like 'PREVIOUS_PREPARATION')) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96739,7 +80807,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` 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 `warehouse`,`b`.`buyingValue` AS `buyingValue` 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` <> 0 */; +/*!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 `warehouse`,`b`.`buyingValue` AS `buyingValue` 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 */; @@ -96758,26 +80826,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `tagL10n` AS select `t`.`id` AS `id`,ifnull(`i`.`name`,`t`.`name`) AS `name` from (`tag` `t` left join `tagI18n` `i` on(`i`.`tagFk` = `t`.`id` and `i`.`lang` = `util`.`LANG`())) */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `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 = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` 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',convert(right(`t`.`routeFk`,3) using utf8)),`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(current_timestamp() + 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`.`zoneEstimatedDelivery` `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`(util.VN_CURDATE()) */; +/*!50001 VIEW `tagL10n` AS select `t`.`id` AS `id`,ifnull(`i`.`name`,`t`.`name`) AS `name` from (`tag` `t` left join `tagI18n` `i` on(((`i`.`tagFk` = `t`.`id`) and (`i`.`lang` = `util`.`LANG`())))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96815,7 +80864,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `ticketLastUpdatedList` AS select `s`.`ticketFk` AS `ticketFk`,`st`.`created` AS `created` from (`vn`.`saleTracking` `st` join `vn`.`sale` `s` on((`s`.`id` = `st`.`saleFk`))) where (`st`.`created` > curdate()) union all select `i`.`Id_Ticket` AS `Id_Ticket`,`i`.`odbc_date` AS `odbc_date` from `vncontrol`.`inter` `i` where (`i`.`odbc_date` > curdate()) union all select `s`.`ticketFk` AS `ticketFk`,`iss`.`created` AS `created` from (`vn`.`itemShelvingSale` `iss` join `vn`.`sale` `s` on((`s`.`id` = `iss`.`saleFk`))) where (`iss`.`created` > curdate()) */; +/*!50001 VIEW `ticketLastUpdatedList` AS select `s`.`ticketFk` AS `ticketFk`,`st`.`created` AS `created` from (`vn`.`saleTracking` `st` join `vn`.`sale` `s` on((`s`.`id` = `st`.`saleFk`))) where (`st`.`created` > vn.VN_CURDATE()) union all select `i`.`Id_Ticket` AS `Id_Ticket`,`i`.`odbc_date` AS `odbc_date` from `vncontrol`.`inter` `i` where (`i`.`odbc_date` > vn.VN_CURDATE()) union all select `s`.`ticketFk` AS `ticketFk`,`iss`.`created` AS `created` from (`vn`.`itemShelvingSale` `iss` join `vn`.`sale` `s` on((`s`.`id` = `iss`.`saleFk`))) where (`iss`.`created` > vn.VN_CURDATE()) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96872,7 +80921,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `ticketNotInvoiced` AS select `t`.`companyFk` AS `companyFk`,`cm`.`code` AS `companyCode`,`t`.`clientFk` AS `clientFk`,`c`.`name` AS `clientName`,`t`.`shipped` AS `shipped`,cast(sum(`s`.`quantity` * `s`.`price` * (100 - `s`.`discount`) / 100) as decimal(10,2)) AS `value` from (((`ticket` `t` join `sale` `s` on(`s`.`ticketFk` = `t`.`id`)) join `client` `c` on(`c`.`id` = `t`.`clientFk`)) join `company` `cm` on(`cm`.`id` = `t`.`companyFk`)) where `t`.`refFk` is null and `t`.`shipped` > '2017-01-01' group by `t`.`id` */; +/*!50001 VIEW `ticketNotInvoiced` AS select `t`.`companyFk` AS `companyFk`,`cm`.`code` AS `companyCode`,`t`.`clientFk` AS `clientFk`,`c`.`name` AS `clientName`,`t`.`shipped` AS `shipped`,cast(sum((((`s`.`quantity` * `s`.`price`) * (100 - `s`.`discount`)) / 100)) as decimal(10,2)) AS `value` from (((`ticket` `t` join `sale` `s` on((`s`.`ticketFk` = `t`.`id`))) join `client` `c` on((`c`.`id` = `t`.`clientFk`))) join `company` `cm` on((`cm`.`id` = `t`.`companyFk`))) where (isnull(`t`.`refFk`) and (`t`.`shipped` > '2017-01-01')) group by `t`.`id` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96891,7 +80940,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `ticketPackingList` AS select `t`.`nickname` AS `nickname`,`t`.`id` AS `ticketFk`,`am`.`name` AS `agencyMode`,`am`.`flag` AS `flag`,`p`.`name` AS `province`,`s`.`itemFk` AS `itemFk`,`s`.`concept` AS `concept`,`s`.`quantity` AS `quantity`,`sv`.`litros` AS `litros`,`to`.`description` AS `observaciones` from (((((((`ticket` `t` join `address` `a` on(`a`.`id` = `t`.`addressFk`)) join `province` `p` on(`p`.`id` = `a`.`provinceFk`)) join `agencyMode` `am` on(`am`.`id` = `t`.`agencyModeFk`)) left join `sale` `s` on(`s`.`ticketFk` = `t`.`id`)) left join `saleVolume` `sv` on(`sv`.`saleFk` = `s`.`id`)) join `observationType` `ot` on(`ot`.`code` = 'packager')) left join `ticketObservation` `to` on(`to`.`ticketFk` = `t`.`id` and `ot`.`id` = `to`.`observationTypeFk`)) */; +/*!50001 VIEW `ticketPackingList` AS select `t`.`nickname` AS `nickname`,`t`.`id` AS `ticketFk`,`am`.`name` AS `agencyMode`,`am`.`flag` AS `flag`,`p`.`name` AS `province`,`s`.`itemFk` AS `itemFk`,`s`.`concept` AS `concept`,`s`.`quantity` AS `quantity`,`sv`.`litros` AS `litros`,`to`.`description` AS `observaciones` from (((((((`ticket` `t` join `address` `a` on((`a`.`id` = `t`.`addressFk`))) join `province` `p` on((`p`.`id` = `a`.`provinceFk`))) join `agencyMode` `am` on((`am`.`id` = `t`.`agencyModeFk`))) left join `sale` `s` on((`s`.`ticketFk` = `t`.`id`))) left join `saleVolume` `sv` on((`sv`.`saleFk` = `s`.`id`))) join `observationType` `ot` on((`ot`.`code` = 'packager'))) left join `ticketObservation` `to` on(((`to`.`ticketFk` = `t`.`id`) and (`ot`.`id` = `to`.`observationTypeFk`)))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96910,7 +80959,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `ticketPreviousPreparingList` AS select `s`.`ticketFk` AS `ticketFk`,`w`.`code` AS `code`,count(`s`.`id`) AS `saleLines`,sum(`s`.`isPicked` <> 0) AS `alreadyMadeSaleLines`,sum(`s`.`isPicked` <> 0) / count(`s`.`id`) AS `madeRate`,`sg`.`created` AS `created`,`p`.`code` AS `parking`,`iss`.`sectorFk` AS `sectorFk`,`al`.`code` AS `alertCode` from (((((((`vn`.`saleGroup` `sg` join `vn`.`saleGroupDetail` `sgd` on(`sgd`.`saleGroupFk` = `sg`.`id`)) join `vn`.`sale` `s` on(`s`.`id` = `sgd`.`saleFk`)) join `vn`.`ticketState` `tls` on(`tls`.`ticketFk` = `s`.`ticketFk`)) join `vn`.`alertLevel` `al` on(`al`.`id` = `tls`.`alertLevel`)) join `vn`.`worker` `w` on(`w`.`id` = `sg`.`userFk`)) left join `vn`.`parking` `p` on(`p`.`id` = `sg`.`parkingFk`)) join `vn`.`itemShelvingStock` `iss` on(`iss`.`itemFk` = `s`.`itemFk`)) where `sg`.`created` >= util.VN_CURDATE() + interval 0.1 day group by `sg`.`id` */; +/*!50001 VIEW `ticketPreviousPreparingList` AS select `s`.`ticketFk` AS `ticketFk`,`w`.`code` AS `code`,count(`s`.`id`) AS `saleLines`,sum((`s`.`isPicked` <> 0)) AS `alreadyMadeSaleLines`,(sum((`s`.`isPicked` <> 0)) / count(`s`.`id`)) AS `madeRate`,`sg`.`created` AS `created`,`p`.`code` AS `parking`,`iss`.`sectorFk` AS `sectorFk`,`al`.`code` AS `alertCode` from (((((((`vn`.`saleGroup` `sg` join `vn`.`saleGroupDetail` `sgd` on((`sgd`.`saleGroupFk` = `sg`.`id`))) join `vn`.`sale` `s` on((`s`.`id` = `sgd`.`saleFk`))) join `vn`.`ticketState` `tls` on((`tls`.`ticketFk` = `s`.`ticketFk`))) join `vn`.`alertLevel` `al` on((`al`.`id` = `tls`.`alertLevel`))) join `vn`.`worker` `w` on((`w`.`id` = `sg`.`userFk`))) left join `vn`.`parking` `p` on((`p`.`id` = `sg`.`parkingFk`))) join `vn`.`itemShelvingStock` `iss` on((`iss`.`itemFk` = `s`.`itemFk`))) where (`sg`.`created` >= (vn.VN_CURDATE() + interval 0.1 day)) group by `sg`.`id` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96929,7 +80978,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `ticketState` AS select `i`.`odbc_date` AS `updated`,`i`.`state_id` AS `stateFk`,`i`.`Id_Trabajador` AS `workerFk`,`tls`.`ticketFk` AS `ticketFk`,`s`.`id` AS `state`,`s`.`order` AS `productionOrder`,`s`.`alertLevel` AS `alertLevel`,`s`.`code` AS `code`,`tls`.`ticketFk` AS `ticket`,`i`.`Id_Trabajador` AS `worker`,`s`.`isPreviousPreparable` AS `isPreviousPreparable`,`s`.`isPicked` AS `isPicked` from ((`vn`.`ticketLastState` `tls` join `vncontrol`.`inter` `i` on(`i`.`inter_id` = `tls`.`ticketTrackingFk`)) join `vn`.`state` `s` on(`s`.`id` = `i`.`state_id`)) */; +/*!50001 VIEW `ticketState` AS select `i`.`odbc_date` AS `updated`,`i`.`state_id` AS `stateFk`,`i`.`Id_Trabajador` AS `workerFk`,`tls`.`ticketFk` AS `ticketFk`,`s`.`id` AS `state`,`s`.`order` AS `productionOrder`,`s`.`alertLevel` AS `alertLevel`,`s`.`code` AS `code`,`tls`.`ticketFk` AS `ticket`,`i`.`Id_Trabajador` AS `worker`,`s`.`isPreviousPreparable` AS `isPreviousPreparable`,`s`.`isPicked` AS `isPicked` from ((`vn`.`ticketLastState` `tls` join `vncontrol`.`inter` `i` on((`i`.`inter_id` = `tls`.`ticketTrackingFk`))) join `vn`.`state` `s` on((`s`.`id` = `i`.`state_id`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -96948,7 +80997,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `ticketStateToday` AS select `ts`.`ticket` AS `ticket`,`ts`.`state` AS `state`,`ts`.`productionOrder` AS `productionOrder`,`ts`.`alertLevel` AS `alertLevel`,`ts`.`worker` AS `worker`,`ts`.`code` AS `code`,`ts`.`updated` AS `updated`,`ts`.`isPicked` AS `isPicked` from (`vn`.`ticketState` `ts` join `vn`.`ticket` `t` on(`t`.`id` = `ts`.`ticket`)) where `t`.`shipped` between util.VN_CURDATE() and `MIDNIGHT`(util.VN_CURDATE()) */; +/*!50001 VIEW `ticketStateToday` AS select `ts`.`ticket` AS `ticket`,`ts`.`state` AS `state`,`ts`.`productionOrder` AS `productionOrder`,`ts`.`alertLevel` AS `alertLevel`,`ts`.`worker` AS `worker`,`ts`.`code` AS `code`,`ts`.`updated` AS `updated`,`ts`.`isPicked` AS `isPicked` from (`vn`.`ticketState` `ts` join `vn`.`ticket` `t` on((`t`.`id` = `ts`.`ticket`))) where (`t`.`shipped` between vn.VN_CURDATE() and `MIDNIGHT`(vn.VN_CURDATE())) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97005,7 +81054,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `traceabilityBuy` AS select `b`.`id` AS `buyFk`,`b`.`quantity` AS `quantity`,`tr`.`landed` AS `landed`,`w`.`name` AS `warehouseName`,`b`.`entryFk` AS `entryFk`,`s`.`name` AS `supplierName`,ifnull(`b`.`itemOriginalFk`,`b`.`itemFk`) AS `itemFk` from ((((`buy` `b` join `entry` `e` on(`e`.`id` = `b`.`entryFk`)) join `travel` `tr` on(`tr`.`id` = `e`.`travelFk`)) join `supplier` `s` on(`s`.`id` = `e`.`supplierFk`)) join `warehouse` `w` on(`w`.`id` = `tr`.`warehouseInFk`)) */; +/*!50001 VIEW `traceabilityBuy` AS select `b`.`id` AS `buyFk`,`b`.`quantity` AS `quantity`,`tr`.`landed` AS `landed`,`w`.`name` AS `warehouseName`,`b`.`entryFk` AS `entryFk`,`s`.`name` AS `supplierName`,ifnull(`b`.`itemOriginalFk`,`b`.`itemFk`) AS `itemFk` from ((((`buy` `b` join `entry` `e` on((`e`.`id` = `b`.`entryFk`))) join `travel` `tr` on((`tr`.`id` = `e`.`travelFk`))) join `supplier` `s` on((`s`.`id` = `e`.`supplierFk`))) join `warehouse` `w` on((`w`.`id` = `tr`.`warehouseInFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97024,7 +81073,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `traceabilitySale` AS select `s`.`ticketFk` AS `ticketFk`,`sb`.`buyFk` AS `buyFk`,`t`.`shipped` AS `shipped`,`t`.`nickname` AS `nickname`,`s`.`quantity` AS `quantity`,concat(`w`.`firstName`,' ',`w`.`lastName`) AS `worker` from (((`saleBuy` `sb` join `sale` `s` on(`s`.`id` = `sb`.`saleFk`)) join `ticket` `t` on(`t`.`id` = `s`.`ticketFk`)) join `worker` `w` on(`w`.`id` = `sb`.`workerFk`)) */; +/*!50001 VIEW `traceabilitySale` AS select `s`.`ticketFk` AS `ticketFk`,`sb`.`buyFk` AS `buyFk`,`t`.`shipped` AS `shipped`,`t`.`nickname` AS `nickname`,`s`.`quantity` AS `quantity`,concat(`w`.`firstName`,' ',`w`.`lastName`) AS `worker` from (((`saleBuy` `sb` join `sale` `s` on((`s`.`id` = `sb`.`saleFk`))) join `ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `worker` `w` on((`w`.`id` = `sb`.`workerFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97062,7 +81111,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerBusinessDated` AS select `t`.`dated` AS `dated`,`b`.`business_id` AS `business_id`,`w`.`id` AS `workerFk` from ((((`vn`.`time` `t` left join `postgresql`.`business` `b` on(`t`.`dated` between `b`.`date_start` and ifnull(`b`.`date_end`,util.VN_CURDATE()))) left join `postgresql`.`profile` `pr` on(`b`.`client_id` = `pr`.`profile_id`)) left join `postgresql`.`person` `p` on(`pr`.`person_id` = `p`.`person_id`)) left join `vn`.`worker` `w` on(`p`.`id_trabajador` = `w`.`id`)) where `t`.`dated` > util.VN_CURDATE() + interval -2 year */; +/*!50001 VIEW `workerBusinessDated` AS select `t`.`dated` AS `dated`,`b`.`business_id` AS `business_id`,`w`.`id` AS `workerFk` from ((((`vn`.`time` `t` left join `postgresql`.`business` `b` on((`t`.`dated` between `b`.`date_start` and ifnull(`b`.`date_end`,vn.VN_CURDATE())))) left join `postgresql`.`profile` `pr` on((`b`.`client_id` = `pr`.`profile_id`))) left join `postgresql`.`person` `p` on((`pr`.`person_id` = `p`.`person_id`))) left join `vn`.`worker` `w` on((`p`.`id_trabajador` = `w`.`id`))) where (`t`.`dated` > (vn.VN_CURDATE() + interval -(2) year)) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97081,7 +81130,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerCalendar` AS select `ce`.`business_id` AS `businessFk`,`p`.`id_trabajador` AS `workerFk`,`ce`.`calendar_state_id` AS `absenceTypeFk`,`ce`.`date` AS `dated` from (((`postgresql`.`person` `p` join `postgresql`.`profile` `pr` on(`pr`.`person_id` = `p`.`person_id`)) join `postgresql`.`business` `b` on(`b`.`client_id` = `pr`.`profile_id`)) join `postgresql`.`calendar_employee` `ce` on(`ce`.`business_id` = `b`.`business_id`)) */; +/*!50001 VIEW `workerCalendar` AS select `ce`.`business_id` AS `businessFk`,`p`.`id_trabajador` AS `workerFk`,`ce`.`calendar_state_id` AS `absenceTypeFk`,`ce`.`date` AS `dated` from (((`postgresql`.`person` `p` join `postgresql`.`profile` `pr` on((`pr`.`person_id` = `p`.`person_id`))) join `postgresql`.`business` `b` on((`b`.`client_id` = `pr`.`profile_id`))) join `postgresql`.`calendar_employee` `ce` on((`ce`.`business_id` = `b`.`business_id`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97100,7 +81149,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerDepartment` AS select `p`.`id_trabajador` AS `workerFk`,`d`.`id` AS `departmentFk` from (((`postgresql`.`person` `p` join `postgresql`.`profile` `pr` on(`pr`.`person_id` = `p`.`person_id`)) left join (`postgresql`.`business` `b` left join `postgresql`.`business_labour` `bl` on(`b`.`business_id` = `bl`.`business_id`)) on(`pr`.`profile_id` = `b`.`client_id`)) join `vn`.`department` `d` on(`d`.`id` = `bl`.`department_id`)) where `b`.`date_end` is null and `b`.`date_start` <= util.VN_CURDATE() or `b`.`date_end` >= util.VN_CURDATE() and `b`.`date_start` <= util.VN_CURDATE() */; +/*!50001 VIEW `workerDepartment` AS select `p`.`id_trabajador` AS `workerFk`,`d`.`id` AS `departmentFk` from (((`postgresql`.`person` `p` join `postgresql`.`profile` `pr` on((`pr`.`person_id` = `p`.`person_id`))) left join (`postgresql`.`business` `b` left join `postgresql`.`business_labour` `bl` on((`b`.`business_id` = `bl`.`business_id`))) on((`pr`.`profile_id` = `b`.`client_id`))) join `vn`.`department` `d` on((`d`.`id` = `bl`.`department_id`))) where ((isnull(`b`.`date_end`) and (`b`.`date_start` <= vn.VN_CURDATE())) or ((`b`.`date_end` >= vn.VN_CURDATE()) and (`b`.`date_start` <= vn.VN_CURDATE()))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97119,7 +81168,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerDepartmentTest` AS select `p`.`workerFk` AS `workerFk`,`d`.`id` AS `departmentFk` from ((((`vn`.`person` `p` join `postgresql`.`profile` `pr` on(`pr`.`person_id` = `p`.`id`)) join `postgresql`.`business` `b` on(`b`.`client_id` = `pr`.`profile_id`)) join `postgresql`.`business_labour` `bl` on(`b`.`business_id` = `bl`.`business_id`)) join `vn`.`department` `d` on(`d`.`id` = `bl`.`department_id`)) where util.VN_CURDATE() between `b`.`date_start` and ifnull(`b`.`date_end`,util.VN_CURDATE()) */; +/*!50001 VIEW `workerDepartmentTest` AS select `p`.`workerFk` AS `workerFk`,`d`.`id` AS `departmentFk` from ((((`vn`.`person` `p` join `postgresql`.`profile` `pr` on((`pr`.`person_id` = `p`.`id`))) join `postgresql`.`business` `b` on((`b`.`client_id` = `pr`.`profile_id`))) join `postgresql`.`business_labour` `bl` on((`b`.`business_id` = `bl`.`business_id`))) join `vn`.`department` `d` on((`d`.`id` = `bl`.`department_id`))) where (vn.VN_CURDATE() between `b`.`date_start` and ifnull(`b`.`date_end`,vn.VN_CURDATE())) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97138,26 +81187,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerLabour` AS select `b`.`business_id` AS `businessFk`,`p`.`id_trabajador` AS `workerFk`,`bl`.`workcenter_id` AS `workCenterFk`,`b`.`date_start` AS `started`,`b`.`date_end` AS `ended`,`d`.`id` AS `departmentFk`,`b`.`payedHolidays` AS `payedHolidays` from ((((`postgresql`.`person` `p` join `postgresql`.`profile` `pr` on(`pr`.`person_id` = `p`.`person_id`)) join `postgresql`.`business` `b` on(`b`.`client_id` = `pr`.`profile_id`)) join `postgresql`.`business_labour` `bl` on(`b`.`business_id` = `bl`.`business_id`)) join `vn`.`department` `d` on(`d`.`id` = `bl`.`department_id`)) order by `b`.`date_start` 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 `workerMana__` --- - -/*!50001 DROP TABLE IF EXISTS `workerMana__`*/; -/*!50001 DROP VIEW IF EXISTS `workerMana__`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerMana__` AS select `ms`.`Id_Trabajador` AS `workerFk`,`ms`.`size` AS `size`,`ms`.`used` AS `amount`,`ms`.`prices_modifier_rate` AS `pricesModifierRate`,`ms`.`prices_modifier_activated` AS `isPricesModifierActivated`,`ms`.`minRate` AS `minRate`,`ms`.`maxRate` AS `maxRate` from `bs`.`mana_spellers` `ms` */; +/*!50001 VIEW `workerLabour` AS select `b`.`business_id` AS `businessFk`,`p`.`id_trabajador` AS `workerFk`,`bl`.`workcenter_id` AS `workCenterFk`,`b`.`date_start` AS `started`,`b`.`date_end` AS `ended`,`d`.`id` AS `departmentFk`,`b`.`payedHolidays` AS `payedHolidays` from ((((`postgresql`.`person` `p` join `postgresql`.`profile` `pr` on((`pr`.`person_id` = `p`.`person_id`))) join `postgresql`.`business` `b` on((`b`.`client_id` = `pr`.`profile_id`))) join `postgresql`.`business_labour` `bl` on((`b`.`business_id` = `bl`.`business_id`))) join `vn`.`department` `d` on((`d`.`id` = `bl`.`department_id`))) order by `b`.`date_start` desc */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97176,7 +81206,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerMedia` AS select `p`.`id_trabajador` AS `workerFk`,`m`.`value` AS `mediaValue` from ((((`postgresql`.`person` `p` join `postgresql`.`profile` `po` on(`po`.`person_id` = `p`.`person_id`)) join `postgresql`.`profile_media` `pom` on(`pom`.`profile_id` = `po`.`profile_id`)) join `postgresql`.`media` `m` on(`m`.`media_id` = `pom`.`media_id`)) join `postgresql`.`media_type` `mt` on(`mt`.`media_type_id` = `m`.`media_type_id`)) where `mt`.`name` = 'movil empresa' */; +/*!50001 VIEW `workerMedia` AS select `p`.`id_trabajador` AS `workerFk`,`m`.`value` AS `mediaValue` from ((((`postgresql`.`person` `p` join `postgresql`.`profile` `po` on((`po`.`person_id` = `p`.`person_id`))) join `postgresql`.`profile_media` `pom` on((`pom`.`profile_id` = `po`.`profile_id`))) join `postgresql`.`media` `m` on((`m`.`media_id` = `pom`.`media_id`))) join `postgresql`.`media_type` `mt` on((`mt`.`media_type_id` = `m`.`media_type_id`))) where (`mt`.`name` = 'movil empresa') */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97195,7 +81225,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerSpeedExpedition` AS select `sv`.`ticketFk` AS `ticketFk`,sum(`sv`.`litros`) AS `litros`,sum(if(`sub`.`started` > current_timestamp() + interval -1 hour,`sv`.`litros`,0)) AS `literLastHour`,cast(60 * sum(`sv`.`litros`) / time_to_sec(timediff(max(`sub`.`finished`),min(`sub`.`started`))) as decimal(10,1)) AS `litersByMinute`,`sub`.`code` AS `workerCode`,`sub`.`cajas` AS `cajas`,`sub`.`warehouseFk` AS `warehouseFk` from (`saleVolume` `sv` join `expeditionTimeExpended` `sub` on(`sub`.`ticketFk` = `sv`.`ticketFk`)) group by `sub`.`code` */; +/*!50001 VIEW `workerSpeedExpedition` AS select `sv`.`ticketFk` AS `ticketFk`,sum(`sv`.`litros`) AS `litros`,sum(if((`sub`.`started` > (vn.VN_NOW() + interval -(1) hour)),`sv`.`litros`,0)) AS `literLastHour`,cast(((60 * sum(`sv`.`litros`)) / time_to_sec(timediff(max(`sub`.`finished`),min(`sub`.`started`)))) as decimal(10,1)) AS `litersByMinute`,`sub`.`code` AS `workerCode`,`sub`.`cajas` AS `cajas`,`sub`.`warehouseFk` AS `warehouseFk` from (`saleVolume` `sv` join `expeditionTimeExpended` `sub` on((`sub`.`ticketFk` = `sv`.`ticketFk`))) group by `workerCode` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97214,7 +81244,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerSpeedSaleTracking` AS select `salesPreparedLastHour`.`warehouseFk` AS `warehouseFk`,`salesPreparedLastHour`.`accion` AS `accion`,`salesPreparedLastHour`.`workerCode` AS `workerCode`,sum(`salesPreparedLastHour`.`litros`) AS `sumaLitros`,min(`salesPreparedLastHour`.`created`) AS `started`,max(`salesPreparedLastHour`.`created`) AS `finished`,sum(if(`salesPreparedLastHour`.`created` >= current_timestamp() + interval -1 hour,`salesPreparedLastHour`.`litros`,0)) AS `sumaLitrosLastHour`,cast(60 * sum(`salesPreparedLastHour`.`litros`) / time_to_sec(timediff(max(`salesPreparedLastHour`.`created`),min(`salesPreparedLastHour`.`created`))) as decimal(10,1)) AS `litersByMinute`,`salesPreparedLastHour`.`departmentName` AS `departmentName` from `vn`.`salesPreparedLastHour` group by `salesPreparedLastHour`.`warehouseFk`,`salesPreparedLastHour`.`accion`,`salesPreparedLastHour`.`workerCode` */; +/*!50001 VIEW `workerSpeedSaleTracking` AS select `salesPreparedLastHour`.`warehouseFk` AS `warehouseFk`,`salesPreparedLastHour`.`accion` AS `accion`,`salesPreparedLastHour`.`workerCode` AS `workerCode`,sum(`salesPreparedLastHour`.`litros`) AS `sumaLitros`,min(`salesPreparedLastHour`.`created`) AS `started`,max(`salesPreparedLastHour`.`created`) AS `finished`,sum(if((`salesPreparedLastHour`.`created` >= (vn.VN_NOW() + interval -(1) hour)),`salesPreparedLastHour`.`litros`,0)) AS `sumaLitrosLastHour`,cast(((60 * sum(`salesPreparedLastHour`.`litros`)) / time_to_sec(timediff(max(`salesPreparedLastHour`.`created`),min(`salesPreparedLastHour`.`created`)))) as decimal(10,1)) AS `litersByMinute`,`salesPreparedLastHour`.`departmentName` AS `departmentName` from `vn`.`salesPreparedLastHour` group by `salesPreparedLastHour`.`warehouseFk`,`salesPreparedLastHour`.`accion`,`salesPreparedLastHour`.`workerCode` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97233,7 +81263,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerTeamCollegues` AS select distinct `w`.`workerFk` AS `workerFk`,`t`.`workerFk` AS `collegueFk` from (`workerTeam` `w` join `workerTeam` `t` on(`w`.`team` = `t`.`team`)) */; +/*!50001 VIEW `workerTeamCollegues` AS select distinct `w`.`workerFk` AS `workerFk`,`t`.`workerFk` AS `collegueFk` from (`workerTeam` `w` join `workerTeam` `t` on((`w`.`team` = `t`.`team`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97252,7 +81282,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerTimeControlUserInfo` AS select `u`.`id` AS `userFk`,`w`.`firstName` AS `name`,`w`.`lastName` AS `surname`,`u`.`name` AS `user`,`u`.`password` AS `password`,`u`.`bcryptPassword` AS `bcryptPassword`,`wd`.`departmentFk` AS `departmentFk`,left(`c`.`fi`,8) AS `dni` from (((`account`.`user` `u` join `vn`.`worker` `w` on(`w`.`userFk` = `u`.`id`)) join `vn`.`client` `c` on(`c`.`id` = `u`.`id`)) left join `vn`.`workerDepartment` `wd` on(`wd`.`workerFk` = `w`.`id`)) */; +/*!50001 VIEW `workerTimeControlUserInfo` AS select `u`.`id` AS `userFk`,`w`.`firstName` AS `name`,`w`.`lastName` AS `surname`,`u`.`name` AS `user`,`u`.`password` AS `password`,`u`.`bcryptPassword` AS `bcryptPassword`,`wd`.`departmentFk` AS `departmentFk`,left(`c`.`fi`,8) AS `dni` from (((`account`.`user` `u` join `vn`.`worker` `w` on((`w`.`userFk` = `u`.`id`))) join `vn`.`client` `c` on((`c`.`id` = `u`.`id`))) left join `vn`.`workerDepartment` `wd` on((`wd`.`workerFk` = `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 */; @@ -97271,26 +81301,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerTimeControlWorking` AS select `wtc`.`userFk` AS `userFk`,`wtc`.`timed` AS `timed`,`w`.`firstName` AS `name`,`w`.`lastName` AS `surname`,`pm`.`mediaValue` AS `phone`,`wm`.`mediaValue` AS `workerPhone`,`d`.`name` AS `department`,`wc`.`name` AS `workerCenter`,count(`wtc`.`order`) AS `maxOrder` from (((((((`vn`.`workerTimeControl` `wtc` join `vn`.`worker` `w` on(`w`.`userFk` = `wtc`.`userFk`)) left join `vn`.`personMedia` `pm` on(`pm`.`workerFk` = `w`.`id`)) left join `vn`.`workerMedia` `wm` on(`wm`.`workerFk` = `w`.`id`)) left join `vn`.`workerDepartment` `wd` on(`wd`.`workerFk` = `w`.`id`)) left join `vn`.`department` `d` on(`d`.`id` = `wd`.`departmentFk`)) left join `vn`.`workerLabour` `wl` on(`wl`.`businessFk` = (select `wl2`.`businessFk` from `vn`.`workerLabour` `wl2` where `wl2`.`workerFk` = `w`.`id` order by `wl2`.`started` desc limit 1))) left join `vn`.`workCenter` `wc` on(`wc`.`id` = `wl`.`workCenterFk`)) where cast(`wtc`.`timed` as date) = util.VN_CURDATE() group by `wtc`.`userFk` having `maxOrder` MOD 2 = 1 order by `wtc`.`timed` 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 `workerTimeControl_Journey__` --- - -/*!50001 DROP TABLE IF EXISTS `workerTimeControl_Journey__`*/; -/*!50001 DROP VIEW IF EXISTS `workerTimeControl_Journey__`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerTimeControl_Journey__` AS select `wtc`.`userFk` AS `userFk`,cast(`wtc`.`timed` as date) AS `dated`,cast(sum(if(`wtc`.`order` MOD 2,-1,1) * (hour(`wtc`.`timed`) + minute(`wtc`.`timed`) / 60)) as decimal(10,2)) AS `Journey`,dayname(`wtc`.`timed`) AS `dayName`,`w`.`lastName` AS `name`,`w`.`firstName` AS `firstname` from (`workerTimeControl` `wtc` join `worker` `w` on(`w`.`userFk` = `wtc`.`userFk`)) group by cast(`wtc`.`timed` as date),`wtc`.`userFk` */; +/*!50001 VIEW `workerTimeControlWorking` AS select `wtc`.`userFk` AS `userFk`,`wtc`.`timed` AS `timed`,`w`.`firstName` AS `name`,`w`.`lastName` AS `surname`,`pm`.`mediaValue` AS `phone`,`wm`.`mediaValue` AS `workerPhone`,`d`.`name` AS `department`,`wc`.`name` AS `workerCenter`,count(`wtc`.`order`) AS `maxOrder` from (((((((`vn`.`workerTimeControl` `wtc` join `vn`.`worker` `w` on((`w`.`userFk` = `wtc`.`userFk`))) left join `vn`.`personMedia` `pm` on((`pm`.`workerFk` = `w`.`id`))) left join `vn`.`workerMedia` `wm` on((`wm`.`workerFk` = `w`.`id`))) left join `vn`.`workerDepartment` `wd` on((`wd`.`workerFk` = `w`.`id`))) left join `vn`.`department` `d` on((`d`.`id` = `wd`.`departmentFk`))) left join `vn`.`workerLabour` `wl` on((`wl`.`businessFk` = (select `wl2`.`businessFk` from `vn`.`workerLabour` `wl2` where (`wl2`.`workerFk` = `w`.`id`) order by `wl2`.`started` desc limit 1)))) left join `vn`.`workCenter` `wc` on((`wc`.`id` = `wl`.`workCenterFk`))) where (cast(`wtc`.`timed` as date) = vn.VN_CURDATE()) group by `wtc`.`userFk` having ((`maxOrder` % 2) = 1) order by `wtc`.`timed` desc */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97309,26 +81320,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `workerTimeJourneyNG` AS select `wtc`.`userFk` AS `userFk`,cast(`wtc`.`timed` as date) AS `dated`,if(`wtc`.`order` MOD 2,-1,1) * (hour(`wtc`.`timed`) + minute(`wtc`.`timed`) / 60) AS `Journey`,dayname(`wtc`.`timed`) AS `dayName`,`w`.`lastName` AS `name`,`w`.`firstName` AS `firstname` from (`workerTimeControl` `wtc` join `worker` `w` on(`w`.`userFk` = `wtc`.`userFk`)) */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!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 = utf8mb4 */; -/*!50001 SET character_set_results = utf8mb4 */; -/*!50001 SET collation_connection = utf8mb4_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` 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` > util.VN_CURDATE() and `dpu`.`userFk` is null group by `c`.`workerFk` */; +/*!50001 VIEW `workerTimeJourneyNG` AS select `wtc`.`userFk` AS `userFk`,cast(`wtc`.`timed` as date) AS `dated`,(if((`wtc`.`order` % 2),-(1),1) * (hour(`wtc`.`timed`) + (minute(`wtc`.`timed`) / 60))) AS `Journey`,dayname(`wtc`.`timed`) AS `dayName`,`w`.`lastName` AS `name`,`w`.`firstName` AS `firstname` from (`workerTimeControl` `wtc` join `worker` `w` on((`w`.`userFk` = `wtc`.`userFk`))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97347,7 +81339,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` 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` > util.VN_CURDATE())) where `c`.`created` > util.VN_CURDATE() and `mw`.`workerFk` is null group by `c`.`workerFk` */; +/*!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` > vn.VN_CURDATE())))) where ((`c`.`created` > vn.VN_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 */; @@ -97366,26 +81358,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8mb4_unicode_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `zoneEstimatedDelivery` AS select `t`.`zoneFk` AS `zoneFk`,cast(util.VN_CURDATE() + interval (hour(ifnull(`zc`.`hour`,`z`.`hour`)) * 60 + minute(ifnull(`zc`.`hour`,`z`.`hour`))) minute as time) AS `hourTheoretical`,cast(sum(`sv`.`volume`) as decimal(5,1)) AS `totalVolume`,cast(sum(if(`s`.`alertLevel` < 2,`sv`.`volume`,0)) as decimal(5,1)) AS `remainingVolume`,greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0)) AS `speed`,cast(`zc`.`hour` + interval (-sum(if(`s`.`alertLevel` < 2,`sv`.`volume`,0)) * 60 / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0))) minute as time) AS `hourEffective`,floor(-sum(if(`s`.`alertLevel` < 2,`sv`.`volume`,0)) * 60 / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0))) AS `minutesLess`,cast(`zc`.`hour` + interval (-sum(if(`s`.`alertLevel` < 2,`sv`.`volume`,0)) * 60 / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0))) minute as time) AS `etc` from (((((((((`vn`.`ticket` `t` join `vn`.`ticketStateToday` `tst` on(`tst`.`ticket` = `t`.`id`)) join `vn`.`state` `s` on(`s`.`id` = `tst`.`state`)) join `vn`.`saleVolume` `sv` on(`sv`.`ticketFk` = `t`.`id`)) left join `vn`.`lastHourProduction` `lhp` on(`lhp`.`warehouseFk` = `t`.`warehouseFk`)) join `vn`.`warehouse` `w` on(`w`.`id` = `t`.`warehouseFk`)) join `vn`.`warehouseAlias` `wa` on(`wa`.`id` = `w`.`aliasFk`)) join `vn`.`zone` `z` on(`z`.`id` = `t`.`zoneFk`)) left join `vn`.`zoneClosure` `zc` on(`zc`.`zoneFk` = `t`.`zoneFk` and `zc`.`dated` = util.VN_CURDATE())) left join `cache`.`departure_limit` `dl` on(`dl`.`warehouse_id` = `t`.`warehouseFk` and `dl`.`fecha` = util.VN_CURDATE())) where `w`.`hasProduction` <> 0 and cast(`t`.`shipped` as date) = util.VN_CURDATE() group by `t`.`zoneFk` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - --- --- Final view structure for view `zone_ETD__` --- - -/*!50001 DROP TABLE IF EXISTS `zone_ETD__`*/; -/*!50001 DROP VIEW IF EXISTS `zone_ETD__`*/; -/*!50001 SET @saved_cs_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_unicode_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ -/*!50001 VIEW `zone_ETD__` AS select `zed`.`zoneFk` AS `zoneFk`,`zed`.`hourTheoretical` AS `HoraTeórica`,`zed`.`totalVolume` AS `volumenTotal`,`zed`.`remainingVolume` AS `volumenPendiente`,`zed`.`speed` AS `velocidad`,`zed`.`hourEffective` AS `HoraPráctica`,`zed`.`minutesLess` AS `minutesLess`,`zed`.`etc` AS `etc` from `vn`.`zoneEstimatedDelivery` `zed` */; +/*!50001 VIEW `zoneEstimatedDelivery` AS select `t`.`zoneFk` AS `zoneFk`,cast((vn.VN_CURDATE() + interval ((hour(ifnull(`zc`.`hour`,`z`.`hour`)) * 60) + minute(ifnull(`zc`.`hour`,`z`.`hour`))) minute) as time) AS `hourTheoretical`,cast(sum(`sv`.`volume`) as decimal(5,1)) AS `totalVolume`,cast(sum(if((`s`.`alertLevel` < 2),`sv`.`volume`,0)) as decimal(5,1)) AS `remainingVolume`,greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0)) AS `speed`,cast((`zc`.`hour` + interval ((-(sum(if((`s`.`alertLevel` < 2),`sv`.`volume`,0))) * 60) / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0))) minute) as time) AS `hourEffective`,floor(((-(sum(if((`s`.`alertLevel` < 2),`sv`.`volume`,0))) * 60) / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0)))) AS `minutesLess`,cast((`zc`.`hour` + interval ((-(sum(if((`s`.`alertLevel` < 2),`sv`.`volume`,0))) * 60) / greatest(ifnull(`lhp`.`m3`,0),ifnull(`dl`.`minSpeed`,0))) minute) as time) AS `etc` from (((((((((`vn`.`ticket` `t` join `vn`.`ticketStateToday` `tst` on((`tst`.`ticket` = `t`.`id`))) join `vn`.`state` `s` on((`s`.`id` = `tst`.`state`))) join `vn`.`saleVolume` `sv` on((`sv`.`ticketFk` = `t`.`id`))) left join `vn`.`lastHourProduction` `lhp` on((`lhp`.`warehouseFk` = `t`.`warehouseFk`))) join `vn`.`warehouse` `w` on((`w`.`id` = `t`.`warehouseFk`))) join `vn`.`warehouseAlias` `wa` on((`wa`.`id` = `w`.`aliasFk`))) join `vn`.`zone` `z` on((`z`.`id` = `t`.`zoneFk`))) left join `vn`.`zoneClosure` `zc` on(((`zc`.`zoneFk` = `t`.`zoneFk`) and (`zc`.`dated` = vn.VN_CURDATE())))) left join `cache`.`departure_limit` `dl` on(((`dl`.`warehouse_id` = `t`.`warehouseFk`) and (`dl`.`fecha` = vn.VN_CURDATE())))) where (`w`.`hasProduction` and (cast(`t`.`shipped` as date) = vn.VN_CURDATE())) group by `t`.`zoneFk` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -97405,4 +81378,4 @@ USE `vncontrol`; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-05-04 15:56:23 +-- Dump completed on 2022-06-23 12:12:10 diff --git a/db/export-data.sh b/db/export-data.sh index 900e630f7..bbbeb7152 100755 --- a/db/export-data.sh +++ b/db/export-data.sh @@ -65,6 +65,7 @@ TABLES=( ticketUpdateAction time volumeConfig + workCenter ) dump_tables ${TABLES[@]} @@ -101,7 +102,6 @@ TABLES=( media_type professional_category profile_type - workcenter ) dump_tables ${TABLES[@]} @@ -111,4 +111,4 @@ TABLES=( TiposTransacciones TiposRetencion ) -dump_tables ${TABLES[@]} \ No newline at end of file +dump_tables ${TABLES[@]}