upload db changes
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-03-15 07:22:15 +01:00
parent aa5ff474ec
commit 6742d7aa43
2 changed files with 403 additions and 388 deletions

View File

@ -1,6 +1,6 @@
USE `util`; USE `util`;
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64) -- MariaDB dump 10.19 Distrib 10.5.12-MariaDB, for debian-linux-gnu (x86_64)
-- --
-- Host: db.verdnatura.es Database: util -- Host: db.verdnatura.es Database: util
-- ------------------------------------------------------ -- ------------------------------------------------------
@ -9,7 +9,7 @@ USE `util`;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */; /*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */; /*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
@ -34,9 +34,9 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2022-03-09 15:31:03 -- Dump completed on 2022-03-14 10:27:51
USE `account`; USE `account`;
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64) -- MariaDB dump 10.19 Distrib 10.5.12-MariaDB, for debian-linux-gnu (x86_64)
-- --
-- Host: db.verdnatura.es Database: account -- Host: db.verdnatura.es Database: account
-- ------------------------------------------------------ -- ------------------------------------------------------
@ -45,7 +45,7 @@ USE `account`;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */; /*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */; /*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
@ -120,9 +120,9 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2022-03-09 15:31:03 -- Dump completed on 2022-03-14 10:27:53
USE `salix`; USE `salix`;
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64) -- MariaDB dump 10.19 Distrib 10.5.12-MariaDB, for debian-linux-gnu (x86_64)
-- --
-- Host: db.verdnatura.es Database: salix -- Host: db.verdnatura.es Database: salix
-- ------------------------------------------------------ -- ------------------------------------------------------
@ -131,7 +131,7 @@ USE `salix`;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */; /*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */; /*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
@ -186,9 +186,9 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2022-03-09 15:31:04 -- Dump completed on 2022-03-14 10:27:55
USE `vn`; USE `vn`;
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64) -- MariaDB dump 10.19 Distrib 10.5.12-MariaDB, for debian-linux-gnu (x86_64)
-- --
-- Host: db.verdnatura.es Database: vn -- Host: db.verdnatura.es Database: vn
-- ------------------------------------------------------ -- ------------------------------------------------------
@ -197,7 +197,7 @@ USE `vn`;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */; /*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */; /*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
@ -452,9 +452,9 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2022-03-09 15:31:05 -- Dump completed on 2022-03-14 10:28:02
USE `cache`; USE `cache`;
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64) -- MariaDB dump 10.19 Distrib 10.5.12-MariaDB, for debian-linux-gnu (x86_64)
-- --
-- Host: db.verdnatura.es Database: cache -- Host: db.verdnatura.es Database: cache
-- ------------------------------------------------------ -- ------------------------------------------------------
@ -463,7 +463,7 @@ USE `cache`;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */; /*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */; /*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
@ -488,9 +488,9 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2022-03-09 15:31:05 -- Dump completed on 2022-03-14 10:28:02
USE `hedera`; USE `hedera`;
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64) -- MariaDB dump 10.19 Distrib 10.5.12-MariaDB, for debian-linux-gnu (x86_64)
-- --
-- Host: db.verdnatura.es Database: hedera -- Host: db.verdnatura.es Database: hedera
-- ------------------------------------------------------ -- ------------------------------------------------------
@ -499,7 +499,7 @@ USE `hedera`;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */; /*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */; /*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
@ -554,9 +554,9 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2022-03-09 15:31:05 -- Dump completed on 2022-03-14 10:28:04
USE `postgresql`; USE `postgresql`;
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64) -- MariaDB dump 10.19 Distrib 10.5.12-MariaDB, for debian-linux-gnu (x86_64)
-- --
-- Host: db.verdnatura.es Database: postgresql -- Host: db.verdnatura.es Database: postgresql
-- ------------------------------------------------------ -- ------------------------------------------------------
@ -565,7 +565,7 @@ USE `postgresql`;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */; /*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */; /*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
@ -640,9 +640,9 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2022-03-09 15:31:05 -- Dump completed on 2022-03-14 10:28:07
USE `sage`; USE `sage`;
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64) -- MariaDB dump 10.19 Distrib 10.5.12-MariaDB, for debian-linux-gnu (x86_64)
-- --
-- Host: db.verdnatura.es Database: sage -- Host: db.verdnatura.es Database: sage
-- ------------------------------------------------------ -- ------------------------------------------------------
@ -651,7 +651,7 @@ USE `sage`;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */; /*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */; /*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
@ -696,4 +696,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2022-03-09 15:31:05 -- Dump completed on 2022-03-14 10:28:10

View File

@ -1,4 +1,4 @@
-- MariaDB dump 10.19 Distrib 10.6.5-MariaDB, for debian-linux-gnu (x86_64) -- MariaDB dump 10.19 Distrib 10.5.12-MariaDB, for debian-linux-gnu (x86_64)
-- --
-- Host: db.verdnatura.es Database: account -- Host: db.verdnatura.es Database: account
-- ------------------------------------------------------ -- ------------------------------------------------------
@ -29955,7 +29955,7 @@ CREATE TABLE `delivery` (
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `delivery_FK` (`addressFk`), KEY `delivery_FK` (`addressFk`),
CONSTRAINT `delivery_FK` FOREIGN KEY (`addressFk`) REFERENCES `address` (`id`) ON DELETE CASCADE ON UPDATE CASCADE CONSTRAINT `delivery_FK` FOREIGN KEY (`addressFk`) REFERENCES `address` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Informa de los datos geográficos y temporales de las entregas de los repartidores'; ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Informa de los datos geográficos y temporales de las entregas de los repartidores';
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@ -31409,6 +31409,7 @@ CREATE TABLE `expedition` (
`packagingFk` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `packagingFk` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL, `itemPackingTypeFk` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL,
`hostFk` varchar(6) COLLATE utf8_unicode_ci NOT NULL, `hostFk` varchar(6) COLLATE utf8_unicode_ci NOT NULL,
`stateTypeFk` int(11) DEFAULT NULL COMMENT 'Ultimo estado de la expedicion',
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `index1` (`agencyModeFk`), KEY `index1` (`agencyModeFk`),
KEY `index2` (`isBox`), KEY `index2` (`isBox`),
@ -31417,6 +31418,8 @@ CREATE TABLE `expedition` (
KEY `expedition_fk3_idx` (`packagingFk`), KEY `expedition_fk3_idx` (`packagingFk`),
KEY `expedition_itemPackingTypeFk` (`itemPackingTypeFk`), KEY `expedition_itemPackingTypeFk` (`itemPackingTypeFk`),
KEY `workerFk` (`workerFk`), KEY `workerFk` (`workerFk`),
KEY `expedition_FK` (`stateTypeFk`),
CONSTRAINT `expedition_FK` FOREIGN KEY (`stateTypeFk`) REFERENCES `expeditionStateType` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `expedition_fk1` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON UPDATE CASCADE, CONSTRAINT `expedition_fk1` FOREIGN KEY (`agencyModeFk`) REFERENCES `agencyMode` (`id`) ON UPDATE CASCADE,
CONSTRAINT `expedition_fk2` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `expedition_fk2` FOREIGN KEY (`ticketFk`) REFERENCES `ticket` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `expedition_fk3` FOREIGN KEY (`packagingFk`) REFERENCES `packaging` (`id`) ON UPDATE CASCADE, CONSTRAINT `expedition_fk3` FOREIGN KEY (`packagingFk`) REFERENCES `packaging` (`id`) ON UPDATE CASCADE,
@ -31767,6 +31770,30 @@ BEGIN
SET NEW.userFk = account.myUser_getId(); SET NEW.userFk = account.myUser_getId();
END */;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8 */ ;
/*!50003 SET character_set_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`@`localhost`*/ /*!50003 TRIGGER expeditionState_AfterInsert
AFTER INSERT
ON expeditionState FOR EACH ROW
BEGIN
UPDATE vn.expedition e
SET e.stateTypeFk = NEW.typeFk
WHERE e.id = NEW.expeditionFk;
END */;; END */;;
DELIMITER ; DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET sql_mode = @saved_sql_mode */ ;
@ -42555,6 +42582,7 @@ CREATE TABLE `vehicle` (
`description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `description` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL,
`deliveryPointFk` int(11) DEFAULT '6' COMMENT 'Direccion para Buscaman', `deliveryPointFk` int(11) DEFAULT '6' COMMENT 'Direccion para Buscaman',
`isKmTruckRate` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Computar km como camión en el cálculo de salario de reparto', `isKmTruckRate` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Computar km como camión en el cálculo de salario de reparto',
`photo` blob,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `empresa_id` (`companyFk`), KEY `empresa_id` (`companyFk`),
KEY `provinceFk_idx` (`warehouseFk`), KEY `provinceFk_idx` (`warehouseFk`),
@ -42581,7 +42609,7 @@ CREATE TABLE `vehicleDms` (
KEY `vehicleDms_FK_1` (`dmsFk`), KEY `vehicleDms_FK_1` (`dmsFk`),
CONSTRAINT `vehicleDms_FK` FOREIGN KEY (`vehicleFk`) REFERENCES `vehicle` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `vehicleDms_FK` FOREIGN KEY (`vehicleFk`) REFERENCES `vehicle` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `vehicleDms_FK_1` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE CONSTRAINT `vehicleDms_FK_1` FOREIGN KEY (`dmsFk`) REFERENCES `dms` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Gestion documental de vehicle'; ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Gestion documental de vehicle';
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@ -42624,7 +42652,7 @@ CREATE TABLE `vehicleInvoiceIn` (
KEY `vehicleInvoiceIn_FK_1` (`invoiceInFk`), KEY `vehicleInvoiceIn_FK_1` (`invoiceInFk`),
CONSTRAINT `vehicleInvoiceIn_FK` FOREIGN KEY (`vehicleFk`) REFERENCES `vehicle` (`id`), CONSTRAINT `vehicleInvoiceIn_FK` FOREIGN KEY (`vehicleFk`) REFERENCES `vehicle` (`id`),
CONSTRAINT `vehicleInvoiceIn_FK_1` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`) CONSTRAINT `vehicleInvoiceIn_FK_1` FOREIGN KEY (`invoiceInFk`) REFERENCES `invoiceIn` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; ) ENGINE=InnoDBDEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */; /*!40101 SET character_set_client = @saved_cs_client */;
-- --
@ -69051,17 +69079,17 @@ DELIMITER ;
/*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `item_getVisibleAvailable` */; /*!50003 DROP PROCEDURE IF EXISTS `item_getVisibleAvailable__` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET collation_connection = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;; DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getVisibleAvailable`( CREATE DEFINER=`root`@`localhost` PROCEDURE `item_getVisibleAvailable__`(
vItem INT, vItem INT,
vDate DATE, vDate DATE,
vWarehouse TINYINT, vWarehouse TINYINT,
@ -78148,93 +78176,93 @@ DELIMITER ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET collation_connection = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;; DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `stockBuyed`(vDate DATE) CREATE DEFINER=`root`@`localhost` PROCEDURE `stockBuyed`(vDate DATE)
BEGIN BEGIN
DECLARE vVolume DECIMAL(10,2); DECLARE vVolume DECIMAL(10,2);
DECLARE vWarehouse INT DEFAULT 7; DECLARE vWarehouse INT DEFAULT 7;
DECLARE vRuben INT; DECLARE vRuben INT;
DECLARE vClaudi INT; DECLARE vClaudi INT;
DECLARE vJose INT; DECLARE vJose INT;
SELECT w.id INTO vRuben SELECT w.id INTO vRuben
FROM vn.worker w FROM vn.worker w
WHERE w.code = 'RET'; WHERE w.code = 'RET';
SELECT w.id INTO vClaudi
FROM vn.worker w
WHERE w.code = 'CSR';
SELECT w.id INTO vJose
FROM vn.worker w
WHERE w.code = 'ATJ';
CALL stockTraslation(vDate);
-- SELECT Volumen INTO vVolume FROM vn2008.Cubos WHERE Id_Cubo = 'cc' LIMIT 1; SELECT w.id INTO vClaudi
FROM vn.worker w
INSERT INTO stockBuyed(user, buyed, `date`) WHERE w.code = 'CSR';
SELECT tr.user_id, SUM(( amount / c.packing ) * vn.buy_getVolume(Id_Compra)) / vc.palletM3 / 1000000 buyed, vDate
FROM tmp_item i SELECT w.id INTO vJose
JOIN vn2008.Articles a ON a.Id_Article = i.item_id FROM vn.worker w
JOIN vn2008.Tipos t ON a.tipo_id = t.tipo_id WHERE w.code = 'ATJ';
CALL stockTraslation(vDate);
-- SELECT Volumen INTO vVolume FROM vn2008.Cubos WHERE Id_Cubo = 'cc' LIMIT 1;
INSERT INTO stockBuyed(user, buyed, `date`)
SELECT tr.user_id, SUM(( amount / c.packing ) * vn.buy_getVolume(Id_Compra)) / vc.palletM3 / 1000000 buyed, vDate
FROM tmp_item i
JOIN vn2008.Articles a ON a.Id_Article = i.item_id
JOIN vn2008.Tipos t ON a.tipo_id = t.tipo_id
JOIN vn2008.reinos r ON r.id = t.reino_id JOIN vn2008.reinos r ON r.id = t.reino_id
JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = t.Id_Trabajador JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = t.Id_Trabajador
JOIN vn2008.t_item_last_buy ilb ON ilb.item_id = Id_Article AND ilb.warehouse_id = vWarehouse JOIN tmp.buyUltimate bu ON bu.itemFk = Id_Article AND bu.warehouseFk = vWarehouse
JOIN vn2008.Compres c ON c.Id_compra = ilb.buy_id JOIN vn2008.Compres c ON c.Id_compra = bu.buyFk
JOIN vn.volumeConfig vc JOIN vn.volumeConfig vc
WHERE r.display <> 0 WHERE r.display <> 0
GROUP BY tr.Id_Trabajador GROUP BY tr.Id_Trabajador
ON DUPLICATE KEY UPDATE buyed = VALUES(buyed); ON DUPLICATE KEY UPDATE buyed = VALUES(buyed);
INSERT INTO stockBuyed(USER, buyed, `date`) INSERT INTO stockBuyed(USER, buyed, `date`)
SELECT vRuben, @amount := SUM(ic.cm3 * io.amount / vc.palletM3 / 1000000), vDate SELECT vRuben, @amount := SUM(ic.cm3 * io.amount / vc.palletM3 / 1000000), vDate
FROM vn2008.item_out io FROM vn2008.item_out io
JOIN vn.itemCost ic ON ic.itemFk = io.item_id AND ic.warehouseFk = vWarehouse JOIN vn.itemCost ic ON ic.itemFk = io.item_id AND ic.warehouseFk = vWarehouse
JOIN vn.ticket t ON t.id = io.ticketFk JOIN vn.ticket t ON t.id = io.ticketFk
JOIN vn.address a ON a.id = t.addressFk JOIN vn.address a ON a.id = t.addressFk
JOIN vn.province p ON p.id = a.provinceFk JOIN vn.province p ON p.id = a.provinceFk
JOIN vn.country c ON c.id = p.countryFk JOIN vn.country c ON c.id = p.countryFk
JOIN vn.volumeConfig vc JOIN vn.volumeConfig vc
WHERE dat = vDate WHERE dat = vDate
AND warehouse_id = vWarehouse AND warehouse_id = vWarehouse
AND c.country = 'Francia' AND c.country = 'Francia'
ON DUPLICATE KEY UPDATE buyed = buyed + @amount; ON DUPLICATE KEY UPDATE buyed = buyed + @amount;
INSERT INTO stockBuyed(USER, buyed, `date`) INSERT INTO stockBuyed(USER, buyed, `date`)
SELECT vJose, @amount := SUM(ic.cm3 * io.amount / vc.palletM3 / 1000000), vDate SELECT vJose, @amount := SUM(ic.cm3 * io.amount / vc.palletM3 / 1000000), vDate
FROM vn2008.item_out io FROM vn2008.item_out io
JOIN vn.itemCost ic ON ic.itemFk = io.item_id AND ic.warehouseFk = vWarehouse JOIN vn.itemCost ic ON ic.itemFk = io.item_id AND ic.warehouseFk = vWarehouse
JOIN vn.ticket t ON t.id = io.ticketFk JOIN vn.ticket t ON t.id = io.ticketFk
JOIN vn.address a ON a.id = t.addressFk JOIN vn.address a ON a.id = t.addressFk
JOIN vn.province p ON p.id = a.provinceFk JOIN vn.province p ON p.id = a.provinceFk
JOIN vn.country c ON c.id = p.countryFk JOIN vn.country c ON c.id = p.countryFk
JOIN vn.volumeConfig vc JOIN vn.volumeConfig vc
WHERE dat = vDate WHERE dat = vDate
AND warehouse_id = vWarehouse AND warehouse_id = vWarehouse
AND c.country = 'Holanda' AND c.country = 'Holanda'
ON DUPLICATE KEY UPDATE buyed = buyed + @amount; ON DUPLICATE KEY UPDATE buyed = buyed + @amount;
INSERT INTO stockBuyed(USER, buyed, `date`) INSERT INTO stockBuyed(USER, buyed, `date`)
SELECT vClaudi, @amount := SUM(ic.cm3 * io.amount / vc.palletM3 / 1000000), vDate SELECT vClaudi, @amount := SUM(ic.cm3 * io.amount / vc.palletM3 / 1000000), vDate
FROM vn2008.item_out io FROM vn2008.item_out io
JOIN vn.itemCost ic ON ic.itemFk = io.item_id AND ic.warehouseFk = vWarehouse JOIN vn.itemCost ic ON ic.itemFk = io.item_id AND ic.warehouseFk = vWarehouse
JOIN vn.ticket t ON t.id = io.ticketFk JOIN vn.ticket t ON t.id = io.ticketFk
JOIN vn.address a ON a.id = t.addressFk JOIN vn.address a ON a.id = t.addressFk
JOIN vn.province p ON p.id = a.provinceFk JOIN vn.province p ON p.id = a.provinceFk
JOIN vn.country c ON c.id = p.countryFk JOIN vn.country c ON c.id = p.countryFk
JOIN vn.volumeConfig vc JOIN vn.volumeConfig vc
WHERE dat BETWEEN vDate AND util.dayend(vDate) WHERE dat BETWEEN vDate AND util.dayend(vDate)
AND warehouse_id = vWarehouse AND warehouse_id = vWarehouse
AND c.country NOT IN ('Francia','Holanda') AND c.country NOT IN ('Francia','Holanda')
ON DUPLICATE KEY UPDATE buyed = buyed + @amount; ON DUPLICATE KEY UPDATE buyed = buyed + @amount;
DROP TEMPORARY TABLE DROP TEMPORARY TABLE
vn2008.t_item_last_buy, tmp.buyUltimate,
tmp_item; tmp_item;
END ;; END ;;
DELIMITER ; DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET sql_mode = @saved_sql_mode */ ;
@ -78247,32 +78275,32 @@ DELIMITER ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET collation_connection = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;; DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `stockBuyedByWorker`(vDate DATE, vWorker INT) CREATE DEFINER=`root`@`localhost` PROCEDURE `stockBuyedByWorker`(vDate DATE, vWorker INT)
BEGIN BEGIN
DECLARE vVolume DECIMAL(10,2); DECLARE vVolume DECIMAL(10,2);
DECLARE vWarehouse INT DEFAULT 7; DECLARE vWarehouse INT DEFAULT 7;
CALL stockTraslation(vDate); CALL stockTraslation(vDate);
SELECT Volumen INTO vVolume FROM vn2008.Cubos WHERE Id_Cubo = 'cc' LIMIT 1; SELECT Volumen INTO vVolume FROM vn2008.Cubos WHERE Id_Cubo = 'cc' LIMIT 1;
SELECT c.Id_Entrada, a.Id_Article, a.Article, i.amount Cantidad, (0.6 * ( i.amount / c.packing ) * vn.buy_getVolume(Id_Compra))/vVolume buyed SELECT c.Id_Entrada, a.Id_Article, a.Article, i.amount Cantidad, (0.6 * ( i.amount / c.packing ) * vn.buy_getVolume(Id_Compra))/vVolume buyed
FROM tmp_item i FROM tmp_item i
JOIN vn2008.Articles a ON a.Id_Article = i.item_id JOIN vn2008.Articles a ON a.Id_Article = i.item_id
JOIN vn2008.Tipos t ON a.tipo_id = t.tipo_id JOIN vn2008.Tipos t ON a.tipo_id = t.tipo_id
JOIN vn2008.reinos r ON r.id = t.reino_id JOIN vn2008.reinos r ON r.id = t.reino_id
JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = t.Id_Trabajador JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = t.Id_Trabajador
JOIN vn2008.t_item_last_buy ilb ON ilb.item_id = a.Id_Article AND ilb.warehouse_id = vWarehouse JOIN tmp.buyUltimate bu ON bu.itemFk = a.Id_Article AND bu.warehouseFk = vWarehouse
JOIN vn2008.Compres c ON c.Id_compra = ilb.buy_id JOIN vn2008.Compres c ON c.Id_compra = bu.buyFk
WHERE r.display <> 0 AND tr.user_id = vWorker; WHERE r.display <> 0 AND tr.user_id = vWorker;
DROP TEMPORARY TABLE DROP TEMPORARY TABLE
vn2008.t_item_last_buy, tmp.buyUltimate,
tmp_item; tmp_item;
END ;; END ;;
DELIMITER ; DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET sql_mode = @saved_sql_mode */ ;
@ -78326,39 +78354,38 @@ DELIMITER ;
DELIMITER ;; DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `stockTraslation`(vDate DATE) CREATE DEFINER=`root`@`localhost` PROCEDURE `stockTraslation`(vDate DATE)
BEGIN BEGIN
/** /**
* Calcula el stock del vWarehouse desde FechaInventario hasta v_date * Calcula el stock del vWarehouse desde FechaInventario hasta v_date
sin tener en cuenta las salidas del mismo dia vDate sin tener en cuenta las salidas del mismo dia vDate
para ver el transporte a reservar para ver el transporte a reservar
**/ **/
DECLARE vWarehouse INT DEFAULT 7;
DELETE FROM stockBuyed WHERE `date` = vDate; DECLARE vWarehouse INT DEFAULT 7;
DROP TEMPORARY TABLE IF EXISTS tmp_item; DELETE FROM stockBuyed WHERE `date` = vDate;
CREATE TEMPORARY TABLE tmp_item
(UNIQUE INDEX i USING HASH (item_id)) DROP TEMPORARY TABLE IF EXISTS tmp_item;
ENGINE = MEMORY CREATE TEMPORARY TABLE tmp_item
SELECT item_id, SUM(amount) amount (UNIQUE INDEX i USING HASH (item_id))
FROM vn2008.item_entry_in ENGINE = MEMORY
WHERE dat = vDate SELECT item_id, SUM(amount) amount
AND vDate >= CURDATE() FROM vn2008.item_entry_in
AND warehouse_id = vWarehouse WHERE dat = vDate
AND vDate >= CURDATE()
AND warehouse_id = vWarehouse
AND isVirtualStock is FALSE AND isVirtualStock is FALSE
GROUP BY item_id GROUP BY item_id
HAVING amount != 0; HAVING amount != 0;
CALL `cache`.stock_refresh (FALSE); CALL `cache`.stock_refresh (FALSE);
INSERT INTO tmp_item (item_id,amount) INSERT INTO tmp_item (item_id,amount)
SELECT item_id,s.amount SELECT item_id,s.amount
FROM `cache`.stock s FROM `cache`.stock s
WHERE warehouse_id = vWarehouse WHERE warehouse_id = vWarehouse
ON DUPLICATE KEY UPDATE ON DUPLICATE KEY UPDATE amount = tmp_item.amount + VALUES(amount);
amount = tmp_item.amount + VALUES(amount);
CALL buyUltimate(vWarehouse,vDate);
CALL vn2008.item_last_buy_(vWarehouse,vDate);
END ;; END ;;
DELIMITER ; DELIMITER ;
@ -83713,7 +83740,7 @@ DELIMITER ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;; DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_getFromFloramondo`(vDated DATE) CREATE DEFINER=`root`@`localhost` PROCEDURE `ticket_getFromFloramondo`(vDateFrom DATE, vDateTo DATE)
BEGIN BEGIN
/** /**
@ -83729,17 +83756,18 @@ BEGIN
agencyName VARCHAR(50), agencyName VARCHAR(50),
freight DECIMAL(10,2) DEFAULT 0, freight DECIMAL(10,2) DEFAULT 0,
expeditionCount INT, expeditionCount INT,
margin DECIMAL(10,3), margin DECIMAL(10,3) DEFAULT 0,
trolleys INT DEFAULT 0, trolleys INT DEFAULT 0,
shipped DATE,
pallets INT DEFAULT 0) pallets INT DEFAULT 0)
ENGINE = MEMORY; ENGINE = MEMORY;
INSERT INTO tmp.ticketFloramondo(ticketFk, clientName, agencyName) INSERT INTO tmp.ticketFloramondo(ticketFk, clientName, agencyName, shipped)
SELECT t.id ticketFk, t.nickname , am.name SELECT t.id ticketFk, t.nickname , am.name, t.shipped
FROM vn.ticket t FROM vn.ticket t
JOIN vn.agencyMode am ON am.id = t.agencyModeFk JOIN vn.agencyMode am ON am.id = t.agencyModeFk
JOIN vn.warehouse w ON w.id = t.warehouseFk AND w.code IN ('VNH','FLM') JOIN vn.warehouse w ON w.id = t.warehouseFk AND w.code IN ('VNH','FLM')
AND t.shipped BETWEEN vDated AND TIMESTAMPADD(HOUR, 23, vDated); AND t.shipped BETWEEN vDateFrom AND TIMESTAMPADD(HOUR, 23, vDateTo);
DROP TEMPORARY TABLE IF EXISTS tmp.ticket; DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
CREATE TEMPORARY TABLE tmp.ticket CREATE TEMPORARY TABLE tmp.ticket
@ -83800,7 +83828,7 @@ BEGIN
-- Pallets -- Pallets
UPDATE tmp.ticketFloramondo tf UPDATE tmp.ticketFloramondo tf
JOIN (SELECT sum(tp.quantity) pallets, t.ticketFk JOIN (SELECT SUM(tp.quantity) pallets, t.ticketFk
FROM vn.ticketPackaging tp FROM vn.ticketPackaging tp
JOIN tmp.ticket t ON t.ticketFk = tp.ticketFk JOIN tmp.ticket t ON t.ticketFk = tp.ticketFk
JOIN vn.packaging p ON p.id = tp.packagingFk JOIN vn.packaging p ON p.id = tp.packagingFk
@ -85526,7 +85554,7 @@ BEGIN
wtc.userFk, wtc.userFk,
wtc.timed, wtc.timed,
wtc.direction, wtc.direction,
TRUE isForShow TRUE isReal
FROM workerTimeControl wtc FROM workerTimeControl wtc
JOIN tmp.`user` w ON w.userFk = wtc.userFk JOIN tmp.`user` w ON w.userFk = wtc.userFk
LEFT JOIN tmp.timeControlError tce ON tce.id = wtc.id LEFT JOIN tmp.timeControlError tce ON tce.id = wtc.id
@ -85578,8 +85606,6 @@ BEGIN
WHERE hasBreak; WHERE hasBreak;
-- Cambio de dia -- Cambio de dia
INSERT INTO tmp.workerTimeControlAux (id, userFk, timed, direction) INSERT INTO tmp.workerTimeControlAux (id, userFk, timed, direction)
SELECT @vCont:= @vCont + 1 id, sub.userFk, util.dayEnd(sub.dated) timed, 'out' direction SELECT @vCont:= @vCont + 1 id, sub.userFk, util.dayEnd(sub.dated) timed, 'out' direction
FROM (SELECT MAX(wtc.timed) timed, wtc.userFk, date(wtc.timed) dated FROM (SELECT MAX(wtc.timed) timed, wtc.userFk, date(wtc.timed) dated
@ -85606,9 +85632,9 @@ BEGIN
JOIN tmp.workerTimeControl wtc ON wtc.timed = sub.timed AND wtc.userFk = sub.userFk JOIN tmp.workerTimeControl wtc ON wtc.timed = sub.timed AND wtc.userFk = sub.userFk
WHERE wtc.direction <> 'out'; WHERE wtc.direction <> 'out';
INSERT INTO tmp.workerTimeControl (id, userFk, timed, direction, isForShow) INSERT INTO tmp.workerTimeControl (id, userFk, timed, direction, isReal)
SELECT *, FALSE FROM tmp.workerTimeControlAux; SELECT id, userFk, timed, direction, FALSE FROM tmp.workerTimeControlAux;
SET vHourToSeconds = 3600; SET vHourToSeconds = 3600;
SET @vIsOdd := TRUE; SET @vIsOdd := TRUE;
SET @vDated := 0; SET @vDated := 0;
@ -85645,17 +85671,17 @@ BEGIN
IF(wb.userFk, vBreakTime, 0) + SUM(sub.timeWork) timeWorkSeconds, IF(wb.userFk, vBreakTime, 0) + SUM(sub.timeWork) timeWorkSeconds,
SEC_TO_TIME(IF(wb.userFk, vBreakTime, 0) + SUM(sub.timeWork)) timeWorkSexagesimal, SEC_TO_TIME(IF(wb.userFk, vBreakTime, 0) + SUM(sub.timeWork)) timeWorkSexagesimal,
(IF(wb.userFk, vBreakTime, 0) + SUM(sub.timeWork)) / vHourToSeconds timeWorkDecimal, (IF(wb.userFk, vBreakTime, 0) + SUM(sub.timeWork)) / vHourToSeconds timeWorkDecimal,
CAST(GROUP_CONCAT(DATE_FORMAT(sub.timed,"%H:%i") ORDER BY sub.timed ASC SEPARATOR ' - ') AS CHAR(256)) timed CAST(GROUP_CONCAT(DATE_FORMAT(sub.realTimed, "%H:%i") ORDER BY sub.timed ASC SEPARATOR ' - ') AS CHAR(256)) timed
FROM (SELECT (@vIsOdd := NOT @vIsOdd), FROM (SELECT (@vIsOdd := NOT @vIsOdd),
IF(direction='in', @vIsOdd := TRUE, 0), IF(direction='in', @vIsOdd := TRUE, 0),
IF(@vIsOdd, @vLastTimed := UNIX_TIMESTAMP(timed), 0), IF(@vIsOdd, @vLastTimed := UNIX_TIMESTAMP(timed), 0),
IF(@vIsOdd, 0, UNIX_TIMESTAMP(timed) - @vLastTimed) timeWork, IF(@vIsOdd, 0, UNIX_TIMESTAMP(timed) - @vLastTimed) timeWork,
timed, timed,
userFk, userFk,
DATE(timed) dated DATE(timed) dated,
IF(isReal, timed, NULL) realTimed
FROM tmp.workerTimeControl FROM tmp.workerTimeControl
WHERE timed BETWEEN vDatedFromYesterday AND vDatedTo WHERE timed BETWEEN vDatedFromYesterday AND vDatedTo
AND isForShow
ORDER BY userFk, timed, id ORDER BY userFk, timed, id
)sub )sub
LEFT JOIN tmp.workerBreakDays wb ON wb.userFk = sub.userFk AND wb.dated = sub.dated LEFT JOIN tmp.workerBreakDays wb ON wb.userFk = sub.userFk AND wb.dated = sub.dated
@ -85937,14 +85963,16 @@ BEGIN
JOIN (SELECT journeyCounter, JOIN (SELECT journeyCounter,
UNIX_TIMESTAMP(MAX(timed)) - UNIX_TIMESTAMP(MIN(timed)) timeWork, UNIX_TIMESTAMP(MAX(timed)) - UNIX_TIMESTAMP(MIN(timed)) timeWork,
SUM(direction = 'in') totalIn, SUM(direction = 'in') totalIn,
SUM(direction = 'out') totalOut SUM(direction = 'out') totalOut,
timed
FROM tmp.timeControl FROM tmp.timeControl
GROUP BY journeyCounter GROUP BY journeyCounter
HAVING COUNT(*) MOD 2 = 1 HAVING COUNT(*) MOD 2 = 1
OR totalIn <> 1 OR totalIn <> 1
OR totalOut <> 1 OR totalOut <> 1
OR timeWork >= vDayMaxTime OR timeWork >= vDayMaxTime
)sub ON sub.journeyCounter = tca.journeyCounter; )sub ON sub.journeyCounter = tca.journeyCounter
WHERE sub.timed BETWEEN vDatedFrom AND vDatedTo;
DROP TEMPORARY TABLE IF EXISTS tmp.timeControl; DROP TEMPORARY TABLE IF EXISTS tmp.timeControl;
DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux; DROP TEMPORARY TABLE IF EXISTS tmp.timeControlAux;
@ -87897,9 +87925,9 @@ DELIMITER ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ; /*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ; /*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET collation_connection = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;; DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `workerJourney_replace`(vDatedFrom DATE, vDatedTo DATE, vWorkerFk INT) CREATE DEFINER=`root`@`localhost` PROCEDURE `workerJourney_replace`(vDatedFrom DATE, vDatedTo DATE, vWorkerFk INT)
BEGIN BEGIN
@ -87921,6 +87949,205 @@ BEGIN
SET vDatedTimeTo = util.dayEnd(vDatedTo); SET vDatedTimeTo = util.dayEnd(vDatedTo);
SELECT minHoursToBreak, breakHours, maxTimePerDay
INTO vMinHoursToBreak, vBreakHours, vMaxTimePerDay
FROM workerTimeControlConfig;
DELETE FROM workerJourney
WHERE dated BETWEEN vDatedFrom AND vDatedTo
AND NOT isPaid
AND NOT isUpdated
AND (vWorkerFk IS NULL OR userFK = vWorkerFk);
-- Se inserta todos los días del periodo por worker y business en el rango de fechas.
INSERT IGNORE INTO workerJourney(userFk, dated, businessFk)
SELECT w.workerFk, t.dated, w.businessFk
FROM workerLabour w
JOIN time t ON t.dated BETWEEN w.started AND IFNULL(w.ended,CURDATE())
WHERE t.dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR w.workerFk = vWorkerFk)
ORDER BY w.workerFk, t.dated, w.businessFk;
DROP TEMPORARY TABLE IF EXISTS tmp.`user`;
IF vWorkerFk THEN
CALL timeControl_calculateByUser(vWorkerFk, vDatedFrom , vDatedTimeTo);
CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user`
SELECT vWorkerFk userFk;
ELSE
CALL timeControl_calculateAll(vDatedFrom, vDatedTimeTo);
CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user`
SELECT id userFk
FROM vn.worker w;
END IF;
UPDATE workerJourney wj
JOIN tmp.timeControlCalculate t ON wj.dated = t.dated AND wj.userFk = t.userFk
SET wj.total = CAST(IF(t.timeWorkDecimal >= vMinHoursToBreak, t.timeWorkDecimal - vBreakHours, t.timeWorkDecimal) AS DECIMAL (10,2)),
wj.lunch = IF(t.timeWorkDecimal >= vMinHoursToBreak , vBreakHours , 0)
WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo
AND NOT wj.isPaid
AND NOT wj.isUpdated
AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk);
-- NOCTURNIDAD
CALL vn.timeControl_getError(vDatedFrom, vDatedTimeTo);
SET @vIsOdd := TRUE;
SET @vDated := NULL;
UPDATE workerJourney wj
JOIN (SELECT sub.dated, userFk, SUM(NigthlyHours) NigthlyHours
FROM(SELECT (@vIsOdd := NOT @vIsOdd) isOdd,
IF(direction='in', @vIsOdd := TRUE, @vIsOdd := @vIsOdd),
IF(@vIsOdd, @vLastTimed:=UNIX_TIMESTAMP(timed),@vLastTimed),
IF(direction='in', @vDated := DATE(wtc.timed), @vDated ) dated,
wtc.userFk,
IF(UNIX_TIMESTAMP(timed)- @vLastTimed < vMaxTimePerDay,
vn.workerNigthlyHours_calculate(FROM_UNIXTIME(@vLastTimed), wtc.timed),
0) NigthlyHours
FROM (SELECT DISTINCT(wtc.id), wtc.userFk, wtc.timed, wtc.direction
FROM workerTimeControl wtc
LEFT JOIN tmp.timeControlError tce ON tce.id = wtc.id
WHERE wtc.timed BETWEEN vDatedFrom AND util.dayEnd(DATE_ADD(vDatedTo, INTERVAL 1 DAY))
AND tce.id IS NULL
ORDER BY userFk, timed ASC
) wtc
)sub
WHERE sub.dated BETWEEN vDatedFrom AND vDatedTo
GROUP BY userFk, sub.dated
)night ON night.userFk = wj.userFk AND night.dated = wj.dated
SET wj.nocturn = night.NigthlyHours
WHERE NOT wj.isPaid
AND NOT isUpdated
AND night.NigthlyHours <> 0;
-- Horas téoricas y precio de la hora ordinaria
UPDATE workerJourney wj
JOIN postgresql.business_labour_payroll blp ON blp.business_id = wj.businessFk
JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk
JOIN postgresql.calendar_labour_type cl ON cl.calendar_labour_type_id = bl.calendar_labour_type_id
SET wj.priceOrdinaryHour = (vMonthsByYear * blp.importepactado) / (vWeeksByYear * cl.hours_week),
wj.contractJourney = cl.hours_week / vDaysByWeek
WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk)
AND NOT wj.isPaid
AND NOT isUpdated;
-- Precio Extras, Vacaciones y Nocturnas
UPDATE workerJourney wj
JOIN(SELECT MAX(w.dated), t.dated, w.holidayInc, w.nightInc, w.extraInc
FROM time t
JOIN workerHourPrice w ON w.dated <= t.dated
WHERE t.dated BETWEEN vDatedFrom AND vDatedTo
GROUP BY t.dated
) sub ON sub.dated = wj.dated
SET wj.priceHolidayHour = wj.priceOrdinaryHour * sub.holidayInc,
wj.priceNocturnHour = wj.priceOrdinaryHour * sub.nightInc,
wj.priceExtraHour = wj.priceOrdinaryHour * sub.extraInc
WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk)
AND NOT wj.isPaid
AND NOT wj.isUpdated;
-- Elimina el precio de las horas extras para los contratos parciales.
UPDATE workerJourney wj
JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk
JOIN postgresql.calendar_labour_type cl ON cl.calendar_labour_type_id = bl.calendar_labour_type_id
SET wj.priceExtraHour = 0
WHERE cl.isPartial
AND wj.dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk)
AND NOT wj.isPaid
AND NOT wj.isUpdated;
-- Ausencias
UPDATE workerJourney wj
JOIN businessCalendar bc ON bc.businessFk = wj.businessFk AND bc.dated = wj.dated
JOIN absenceType ab ON ab.id = bc.absenceTypeFk
JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk
SET wj.permission = ab.permissionRate * wj.contractJourney,
wj.contractJourney = IF(ab.permissionRate = 1, 0, ab.permissionRate) * wj.contractJourney
WHERE ab.permissionRate > 0
AND wj.dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk)
AND NOT wj.isPaid
AND NOT wj.isUpdated;
-- Sábados / Domingos
UPDATE workerJourney
SET holiday = IF(DAYNAME(dated)='sábado', 0, total),
contractJourney = 0
WHERE DAYNAME(dated) IN ('sábado', 'domingo')
AND dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR userFk = vWorkerFk)
AND NOT isPaid
AND NOT isUpdated;
-- Festivos por centro de trabajo
UPDATE workerJourney wj
JOIN calendarHolidays ch ON ch.dated = wj.dated
JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk
AND bl.workcenter_id = ch.workcenterFk
SET wj.holiday = wj.total,
wj.permission = wj.contractJourney,
wj.contractJourney = 0
WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk)
AND NOT wj.isPaid
AND NOT wj.isUpdated;
-- Horas extras
UPDATE workerJourney
SET extra = lunch + total - contractJourney
WHERE dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR userFk = vWorkerFk)
AND NOT isPaid
AND NOT isUpdated;
DROP TEMPORARY TABLE tmp.timeControlCalculate;
DROP TEMPORARY TABLE tmp.`user`;
DROP TEMPORARY TABLE tmp.timeControlError;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `workerJourney_replace__` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `workerJourney_replace__`(vDatedFrom DATE, vDatedTo DATE, vWorkerFk INT)
BEGIN
/**
* Actualiza la tabla workerJourney para que actue como caché permanente revisable de las jornadas laborales.
* @param vDatedFrom workerTimeControl
* @param vDatedTo workerTimeControl
* @param vWorkerFk, en caso de pasar 0 ó NULL se aplica a todos
*/
DECLARE vDatedTimeTo DATETIME;
DECLARE vMaxTimePerDay INT;
DECLARE vMinHoursToBreak DECIMAL(10,2);
DECLARE vBreakHours DECIMAL(10,2);
DECLARE vMonthByYear INT;
DECLARE vWeeksByYear INT DEFAULT 52;
DECLARE vMonthsByYear INT DEFAULT 12;
DECLARE vDaysByWeek INT DEFAULT 5;
SET vDatedTimeTo = util.dayEnd(vDatedTo);
SELECT minHoursToBreak, breakHours, maxTimePerDay SELECT minHoursToBreak, breakHours, maxTimePerDay
INTO vMinHoursToBreak, vBreakHours, vMaxTimePerDay INTO vMinHoursToBreak, vBreakHours, vMaxTimePerDay
FROM workerTimeControlConfig; FROM workerTimeControlConfig;
@ -88079,218 +88306,6 @@ DELIMITER ;
/*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `workerJourney_replace__` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
/*!50003 SET character_set_client = utf8mb4 */ ;
/*!50003 SET character_set_results = utf8mb4 */ ;
/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
/*!50003 SET sql_mode = 'IGNORE_SPACE,NO_ENGINE_SUBSTITUTION' */ ;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `workerJourney_replace__`(vDatedFrom DATE, vDatedTo DATE, vWorkerFk INT)
BEGIN
/**
* Actualiza la tabla workerJourney para que actue como caché permanente revisable de las jornadas laborales.
* @param vDatedFrom workerTimeControl
* @param vDatedTo workerTimeControl
* @param vWorkerFk, en caso de pasar 0 ó NULL se aplica a todos
*/
DECLARE vDatedTimeTo DATETIME;
DECLARE vMinHoursToBreak DECIMAL(10,2);
DECLARE vBreakHours DECIMAL(10,2);
DECLARE vMonthByYear INT;
DECLARE vWeeksByYear INT DEFAULT 52;
DECLARE vMonthsByYear INT DEFAULT 12;
DECLARE vDaysByWeek INT DEFAULT 5;
SET vDatedTimeTo = util.dayEnd(vDatedTo);
SELECT minHoursToBreak, breakHours
INTO vMinHoursToBreak, vBreakHours
FROM workerTimeControlConfig;
DELETE FROM workerJourney
WHERE dated BETWEEN vDatedFrom AND vDatedTo
AND NOT isPaid
AND NOT isUpdated
AND (vWorkerFk IS NULL OR userFK = vWorkerFk);
-- Se inserta todos los días del periodo por worker y business en el rango de fechas.
INSERT IGNORE INTO workerJourney(userFk, dated, businessFk)
SELECT w.workerFk, t.dated, w.businessFk
FROM workerLabour w
JOIN time t ON t.dated BETWEEN w.started AND IFNULL(w.ended,CURDATE())
WHERE t.dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR w.workerFk = vWorkerFk)
ORDER BY w.workerFk, t.dated, w.businessFk;
IF vWorkerFk THEN
CALL timeControl_calculateByUser(vWorkerFk, vDatedFrom , vDatedTimeTo);
ELSE
CALL timeControl_calculateAll(vDatedFrom, vDatedTimeTo);
END IF;
UPDATE workerJourney wj
JOIN tmp.timeControlCalculate t ON wj.dated = t.dated AND wj.userFk = t.userFk
SET wj.total = CAST(IF(t.timeWorkDecimal >= vMinHoursToBreak, t.timeWorkDecimal - vBreakHours, t.timeWorkDecimal) AS DECIMAL (10,2)),
wj.lunch = IF(t.timeWorkDecimal >= vMinHoursToBreak , vBreakHours , 0)
WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo
AND NOT wj.isPaid
AND NOT wj.isUpdated
AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk);
-- NOCTURNIDAD
DROP TEMPORARY TABLE IF EXISTS tmp.workerTimeControl;
CREATE TEMPORARY TABLE tmp.workerTimeControl
SELECT sub.userFk, sub.timed, sub.order, 0 Non, FALSE manual
FROM (SELECT w.userFk,
IF(TIME(w.timed) IN ('06:00:00','22:00:00'), TIMESTAMPADD(SECOND, -1, w.timed), w.timed) timed, -- Regalamos un segundo para evitar que hayan fichadas en las horas claves de inicio y fin de la nocturnidad.
w.`order`
FROM workerTimeControl w
WHERE w.timed BETWEEN vDatedFrom AND vDatedTo
AND w.userFk = IFNULL(vWorkerFk, w.userFk)
UNION ALL
SELECT w.userFk,
TIMESTAMPADD(HOUR, 6, DATE(w.timed)),
w.`order`
FROM workerTimeControl w
WHERE w.timed BETWEEN vDatedFrom AND vDatedTo
AND w.userFk = IFNULL(vWorkerFk, w.userFk)
GROUP BY w.userFk, DATE(w.timed)
UNION ALL
SELECT w.userFk,
TIMESTAMPADD(HOUR, 22, DATE(w.timed)),
w.order
FROM workerTimeControl w
WHERE w.timed BETWEEN vDatedFrom AND vDatedTo
AND w.userFk = IFNULL(vWorkerFk, w.userFk)
GROUP BY w.userFk, DATE(w.timed)
) sub
ORDER BY sub.userFk, sub.timed;
-- Establece el orden en que se han de leer las fichadas
CALL workerTimeControlSetOrder();
-- Marca los impares para facilitar la consulta siguiente
UPDATE tmp.workerTimeControl
SET Non = 1
WHERE `order` mod 2;
-- Actualizamos la nocturnidad
UPDATE workerJourney wj
JOIN(SELECT userFk, Dia, sum(Nocturnidad) Nocturnidad FROM
(SELECT userFk,
date(timed) Dia,
((IF( TIME(timed) < '06:00:00' OR (TIME(timed) = '06:00:00' AND Non = FALSE ) , IF(Non,-1,1),0)
+
IF(TIME(timed) > '22:00:00' OR (TIME(timed) = '22:00:00' AND Non = TRUE), If(Non,-1,1),0))
* (HOUR(`timed`) + MINUTE(`timed`) / 60)
) Nocturnidad
FROM tmp.workerTimeControl
) sub
GROUP BY userFk, Dia
) night ON night.userFk = wj.userFk AND night.Dia = wj.dated
SET wj.nocturn = night.Nocturnidad
WHERE NOT wj.isPaid
AND NOT isUpdated
AND night.Nocturnidad<>0;
-- Horas téoricas y precio de la hora ordinaria
UPDATE workerJourney wj
JOIN postgresql.business_labour_payroll blp ON blp.business_id = wj.businessFk
JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk
JOIN postgresql.calendar_labour_type cl ON cl.calendar_labour_type_id = bl.calendar_labour_type_id
SET wj.priceOrdinaryHour = (vMonthsByYear * blp.importepactado) / (vWeeksByYear * cl.hours_week),
wj.contractJourney = cl.hours_week / vDaysByWeek
WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk)
AND NOT wj.isPaid
AND NOT isUpdated;
-- Precio Extras, Vacaciones y Nocturnas
UPDATE workerJourney wj
JOIN(SELECT MAX(w.dated), t.dated, w.holidayInc, w.nightInc, w.extraInc
FROM time t
JOIN workerHourPrice w ON w.dated <= t.dated
WHERE t.dated BETWEEN vDatedFrom AND vDatedTo
GROUP BY t.dated
) sub ON sub.dated = wj.dated
SET wj.priceHolidayHour = wj.priceOrdinaryHour * sub.holidayInc,
wj.priceNocturnHour = wj.priceOrdinaryHour * sub.nightInc,
wj.priceExtraHour = wj.priceOrdinaryHour * sub.extraInc
WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk)
AND NOT wj.isPaid
AND NOT wj.isUpdated;
-- Elimina el precio de las horas extras para los contratos parciales.
UPDATE workerJourney wj
JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk
JOIN postgresql.calendar_labour_type cl ON cl.calendar_labour_type_id = bl.calendar_labour_type_id
SET wj.priceExtraHour = 0
WHERE cl.isPartial
AND wj.dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk)
AND NOT wj.isPaid
AND NOT wj.isUpdated;
-- Bajas, vacaciones y festivos personales
UPDATE workerJourney wj
JOIN businessCalendar bc ON bc.businessFk = wj.businessFk AND bc.dated = wj.dated
JOIN absenceType ab ON ab.id = bc.absenceTypeFk
JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk
SET wj.permission = ab.permissionRate * wj.contractJourney,
wj.contractJourney = IF(ab.permissionRate = 1, 0, ab.permissionRate) * wj.contractJourney,
wj.holiday = wj.total - IF(ab.permissionRate = 1, 0, ab.permissionRate) * wj.contractJourney
WHERE ab.permissionRate > 0
AND wj.dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk)
AND NOT wj.isPaid
AND NOT wj.isUpdated;
-- Festivos por centro de trabajo
UPDATE workerJourney wj
JOIN calendarHolidays ch ON ch.dated = wj.dated
JOIN postgresql.business_labour bl ON bl.business_id = wj.businessFk
AND bl.workcenter_id = ch.workcenterFk
SET wj.holiday = wj.total,
wj.permission = wj.contractJourney,
wj.contractJourney = 0
WHERE wj.dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR wj.userFk = vWorkerFk)
AND NOT wj.isPaid
AND NOT wj.isUpdated;
-- Sábados / Domingos
UPDATE workerJourney
SET holiday = total,
contractJourney = 0
WHERE DAYNAME(dated) IN ('sábado', 'domingo')
AND dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR userFk = vWorkerFk)
AND NOT isPaid
AND NOT isUpdated;
-- Horas extras
UPDATE workerJourney
SET extra = lunch + total - contractJourney
WHERE dated BETWEEN vDatedFrom AND vDatedTo
AND (vWorkerFk IS NULL OR userFk = vWorkerFk)
AND NOT isPaid
AND NOT isUpdated;
DROP TEMPORARY TABLE tmp.timeControlCalculate;
DROP TEMPORARY TABLE tmp.workerTimeControl;
END ;;
DELIMITER ;
/*!50003 SET sql_mode = @saved_sql_mode */ ;
/*!50003 SET character_set_client = @saved_cs_client */ ;
/*!50003 SET character_set_results = @saved_cs_results */ ;
/*!50003 SET collation_connection = @saved_col_connection */ ;
/*!50003 DROP PROCEDURE IF EXISTS `workerMistakeType_get` */; /*!50003 DROP PROCEDURE IF EXISTS `workerMistakeType_get` */;
/*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_client = @@character_set_client */ ;
/*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ;
@ -98017,4 +98032,4 @@ USE `vncontrol`;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2022-03-09 15:30:23 -- Dump completed on 2022-03-14 10:24:57