From 4876f36190e15145d27caef99dc1ed3bf56448cb Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 7 Feb 2018 16:45:40 +0100 Subject: [PATCH] Local database structure updated & import changes script --- services/db/01-structure.sql | 1097 +++++++++++------ services/db/02-changes.sh | 8 + .../db/{02-fixtures.sql => 03-fixtures.sql} | 56 +- services/db/Dockerfile | 8 +- services/db/changes/1.0.0/01-agencyMode.sql | 5 - services/db/changes/1.0.0/02-agencyHour.sql | 3 - .../1.0.0/04-itemLog.sql} | 0 services/db/changes/1.0.0/04-userRole.sql | 36 - .../db/changes/1.0.0/05-userHasRoleId.sql | 31 - .../db/{script.cmd => export-structure.cmd} | 0 10 files changed, 743 insertions(+), 501 deletions(-) create mode 100755 services/db/02-changes.sh rename services/db/{02-fixtures.sql => 03-fixtures.sql} (93%) rename services/db/{01-titemLog.sql => changes/1.0.0/04-itemLog.sql} (100%) delete mode 100644 services/db/changes/1.0.0/04-userRole.sql delete mode 100644 services/db/changes/1.0.0/05-userHasRoleId.sql rename services/db/{script.cmd => export-structure.cmd} (100%) diff --git a/services/db/01-structure.sql b/services/db/01-structure.sql index f6781374c..a7aed8294 100644 --- a/services/db/01-structure.sql +++ b/services/db/01-structure.sql @@ -2252,7 +2252,7 @@ CREATE TABLE `Agencias_dits` ( `value_old` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `value_new` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`idAgencia_dits`) -) ENGINE=InnoDB AUTO_INCREMENT=14748 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=14749 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2352,7 +2352,7 @@ CREATE TABLE `Articles` ( CONSTRAINT `Articles_ibfk_5` FOREIGN KEY (`tipo_id`) REFERENCES `Tipos` (`tipo_id`) ON UPDATE CASCADE, CONSTRAINT `expenceFk` FOREIGN KEY (`expenceFk`) REFERENCES `Gastos` (`Id_Gasto`) ON UPDATE CASCADE, CONSTRAINT `producer_id` FOREIGN KEY (`producer_id`) REFERENCES `producer` (`producer_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=300035 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=300172 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 */ ; @@ -2536,7 +2536,7 @@ CREATE TABLE `Articles_dits` ( KEY `fgkey1_idx` (`idaccion_dits`), KEY `fgkey2_idx` (`Id_Ticket`), KEY `fgkey3_idx` (`Id_Trabajador`) -) ENGINE=InnoDB AUTO_INCREMENT=19689 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=19693 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2555,7 +2555,7 @@ CREATE TABLE `Articles_nicho` ( KEY `Articles_nicho_wh_fk` (`warehouse_id`), CONSTRAINT `Articles_nicho_wh_fk` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Articles_nichos_fk` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=296877 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=296900 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2714,7 +2714,7 @@ CREATE TABLE `Cajas` ( KEY `warehouse_id` (`warehouse_id`), KEY `fk_Cajas_Proveedores_account1_idx` (`Proveedores_account_Id`), CONSTRAINT `Cajas_ibfk_2` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=551258 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=552023 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 */ ; @@ -2861,7 +2861,7 @@ CREATE TABLE `Clientes` ( CONSTRAINT `Clientes_ibfk_5` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE, CONSTRAINT `canal_nuevo_cliente` FOREIGN KEY (`chanel_id`) REFERENCES `chanel` (`chanel_id`) ON UPDATE CASCADE, CONSTRAINT `tipos_de_cliente` FOREIGN KEY (`clientes_tipo_id`) REFERENCES `clientes_tipo` (`clientes_tipo_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=10126 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=10138 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 */ ; @@ -3071,7 +3071,7 @@ CREATE TABLE `Clientes_empresa` ( PRIMARY KEY (`Id_Clientes_empresa`), KEY `empresa_id_idx` (`empresa_id`), CONSTRAINT `empresa_id` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=470497 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Empresa por defecto para crear los tickets'; +) ENGINE=InnoDB AUTO_INCREMENT=470498 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Empresa por defecto para crear los tickets'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3152,7 +3152,7 @@ CREATE TABLE `Colas` ( CONSTRAINT `Colas_ibfk_3` FOREIGN KEY (`Id_Prioridad`) REFERENCES `Prioridades` (`Id_Prioridad`) ON UPDATE CASCADE, CONSTRAINT `Colas_ibfk_4` FOREIGN KEY (`Id_Impresora`) REFERENCES `Impresoras` (`Id_Impresora`) ON UPDATE CASCADE, CONSTRAINT `Colas_ibfk_5` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=19777 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=26527 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3234,7 +3234,7 @@ CREATE TABLE `Compres` ( CONSTRAINT `Compres_ibfk_2` FOREIGN KEY (`Id_Cubo`) REFERENCES `Cubos` (`Id_Cubo`) ON UPDATE CASCADE, CONSTRAINT `Compres_ibfk_3` FOREIGN KEY (`container_id`) REFERENCES `container` (`container_id`) ON UPDATE CASCADE, CONSTRAINT `buy_id` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=236271662 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=237016297 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -3486,7 +3486,7 @@ CREATE TABLE `Compres_ok` ( KEY `Id_Movimiento` (`Id_Compra`), KEY `Id_Accion` (`Id_Accion`), CONSTRAINT `Compres_ok_ibfk_1` FOREIGN KEY (`Id_Compra`) REFERENCES `Compres` (`Id_Compra`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=15683 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=15788 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3530,7 +3530,7 @@ CREATE TABLE `Consignatarios` ( CONSTRAINT `Consignatarios_ibfk_3` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE, CONSTRAINT `Consignatarios_ibfk_4` FOREIGN KEY (`Id_Agencia`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `address_customer_id` FOREIGN KEY (`Id_cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=24016 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=24034 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 */ ; @@ -3714,7 +3714,7 @@ CREATE TABLE `Contactos` ( PRIMARY KEY (`Id_Contacto`), KEY `Telefono` (`Telefono`), KEY `Movil` (`Movil`) -) ENGINE=InnoDB AUTO_INCREMENT=2590 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2591 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 */ ; @@ -3910,7 +3910,7 @@ CREATE TABLE `Entradas` ( CONSTRAINT `Entradas_ibfk_1` FOREIGN KEY (`Id_Proveedor`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `Entradas_ibfk_6` FOREIGN KEY (`travel_id`) REFERENCES `travel` (`id`) ON UPDATE CASCADE, CONSTRAINT `Entradas_ibfk_7` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=133866 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='InnoDB free: 88064 kB; (`Id_Proveedor`) REFER `vn2008/Provee'; +) ENGINE=InnoDB AUTO_INCREMENT=134066 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='InnoDB free: 88064 kB; (`Id_Proveedor`) REFER `vn2008/Provee'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4064,7 +4064,7 @@ CREATE TABLE `Entradas_dits` ( CONSTRAINT `Entradas_dits_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fgkey_entradas_1` FOREIGN KEY (`idaccion_dits`) REFERENCES `accion_dits` (`idaccion_dits`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `fgkey_entradas_3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2530450 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2538657 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4082,7 +4082,7 @@ CREATE TABLE `Entradas_kop` ( PRIMARY KEY (`Id_Entradas_kop`), KEY `entradas_entradas_kop_idx` (`Id_Entrada`), CONSTRAINT `entradas_entradas_kop` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona las entradas con los origenes de compra'; +) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona las entradas con los origenes de compra'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4325,7 +4325,7 @@ CREATE TABLE `Facturas` ( CONSTRAINT `Facturas_ibfk_4` FOREIGN KEY (`cplusTaxBreakFk`) REFERENCES `vn`.`cplusTaxBreak` (`id`) ON UPDATE CASCADE, CONSTRAINT `invoice_bank_id` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `invoice_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=439842 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=442539 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 */ ; @@ -4543,7 +4543,7 @@ CREATE TABLE `Greuges` ( KEY `Id_Ticket_Greuge_Ticket_idx` (`Id_Ticket`), CONSTRAINT `Id_Ticket_Greuge_Ticket` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `greuges_type_fk` FOREIGN KEY (`Greuges_type_id`) REFERENCES `Greuges_type` (`Greuges_type_id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1740537 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=FIXED; +) ENGINE=InnoDB AUTO_INCREMENT=1746026 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=FIXED; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -4742,7 +4742,7 @@ CREATE TABLE `Movimientos` ( KEY `itemFk_ticketFk` (`Id_Article`,`Id_Ticket`), CONSTRAINT `Movimientos_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON UPDATE CASCADE, CONSTRAINT `movement_ticket_id` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=19632525 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=19658177 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 */ ; @@ -4891,7 +4891,7 @@ CREATE TABLE `Movimientos_mark` ( `Id_Movimiento_mark` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`Id_Movimiento_mark`), KEY `Id_Movimiento` (`Id_Movimiento`) -) ENGINE=InnoDB AUTO_INCREMENT=9115997 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=9147587 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4961,7 +4961,7 @@ CREATE TABLE `Ordenes` ( KEY `Id_Comprador` (`CodCOMPRADOR`), KEY `Id_Movimiento` (`Id_Movimiento`), KEY `Id_Vendedor` (`CodVENDEDOR`) -) ENGINE=InnoDB AUTO_INCREMENT=26052 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=26079 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5027,6 +5027,7 @@ CREATE TABLE `Paises` ( `nst_geo_id` int(11) DEFAULT NULL, `nst_name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `geoFk` int(11) DEFAULT NULL, + `isUeeMember` tinyint(4) NOT NULL DEFAULT '0', PRIMARY KEY (`Id`), KEY `Id_Paisreal` (`Id_Paisreal`) ) ENGINE=InnoDB AUTO_INCREMENT=68 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -5133,7 +5134,7 @@ CREATE TABLE `Proveedores` ( CONSTRAINT `pay_dem_id` FOREIGN KEY (`pay_dem_id`) REFERENCES `pay_dem` (`id`) ON UPDATE CASCADE, CONSTRAINT `pay_met_id` FOREIGN KEY (`pay_met_id`) REFERENCES `pay_met` (`id`) ON UPDATE CASCADE, CONSTRAINT `province_id` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2421 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2424 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5159,7 +5160,7 @@ CREATE TABLE `Proveedores_account` ( KEY `fk_Proveedores_account_entity1_idx` (`entity_id`), KEY `fk_banco_prov_account_idx` (`Id_Banco`), CONSTRAINT `fk_banco_prov_account` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=590 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=591 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5250,7 +5251,7 @@ CREATE TABLE `Recibos` ( CONSTRAINT `Recibos_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `Recibos_ibfk_2` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `recibo_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=435028 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=436710 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 */ ; @@ -5341,7 +5342,7 @@ CREATE TABLE `Relaciones` ( KEY `Id_Contacto` (`Id_Contacto`), KEY `Id_Proveedor` (`Id_Proveedor`), KEY `Id_Cliente` (`Id_Cliente`) -) ENGINE=InnoDB AUTO_INCREMENT=2592 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2593 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5361,7 +5362,7 @@ CREATE TABLE `Remesas` ( KEY `empresa_id` (`empresa_id`), CONSTRAINT `Remesas_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `Remesas_ibfk_2` FOREIGN KEY (`Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=999 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1002 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5417,7 +5418,7 @@ CREATE TABLE `Rutas` ( KEY `Fecha` (`Fecha`), KEY `gestdoc_id` (`gestdoc_id`), CONSTRAINT `Rutas_ibfk_1` FOREIGN KEY (`gestdoc_id`) REFERENCES `gestdoc` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=35105 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=35203 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 */ ; @@ -5605,7 +5606,7 @@ CREATE TABLE `Split_lines` ( KEY `Id_Compra` (`Id_Compra`), CONSTRAINT `Id_Compra` FOREIGN KEY (`Id_Compra`) REFERENCES `Compres` (`Id_Compra`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Split_lines_ibfk_1` FOREIGN KEY (`Id_Split`) REFERENCES `Splits` (`Id_Split`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=312071 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=312222 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5623,7 +5624,7 @@ CREATE TABLE `Splits` ( `Notas` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Split`), KEY `Id_Entrada` (`Id_Entrada`) -) ENGINE=InnoDB AUTO_INCREMENT=36105 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=36109 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5651,7 +5652,7 @@ CREATE TABLE `Stockcontrol` ( CONSTRAINT `Stockcontrol_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Stockcontrol_ibfk_2` FOREIGN KEY (`Id_Remitente`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `Stockcontrol_ibfk_3` FOREIGN KEY (`Id_Solver`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=23250 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=23258 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5708,7 +5709,7 @@ CREATE TABLE `Tickets` ( CONSTRAINT `Tickets_ibfk_9` FOREIGN KEY (`Id_Ruta`) REFERENCES `Rutas` (`Id_Ruta`) ON UPDATE CASCADE, CONSTRAINT `ticket_customer_id` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE, CONSTRAINT `tickets_fk10` FOREIGN KEY (`Factura`) REFERENCES `Facturas` (`Id_Factura`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1753139 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1756205 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 */ ; @@ -5868,6 +5869,29 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`z-developer`@`%`*/ /*!50003 TRIGGER `vn2008`.`Tickets_BEFORE_DELETE` BEFORE DELETE ON `Tickets` FOR EACH ROW +BEGIN + INSERT INTO vn2008.mail SET + `to` = 'jgallego@verdnatura.es', + `reply_to` = 'jgallego@verdnatura.es', + `subject` = 'Ticket Eliminado', + `text` = CONCAT(USER(), ' ha eliminado el ticket ', + OLD.`Id_Ticket`); +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Tickets_dits` @@ -5891,7 +5915,7 @@ CREATE TABLE `Tickets_dits` ( CONSTRAINT `Tickets_dits_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `fgkey1` FOREIGN KEY (`idaccion_dits`) REFERENCES `accion_dits` (`idaccion_dits`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `fgkey3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=56618879 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=56922708 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6090,7 +6114,7 @@ CREATE TABLE `Trabajadores` ( KEY `sub` (`sub`), CONSTRAINT `Clientes` FOREIGN KEY (`Id_Cliente_Interno`) REFERENCES `Clientes` (`id_cliente`) ON UPDATE CASCADE, CONSTRAINT `Trabajadores_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1046 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1047 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 */ ; @@ -6244,7 +6268,7 @@ CREATE TABLE `Vehiculos_consumo` ( PRIMARY KEY (`Vehiculos_consumo_id`,`Id_Vehiculo`), KEY `fk_Vehiculos_consumo_Vehiculos_idx` (`Id_Vehiculo`), CONSTRAINT `fk_Vehiculos_consumo_Vehiculos` FOREIGN KEY (`Id_Vehiculo`) REFERENCES `Vehiculos` (`Id_Vehiculo`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=7102 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla apuntan el importe de los tickets de la gasolinera solred, con quien tenemos un contrato y nos facturan mensualmente'; +) ENGINE=InnoDB AUTO_INCREMENT=7120 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='En esta tabla apuntan el importe de los tickets de la gasolinera solred, con quien tenemos un contrato y nos facturan mensualmente'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6338,6 +6362,8 @@ CREATE TABLE `XDiario` ( `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', `FACTURAEX` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Numero de factura del proveedor', `TIPOCLAVE` int(3) DEFAULT NULL, @@ -6357,7 +6383,7 @@ CREATE TABLE `XDiario` ( PRIMARY KEY (`id`), KEY `empresa_id` (`empresa_id`), CONSTRAINT `XDiario_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3158852 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3177950 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6494,7 +6520,7 @@ CREATE TABLE `account_conciliacion` ( KEY `fg_accconciliacion_key1_idx` (`Id_Proveedores_account`), KEY `index_id_calculated` (`id_calculated`), CONSTRAINT `fg_key1_accountconc` FOREIGN KEY (`Id_Proveedores_account`) REFERENCES `Proveedores_account` (`Id_Proveedores_account`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=28304 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=28412 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 */ ; @@ -6845,7 +6871,7 @@ CREATE TABLE `albaran` ( CONSTRAINT `fk_albaran_empresa1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `fk_albaran_recibida` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `fk_albaran_warehouse1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2012 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2018 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6921,7 +6947,7 @@ CREATE TABLE `awb` ( CONSTRAINT `awbInvoiceIn` FOREIGN KEY (`invoiceInFk`) REFERENCES `recibida` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `awbTransitoryFk` FOREIGN KEY (`transitario_id`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `awb_ibfk_1` FOREIGN KEY (`iva_id`) REFERENCES `iva_codigo` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2336 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2342 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 */ ; @@ -7023,8 +7049,9 @@ CREATE TABLE `awb_component_template` ( `max_value` decimal(10,2) unsigned DEFAULT NULL, `min_value` decimal(10,2) unsigned DEFAULT NULL, `Id_Moneda` tinyint(3) unsigned NOT NULL DEFAULT '2', + `days` varchar(7) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`awb_component_template_id`), - UNIQUE KEY `carguera_id_UNIQUE` (`carguera_id`,`airport_in`,`airport_out`,`airline_id`,`awb_component_type_id`,`Fecha`), + UNIQUE KEY `carguera_id_UNIQUE` (`carguera_id`,`airport_in`,`airport_out`,`airline_id`,`awb_component_type_id`,`Fecha`,`days`), KEY `Id_Moneda` (`Id_Moneda`), KEY `airline_idx` (`airline_id`), KEY `role_idx` (`awb_role_id`), @@ -7065,7 +7092,7 @@ CREATE TABLE `awb_gestdoc` ( KEY `awb_gestdoc_gestdoc_fk` (`gestdoc_id`), CONSTRAINT `awb_gestdoc_awb_fk` FOREIGN KEY (`awb_id`) REFERENCES `awb` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `awb_gestdoc_gestdoc_fk` FOREIGN KEY (`gestdoc_id`) REFERENCES `gestdoc` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2036 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2045 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7184,7 +7211,7 @@ CREATE TABLE `barcodes` ( UNIQUE KEY `Id_Article_2` (`Id_Article`,`code`), KEY `Id_Article` (`Id_Article`), CONSTRAINT `barcodes_ibfk_1` FOREIGN KEY (`Id_Article`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=33670 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=33753 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7325,7 +7352,7 @@ CREATE TABLE `buy_edi` ( KEY `kop` (`kop`), KEY `barcode` (`barcode`), KEY `fec` (`fec`) -) ENGINE=InnoDB AUTO_INCREMENT=634105 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=635704 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7580,7 +7607,7 @@ CREATE TABLE `cl_act` ( CONSTRAINT `cl_act_ibfk_1` FOREIGN KEY (`Id_Movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `cl_act_ibfk_3` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `cl_act_ibfk_4` FOREIGN KEY (`cl_main_id`) REFERENCES `cl_main` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=76404 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Acciones en respuesta a las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=76500 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Acciones en respuesta a las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7614,7 +7641,7 @@ CREATE TABLE `cl_cau` ( CONSTRAINT `cl_cau_ibfk_7` FOREIGN KEY (`cl_mot_id`) REFERENCES `cl_mot` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_cau_ibfk_8` FOREIGN KEY (`cl_con_id`) REFERENCES `cl_con` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_cau_ibfk_9` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=42673 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Causas de las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=42708 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Causas de las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7668,7 +7695,7 @@ CREATE TABLE `cl_det` ( CONSTRAINT `cl_det_ibfk_6` FOREIGN KEY (`cl_pet_id`) REFERENCES `cl_pet` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_det_ibfk_7` FOREIGN KEY (`Id_Movimiento`) REFERENCES `Movimientos` (`Id_Movimiento`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `cl_det_ibfk_8` FOREIGN KEY (`cl_main_id`) REFERENCES `cl_main` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=105982 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=106082 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7725,7 +7752,7 @@ CREATE TABLE `cl_main` ( CONSTRAINT `cl_main_ibfk_3` FOREIGN KEY (`cl_est_id`) REFERENCES `cl_est` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_main_ibfk_4` FOREIGN KEY (`cl_dep_id`) REFERENCES `cl_dep` (`id`) ON UPDATE CASCADE, CONSTRAINT `cl_main_ibfk_5` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=45089 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Reclamaciones, tabla principal'; +) ENGINE=InnoDB AUTO_INCREMENT=45155 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Reclamaciones, tabla principal'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7839,7 +7866,7 @@ CREATE TABLE `client_observation` ( KEY `Id_Cliente` (`Id_Cliente`), CONSTRAINT `client_observation_ibfk_1` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `client_observation_ibfk_2` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=55439 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; +) ENGINE=InnoDB AUTO_INCREMENT=55566 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8003,7 +8030,7 @@ CREATE TABLE `consignatarios_observation` ( `text` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`consignatarios_observation_id`), UNIQUE KEY `Id_Consigna` (`Id_Consigna`,`observation_type_id`) -) ENGINE=InnoDB AUTO_INCREMENT=2880 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de los consignatarios'; +) ENGINE=InnoDB AUTO_INCREMENT=2882 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de los consignatarios'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8085,7 +8112,7 @@ CREATE TABLE `credit` ( KEY `credit_ClienteFk` (`Id_Cliente`), CONSTRAINT `credit_ClienteFk` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `workers_fk` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=58560 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=58651 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8607,7 +8634,7 @@ CREATE TABLE `escritos_det` ( PRIMARY KEY (`id`), KEY `empresa_id` (`empresa_id`), CONSTRAINT `escritos_det_ibfk_1` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=14453 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=14468 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8636,7 +8663,7 @@ CREATE TABLE `expeditions` ( KEY `index4` (`ticket_id`), CONSTRAINT `Id_Agencia` FOREIGN KEY (`agency_id`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `ticket_id` FOREIGN KEY (`ticket_id`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2209183 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2213680 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 */ ; @@ -8776,7 +8803,7 @@ CREATE TABLE `expeditions_deleted` ( KEY `index2` (`EsBulto`), KEY `index3` (`odbc_date`), KEY `index4` (`ticket_id`) -) ENGINE=InnoDB AUTO_INCREMENT=2208973 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2213589 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8901,7 +8928,7 @@ CREATE TABLE `gestdoc` ( UNIQUE KEY `emp_id` (`emp_id`,`orden`,`warehouse_id`), KEY `trabajador_id` (`trabajador_id`), KEY `warehouse_id` (`warehouse_id`) -) ENGINE=InnoDB AUTO_INCREMENT=802254 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=807642 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -9100,7 +9127,7 @@ CREATE TABLE `intrastat_data` ( KEY `recibida` (`recibida_id`), CONSTRAINT `intrastat_data_ibfk_1` FOREIGN KEY (`intrastat_id`) REFERENCES `Intrastat` (`Codintrastat`) ON UPDATE CASCADE, CONSTRAINT `intrastat_data_ibfk_2` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=61688 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=61695 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9472,7 +9499,7 @@ CREATE TABLE `mail` ( `recipientFk` int(11) DEFAULT NULL, `plainTextBody` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=1232795 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=MyISAM AUTO_INCREMENT=1240876 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9515,7 +9542,7 @@ CREATE TABLE `mandato` ( CONSTRAINT `mandato_fgkey1` FOREIGN KEY (`Id_Cliente`) REFERENCES `Clientes` (`id_cliente`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `mandato_fgkey2` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `mandato_fgkey3` FOREIGN KEY (`idmandato_tipo`) REFERENCES `mandato_tipo` (`idmandato_tipo`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=14235 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=14251 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 */ ; @@ -9742,7 +9769,7 @@ CREATE TABLE `pago` ( CONSTRAINT `pago_moneda` FOREIGN KEY (`id_moneda`) REFERENCES `Monedas` (`Id_Moneda`) ON UPDATE CASCADE, CONSTRAINT `pago_pay_met` FOREIGN KEY (`pay_met_id`) REFERENCES `pay_met` (`id`) ON UPDATE CASCADE, CONSTRAINT `proveedor_pago` FOREIGN KEY (`id_proveedor`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=38926 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=38955 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 */ ; @@ -10239,7 +10266,7 @@ CREATE TABLE `price_fixed` ( KEY `date_end` (`date_end`), KEY `warehouse_id` (`warehouse_id`), CONSTRAINT `price_fixed_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=51265 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=51294 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 */ ; @@ -10484,7 +10511,7 @@ CREATE TABLE `recibida` ( CONSTRAINT `recibida_ibfk_5` FOREIGN KEY (`cplusInvoiceType472Fk`) REFERENCES `vn`.`cplusInvoiceType472` (`id`) ON UPDATE CASCADE, CONSTRAINT `recibida_ibfk_6` FOREIGN KEY (`cplusRectificationTypeFk`) REFERENCES `vn`.`cplusRectificationType` (`id`) ON UPDATE CASCADE, CONSTRAINT `recibida_ibfk_7` FOREIGN KEY (`cplusTrascendency472Fk`) REFERENCES `vn`.`cplusTrascendency472` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=63478 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=63617 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 */ ; @@ -10983,7 +11010,7 @@ CREATE TABLE `recibida_entrada` ( KEY `Id_Entrada` (`Id_Entrada`), KEY `recibida_id` (`recibida_id`), CONSTRAINT `recibida_entrada_ibfk_2` FOREIGN KEY (`Id_Entrada`) REFERENCES `Entradas` (`Id_Entrada`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=9741 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=9786 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 */ ; @@ -11071,7 +11098,7 @@ CREATE TABLE `recibida_iva` ( CONSTRAINT `recibida_iva_ibfk_2` FOREIGN KEY (`iva_id`) REFERENCES `iva_codigo` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `recibida_iva_ibfk_5` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `recibida_iva_ibfk_6` FOREIGN KEY (`gastos_id`) REFERENCES `Gastos` (`Id_Gasto`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=84342 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=84448 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11094,7 +11121,7 @@ CREATE TABLE `recibida_vencimiento` ( KEY `banco_id` (`banco_id`), CONSTRAINT `recibida_vencimiento_ibfk_6` FOREIGN KEY (`banco_id`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `recibida_vencimiento_ibfk_7` FOREIGN KEY (`recibida_id`) REFERENCES `recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=81951 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=82106 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 */ ; @@ -11331,7 +11358,7 @@ CREATE TABLE `scan` ( `name` varchar(45) CHARACTER SET utf8 DEFAULT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=44311 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Se borra automaticamente 8 dias en el pasado desde vn2008.clean'; +) ENGINE=InnoDB AUTO_INCREMENT=44635 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Se borra automaticamente 8 dias en el pasado desde vn2008.clean'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11371,7 +11398,7 @@ CREATE TABLE `scan_line` ( PRIMARY KEY (`scan_line_id`), KEY `id_scan_id_idx` (`scan_id`), CONSTRAINT `id_scan_id` FOREIGN KEY (`scan_id`) REFERENCES `scan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=583328 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=586976 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11749,8 +11776,8 @@ CREATE TABLE `template_bionic_component` ( `item_id` int(11) NOT NULL, `component_id` int(10) unsigned NOT NULL, `cost` decimal(10,4) NOT NULL, - KEY `item_warehouse` (`item_id`,`warehouse_id`) USING BTREE, - KEY `item_warehouse_component` (`item_id`,`warehouse_id`,`component_id`) USING HASH + UNIQUE KEY `item_warehouse_component` (`item_id`,`warehouse_id`,`component_id`) USING HASH, + KEY `item_warehouse` (`item_id`,`warehouse_id`) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -11853,7 +11880,7 @@ CREATE TABLE `ticket_observation` ( KEY `observation_type_id` (`observation_type_id`), CONSTRAINT `ticket_observation_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticket_observation_ibfk_2` FOREIGN KEY (`observation_type_id`) REFERENCES `observation_type` (`observation_type_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=978144 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; +) ENGINE=InnoDB AUTO_INCREMENT=980628 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11976,7 +12003,7 @@ CREATE TABLE `travel` ( CONSTRAINT `travel_ibfk_2` FOREIGN KEY (`warehouse_id_out`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_3` FOREIGN KEY (`agency_id`) REFERENCES `Agencias` (`Id_Agencia`) ON UPDATE CASCADE, CONSTRAINT `travel_ibfk_4` FOREIGN KEY (`cargoSupplierFk`) REFERENCES `Proveedores` (`Id_Proveedor`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=98906 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=99003 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -12113,7 +12140,7 @@ CREATE TABLE `travel_dits` ( KEY `fgkey2_idx` (`Id_Ticket`), KEY `fgkey3_idx` (`Id_Trabajador`), CONSTRAINT `travel_dits_ibfk_1` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=148480 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=148916 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -18491,7 +18518,7 @@ proc: BEGIN SELECT cb.warehouse_id, b.item_id, Id_Componente, GREATEST(IFNULL(ROUND(base * tax,4), 0), b.min_price - b.rate_3) FROM t_components_base cb JOIN bi.tarifa_componentes - JOIN t_bionic_temp b ON b.item_id = cb.item_id + JOIN t_bionic_temp b ON b.item_id = cb.item_id AND b.warehouse_id = cb.warehouse_id LEFT JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id WHERE Id_Componente = 32 AND tax <> 0 AND b.min_price < b.rate_3 AND PrecioEspecial IS NULL; @@ -19463,13 +19490,13 @@ BEGIN CALL bionic_calc_component ( v_consigna, v_agencia); - -- REPLACE INTO tmp.bionic_component (warehouse_id, item_id, component_id, cost) - -- SELECT t.warehouse_id, m.Id_Article, mc.Id_Componente, mc.Valor - -- FROM Movimientos_componentes mc - -- JOIN Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento - -- JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket - -- JOIN tarifa_componentes tc ON tc.Id_componente = mc.Id_Componente - -- WHERE m.Id_Ticket = v_ticket AND tc.is_renewable = FALSE; + REPLACE INTO tmp.bionic_component (warehouse_id, item_id, component_id, cost) + SELECT t.warehouse_id, m.Id_Article, mc.Id_Componente, mc.Valor + FROM Movimientos_componentes mc + JOIN Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento + JOIN Tickets t ON t.Id_Ticket = m.Id_Ticket + JOIN tarifa_componentes tc ON tc.Id_componente = mc.Id_Componente + WHERE m.Id_Ticket = v_ticket AND tc.is_renewable = FALSE; -- para recuperar el shipment en caso de que se necesite @@ -21998,11 +22025,12 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `clean`(IN v_full TINYINT(1)) BEGIN DECLARE v_date DATETIME; - DECLARE v_date_fut DATE; DECLARE v_date18 DATETIME; DECLARE v_date8 DATE; DECLARE v_date6 DATE; DECLARE v_date3Month DATE; + DECLARE vDate2000 DATE; + DECLARE vRangeDeleteTicket INT; DECLARE strtable varchar(15) DEFAULT NULL; DECLARE done BIT DEFAULT 0; @@ -22011,7 +22039,7 @@ BEGIN SET v_date3Month = TIMESTAMPADD(MONTH, -3, CURDATE()); SET v_date8 = TIMESTAMPADD(DAY, -8,CURDATE()); SET v_date6 = TIMESTAMPADD(DAY, -6,CURDATE()); - + SET vRangeDeleteTicket = 60; INSERT INTO vn2008.daily_task_log(consulta) VALUES('clean START'); DELETE FROM cdr WHERE calldate < v_date; @@ -22079,21 +22107,17 @@ BEGIN JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada JOIN travel t ON t.id = e.travel_id WHERE t.landing <= v_date; - -- + DELETE FROM vn2008.scan WHERE odbc_date < v_date6 AND id <> 1; - SET v_date = TIMESTAMPADD(YEAR, 2000 - YEAR(v_date), v_date); - SET v_date_fut = TIMESTAMPADD(MONTH, 3, v_date); - - IF v_date_fut > '2000-12-31' THEN - SET v_date_fut = '2000-12-30'; - END IF; + SET vDate2000 = TIMESTAMPADD(YEAR, 2000 - YEAR(CURDATE()), CURDATE()); IF v_full THEN DELETE FROM Tickets - WHERE (Fecha <= v_date AND Fecha NOT IN ('2000-01-01','2000-01-02')) - OR (Fecha BETWEEN v_date_fut AND '2000-12-31'); + WHERE Fecha NOT IN ('2000-01-01','2000-01-02') + AND YEAR(Fecha) = 2000 + AND ABS(DATEDIFF(Fecha,vDate2000)) > vRangeDeleteTicket; DELETE e.* FROM Entradas e LEFT JOIN recibida_entrada re ON e.Id_Entrada = re.Id_Entrada @@ -35708,7 +35732,7 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `radartest` */; +/*!50003 DROP PROCEDURE IF EXISTS `radarTest` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -35718,7 +35742,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `radartest`(IN today DATETIME, IN worker INTEGER, IN scopeDays SMALLINT) +CREATE DEFINER=`root`@`%` PROCEDURE `radarTest`(IN today DATETIME, IN worker INTEGER, IN scopeDays SMALLINT) BEGIN DECLARE todayMidnight DATE DEFAULT TIMESTAMP(today,'23:59:59'); @@ -35738,10 +35762,9 @@ BEGIN -- SELECT TIMESTAMP(TIMESTAMPADD(DAY, 14, yesterday),'23:59:59') INTO maxDate; -- Creamos una tabla con los Comerciales de los que se mostraran los tickets CALL subordinate(worker,TRUE); - + select now(),1; -- Se genera una tabla con los tickets representados DROP TEMPORARY TABLE IF EXISTS ticketRange; - CREATE TEMPORARY TABLE ticketRange SELECT T.Id_Ticket, T.Id_Cliente, C.Id_Trabajador FROM Tickets T @@ -35798,7 +35821,7 @@ BEGIN AND Fecha <= maxDate AND T.Factura Is NULL AND IFNULL(tls.alertLevel,0) < 3 AND w.workerId = worker; - + select now(),2; IF (SELECT COUNT(*) FROM ticketRange) THEN -- Generamos varias auxiliares (ya podian los de mysql haber solucionado esto) @@ -35815,64 +35838,106 @@ BEGIN ENGINE = MEMORY SELECT Id_Cliente FROM tmp.client_list; - -- usar ticket_total crear ticket_tmp(ticket_id) - DROP TEMPORARY TABLE IF EXISTS ticket_tmp; - CREATE TEMPORARY TABLE `ticket_tmp` + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket ENGINE = MEMORY - SELECT t.Id_Ticket ticket_id FROM Tickets t + SELECT t.Id_Ticket ticketFk FROM Tickets t STRAIGHT_JOIN tmp.client_list c ON t.Id_Cliente = c.Id_Cliente WHERE Fecha BETWEEN dateStart AND maxDate AND Factura Is NULL; - - CALL ticket_total(); - + select now(),3; + CALL vn.ticketGetTotal(); + select now(),4; -- Generamos otra tabla temporal con los Tickets_iva DROP TEMPORARY TABLE IF EXISTS tt3; CREATE TEMPORARY TABLE tt3 ENGINE = MEMORY - SELECT * FROM ticket_total tt - JOIN ticketRange tr ON tr.Id_Ticket = tt.ticket_id; - + SELECT * FROM tmp.ticketTotal tt + JOIN ticketRange tr ON tr.Id_Ticket = tt.ticketFk; -- Generamos la lista de tickets y sus datos DROP TEMPORARY TABLE IF EXISTS Radartest; CREATE TEMPORARY TABLE Radartest - (INDEX (Id_Ticket)) - ENGINE = MEMORY - SELECT IF(c.Id_Trabajador = worker, 1, 0) as Propio, + + SELECT IF(C.Id_Trabajador = worker, 1, 0) as Propio, Credito, - 0 Riesgo, + CAST(Riesgo AS DECIMAL (10,2)) Riesgo, -- Greuge, - t.Id_Ticket, - t.warehouse_id as wh, - t.Fecha, - t.Alias, + T.Id_Ticket, + T.warehouse_id as wh, + T.Fecha, + T.Alias, -- T.Vista, REPEAT(' ',50) as problem, - a.Agencia Tipo, - tt3.Id_Trabajador, - t.Solucion, - t.Localizacion, - IFNULL(s.`name`,'LIBRE') as Estado, - ts.alertLevel, - Date(t.Fecha) as Fecha_Simple, - tt3.total as Importe, - c.Descuento, - c.calidad, - c.Id_Cliente, + T.Agencia Tipo, + -- C.Id_Trabajador, + T.workerId AS Id_Trabajador, + T.Solucion, + T.Localizacion, + IFNULL(state,'LIBRE') as Estado, + alertLevel, + alertCode, + Date(T.Fecha) as Fecha_Simple, + CAST(T.Importe AS DECIMAL (10,2)) Importe, + C.Descuento, + C.calidad, + C.Id_Cliente, p.`name` provincia - FROM tt3 - JOIN Tickets t ON t.Id_Ticket = tt3.ticket_id - JOIN Clientes c ON c.Id_Cliente = t.Id_Cliente - LEFT JOIN vn.ticketState ts on ts.ticket = tt3.ticket_id - LEFT JOIN vn2008.state s on s.id = ts.state - JOIN Agencias a ON a.Id_Agencia = t.Id_Agencia - LEFT JOIN Consignatarios co ON co.Id_Consigna = t.Id_Consigna - LEFT JOIN province p ON p.province_id = co.province_id; - + FROM Clientes C + INNER JOIN + + ( + + SELECT T.* , A.Vista, A.Agencia, s.`name` as state, alertLevel, s.`code` AS alertCode, tt3.Id_Trabajador AS workerId, + + tt3.total as Importe, + + 0 AS inacabable + + -- (-1 < ifnull(order_id,-1)) as isbionic + + FROM Tickets T + LEFT JOIN vn.ticketState ts on ts.ticket = T.Id_Ticket + LEFT JOIN vn2008.state s on s.id = ts.state + + INNER JOIN tt3 ON tt3.ticketFk = T.Id_Ticket + + -- LEFT JOIN (SELECT DISTINCT 1 as order_id, Id_Ticket FROM order_Tickets) o on o.Id_Ticket = T.Id_Ticket + + INNER JOIN Agencias A ON A.Id_Agencia = T.Id_Agencia + + -- WHERE T.Etiquetasemitidas = FALSE + GROUP BY T.Id_Ticket + + ) AS T ON T.Id_Cliente = C.Id_Cliente + + LEFT JOIN Consignatarios co ON co.Id_Consigna = T.Id_Consigna + LEFT JOIN province p ON p.province_id = co.province_id + + LEFT JOIN + + ( + + SELECT TOTAL.Id_Cliente, ROUND(SUM(amount),2) as Riesgo FROM + + (SELECT cl.Id_Cliente, amount FROM bi.customer_risk cr + INNER JOIN tmp.client_list cl ON cr.customer_id = cl.Id_Cliente + + UNION ALL + + SELECT t.Id_Cliente, tt.total FROM tmp.ticketTotal tt + INNER JOIN Tickets t ON t.Id_Ticket = tt.ticketFk + INNER JOIN cr5 C ON C.Id_Cliente = t.Id_Cliente + WHERE t.Fecha BETWEEN dateStart AND maxDate + AND t.Factura is null + + ) as TOTAL GROUP BY TOTAL.Id_Cliente + + ) AS Peligros ON Peligros.Id_Cliente = C.Id_Cliente + ; -- Actualizamos el Riesgo con los tickets futuros set @cliente:= 0; SET @riesgo := 0; @@ -35880,17 +35945,16 @@ BEGIN UPDATE Radartest SET Riesgo = IF(@cliente <> @cliente:= Id_Cliente , - Importe + @riesgo:= - Riesgo + Importe , - Importe + @riesgo:= @riesgo + Importe) order by Id_Cliente, Fecha_Simple DESC; - - - + select now(),5; DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; CREATE TEMPORARY TABLE tmp.ticket_list SELECT Id_Ticket, Id_Cliente FROM Radartest; - + select now(),6; CALL prepare_client_list(); + select now(),7; CALL production_buffer_problems; - + select now(),8; UPDATE Radartest r JOIN ( SELECT Id_Ticket, GROUP_CONCAT(problem) problem @@ -35898,7 +35962,7 @@ BEGIN GROUP BY Id_Ticket ) p on p.Id_Ticket = r.Id_Ticket SET r.problem = p.problem; - + select now(),9; SELECT R.*, Riesgo + Credito as Risk , CodigoTrabajador @@ -35911,6 +35975,8 @@ BEGIN DROP TABLE IF EXISTS subordinate; DROP TEMPORARY TABLE IF EXISTS tmp.client_list; DROP TEMPORARY TABLE IF EXISTS cr5; + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + END ;; DELIMITER ; @@ -38277,7 +38343,7 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `supplierExcerpt` */; +/*!50003 DROP PROCEDURE IF EXISTS `suppliersDebt` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -38287,11 +38353,55 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `supplierExcerpt`(vSupplierFk INT, vCurrencyFk INT, vCompanyFk INT, vOrderBy VARCHAR(15)) +CREATE DEFINER=`root`@`%` PROCEDURE `suppliersDebt`() +BEGIN + + SELECT abbreviation as Empresa, Proveedor, Euros, empresa_id, proveedor_id + FROM + ( + SELECT empresa_id, proveedor_id, cast(sum(Euros) AS DECIMAL(10,2)) as Euros + FROM + ( + SELECT empresa_id, proveedor_id, -1 * cantidad as Euros + FROM recibida_vencimiento rv + INNER JOIN recibida r ON r.id = rv.recibida_id + WHERE r.fecha > '2014-12-31' + + UNION ALL + + SELECT empresa_id, id_proveedor, importe + FROM pago + WHERE fecha > '2014-12-31' + ) sub + GROUP BY empresa_id, proveedor_id + ) sub2 + JOIN Proveedores p ON p.Id_Proveedor = sub2.proveedor_id + JOIN empresa e ON e.id = sub2.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 `supplierStatement` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `supplierStatement`(vSupplierFk INT, vCurrencyFk INT, vCompanyFk INT, vOrderBy VARCHAR(15)) BEGIN SET @saldo_eur:= 0; SET @saldo_div:= 0; + DROP TEMPORARY TABLE IF EXISTS tmp.supplierStatement; + + CREATE TEMPORARY TABLE tmp.supplierStatement ENGINE = MEMORY SELECT *, @saldo_eur:= round(@saldo_eur + IFNULL(Pago_Euros, 0) - IFNULL(Fac_Euros, 0) ,2 ) AS saldo_eur, @@ -38358,48 +38468,7 @@ BEGIN AND vCurrencyFk IN (p.id_moneda,0) AND vCompanyFk IN (p.empresa_id,0) ) AS SUB - ORDER BY fecha, id) t; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `suppliersDebt` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `suppliersDebt`() -BEGIN - - SELECT abbreviation as Empresa, Proveedor, Euros, empresa_id, proveedor_id - FROM - ( - SELECT empresa_id, proveedor_id, cast(sum(Euros) AS DECIMAL(10,2)) as Euros - FROM - ( - SELECT empresa_id, proveedor_id, -1 * cantidad as Euros - FROM recibida_vencimiento rv - INNER JOIN recibida r ON r.id = rv.recibida_id - WHERE r.fecha > '2014-12-31' - - UNION ALL - - SELECT empresa_id, id_proveedor, importe - FROM pago - WHERE fecha > '2014-12-31' - ) sub - GROUP BY empresa_id, proveedor_id - ) sub2 - JOIN Proveedores p ON p.Id_Proveedor = sub2.proveedor_id - JOIN empresa e ON e.id = sub2.empresa_id - ; + ORDER BY fecha, IF(vOrderBy = 'dueDate', id, NULL)) t; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -42696,8 +42765,7 @@ BEGIN total DOUBLE DEFAULT 0) ENGINE = MEMORY; - ALTER TABLE inv ADD PRIMARY KEY USING HASH (warehouseFk, itemFk); - + ALTER TABLE inv ADD PRIMARY KEY USING HASH (warehouseFk, itemFk); -- Valor del inventario INSERT INTO inv(warehouseFk, itemFk, amount) SELECT TR.warehouse_id, C.Id_Article, C.Cantidad @@ -42711,7 +42779,17 @@ BEGIN AND E.Id_Proveedor = 4 AND reino_id NOT IN (7) ON DUPLICATE KEY UPDATE inv.amount = inv.amount + C.Cantidad; - +select warehouseFk,inv.amount AS 'Inventario' from inv where itemFk=2080; + SELECT TR.warehouse_id, C.Id_Article, C.Cantidad + FROM Compres C + JOIN Articles A USING(Id_Article) + JOIN Entradas E USING (Id_Entrada) + JOIN travel TR ON TR.id = E.travel_id + JOIN Tipos t USING(tipo_id) + JOIN warehouse w ON w.id = TR.warehouse_id + WHERE landing = vLastInventoryDate + AND E.Id_Proveedor = 4 + AND reino_id NOT IN (7); -- Añadimos compras INSERT INTO inv(warehouseFk, itemFk, amount) SELECT TR.warehouse_id, C.Id_Article, C.Cantidad @@ -42726,7 +42804,22 @@ BEGIN AND NOT w.fuente AND reino_id NOT IN (7) AND t.inventory + AND E.Id_Proveedor <> 4 ON DUPLICATE KEY UPDATE inv.amount = inv.amount + C.Cantidad; +select warehouseFk,inv.amount AS '+Compras' from inv where itemFk=2080; + SELECT TR.warehouse_id, C.Id_Article, C.Cantidad, C.Id_Entrada + FROM Compres C + INNER JOIN Articles A USING(Id_Article) + INNER JOIN Entradas E USING (Id_Entrada) + INNER JOIN travel TR ON TR.id = E.travel_id + INNER JOIN Tipos t USING(tipo_id) + INNER JOIN warehouse w ON w.id = TR.warehouse_id + WHERE landing BETWEEN vLastInventoryDate AND vDate + AND NOT redada + AND NOT w.fuente + AND E.Id_Proveedor <> 4 + AND reino_id NOT IN (7) + AND t.inventory; -- Restamos salidas INSERT INTO inv(warehouseFk, itemFk, amount) @@ -42743,7 +42836,19 @@ BEGIN AND reino_id NOT IN (7) AND t.inventory ON DUPLICATE KEY UPDATE inv.amount = inv.amount - C.Cantidad; - +select warehouseFk,inv.amount AS '-Salidas' from inv where itemFk=2080 ; + SELECT TR.warehouse_id_out, C.Id_Article, - C.Cantidad + FROM Compres C + INNER JOIN Articles A USING(Id_Article) + INNER JOIN Entradas E USING (Id_Entrada) + INNER JOIN travel TR ON TR.id = E.travel_id + INNER JOIN Tipos t USING(tipo_id) + INNER JOIN warehouse w ON w.id = warehouse_id_out + WHERE shipment BETWEEN vLastInventoryDate AND vDate + AND NOT redada + AND NOT w.fuente + AND reino_id NOT IN (7) + AND t.inventory; -- Restamos ventas INSERT INTO inv(warehouseFk, itemFk, amount) SELECT w.id, M.Id_Article, - M.Cantidad @@ -42759,6 +42864,18 @@ BEGIN AND t.inventory ON DUPLICATE KEY UPDATE inv.amount = inv.amount - M.Cantidad; +select warehouseFk,inv.amount AS '-Ventas' from inv where itemFk=2080; + SELECT w.id, M.Id_Article, - M.Cantidad, T.Id_Ticket + FROM Movimientos M + INNER JOIN Tickets T USING (Id_Ticket) + INNER JOIN Clientes C USING(Id_Cliente) + INNER JOIN Articles A USING(Id_Article) + INNER JOIN Tipos t USING(tipo_id) + INNER JOIN warehouse w ON w.id = warehouse_id + WHERE T.Fecha BETWEEN vLastInventoryDate AND TIMESTAMPADD(DAY, -1 ,vDate) + AND NOT w.fuente + AND reino_id NOT IN (7) + AND t.inventory; -- Restamos el dia de hoy INSERT INTO inv(warehouseFk, itemFk, amount) SELECT w.id, M.Id_Article, - M.Cantidad @@ -42774,9 +42891,21 @@ BEGIN AND reino_id NOT IN (7) AND t.inventory ON DUPLICATE KEY UPDATE inv.amount = inv.amount - M.Cantidad ; - +select inv.amount AS '-Hoy' from inv where itemFk=2080; + SELECT w.id, M.Id_Article, - M.Cantidad + FROM Movimientos M + INNER JOIN Tickets T USING (Id_Ticket) + INNER JOIN Clientes C USING(Id_Cliente) + INNER JOIN Articles A USING(Id_Article) + INNER JOIN Tipos t USING(tipo_id) + INNER JOIN warehouse w ON w.id = warehouse_id + WHERE date(T.Fecha) = vDate + AND (vDate <> CURDATE() or (M.OK <> 0 or T.Etiquetasemitidas <> 0 )) + AND NOT w.fuente + AND reino_id NOT IN (7) + AND t.inventory; CALL item_last_buy_from_interval(NULL,vLastInventoryDate,vDate); - +select inv.amount from inv where itemFk=2080; UPDATE inv JOIN tmp.item_last_buy_from_interval lb ON inv.warehouseFk = lb.warehouse_id AND inv.itemFk = lb.item_id @@ -42784,7 +42913,7 @@ BEGIN SET total = inv.amount * (ifnull(C.Costefijo,0) + IFNULL(C.Embalajefijo,0) + IFNULL(C.Portefijo,0) + IFNULL(C.Comisionfija,0)), cost = ifnull(C.Costefijo,0) + IFNULL(C.Embalajefijo,0) + IFNULL(C.Portefijo,0) + IFNULL(C.Comisionfija,0) WHERE inv.amount <> 0; - +select inv.amount from inv where itemFk=2080; DELETE FROM inv WHERE amount IS NULL or amount = 0; IF vIsItemised THEN @@ -42902,9 +43031,9 @@ DELIMITER ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `vips_in_a_week`(vCondition VARCHAR(512)) -BEGIN +BEGIN CALL util.exec (CONCAT( - 'SELECT C.Id_Cliente, C.Cliente, RED(SUM((M.Cantidad * M.Preu) * 100 - M.Descuento) / 100) as Importe + 'SELECT C.Id_Cliente, C.Cliente, ROUND(SUM((M.Cantidad * M.Preu) * 100 - M.Descuento) / 100, 2) as Importe FROM vn2008.Clientes C JOIN vn2008.Tickets T ON T.Id_Cliente = C.Id_Cliente JOIN vn2008.Movimientos M ON M.Id_Ticket = T.Id_Ticket @@ -43395,20 +43524,27 @@ SET character_set_client = utf8; /*!50001 CREATE TABLE `address` ( `id` tinyint NOT NULL, `clientFk` tinyint NOT NULL, + `customer` tinyint NOT NULL, `street` tinyint NOT NULL, `city` tinyint NOT NULL, `postalCode` tinyint NOT NULL, `provinceFk` tinyint NOT NULL, + `province` tinyint NOT NULL, `phone` tinyint NOT NULL, `mobile` tinyint NOT NULL, + `celular` tinyint NOT NULL, `nickname` tinyint NOT NULL, `isDefaultAddress` tinyint NOT NULL, + `defaultAddress` tinyint NOT NULL, `longitude` tinyint NOT NULL, `latitude` tinyint NOT NULL, `warehouseFk` tinyint NOT NULL, + `warehouse` tinyint NOT NULL, `agencyFk` tinyint NOT NULL, + `agency` tinyint NOT NULL, `isEqualizated` tinyint NOT NULL, - `isActive` tinyint NOT NULL + `isActive` tinyint NOT NULL, + `active` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; @@ -43918,7 +44054,7 @@ CREATE TABLE `clientLog` ( KEY `userFk` (`userFk`), CONSTRAINT `clientLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `clientLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=147609 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=148090 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44315,7 +44451,7 @@ CREATE TABLE `creditInsurance` ( PRIMARY KEY (`id`), KEY `CreditInsurance_Fk1_idx` (`creditClassification`), CONSTRAINT `CreditInsurance_Fk1` FOREIGN KEY (`creditClassification`) REFERENCES `creditClassification` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1701 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalla los clientes que tienen seguro de credito'; +) ENGINE=InnoDB AUTO_INCREMENT=1704 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalla los clientes que tienen seguro de credito'; /*!40101 SET character_set_client = @saved_cs_client */; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -44500,7 +44636,7 @@ CREATE TABLE `entryLog` ( KEY `logEntry_ibfk_1` (`originFk`), CONSTRAINT `entryLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Entradas` (`Id_Entrada`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `entryLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=25664 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=26307 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44964,7 +45100,7 @@ CREATE TABLE `invoiceOutExpence` ( KEY `invoiceOutExpence_FK_2_idx` (`expenceFk`), CONSTRAINT `invoiceOutExpence_FK_1` FOREIGN KEY (`invoiceOutFk`) REFERENCES `vn2008`.`Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceOutExpence_FK_2` FOREIGN KEY (`expenceFk`) REFERENCES `vn2008`.`Gastos` (`Id_Gasto`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=45525 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Desglosa la base imponible de una factura en funcion del tipo de gasto/venta'; +) ENGINE=InnoDB AUTO_INCREMENT=48393 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Desglosa la base imponible de una factura en funcion del tipo de gasto/venta'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45007,7 +45143,7 @@ CREATE TABLE `invoiceOutTax` ( KEY `pgcFk` (`pgcFk`), CONSTRAINT `invoiceOutFk` FOREIGN KEY (`invoiceOutFk`) REFERENCES `vn2008`.`Facturas` (`factura_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `invoiceOutTax_ibfk_1` FOREIGN KEY (`pgcFk`) REFERENCES `pgc` (`code`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=855644 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=866583 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45147,6 +45283,27 @@ CREATE TABLE `itemConversor` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona los item específicos con los genéricos'; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `itemLog` +-- + +DROP TABLE IF EXISTS `itemLog`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `itemLog` ( + `id` int(11) NOT NULL DEFAULT '0', + `originFk` int(11) NOT NULL, + `userFk` int(10) unsigned NOT NULL, + `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL, + `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `description` text COLLATE utf8_unicode_ci NOT NULL, + KEY `itemLogItemFk_idx` (`originFk`), + KEY `itemLogUserFk_idx` (`userFk`), + CONSTRAINT `itemLogItemFk` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `itemLogUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Temporary table structure for view `itemPlacement` -- @@ -45241,7 +45398,7 @@ CREATE TABLE `itemTaxCountry` ( CONSTRAINT `countryFK_paises` FOREIGN KEY (`countryFk`) REFERENCES `vn2008`.`Paises` (`Id`) ON UPDATE CASCADE, CONSTRAINT `itemFK_Article` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `taxClassFK_Iva_Group` FOREIGN KEY (`taxClassFk`) REFERENCES `vn2008`.`iva_group` (`iva_group_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=439744 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Define la clase de iva por artículo y pais'; +) ENGINE=InnoDB AUTO_INCREMENT=440335 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Define la clase de iva por artículo y pais'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45433,7 +45590,7 @@ CREATE TABLE `message` ( KEY `sender` (`sender`), KEY `recipient` (`recipient`), KEY `uuid` (`uuid`(8)) -) ENGINE=InnoDB AUTO_INCREMENT=1346492 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1350061 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45455,7 +45612,7 @@ CREATE TABLE `messageInbox` ( PRIMARY KEY (`id`), KEY `uuid` (`uuid`(8)), KEY `finalRecipient` (`finalRecipient`) -) ENGINE=InnoDB AUTO_INCREMENT=1490245 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1493862 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46200,7 +46357,7 @@ CREATE TABLE `routeLog` ( `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `description` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=334756 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=337879 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46275,7 +46432,7 @@ CREATE TABLE `sms` ( `status` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=87656 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=87791 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46425,7 +46582,7 @@ CREATE TABLE `stockBuyed` ( UNIQUE KEY `date_UNIQUE` (`date`,`user`), KEY `stockBuyed_user_idx` (`user`), CONSTRAINT `stockBuyedUserFk` FOREIGN KEY (`user`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=228842 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=231344 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46652,8 +46809,39 @@ CREATE TABLE `ticketLog` ( KEY `logTicketuserFk` (`userFk`), CONSTRAINT `ticketLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=290031 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=326140 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`ticketLog_AFTER_INSERT` AFTER INSERT ON `ticketLog` FOR EACH ROW +BEGIN + DECLARE vActionId INT DEFAULT 84; + DECLARE vWorkerFk INT; + DECLARE vWebWorkerFk INT DEFAULT 4; + + SELECT id INTO vWorkerFk + FROM worker w + WHERE w.userFk = NEW.userFk; + + IF ISNULL(vWorkerFk) THEN + SET vWorkerFk = vWebWorkerFk; + END IF; + + INSERT INTO vn2008.Tickets_dits(idaccion_dits,Id_Trabajador,Id_Ticket,value_old,value_new) + VALUES (vActionId, vWorkerFk, NEW.originFk, 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 */ ; -- -- Temporary table structure for view `ticketObservation` @@ -46705,7 +46893,7 @@ CREATE TABLE `ticketPackaging` ( KEY `ticketPackaging_fk2_idx` (`packagingFk`), CONSTRAINT `ticketPackaging_fk1` FOREIGN KEY (`ticketFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketPackaging_fk2` FOREIGN KEY (`packagingFk`) REFERENCES `vn2008`.`Cubos` (`Id_Cubo`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=6319 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=6958 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47076,7 +47264,7 @@ CREATE TABLE `workerDocument` ( KEY `workerDocument_ibfk_2` (`document`), CONSTRAINT `workerDocument_ibfk_1` FOREIGN KEY (`worker`) REFERENCES `vn2008`.`Trabajadores` (`user_id`) ON UPDATE CASCADE, CONSTRAINT `workerDocument_ibfk_2` FOREIGN KEY (`document`) REFERENCES `vn2008`.`gestdoc` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3270 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3315 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47098,7 +47286,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 `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=1258 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1278 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47149,7 +47337,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 AUTO_INCREMENT=14972 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena horas de Entrada y de Salida del personal'; +) ENGINE=InnoDB AUTO_INCREMENT=15208 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Almacena horas de Entrada y de Salida del personal'; /*!40101 SET character_set_client = @saved_cs_client */; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -47592,7 +47780,6 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `getAlert3State` */; -ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -47603,6 +47790,55 @@ ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `getAlert3State`(vTicket INT) RETURNS varchar(45) CHARSET latin1 +BEGIN + DECLARE vDeliveryType INTEGER DEFAULT 0; + DECLARE 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 `getAlert3StateKk` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` FUNCTION `getAlert3StateKk`(vTicket INT) RETURNS varchar(45) CHARSET latin1 BEGIN DECLARE vDeliveryType INTEGER DEFAULT 0; DECLARE vWorker INT; @@ -47643,7 +47879,56 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; +/*!50003 DROP FUNCTION IF EXISTS `getAlert3StateTest` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` FUNCTION `getAlert3StateTest`(vTicket INT) RETURNS varchar(45) CHARSET latin1 +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 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 AND w.warehouse_id = t.warehouse_id + 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` */; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -48784,6 +49069,54 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `addressTaxArea` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `addressTaxArea`() + READS SQL DATA +BEGIN +/** + * Devuelve el taxArea para un conjunto de Consignatarios y empresas, + * + * @table tmp.addressCompany(addressFk, companyFk) valores a calcular + * @return tmp.addressTaxArea(addressFk,companyFk) + */ + + DECLARE vSpainCountryCode INT DEFAULT 1; + + DROP TEMPORARY TABLE IF EXISTS tmp.addressTaxArea; + CREATE TEMPORARY TABLE tmp.addressTaxArea + (PRIMARY KEY (addressFk, companyFk)) + ENGINE = MEMORY + SELECT CASE + WHEN (NOT cClient.isUeeMember OR NOT cSupplier.isUeeMember) AND s.countryFk != c.countryFk THEN + 'WORLD' + WHEN cClient.isUeeMember AND cSupplier.isUeeMember AND c.countryFk != s.countryFk AND c.isVies THEN + 'CEE' + WHEN a.isEqualizated AND c.countryFk = vSpainCountryCode THEN + 'EQU' + ELSE + 'NATIONAL' + END AS areaFk, ac.addressFk, ac.companyFk + FROM tmp.addressCompany ac + JOIN address a ON a.id = ac.addressFk + JOIN `client` c ON c.id = a.clientFk + JOIN country cClient ON cClient.id = c.countryFk + JOIN supplier s ON s.id = ac.companyFk + JOIN country cSupplier ON cSupplier.id = s.countryFk; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `agencyListAvailable` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48879,10 +49212,11 @@ BEGIN IF day(CURDATE()) IN (10,20,30) THEN UPDATE vn.client c + JOIN vn.clientType ct ON ct.id = c.id JOIN bi.defaulters d ON d.client = c.id AND d.date = CURDATE() JOIN vn.config ON TRUE SET c.isFreezed = TRUE - WHERE d.amount > config.defaultersMaxAmount; + WHERE d.amount > config.defaultersMaxAmount AND ct.code = 'normal'; END IF; @@ -51097,7 +51431,7 @@ BEGIN FROM supplier s JOIN invoiceOut io ON io.companyFk = s.id WHERE io.id = vInvoice; - + /* SELECT IF(a.isEqualizated AND c.countryFk = vSpainCountryCode AND i.taxAreaFk = 'NATIONAL', @@ -51111,7 +51445,7 @@ BEGIN JOIN client c ON c.id = t.clientFk WHERE io.id = vInvoice AND i.code = invoiceSerial(io.clientFk,io.companyFk,'R') LIMIT 1; - + */ DROP TEMPORARY TABLE IF EXISTS ticketToInvoice; CREATE TEMPORARY TABLE ticketToInvoice @@ -51120,7 +51454,9 @@ BEGIN WHERE refFk = vInvoiceRef; CALL invoiceExpenceMake(vInvoice); - CALL invoiceTaxMake(vInvoice,vCountry,vTaxArea); + + -- CALL invoiceTaxMake(vInvoice,vCountry,vTaxArea); + CALL invoiceTaxMake(vInvoice,vCountry); UPDATE invoiceOut io JOIN ( @@ -53853,137 +54189,112 @@ BEGIN * tickets de la table ticketClosure. */ - DECLARE vDone BOOL; - DECLARE vClientFk INT; - DECLARE vCredit INT; - DECLARE vPayMethod INT; + DECLARE vDone BOOL; + DECLARE vClientFk INT; DECLARE vTicketFk INT; - DECLARE vIsToBeMailed BOOL; - DECLARE vIsTaxDataChecked BOOL; + DECLARE vIsTaxDataChecked BOOL; DECLARE vCompanyFk INT; - DECLARE vDeliveryMethod INT; - DECLARE vAgencyFk INT; - DECLARE vAgencyModeFk INT; - DECLARE vWarehouseFk INT; DECLARE vShipped DATE; - DECLARE vWarehouseVnh INT DEFAULT 7; - DECLARE vWarehouseFloramondo INT DEFAULT 40; - DECLARE vCompanyBlk INT DEFAULT 965; - DECLARE vCompanyCcs INT DEFAULT 69; - DECLARE vAgencyPackage INT DEFAULT 628; - DECLARE vPayMethodCard INT DEFAULT 5; - DECLARE vhasPackage BOOL DEFAULT 0; DECLARE vPriority INT DEFAULT 1; DECLARE vReportDeliveryNote INT DEFAULT 1; - DECLARE vReportInvoice INT DEFAULT 3; - DECLARE vNewPackageTicket INT; - DECLARE vNewInvoiceId INT; - DECLARE vHasToInvoice BOOL; + DECLARE vNewInvoiceId INT; + DECLARE vIsUeeMember BOOL; + DECLARE vWithPackage BOOL; - DECLARE cur CURSOR FOR - SELECT ticketFk FROM tmp.ticketClosure; + DECLARE cur CURSOR FOR + SELECT ticketFk FROM tmp.ticketClosure; - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN RESIGNAL; - END; + END; - OPEN cur; + INSERT INTO dailyTaskLog(state) VALUES('ticketClosure: START'); + + OPEN cur; proc: LOOP - SET vDone = FALSE; - SET vNewPackageTicket = 0; + SET vDone = FALSE; FETCH cur INTO vTicketFk; IF vDone THEN - LEAVE proc; - END IF; + LEAVE proc; + END IF; - -- ticketClosure start + -- ticketClosure start SELECT - c.id, - c.credit, - c.paymentMethodFk, - c.isToBeMailed, - c.isTaxDataChecked, - t.companyFk, - IFNULL(aw.agencyType, a.deliveryMethod) AS deliveryMethod, - a.id AS agencyFk, - t.agencyModeFk, - t.warehouseFk, + c.id, + c.isTaxDataChecked, + t.companyFk, t.shipped, - c.hasToInvoice - INTO vClientFk, - vCredit, - vPayMethod, - vIsToBeMailed, - vIsTaxDataChecked, - vCompanyFk, - vDeliveryMethod, - vAgencyFk, - vAgencyModeFk, - vWarehouseFk, + co.isUeeMember, + w.isManaged + INTO vClientFk, + vIsTaxDataChecked, + vCompanyFk, vShipped, - vHasToInvoice - FROM ticket t - INNER JOIN `client` c ON c.id = t.clientFk - LEFT JOIN agencyMode a ON a.id = t.agencyModeFk - LEFT JOIN agencyWarehouse aw ON a.id = aw.agencyFk AND t.warehouseFk = aw.warehouseFk - WHERE t.id = vTicketFk; + vIsUeeMember, + vWithPackage + 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 = vTicketFk; -- Fusión de ticket - CALL mergeTicketUnattended(vTicketFk, TRUE); + -- CALL mergeTicketUnattended(vTicketFk, TRUE); JGF 2017/12/04 - INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity) - (SELECT vTicketFk, p.id, COUNT(*) - FROM expedition e - JOIN package p ON p.itemFk = e.itemFk - WHERE e.ticketFk = vTicketFk AND p.isPackageReturnable - GROUP BY p.itemFk); + INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity) + (SELECT vTicketFk, p.id, COUNT(*) + FROM expedition e + JOIN package p ON p.itemFk = e.itemFk + WHERE e.ticketFk = vTicketFk AND p.isPackageReturnable + AND vWithPackage + GROUP BY p.itemFk); - -- No retornables o no catalogados - INSERT INTO sale (itemFk, ticketFk, concept, quantity, price) - (SELECT e.itemFk, vTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.itemFk, vClientFk) - FROM expedition e - JOIN item i ON i.id = e.itemFk - LEFT JOIN package p ON p.itemFk = i.id - WHERE e.ticketFk = vTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0 - GROUP BY e.itemFk); - - -- Albaran_print - CALL ticketTrackingAdd(vTicketFk, (SELECT vn.getAlert3State(vTicketFk)), 20); - INSERT INTO printServerQueue(priorityFk, reportFk, param1) VALUES(vPriority, vReportDeliveryNote, vTicketFk); + -- No retornables o no catalogados + INSERT INTO movement (item, ticket, concept, amount, price, priceFixed) + (SELECT e.itemFk, vTicketFk, i.name, COUNT(*) AS amount, getSpecialPrice(e.itemFk, vClientFk), 1 + FROM expedition e + JOIN item i ON i.id = e.itemFk + LEFT JOIN package p ON p.itemFk = i.id + WHERE e.ticketFk = vTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0 + AND getSpecialPrice(e.itemFk, vClientFk) > 0 + GROUP BY e.itemFk); + + IF(vIsUeeMember = FALSE) THEN - IF((vCredit <= 1 OR vPayMethod = vPayMethodCard) AND vHasToInvoice <> FALSE) THEN - - -- Facturacion rapida - CALL ticketTrackingAdd(vTicketFk, 'DELIVERED', 20); + -- Facturacion rapida + CALL ticketTrackingAdd(vTicketFk, 'DELIVERED', 20); -- Facturar si está contabilizado IF vIsTaxDataChecked THEN - IF (SELECT clientTaxArea(vClientFk, vCompanyFk)) = 'NATIONAL' THEN - CALL invoiceMakeByClient( - vClientFk, + IF (SELECT clientTaxArea(vClientFk, vCompanyFk)) = 'NATIONAL' THEN + CALL invoiceMakeByClient( + vClientFk, (SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')), vShipped, vCompanyFk, vNewInvoiceId); ELSE - CALL invoiceMakeByTicket(vTicketFk, (SELECT invoiceSerial(vClientFk, vCompanyFk, 'R')), vNewInvoiceId); + CALL invoiceMakeByTicket(vTicketFk, (SELECT invoiceSerial(vClientFk, vCompanyFk, 'R')), vNewInvoiceId); END IF; - END IF; - ELSE - -- Albaran_print - CALL ticketTrackingAdd(vTicketFk, (SELECT vn.getAlert3State(vTicketFk)), 20); + END IF; + ELSE + -- Albaran_print + CALL ticketTrackingAdd(vTicketFk, (SELECT vn.getAlert3State(vTicketFk)), 20); INSERT INTO printServerQueue(priorityFk, reportFk, param1) VALUES(vPriority, vReportDeliveryNote, vTicketFk); END IF; - -- ticketClosure end - END LOOP; - - CLOSE cur; + -- ticketClosure end + END LOOP; + + CLOSE cur; + + INSERT INTO dailyTaskLog(state) VALUES('ticketClosure: END'); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -54462,7 +54773,7 @@ BEGIN JOIN address a ON a.id = ao.addressFk WHERE a.clientFk = vClientId AND a.isDefaultAddress != FALSE; - CALL logAdd(vNewTicket, 'insert', 'ticket', CONCAT('CREA EL TICKET', ' ', vNewTicket)); + CALL logAdd(vNewTicket, 'insert', 'ticket', CONCAT('Ha creado el ticket', ' ', vNewTicket)); IF (SELECT isCreatedAsServed FROM vn.client WHERE id = vClientId ) <> FALSE THEN @@ -54495,18 +54806,20 @@ BEGIN * un conjunto de tickets. * * @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular - * @treturn tmp.ticketTax Impuesto desglosado para cada ticket + * @return tmp.ticketTax Impuesto desglosado para cada ticket * @return tmp.ticketAmount */ - DROP TEMPORARY TABLE IF EXISTS tmp.ticketArea; - CREATE TEMPORARY TABLE tmp.ticketArea - (INDEX (ticketFk)) + DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; + CREATE TEMPORARY TABLE tmp.addressCompany + (INDEX (addressFk, companyFk)) ENGINE = MEMORY - SELECT tmpTicket.ticketFk, addressTaxArea(t.addressFk, t.companyFk) areaFk + SELECT DISTINCT t.addressFk, t.companyFk FROM tmp.ticket tmpTicket JOIN ticket t ON t.id = tmpTicket.ticketFk; - + + CALL addressTaxArea (); + DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax; CREATE TEMPORARY TABLE tmp.ticketTax (INDEX (ticketFk)) @@ -54520,16 +54833,17 @@ BEGIN tc.code FROM tmp.ticket tmpTicket - JOIN tmp.ticketArea ta ON ta.ticketFk = tmpTicket.ticketFk 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 = ta.areaFk + 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 @@ -54543,8 +54857,9 @@ BEGIN SELECT ticketFk, taxableBase, SUM(tax) tax FROM tmp.ticketTax GROUP BY ticketFk, code; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketArea; + + DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; + DROP TEMPORARY TABLE IF EXISTS tmp.addressTaxArea; END ;; DELIMITER ; @@ -54552,6 +54867,52 @@ DELIMITER ; /*!50003 SET character_set_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 */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `ticketGetTaxAdd`(vTicketFk INT) +BEGIN +/** + * Añade un ticket a la tabla tmp.ticket para calcular + * el IVA y el recargo de equivalencia y devuelve el resultado. + */ + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + ENGINE = MEMORY + SELECT vTicketFk ticketFk; + + CALL vn.ticketGetTax(); + + SELECT + tt.ticketFk, + CAST(tt.taxableBase AS DECIMAL(10, 2)) AS taxableBase, + CAST(tt.tax AS DECIMAL(10, 2)) AS tax, + pgc.*, + -- IF(pe.equFk IS NULL, taxableBase, 0) AS Base, + CAST(IF(pe.equFk IS NULL, taxableBase, 0) AS DECIMAL(10, 2)) AS Base, + pgc.rate / 100 as vatPercent + FROM tmp.ticketTax tt + JOIN vn.pgc ON pgc.code = tt.pgcFk + LEFT JOIN vn.pgcEqu pe ON pe.equFk = pgc.code; + + + 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 `ticketGetTaxkk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -54631,13 +54992,16 @@ BEGIN * @return tmp.ticketTotal Total para cada ticket */ CALL ticketGetTax (); - + DROP TEMPORARY TABLE IF EXISTS tmp.ticketTotal; CREATE TEMPORARY TABLE tmp.ticketTotal (INDEX (ticketFk)) ENGINE = MEMORY SELECT ticketFk, SUM(ta.taxableBase + ta.tax) AS total FROM tmp.ticketAmount ta GROUP BY ticketFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount; + DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax; END ;; DELIMITER ; @@ -55163,7 +55527,7 @@ CREATE TABLE `batch` ( KEY `buy_edi_id` (`buy_edi_id`), CONSTRAINT `batch_ibfk_1` FOREIGN KEY (`message_id`) REFERENCES `message` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `batch_ibfk_2` FOREIGN KEY (`buy_edi_id`) REFERENCES `vn2008`.`buy_edi` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=276675 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=277702 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -55260,7 +55624,7 @@ CREATE TABLE `deliveryInformation` ( `LatestOrderDateTime` datetime DEFAULT NULL, `supplyResponseID` int(11) DEFAULT NULL, PRIMARY KEY (`ID`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2046639 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -55501,7 +55865,7 @@ CREATE TABLE `message` ( UNIQUE KEY `mail_id` (`mail_id`), KEY `sender_id` (`sender_id`), CONSTRAINT `message_ibfk_2` FOREIGN KEY (`sender_id`) REFERENCES `mail` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=296385 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=297651 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -55669,7 +56033,7 @@ CREATE TABLE `supplyResponse` ( `MarketPlaceID` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID_UNIQUE` (`ID`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=523827 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -61664,7 +62028,7 @@ CREATE TABLE `cdr` ( KEY `dstchannel` (`dst_channel`), KEY `disposition` (`disposition`), KEY `src` (`src`) -) ENGINE=MyISAM AUTO_INCREMENT=178501 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=MyISAM AUTO_INCREMENT=178994 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -62468,7 +62832,7 @@ CREATE TABLE `cache_calc` ( KEY `cache_id` (`cache_id`), KEY `cacheName` (`cacheName`), KEY `expires` (`expires`) -) ENGINE=InnoDB AUTO_INCREMENT=67662 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -64381,7 +64745,7 @@ CREATE TABLE `ACL` ( `principalType` varchar(512) CHARACTER SET utf8 DEFAULT NULL, `principalId` varchar(512) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -65154,7 +65518,7 @@ CREATE TABLE `inter` ( CONSTRAINT `inter_ibfk_1` FOREIGN KEY (`Id_Ticket`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `inter_state` FOREIGN KEY (`state_id`) REFERENCES `vn2008`.`state` (`id`) ON UPDATE CASCADE, CONSTRAINT `responsable` FOREIGN KEY (`Id_Supervisor`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=8821795 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=8865982 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 */ ; @@ -66019,7 +66383,7 @@ CREATE TABLE `order` ( CONSTRAINT `order_ibfk_5` FOREIGN KEY (`address_id`) REFERENCES `vn2008`.`Consignatarios` (`id_consigna`) ON UPDATE CASCADE, CONSTRAINT `order_ibfk_8` FOREIGN KEY (`delivery_method_id`) REFERENCES `vn2008`.`Vistas` (`vista_id`) ON UPDATE CASCADE, CONSTRAINT `order_ibfk_9` FOREIGN KEY (`agency_id`) REFERENCES `vn2008`.`Agencias` (`Id_Agencia`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1242334 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1246364 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -66118,7 +66482,7 @@ CREATE TABLE `orderRow` ( KEY `warehouse_shipment` (`warehouseFk`,`shipment`), CONSTRAINT `orderRow_ibfk_2` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON UPDATE CASCADE, CONSTRAINT `orderRow_ibfk_3` FOREIGN KEY (`orderFk`) REFERENCES `order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=7735016 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=7761646 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 */ ; @@ -66538,7 +66902,7 @@ CREATE TABLE `tpvTransaction` ( CONSTRAINT `receipt_id` FOREIGN KEY (`receiptFk`) REFERENCES `vn2008`.`Recibos` (`Id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `tpvTransaction_ibfk_1` FOREIGN KEY (`clientFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `tpvTransaction_ibfk_2` FOREIGN KEY (`merchantFk`) REFERENCES `tpvMerchant` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=187209 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Transactions realized through the virtual TPV'; +) ENGINE=InnoDB AUTO_INCREMENT=187959 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Transactions realized through the virtual TPV'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -66587,7 +66951,7 @@ CREATE TABLE `visit` ( PRIMARY KEY (`id`), KEY `firstAgent` (`firstAgent`), CONSTRAINT `visit_ibfk_1` FOREIGN KEY (`firstAgent`) REFERENCES `visitAgent` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1147304 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1151313 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -66607,7 +66971,7 @@ CREATE TABLE `visitAccess` ( KEY `visit_access_idx_agent` (`agent`), KEY `stamp` (`stamp`), CONSTRAINT `visitAccess_ibfk_1` FOREIGN KEY (`agent`) REFERENCES `visitAgent` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2440628 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2450039 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -66632,7 +66996,7 @@ CREATE TABLE `visitAgent` ( KEY `firstAccess` (`firstAccess`), CONSTRAINT `visitAgent_ibfk_1` FOREIGN KEY (`visit`) REFERENCES `visit` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `visitAgent_ibfk_2` FOREIGN KEY (`firstAccess`) REFERENCES `visitAccess` (`id`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1666846 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1671439 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -66652,7 +67016,7 @@ CREATE TABLE `visitUser` ( KEY `date_time` (`stamp`), KEY `user_id` (`user`), CONSTRAINT `visitUser_ibfk_1` FOREIGN KEY (`access`) REFERENCES `visitAccess` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2372523 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2379645 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -67700,78 +68064,27 @@ BEGIN SELECT id ticketFk FROM myTicket WHERE id = vTicket; - CALL vn.ticketGetTax (); + CALL vn.ticketGetTax; SELECT SUM(taxableBase), SUM(tax) INTO vTaxBase, vTax FROM tmp.ticketAmount; - SELECT t.id, t.landed, t.shipped, t.refFk, ag.description agency, + SELECT t.id, t.landed, t.shipped, t.refFk, ag.description agency, m.code method, a.street, a.postalCode, a.city, a.nickname, p.name province, vTaxBase taxBase, vTaxBase + vTax AS total FROM tmp.ticket v JOIN vn.ticket t ON t.id = v.ticketFk JOIN vn.address a ON a.id = t.addressFk JOIN vn.agencyMode ag ON ag.id = t.agencyModeFk + LEFT JOIN vn.deliveryMethod m ON m.id = ag.deliveryMethodFk LEFT JOIN vn.province p ON p.id = a.provinceFk WHERE t.id = vTicket; DROP TEMPORARY TABLE tmp.ticket, tmp.ticketTax, - 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 `myTicketGetKk` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `myTicketGetKk`(vTicket INT) -BEGIN -/** - * Returns a current user ticket header. - * - * @param vTicket The ticket identifier - */ - DECLARE vTaxBase DECIMAL(10,2); - DECLARE vTax DECIMAL(10,2); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - ENGINE = MEMORY - SELECT id ticketFk FROM myTicket - WHERE id = vTicket; - - CALL vn.ticketGetTax (NULL); - - SELECT SUM(taxBase), SUM(tax + equalizationTax) - INTO vTaxBase, vTax - FROM tmp.ticketTax; - - SELECT t.id, t.landed, t.shipped, t.refFk, ag.description agency, - a.street, a.postalCode, a.city, a.nickname, p.name province, - vTaxBase taxBase, vTaxBase + vTax AS total - FROM tmp.ticket v - JOIN vn.ticket t ON t.id = v.ticketFk - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.agencyMode ag ON ag.id = t.agencyModeFk - LEFT JOIN vn.province p ON p.id = a.provinceFk - WHERE t.id = vTicket; - - DROP TEMPORARY TABLE - tmp.ticket, - tmp.ticketTax; + tmp.ticketAmount; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -67909,7 +68222,7 @@ BEGIN */ INSERT INTO vn.ticketLog (originFk, userFk, `action`, description) - SELECT vTicket, account.userGetId(), 'select', 'Access' + SELECT vTicket, account.userGetId(), 'select', 'Accede a ticket' FROM myTicket t WHERE t.id = vTicket; END ;; @@ -70908,7 +71221,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `address` AS select `t`.`id_consigna` AS `id`,`t`.`Id_cliente` AS `clientFk`,`t`.`domicilio` AS `street`,`t`.`poblacion` AS `city`,`t`.`codPostal` AS `postalCode`,`t`.`province_id` AS `provinceFk`,`t`.`telefono` AS `phone`,`t`.`movil` AS `mobile`,`t`.`consignatario` AS `nickname`,`t`.`predeterminada` AS `isDefaultAddress`,`t`.`longitude` AS `longitude`,`t`.`latitude` AS `latitude`,`t`.`warehouse_id` AS `warehouseFk`,`t`.`Id_Agencia` AS `agencyFk`,`t`.`isEqualizated` AS `isEqualizated`,`t`.`active` AS `isActive` from `vn2008`.`Consignatarios` `t` */; +/*!50001 VIEW `address` AS select `t`.`id_consigna` AS `id`,`t`.`Id_cliente` AS `clientFk`,`t`.`Id_cliente` AS `customer`,`t`.`domicilio` AS `street`,`t`.`poblacion` AS `city`,`t`.`codPostal` AS `postalCode`,`t`.`province_id` AS `provinceFk`,`t`.`province_id` AS `province`,`t`.`telefono` AS `phone`,`t`.`movil` AS `mobile`,`t`.`movil` AS `celular`,`t`.`consignatario` AS `nickname`,`t`.`predeterminada` AS `isDefaultAddress`,`t`.`predeterminada` AS `defaultAddress`,`t`.`longitude` AS `longitude`,`t`.`latitude` AS `latitude`,`t`.`warehouse_id` AS `warehouseFk`,`t`.`warehouse_id` AS `warehouse`,`t`.`Id_Agencia` AS `agencyFk`,`t`.`Id_Agencia` AS `agency`,`t`.`isEqualizated` AS `isEqualizated`,`t`.`active` AS `isActive`,`t`.`active` AS `active` from `vn2008`.`Consignatarios` `t` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -71383,7 +71696,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `country` AS select `p`.`Id` AS `id`,`p`.`Pais` AS `country`,`p`.`CEE` AS `CEE`,if((`p`.`CEE` < 2),1,0) AS `isUeeMember`,`p`.`Codigo` AS `code`,`p`.`Id_Moneda` AS `currencyFk`,`p`.`Id_Paisreal` AS `politicalCountryFk`,`p`.`geoFk` AS `geoFk` from `vn2008`.`Paises` `p` */; +/*!50001 VIEW `country` AS select `p`.`Id` AS `id`,`p`.`Pais` AS `country`,`p`.`CEE` AS `CEE`,`p`.`isUeeMember` AS `isUeeMember`,`p`.`Codigo` AS `code`,`p`.`Id_Moneda` AS `currencyFk`,`p`.`Id_Paisreal` AS `politicalCountryFk`,`p`.`geoFk` AS `geoFk` from `vn2008`.`Paises` `p` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -74436,4 +74749,4 @@ USE `hedera`; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2018-02-01 9:35:46 +-- Dump completed on 2018-02-07 16:28:24 diff --git a/services/db/02-changes.sh b/services/db/02-changes.sh new file mode 100755 index 000000000..14253fe2f --- /dev/null +++ b/services/db/02-changes.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +myDir=$(dirname $0) + +for file in $myDir/changes/*/*.sql; do + echo "Importing $file" + mysql -u root < $file +done diff --git a/services/db/02-fixtures.sql b/services/db/03-fixtures.sql similarity index 93% rename from services/db/02-fixtures.sql rename to services/db/03-fixtures.sql index d6bd1acae..813558575 100644 --- a/services/db/02-fixtures.sql +++ b/services/db/03-fixtures.sql @@ -272,14 +272,14 @@ INSERT INTO `account`.`user`(`id`,`name`,`password`,`role`,`active`,`email`) (10, 'JessicaJones', 'ac754a330530832ba1bf7687f577da91', 9, 1, 'JessicaJones@verdnatura.es'), (11, 'Cyborg', 'ac754a330530832ba1bf7687f577da91', 1, 1, 'cyborg@verdnatura.es'); -INSERT INTO `salix`.`Country`(`id`, `name`, `inCee`, `code`, `currencyFk`, `realCountryFk`) +INSERT INTO `vn`.`country`(`id`, `country`, `isUeeMember`, `code`, `currencyFk`) VALUES - (1, 'España', 0, 'ES', 1, 1), - (2, 'Italia', 1, 'IT', 1, 2), - (3, 'Alemania', 1, 'DE', 1, 3), - (4, 'Rumania', 1, 'RO', 1, 4), - (5, 'Holanda', 1, 'NL', 1, 5), - (30,'Francia', 1, 'FR', 1, 6); + (1, 'España', 0, 'ES', 1), + (2, 'Italia', 1, 'IT', 1), + (3, 'Alemania', 1, 'DE', 1), + (4, 'Rumania', 1, 'RO', 1), + (5, 'Holanda', 1, 'NL', 1), + (30,'Francia', 1, 'FR', 1); INSERT INTO `vn`.`warehouse`(`id`, `name`, `isComparative`, `isInventory`, `isManaged`) VALUES @@ -305,7 +305,7 @@ INSERT INTO `vn`.`bank`(`id`, `bank`, `account`, `cash`, `entityFk`, `isActive`) VALUES (8, 'Pay on receipt', '0000000000', 4, 0, 1); -INSERT INTO `salix`.`Agency`(`id`, `name`, `warehouseFk`, `isVolumetric`, `bankFk`, `warehouseAliasFk`) +INSERT INTO `vn`.`agency`(`id`, `name`, `warehouseFk`, `isVolumetric`, `bankFk`, `warehouseAliasFk`) VALUES (1, 'inhouse pickup', 1, 0, 8, 1), (2, 'Super-Man delivery', 1, 0, 8, 1), @@ -329,12 +329,6 @@ INSERT INTO `vn`.`payMethod`(`id`, `name`, `graceDays`, `outstandingDebt`, `iban (4, 'PayMethod with IBAN', 0, 001, 1), (5, 'PayMethod five', 10, 001, 0); -INSERT INTO `salix`.`Zone`(`id`, `name`, `printingOrder`) - VALUES - (1, 'zone one', 1), - (2, 'zone two', 2), - (3, 'zone three', 3); - INSERT INTO `vn`.`province`(`id`, `name`, `countryFk`, `warehouseFk`, `zoneFk`) VALUES (1, 'Province one', 1, NULL, 1), @@ -388,7 +382,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (9, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceBanner@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 4, 0, 1), (10, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'JessicaJones@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 4, 0, 1); -INSERT INTO `salix`.`Address`(`id`, `consignee`, `street`, `city`, `postcode`, `provinceFk`, `phone`, `mobile`, `isEnabled`, `isDefaultAddress`, `clientFk`, `defaultAgencyFk`, `longitude`, `latitude`, `isEqualizated`) +INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `phone`, `mobile`, `isEnabled`, `isDefaultAddress`, `clientFk`, `agencyFk`, `longitude`, `latitude`, `isEqualizated`) VALUES (101, 'Bruce Wayne', 'The Bat cave', 'Silla', 46460, 1, NULL, NULL, 1, 1, 1, 2, NULL, NULL, 0), (102, 'Petter Parker', 'NY roofs', 'Silla', 46460, 1, NULL, NULL, 1, 1, 2, 2, NULL, NULL, 0), @@ -399,9 +393,9 @@ INSERT INTO `salix`.`Address`(`id`, `consignee`, `street`, `city`, `postcode`, ` (107, 'Hank Pym', 'Your pocket', 'Silla', 46460, 1, NULL, NULL, 1, 1, 7, 2, NULL, NULL, 0), (108, 'Charles Xavier', 'Cerebro', 'Silla', 46460, 1, NULL, NULL, 1, 1, 8, 2, NULL, NULL, 0), (109, 'Bruce Banner', 'Somewhere in Thailand', 'Silla', 46460, 1, NULL, NULL, 1, 1, 9, 2, NULL, NULL, 0), - (1010,'Jessica Jones', 'Luke Cages Bar', 'Silla', 46460, 1, NULL, NULL, 1, 1, 10, 2, NULL, NULL, 0); + (110,'Jessica Jones', 'Luke Cages Bar', 'Silla', 46460, 1, NULL, NULL, 1, 1, 10, 2, NULL, NULL, 0); -INSERT INTO `salix`.`ClientCredit`(`id`, `clientFk`, `employeeFk`, `amount`, `created`) +INSERT INTO `vn`.`clientCredit`(`id`, `clientFk`, `workerFk`, `amount`, `created`) VALUES (1, 1, 1, 1200, CURDATE()), (2, 2, 2, 800, CURDATE()), @@ -409,13 +403,13 @@ INSERT INTO `salix`.`ClientCredit`(`id`, `clientFk`, `employeeFk`, `amount`, `cr (4, 4, 4, 90, CURDATE()), (5, 5, 5, 90, CURDATE()); -INSERT INTO `salix`.`ClientCreditLimit`(`id`, `maxAmount`, `roleFk`) +INSERT INTO `vn`.`clientCreditLimit`(`id`, `maxAmount`, `roleFk`) VALUES (1, 1000, 5), (2, 600, 5), (3, 0, 5); -INSERT INTO `salix`.`ClientObservation`(`id`, `clientFk`, `employeeFk`, `text`, `created`) +INSERT INTO `vn`.`clientObservation`(`id`, `clientFk`, `workerFk`, `text`, `created`) VALUES (1, 1, 1, 'Madness, as you know, is like gravity, all it takes is a little push', CURDATE()), (2, 2, 1, 'With great power, comes great responsibility', CURDATE()), @@ -448,7 +442,7 @@ INSERT INTO `vn`.`creditClassification`(`id`, `client`, `dateStart`, `dateEnd`) (4, 4, CURDATE(), CURDATE()), (5, 5, CURDATE(), CURDATE()); -INSERT INTO `salix`.`Route`(`id`, `date`) +INSERT INTO `vn`.`route`(`id`, `created`) VALUES (1, CURDATE()), (2, CURDATE()), @@ -458,7 +452,7 @@ INSERT INTO `salix`.`Route`(`id`, `date`) (6, CURDATE()), (7, CURDATE()); -INSERT INTO `salix`.`State`(`id`, `name`, `order`, `alertLevel`, `code`) +INSERT INTO `vn`.`state`(`id`, `name`, `order`, `alertLevel`, `code`) VALUES (1, 'To check', 2, 0, 'FIXING'), (2, 'Owes', 1, 0, 'FREE'), @@ -475,16 +469,16 @@ INSERT INTO `vn2008`.`empresa`(`id`, `abbreviation`, `registro`, `gerente_id`, ` INSERT INTO `vn`.`ticket`(`id`, `agencyModeFk`,`warehouseFk`,`routeFk`, `shipped`, `clientFk`,`nickname`, `addressFk`) VALUES - (1, 1, 1, NULL, CURDATE(), 1, 'Batman', 1), - (2, 1, 1, NULL, CURDATE(), 1, 'Spider-Man', 2), - (3, 2, 2, NULL, CURDATE(), 2, 'Super-Man', 3), - (4, 2, 2, NULL, CURDATE(), 2, 'Iron-Man', 4), - (5, 3, 3, NULL, CURDATE(), 3, 'Magneto', 5), - (6, 3, 3, NULL, CURDATE(), 3, 'Legion', 6), - (7, 4, 4, NULL, CURDATE(), 4, 'Ant-Man', 7), - (8, 4, 4, NULL, CURDATE(), 4, 'Professor X', 8), - (9, 5, 5, NULL, CURDATE(), 5, 'Hulk', 9), - (10, 6, 5, NULL, CURDATE(), 5, 'Jessica Jones', 10); + (1, 1, 1, NULL, CURDATE(), 1, 'Batman', 101), + (2, 1, 1, NULL, CURDATE(), 1, 'Spider-Man', 102), + (3, 2, 2, NULL, CURDATE(), 2, 'Super-Man', 103), + (4, 2, 2, NULL, CURDATE(), 2, 'Iron-Man', 104), + (5, 3, 3, NULL, CURDATE(), 3, 'Magneto', 105), + (6, 3, 3, NULL, CURDATE(), 3, 'Legion', 106), + (7, 4, 4, NULL, CURDATE(), 4, 'Ant-Man', 107), + (8, 4, 4, NULL, CURDATE(), 4, 'Professor X', 108), + (9, 5, 5, NULL, CURDATE(), 5, 'Hulk', 109), + (10, 6, 5, NULL, CURDATE(), 5, 'Jessica Jones', 110); INSERT INTO `vn`.`ticketTracking`(`id`, `ticketFk`, `stateFk`, `workerFk`, `created`) VALUES diff --git a/services/db/Dockerfile b/services/db/Dockerfile index 3b099daad..3b93aab02 100644 --- a/services/db/Dockerfile +++ b/services/db/Dockerfile @@ -3,9 +3,11 @@ FROM mysql:5.6.37 ENV MYSQL_ALLOW_EMPTY_PASSWORD yes ENV TZ GMT-1 -COPY *.sql /docker-entrypoint-initdb.d/ - -RUN chmod -R 755 /docker-entrypoint-initdb.d +WORKDIR /docker-entrypoint-initdb.d +COPY *.sql ./ +COPY 02-changes.sh . +COPY changes changes +RUN chmod -R 755 . CMD ["mysqld"] diff --git a/services/db/changes/1.0.0/01-agencyMode.sql b/services/db/changes/1.0.0/01-agencyMode.sql index 5190821c5..3e9fdbe72 100644 --- a/services/db/changes/1.0.0/01-agencyMode.sql +++ b/services/db/changes/1.0.0/01-agencyMode.sql @@ -8,17 +8,12 @@ VIEW `vn`.`agencyMode` AS `a`.`Agencia` AS `name`, `a`.`description` AS `description`, `a`.`Vista` AS `deliveryMethodFk`, - `a`.`Vista` AS `__deliveryMethod`, - `a`.`Vista` AS `__view`, `a`.`m3` AS `m3`, `a`.`cod71` AS `cod71`, `a`.`web` AS `web`, `a`.`agency_id` AS `agencyFk`, - `a`.`agency_id` AS `__agency`, `a`.`agency_service_id` AS `agencyServiceFk`, - `a`.`agency_service_id` AS `__agencyService`, `a`.`inflacion` AS `inflation`, - `a`.`inflacion` AS `__inflacion`, `a`.`is_volumetric` AS `isVolumetric`, `a`.`send_mail` AS `reportMail` FROM diff --git a/services/db/changes/1.0.0/02-agencyHour.sql b/services/db/changes/1.0.0/02-agencyHour.sql index 1c3a743f6..67fb95bcc 100644 --- a/services/db/changes/1.0.0/02-agencyHour.sql +++ b/services/db/changes/1.0.0/02-agencyHour.sql @@ -6,12 +6,9 @@ VIEW `vn`.`agencyHour` AS SELECT `h`.`agency_hour_id` AS `id`, `h`.`agency_id` AS `agencyFk`, - `h`.`agency_id` AS `__agency`, `h`.`week_day` AS `weekDay`, `h`.`warehouse_id` AS `warehouseFk`, - `h`.`warehouse_id` AS `__warehouse`, `h`.`province_id` AS `provinceFk`, - `h`.`province_id` AS `__province`, `h`.`subtract_day` AS `substractDay`, `h`.`max_hour` AS `maxHour` FROM diff --git a/services/db/01-titemLog.sql b/services/db/changes/1.0.0/04-itemLog.sql similarity index 100% rename from services/db/01-titemLog.sql rename to services/db/changes/1.0.0/04-itemLog.sql diff --git a/services/db/changes/1.0.0/04-userRole.sql b/services/db/changes/1.0.0/04-userRole.sql deleted file mode 100644 index b896589bc..000000000 --- a/services/db/changes/1.0.0/04-userRole.sql +++ /dev/null @@ -1,36 +0,0 @@ -USE `account`; -CREATE - OR REPLACE ALGORITHM = UNDEFINED - DEFINER = `root`@`%` - SQL SECURITY DEFINER -VIEW `account`.`__userRole` AS - SELECT - `r`.`inheritsFrom` AS `id` - FROM - (`account`.`roleRole` `r` - JOIN `account`.`user` `u` ON ((`u`.`role` = `r`.`role`))) - WHERE - (`u`.`id` = USERGETID()); - -DROP VIEW `account`.`userRole`; - -CREATE TABLE `account`.`userRole` ( - `userFk` INT(10) UNSIGNED NOT NULL, - `roleFk` INT(10) UNSIGNED NOT NULL, - PRIMARY KEY (`userFk`, `roleFk`)); - -ALTER TABLE `account`.`userRole` - ADD INDEX `user` (`userFk` ASC), - ADD INDEX `role` (`roleFk` ASC); - -ALTER TABLE `account`.`userRole` - ADD CONSTRAINT `user` - FOREIGN KEY (`userFk`) - REFERENCES `account`.`user` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE, - ADD CONSTRAINT `role` - FOREIGN KEY (`roleFk`) - REFERENCES `account`.`role` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE; diff --git a/services/db/changes/1.0.0/05-userHasRoleId.sql b/services/db/changes/1.0.0/05-userHasRoleId.sql deleted file mode 100644 index 9d96ff775..000000000 --- a/services/db/changes/1.0.0/05-userHasRoleId.sql +++ /dev/null @@ -1,31 +0,0 @@ -DROP function IF EXISTS `userHasRoleId`; -DELIMITER $$ -CREATE DEFINER=`root`@`%` FUNCTION `account`.`userHasRoleId`(vRoleId INT) RETURNS tinyint(1) - DETERMINISTIC -BEGIN -/** - * Comprueba si el usuario actual tiene asociado un rol. - * - * @param vRoleId Identificador del rol a comprobar - * @return %TRUE si tiene el rol, %FALSE en caso contrario - */ - DECLARE vHasRole BOOL DEFAULT FALSE; - - SELECT COUNT(*) > 0 INTO vHasRole - FROM user u - JOIN roleRole r ON r.role = u.role - WHERE u.id = userGetId() - AND r.inheritsFrom = vRoleId; - - IF NOT vHasRole - THEN - SELECT COUNT(*) > 0 INTO vHasRole - FROM userRole - WHERE userFk = userGetId() - AND roleFk = vRoleId; - END IF; - - RETURN vHasRole; -END$$ -DELIMITER ; - diff --git a/services/db/script.cmd b/services/db/export-structure.cmd similarity index 100% rename from services/db/script.cmd rename to services/db/export-structure.cmd