diff --git a/db/export-data.sh b/db/export-data.sh index aa3000d9d..0ce7a530a 100755 --- a/db/export-data.sh +++ b/db/export-data.sh @@ -1,17 +1,19 @@ #!/bin/bash echo "USE \`account\`;" > install/dump/dumpedFixtures.sql -mysqldump --defaults-file=connect.ini --no-create-info account role roleRole roleInherit >> install/dump/dumpedFixtures.sql +mysqldump --defaults-file=config.production.ini --no-create-info account role roleRole roleInherit >> install/dump/dumpedFixtures.sql echo "USE \`salix\`;" >> install/dump/dumpedFixtures.sql -mysqldump --defaults-file=connect.ini --no-create-info salix ACL fieldAcl>> install/dump/dumpedFixtures.sql +mysqldump --defaults-file=config.production.ini --no-create-info salix ACL fieldAcl>> install/dump/dumpedFixtures.sql echo "USE \`vn\`;" >> install/dump/dumpedFixtures.sql -mysqldump --defaults-file=connect.ini --no-create-info vn cplusInvoiceType477 cplusSubjectOp cplusTaxBreak bookingPlanner pgc tag alertLevel >> install/dump/dumpedFixtures.sql +mysqldump --defaults-file=config.production.ini --no-create-info vn cplusInvoiceType477 cplusSubjectOp cplusTaxBreak bookingPlanner pgc tag alertLevel >> install/dump/dumpedFixtures.sql echo "USE \`vn2008\`;" >> install/dump/dumpedFixtures.sql -mysqldump --defaults-file=connect.ini --no-create-info vn2008 accion_dits Gastos Tintas tarifa_componentes tarifa_componentes_series state bionic_updating_options Grupos Monedas container iva_group_codigo escritos cl_est cl_con cl_res cl_dev cl_mot department businessReasonEnd>> install/dump/dumpedFixtures.sql +mysqldump --defaults-file=config.production.ini --no-create-info vn2008 accion_dits Gastos Tintas tarifa_componentes tarifa_componentes_series state bionic_updating_options \ + Grupos Monedas container iva_group_codigo escritos cl_est cl_con cl_res cl_dev cl_mot department businessReasonEnd>> install/dump/dumpedFixtures.sql echo "USE \`bi\`;" >> install/dump/dumpedFixtures.sql -mysqldump --defaults-file=connect.ini --no-create-info bi tarifa_componentes tarifa_componentes_series >> install/dump/dumpedFixtures.sql +mysqldump --defaults-file=config.production.ini --no-create-info bi tarifa_componentes tarifa_componentes_series >> install/dump/dumpedFixtures.sql echo "USE \`cache\`;" >> install/dump/dumpedFixtures.sql -mysqldump --defaults-file=connect.ini --no-create-info cache cache >> install/dump/dumpedFixtures.sql +mysqldump --defaults-file=config.production.ini --no-create-info cache cache >> install/dump/dumpedFixtures.sql echo "USE \`hedera\`;" >> install/dump/dumpedFixtures.sql -mysqldump --defaults-file=connect.ini --no-create-info hedera tpvError tpvResponse tpvConfig >> install/dump/dumpedFixtures.sql +mysqldump --defaults-file=config.production.ini --no-create-info hedera tpvError tpvResponse tpvConfig >> install/dump/dumpedFixtures.sql echo "USE \`postgresql\`;" >> install/dump/dumpedFixtures.sql -mysqldump --defaults-file=connect.ini --no-create-info postgresql profile_type media_type professional_category labour_agreement calendar_labour_type workcenter>> install/dump/dumpedFixtures.sql \ No newline at end of file +mysqldump --defaults-file=config.production.ini --no-create-info postgresql profile_type media_type professional_category labour_agreement \ + calendar_labour_type workcenter>> install/dump/dumpedFixtures.sql \ No newline at end of file diff --git a/db/export-structure.sh b/db/export-structure.sh index 89940683b..f3ddcbdd1 100755 --- a/db/export-structure.sh +++ b/db/export-structure.sh @@ -1,3 +1,4 @@ #!/bin/bash #IMPORTANT Any changes in this file are to applyed to mirror file export-structure.cmd -mysqldump --defaults-file=connect.ini --default-character-set=utf8 --no-data --comments --triggers --routines --events --databases account util vn2008 vn edi bs bi pbx cache salix vncontrol hedera stock postgresql> install/dump/structure.sql +mysqldump --defaults-file=config.production.ini --default-character-set=utf8 --no-data --comments --triggers --routines --events --databases \ + account util vn2008 vn edi bs bi pbx cache salix vncontrol hedera stock postgresql> install/dump/structure.sql diff --git a/db/install/changes/0-ACL.sql b/db/install/changes/0-ACL.sql index a2f3991f1..3fd811372 100644 --- a/db/install/changes/0-ACL.sql +++ b/db/install/changes/0-ACL.sql @@ -1,4 +1,4 @@ -INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (149, 'Sip', '*', 'WRITE', 'ALLOW', 'ROLE', 'hr'); -INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (150, 'Sip', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); -INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (151, 'Department','*','READ','ALLOW','ROLE','employee'); -INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (152, 'Department','*','WRITE','ALLOW','ROLE','hr'); +-- INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (149, 'Sip', '*', 'WRITE', 'ALLOW', 'ROLE', 'hr'); +-- INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (150, 'Sip', '*', 'READ', 'ALLOW', 'ROLE', 'employee'); +-- INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (151, 'Department','*','READ','ALLOW','ROLE','employee'); +-- INSERT INTO `salix`.`ACL` (`id`,`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES (152, 'Department','*','WRITE','ALLOW','ROLE','hr'); diff --git a/db/install/changes/15-zoneGeo.sql b/db/install/changes/15-zoneGeo.sql deleted file mode 100644 index 1037fe089..000000000 --- a/db/install/changes/15-zoneGeo.sql +++ /dev/null @@ -1,4 +0,0 @@ -USE `vn`; - -CREATE UNIQUE INDEX zoneGeo_lft_IDX USING BTREE ON vn.zoneGeo (lft); -CREATE UNIQUE INDEX zoneGeo_rgt_IDX USING BTREE ON vn.zoneGeo (rgt); \ No newline at end of file diff --git a/db/install/changes/16-itemLog.sql b/db/install/changes/16-itemLog.sql index f6d028dab..0490ba9f4 100644 --- a/db/install/changes/16-itemLog.sql +++ b/db/install/changes/16-itemLog.sql @@ -1,16 +1,16 @@ -ALTER TABLE `vn`.`itemLog` -CHANGE COLUMN `id` `id` INT(11) NOT NULL AUTO_INCREMENT , -ADD PRIMARY KEY (`id`); +-- ALTER TABLE `vn`.`itemLog` +-- CHANGE COLUMN `id` `id` INT(11) NOT NULL AUTO_INCREMENT , +-- ADD PRIMARY KEY (`id`); -ALTER TABLE `vn`.`itemLog` -DROP FOREIGN KEY `itemLogUserFk`; -ALTER TABLE `vn`.`itemLog` -CHANGE COLUMN `id` `id` INT(11) NOT NULL AUTO_INCREMENT , -CHANGE COLUMN `userFk` `userFk` INT(10) UNSIGNED NULL DEFAULT NULL ; -ALTER TABLE `vn`.`itemLog` -ADD CONSTRAINT `itemLogUserFk` - FOREIGN KEY (`userFk`) - REFERENCES `account`.`user` (`id`) - ON DELETE CASCADE - ON UPDATE CASCADE; +-- ALTER TABLE `vn`.`itemLog` +-- DROP FOREIGN KEY `itemLogUserFk`; +-- ALTER TABLE `vn`.`itemLog` +-- CHANGE COLUMN `id` `id` INT(11) NOT NULL AUTO_INCREMENT , +-- CHANGE COLUMN `userFk` `userFk` INT(10) UNSIGNED NULL DEFAULT NULL ; +-- ALTER TABLE `vn`.`itemLog` +-- ADD CONSTRAINT `itemLogUserFk` +-- FOREIGN KEY (`userFk`) +-- REFERENCES `account`.`user` (`id`) +-- ON DELETE CASCADE +-- ON UPDATE CASCADE; diff --git a/db/install/changes/17-ticketComponentUpdateSale.sql b/db/install/changes/17-ticketComponentUpdateSale.sql new file mode 100644 index 000000000..9fe840404 --- /dev/null +++ b/db/install/changes/17-ticketComponentUpdateSale.sql @@ -0,0 +1,148 @@ +USE `vn`; +DROP procedure IF EXISTS `ticketComponentUpdateSale`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentUpdateSale`(vOption INT) +BEGIN + + DECLARE vComponentFk INT; + DECLARE vRenewComponents BOOLEAN; + DECLARE vKeepPrices BOOLEAN; + + CASE vOption + WHEN 1 THEN + SET vRenewComponents = TRUE; + SET vKeepPrices = FALSE; + WHEN 2 THEN + SET vComponentFk = 17; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 3 THEN + SET vComponentFk = 37; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 4 THEN + SET vComponentFk = 34; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 5 THEN + SET vComponentFk = 35; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 6 THEN + SET vComponentFk = 36; + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + WHEN 7 THEN + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.8, 3) + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk NOT IN (28, 29) + GROUP BY s.id; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 29, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.2, 3) + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk NOT IN (28, 29) + GROUP BY s.id; + + SET vRenewComponents = FALSE; + SET vKeepPrices = FALSE; + WHEN 8 THEN + DELETE sc.* + FROM tmp.sale tmps JOIN saleComponent sc ON sc.saleFk = tmps.saleFk; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100)), 3) + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id; + + SET vRenewComponents = FALSE; + SET vKeepPrices = FALSE; + WHEN 9 THEN + SET vRenewComponents = TRUE; + SET vKeepPrices = TRUE; + END CASE; + + IF vRenewComponents THEN + DELETE sc.* + FROM tmp.sale tmps + JOIN saleComponent sc ON sc.saleFk = tmps.saleFk + JOIN componentRate cr ON cr.id = sc.componentFk + WHERE cr.isRenewable; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, tc.componentFk, tc.cost + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk = tc.componentFk + LEFT JOIN componentRate cr ON cr.id = tc.componentFk + WHERE IF(sc.componentFk IS NULL AND NOT cr.isRenewable, FALSE, TRUE); + END IF; + + IF vKeepPrices THEN + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + WHERE sc.saleFk <> vComponentFk + GROUP BY s.id + HAVING dif <> 0; + ELSE + UPDATE sale s + JOIN item i on i.id = s.itemFk + JOIN itemType it on it.id = i.typeFk + JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + GROUP BY sc.saleFk) sc ON sc.saleFk = s.id + SET s.price = sumValue + WHERE it.code != 'PRT'; + + REPLACE INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 21, ROUND((s.price * (100 - s.discount) / 100) - SUM(value), 3) saleValue + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + WHERE sc.componentFk != 21 + GROUP BY s.id + HAVING ROUND(saleValue, 4) <> 0; + END IF; + + UPDATE sale s + JOIN ( + SELECT SUM(sc.value) sumValue, sc.saleFk + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + JOIN componentRate cr ON cr.id = sc.componentFk + JOIN componentTypeRate ctr on ctr.id = cr.componentTypeRate AND ctr.base + GROUP BY sc.saleFk) sc ON sc.saleFk = s.id + SET s.priceFixed = sumValue, s.isPriceFixed = 1; + + DELETE sc.* + FROM saleComponent sc + JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk + JOIN sale s on s.id = sc.saleFk + JOIN item i ON i.id = s.itemFk + JOIN itemType it ON it.id = i.typeFk + WHERE it.code = 'PRT'; + + INSERT INTO saleComponent(saleFk, componentFk, value) + SELECT s.id, 15, s.price + FROM sale s + JOIN tmp.sale tmps ON tmps.saleFk = s.id + JOIN item i ON i.id = s.itemFK + JOIN itemType it ON it.id = i.typeFk + WHERE it.code = 'PRT' AND s.price > 0; +END$$ + +DELIMITER ; + diff --git a/db/install/changes/18-zone.sql b/db/install/changes/18-zone.sql deleted file mode 100644 index 7bf078830..000000000 --- a/db/install/changes/18-zone.sql +++ /dev/null @@ -1,7 +0,0 @@ -USE `vn`; - -ALTER TABLE `vn`.`zone` -ADD COLUMN `isVolumetric` TINYINT(1) NOT NULL DEFAULT 0 AFTER `bonus`; - -ALTER TABLE `vn`.`zone` -DROP INDEX `name_UNIQUE` ; diff --git a/db/install/dump/dumpedFixtures.sql b/db/install/dump/dumpedFixtures.sql index 9eb199ce7..f6beced0d 100644 --- a/db/install/dump/dumpedFixtures.sql +++ b/db/install/dump/dumpedFixtures.sql @@ -1,7 +1,7 @@ USE `account`; -- MySQL dump 10.13 Distrib 5.7.21, for osx10.13 (x86_64) -- --- Host: test-db.verdnatura.es Database: account +-- Host: db.verdnatura.es Database: account -- ------------------------------------------------------ -- Server version 5.6.25-4-log @@ -55,11 +55,11 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-03-01 13:31:23 +-- Dump completed on 2019-03-14 7:15:33 USE `salix`; -- MySQL dump 10.13 Distrib 5.7.21, for osx10.13 (x86_64) -- --- Host: test-db.verdnatura.es Database: salix +-- Host: db.verdnatura.es Database: salix -- ------------------------------------------------------ -- Server version 5.6.25-4-log @@ -80,7 +80,7 @@ USE `salix`; LOCK TABLES `ACL` WRITE; /*!40000 ALTER TABLE `ACL` DISABLE KEYS */; -INSERT INTO `ACL` VALUES (1,'Account','*','*','ALLOW','ROLE','employee'),(3,'Address','*','*','ALLOW','ROLE','employee'),(5,'AgencyService','*','READ','ALLOW','ROLE','employee'),(7,'Client','*','*','ALLOW','ROLE','employee'),(9,'ClientObservation','*','*','ALLOW','ROLE','employee'),(11,'ContactChannel','*','READ','ALLOW','ROLE','employee'),(13,'Employee','*','READ','ALLOW','ROLE','employee'),(14,'PayMethod','*','READ','ALLOW','ROLE','employee'),(16,'FakeProduction','*','READ','ALLOW','ROLE','employee'),(17,'Warehouse','* ','READ','ALLOW','ROLE','employee'),(18,'State','*','READ','ALLOW','ROLE','employee'),(20,'TicketState','*','*','ALLOW','ROLE','employee'),(24,'Delivery','*','READ','ALLOW','ROLE','employee'),(25,'Zone','*','READ','ALLOW','ROLE','employee'),(26,'ClientCredit','*','*','ALLOW','ROLE','employee'),(27,'ClientCreditLimit','*','READ','ALLOW','ROLE','employee'),(30,'GreugeType','*','READ','ALLOW','ROLE','employee'),(31,'Mandate','*','READ','ALLOW','ROLE','employee'),(32,'MandateType','*','READ','ALLOW','ROLE','employee'),(33,'Company','*','READ','ALLOW','ROLE','employee'),(34,'Greuge','*','READ','ALLOW','ROLE','employee'),(35,'AddressObservation','*','*','ALLOW','ROLE','employee'),(36,'ObservationType','*','*','ALLOW','ROLE','employee'),(37,'Greuge','*','WRITE','ALLOW','ROLE','employee'),(38,'AgencyMode','*','READ','ALLOW','ROLE','employee'),(39,'ItemTag','*','WRITE','ALLOW','ROLE','buyer'),(40,'ItemBotanical','*','WRITE','ALLOW','ROLE','buyer'),(41,'ItemBotanical','*','READ','ALLOW','ROLE','employee'),(42,'ItemPlacement','*','WRITE','ALLOW','ROLE','buyer'),(43,'ItemPlacement','*','WRITE','ALLOW','ROLE','replenisher'),(44,'ItemPlacement','*','READ','ALLOW','ROLE','employee'),(45,'ItemBarcode','*','READ','ALLOW','ROLE','employee'),(46,'ItemBarcode','*','WRITE','ALLOW','ROLE','buyer'),(47,'ItemBarcode','*','WRITE','ALLOW','ROLE','replenisher'),(48,'ItemNiche','*','READ','ALLOW','ROLE','employee'),(49,'ItemNiche','*','WRITE','ALLOW','ROLE','buyer'),(50,'ItemNiche','*','WRITE','ALLOW','ROLE','replenisher'),(51,'ItemTag','*','READ','ALLOW','ROLE','employee'),(53,'Item','*','READ','ALLOW','ROLE','employee'),(54,'Item','*','WRITE','ALLOW','ROLE','buyer'),(55,'Recovery','*','READ','ALLOW','ROLE','employee'),(56,'Recovery','*','WRITE','ALLOW','ROLE','administrative'),(58,'CreditClassification','*','*','ALLOW','ROLE','insurance'),(60,'CreditInsurance','*','*','ALLOW','ROLE','insurance'),(61,'InvoiceOut','*','READ','ALLOW','ROLE','employee'),(62,'Ticket','*','*','ALLOW','ROLE','employee'),(63,'TicketObservation','*','*','ALLOW','ROLE','employee'),(64,'Route','*','READ','ALLOW','ROLE','employee'),(65,'Sale','*','READ','ALLOW','ROLE','employee'),(66,'TicketTracking','*','READ','ALLOW','ROLE','employee'),(68,'TicketPackaging','*','*','ALLOW','ROLE','employee'),(69,'Packaging','*','READ','ALLOW','ROLE','employee'),(70,'Packaging','*','WRITE','ALLOW','ROLE','logistic'),(71,'SaleChecked','*','READ','ALLOW','ROLE','employee'),(72,'SaleComponent','*','READ','ALLOW','ROLE','employee'),(73,'Expedition','*','READ','ALLOW','ROLE','employee'),(74,'Expedition','*','WRITE','ALLOW','ROLE','deliveryBoss'),(75,'Expedition','*','WRITE','ALLOW','ROLE','production'),(76,'AnnualAverageInvoiced','*','READ','ALLOW','ROLE','employee'),(77,'WorkerMana','*','READ','ALLOW','ROLE','employee'),(78,'TicketTracking','*','WRITE','ALLOW','ROLE','production'),(79,'TicketTracking','changeState','*','ALLOW','ROLE','employee'),(80,'Sale','removes','*','ALLOW','ROLE','employee'),(81,'Sale','moveToTicket','*','ALLOW','ROLE','employee'),(82,'Sale','updateQuantity','*','ALLOW','ROLE','employee'),(83,'Sale','updatePrice','*','ALLOW','ROLE','employee'),(84,'Sale','updateDiscount','*','ALLOW','ROLE','employee'),(85,'SaleTracking','*','READ','ALLOW','ROLE','employee'),(86,'Order','*','*','ALLOW','ROLE','employee'),(87,'OrderRow','*','*','ALLOW','ROLE','employee'),(88,'ClientContact','*','*','ALLOW','ROLE','employee'),(89,'Sale','moveToNewTicket','*','ALLOW','ROLE','employee'),(90,'Sale','reserve','*','ALLOW','ROLE','employee'),(91,'TicketWeekly','*','*','ALLOW','ROLE','employee'),(94,'Agency','landsThatDay','*','ALLOW','ROLE','employee'),(96,'ClaimEnd','*','READ','ALLOW','ROLE','employee'),(97,'ClaimEnd','*','WRITE','ALLOW','ROLE','salesAssistant'),(98,'ClaimBeginning','*','*','ALLOW','ROLE','employee'),(99,'ClaimDevelopment','*','READ','ALLOW','ROLE','employee'),(100,'ClaimDevelopment','*','WRITE','ALLOW','ROLE','salesAssistant'),(101,'Claim','*','*','ALLOW','ROLE','employee'),(102,'Claim','createFromSales','*','ALLOW','ROLE','employee'),(103,'ClaimEnd','importTicketSales','WRITE','ALLOW','ROLE','salesAssistant'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','WRITE','ALLOW','ROLE','marketingBoss'),(107,'ItemNiche','*','WRITE','ALLOW','ROLE','marketingBoss'),(108,'ItemPlacement','*','WRITE','ALLOW','ROLE','marketingBoss'),(109,'UserConfig','*','*','ALLOW','ROLE','employee'),(110,'Bank','*','READ','ALLOW','ROLE','employee'),(111,'ClientLog','*','READ','ALLOW','ROLE','employee'),(112,'Defaulter','*','READ','ALLOW','ROLE','employee'),(113,'ClientRisk','*','READ','ALLOW','ROLE','employee'),(114,'Receipt','*','READ','ALLOW','ROLE','employee'),(115,'Receipt','*','WRITE','ALLOW','ROLE','administrative'),(116,'BankEntity','*','*','ALLOW','ROLE','employee'),(117,'ClientSample','*','*','ALLOW','ROLE','employee'),(118,'WorkerTeam','*','*','ALLOW','ROLE','salesPerson'),(119,'Travel','*','READ','ALLOW','ROLE','employee'),(120,'Travel','*','WRITE','ALLOW','ROLE','buyer'),(121,'Item','regularize','*','ALLOW','ROLE','employee'),(122,'TicketRequest','*','*','ALLOW','ROLE','salesPerson'),(123,'Worker','*','READ','ALLOW','ROLE','employee'),(124,'Client','confirmTransaction','WRITE','ALLOW','ROLE','administrative'),(125,'Agency','getAgenciesWithWarehouse','*','ALLOW','ROLE','employee'),(126,'Client','activeWorkersWithRole','*','ALLOW','ROLE','employee'),(127,'TicketLog','*','READ','ALLOW','ROLE','employee'),(129,'TicketService','*','*','ALLOW','ROLE','employee'),(130,'Expedition','*','WRITE','ALLOW','ROLE','packager'),(131,'CreditInsurance','*','READ','ALLOW','ROLE','employee'),(132,'CreditClassification','*','READ','ALLOW','ROLE','employee'),(133,'ItemTag','*','WRITE','ALLOW','ROLE','marketingBoss'),(135,'ZoneGeo','*','READ','ALLOW','ROLE','employee'),(136,'ZoneCalendar','*','READ','ALLOW','ROLE','employee'),(137,'ZoneIncluded','*','READ','ALLOW','ROLE','employee'),(138,'LabourHoliday','*','READ','ALLOW','ROLE','employee'),(139,'LabourHolidayLegend','*','READ','ALLOW','ROLE','employee'),(140,'LabourHolidayType','*','READ','ALLOW','ROLE','employee'),(141,'Zone','*','WRITE','ALLOW','ROLE','deliveryBoss'),(142,'ZoneCalendar','*','WRITE','ALLOW','ROLE','deliveryBoss'),(143,'ZoneIncluded','*','*','ALLOW','ROLE','deliveryBoss'),(144,'Stowaway','*','*','ALLOW','ROLE','employee'),(145,'Ticket','getPossibleStowaways','READ','ALLOW','ROLE','employee'),(147,'UserConfigView','*','*','ALLOW','ROLE','employee'),(148,'UserConfigView','*','*','ALLOW','ROLE','employee'); +INSERT INTO `ACL` VALUES (1,'Account','*','*','ALLOW','ROLE','employee'),(3,'Address','*','*','ALLOW','ROLE','employee'),(5,'AgencyService','*','READ','ALLOW','ROLE','employee'),(7,'Client','*','*','ALLOW','ROLE','employee'),(9,'ClientObservation','*','*','ALLOW','ROLE','employee'),(11,'ContactChannel','*','READ','ALLOW','ROLE','employee'),(13,'Employee','*','READ','ALLOW','ROLE','employee'),(14,'PayMethod','*','READ','ALLOW','ROLE','employee'),(16,'FakeProduction','*','READ','ALLOW','ROLE','employee'),(17,'Warehouse','* ','READ','ALLOW','ROLE','employee'),(18,'State','*','READ','ALLOW','ROLE','employee'),(20,'TicketState','*','*','ALLOW','ROLE','employee'),(24,'Delivery','*','READ','ALLOW','ROLE','employee'),(25,'Zone','*','READ','ALLOW','ROLE','employee'),(26,'ClientCredit','*','*','ALLOW','ROLE','employee'),(27,'ClientCreditLimit','*','READ','ALLOW','ROLE','employee'),(30,'GreugeType','*','READ','ALLOW','ROLE','employee'),(31,'Mandate','*','READ','ALLOW','ROLE','employee'),(32,'MandateType','*','READ','ALLOW','ROLE','employee'),(33,'Company','*','READ','ALLOW','ROLE','employee'),(34,'Greuge','*','READ','ALLOW','ROLE','employee'),(35,'AddressObservation','*','*','ALLOW','ROLE','employee'),(36,'ObservationType','*','*','ALLOW','ROLE','employee'),(37,'Greuge','*','WRITE','ALLOW','ROLE','employee'),(38,'AgencyMode','*','READ','ALLOW','ROLE','employee'),(39,'ItemTag','*','WRITE','ALLOW','ROLE','buyer'),(40,'ItemBotanical','*','WRITE','ALLOW','ROLE','buyer'),(41,'ItemBotanical','*','READ','ALLOW','ROLE','employee'),(42,'ItemPlacement','*','WRITE','ALLOW','ROLE','buyer'),(43,'ItemPlacement','*','WRITE','ALLOW','ROLE','replenisher'),(44,'ItemPlacement','*','READ','ALLOW','ROLE','employee'),(45,'ItemBarcode','*','READ','ALLOW','ROLE','employee'),(46,'ItemBarcode','*','WRITE','ALLOW','ROLE','buyer'),(47,'ItemBarcode','*','WRITE','ALLOW','ROLE','replenisher'),(48,'ItemNiche','*','READ','ALLOW','ROLE','employee'),(49,'ItemNiche','*','WRITE','ALLOW','ROLE','buyer'),(50,'ItemNiche','*','WRITE','ALLOW','ROLE','replenisher'),(51,'ItemTag','*','READ','ALLOW','ROLE','employee'),(53,'Item','*','READ','ALLOW','ROLE','employee'),(54,'Item','*','WRITE','ALLOW','ROLE','buyer'),(55,'Recovery','*','READ','ALLOW','ROLE','employee'),(56,'Recovery','*','WRITE','ALLOW','ROLE','administrative'),(58,'CreditClassification','*','*','ALLOW','ROLE','insurance'),(60,'CreditInsurance','*','*','ALLOW','ROLE','insurance'),(61,'InvoiceOut','*','READ','ALLOW','ROLE','employee'),(62,'Ticket','*','*','ALLOW','ROLE','employee'),(63,'TicketObservation','*','*','ALLOW','ROLE','employee'),(64,'Route','*','READ','ALLOW','ROLE','employee'),(65,'Sale','*','READ','ALLOW','ROLE','employee'),(66,'TicketTracking','*','READ','ALLOW','ROLE','employee'),(68,'TicketPackaging','*','*','ALLOW','ROLE','employee'),(69,'Packaging','*','READ','ALLOW','ROLE','employee'),(70,'Packaging','*','WRITE','ALLOW','ROLE','logistic'),(71,'SaleChecked','*','READ','ALLOW','ROLE','employee'),(72,'SaleComponent','*','READ','ALLOW','ROLE','employee'),(73,'Expedition','*','READ','ALLOW','ROLE','employee'),(74,'Expedition','*','WRITE','ALLOW','ROLE','deliveryBoss'),(75,'Expedition','*','WRITE','ALLOW','ROLE','production'),(76,'AnnualAverageInvoiced','*','READ','ALLOW','ROLE','employee'),(77,'WorkerMana','*','READ','ALLOW','ROLE','employee'),(78,'TicketTracking','*','WRITE','ALLOW','ROLE','production'),(79,'TicketTracking','changeState','*','ALLOW','ROLE','employee'),(80,'Sale','removes','*','ALLOW','ROLE','employee'),(81,'Sale','moveToTicket','*','ALLOW','ROLE','employee'),(82,'Sale','updateQuantity','*','ALLOW','ROLE','employee'),(83,'Sale','updatePrice','*','ALLOW','ROLE','employee'),(84,'Sale','updateDiscount','*','ALLOW','ROLE','employee'),(85,'SaleTracking','*','READ','ALLOW','ROLE','employee'),(86,'Order','*','*','ALLOW','ROLE','employee'),(87,'OrderRow','*','*','ALLOW','ROLE','employee'),(88,'ClientContact','*','*','ALLOW','ROLE','employee'),(89,'Sale','moveToNewTicket','*','ALLOW','ROLE','employee'),(90,'Sale','reserve','*','ALLOW','ROLE','employee'),(91,'TicketWeekly','*','*','ALLOW','ROLE','employee'),(94,'Agency','landsThatDay','*','ALLOW','ROLE','employee'),(96,'ClaimEnd','*','READ','ALLOW','ROLE','employee'),(97,'ClaimEnd','*','WRITE','ALLOW','ROLE','salesAssistant'),(98,'ClaimBeginning','*','*','ALLOW','ROLE','employee'),(99,'ClaimDevelopment','*','READ','ALLOW','ROLE','employee'),(100,'ClaimDevelopment','*','WRITE','ALLOW','ROLE','salesAssistant'),(101,'Claim','*','*','ALLOW','ROLE','employee'),(102,'Claim','createFromSales','*','ALLOW','ROLE','employee'),(103,'ClaimEnd','importTicketSales','WRITE','ALLOW','ROLE','salesAssistant'),(104,'Item','*','WRITE','ALLOW','ROLE','marketingBoss'),(105,'ItemBarcode','*','WRITE','ALLOW','ROLE','marketingBoss'),(106,'ItemBotanical','*','WRITE','ALLOW','ROLE','marketingBoss'),(107,'ItemNiche','*','WRITE','ALLOW','ROLE','marketingBoss'),(108,'ItemPlacement','*','WRITE','ALLOW','ROLE','marketingBoss'),(109,'UserConfig','*','*','ALLOW','ROLE','employee'),(110,'Bank','*','READ','ALLOW','ROLE','employee'),(111,'ClientLog','*','READ','ALLOW','ROLE','employee'),(112,'Defaulter','*','READ','ALLOW','ROLE','employee'),(113,'ClientRisk','*','READ','ALLOW','ROLE','employee'),(114,'Receipt','*','READ','ALLOW','ROLE','employee'),(115,'Receipt','*','WRITE','ALLOW','ROLE','administrative'),(116,'BankEntity','*','*','ALLOW','ROLE','employee'),(117,'ClientSample','*','*','ALLOW','ROLE','employee'),(118,'WorkerTeam','*','*','ALLOW','ROLE','salesPerson'),(119,'Travel','*','READ','ALLOW','ROLE','employee'),(120,'Travel','*','WRITE','ALLOW','ROLE','buyer'),(121,'Item','regularize','*','ALLOW','ROLE','employee'),(122,'TicketRequest','*','*','ALLOW','ROLE','salesPerson'),(123,'Worker','*','READ','ALLOW','ROLE','employee'),(124,'Client','confirmTransaction','WRITE','ALLOW','ROLE','administrative'),(125,'Agency','getAgenciesWithWarehouse','*','ALLOW','ROLE','employee'),(126,'Client','activeWorkersWithRole','*','ALLOW','ROLE','employee'),(127,'TicketLog','*','READ','ALLOW','ROLE','employee'),(129,'TicketService','*','*','ALLOW','ROLE','employee'),(130,'Expedition','*','WRITE','ALLOW','ROLE','packager'),(131,'CreditInsurance','*','READ','ALLOW','ROLE','employee'),(132,'CreditClassification','*','READ','ALLOW','ROLE','employee'),(133,'ItemTag','*','WRITE','ALLOW','ROLE','marketingBoss'),(135,'ZoneGeo','*','READ','ALLOW','ROLE','employee'),(136,'ZoneCalendar','*','READ','ALLOW','ROLE','employee'),(137,'ZoneIncluded','*','READ','ALLOW','ROLE','employee'),(138,'LabourHoliday','*','READ','ALLOW','ROLE','employee'),(139,'LabourHolidayLegend','*','READ','ALLOW','ROLE','employee'),(140,'LabourHolidayType','*','READ','ALLOW','ROLE','employee'),(141,'Zone','*','WRITE','ALLOW','ROLE','deliveryBoss'),(142,'ZoneCalendar','*','WRITE','ALLOW','ROLE','deliveryBoss'),(143,'ZoneIncluded','*','*','ALLOW','ROLE','deliveryBoss'),(144,'Stowaway','*','*','ALLOW','ROLE','employee'),(145,'Ticket','getPossibleStowaways','READ','ALLOW','ROLE','employee'),(147,'UserConfigView','*','*','ALLOW','ROLE','employee'),(148,'UserConfigView','*','*','ALLOW','ROLE','employee'),(149,'Sip','*','READ','ALLOW','ROLE','employee'),(150,'Sip','*','WRITE','ALLOW','ROLE','hr'); /*!40000 ALTER TABLE `ACL` ENABLE KEYS */; UNLOCK TABLES; @@ -103,11 +103,11 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-03-01 13:31:23 +-- Dump completed on 2019-03-14 7:15:33 USE `vn`; -- MySQL dump 10.13 Distrib 5.7.21, for osx10.13 (x86_64) -- --- Host: test-db.verdnatura.es Database: vn +-- Host: db.verdnatura.es Database: vn -- ------------------------------------------------------ -- Server version 5.6.25-4-log @@ -201,11 +201,11 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-03-01 13:31:23 +-- Dump completed on 2019-03-14 7:15:33 USE `vn2008`; -- MySQL dump 10.13 Distrib 5.7.21, for osx10.13 (x86_64) -- --- Host: test-db.verdnatura.es Database: vn2008 +-- Host: db.verdnatura.es Database: vn2008 -- ------------------------------------------------------ -- Server version 5.6.25-4-log @@ -236,7 +236,7 @@ UNLOCK TABLES; LOCK TABLES `Gastos` WRITE; /*!40000 ALTER TABLE `Gastos` DISABLE KEYS */; -INSERT INTO `Gastos` VALUES ('2000000000',1,'Inmovilizado pendiente',1,0,0),('2000000000',3,'Compra de bienes de inmovilizado',1,0,0),('2600000000',1,'Fianzas',0,0,0),('4600000000',1,'Anticipos de remuneraciones',1,0,0),('4600000001',1,'Anticpos de remuneración',1,0,0),('4751000000',0,'Retenciones',0,1,0),('4751000000',1,'Retenciones',0,1,0),('4751000000',6,'Retencion',0,0,0),('4759000000',1,'Embargos salariales',1,0,0),('5200000006',1,'Deudas a c/p CRA',1,0,0),('5200000008',0,'Prestamo CP Transolver IVECO 269',1,0,0),('5200000008',1,'Prestamo Transolver 201600269',1,0,0),('5200000009',0,'Prestamo CP Transolver IVECO 270',1,0,0),('5200000009',1,'Prestamo Transolver 201600270',1,0,0),('5200000010',0,'Prestamo CP Transolver IVECO 271',1,0,0),('5200000010',1,'Prestamo Transolver 201600271',1,0,0),('5200000011',1,'Prestamo Transolver 339',0,0,0),('5200000012',1,'Prestamo Transolver 340',1,0,0),('5200000013',1,'Prestamo Transolver 341',1,0,0),('5200000014',1,'Prestamo a c/p BBVA 600.000€',1,0,0),('5200000022',1,'Linea comercio exterior',1,0,0),('5240000001',1,'Leasing BBVA',1,0,0),('5240002032',1,'Leasing Iveco',1,0,0),('5240002066',1,'Leasing c/p Man',1,0,0),('5240002104',1,'Leasing c/p La caixa 3 vehículos',1,0,0),('5325000003',6,'Prestamo a partes vinculadas',0,0,0),('5420000001',1,'Prestamo concedido',1,0,0),('5650000001',1,'Fianza c/p vehiculo',0,0,0),('5660000001',1,'Suplidos',0,0,0),('5660000001',20,'Suplidos',1,0,0),('5660000002',0,'Suplidos',0,0,0),('5660000002',1,'Suplidos Transitarios nacionales',1,0,0),('5660000003',1,'Deposito c/p Ebury',1,0,0),('5660000003',4,'Deposito Ebury',0,0,0),('5660000004',4,'Deposito Global Reach',0,0,0),('6001000000',1,'Compras a terceros nacional',1,0,0),('6001000000',18,'Compras a terceros nacional',1,0,0),('6001000000',19,'Compras a terceros nacional',1,0,0),('6001000001',1,'Adquisiones en Europa',0,0,0),('6001000001',3,'Adquisición en Europa',1,0,0),('6002000000',1,'Transportes de compras',1,0,0),('6002000001',1,'Tranportes de compra Europa',1,0,0),('6002000001',4,'Transportes de compras Europa',1,0,0),('6002000567',0,'Transporte de compras VNH',1,0,0),('6003000000',1,'Adquisición mercancia Extracomunitaria',1,0,0),('6003000000',5,'Adquisición mercancia Extracomunitaria',1,0,0),('6003000000',6,'Adquisición mercancia Extracomunitaria',1,0,0),('6003000567',0,'Compra de mercancia extracomunitaria VNH',1,0,0),('6004000000',1,'Transporte compras Sudamérica',1,0,0),('6004000000',4,'Transporte compras Sudamérica',1,0,0),('6004000000',6,'Transporte compras Sudamérica',1,0,0),('6010000000',1,'Materias primas',1,0,0),('6020000000',1,'Otros aprovisionamientos',1,0,0),('6020000001',1,'Embalajes',1,0,0),('6020000002',1,'Otros aprov. Taller artíficial',1,0,0),('6070000000',1,'Trabajos de produccion encargados a terceros',1,0,0),('6090000000',6,'Rappels por compras',1,0,0),('6100000000',0,'Variacion existencias',1,0,0),('6210000000',1,'Arrendamientos',1,0,0),('6210000001',1,'Arrendamiento vehículo',1,0,0),('6210000001',4,'Gastos de arrendamiento vehículos',1,0,0),('6210000002',1,'Arrendamiento nave',1,0,0),('6210000003',1,'Arrendamiento espacio virtual-informatic',1,0,0),('6210000004',1,'Arrendamiento elementos para el proceso de informa',1,0,0),('6210000005',1,'Arrendamiento CC y banddejas',1,0,0),('6210000567',0,'Alquiler VNH',1,0,0),('6220000000',1,'Reparaciones y conservacion',1,0,0),('6220000001',1,'Reparación-Informatica',1,0,0),('6220000001',4,'Reparacion y mantenimiento informatica',1,0,0),('6220000003',1,'Reparación-Vehiculos',1,0,0),('6220000004',1,'Reparación-Instalaciones',1,0,0),('6220000005',1,'Reparación y mantenimineto CCs',1,0,0),('6220000006',1,'Repracion y conser maquinaria',1,0,0),('6230000000',1,'Servicios de profesionales independientes',1,0,0),('6230000000',4,'Servicio de profesionales',0,0,0),('6230000000',6,'Servicios de profesionales',1,0,0),('6230000001',1,'Servicios por gestión de ventas',1,0,0),('6230000001',4,'Servicios por gestión de ventas',1,0,0),('6240000000',1,'Transportes de ventas rutas',1,0,0),('6240000000',4,'Transportes de ventas',1,0,0),('6240000001',1,'Transporte ventas agencias',1,0,0),('6240000002',1,'Transporte ventas reclamaciones',1,0,0),('6240000567',1,'Transporte ventas VNH',1,0,0),('6250000000',1,'Primas de seguros',1,0,0),('6250000000',4,'Prima de Seguros',1,0,0),('6250000001',1,'Primas de seguros-Personales',1,0,0),('6250000002',1,'Primas de seguros-Colectivos',1,0,0),('6250000003',1,'Primas de seguros-Vehiculos',1,0,0),('6250000004',1,'Primas de seguros-Inmuebles',1,0,0),('6250000567',0,'Seguros VNH',1,0,0),('6260000000',1,'Gastos bancarios',1,0,0),('6260000000',4,'Gastos bancarios',0,0,0),('6260000000',6,'Gastos bancarios',1,0,0),('6260000001',1,'Gastos bancarios datafono',1,0,0),('6260000002',1,'Gastos bancarios transferencia nacional',1,0,0),('6260000003',1,'Gastos bancarios transferencia Europa',1,0,0),('6260000004',1,'Gastos bancarios transferencia divisas',1,0,0),('6260000567',0,'Gastos bancarios VNH',1,0,0),('6270000000',1,'Publicidad y RRPP',1,0,0),('6270000000',3,'Publicidad, propaganda y RR PP',1,0,0),('6270000000',6,'Publicidad',1,0,0),('6270000000',14,'Publicidad, propaganda RRPP',1,0,0),('6270000001',1,'Patrocinio',0,0,0),('6280000000',1,'Suministros',1,0,0),('6280000001',1,'Telefonos',1,0,0),('6280000002',1,'Gasoil',1,0,0),('6280000003',1,'Suministros-Electricidad',1,0,0),('6280000004',1,'Internet',1,0,0),('6280000567',0,'Suministros VNH',1,0,0),('6280001567',0,'Suministros telefono VNH',1,0,0),('6280003567',0,'Suministro luz VNH',1,0,0),('6290000000',1,'Otros servicios',1,0,0),('6290000000',6,'Otros gastos varios',1,0,0),('6290000001',1,'Material de oficina',1,0,0),('6290000002',1,'Gastos en formacion',1,0,0),('6290000003',1,'Asesoria juridica',1,0,0),('6290000004',4,'Otros servicios UE',1,0,0),('6290000005',1,'Gastos varios-Correos',1,0,0),('6290000006',1,'Otros servicios extranjero',1,0,0),('6290000006',5,'Otros servicios extranjero',1,0,0),('6290000006',6,'Otros servicios extranjero',1,0,0),('6290000007',1,'Gastos pequeño material',1,0,0),('6290000007',3,'Compras pequeño material',1,0,0),('6290000007',6,'Pequeño material',1,0,0),('6290000008',1,'Gastos varios-uniformes personal',1,0,0),('6290000008',3,'Compra uniformes',1,0,0),('6290000009',1,'Gastos-CC Container',1,0,0),('6290000010',1,'Gastos formación clientes',1,0,0),('6290000012',1,'Gastos gestión contra-reembolsos',1,0,0),('6290000013',1,'Arrendamiento Vilassar',1,0,0),('6290000014',1,'Gasto laboral espresas ETT',1,0,0),('6290000015',1,'Gasto compra terminales moviles y similares',1,0,0),('6290000015',3,'Gasto compra terminales moviles y similares',1,0,0),('6290000015',6,'Gasto compra terminales moviles y similares',1,0,0),('6290000016',1,'Gasto gestión cobro ventas',1,0,0),('6290000553',1,'Gastos viaje administrador',1,0,0),('6290000553',4,'Gastos viaje administrador-gerente',1,0,0),('6290000553',6,'Gastos viaje administrador',1,0,0),('6290001000',1,'Gastos de viaje',1,0,0),('6290001000',4,'Gastos viajes otros departamentos',1,0,0),('6290001000',6,'Gastos viaje personal otros departamentos',1,0,0),('6290001001',1,'Gastos R.R.P.P. Gerente',1,0,0),('6290001002',1,'Gastos R.R.P.P. Comerciales',1,0,0),('6290001567',0,'Gastos material oficina',1,0,0),('6300000000',1,'Impuesto de sociedades',1,0,0),('6310000000',1,'Otros tributos',1,0,0),('6380000000',1,'Ajustes positivos s/b Bº',1,0,0),('6400000000',0,'Sueldos y salarios',1,0,0),('6400000000',1,'Salarios',0,0,0),('6400000001',0,'Productividad',1,0,0),('6400000567',0,'Salarios VNH',1,0,0),('6410000001',1,'Indemnizaciones',1,0,0),('6420000000',0,'Seguridad Social a cargo de la empresa',1,0,0),('6420000000',1,'Seguridad Social',0,0,0),('6490000000',1,'Otros gastos sociales',1,0,0),('6500000000',1,'Impagados definitivos',1,0,0),('6620000000',0,'Intereses Bancarios',1,0,0),('6620000001',1,'Intereses deudas a l/p',1,0,0),('6620000006',1,'Intereses deuda prestamo CRA',1,0,0),('6620000007',1,'Intereses La Caixa linea comercio exterior',1,0,0),('6620000007',16,'Intereses La Caixa Linea Comercio Exterior',0,0,0),('6620000008',1,'Intereses Prestamos Transolver 2016',1,0,0),('6620000011',1,'Intereses BBVA linea comercio exterior',1,0,0),('6620000014',1,'Intereses Prestamo BBVA',1,0,0),('6620000015',1,'Interés Póliza Deutsche Bank Comercio Exterior',0,0,0),('6620000023',1,'Intereses Bankinter Póliza Comercio Exterior',0,0,0),('6620002032',1,'Intereses Leaing Iveco',1,0,0),('6620002066',1,'Leasing Intereses Man',1,0,0),('6620002104',1,'Intereses Leasing La caixa 3 vehículos',1,0,0),('6660000000',1,'Perdidas en valores representativos de deuda a l/p',0,0,0),('6681000000',1,'Diferencia negativa tipo de cambio',1,0,0),('6681000000',4,'Diferencia negativa tipo de cambio',0,0,0),('6681000000',6,'Diferencia negativa tipo de cambio',1,0,0),('6681000567',0,'Diferencias de cambio VNH',1,0,0),('6690000000',1,'Otros gastos financieros',1,0,0),('6690000000',6,'Gastos financieros',1,0,0),('6720000000',16,'Perdidas procedentes de inversiones',0,0,0),('6780000000',1,'Gastos extraordinarios',1,0,0),('6780000001',1,'Gastos no deducibles',1,0,0),('6780000001',16,'Gasto no deducible',0,0,0),('6800000000',1,'Amortización inmovilizado intangible',1,0,0),('6800000001',0,'Amortizacion inmovilizado material',1,0,0),('6800000001',1,'Amortización del inmovilizado material',1,0,0),('6810000000',0,'Amortizaciones inmovilizado',1,0,0),('6810000000',1,'Amortizacion inmovilizado material',1,0,0),('7000000000',0,'Ventas',1,0,0),('7000000001',1,'Venta entre empresas',1,0,0),('7000010000',0,'Terceros Flor',1,0,0),('7000020000',0,'Terceros Planta',1,0,0),('7000030000',0,'Terceros Complementos',1,0,0),('7000040000',0,'Terceros Artificial',1,0,0),('7000050000',0,'Terceros Verdes',1,0,0),('7000060000',0,'Terceros Otros',1,0,0),('7000070000',0,'Terceros Confección',1,0,0),('7000080000',1,'Terceros Logística',1,0,0),('7001000000',1,'Mercaderia',1,0,1),('7001010000',0,'Grupo Flor',1,0,0),('7001020000',0,'Grupo Planta',1,0,0),('7001030000',0,'Grupo Complementos',1,0,0),('7001040000',0,'Grupo Artificial',1,0,0),('7001050000',0,'Grupo Verdes',1,0,0),('7001060000',0,'Grupo Otros',1,0,0),('7001070000',0,'Grupo Confección',1,0,0),('7001080000',1,'Grupo Logística',1,0,0),('7002010000',0,'Asociados Flor',1,0,0),('7002020000',0,'Asociados Planta',1,0,0),('7002030000',0,'Asociados Complementos',1,0,0),('7002040000',0,'Asociados Artificial',1,0,0),('7002050000',0,'Asociados Verdes',1,0,0),('7002060000',0,'Asociados Otros',1,0,0),('7002070000',0,'Asociados Confección',1,0,0),('7002080000',1,'Asociados Logística',1,0,0),('7040000000',1,'Embalajes',1,0,1),('7050000000',1,'Prestacion de servicios',1,0,1),('7400000000',1,'Subvenciones, donaciones a la explotacion',1,0,0),('7550000000',0,'Ingresos por serivicios al personal',1,0,0),('7620000000',16,'Intereses de créditos a l/p',1,0,0),('768,0',0,NULL,1,0,0),('7680000000',0,'Diferencias positivas de cambio',1,0,0),('7680000000',1,'Diferenica positiva tipo de cambio',1,0,0),('7680000000',4,'Diferenica positiva tipo de cambio',0,0,0),('7680000000',6,'Diferenica positiva tipo de cambio',1,0,0),('7690000000',1,'Otros ingresos financieros',1,0,0),('7710000000',20,'Beneficio procendente vta inm',1,0,0),('7780000000',1,'Ingresos excepcionales',1,0,0),('7780000000',16,'Ingreso extraordinario',0,0,0),('7780000001',1,'Indemnizaciones transporte',1,0,0),('7780000001',4,'Indemnizaciones agencias transporte',1,0,0),('7780000001',5,'Indemnizaciones agencias transporte',1,0,0),('7780000001',6,'Indemnizaciones transporte',1,0,0),('7940000000',1,'Reversión impagos',1,0,0),('7940000000',16,'Reversión impagos',0,0,0); +INSERT INTO `Gastos` VALUES ('2000000000',1,'Inmovilizado pendiente',1,0,0),('2000000000',3,'Compra de bienes de inmovilizado',1,0,0),('2600000000',1,'Fianzas',0,0,0),('4600000000',1,'Anticipos de remuneraciones',1,0,0),('4600000001',1,'Anticpos de remuneración',1,0,0),('4751000000',0,'Retenciones',0,1,0),('4751000000',1,'Retenciones',0,1,0),('4751000000',6,'Retencion',0,0,0),('4759000000',1,'Embargos salariales',1,0,0),('5200000006',1,'Deudas a c/p CRA',1,0,0),('5200000008',0,'Prestamo CP Transolver IVECO 269',1,0,0),('5200000008',1,'Prestamo Transolver 201600269',1,0,0),('5200000009',0,'Prestamo CP Transolver IVECO 270',1,0,0),('5200000009',1,'Prestamo Transolver 201600270',1,0,0),('5200000010',0,'Prestamo CP Transolver IVECO 271',1,0,0),('5200000010',1,'Prestamo Transolver 201600271',1,0,0),('5200000011',1,'Prestamo Transolver 339',0,0,0),('5200000012',1,'Prestamo Transolver 340',1,0,0),('5200000013',1,'Prestamo Transolver 341',1,0,0),('5200000014',1,'Prestamo a c/p BBVA 600.000€',1,0,0),('5200000022',1,'Linea comercio exterior',1,0,0),('5240000001',1,'Leasing BBVA',1,0,0),('5240002032',1,'Leasing Iveco',1,0,0),('5240002066',1,'Leasing c/p Man',1,0,0),('5240002104',1,'Leasing c/p La caixa 3 vehículos',1,0,0),('5325000003',6,'Prestamo a partes vinculadas',0,0,0),('5420000001',1,'Prestamo concedido',1,0,0),('5650000001',1,'Fianza c/p vehiculo',0,0,0),('5660000001',1,'Suplidos',0,0,0),('5660000001',20,'Suplidos',1,0,0),('5660000002',0,'Suplidos',0,0,0),('5660000002',1,'Suplidos Transitarios nacionales',1,0,0),('5660000003',1,'Deposito c/p Ebury',1,0,0),('5660000003',4,'Deposito Ebury',0,0,0),('5660000004',4,'Deposito Global Reach',0,0,0),('6001000000',1,'Compras a terceros nacional',1,0,0),('6001000000',18,'Compras a terceros nacional',1,0,0),('6001000000',19,'Compras a terceros nacional',1,0,0),('6001000001',1,'Adquisiones en Europa',0,0,0),('6001000001',3,'Adquisición en Europa',1,0,0),('6001000002',1,'Compras a terceros Mascotas',1,0,0),('6001000002',4,'Compras a terceros mascotas',1,0,0),('6001000002',19,'Compras a terceros Mascotas',1,0,0),('6002000000',1,'Transportes de compras',1,0,0),('6002000001',1,'Tranportes de compra Europa',1,0,0),('6002000001',4,'Transportes de compras Europa',1,0,0),('6002000567',0,'Transporte de compras VNH',1,0,0),('6003000000',1,'Adquisición mercancia Extracomunitaria',1,0,0),('6003000000',5,'Adquisición mercancia Extracomunitaria',1,0,0),('6003000000',6,'Adquisición mercancia Extracomunitaria',1,0,0),('6003000567',0,'Compra de mercancia extracomunitaria VNH',1,0,0),('6004000000',1,'Transporte compras Sudamérica',1,0,0),('6004000000',4,'Transporte compras Sudamérica',1,0,0),('6004000000',6,'Transporte compras Sudamérica',1,0,0),('6010000000',1,'Materias primas',1,0,0),('6020000000',1,'Otros aprovisionamientos',1,0,0),('6020000001',1,'Embalajes',1,0,0),('6020000002',1,'Otros aprov. Taller artíficial',1,0,0),('6070000000',1,'Trabajos de produccion encargados a terceros',1,0,0),('6090000000',6,'Rappels por compras',1,0,0),('6100000000',0,'Variacion existencias',1,0,0),('6210000000',1,'Arrendamientos',1,0,0),('6210000001',1,'Arrendamiento vehículo',1,0,0),('6210000001',4,'Gastos de arrendamiento vehículos',1,0,0),('6210000002',1,'Arrendamiento nave',1,0,0),('6210000003',1,'Arrendamiento espacio virtual-informatic',1,0,0),('6210000004',1,'Arrendamiento elementos para el proceso de informa',1,0,0),('6210000005',1,'Arrendamiento CC y banddejas',1,0,0),('6210000567',0,'Alquiler VNH',1,0,0),('6220000000',1,'Reparaciones y conservacion',1,0,0),('6220000001',1,'Reparación-Informatica',1,0,0),('6220000001',4,'Reparacion y mantenimiento informatica',1,0,0),('6220000003',1,'Reparación-Vehiculos',1,0,0),('6220000004',1,'Reparación-Instalaciones',1,0,0),('6220000005',1,'Reparación y mantenimineto CCs',1,0,0),('6220000006',1,'Repracion y conser maquinaria',1,0,0),('6230000000',1,'Servicios de profesionales independientes',1,0,0),('6230000000',4,'Servicio de profesionales',0,0,0),('6230000000',6,'Servicios de profesionales',1,0,0),('6230000001',1,'Servicios por gestión de ventas',1,0,0),('6230000001',4,'Servicios por gestión de ventas',1,0,0),('6240000000',1,'Transportes de ventas rutas',1,0,0),('6240000000',4,'Transportes de ventas',1,0,0),('6240000001',1,'Transporte ventas agencias',1,0,0),('6240000002',1,'Transporte ventas reclamaciones',1,0,0),('6240000567',1,'Transporte ventas VNH',1,0,0),('6250000000',1,'Primas de seguros',1,0,0),('6250000000',4,'Prima de Seguros',1,0,0),('6250000001',1,'Primas de seguros-Personales',1,0,0),('6250000002',1,'Primas de seguros-Colectivos',1,0,0),('6250000003',1,'Primas de seguros-Vehiculos',1,0,0),('6250000004',1,'Primas de seguros-Inmuebles',1,0,0),('6250000567',0,'Seguros VNH',1,0,0),('6260000000',1,'Gastos bancarios',1,0,0),('6260000000',4,'Gastos bancarios',0,0,0),('6260000000',6,'Gastos bancarios',1,0,0),('6260000001',1,'Gastos bancarios datafono',1,0,0),('6260000002',1,'Gastos bancarios transferencia nacional',1,0,0),('6260000003',1,'Gastos bancarios transferencia Europa',1,0,0),('6260000004',1,'Gastos bancarios transferencia divisas',1,0,0),('6260000567',0,'Gastos bancarios VNH',1,0,0),('6270000000',1,'Publicidad y RRPP',1,0,0),('6270000000',3,'Publicidad, propaganda y RR PP',1,0,0),('6270000000',6,'Publicidad',1,0,0),('6270000000',14,'Publicidad, propaganda RRPP',1,0,0),('6270000001',1,'Patrocinio',0,0,0),('6280000000',1,'Suministros',1,0,0),('6280000001',1,'Telefonos',1,0,0),('6280000002',1,'Gasoil',1,0,0),('6280000003',1,'Suministros-Electricidad',1,0,0),('6280000004',1,'Internet',1,0,0),('6280000567',0,'Suministros VNH',1,0,0),('6280001567',0,'Suministros telefono VNH',1,0,0),('6280003567',0,'Suministro luz VNH',1,0,0),('6290000000',1,'Otros servicios',1,0,0),('6290000000',6,'Otros gastos varios',1,0,0),('6290000001',1,'Material de oficina',1,0,0),('6290000002',1,'Gastos en formacion',1,0,0),('6290000003',1,'Asesoria juridica',1,0,0),('6290000004',4,'Otros servicios UE',1,0,0),('6290000005',1,'Gastos varios-Correos',1,0,0),('6290000006',1,'Otros servicios extranjero',1,0,0),('6290000006',5,'Otros servicios extranjero',1,0,0),('6290000006',6,'Otros servicios extranjero',1,0,0),('6290000007',1,'Gastos pequeño material',1,0,0),('6290000007',3,'Compras pequeño material',1,0,0),('6290000007',6,'Pequeño material',1,0,0),('6290000008',1,'Gastos varios-uniformes personal',1,0,0),('6290000008',3,'Compra uniformes',1,0,0),('6290000009',1,'Gastos-CC Container',1,0,0),('6290000010',1,'Gastos formación clientes',1,0,0),('6290000012',1,'Gastos gestión contra-reembolsos',1,0,0),('6290000013',1,'Arrendamiento Vilassar',1,0,0),('6290000014',1,'Gasto laboral espresas ETT',1,0,0),('6290000015',1,'Gasto compra terminales moviles y similares',1,0,0),('6290000015',3,'Gasto compra terminales moviles y similares',1,0,0),('6290000015',6,'Gasto compra terminales moviles y similares',1,0,0),('6290000016',1,'Gasto gestión cobro ventas',1,0,0),('6290000553',1,'Gastos viaje administrador',1,0,0),('6290000553',4,'Gastos viaje administrador-gerente',1,0,0),('6290000553',6,'Gastos viaje administrador',1,0,0),('6290001000',1,'Gastos de viaje',1,0,0),('6290001000',4,'Gastos viajes otros departamentos',1,0,0),('6290001000',6,'Gastos viaje personal otros departamentos',1,0,0),('6290001001',1,'Gastos R.R.P.P. Gerente',1,0,0),('6290001002',1,'Gastos R.R.P.P. Comerciales',1,0,0),('6290001567',0,'Gastos material oficina',1,0,0),('6300000000',1,'Impuesto de sociedades',1,0,0),('6310000000',1,'Otros tributos',1,0,0),('6380000000',1,'Ajustes positivos s/b Bº',1,0,0),('6400000000',0,'Sueldos y salarios',1,0,0),('6400000000',1,'Salarios',0,0,0),('6400000001',0,'Productividad',1,0,0),('6400000567',0,'Salarios VNH',1,0,0),('6410000001',1,'Indemnizaciones',1,0,0),('6420000000',0,'Seguridad Social a cargo de la empresa',1,0,0),('6420000000',1,'Seguridad Social',0,0,0),('6490000000',1,'Otros gastos sociales',1,0,0),('6500000000',1,'Impagados definitivos',1,0,0),('6620000000',0,'Intereses Bancarios',1,0,0),('6620000001',1,'Intereses deudas a l/p',1,0,0),('6620000006',1,'Intereses deuda prestamo CRA',1,0,0),('6620000007',1,'Intereses La Caixa linea comercio exterior',1,0,0),('6620000007',16,'Intereses La Caixa Linea Comercio Exterior',0,0,0),('6620000008',1,'Intereses Prestamos Transolver 2016',1,0,0),('6620000011',1,'Intereses BBVA linea comercio exterior',1,0,0),('6620000014',1,'Intereses Prestamo BBVA',1,0,0),('6620000015',1,'Interés Póliza Deutsche Bank Comercio Exterior',0,0,0),('6620000023',1,'Intereses Bankinter Póliza Comercio Exterior',0,0,0),('6620002032',1,'Intereses Leaing Iveco',1,0,0),('6620002066',1,'Leasing Intereses Man',1,0,0),('6620002104',1,'Intereses Leasing La caixa 3 vehículos',1,0,0),('6622000000',20,'Intereses deudas otras partes vinculadas',1,0,0),('6660000000',1,'Perdidas en valores representativos de deuda a l/p',0,0,0),('6681000000',1,'Diferencia negativa tipo de cambio',1,0,0),('6681000000',4,'Diferencia negativa tipo de cambio',0,0,0),('6681000000',6,'Diferencia negativa tipo de cambio',1,0,0),('6681000567',0,'Diferencias de cambio VNH',1,0,0),('6690000000',1,'Otros gastos financieros',1,0,0),('6690000000',6,'Gastos financieros',1,0,0),('6720000000',16,'Perdidas procedentes de inversiones',0,0,0),('6780000000',1,'Gastos extraordinarios',1,0,0),('6780000001',1,'Gastos no deducibles',1,0,0),('6780000001',16,'Gasto no deducible',0,0,0),('6800000000',1,'Amortización inmovilizado intangible',1,0,0),('6800000001',0,'Amortizacion inmovilizado material',1,0,0),('6800000001',1,'Amortización del inmovilizado material',1,0,0),('6810000000',0,'Amortizaciones inmovilizado',1,0,0),('6810000000',1,'Amortizacion inmovilizado material',1,0,0),('7000000000',0,'Ventas',1,0,0),('7000000001',1,'Venta entre empresas',1,0,0),('7000010000',0,'Terceros Flor',1,0,0),('7000020000',0,'Terceros Planta',1,0,0),('7000030000',0,'Terceros Complementos',1,0,0),('7000040000',0,'Terceros Artificial',1,0,0),('7000050000',0,'Terceros Verdes',1,0,0),('7000060000',0,'Terceros Otros',1,0,0),('7000070000',0,'Terceros Confección',1,0,0),('7000080000',1,'Terceros Logística',1,0,0),('7001000000',1,'Mercaderia',1,0,1),('7001010000',0,'Grupo Flor',1,0,0),('7001020000',0,'Grupo Planta',1,0,0),('7001030000',0,'Grupo Complementos',1,0,0),('7001040000',0,'Grupo Artificial',1,0,0),('7001050000',0,'Grupo Verdes',1,0,0),('7001060000',0,'Grupo Otros',1,0,0),('7001070000',0,'Grupo Confección',1,0,0),('7001080000',1,'Grupo Logística',1,0,0),('7002010000',0,'Asociados Flor',1,0,0),('7002020000',0,'Asociados Planta',1,0,0),('7002030000',0,'Asociados Complementos',1,0,0),('7002040000',0,'Asociados Artificial',1,0,0),('7002050000',0,'Asociados Verdes',1,0,0),('7002060000',0,'Asociados Otros',1,0,0),('7002070000',0,'Asociados Confección',1,0,0),('7002080000',1,'Asociados Logística',1,0,0),('7040000000',1,'Embalajes',1,0,1),('7050000000',1,'Prestacion de servicios',1,0,1),('7400000000',1,'Subvenciones, donaciones a la explotacion',1,0,0),('7550000000',0,'Ingresos por serivicios al personal',1,0,0),('7620000000',16,'Intereses de créditos a l/p',1,0,0),('768,0',0,NULL,1,0,0),('7680000000',0,'Diferencias positivas de cambio',1,0,0),('7680000000',1,'Diferenica positiva tipo de cambio',1,0,0),('7680000000',4,'Diferenica positiva tipo de cambio',0,0,0),('7680000000',6,'Diferenica positiva tipo de cambio',1,0,0),('7690000000',1,'Otros ingresos financieros',1,0,0),('7710000000',20,'Beneficio procendente vta inm',1,0,0),('7780000000',1,'Ingresos excepcionales',1,0,0),('7780000000',16,'Ingreso extraordinario',0,0,0),('7780000001',1,'Indemnizaciones transporte',1,0,0),('7780000001',4,'Indemnizaciones agencias transporte',1,0,0),('7780000001',5,'Indemnizaciones agencias transporte',1,0,0),('7780000001',6,'Indemnizaciones transporte',1,0,0),('7940000000',1,'Reversión impagos',1,0,0),('7940000000',16,'Reversión impagos',0,0,0); /*!40000 ALTER TABLE `Gastos` ENABLE KEYS */; UNLOCK TABLES; @@ -399,11 +399,11 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-03-01 13:31:24 +-- Dump completed on 2019-03-14 7:15:33 USE `bi`; -- MySQL dump 10.13 Distrib 5.7.21, for osx10.13 (x86_64) -- --- Host: test-db.verdnatura.es Database: bi +-- Host: db.verdnatura.es Database: bi -- ------------------------------------------------------ -- Server version 5.6.25-4-log @@ -447,11 +447,11 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-03-01 13:31:24 +-- Dump completed on 2019-03-14 7:15:33 USE `cache`; -- MySQL dump 10.13 Distrib 5.7.21, for osx10.13 (x86_64) -- --- Host: test-db.verdnatura.es Database: cache +-- Host: db.verdnatura.es Database: cache -- ------------------------------------------------------ -- Server version 5.6.25-4-log @@ -472,7 +472,7 @@ USE `cache`; LOCK TABLES `cache` WRITE; /*!40000 ALTER TABLE `cache` DISABLE KEYS */; -INSERT INTO `cache` VALUES (1,'equalizator','00:15:00'),(2,'available','00:03:00'),(3,'stock','00:30:00'),(4,'last_buy','00:30:00'),(5,'weekly_sales','12:00:00'),(6,'bionic','00:05:00'),(7,'sales','00:03:00'),(8,'visible','00:04:00'),(9,'item_range','00:03:00'),(10,'barcodes','01:00:00'),(11,'prod_graphic','00:15:00'),(12,'ticketShipping','00:01:00'); +INSERT INTO `cache` VALUES (1,'equalizator','00:15:00'),(2,'available','00:01:00'),(3,'stock','00:30:00'),(4,'last_buy','00:30:00'),(5,'weekly_sales','12:00:00'),(6,'bionic','00:05:00'),(7,'sales','00:03:00'),(8,'visible','00:04:00'),(9,'item_range','00:03:00'),(10,'barcodes','01:00:00'),(11,'prod_graphic','00:15:00'),(12,'ticketShipping','00:01:00'); /*!40000 ALTER TABLE `cache` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -485,11 +485,11 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-03-01 13:31:24 +-- Dump completed on 2019-03-14 7:15:33 USE `hedera`; -- MySQL dump 10.13 Distrib 5.7.21, for osx10.13 (x86_64) -- --- Host: test-db.verdnatura.es Database: hedera +-- Host: db.verdnatura.es Database: hedera -- ------------------------------------------------------ -- Server version 5.6.25-4-log @@ -543,11 +543,11 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-03-01 13:31:24 +-- Dump completed on 2019-03-14 7:15:33 USE `postgresql`; -- MySQL dump 10.13 Distrib 5.7.21, for osx10.13 (x86_64) -- --- Host: test-db.verdnatura.es Database: postgresql +-- Host: db.verdnatura.es Database: postgresql -- ------------------------------------------------------ -- Server version 5.6.25-4-log @@ -618,7 +618,7 @@ UNLOCK TABLES; LOCK TABLES `workcenter` WRITE; /*!40000 ALTER TABLE `workcenter` DISABLE KEYS */; -INSERT INTO `workcenter` VALUES (1,'Silla',20,865,1),(2,'Mercaflor',19,NULL,NULL),(3,'Marjales',26,20006,NULL),(4,'VNH',NULL,NULL,3),(5,'Madrid',28,2843,5),(6,'Vilassar',88,88014,2),(7,'Tenerife',NULL,NULL,10),(8,'Silla-Agrario',26,NULL,NULL); +INSERT INTO `workcenter` VALUES (1,'Silla',20,871,1),(2,'Mercaflor',19,NULL,NULL),(3,'Marjales',26,20006,NULL),(4,'VNH',NULL,NULL,3),(5,'Madrid',28,2843,5),(6,'Vilassar',88,88014,2),(7,'Tenerife',NULL,NULL,10),(8,'Silla-Agrario',26,NULL,NULL); /*!40000 ALTER TABLE `workcenter` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -631,4 +631,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-03-01 13:31:24 +-- Dump completed on 2019-03-14 7:15:33 diff --git a/db/install/dump/fixtures.sql b/db/install/dump/fixtures.sql index 3d867bdbe..aba603956 100644 --- a/db/install/dump/fixtures.sql +++ b/db/install/dump/fixtures.sql @@ -6,6 +6,10 @@ ALTER TABLE `vn2008`.`Consignatarios` AUTO_INCREMENT = 1; INSERT INTO `util`.`config` ( `dbVersion`, `hasTriggersDisabled`, `environment`) VALUES ('1.0.0', '0', 'development'); +INSERT INTO `account`.`mailConfig` (`id`, `domain`) + VALUES + ('1', 'verdnatura.es'); + INSERT INTO `account`.`user`(`id`,`name`, `nickname`, `password`,`role`,`active`,`email`) SELECT id, name, CONCAT(name, 'Nick'),MD5('nightmare'), id, 1, CONCAT(name, '@mydomain.com') FROM `account`.`role`; @@ -573,8 +577,9 @@ INSERT INTO `vn`.`expedition`(`id`, `agencyModeFk`, `ticketFk`, `isBox`, `create INSERT INTO `vn`.`packaging`(`id`, `volume`, `width`, `height`, `depth`, `isPackageReturnable`, `created`, `itemFk`, `price`) VALUES - (1, 0.00, 10, 10, 0, 0, CURDATE(), 6, 1.50), - (2, 100.00, 20, 20, 0, 0, CURDATE(), 7, 1.00); + (1, 0.00, 10, 10, 0, 0, CURDATE(), 6, 1.50), + (2, 100.00, 20, 20, 0, 0, CURDATE(), 7, 1.00), + (94, 140875.00, 49.00, 115.00,25.00, 0, CURDATE(), 71, 0.00); INSERT INTO `vn`.`ticketPackaging`(`id`, `ticketFk`, `packagingFk`, `quantity`, `created`, `pvp`) VALUES @@ -590,7 +595,7 @@ INSERT INTO `vn`.`sale`(`id`, `itemFk`, `ticketFk`, `concept`, `quantity`, `pric (4, 4, 1 , 'Object4 Armor2 2', 20, 3.06, 0, 0, 0, DATE_ADD(CURDATE(), INTERVAL -15 DAY)), (5, 1, 2 , 'Object1 Gem1 5', 10, 9.10, 0, 0, 0, DATE_ADD(CURDATE(), INTERVAL -10 DAY)), (6, 1, 3 , 'Object1 Gem1 5', 15, 6.50, 0, 0, 0, DATE_ADD(CURDATE(), INTERVAL -5 DAY)), - (7, 2, 11, 'Object2 Gem2 3', 15, 1.30, 0, 0, 0, CURDATE()), + (7, 2, 11, 'Object2 Gem2 3', 15, 1.46, 0, 0, 0, CURDATE()), (8, 4, 11, 'Object4 Armor2 2', 10, 3.05, 0, 0, 0, CURDATE()), (9, 1, 16, 'Object1 Gem1 5', 5, 9.10, 0, 0, 0, CURDATE()), (10, 2, 16, 'Object2 Gem2 3', 10, 1.07, 0, 0, 0, CURDATE()), @@ -637,12 +642,13 @@ INSERT INTO `vn`.`saleComponent`(`saleFk`, `componentFk`, `value`) (5, 29, -18.72), (5, 39, 0.02), (6, 23, 6.5), - (7, 15, 0.2899), + (7, 15, 0.2839), + (7, 21, 0.166), (7, 28, 5.6), (7, 29, -4.6), (7, 39, 0.01), - (8, 15, 0.0435), - (8, 21, -0.004), + (8, 15, 0.0426), + (8, 21, -0.003), (8, 28, 20.72), (8, 29, -19.72), (8, 37, 2), @@ -1212,5 +1218,3 @@ INSERT INTO `postgresql`.`business_labour`(`business_id`, `notes`, `department_i (1, NULL, 22, 4, 0, 1, 1, 1, 1), (2, 'From las friday worker ownes the company 1 hour', 23, 1, 0, 1, 0, 1, 1); -INSERT INTO `account`.`mailConfig` (`id`, `domain`) VALUES ('1', 'verdnatura.es'); - diff --git a/db/install/dump/structure.sql b/db/install/dump/structure.sql index 70588d75f..bc50a8ce7 100644 --- a/db/install/dump/structure.sql +++ b/db/install/dump/structure.sql @@ -1,6 +1,6 @@ -- MySQL dump 10.13 Distrib 5.7.21, for osx10.13 (x86_64) -- --- Host: test-db.verdnatura.es Database: account +-- Host: db.verdnatura.es Database: account -- ------------------------------------------------------ -- Server version 5.6.25-4-log @@ -95,7 +95,7 @@ CREATE TABLE `accountConfig` ( `warn` smallint(6) NOT NULL, `inact` smallint(6) NOT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters for accounts'; +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters for accounts'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -127,7 +127,7 @@ CREATE TABLE `accountLog` ( `rhost` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `time` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -315,7 +315,7 @@ CREATE TABLE `roleRole` ( `role` int(10) unsigned NOT NULL, `inheritsFrom` int(10) unsigned NOT NULL, UNIQUE KEY `role` (`role`,`inheritsFrom`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Calculated role inheritance'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Calculated role inheritance'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -332,7 +332,7 @@ CREATE TABLE `sambaConfig` ( `sshPass` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The SSH password base64 encoded', `uidBase` int(10) unsigned NOT NULL DEFAULT '10000' COMMENT 'The base for Unix uids', PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters for accounts'; +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters for accounts'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -363,7 +363,7 @@ CREATE TABLE `user` ( KEY `nickname` (`nickname`), KEY `lang` (`lang`), CONSTRAINT `user_ibfk_2` FOREIGN KEY (`role`) REFERENCES `role` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=15285 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global users'; +) ENGINE=InnoDB AUTO_INCREMENT=15389 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global users'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -392,27 +392,26 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `account`.`userBeforeUpdate` - BEFORE UPDATE ON `user` - FOR EACH ROW -BEGIN - IF NOT (NEW.`name` <=> OLD.`name`) THEN - CALL userCheckName (NEW.`name`); - END IF; - - IF NOT (NEW.`password` <=> OLD.`password`) THEN - SET NEW.lastPassChange = NOW(); - END IF; - - IF NEW.`sync` <=> OLD.`sync` THEN - SET NEW.`sync` = FALSE; - END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `userBeforeUpdate` BEFORE UPDATE ON `user` FOR EACH ROW trig: BEGIN + IF NOT (NEW.`name` <=> OLD.`name`) THEN + CALL userCheckName (NEW.`name`); + END IF; + + IF NEW.`sync` <=> OLD.`sync` THEN + SET NEW.`sync` = FALSE; + END IF; + + -- LEAVE trig; + + IF NOT (NEW.`password` <=> OLD.`password`) THEN + SET NEW.lastPassChange = NOW(); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -422,34 +421,43 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `userAfterUpdate` - AFTER UPDATE ON `user` - FOR EACH ROW -BEGIN - IF NOT (NEW.`role` <=> OLD.`role`) - THEN - INSERT INTO vn2008.mail SET - `to` = 'jgallego@verdnatura.es', - `reply_to` = 'jgallego@verdnatura.es', - `subject` = 'Rol modificado', - `text` = CONCAT(account.userGetName(), ' ha modificado el rol del usuario ', - NEW.`name`, ' de ', OLD.role, ' a ', NEW.role); - END IF; - IF NOT (NEW.`active` <=> OLD.`active`) - THEN - INSERT INTO vn2008.mail SET - `to` = 'jgallego@verdnatura.es', - `reply_to` = 'jgallego@verdnatura.es', - `subject` = 'active modificado', - `text` = CONCAT(account.userGetName(), ' ha modificado el active del usuario ', - NEW.`name`, ' de ', OLD.active, ' a ', NEW.active); - END IF; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `userAfterUpdate` AFTER UPDATE ON `user` FOR EACH ROW trig: BEGIN + -- LEAVE trig; + + IF NOT (NEW.`role` <=> OLD.`role`) + THEN + INSERT INTO vn2008.mail SET + `to` = 'jgallego@verdnatura.es', + `reply_to` = 'jgallego@verdnatura.es', + `subject` = 'Rol modificado', + `text` = CONCAT(account.userGetName(), ' ha modificado el rol del usuario ', + NEW.`name`, ' de ', OLD.role, ' a ', NEW.role); + END IF; + IF NOT (NEW.`active` <=> OLD.`active`) + THEN + INSERT INTO vn2008.mail SET + `to` = 'jgallego@verdnatura.es', + `reply_to` = 'jgallego@verdnatura.es', + `subject` = 'active modificado', + `text` = CONCAT(account.userGetName(), ' ha modificado el active del usuario ', + NEW.`name`, ' de ', OLD.active, ' a ', NEW.active); + END IF; + IF NEW.id = 5270 THEN + + INSERT INTO vn2008.mail SET + `to` = 'jgallego@verdnatura.es', + `reply_to` = 'jgallego@verdnatura.es', + `subject` = 'cambiar password', + `text` = CONCAT(account.userGetName(), ' ha modificado el password de ornamentales ', + NEW.`name`, ' de ', OLD.active, ' a ', NEW.active); + CALL util.throw('NO_TIENE_PERMISO_PARA_MODIFICAR_ESTA_CONTRASEÑA'); + END IF; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -468,7 +476,7 @@ CREATE TABLE `userConfig` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `loginKey` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -486,7 +494,7 @@ CREATE TABLE `userPassword` ( `nDigits` tinyint(3) unsigned NOT NULL, `nPunct` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Restrictions on user passwords'; +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Restrictions on user passwords'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2440,7 +2448,7 @@ CREATE TABLE `Agencias` ( PRIMARY KEY (`Id_Agencia`), KEY `Agencias` (`Agencia`), KEY `Vista` (`Vista`) -) ENGINE=InnoDB AUTO_INCREMENT=1221 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1222 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2459,7 +2467,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=34158 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=34723 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2562,7 +2570,6 @@ CREATE TABLE `Articles` ( `compression` decimal(5,2) NOT NULL DEFAULT '1.00' COMMENT 'Relacion de compresividad entre el volumen de las entradas en Silla y el empaquetado en los envios a clientes.\n\nMenor que 1 significa que se puede comprimir más que el volumen original.', `minimum` decimal(10,0) unsigned NOT NULL DEFAULT '3', `upToDown` decimal(10,0) unsigned NOT NULL DEFAULT '0', - `lastPrice` decimal(10,2) DEFAULT '0.00', PRIMARY KEY (`Id_Article`), KEY `Article` (`Article`), KEY `Color` (`Color`), @@ -2572,13 +2579,14 @@ CREATE TABLE `Articles` ( KEY `tipo_id` (`tipo_id`), KEY `producer_id` (`producer_id`), KEY `expenceFk_idx` (`expenceFk`), + KEY `ArticlesIsActive_idx` (`isActive`), CONSTRAINT `Articles_ibfk_1` FOREIGN KEY (`id_origen`) REFERENCES `Origen` (`id`) ON UPDATE CASCADE, CONSTRAINT `Articles_ibfk_2` FOREIGN KEY (`Codintrastat`) REFERENCES `Intrastat` (`Codintrastat`) ON UPDATE CASCADE, CONSTRAINT `Articles_ibfk_4` FOREIGN KEY (`iva_group_id`) REFERENCES `iva_group` (`iva_group_id`) ON UPDATE CASCADE, 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=339584 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=341058 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 */ ; @@ -2760,7 +2768,7 @@ CREATE TABLE `Articles_dits` ( KEY `fgkey1_idx` (`idaccion_dits`), KEY `fgkey2_idx` (`Id_Ticket`), KEY `fgkey3_idx` (`Id_Trabajador`) -) ENGINE=InnoDB AUTO_INCREMENT=21244 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=21375 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2783,7 +2791,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=687346 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=701681 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2798,7 +2806,7 @@ CREATE TABLE `Baldas` ( `Id_Baldas` int(11) NOT NULL, `h` int(11) NOT NULL, PRIMARY KEY (`Id_Estanterias`,`Id_Baldas`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2850,7 +2858,7 @@ CREATE TABLE `Bancos_poliza` ( KEY `Id_Poliza_Empresa_idx` (`empresa_id`), CONSTRAINT `Id_Banco_Poliza` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `Id_Poliza_Empresa` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lineas de credito asociadas a cuentas corrientes'; +) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lineas de credito asociadas a cuentas corrientes'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2869,7 +2877,7 @@ CREATE TABLE `Brasa` ( `Grupo` int(10) unsigned NOT NULL, PRIMARY KEY (`Id_Cliente`), KEY `Index_1` (`Id_Cliente`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -2909,7 +2917,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=664380 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=668132 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 */ ; @@ -3041,7 +3049,7 @@ CREATE TABLE `Clientes` ( 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, CONSTRAINT `typeFk` FOREIGN KEY (`typeFk`) REFERENCES `clientes_tipo` (`code`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=15285 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=15389 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 */ ; @@ -3073,35 +3081,6 @@ BEGIN SET NEW.cuenta = 4300000000 + NEW.Id_Cliente; -END */;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`ClientesAfterInsert` - AFTER INSERT ON `vn2008`.`Clientes` - FOR EACH ROW -BEGIN - INSERT INTO Consignatarios SET - Id_Cliente = NEW.Id_Cliente, - Domicilio = NEW.domicilio, - Poblacion = NEW.POBLACION, - province_id = NEW.province_id, - Codpostal = NEW.CODPOSTAL, - Consignatario = NEW.Cliente, - Predeterminada = TRUE, - Id_Agencia = 2, - isEqualizated = NEW.RE; END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -3179,6 +3158,31 @@ DELIMITER ; /*!50003 SET 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 = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`ClientesAfterUpdate` +AFTER UPDATE ON `Clientes` +FOR EACH ROW +BEGIN + IF NEW.default_address AND (NEW.default_address != OLD.default_address) THEN + UPDATE Consignatarios SET predeterminada = FALSE + WHERE Id_cliente = NEW.Id_cliente; + + + END IF; +END */;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Table structure for table `Clientes_cedidos` @@ -3324,7 +3328,7 @@ CREATE TABLE `Colas` ( CONSTRAINT `Colas_ibfk_3` FOREIGN KEY (`Id_Prioridad`) REFERENCES `Prioridades` (`Id_Prioridad`) ON UPDATE CASCADE, CONSTRAINT `Colas_ibfk_4` FOREIGN KEY (`Id_Impresora`) REFERENCES `Impresoras` (`Id_Impresora`) ON UPDATE CASCADE, CONSTRAINT `Colas_ibfk_5` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=36215 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -3406,7 +3410,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=295179612 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=296969353 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 */ ; @@ -3457,9 +3461,6 @@ bi:BEGIN IF NEW.caja IS NULL THEN SET NEW.caja = IFNULL(vIsBox, NEW.caja); END IF; - - UPDATE vn.item SET isActive = 1 WHERE id = NEW.Id_Article ; - END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -3513,6 +3514,16 @@ ai:BEGIN CALL notify_passport(NEW.Id_Article, NEW.Etiquetas, NEW.Packing,NEW.Id_Compra); CALL insert_producer_plantpassport(NEW.Id_Compra); END IF; + /* + IF (SELECT isFeedStock + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel t ON t.id = e.travelFk + JOIN vn.warehouse w ON w.id = t.warehouseOutFk + WHERE b.id = NEW.Id_Compra) + THEN + UPDATE vn.item i SET i.lastPrice = NEW.Costefijo; + END IF;*/ END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -3582,6 +3593,16 @@ BEGIN CALL notify_passport(NEW.Id_Article, NEW.Etiquetas, NEW.Packing,NEW.Id_Compra); CALL insert_producer_plantpassport(NEW.Id_Compra); END IF; + /* + IF (SELECT isFeedStock + FROM vn.buy b + JOIN vn.entry e ON e.id = b.entryFk + JOIN vn.travel t ON t.id = e.travelFk + JOIN vn.warehouse w ON w.id = t.warehouseOutFk + WHERE b.id = NEW.Id_Compra) + THEN + UPDATE vn.item i SET i.lastPrice = NEW.Costefijo; + END IF;*/ END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -3698,7 +3719,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=26883 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=27038 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 */ ; @@ -3707,36 +3728,25 @@ CREATE TABLE `Consignatarios` ( /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`ConsignatariosBeforeInsert` BEFORE INSERT ON `vn2008`.`Consignatarios` FOR EACH ROW BEGIN - DECLARE v_has_default BOOLEAN; - DECLARE vIsEqualizated BOOLEAN; - + DECLARE vIsEqualizated BOOLEAN; + CALL pbx.phoneIsValid (NEW.telefono); CALL pbx.phoneIsValid (NEW.movil); - - SELECT COUNT(*) > 0 INTO v_has_default - FROM Consignatarios - WHERE Id_Cliente = NEW.Id_Cliente - AND Predeterminada <> FALSE; - - IF NEW.Predeterminada AND v_has_default THEN - SET NEW.Predeterminada = FALSE; - END IF; IF NEW.isEqualizated IS NULL THEN SELECT RE INTO vIsEqualizated - FROM Clientes + FROM Clientes WHERE Id_Cliente = NEW.Id_Cliente; SET NEW.isEqualizated = vIsEqualizated; END IF; - END */;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -3786,37 +3796,11 @@ DELIMITER ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`ConsignatariosAfterUpdate` AFTER UPDATE ON `Consignatarios` FOR EACH ROW BEGIN - DECLARE vCurDefault INT; - DECLARE vNewDefault INT; - - IF NEW.Predeterminada AND (NEW.Predeterminada != OLD.Predeterminada) - THEN - UPDATE Clientes SET default_address = NEW.Id_Consigna - WHERE Id_cliente = NEW.Id_cliente; - END IF; - - IF NOT NEW.active AND (NEW.active != OLD.active) - THEN - SELECT default_address INTO vCurDefault - FROM Clientes - WHERE Id_Cliente = NEW.Id_Cliente; - - IF vCurDefault = NEW.Id_Consigna - THEN - SELECT Id_Consigna INTO vNewDefault - FROM Consignatarios - WHERE Id_Cliente = NEW.Id_Cliente AND active - LIMIT 1; - - UPDATE Clientes SET default_address = vNewDefault - WHERE Id_Cliente = NEW.Id_Cliente; - END IF; - END IF; - + -- Recargos de equivalencia distintos implican facturacion por consignatario IF NEW.isEqualizated != OLD.isEqualizated THEN @@ -3882,7 +3866,7 @@ CREATE TABLE `Contactos` ( PRIMARY KEY (`Id_Contacto`), KEY `Telefono` (`Telefono`), KEY `Movil` (`Movil`) -) ENGINE=InnoDB AUTO_INCREMENT=2688 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2691 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 */ ; @@ -3941,7 +3925,7 @@ CREATE TABLE `Conteo` ( `dispositivo` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, `warehouse_id` int(10) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`Id_Conteo`) -) ENGINE=MyISAM AUTO_INCREMENT=1080422 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1080422 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 */ ; @@ -4079,7 +4063,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=161601 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='InnoDB free: 88064 kB; (`Id_Proveedor`) REFER `vn2008/Provee'; +) ENGINE=InnoDB AUTO_INCREMENT=162630 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 */ ; @@ -4240,7 +4224,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=3365684 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3398496 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4258,7 +4242,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 DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=975 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona las entradas con los origenes de compra'; +) ENGINE=InnoDB AUTO_INCREMENT=1059 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Relaciona las entradas con los origenes de compra'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4323,7 +4307,7 @@ CREATE TABLE `EnvioMasivo` ( `Observaciones` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL, `IdTicket` int(11) NOT NULL, PRIMARY KEY (`Id`) -) ENGINE=MyISAM AUTO_INCREMENT=3373 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Generación de etiquetas a través de Zeleris con los clientes de esta tabla'; +) ENGINE=InnoDB AUTO_INCREMENT=3373 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Generación de etiquetas a través de Zeleris con los clientes de esta tabla'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4365,7 +4349,7 @@ CREATE TABLE `Espionajes` ( `Id_Equipo` int(11) DEFAULT NULL, PRIMARY KEY (`idEspionaje`), KEY `index` (`Id_Trabajador`,`Fecha`) -) ENGINE=MyISAM AUTO_INCREMENT=75648 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=75648 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4395,7 +4379,7 @@ CREATE TABLE `Estanterias` ( `d` int(11) DEFAULT NULL, `modelo` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id_Estanterias`) -) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -4502,7 +4486,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=486361 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=489566 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 */ ; @@ -4681,7 +4665,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=2817960 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=FIXED; +) ENGINE=InnoDB AUTO_INCREMENT=2873515 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 */ ; @@ -4882,7 +4866,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=23749175 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=23876749 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 */ ; @@ -5040,7 +5024,7 @@ CREATE TABLE `Movimientos_mark` ( KEY `Id_Movimiento` (`Id_Movimiento`), KEY `fgnStateFk_idx` (`stateFk`), CONSTRAINT `fgnStateFk` FOREIGN KEY (`stateFk`) REFERENCES `state` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=14754870 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=15044010 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 */ ; @@ -5098,7 +5082,7 @@ CREATE TABLE `Objetivos` ( `Periodo` int(11) NOT NULL, `Objetivo` double NOT NULL, PRIMARY KEY (`Periodo`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5145,7 +5129,7 @@ CREATE TABLE `Ordenes` ( CONSTRAINT `fgnAtender` FOREIGN KEY (`atenderFk`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `fgnRequester` FOREIGN KEY (`requesterFk`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `fgnTicket` FOREIGN KEY (`ticketFk`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=39488 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=39871 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 */ ; @@ -5249,7 +5233,7 @@ CREATE TABLE `Pagares` ( KEY `empresa_id` (`kk_empresa_id`), KEY `pago_id` (`pago_id`), CONSTRAINT `Pagares_ibfk_2` FOREIGN KEY (`pago_id`) REFERENCES `pago` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2862 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2865 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5375,7 +5359,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=2712 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2727 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5401,7 +5385,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=730 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=739 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5426,14 +5410,16 @@ DROP TABLE IF EXISTS `Proveedores_comunicados`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `Proveedores_comunicados` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Id_Proveedor` int(11) NOT NULL, `escrito_id` int(11) NOT NULL, `fecha` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), KEY `Proveedor` (`Id_Proveedor`), KEY `Escrito` (`escrito_id`), CONSTRAINT `Proveedores_comunicados_ibfk_3` FOREIGN KEY (`Id_Proveedor`) REFERENCES `Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `Proveedores_comunicados_ibfk_4` FOREIGN KEY (`escrito_id`) REFERENCES `Proveedores_escritos` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=173 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5492,7 +5478,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=542659 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=546690 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 */ ; @@ -5583,7 +5569,7 @@ CREATE TABLE `Relaciones` ( KEY `Id_Contacto` (`Id_Contacto`), KEY `Id_Proveedor` (`Id_Proveedor`), KEY `Id_Cliente` (`Id_Cliente`) -) ENGINE=InnoDB AUTO_INCREMENT=2687 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2690 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5603,7 +5589,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=1215 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1233 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5628,7 +5614,7 @@ CREATE TABLE `Reservas` ( PRIMARY KEY (`Id_Reserva`), KEY `Id_1` (`Id_Ticket`), KEY `Id_Article` (`Id_Article`) -) ENGINE=InnoDB AUTO_INCREMENT=70 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=374 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5659,7 +5645,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=48347 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=48900 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 */ ; @@ -5812,7 +5798,7 @@ CREATE TABLE `Saldos_Prevision` ( KEY `empresa_prevision_idx` (`empresa_id`), CONSTRAINT `banco_prevision` FOREIGN KEY (`Id_Banco`) REFERENCES `Bancos` (`Id_Banco`) ON UPDATE CASCADE, CONSTRAINT `empresa_prevision` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=163 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Aqui ponemos los gastos e ingresos pendientes de introducir '; +) ENGINE=InnoDB AUTO_INCREMENT=177 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Aqui ponemos los gastos e ingresos pendientes de introducir '; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5847,7 +5833,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=347007 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=348213 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5865,7 +5851,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=36559 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=36573 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5893,7 +5879,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=24024 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=24029 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -5941,9 +5927,9 @@ CREATE TABLE `Tickets` ( KEY `empresa_id` (`empresa_id`), KEY `Id_Agencia` (`Id_Agencia`), KEY `Factura` (`Factura`), - KEY `Fecha` (`Fecha`), KEY `Id_Ruta` (`Id_Ruta`), KEY `warehouse_date` (`warehouse_id`,`Fecha`), + KEY `Fecha` (`Fecha`,`Id_Cliente`), CONSTRAINT `Tickets_ibfk_1` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `Tickets_ibfk_5` FOREIGN KEY (`empresa_id`) REFERENCES `empresa` (`id`) ON UPDATE CASCADE, CONSTRAINT `Tickets_ibfk_6` FOREIGN KEY (`Id_Consigna`) REFERENCES `Consignatarios` (`id_consigna`) ON UPDATE CASCADE, @@ -5951,7 +5937,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=2158859 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2174356 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 */ ; @@ -5962,43 +5948,6 @@ CREATE TABLE `Tickets` ( /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `TicketsBeforeInsert` - BEFORE INSERT ON `Tickets` FOR EACH ROW -BEGIN - - DECLARE strEspecif VARCHAR(255); - DECLARE intId_Agencia INTEGER; - DECLARE auxprovince INTEGER; - DECLARE intemp INTEGER; - - -- Si el cliente es de Canarias se le asigna la empresa ORN - - SELECT province_id INTO auxprovince - FROM Consignatarios WHERE Id_Consigna = NEW.Id_Consigna; - - IF (auxprovince = 49 OR auxprovince = 33) AND NEW.Id_Cliente <> 5270 THEN - SET intemp = 1381; - END IF; - - IF intemp THEN - SET NEW.empresa_id = intemp; - END IF; - -END */;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn2008`.`TicketsAfterInsert` AFTER INSERT ON `vn2008`.`Tickets` FOR EACH ROW BEGIN @@ -6147,7 +6096,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=64394157 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=64430259 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 */ ; @@ -6228,7 +6177,7 @@ CREATE TABLE `Tickets_turno` ( `weekDay` tinyint(1) DEFAULT NULL COMMENT 'funcion de mysql Lunes = 0, Domingo = 6', PRIMARY KEY (`Id_Ticket`), CONSTRAINT `Id_Ticket_fk` FOREIGN KEY (`Id_Ticket`) REFERENCES `Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2156930 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2171535 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6297,7 +6246,7 @@ CREATE TABLE `Tipos` ( CONSTRAINT `Tipos_ibfk_2` FOREIGN KEY (`roleCodeFk`) REFERENCES `account`.`role` (`name`) ON UPDATE CASCADE, CONSTRAINT `Trabajador` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `warehouseFk5` FOREIGN KEY (`warehouseFk`) REFERENCES `warehouse` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=244 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Protege la tabla tipos de updates para los 4 parámetros de los compradores, en funcion del valor del campo CodigoRojo de tblContadores.'; +) ENGINE=InnoDB AUTO_INCREMENT=254 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Protege la tabla tipos de updates para los 4 parámetros de los compradores, en funcion del valor del campo CodigoRojo de tblContadores.'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -6385,7 +6334,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=1254 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1260 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 */ ; @@ -6444,25 +6393,7 @@ CREATE TABLE `Tramos` ( `Tramo` time NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `Tramo` (`Tramo`) -) ENGINE=MyISAM AUTO_INCREMENT=50 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `Ubicator` --- - -DROP TABLE IF EXISTS `Ubicator`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `Ubicator` ( - `Id_Estanterias` int(11) NOT NULL, - `Date` date NOT NULL, - `w` int(11) DEFAULT '0', - `d` int(11) DEFAULT '0', - `h` int(11) DEFAULT '0', - `Id_Cubo` int(11) NOT NULL, - `Id_Article` int(11) NOT NULL -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=50 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -6538,7 +6469,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=10520 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=10653 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 */; -- @@ -6652,7 +6583,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=3669159 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3698447 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 */ ; @@ -6723,6 +6654,84 @@ CREATE TABLE `__Cartera_Ventas` ( ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `__Ubicator` +-- + +DROP TABLE IF EXISTS `__Ubicator`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__Ubicator` ( + `Id_Estanterias` int(11) NOT NULL, + `Date` date NOT NULL, + `w` int(11) DEFAULT '0', + `d` int(11) DEFAULT '0', + `h` int(11) DEFAULT '0', + `Id_Cubo` int(11) NOT NULL, + `Id_Article` int(11) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__daily_task_log` +-- + +DROP TABLE IF EXISTS `__daily_task_log`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__daily_task_log` ( + `consulta` varchar(250) COLLATE utf8_unicode_ci NOT NULL, + `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='@deprecated: 2019-02-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__item_catalog` +-- + +DROP TABLE IF EXISTS `__item_catalog`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__item_catalog` ( + `item_id` int(11) unsigned NOT NULL, + `available` mediumint(9) NOT NULL, + `fixed` tinyint(1) NOT NULL DEFAULT '0', + `price` double DEFAULT NULL, + `s1` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `s2` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, + `discount` tinyint(3) unsigned DEFAULT NULL, + `grouping` decimal(10,0) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__split` +-- + +DROP TABLE IF EXISTS `__split`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__split` ( + `edi_id` int(11) NOT NULL, + `customer_id` int(11) NOT NULL, + `quantity` int(11) NOT NULL, + KEY `edi_id` (`edi_id`,`customer_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__warehouse_tree_bidi` +-- + +DROP TABLE IF EXISTS `__warehouse_tree_bidi`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__warehouse_tree_bidi` ( + `father` tinyint(1) unsigned NOT NULL, + `son` tinyint(1) unsigned NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `accion_dits` -- @@ -6760,7 +6769,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=20237 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=21190 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 */ ; @@ -6927,7 +6936,7 @@ CREATE TABLE `agency_hour` ( CONSTRAINT `agency_hour_ibfk_1` FOREIGN KEY (`agency_id`) REFERENCES `agency` (`agency_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `agency_hour_ibfk_2` FOREIGN KEY (`warehouse_id`) REFERENCES `warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `agency_hour_ibfk_3` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=5290 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=5420 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 */ ; @@ -7093,7 +7102,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=3013 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3047 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7171,7 +7180,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=3030 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3054 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 */ ; @@ -7317,6 +7326,7 @@ DROP TABLE IF EXISTS `awb_component`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `awb_component` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `awb_id` smallint(11) unsigned DEFAULT NULL, `Id_Proveedor` int(11) NOT NULL, `Fecha` date NOT NULL, @@ -7326,6 +7336,7 @@ CREATE TABLE `awb_component` ( `value` decimal(10,2) DEFAULT NULL, `Id_Moneda` tinyint(3) unsigned NOT NULL DEFAULT '2', `recibida_id` mediumint(8) unsigned DEFAULT NULL, + PRIMARY KEY (`id`), UNIQUE KEY `unique_idx` (`awb_id`,`Id_Proveedor`,`awb_component_type_id`,`Fecha`), KEY `Id_Moneda` (`Id_Moneda`), KEY `awb_component_fk` (`awb_component_type_id`), @@ -7335,7 +7346,7 @@ CREATE TABLE `awb_component` ( CONSTRAINT `awb_component_` FOREIGN KEY (`awb_component_type_id`) REFERENCES `awb_component_type` (`awb_component_type_id`) ON UPDATE CASCADE, CONSTRAINT `awb_role_fk` FOREIGN KEY (`awb_role_id`) REFERENCES `awb_role` (`awb_role_id`) ON UPDATE CASCADE, CONSTRAINT `awb_unit_fk` FOREIGN KEY (`awb_unit_id`) REFERENCES `awb_unit` (`awb_unit_id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=17893 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7369,7 +7380,7 @@ CREATE TABLE `awb_component_template` ( CONSTRAINT `Id_Moneda` FOREIGN KEY (`Id_Moneda`) REFERENCES `Monedas` (`Id_Moneda`) ON UPDATE CASCADE, CONSTRAINT `awb_unit_fk1` FOREIGN KEY (`awb_unit_id`) REFERENCES `awb_unit` (`awb_unit_id`) ON UPDATE CASCADE, CONSTRAINT `role_fk` FOREIGN KEY (`awb_role_id`) REFERENCES `awb_role` (`awb_role_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=738 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=740 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7450,7 +7461,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=2662 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2684 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7550,7 +7561,7 @@ CREATE TABLE `balance_nest_tree` ( `Id_Gasto` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `isSelected` tinyint(1) DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=392 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=394 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7569,7 +7580,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=39059 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=39379 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7713,7 +7724,7 @@ CREATE TABLE `buy_edi` ( KEY `barcode` (`barcode`), KEY `fec` (`fec`), KEY `putOrderFk` (`putOrderFk`) -) ENGINE=InnoDB AUTO_INCREMENT=850125 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=859080 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7790,13 +7801,13 @@ CREATE TABLE `call_option` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `callings` +-- Table structure for table `callingskk` -- -DROP TABLE IF EXISTS `callings`; +DROP TABLE IF EXISTS `callingskk`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `callings` ( +CREATE TABLE `callingskk` ( `id` int(11) NOT NULL, `motivo` varchar(105) COLLATE utf8_unicode_ci DEFAULT NULL, `tel1` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, @@ -7946,7 +7957,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=101261 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Acciones en respuesta a las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=102131 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Acciones en respuesta a las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -7980,7 +7991,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=52803 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Causas de las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=53174 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Causas de las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8030,7 +8041,7 @@ CREATE TABLE `cl_det` ( KEY `cl_main_id` (`cl_main_id`), 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=136574 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de las reclamaciones'; +) ENGINE=InnoDB AUTO_INCREMENT=137320 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de las reclamaciones'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -8118,7 +8129,7 @@ CREATE TABLE `cl_main` ( 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, CONSTRAINT `cl_main_ticketFk` FOREIGN KEY (`ticketFk`) REFERENCES `Tickets` (`Id_Ticket`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=59576 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Reclamaciones, tabla principal'; +) ENGINE=InnoDB AUTO_INCREMENT=60053 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Reclamaciones, tabla principal'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8234,7 +8245,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=72248 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; +) ENGINE=InnoDB AUTO_INCREMENT=72778 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8266,7 +8277,7 @@ CREATE TABLE `clientes_regalos_enc` ( `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `Id_Regalo` int(11) NOT NULL, PRIMARY KEY (`Id_Cliente`,`Id_Regalo`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8287,7 +8298,7 @@ CREATE TABLE `clientes_regalos_lista_enc` ( `province_id` smallint(5) unsigned DEFAULT NULL, `countryFk` smallint(5) unsigned DEFAULT NULL, PRIMARY KEY (`Id_Regalo`) -) ENGINE=MyISAM AUTO_INCREMENT=181 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=181 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8319,7 +8330,7 @@ CREATE TABLE `commission` ( `percentage` tinyint(3) unsigned NOT NULL, `value` float unsigned NOT NULL, PRIMARY KEY (`commisision_id`) -) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8337,7 +8348,7 @@ CREATE TABLE `config` ( `lastNicho` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, `lastReserve` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8402,7 +8413,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=3646 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de los consignatarios'; +) ENGINE=InnoDB AUTO_INCREMENT=3693 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Observaciones de los consignatarios'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8484,7 +8495,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=73104 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=73643 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8543,19 +8554,6 @@ CREATE TABLE `cyc_declaration` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Registro de las facturas declaradas a cyc'; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `daily_task_log` --- - -DROP TABLE IF EXISTS `daily_task_log`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `daily_task_log` ( - `consulta` varchar(250) COLLATE utf8_unicode_ci NOT NULL, - `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='No he encontrado el lugar en el que vicente almacena la hora en que se ejecutan las daily tasks, asi que he hecho esta tabla, a eliminar cuando se considere oportuno'; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `definitivo` -- @@ -8570,7 +8568,7 @@ CREATE TABLE `definitivo` ( `hasta` bigint(20) NOT NULL, `fecha` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`definitivo_id`,`empresa_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -8620,7 +8618,7 @@ CREATE TABLE `device` ( PRIMARY KEY (`device_id`), UNIQUE KEY `device_id_UNIQUE` (`device_id`), UNIQUE KEY `sn_UNIQUE` (`sn`) -) ENGINE=InnoDB AUTO_INCREMENT=289 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=292 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9010,7 +9008,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=17011 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=17078 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9040,7 +9038,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=2876446 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2900130 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 */ ; @@ -9284,7 +9282,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=1176798 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='document managment system'; +) ENGINE=InnoDB AUTO_INCREMENT=1187437 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='document managment system'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -9458,7 +9456,7 @@ CREATE TABLE `intervalos` ( `id` int(11) NOT NULL, `hour` time NOT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9483,7 +9481,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=73411 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=73628 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9546,50 +9544,6 @@ SET character_set_client = utf8; 1 AS `priority`*/; SET character_set_client = @saved_cs_client; --- --- Temporary table structure for view `itemTagArranged` --- - -DROP TABLE IF EXISTS `itemTagArranged`; -/*!50001 DROP VIEW IF EXISTS `itemTagArranged`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE VIEW `itemTagArranged` AS SELECT - 1 AS `itemFk`, - 1 AS `tag1`, - 1 AS `val1`, - 1 AS `tag2`, - 1 AS `val2`, - 1 AS `tag3`, - 1 AS `val3`, - 1 AS `tag4`, - 1 AS `val4`, - 1 AS `tag5`, - 1 AS `val5`, - 1 AS `tag6`, - 1 AS `val6`, - 1 AS `description`*/; -SET character_set_client = @saved_cs_client; - --- --- Table structure for table `item_catalog` --- - -DROP TABLE IF EXISTS `item_catalog`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `item_catalog` ( - `item_id` int(11) unsigned NOT NULL, - `available` mediumint(9) NOT NULL, - `fixed` tinyint(1) NOT NULL DEFAULT '0', - `price` double DEFAULT NULL, - `s1` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, - `s2` varchar(5) COLLATE utf8_unicode_ci DEFAULT NULL, - `discount` tinyint(3) unsigned DEFAULT NULL, - `grouping` decimal(10,0) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Temporary table structure for view `item_entry_in` -- @@ -9756,7 +9710,7 @@ CREATE TABLE `language` ( `name` varchar(20) COLLATE utf8_unicode_ci NOT NULL, `active` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`code`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9822,7 +9776,7 @@ CREATE TABLE `mail` ( `recipientFk` int(11) DEFAULT NULL, `plainTextBody` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=1618503 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1635338 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -9880,7 +9834,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=16150 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=16187 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 */ ; @@ -9966,7 +9920,7 @@ DROP TABLE IF EXISTS `nichos`; CREATE TABLE `nichos` ( `id` varchar(5) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10089,7 +10043,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=47163 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=47400 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 */ ; @@ -10216,7 +10170,7 @@ CREATE TABLE `pay_met` ( `graceDays` int(11) unsigned NOT NULL DEFAULT '0', `ibanRequired` tinyint(3) DEFAULT '0', PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10586,7 +10540,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=60631 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=60975 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 */ ; @@ -10648,7 +10602,7 @@ CREATE TABLE `producer` ( `visible` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`producer_id`), UNIQUE KEY `name_UNIQUE` (`name`) -) ENGINE=InnoDB AUTO_INCREMENT=7065 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=7459 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -10817,7 +10771,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=77896 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=78482 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 */ ; @@ -11406,7 +11360,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=121033 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=122522 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11429,7 +11383,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=118410 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=120016 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 */ ; @@ -11586,7 +11540,7 @@ CREATE TABLE `rounding` ( `price` double DEFAULT '0', `discount` double NOT NULL DEFAULT '0', PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11653,7 +11607,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=83737 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Se borra automaticamente 8 dias en el pasado desde vn2008.clean'; +) ENGINE=InnoDB AUTO_INCREMENT=85132 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 */; -- @@ -11693,7 +11647,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=1038812 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1056257 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -11715,7 +11669,7 @@ CREATE TABLE `sharingcart` ( KEY `Suplent` (`Id_Suplente`), CONSTRAINT `Suplent_key` FOREIGN KEY (`Id_Suplente`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE, CONSTRAINT `Trabajador_key` FOREIGN KEY (`Id_Trabajador`) REFERENCES `Trabajadores` (`Id_Trabajador`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1987 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1998 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 */ ; @@ -11858,21 +11812,6 @@ SET character_set_client = utf8; 1 AS `DATE_ODBC`*/; SET character_set_client = @saved_cs_client; --- --- Table structure for table `split` --- - -DROP TABLE IF EXISTS `split`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `split` ( - `edi_id` int(11) NOT NULL, - `customer_id` int(11) NOT NULL, - `quantity` int(11) NOT NULL, - KEY `edi_id` (`edi_id`,`customer_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `state` -- @@ -11892,21 +11831,6 @@ CREATE TABLE `state` ( ) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `subordinate` --- - -DROP TABLE IF EXISTS `subordinate`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `subordinate` ( - `Id_Trabajador` bigint(11) DEFAULT NULL, - `visited` int(1) NOT NULL DEFAULT '0', - `boss` int(1) NOT NULL DEFAULT '0', - KEY `Id_Trabajador` (`Id_Trabajador`) -) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Temporary table structure for view `tag` -- @@ -12025,7 +11949,7 @@ CREATE TABLE `tblContadores` ( `route_option` int(11) DEFAULT '1', `dbproduccion` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -12101,8 +12025,8 @@ CREATE TABLE `template_bionic_lot` ( `available` double DEFAULT NULL, `buy_id` int(11) DEFAULT NULL, `fix` tinyint(3) unsigned DEFAULT '0', - KEY `item_id` (`item_id`), - KEY `item_warehouse` (`item_id`,`warehouse_id`) USING HASH + UNIQUE KEY `warehouse_id` (`warehouse_id`,`item_id`), + KEY `item_id` (`item_id`) ) ENGINE=MEMORY DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; @@ -12120,6 +12044,7 @@ CREATE TABLE `template_bionic_price` ( `items` int(11) DEFAULT NULL, `grouping` int(11) DEFAULT NULL, `price` decimal(10,2) DEFAULT NULL, + UNIQUE KEY `warehouse_id` (`warehouse_id`,`item_id`,`rate`), KEY `item_id` (`item_id`) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; @@ -12186,7 +12111,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=1285707 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; +) ENGINE=InnoDB AUTO_INCREMENT=1296919 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Todas las observaciones referentes a un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -12272,7 +12197,7 @@ DROP TABLE IF EXISTS `transport`; CREATE TABLE `transport` ( `wday` tinyint(4) NOT NULL, PRIMARY KEY (`wday`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -12310,7 +12235,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_cargueras` (`Id_Proveedor`) ON DELETE SET NULL ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=124354 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=125216 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 */ ; @@ -12447,7 +12372,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=207917 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=210074 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -12557,7 +12482,7 @@ CREATE TABLE `turn` ( `number` int(11) NOT NULL, `odbc_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`number`,`odbc_date`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -13586,7 +13511,7 @@ CREATE TABLE `warehouse` ( UNIQUE KEY `name_UNIQUE` (`name`), KEY `Id_Paises` (`Id_Paises`), CONSTRAINT `warehouse_ibfk_1` FOREIGN KEY (`Id_Paises`) REFERENCES `Paises` (`Id`) -) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=58 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 */ ; @@ -13731,19 +13656,6 @@ CREATE TABLE `warehouse_pickup` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `warehouse_tree_bidi` --- - -DROP TABLE IF EXISTS `warehouse_tree_bidi`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `warehouse_tree_bidi` ( - `father` tinyint(1) unsigned NOT NULL, - `son` tinyint(1) unsigned NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `wh_selection` -- @@ -13774,7 +13686,7 @@ CREATE TABLE `widget` ( `chr` int(11) NOT NULL, PRIMARY KEY (`widget_id`), UNIQUE KEY `chr_UNIQUE` (`chr`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -13837,7 +13749,7 @@ CREATE TABLE `workerTeam` ( PRIMARY KEY (`id`), KEY `user_team_idx` (`user`), CONSTRAINT `user_team` FOREIGN KEY (`user`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=201 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=205 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -13937,24 +13849,6 @@ DELIMITER ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; /*!50003 SET character_set_results = @saved_cs_results */ ;; /*!50003 SET collation_connection = @saved_col_connection */ ;; -/*!50106 DROP EVENT IF EXISTS `item_cache_cleaner` */;; -DELIMITER ;; -/*!50003 SET @saved_cs_client = @@character_set_client */ ;; -/*!50003 SET @saved_cs_results = @@character_set_results */ ;; -/*!50003 SET @saved_col_connection = @@collation_connection */ ;; -/*!50003 SET character_set_client = utf8mb4 */ ;; -/*!50003 SET character_set_results = utf8mb4 */ ;; -/*!50003 SET collation_connection = utf8mb4_general_ci */ ;; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ;; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;; -/*!50003 SET @saved_time_zone = @@time_zone */ ;; -/*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `item_cache_cleaner` ON SCHEDULE EVERY 30 SECOND STARTS '2014-06-30 13:38:27' ON COMPLETION NOT PRESERVE DISABLE COMMENT 'Cleans the item cache' DO CALL item_cache_cleaner () */ ;; -/*!50003 SET time_zone = @saved_time_zone */ ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ;; -/*!50003 SET character_set_client = @saved_cs_client */ ;; -/*!50003 SET character_set_results = @saved_cs_results */ ;; -/*!50003 SET collation_connection = @saved_col_connection */ ;; /*!50106 DROP EVENT IF EXISTS `nightlyTaskChecker` */;; DELIMITER ;; /*!50003 SET @saved_cs_client = @@character_set_client */ ;; @@ -13997,6 +13891,24 @@ DELIMITER ;; /*!50003 SET character_set_client = @saved_cs_client */ ;; /*!50003 SET character_set_results = @saved_cs_results */ ;; /*!50003 SET collation_connection = @saved_col_connection */ ;; +/*!50106 DROP EVENT IF EXISTS `__item_cache_cleaner` */;; +DELIMITER ;; +/*!50003 SET @saved_cs_client = @@character_set_client */ ;; +/*!50003 SET @saved_cs_results = @@character_set_results */ ;; +/*!50003 SET @saved_col_connection = @@collation_connection */ ;; +/*!50003 SET character_set_client = utf8mb4 */ ;; +/*!50003 SET character_set_results = utf8mb4 */ ;; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ;; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ;; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;; +/*!50003 SET @saved_time_zone = @@time_zone */ ;; +/*!50003 SET time_zone = 'SYSTEM' */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `__item_cache_cleaner` ON SCHEDULE EVERY 30 SECOND STARTS '2014-06-30 13:38:27' ON COMPLETION NOT PRESERVE DISABLE COMMENT 'Cleans the item cache' DO CALL item_cache_cleaner () */ ;; +/*!50003 SET time_zone = @saved_time_zone */ ;; +/*!50003 SET sql_mode = @saved_sql_mode */ ;; +/*!50003 SET character_set_client = @saved_cs_client */ ;; +/*!50003 SET character_set_results = @saved_cs_results */ ;; +/*!50003 SET collation_connection = @saved_col_connection */ ;; DELIMITER ; /*!50106 SET TIME_ZONE= @save_time_zone */ ; @@ -14929,13 +14841,24 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `getInvoiceWeight`(vInvoice VARCHAR(15)) RETURNS decimal(10,2) BEGIN DECLARE vTotalWeight DECIMAL(10,2); - + /* SELECT SUM(IFNULL(tallos,1) * Cantidad * a.density) sumTotal INTO vTotalWeight FROM Tickets t LEFT JOIN Movimientos m ON m.Id_Ticket = t.Id_Ticket LEFT JOIN Articles a ON a.Id_Article = m.Id_Article - LEFT JOIN Tipos tp ON tp.tipo_id = a.tipo_id + LEFT JOIN bi.rotacion r ON t. WHERE t.Factura = vInvoice AND Codintrastat; + + */ + SELECT SUM(IFNULL(i.stems,1) * s.quantity * i.density * r.cm3) / 1000000 + INTO vTotalWeight + FROM vn.ticket t + JOIN vn.sale s ON s.ticketFk = t.id + JOIN vn.item i ON i.id = s.itemFk + JOIN bi.rotacion r ON r.Id_Article = i.id AND r.warehouse_id = t.warehouseFk + WHERE t.refFk = vInvoice AND i.intrastatFk ; + + RETURN vTotalWeight; END ;; DELIMITER ; @@ -18555,11 +18478,15 @@ CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_component`( proc: BEGIN DECLARE v_customer INT; - DECLARE COEFICIENTE_DE_INFLACION_GENERAL INT DEFAULT 1.3; + DECLARE COEFICIENTE_DE_INFLACION_GENERAL INT DEFAULT 1.0; DECLARE DENSIDAD_MINIMA_PESO_VOLUMETRICO INT DEFAULT 167; - DECLARE VOLUMEN_CAJA_VERDNATURA BIGINT DEFAULT 138000; + DECLARE VOLUMEN_CAJA_VERDNATURA BIGINT; -- DEFAULT 138000; -- DECLARE vValorEmbolsado DOUBLE DEFAULT 0.04; + SELECT Volumen INTO VOLUMEN_CAJA_VERDNATURA + FROM Cubos + WHERE Id_Cubo = '94'; + SELECT Id_Cliente INTO v_customer FROM Consignatarios WHERE Id_Consigna = v_consigna; SET @rate2 := 0; SET @rate3 := 0; @@ -19125,7 +19052,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 `bionic_calc_date` */; +/*!50003 DROP PROCEDURE IF EXISTS `bionic_calc_component_beta` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -19133,9 +19060,308 @@ DELIMITER ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = '' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_date`(v_ticket INT) +CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_component_beta`( + -- DEPRECATED use vn.ticketComponentCalculate + -- v_date DATE, -- fecha de recepcion de mercancia + v_consigna INT, + v_agencia INT) +proc: BEGIN + + DECLARE v_customer INT; + DECLARE COEFICIENTE_DE_INFLACION_GENERAL INT DEFAULT 1.3; + DECLARE DENSIDAD_MINIMA_PESO_VOLUMETRICO INT DEFAULT 167; + DECLARE VOLUMEN_CAJA_VERDNATURA BIGINT; + -- DECLARE vValorEmbolsado DOUBLE DEFAULT 0.04; + + + SELECT Volumen INTO VOLUMEN_CAJA_VERDNATURA + FROM Cubos + WHERE Id_Cubo = 94; + + SELECT Id_Cliente INTO v_customer FROM Consignatarios WHERE Id_Consigna = v_consigna; + SET @rate2 := 0; + SET @rate3 := 0; + + DROP TEMPORARY TABLE IF EXISTS t_bionic_temp; + CREATE TEMPORARY TABLE t_bionic_temp + (PRIMARY KEY (item_id,warehouse_id)) + ENGINE = MEMORY + SELECT + b.item_id, b.warehouse_id,available, + IF((@rate2 := IFNULL(pf.rate_2,c.Tarifa2)) < a.PVP AND a.`Min`, a.PVP, @rate2) * 1.0 rate_2, + IF((@rate3 := IFNULL(pf.rate_3,c.Tarifa3)) < a.PVP AND a.`Min`, a.PVP, @rate3) * 1.0 rate_3, + ifnull(pf.rate_3,0) AS min_price, + IFNULL(pf.Packing,c.Packing) packing, + IFNULL(pf.grouping,c.grouping) grouping, + ABS(IFNULL(pf.caja,c.caja)) box, + b.buy_id, a.tipo_id + FROM tmp.bionic_lot b + JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra + JOIN vn2008.Articles a ON b.item_id = a.Id_Article + JOIN vn2008.Tipos t ON t.tipo_id = a.tipo_id + LEFT JOIN vn2008.reinos r ON r.id = t.reino_id + LEFT JOIN vn2008.PreciosEspeciales p ON a.Id_Article = p.Id_Article AND p.Id_Cliente = v_customer + LEFT JOIN ( + SELECT * FROM ( + SELECT p.item_id, p.grouping, p.Packing,p.caja, p.rate_2, p.rate_3, ah.warehouseFk AS warehouse_id + FROM vn2008.price_fixed p + JOIN tmp.agencyHourGetShipped ah ON ah.warehouseFk = p.warehouse_id OR p.warehouse_id = 0 + WHERE ah.shipped BETWEEN p.date_start AND p.date_end ORDER BY p.item_id, p.warehouse_id DESC + ) t + GROUP BY item_id, warehouse_id + ) pf ON pf.item_id = b.item_id AND pf.warehouse_id = b.warehouse_id + -- descartamos articulos con coste menor de 0.01 + WHERE Costefijo + Portefijo + Embalajefijo + Comisionfija > 0.01 AND r.display <> 0; + + -- Creamos la tabla tmp.bionic_component + DROP TEMPORARY TABLE IF EXISTS tmp.bionic_component; + CREATE TEMPORARY TABLE tmp.bionic_component LIKE + template_bionic_component; + + -- Componentes del precio, valores absolutos + INSERT INTO tmp.bionic_component ( warehouse_id, item_id, component_id, cost) + SELECT b.warehouse_id, b.item_id, 29, rate_3 - Costefijo - Portefijo - Embalajefijo - Comisionfija + FROM t_bionic_temp b + JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra; + + INSERT INTO tmp.bionic_component ( warehouse_id, item_id, component_id, cost) + SELECT b.warehouse_id, b.item_id, 28, Costefijo + Portefijo + Embalajefijo + Comisionfija + FROM t_bionic_temp b + JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra; + + -- Ahora los valores en funcion de la base + + DROP TEMPORARY TABLE IF EXISTS t_components_base; + + CREATE TEMPORARY TABLE t_components_base + SELECT bc.item_id, ROUND(SUM(cost), 4) AS base, bc.warehouse_id + FROM tmp.bionic_component bc + GROUP BY bc.item_id,warehouse_id; + + -- La ratio se calcula teniendo en cuenta el valor de las reclamaciones y el saldo de greuge + + INSERT INTO tmp.bionic_component + SELECT cb.warehouse_id, item_id, 17, ROUND(base * LEAST(recobro,0.25), 3) + FROM t_components_base cb + JOIN bi.claims_ratio ON Id_Cliente = v_customer + WHERE recobro > 0.009; + + -- PAK 2016-08-31 Componente de maná automático, en función del maná acumulado por el comercial. + + INSERT INTO tmp.bionic_component + SELECT cb.warehouse_id, item_id, 39, ROUND(base * (0.01 + prices_modifier_rate), 3) as manaAuto + FROM t_components_base cb + JOIN Clientes c on c.Id_Cliente = v_customer + JOIN bs.mana_spellers ms ON c.Id_Trabajador = ms.Id_Trabajador + WHERE ms.prices_modifier_activated + AND c.Id_Trabajador != 196 -- Ruben Espinosa + HAVING manaAuto <> 0 ; + + +/* + -- Vendedor variable + INSERT INTO tmp.bionic_component + SELECT cb.warehouse_id, item_id, Id_Componente, IFNULL(ROUND(base * tax,4), 0) + FROM t_components_base cb + JOIN bi.tarifa_componentes + WHERE tarifa_componentes_series_id = 2 and IFNULL(tax, 0) > 0; + */ + + +-- ******* Inicio Bloque para componentes con tarifa_class diferente de NULL + -- Descuento por ultimas unidades + INSERT INTO tmp.bionic_component + SELECT cb.warehouse_id, b.item_id, Id_Componente, GREATEST(IFNULL(ROUND(base * tax,4), 0), b.min_price - b.rate_3) + FROM t_components_base cb + JOIN bi.tarifa_componentes + 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; + + -- Incremento por paquete suelto + INSERT INTO tmp.bionic_component + SELECT b.warehouse_id, b.item_id, 22, rate_2 - rate_3 + FROM t_bionic_temp b + JOIN vn2008.Compres c ON b.buy_id = c.Id_Compra + LEFT JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id + WHERE PrecioEspecial IS NULL; + +-- ******* Fin Bloque para componentes con tarifa_class diferente de NULL + + -- Reparto + INSERT INTO tmp.bionic_component + SELECT b.warehouse_id + , b.item_id + , 15 + , COEFICIENTE_DE_INFLACION_GENERAL + * ROUND( + r.cm3 + * art.compression + * IF(a.Vista = 1, (GREATEST(art.density,DENSIDAD_MINIMA_PESO_VOLUMETRICO) / DENSIDAD_MINIMA_PESO_VOLUMETRICO ) , 1) + * IFNULL(az.price + * az.inflacion ,50) + / VOLUMEN_CAJA_VERDNATURA, 4 + ) cost + FROM t_bionic_temp b + JOIN vn2008.Articles art ON art.Id_Article = b.item_id + JOIN vn2008.Agencias a ON a.Id_Agencia = v_agencia + JOIN vn2008.Consignatarios c ON c.Id_Consigna = v_consigna + JOIN vn2008.Agencias_province ap ON ap.agency_id = a.agency_id AND ap.warehouse_id = b.warehouse_id AND ap.province_id = c.province_id + JOIN vn2008.Agencias_zonas az ON az.Id_Agencia = v_agencia AND az.zona = ap.zona AND az.Id_Article = 71 AND az.warehouse_id = b.warehouse_id + LEFT JOIN bi.rotacion r ON r.warehouse_id = b.warehouse_id AND r.Id_Article = b.item_id + HAVING cost <> 0; + +-- Reparto bonificado + INSERT INTO tmp.bionic_component + SELECT b.warehouse_id + , b.item_id + , 41 + , COEFICIENTE_DE_INFLACION_GENERAL + * ROUND( + r.cm3 + * art.compression + * IF(a.Vista = 1, (GREATEST(art.density,DENSIDAD_MINIMA_PESO_VOLUMETRICO) / DENSIDAD_MINIMA_PESO_VOLUMETRICO ) , 1) + * awb.bonus + * az.inflacion + / VOLUMEN_CAJA_VERDNATURA, 4 + ) cost + FROM t_bionic_temp b + JOIN vn2008.Articles art ON art.Id_Article = b.item_id + JOIN vn2008.Agencias a ON a.Id_Agencia = v_agencia + JOIN vn2008.Consignatarios c ON c.Id_Consigna = v_consigna + JOIN vn2008.Agencias_province ap ON ap.agency_id = a.agency_id AND ap.warehouse_id = b.warehouse_id AND ap.province_id = c.province_id + JOIN vn2008.Agencias_zonas az ON az.Id_Agencia = v_agencia AND az.zona = ap.zona AND az.Id_Article = 71 AND az.warehouse_id = b.warehouse_id + JOIN vn2008.agency_weekday_bonus awb ON awb.warehouse_id = az.warehouse_id AND awb.zona = az.zona AND a.agency_id = awb.agency_id + LEFT JOIN bi.rotacion r ON r.warehouse_id = b.warehouse_id AND r.Id_Article = b.item_id + JOIN tmp.agencyHourGetShipped ah ON ah.warehouseFk = awb.warehouse_id AND weekday(ah.landed) = awb.weekDay + HAVING cost <> 0 + LIMIT 1; + +-- PAK 12-05-2015 + -- EMBOLSADO + IF (SELECT COUNT(*) FROM vn.addressForPackaging WHERE addressFk = v_consigna) THEN + + -- IF v_consigna IN (13690, 3402, 5661, 4233) THEN + + INSERT INTO tmp.bionic_component + SELECT b.warehouse_id, b.item_id, 38, ap.packagingValue cost + FROM t_bionic_temp b + JOIN vn.addressForPackaging ap + WHERE ap.addressFk = v_consigna; + + END IF; + + -- JGF 14-08-2015 + -- Modificacion de precio por dia de preparacion del pedido + INSERT INTO tmp.bionic_component + SELECT cb.warehouse_id, cb.item_id, 14, cb.base * (IFNULL(pe.percentage,pp.percentage)/100) + FROM t_components_base cb + JOIN tmp.agencyHourGetShipped ah ON ah.warehouseFk = cb.warehouse_id + LEFT JOIN vn2008.preparation_percentage pp ON pp.week_day = weekday(ah.shipped) AND cb.warehouse_id = IFNULL(pp.warehouse_id,cb.warehouse_id) + LEFT JOIN vn2008.preparation_exception pe ON pe.exception_day = ah.shipped AND cb.warehouse_id = IFNULL(pe.warehouse_id,cb.warehouse_id) + WHERE IFNULL(pe.percentage,pp.percentage); + + -- Creamos la tabla tmp.bionic_component_copy por que mysql no puede reabrir una tabla temporal + DROP TEMPORARY TABLE IF EXISTS tmp.bionic_component_copy; + CREATE TEMPORARY TABLE tmp.bionic_component_copy + SELECT * FROM tmp.bionic_component; + + -- JGF 19-01-2016 + -- Precios especiales + INSERT INTO tmp.bionic_component + SELECT b.warehouse_id, b.item_id, 10, pe.PrecioEspecial - SUM(cost) sum_cost + FROM tmp.bionic_component_copy b + JOIN bi.tarifa_componentes t ON b.component_id = t.Id_Componente + JOIN PreciosEspeciales pe ON pe.Id_Cliente = v_customer AND pe.Id_Article = b.item_id + WHERE t.tarifa_class IS NULL + GROUP BY b.item_id, b.warehouse_id + HAVING ABS(sum_cost) > 0.001; + + -- Lotes + DROP TEMPORARY TABLE IF EXISTS t_component_sum; + CREATE TEMPORARY TABLE t_component_sum + (INDEX (item_id, warehouse_id)) + ENGINE = MEMORY + SELECT SUM(cost) sum_cost, b.item_id, b.warehouse_id, t.tarifa_class + FROM tmp.bionic_component b + JOIN bi.tarifa_componentes t ON b.component_id = t.Id_Componente + GROUP BY b.item_id, b.warehouse_id, t.tarifa_class; + + -- ***** Inicia Modifica t_bionic_rate las diferentes tarifas + -- Tarifa por unidad minima + DROP TEMPORARY TABLE IF EXISTS t_bionic_rate; + CREATE TEMPORARY TABLE t_bionic_rate + ENGINE = MEMORY + SELECT b.warehouse_id, item_id, 1 rate, + IF(box = 1, grouping, 1) grouping, SUM(sum_cost) price + FROM t_bionic_temp b + JOIN t_component_sum cs USING(item_id, warehouse_id) + WHERE IFNULL(cs.tarifa_class,1) = 1 AND box < 2 AND (packing > grouping or box = 0) + GROUP BY warehouse_id, item_id; + + -- Tarifa por caja + INSERT INTO t_bionic_rate (warehouse_id, item_id, rate, grouping, price) + SELECT b.warehouse_id, item_id, 2 rate, packing grouping, + SUM(sum_cost) price + FROM t_bionic_temp b + JOIN t_component_sum cs USING(item_id, warehouse_id) + WHERE available IS NULL OR (IFNULL(cs.tarifa_class,2) = 2 AND packing > 0 AND available >= packing) + GROUP BY warehouse_id, item_id; + + -- Tarifa para toda la cantidad disponible + INSERT INTO t_bionic_rate (warehouse_id, item_id, rate, grouping, price) + SELECT b.warehouse_id, item_id, 3 rate, available grouping, + SUM(sum_cost) price + FROM t_bionic_temp b + JOIN t_component_sum cs USING(item_id, warehouse_id) + WHERE IFNULL(cs.tarifa_class,3) = 3 + GROUP BY warehouse_id, item_id; + + -- ***** Fin Modifica t_bionic_rate las diferentes tarifas + + DROP TEMPORARY TABLE IF EXISTS tmp.bionic_price; + CREATE TEMPORARY TABLE tmp.bionic_price + LIKE template_bionic_price; + + INSERT INTO tmp.bionic_price (warehouse_id, item_id, rate, grouping, price) + SELECT * FROM ( + SELECT * FROM t_bionic_rate ORDER BY price + ) t + GROUP BY item_id, warehouse_id, grouping; + + + DROP TEMPORARY TABLE IF EXISTS tmp.travel_tree; + CREATE TEMPORARY TABLE tmp.travel_tree + ENGINE = MEMORY + SELECT * FROM tmp.agencyHourGetShipped; + + -- Limpieza + + DROP TEMPORARY TABLE tmp.agencyHourGetShipped; + DROP TEMPORARY TABLE t_bionic_temp; + DROP TEMPORARY TABLE t_component_sum; + DROP TEMPORARY TABLE t_components_base; + DROP TEMPORARY TABLE t_bionic_rate; + DROP TEMPORARY TABLE tmp.bionic_component_copy; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `bionic_calc_dateKk` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `bionic_calc_dateKk`(v_ticket INT) proc: BEGIN /** * Este procedimiento asigna la fecha de llegada correcta a un ticket. @@ -21106,97 +21332,10 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_tarifas_entry`(IN idENTRADA INT(11)) +CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_tarifas_entry`(IN entryFk INT(11)) BEGIN DECLARE datINV DATE; - DECLARE wh_id INT; - DECLARE m3i INTEGER; - - - SELECT warehouse_id INTO wh_id - FROM Entradas - JOIN travel ON travel.id = travel_id - WHERE Id_Entrada = idENTRADA; - - CALL buy_tarifas_table(idENTRADA); - - UPDATE Compres C - LEFT JOIN Cubos CB USING(Id_Cubo) - JOIN Articles A USING(Id_Article) - JOIN Entradas E USING(Id_Entrada) - LEFT JOIN vn.duaEntry de on E.Id_Entrada = de.entryFk - LEFT JOIN vn.dua d ON d.id = de.duaFk - LEFT JOIN v_awb_volumen va ON va.awb_id = d.awbFk - JOIN Tipos TP USING(tipo_id) - JOIN travel TR ON TR.id = E.travel_id - JOIN Agencias AG ON TR.agency_id = AG.Id_Agencia - JOIN tblTARIFAS TC - - SET C.Portefijo = @PF:= - IF (va.importe, - - round((va.importe * A.density * CM3_2(C.Id_Cubo, C.Id_Article) / 1000) / (va.Vol_Total * 167 * C.Packing ),3), - - ROUND(IFNULL(((AG.m3 * @cm3:= cm3_2(C.Id_Cubo, C.Id_Article)) / 1000000) / C.Packing,0),3) - ), - - C.Comisionfija = @CF:= ROUND(IFNULL(E.comision * C.Costefijo / 100,0),3), - - C.Embalajefijo = @EF:= IF(CB.Retornable != 0, 0, ROUND(IFNULL( CB.Valor / C.Packing ,0),3)), - - C.Tarifa3 = @t3:= IF(TC.t3 = 0, C.Costefijo,ROUND((C.Costefijo + @CF + @EF + @PF) / ((100 - TC.t3 - TP.promo ) /100) ,2)), -- He añadido que el coste sea igual a tarifa3 si t3 = 0 - - C.Tarifa2 = @t2:= round(@t3 * (1 + ( (TC.t2 - TC.t3)/100)),2), - - C.Tarifa2 = @t2:= IF(@t2 <= @t3, @t3 , @t2) - - WHERE C.Id_Entrada = idENTRADA; - - CASE wh_id - - WHEN 41 THEN -- Canarias - - UPDATE Compres - SET Tarifa2 = Tarifa3 - WHERE Id_Entrada = idENTRADA; - ELSE - - BEGIN - END; - - END CASE; - - -- priceBuilder - call buy_tarifas_priceBuilder_Entry(idENTRADA); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `buy_tarifas_entryTest` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_tarifas_entryTest`(IN entryFk INT(11)) -BEGIN - - DECLARE datINV DATE; - DECLARE wh_id INT; - DECLARE m3i INTEGER; - - - SELECT warehouse_id INTO wh_id - FROM Entradas - JOIN travel ON travel.id = travel_id - WHERE Id_Entrada = entryFk; CALL buy_tarifas_table(entryFk); @@ -21231,23 +21370,102 @@ BEGIN C.Tarifa2 = @t2:= IF(@t2 <= @t3, @t3 , @t2) WHERE C.Id_Entrada = entryFk; + + -- priceBuilder + call buy_tarifas_priceBuilder_Entry(entryFk); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `buy_tarifas_entryKk` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `buy_tarifas_entryKk`(IN idENTRADA INT(11)) +BEGIN + + DECLARE datINV DATE; + DECLARE wh_id INT; + DECLARE m3i INTEGER; + + + SELECT warehouse_id INTO wh_id + FROM Entradas + JOIN travel ON travel.id = travel_id + WHERE Id_Entrada = idENTRADA; + + CALL buy_tarifas_table(idENTRADA); + + SELECT AG.m3 * sum( etiquetas * IFNULL(((AG.m3 * cm3_2(C.Id_Cubo, C.Id_Article)) / 1000000) ,0) ) / + sum(etiquetas * IFNULL(((AG.m3 * ( A.density / 167 ) * cm3_2(C.Id_Cubo, C.Id_Article)) / 1000000) ,0)) INTO m3i + FROM Compres C + JOIN Articles A USING(Id_Article) + JOIN Entradas E USING(Id_Entrada) + JOIN Tipos TP USING(tipo_id) + JOIN travel TR ON TR.id = E.travel_id + JOIN Agencias AG ON TR.agency_id = AG.Id_Agencia + WHERE E.Id_Entrada = idENTRADA; + + + + UPDATE Compres C + LEFT JOIN Cubos CB USING(Id_Cubo) + JOIN Articles A USING(Id_Article) + JOIN Entradas E USING(Id_Entrada) + LEFT JOIN recibida_entrada re on E.Id_Entrada = re.Id_Entrada + LEFT JOIN awb_recibida ar ON re.awb_recibida = ar.recibida_id + LEFT JOIN v_awb_volumen va ON va.awb_id = ar.awb_id + JOIN Tipos TP USING(tipo_id) + JOIN travel TR ON TR.id = E.travel_id + JOIN Agencias AG ON TR.agency_id = AG.Id_Agencia + JOIN tblTARIFAS TC + + SET C.Portefijo = @PF:= + IF (va.importe, + + round((va.importe * A.density * CM3_2(C.Id_Cubo, C.Id_Article) / 1000) / (va.Vol_Total * 167 * C.Packing ),3), + + ROUND(IFNULL(((AG.m3 * @cm3:= cm3_2(C.Id_Cubo, C.Id_Article)) / 1000000) / C.Packing,0),3) + ), + + C.Comisionfija = @CF:= ROUND(IFNULL(E.comision * C.Costefijo / 100,0),3), + + C.Embalajefijo = @EF:= IF(CB.Retornable != 0, 0, ROUND(IFNULL( CB.Valor / C.Packing ,0),3)), + + C.Tarifa3 = @t3:= IF(TC.t3 = 0, C.Costefijo,ROUND((C.Costefijo + @CF + @EF + @PF) / ((100 - TC.t3 - TP.promo ) /100) ,2)), -- He añadido que el coste sea igual a tarifa3 si t3 = 0 + + C.Tarifa2 = @t2:= round(@t3 * (1 + ( (TC.t2 - TC.t3)/100)),2), + + C.Tarifa2 = @t2:= IF(@t2 <= @t3, @t3 , @t2) + + WHERE C.Id_Entrada = idENTRADA ; + CASE wh_id WHEN 41 THEN -- Canarias - UPDATE Compres - SET Tarifa2 = Tarifa3 - WHERE Id_Entrada = entryFk; - ELSE + UPDATE Compres + SET Tarifa2 = Tarifa3 + WHERE Id_Entrada = idENTRADA; + ELSE - BEGIN - END; + BEGIN + END; END CASE; -- priceBuilder - call buy_tarifas_priceBuilder_Entry(entryFk); + call buy_tarifas_priceBuilder_Entry(idENTRADA); + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -21661,8 +21879,6 @@ BEGIN ) sub2 LIMIT 1; - -- pak 22/09/2015 - UPDATE bi.rotacion r JOIN Compres c ON c.Id_Article = r.Id_Article SET cm3 = vn2008.cm3_unidad(c.Id_Compra) @@ -22416,148 +22632,141 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `clean`(IN v_full TINYINT(1)) -BEGIN - DECLARE v_date DATETIME; - 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; - - SET v_date = TIMESTAMPADD(MONTH, -2, CURDATE()); - SET v_date18 = TIMESTAMPADD(MONTH, -18,CURDATE()); - SET v_date3Month = TIMESTAMPADD(MONTH, -3, CURDATE()); - SET v_date8 = TIMESTAMPADD(DAY, -8,CURDATE()); - SET v_date6 = TIMESTAMPADD(DAY, -6,CURDATE()); - SET vRangeDeleteTicket = 60; - INSERT INTO vn2008.daily_task_log(consulta) VALUES('clean START'); - - DELETE FROM cdr WHERE calldate < v_date; - DELETE FROM Monitoring WHERE ODBC_TIME < v_date; - DELETE FROM Conteo WHERE Fecha < v_date; - DELETE FROM XDiario WHERE FECHA < v_date3Month OR FECHA IS NULL; - DELETE FROM mail WHERE DATE_ODBC < v_date; - - - -- DELETE FROM Cajas WHERE CajaFecha < v_date18; - - DELETE rr FROM Recibos_recorded rr JOIN Recibos r ON rr.Id_Recibos = r.Id WHERE r.Fechacobro < v_date; - - SELECT MAX(idTickets_dits) - INTO @id - FROM Tickets_dits - WHERE ODBC_DATE < v_date; - DELETE FROM Tickets_dits WHERE idTickets_dits <= @id; - - DELETE FROM expeditions WHERE odbc_date < v_date18; - DELETE FROM expeditions_deleted WHERE odbc_date < v_date18; - DELETE FROM Entradas_dits WHERE ODBC_DATE < v_date18; - DELETE FROM log_articles WHERE ODBC_DATE < v_date; - DELETE FROM sms WHERE DATE_ODBC < v_date18; - DELETE FROM Movimientos_mark WHERE odbc_date < v_date; - DELETE FROM Splits WHERE Fecha < v_date18; - DELETE ts FROM Tickets_stack ts JOIN Tickets t ON ts.Id_Ticket = t.Id_Ticket WHERE t.Fecha < v_date; - DELETE tobs FROM ticket_observation tobs JOIN Tickets t ON tobs.Id_Ticket = t.Id_Ticket WHERE t.Fecha < v_date; - DELETE tobs FROM movement_label tobs JOIN Movimientos m ON tobs.Id_Movimiento = m.Id_Movimiento - JOIN Tickets t ON m.Id_Ticket = t.Id_Ticket WHERE t.Fecha < v_date; - DELETE FROM chat WHERE odbc_date < v_date; - DELETE FROM Extractos WHERE Fecha < v_date; - DELETE FROM Remesas WHERE `Fecha Remesa` < v_date18; - DELETE FROM sharingcart where datEND < v_date; - DELETE FROM sharingclient where datEND < v_date; - DELETE FROM Stockcontrol WHERE Datestart < v_date18; - -- DELETE FROM reference_rate WHERE date < v_date18; - DELETE tt.* FROM Tickets_turno tt LEFT JOIN Movimientos m using(Id_Ticket) WHERE m.Id_Article IS NULL; - DELETE FROM cl_main WHERE Fecha < v_date18; - DELETE FROM hedera.`order` WHERE date_send < v_date18; - -- DELETE FROM Ordenes WHERE odbc_date < v_date18; JGF 2018-12-21 Si estan en un turno no hay que borrarlas. - - SELECT MAX(inter_id) - INTO @id - FROM vncontrol.inter - WHERE odbc_date < v_date18; - DELETE FROM vncontrol.inter WHERE inter_id <= @id; - - DELETE FROM Entradas_dits WHERE ODBC_DATE < v_date; - DELETE FROM cyc_declaration WHERE Fecha < v_date18; - DELETE FROM vn.message WHERE sendDate < v_date; - DELETE FROM travel_reserve WHERE odbc_date < v_date; - -- DELETE FROM syslog.systemevents WHERE odbc_date < v_date8; - DELETE FROM daily_task_log WHERE odbc_date < v_date; - DELETE mc FROM Movimientos_checked mc JOIN Movimientos m ON mc.Id_Movimiento = m.Id_Movimiento WHERE m.odbc_date < v_date; - DELETE FROM cache.departure_limit WHERE Fecha < TIMESTAMPADD(MONTH,-1,CURDATE()); - DELETE cm - FROM Compres_mark cm - JOIN Compres c ON c.Id_Compra = cm.Id_Compra - JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada - JOIN travel t ON t.id = e.travel_id - WHERE t.landing <= v_date; - DELETE co - FROM Compres_ok co JOIN Compres c ON c.Id_Compra = co.Id_Compra - JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada - JOIN travel t ON t.id = e.travel_id - WHERE t.landing <= v_date; - - DELETE FROM vn2008.scan WHERE odbc_date < v_date6 AND id <> 1; - - SET vDate2000 = TIMESTAMPADD(YEAR, 2000 - YEAR(CURDATE()), CURDATE()); - - IF v_full - THEN - DELETE t FROM Tickets t - LEFT JOIN Tickets_turno tt ON tt.Id_Ticket = t.Id_Ticket - WHERE Fecha NOT IN ('2000-01-01','2000-01-02') - AND YEAR(Fecha) = 2000 - AND ABS(DATEDIFF(Fecha,vDate2000)) > vRangeDeleteTicket - AND tt.Id_Ticket IS NULL; - - DELETE e.* FROM Entradas e - LEFT JOIN recibida_entrada re ON e.Id_Entrada = re.Id_Entrada - WHERE travel_id IS NULL - AND re.Id_Entrada IS NULL; - END IF; - - -- Tickets Nulos PAK 11/10/2016 - - UPDATE vn2008.Tickets - SET empresa_id = 965 - WHERE Id_Cliente = 31 - AND empresa_id != 965; - - -- Equipos duplicados - - DELETE w.* - FROM vn2008.workerTeam w - JOIN (SELECT id, team, user, COUNT(*) - 1 as duplicated - FROM vn.workerTeam - GROUP BY team,user - HAVING duplicated - ) d ON d.team = w.team AND d.user = w.user AND d.id != w.id; - - - - -- CAP 29/10/2018 Mantenimiento tabla Movimientos_componentes - - DELETE mc - FROM vn2008.Movimientos_componentes mc - JOIN vn2008.Movimientos mv - ON mv.Id_Movimiento=mc.Id_Movimiento - JOIN vn2008.Tickets t - ON t.Id_Ticket= mv.Id_Ticket - WHERE t.Fecha 1; + + SET vDate2000 = TIMESTAMPADD(YEAR, 2000 - YEAR(CURDATE()), CURDATE()); + + IF v_full + THEN + DELETE t FROM Tickets t + LEFT JOIN Tickets_turno tt ON tt.Id_Ticket = t.Id_Ticket + WHERE Fecha NOT IN ('2000-01-01','2000-01-02') + AND YEAR(Fecha) = 2000 + AND ABS(DATEDIFF(Fecha,vDate2000)) > vRangeDeleteTicket + AND tt.Id_Ticket IS NULL; + + DELETE e.* FROM Entradas e + LEFT JOIN recibida_entrada re ON e.Id_Entrada = re.Id_Entrada + WHERE travel_id IS NULL + AND re.Id_Entrada IS NULL; + END IF; + + -- Tickets Nulos PAK 11/10/2016 + + UPDATE vn2008.Tickets + SET empresa_id = 965 + WHERE Id_Cliente = 31 + AND empresa_id != 965; + + -- Equipos duplicados + + DELETE w.* + FROM vn2008.workerTeam w + JOIN (SELECT id, team, user, COUNT(*) - 1 as duplicated + FROM vn.workerTeam + GROUP BY team,user + HAVING duplicated + ) d ON d.team = w.team AND d.user = w.user AND d.id != w.id; + + -- CAP 29/10/2018 Mantenimiento tabla Movimientos_componentes + + DELETE mc + FROM vn2008.Movimientos_componentes mc + JOIN vn2008.Movimientos mv + ON mv.Id_Movimiento=mc.Id_Movimiento + JOIN vn2008.Tickets t + ON t.Id_Ticket= mv.Id_Ticket + WHERE t.Fecha 0 - THEN - DELETE a - FROM cache_a a - LEFT JOIN `cache` c ON c.id = a.cache_id - WHERE c.id IS NULL; - END IF; - ELSE - TRUNCATE TABLE `cache`; - END IF; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `item_catalog` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8mb4 */ ; -/*!50003 SET character_set_results = utf8mb4 */ ; -/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `item_catalog`(IN `v_wh` INT, IN `v_date` DATE, IN `v_customer` INT) -BEGIN - DECLARE v_cache SMALLINT; - - CALL item_cache (v_cache, 'a', v_wh, v_date); - - DROP TEMPORARY TABLE IF EXISTS item_catalog; - - CREATE TEMPORARY TABLE item_catalog - (KEY (item_id)) - ENGINE = MEMORY - SELECT - b.item_id - ,b.available - ,b.fixed - ,IFNULL(p.PrecioEspecial,( - CASE c.Descuento - WHEN 0 THEN b.rate_0 - WHEN 1 THEN b.rate_1 - WHEN 2 THEN b.rate_2 - WHEN 3 THEN b.rate_3 - ELSE NULL - END - )) AS price - ,be.S1 s1 - ,be.S2 s2 - ,0 discount - ,CASE co.caja WHEN 0 THEN 1 WHEN 2 THEN co.packing ELSE co.grouping END AS `grouping` - FROM cache_a b - JOIN Clientes c - ON c.Id_cliente = v_customer - JOIN Articles a - ON a.Id_Article = b.item_id - JOIN Tipos t - ON t.tipo_id = a.tipo_id - JOIN reinos r - ON r.id = t.reino_id - JOIN Compres co - ON co.Id_Compra = b.buy_id - LEFT JOIN buy_edi be - ON be.id = co.buy_edi_id - LEFT JOIN PreciosEspeciales p - ON p.Id_Cliente = v_customer AND b.item_id = p.Id_Article - WHERE b.available > 0 AND b.cache_id = v_cache; - -- ON be.compra_id = co.compra_id - -- Cliente Te gustan las flores - - IF NOT v_customer = 3064 - THEN - DELETE c - FROM item_catalog c - JOIN Articles ON item_id = Id_Article - WHERE tipo_id = 105; - END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -31074,98 +31176,6 @@ END WHILE; SELECT CONCAT('*',label,'*') as label, label as id FROM labels; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `nightly_tasks` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `nightly_tasks`() -BEGIN - -DECLARE AUX INT; - -DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - GET DIAGNOSTICS CONDITION 2 @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT; - SELECT CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')); - INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('jgallego@verdnatura.es', 'error nightly tasks' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'))); - INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('pako@verdnatura.es', 'error nightly tasks' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'))); - -END; - - INSERT INTO vn2008.daily_task_log(consulta) VALUES('arranca el event vn2008.nightly_tasks'); - - SELECT SLEEP(1) INTO AUX; - CALL vn2008.emailYesterdayPurchasesLauncher(); - INSERT INTO vn2008.daily_task_log(consulta) VALUES('emailYesterdayPurchasesLauncher END'); - - SELECT SLEEP(1) INTO AUX; - CALL vn2008.inventory_refresh(); - INSERT INTO vn2008.daily_task_log(consulta) VALUES('inventory refresh END'); - - SELECT SLEEP(1) INTO AUX; - CALL bi.last_buy_id_add; - INSERT INTO vn2008.daily_task_log(consulta) VALUES('last buy id END'); - - SELECT SLEEP(1) INTO AUX; - CALL bi.defaulting(curdate()); - INSERT INTO vn2008.daily_task_log(consulta) VALUES('defaulting END'); - - INSERT INTO vn2008.Colas(Id_Informe,Id_Trabajador) VALUES (11,57); - - SELECT SLEEP(1) INTO AUX; - CALL `bi`.`Ultima_Accion`; - INSERT INTO vn2008.daily_task_log(consulta) VALUES('ultima accion END'); - - SELECT SLEEP(1) INTO AUX; - CALL `bi`.`facturacion_media_anual_update`(); - INSERT INTO vn2008.daily_task_log(consulta) VALUES('facturacion media anual END'); - - SELECT SLEEP(1) INTO AUX; - CALL vn2008.Clientes_calidad; - INSERT INTO vn2008.daily_task_log(consulta) VALUES('clientes calidad END'); - - SELECT SLEEP(1) INTO AUX; - CALL bi.rotacion_update; - INSERT INTO vn2008.daily_task_log(consulta) VALUES('rotation update END'); - - SELECT SLEEP(1) INTO AUX; - CALL bi.rutas_m3_add; - INSERT INTO vn2008.daily_task_log(consulta) VALUES('rutas_m3 END'); - - SELECT SLEEP(1) INTO AUX; - CALL vn2008.tarjetas_credito_0; - INSERT INTO vn2008.daily_task_log(consulta) VALUES('tarjetas credito 0 END'); - - SELECT SLEEP(1) INTO AUX; - CALL bi.comparativa_add(); - INSERT INTO vn2008.daily_task_log(consulta) VALUES('comparativa add END'); - - SELECT SLEEP(1) INTO AUX; - call vn2008.recobro_credito(); -- PAK 12/01/2016 - INSERT INTO vn2008.daily_task_log(consulta) VALUES('recobro_credito END'); - - SELECT SLEEP(1) INTO AUX; - CALL vn2008.accumulatorsReadingDateUpdate(); - INSERT INTO vn2008.daily_task_log(consulta) VALUES('accumulatorsReadingDateUpdate END'); - - SELECT SLEEP(1) INTO AUX; - call vn2008.itemTagArrangedUpdate(0); - INSERT INTO vn2008.daily_task_log(consulta) VALUES('itemTagFormatUpdate END'); - - SELECT SLEEP(1) INTO AUX; - INSERT INTO vn2008.daily_task_log(consulta) VALUES('finalitza el event vn2008.nightly_tasks'); - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -33622,499 +33632,226 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `radar`(IN today DATETIME, IN worker INTEGER, IN scopeDays SMALLINT) -BEGIN - - DECLARE todayMidnight DATE DEFAULT TIMESTAMP(today,'23:59:59'); - DECLARE yesterday DATETIME; - DECLARE maxDate DATETIME; - DECLARE datBUF DATETIME; - DECLARE warehouse INTEGER; - DECLARE done BIT DEFAULT 0; - DECLARE visible_calc INTEGER; - DECLARE available_calc INTEGER; - DECLARE dateStart DATE; - - SET dateStart = TIMESTAMPADD(MONTH, -2, CURDATE()); - SELECT TIMESTAMPADD(DAY, -1, today) INTO yesterday; - -- lo quitamos despues de campañaA - SELECT TIMESTAMP(TIMESTAMPADD(DAY, scopeDays, yesterday),'23:59:59') INTO maxDate; - -- SELECT TIMESTAMP(TIMESTAMPADD(DAY, 14, yesterday),'23:59:59') INTO maxDate; - -- Creamos una tabla con los Comerciales de los que se mostraran los tickets - IF worker = 2 and curdate() between '2018-07-02' and '2018-07-09' then - - set worker = 43; - - end if; - - CALL subordinate(worker,TRUE); - - -- 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 - LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket - INNER JOIN Clientes C on C.Id_Cliente = T.Id_Cliente - INNER JOIN subordinate s1 ON C.Id_Trabajador = s1.Id_Trabajador - WHERE Fecha >= yesterday - AND Fecha <= maxDate AND T.Factura Is NULL - AND IFNULL(tls.alertLevel,0) < 3 - - UNION DISTINCT - - SELECT Id_Ticket, s.Id_Cliente, s.Id_Trabajador - FROM sharingclient s - INNER JOIN Tickets T USING(Id_Cliente) - LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket - INNER JOIN subordinate s2 ON s.Id_Trabajador = s2.Id_Trabajador - WHERE maxDate >= datSTART - AND datEND >= yesterday - AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART) - AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND) - AND IFNULL(tls.alertLevel,0) < 3 - - UNION DISTINCT - - SELECT Id_Ticket, C.Id_Cliente, s.Id_Suplente - FROM Clientes C - INNER JOIN Tickets T USING(Id_Cliente) - LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket - INNER JOIN sharingcart s ON s.Id_Trabajador = C.Id_Trabajador - INNER JOIN subordinate su on su.Id_Trabajador=Id_Suplente - WHERE maxDate >= datSTART - AND datEND >= yesterday - AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART) - AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND) - AND IFNULL(tls.alertLevel,0) < 3 - - UNION DISTINCT - - SELECT Id_Ticket, C.Id_Cliente, C.Id_Trabajador - FROM Clientes C - INNER JOIN Tickets T USING(Id_Cliente) - LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket - INNER JOIN workerTeamCollegues w ON w.collegueId = C.Id_Trabajador - WHERE Fecha >= yesterday - AND Fecha <= maxDate AND T.Factura Is NULL - AND IFNULL(tls.alertLevel,0) < 3 - AND w.workerId = worker; - - IF (SELECT COUNT(*) FROM ticketRange) THEN - - -- Generamos varias auxiliares (ya podian los de mysql haber solucionado esto) - - DROP TEMPORARY TABLE IF EXISTS tmp.client_list; - CREATE TEMPORARY TABLE tmp.client_list - (INDEX (Id_Cliente)) - ENGINE = MEMORY - SELECT DISTINCT Id_Cliente FROM ticketRange; - - DROP TEMPORARY TABLE IF EXISTS cr5; - CREATE TEMPORARY TABLE cr5 - (INDEX (Id_Cliente)) - ENGINE = MEMORY - SELECT Id_Cliente FROM tmp.client_list; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - ENGINE = MEMORY - 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 vn.ticketGetTotal(); - - -- Generamos otra tabla temporal con los Tickets_iva - - DROP TEMPORARY TABLE IF EXISTS tt3; - CREATE TEMPORARY TABLE tt3 - ENGINE = MEMORY - SELECT t.ticketFk, tt.total, tr.* - FROM tmp.ticket t - LEFT JOIN tmp.ticketTotal tt ON t.ticketFk = tt.ticketFk - JOIN ticketRange tr ON tr.Id_Ticket = t.ticketFk; - - -- Generamos la lista de tickets y sus datos - - DROP TEMPORARY TABLE IF EXISTS Radartest; - - CREATE TEMPORARY TABLE Radartest - - SELECT IF(C.Id_Trabajador = worker, 1, 0) as Propio, - Credito, - CAST(Riesgo AS DECIMAL (10,2)) Riesgo, - -- Greuge, - T.Id_Ticket, - T.warehouse_id as wh, - T.Fecha, - T.Alias, - -- T.Vista, - REPEAT(' ',50) as problem, - T.Agencia Tipo, - -- C.Id_Trabajador, - T.workerId AS Id_Trabajador, - T.Solucion, - T.Localizacion, - 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 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; - - UPDATE Radartest SET Riesgo = - IF(@cliente <> @cliente:= Id_Cliente , - Importe + @riesgo:= - Riesgo + Importe , - Importe + @riesgo:= @riesgo + Importe) - order by Id_Cliente, Fecha_Simple DESC; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; - - CREATE TEMPORARY TABLE tmp.ticket_list - SELECT Id_Ticket, Id_Cliente FROM Radartest; - - CALL prepare_client_list(); - CALL production_buffer_problems; - - UPDATE Radartest r - JOIN ( - SELECT Id_Ticket, GROUP_CONCAT(problem) problem - FROM tmp.buffer_problems - GROUP BY Id_Ticket - ) p on p.Id_Ticket = r.Id_Ticket - SET r.problem = p.problem; - - - - SELECT R.*, Riesgo + Credito as Risk , CodigoTrabajador - FROM Radartest R - INNER JOIN vn2008.Trabajadores trab on R.Id_Trabajador=trab.Id_Trabajador; - - END IF; - - DROP TEMPORARY TABLE IF EXISTS ticketRange; - 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 ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_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 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!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) -BEGIN - - DECLARE todayMidnight DATE DEFAULT TIMESTAMP(today,'23:59:59'); - DECLARE yesterday DATETIME; - DECLARE maxDate DATETIME; - DECLARE datBUF DATETIME; - DECLARE warehouse INTEGER; - DECLARE done BIT DEFAULT 0; - DECLARE visible_calc INTEGER; - DECLARE available_calc INTEGER; - DECLARE dateStart DATE; - - SET dateStart = TIMESTAMPADD(MONTH, -2, CURDATE()); - SELECT TIMESTAMPADD(DAY, -1, today) INTO yesterday; - -- lo quitamos despues de campañaA - SELECT TIMESTAMP(TIMESTAMPADD(DAY, scopeDays, yesterday),'23:59:59') INTO maxDate; - -- SELECT TIMESTAMP(TIMESTAMPADD(DAY, 14, yesterday),'23:59:59') INTO maxDate; - -- Creamos una tabla con los Comerciales de los que se mostraran los tickets - CALL subordinate(worker,TRUE); - - -- Se genera una tabla con los tickets representados - DROP TEMPORARY TABLE IF EXISTS ticketRange; - CREATE TEMPORARY TABLE ticketRange - SELECT T.Id_Ticket, T.Id_Cliente, C.Id_Trabajador - FROM Tickets T - LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket - INNER JOIN Clientes C on C.Id_Cliente = T.Id_Cliente - INNER JOIN subordinate s1 ON C.Id_Trabajador = s1.Id_Trabajador - WHERE Fecha >= yesterday - AND Fecha <= maxDate AND T.Factura Is NULL - AND IFNULL(tls.alertLevel,0) < 3 - - UNION DISTINCT - - SELECT Id_Ticket, s.Id_Cliente, s.Id_Trabajador - FROM sharingclient s - INNER JOIN Tickets T USING(Id_Cliente) - LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket - INNER JOIN subordinate s2 ON s.Id_Trabajador = s2.Id_Trabajador - WHERE maxDate >= datSTART - AND datEND >= yesterday - AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART) - AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND) - AND IFNULL(tls.alertLevel,0) < 3 - - UNION DISTINCT - - SELECT Id_Ticket, C.Id_Cliente, s.Id_Suplente - FROM Clientes C - INNER JOIN Tickets T USING(Id_Cliente) - LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket - INNER JOIN sharingcart s ON s.Id_Trabajador = C.Id_Trabajador - INNER JOIN subordinate su on su.Id_Trabajador=Id_Suplente - WHERE maxDate >= datSTART - AND datEND >= yesterday - AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART) - AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND) - AND IFNULL(tls.alertLevel,0) < 3 - - UNION DISTINCT - - SELECT Id_Ticket, C.Id_Cliente, C.Id_Trabajador - FROM Clientes C - INNER JOIN Tickets T USING(Id_Cliente) - LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket - INNER JOIN workerTeamCollegues w ON w.collegueId = C.Id_Trabajador - WHERE Fecha >= yesterday - AND Fecha <= maxDate AND T.Factura Is NULL - AND IFNULL(tls.alertLevel,0) < 3 - AND w.workerId = worker; - - IF (SELECT COUNT(*) FROM ticketRange) THEN - - -- Generamos varias auxiliares (ya podian los de mysql haber solucionado esto) - - DROP TEMPORARY TABLE IF EXISTS tmp.client_list; - CREATE TEMPORARY TABLE tmp.client_list - (INDEX (Id_Cliente)) - ENGINE = MEMORY - SELECT DISTINCT Id_Cliente FROM ticketRange; - - DROP TEMPORARY TABLE IF EXISTS cr5; - CREATE TEMPORARY TABLE cr5 - (INDEX (Id_Cliente)) - ENGINE = MEMORY - SELECT Id_Cliente FROM tmp.client_list; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket; - CREATE TEMPORARY TABLE tmp.ticket - ENGINE = MEMORY - 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 vn.ticketGetTotal(); - - -- Generamos otra tabla temporal con los Tickets_iva - - DROP TEMPORARY TABLE IF EXISTS tt3; - CREATE TEMPORARY TABLE tt3 - ENGINE = MEMORY - SELECT t.ticketFk, tt.total, tr.* - FROM tmp.ticket t - LEFT JOIN tmp.ticketTotal tt ON t.ticketFk = tt.ticketFk - JOIN ticketRange tr ON tr.Id_Ticket = t.ticketFk; - - -- Generamos la lista de tickets y sus datos - - DROP TEMPORARY TABLE IF EXISTS Radartest; - - CREATE TEMPORARY TABLE Radartest - - SELECT IF(C.Id_Trabajador = worker, 1, 0) as Propio, - Credito, - CAST(Riesgo AS DECIMAL (10,2)) Riesgo, - -- Greuge, - T.Id_Ticket, - T.warehouse_id as wh, - T.Fecha, - T.Alias, - -- T.Vista, - REPEAT(' ',50) as problem, - T.Agencia Tipo, - -- C.Id_Trabajador, - T.workerId AS Id_Trabajador, - T.Solucion, - T.Localizacion, - 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 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 - ORDER BY C.Id_Cliente; - -- Actualizamos el Riesgo con los tickets futuros - set @cliente:= 0; - SET @riesgo := 0; - - SELECT * FROM Radartest; - - UPDATE Radartest SET Riesgo = - IF(@cliente <> @cliente:= Id_Cliente , - - Importe + @riesgo:= - (Riesgo + Importe), - - Importe + @riesgo := (@riesgo + Importe)), - Propio = @riesgo - order by Id_Cliente, Fecha_Simple DESC; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; - - CREATE TEMPORARY TABLE tmp.ticket_list - SELECT Id_Ticket, Id_Cliente FROM Radartest; - -- select * from Radartest; - - CALL prepare_client_list(); - CALL production_buffer_problems; - - - UPDATE Radartest r - JOIN ( - SELECT Id_Ticket, GROUP_CONCAT(problem) problem - FROM tmp.buffer_problems - GROUP BY Id_Ticket - ) p on p.Id_Ticket = r.Id_Ticket - SET r.problem = p.problem; - - - - SELECT R.*, Riesgo + Credito as Risk , CodigoTrabajador - FROM Radartest R - INNER JOIN vn2008.Trabajadores trab on R.Id_Trabajador=trab.Id_Trabajador; - - END IF; - - DROP TEMPORARY TABLE IF EXISTS ticketRange; - 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; - - +CREATE DEFINER=`root`@`%` PROCEDURE `radar`(IN `today` DATETIME, IN `worker` INT, IN `scopeDays` SMALLINT) + NO SQL +BEGIN + DECLARE todayMidnight DATE DEFAULT TIMESTAMP(today,'23:59:59'); + DECLARE yesterday DATETIME; + DECLARE maxDate DATETIME; + DECLARE datBUF DATETIME; + DECLARE warehouse INTEGER; + DECLARE done BIT DEFAULT 0; + DECLARE visible_calc INTEGER; + DECLARE available_calc INTEGER; + DECLARE dateStart DATE; + + SET dateStart = TIMESTAMPADD(MONTH, -2, CURDATE()); + SELECT TIMESTAMPADD(DAY, -1, today) INTO yesterday; + + -- Lo quitamos despues de campaña + SELECT TIMESTAMP(TIMESTAMPADD(DAY, scopeDays, yesterday),'23:59:59') INTO maxDate; + -- SELECT TIMESTAMP(TIMESTAMPADD(DAY, 14, yesterday),'23:59:59') INTO maxDate; + -- Creamos una tabla con los Comerciales de los que se mostraran los tickets + + IF worker = 2 AND curdate() between '2018-07-02' AND '2018-07-09' THEN + SET worker = 43; + END IF; + + CALL subordinate(worker, TRUE); + + -- Se genera una tabla con los tickets representados + + DROP TEMPORARY TABLE IF EXISTS ticketRange; + CREATE TEMPORARY TABLE ticketRange + (INDEX (Id_Ticket)) + ENGINE = MEMORY + SELECT T.Id_Ticket, T.Id_Cliente, C.Id_Trabajador + FROM Tickets T + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + JOIN Clientes C on C.Id_Cliente = T.Id_Cliente + JOIN subordinate s1 ON C.Id_Trabajador = s1.Id_Trabajador + WHERE Fecha >= yesterday + AND Fecha <= maxDate AND T.Factura Is NULL + AND IFNULL(tls.alertLevel,0) < 3; + + INSERT INTO ticketRange + SELECT Id_Ticket, s.Id_Cliente, s.Id_Trabajador + FROM sharingclient s + JOIN Tickets T USING(Id_Cliente) + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + JOIN subordinate s2 ON s.Id_Trabajador = s2.Id_Trabajador + WHERE maxDate >= datSTART + AND datEND >= yesterday + AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART) + AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND) + AND IFNULL(tls.alertLevel,0) < 3; + + INSERT INTO ticketRange + SELECT Id_Ticket, C.Id_Cliente, s.Id_Suplente + FROM Clientes C + JOIN Tickets T USING(Id_Cliente) + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + JOIN sharingcart s ON s.Id_Trabajador = C.Id_Trabajador + JOIN subordinate su on su.Id_Trabajador = Id_Suplente + WHERE maxDate >= datSTART + AND datEND >= yesterday + AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART) + AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND) + AND IFNULL(tls.alertLevel,0) < 3; + + INSERT INTO ticketRange + SELECT Id_Ticket, C.Id_Cliente, C.Id_Trabajador + FROM Clientes C + JOIN Tickets T USING(Id_Cliente) + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + JOIN workerTeamCollegues w ON w.collegueId = C.Id_Trabajador + WHERE Fecha >= yesterday + AND Fecha <= maxDate AND T.Factura Is NULL + AND IFNULL(tls.alertLevel,0) < 3 + AND w.workerId = worker; + + IF (SELECT COUNT(*) FROM ticketRange) THEN + + -- Generamos varias auxiliares (ya podian los de mysql haber solucionado esto) + + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; + CREATE TEMPORARY TABLE tmp.client_list + (INDEX (Id_Cliente)) + ENGINE = MEMORY + SELECT DISTINCT Id_Cliente FROM ticketRange; + + DROP TEMPORARY TABLE IF EXISTS cr5; + CREATE TEMPORARY TABLE cr5 + (INDEX (Id_Cliente)) + ENGINE = MEMORY + SELECT Id_Cliente FROM tmp.client_list; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + ENGINE = MEMORY + 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 vn.ticketGetTotal; + + -- Generamos otra tabla temporal con los Tickets_iva + + DROP TEMPORARY TABLE IF EXISTS tt3; + CREATE TEMPORARY TABLE tt3 + ENGINE = MEMORY + SELECT t.ticketFk, tt.total, tr.* + FROM tmp.ticket t + LEFT JOIN tmp.ticketTotal tt ON t.ticketFk = tt.ticketFk + JOIN ticketRange tr ON tr.Id_Ticket = t.ticketFk; + + -- Generamos la lista de tickets y sus datos + + DROP TEMPORARY TABLE IF EXISTS Radartest; + CREATE TEMPORARY TABLE Radartest + SELECT IF(C.Id_Trabajador = worker, 1, 0) as Propio, + Credito, + CAST(Riesgo AS DECIMAL (10,2)) Riesgo, + -- Greuge, + T.Id_Ticket, + T.warehouse_id as wh, + T.Fecha, + T.Alias, + -- T.Vista, + REPEAT(' ',50) as problem, + T.Agencia Tipo, + -- C.Id_Trabajador, + T.workerId AS Id_Trabajador, + T.Solucion, + T.Localizacion, + 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 Clientes C + 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 + JOIN tt3 ON tt3.ticketFk = T.Id_Ticket + 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 + JOIN tmp.client_list cl ON cr.customer_id = cl.Id_Cliente + UNION ALL + SELECT t.Id_Cliente, tt.total + FROM tmp.ticketTotal tt + JOIN Tickets t ON t.Id_Ticket = tt.ticketFk + 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; + + UPDATE Radartest + SET Riesgo = IF(@cliente <> @cliente:= Id_Cliente, + -Importe + @riesgo:= - Riesgo + Importe, + -Importe + @riesgo:= @riesgo + Importe + ) + ORDER BY Id_Cliente, Fecha_Simple DESC; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; + + CREATE TEMPORARY TABLE tmp.ticket_list + SELECT Id_Ticket, Id_Cliente FROM Radartest; + + CALL prepare_client_list; + CALL production_buffer_problems; + + UPDATE Radartest r + JOIN ( + SELECT Id_Ticket, GROUP_CONCAT(problem) problem + FROM tmp.buffer_problems + GROUP BY Id_Ticket + ) p on p.Id_Ticket = r.Id_Ticket + SET r.problem = p.problem; + + SELECT R.*, Riesgo + Credito as Risk , CodigoTrabajador + FROM Radartest R + JOIN vn2008.Trabajadores trab on R.Id_Trabajador=trab.Id_Trabajador; + END IF; + + DROP TEMPORARY TABLE ticketRange; + DROP TEMPORARY TABLE subordinate; + DROP TEMPORARY TABLE tmp.client_list; + DROP TEMPORARY TABLE cr5; + DROP TEMPORARY TABLE tmp.ticket; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -35061,49 +34798,42 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `recobro_credito`() -BEGIN - -INSERT INTO vn2008.daily_task_log(consulta) VALUES('recobro_credito'); - -DROP TEMPORARY TABLE IF EXISTS clientes_credit; -CREATE TEMPORARY TABLE clientes_credit -SELECT Id_Cliente, if (Credito > Recobro ,Credito - Recobro,0) as newCredit -from -( -SELECT r.Id_Cliente, r.amount as Recobro, timestampadd(DAY, period, UltimaFecha) as Deadline, sub2.amount as Credito -FROM vn2008.recovery r -join - ( - select Id_Cliente, amount , odbc_date as UltimaFecha - from - ( - select * from credit - order by odbc_date desc - ) sub - group by Id_Cliente - ) sub2 using(Id_Cliente) - -where dend is null or dend >= curdate() -group by Id_Cliente -having Deadline <= curdate() -) sub3 -where Credito > 0; - -UPDATE Clientes - JOIN clientes_credit using(Id_Cliente) - SET Clientes.Credito = newCredit; - -INSERT INTO credit(Id_Cliente, amount, Id_Trabajador) - SELECT Id_Cliente, newCredit, 20 - FROM clientes_credit; - +BEGIN + DROP TEMPORARY TABLE IF EXISTS clientes_credit; + CREATE TEMPORARY TABLE clientes_credit + SELECT Id_Cliente, if (Credito > Recobro ,Credito - Recobro,0) AS newCredit + FROM ( + SELECT r.Id_Cliente, r.amount AS Recobro, + timestampadd(DAY, period, UltimaFecha) AS Deadline, sub2.amount AS Credito + FROM vn2008.recovery r + JOIN ( + SELECT Id_Cliente, amount , odbc_date AS UltimaFecha + FROM ( + SELECT * FROM credit + ORDER BY odbc_date DESC + ) sub + GROUP BY Id_Cliente + ) sub2 USING(Id_Cliente) + WHERE dend IS NULL or dend >= curdate() + GROUP BY Id_Cliente + HAVING Deadline <= curdate() + ) sub3 + WHERE Credito > 0; + + UPDATE Clientes + JOIN clientes_credit USING(Id_Cliente) + SET Clientes.Credito = newCredit; + + INSERT INTO credit(Id_Cliente, amount, Id_Trabajador) + SELECT Id_Cliente, newCredit, 20 + FROM clientes_credit; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -35497,157 +35227,6 @@ JOIN ) t ON t.Id_Ruta = rm.Id_Ruta SET rm.bultos = t.bultos; -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `saldos_bancos` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `saldos_bancos`() -BEGIN - -declare datEND DATE; - -SET datEND = CURDATE() + INTERVAL 2 MONTH; - -drop table if exists bi.saldos_bancos; - - -create table bi.saldos_bancos - - select Semana, Mes, Año, Entrada - , Salida - , @saldo := IF(@banco = Id_Banco and @emp = empresa_id, @saldo,0) + ifnull(Entrada,0)-ifnull(Salida,0) as Saldo - , @banco := Id_Banco as Id_Banco - , @emp := empresa_id as empresa_id - , 'NUL' as Empresa - - from - ( - select * from - ( - select t.week as Semana, t.year as Año, t.month as Mes, b.Id_Banco, sum(Entrada) as Entrada, sum(Salida) as Salida, @banco := 0, @saldo := 0, @emp := 0, e.id as empresa_id - from time t - join Bancos b on b.entity_id = 1 - join empresa e on e.id IN (791,442) - left join - ( - Select Id_Banco, Entrada, Salida, Cajafecha,empresa_id - from Cajas - where Cajafecha >= '2015-01-01' - and Serie = 'MB' - union all - Select Id_Banco, NULL, importe, greatest(fecha,TIMESTAMPADD(DAY,1,CURDATE())),empresa_id - from pago - where conciliado = FALSE /*fecha between CURDATE() and datEND*/ - union all - Select Id_Banco, Entregado, NULL, greatest(Fechacobro,TIMESTAMPADD(DAY,1,CURDATE())),empresa_id - from Recibos - where Fechacobro between CURDATE() and datEND - union all - Select IFNULL(Id_Banco,9999), Importe, NULL, Fecha,empresa_id - from Saldos_Prevision - where Fecha between CURDATE() and datEND - ) sub2 on t.date = sub2.Cajafecha and b.Id_Banco = sub2.Id_Banco and e.id = sub2.empresa_id - - where t.date between '2015-01-01' and datEND - and b.cash != 1 - group by b.Id_Banco, e.id, t.year, t.week - ) sub3 - order by Id_Banco, empresa_id, Año, Mes, Semana - ) sub -; - -update bi.saldos_bancos s -join empresa e on e.id = s.empresa_id -set s.Empresa = abbreviation; - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `saldos_bancos_pordia` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `saldos_bancos_pordia`() -BEGIN - -declare datEND DATE; - -SET datEND = CURDATE() + INTERVAL 2 MONTH; - -drop table if exists bi.saldos_bancos_pordia; - - -create table bi.saldos_bancos_pordia - - select Fecha, Entrada - , Salida - , @saldo := IF(@banco = Id_Banco and @emp = empresa_id, @saldo,0) + ifnull(Entrada,0)-ifnull(Salida,0) as Saldo - , @banco := Id_Banco as Id_Banco - , @emp := empresa_id as empresa_id - , 'NUL' as Empresa - , Año, Mes, Dia - - from - ( - select * from - ( - select t.day as Dia, t.month as Mes,t.year as Año, t.date as Fecha, b.Id_Banco, sum(Entrada) as Entrada, sum(Salida) as Salida, @banco := 0, @saldo := 0, @emp := 0, e.id as empresa_id - from time t - join Bancos b on b.entity_id = 1 - join empresa e on e.id IN (791,442) - left join - ( - Select Id_Banco, Entrada, Salida, Cajafecha,empresa_id - from Cajas - where Cajafecha >= '2015-01-01' - and Serie = 'MB' - union all - Select Id_Banco, NULL, importe, greatest(fecha,TIMESTAMPADD(DAY,1,CURDATE())),empresa_id - from pago - where conciliado = FALSE /*fecha between CURDATE() and datEND*/ - union all - Select Id_Banco, Entregado, NULL, greatest(Fechacobro,TIMESTAMPADD(DAY,1,CURDATE())),empresa_id - from Recibos - where conciliado = FALSE -- Fechacobro between CURDATE() and datEND - union all - Select IFNULL(Id_Banco,9999), Importe, NULL, Fecha,empresa_id - from Saldos_Prevision - where Fecha between CURDATE() and datEND - ) sub2 on t.date = sub2.Cajafecha and b.Id_Banco = sub2.Id_Banco and e.id = sub2.empresa_id - - where t.date between '2015-01-01' and datEND - and b.cash != 1 - group by b.Id_Banco, e.id, t.date - ) sub3 - order by Id_Banco, empresa_id, Fecha - ) sub -; - -update bi.saldos_bancos_pordia s -join empresa e on e.id = s.empresa_id -set s.Empresa = abbreviation; - END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -36529,187 +36108,54 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `subordinate`( IN idWORKER INTEGER,IN CasoBase BOOL) -BEGIN - DECLARE auxWorker INT; - DECLARE vCompanyId INT; - - SELECT empresa_id - INTO vCompanyId - FROM Trabajadores - WHERE Id_Trabajador = idWORKER; - - IF vCompanyId = 1381 THEN -- ORNAMENTALES - - DROP TABLE IF EXISTS subordinate; - CREATE TABLE subordinate - (INDEX (Id_Trabajador)) ENGINE = MEMORY - SELECT Id_Trabajador,TRUE visited,0 boss - FROM Trabajadores - WHERE empresa_id = vCompanyId; - - ELSE - - - /* PAK 23/05/2016 - - Guardia de domingos - - Los domingos viene Fran a hacer de comercial y necesita ver todos los radares - - - - IF dayofweek(curdate()) = 1 and idWORKER = 43 then -- Domingo y Fran Natek - - DROP TABLE IF EXISTS subordinate; - - CREATE TABLE subordinate - (INDEX (Id_Trabajador)) ENGINE = MEMORY - SELECT Id_Trabajador,TRUE visited,0 boss - FROM Trabajadores; - - - else - */ - - IF CasoBase THEN - SET @@max_sp_recursion_depth = 5 ; - DROP TABLE IF EXISTS subordinate; - CREATE TABLE subordinate - (INDEX (Id_Trabajador)) ENGINE = MEMORY - SELECT idWORKER Id_Trabajador,TRUE visited,0 boss; - END IF; - - INSERT INTO subordinate - SELECT Id_Trabajador,0,idWORKER FROM Trabajadores WHERE boss = idWORKER; - IF (SELECT COUNT(*) FROM subordinate WHERE visited = 0 AND idWORKER = boss LIMIT 1) > 0 THEN - SELECT Id_Trabajador into auxWorker FROM subordinate WHERE visited = 0 AND idWORKER = boss LIMIT 1; - REPEAT - CALL subordinate(auxWorker,FALSE); - UPDATE subordinate SET visited = TRUE WHERE Id_Trabajador = auxWorker; - SET auxWorker = 0; - SELECT Id_Trabajador into auxWorker FROM subordinate WHERE visited = 0 AND idWORKER = boss LIMIT 1; - UNTIL auxWorker = 0 - END REPEAT; - END IF; - - /* - end if; - */ - - END IF; - - IF idWorker = 2 THEN - INSERT INTO subordinate(Id_Trabajador,visited,boss) VALUES (2,TRUE,2); - -- INSERT INTO subordinate(Id_Trabajador,visited,boss) VALUES (43,TRUE,2); - END IF; - - /* - IF CasoBase THEN - SELECT * FROM subordinate; - END IF;*/ - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `subordinate2` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `subordinate2`( IN idWORKER INTEGER,IN CasoBase BOOL) -BEGIN - DECLARE auxWorker INT; - DECLARE vCompanyId INT; - - SELECT empresa_id - INTO vCompanyId - FROM Trabajadores - WHERE Id_Trabajador = idWORKER; - - IF vCompanyId = 1381 THEN -- ORNAMENTALES - - DROP TABLE IF EXISTS subordinate; - CREATE TABLE subordinate - (INDEX (Id_Trabajador)) ENGINE = MEMORY - SELECT Id_Trabajador,TRUE visited,0 boss - FROM Trabajadores - WHERE empresa_id = vCompanyId; - - ELSE - - - /* PAK 23/05/2016 - - Guardia de domingos - - Los domingos viene Fran a hacer de comercial y necesita ver todos los radares - - - - IF dayofweek(curdate()) = 1 and idWORKER = 43 then -- Domingo y Fran Natek - - DROP TABLE IF EXISTS subordinate; - - CREATE TABLE subordinate - (INDEX (Id_Trabajador)) ENGINE = MEMORY - SELECT Id_Trabajador,TRUE visited,0 boss - FROM Trabajadores; - - - else - */ - - IF CasoBase THEN - SET @@max_sp_recursion_depth = 5 ; - DROP TABLE IF EXISTS subordinate; - CREATE TABLE subordinate - (INDEX (Id_Trabajador)) ENGINE = MEMORY - SELECT idWORKER Id_Trabajador,TRUE visited,0 boss; - END IF; - - INSERT INTO subordinate - SELECT Id_Trabajador,0,idWORKER FROM Trabajadores WHERE boss = idWORKER; - IF (SELECT COUNT(*) FROM subordinate WHERE visited = 0 AND idWORKER = boss LIMIT 1) > 0 THEN - SELECT Id_Trabajador into auxWorker FROM subordinate WHERE visited = 0 AND idWORKER = boss LIMIT 1; - REPEAT - CALL subordinate(auxWorker,FALSE); - UPDATE subordinate SET visited = TRUE WHERE Id_Trabajador = auxWorker; - SET auxWorker = 0; - SELECT Id_Trabajador into auxWorker FROM subordinate WHERE visited = 0 AND idWORKER = boss LIMIT 1; - UNTIL auxWorker = 0 - END REPEAT; - END IF; - - /* - end if; - */ - - END IF; - - IF idWorker = 2 THEN - INSERT INTO subordinate(Id_Trabajador) VALUES (2); - END IF; - - /* - IF CasoBase THEN - SELECT * FROM subordinate; - END IF;*/ - +CREATE DEFINER=`root`@`%` PROCEDURE `subordinate`(IN `vWorker` INT, IN `vBaseCase` BOOLEAN) + NO SQL +BEGIN + DECLARE vAuxWorker INT; + + IF vBaseCase THEN + SET @@max_sp_recursion_depth = 5 ; + DROP TEMPORARY TABLE IF EXISTS subordinate; + CREATE TEMPORARY TABLE subordinate + (INDEX (Id_Trabajador)) + ENGINE = MEMORY + SELECT vWorker Id_Trabajador, TRUE visited, 0 boss; + END IF; + + INSERT INTO subordinate + SELECT Id_Trabajador, FALSE, vWorker + FROM Trabajadores WHERE boss = vWorker; + + IF (SELECT COUNT(*) FROM subordinate WHERE NOT visited AND vWorker = boss LIMIT 1) > 0 THEN + SELECT Id_Trabajador INTO vAuxWorker + FROM subordinate + WHERE NOT visited AND vWorker = boss LIMIT 1; + + REPEAT + CALL subordinate(vAuxWorker, FALSE); + UPDATE subordinate SET visited = TRUE WHERE Id_Trabajador = vAuxWorker; + SET vAuxWorker = 0; + + SELECT Id_Trabajador INTO vAuxWorker + FROM subordinate + WHERE NOT visited + AND vWorker = boss + LIMIT 1; + + UNTIL vAuxWorker = 0 + END REPEAT; + END IF; + + IF vWorker = 2 THEN + INSERT INTO subordinate + SET Id_Trabajador = vWorker, visited = TRUE, boss = vWorker; + END IF; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -40660,6 +40106,208 @@ GROUP BY ASIEN SET Eurohaber = IF(IFNULL(Eurohaber,0) = 0, Eurohaber, Eurohaber + Quadre), Eurodebe = IF(IFNULL(Eurodebe,0) = 0, Eurodebe, Eurodebe - Quadre); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `__item_cache_cleaner` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `__item_cache_cleaner`() +BEGIN + DECLARE v_lifetime INT DEFAULT 80; + DECLARE v_expired DATETIME DEFAULT TIMESTAMPADD(SECOND, -v_lifetime, NOW()); + + IF (SELECT MAX(id) FROM`cache`) < 32000 + THEN + UPDATE `cache` SET age = age + 1 WHERE stamp < v_expired ORDER BY age DESC; + + DELETE FROM `cache` WHERE stamp < TIMESTAMPADD(SECOND, -40, v_expired); + + IF ROW_COUNT() > 0 + THEN + DELETE a + FROM cache_a a + LEFT JOIN `cache` c ON c.id = a.cache_id + WHERE c.id IS NULL; + END IF; + ELSE + TRUNCATE TABLE `cache`; + END IF; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `__item_catalog` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `__item_catalog`(IN `v_wh` INT, IN `v_date` DATE, IN `v_customer` INT) +BEGIN + DECLARE v_cache SMALLINT; + + CALL item_cache (v_cache, 'a', v_wh, v_date); + + DROP TEMPORARY TABLE IF EXISTS item_catalog; + + CREATE TEMPORARY TABLE item_catalog + (KEY (item_id)) + ENGINE = MEMORY + SELECT + b.item_id + ,b.available + ,b.fixed + ,IFNULL(p.PrecioEspecial,( + CASE c.Descuento + WHEN 0 THEN b.rate_0 + WHEN 1 THEN b.rate_1 + WHEN 2 THEN b.rate_2 + WHEN 3 THEN b.rate_3 + ELSE NULL + END + )) AS price + ,be.S1 s1 + ,be.S2 s2 + ,0 discount + ,CASE co.caja WHEN 0 THEN 1 WHEN 2 THEN co.packing ELSE co.grouping END AS `grouping` + FROM cache_a b + JOIN Clientes c + ON c.Id_cliente = v_customer + JOIN Articles a + ON a.Id_Article = b.item_id + JOIN Tipos t + ON t.tipo_id = a.tipo_id + JOIN reinos r + ON r.id = t.reino_id + JOIN Compres co + ON co.Id_Compra = b.buy_id + LEFT JOIN buy_edi be + ON be.id = co.buy_edi_id + LEFT JOIN PreciosEspeciales p + ON p.Id_Cliente = v_customer AND b.item_id = p.Id_Article + WHERE b.available > 0 AND b.cache_id = v_cache; + -- ON be.compra_id = co.compra_id + -- Cliente Te gustan las flores + + IF NOT v_customer = 3064 + THEN + DELETE c + FROM item_catalog c + JOIN Articles ON item_id = Id_Article + WHERE tipo_id = 105; + END IF; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `__nightly_tasks` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `__nightly_tasks`() +BEGIN +/** + * @deprecated: 2019-02-06 + */ + +DECLARE AUX INT; + +DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + GET DIAGNOSTICS CONDITION 2 @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT; + SELECT CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')); + INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('jgallego@verdnatura.es', 'error nightly tasks' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'))); + INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('pako@verdnatura.es', 'error nightly tasks' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'))); + +END; + + INSERT INTO vn2008.daily_task_log(consulta) VALUES('arranca el event vn2008.nightly_tasks'); + + SELECT SLEEP(1) INTO AUX; + CALL vn2008.emailYesterdayPurchasesLauncher(); + INSERT INTO vn2008.daily_task_log(consulta) VALUES('emailYesterdayPurchasesLauncher END'); + + SELECT SLEEP(1) INTO AUX; + CALL vn2008.inventory_refresh(); + INSERT INTO vn2008.daily_task_log(consulta) VALUES('inventory refresh END'); + + SELECT SLEEP(1) INTO AUX; + CALL bi.last_buy_id_add; + INSERT INTO vn2008.daily_task_log(consulta) VALUES('last buy id END'); + + SELECT SLEEP(1) INTO AUX; + CALL bi.defaulting(curdate()); + INSERT INTO vn2008.daily_task_log(consulta) VALUES('defaulting END'); + + INSERT INTO vn2008.Colas(Id_Informe,Id_Trabajador) VALUES (11,57); + + SELECT SLEEP(1) INTO AUX; + CALL `bi`.`Ultima_Accion`; + INSERT INTO vn2008.daily_task_log(consulta) VALUES('ultima accion END'); + + SELECT SLEEP(1) INTO AUX; + CALL `bi`.`facturacion_media_anual_update`(); + INSERT INTO vn2008.daily_task_log(consulta) VALUES('facturacion media anual END'); + + SELECT SLEEP(1) INTO AUX; + CALL vn2008.Clientes_calidad; + INSERT INTO vn2008.daily_task_log(consulta) VALUES('clientes calidad END'); + + SELECT SLEEP(1) INTO AUX; + CALL bi.rotacion_update; + INSERT INTO vn2008.daily_task_log(consulta) VALUES('rotation update END'); + + SELECT SLEEP(1) INTO AUX; + CALL bi.rutas_m3_add; + INSERT INTO vn2008.daily_task_log(consulta) VALUES('rutas_m3 END'); + + SELECT SLEEP(1) INTO AUX; + CALL vn2008.tarjetas_credito_0; + INSERT INTO vn2008.daily_task_log(consulta) VALUES('tarjetas credito 0 END'); + + SELECT SLEEP(1) INTO AUX; + CALL bi.comparativa_add(); + INSERT INTO vn2008.daily_task_log(consulta) VALUES('comparativa add END'); + + SELECT SLEEP(1) INTO AUX; + call vn2008.recobro_credito(); -- PAK 12/01/2016 + INSERT INTO vn2008.daily_task_log(consulta) VALUES('recobro_credito END'); + + SELECT SLEEP(1) INTO AUX; + CALL vn2008.accumulatorsReadingDateUpdate(); + INSERT INTO vn2008.daily_task_log(consulta) VALUES('accumulatorsReadingDateUpdate END'); + + SELECT SLEEP(1) INTO AUX; + call vn2008.itemTagArrangedUpdate(0); + INSERT INTO vn2008.daily_task_log(consulta) VALUES('itemTagFormatUpdate END'); + + SELECT SLEEP(1) INTO AUX; + INSERT INTO vn2008.daily_task_log(consulta) VALUES('finalitza el event vn2008.nightly_tasks'); + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -40846,6 +40494,851 @@ FROM ) 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 `__radar` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `__radar`(IN `today` DATETIME, IN `worker` INT, IN `scopeDays` SMALLINT) +BEGIN + + DECLARE todayMidnight DATE DEFAULT TIMESTAMP(today,'23:59:59'); + DECLARE yesterday DATETIME; + DECLARE maxDate DATETIME; + DECLARE datBUF DATETIME; + DECLARE warehouse INTEGER; + DECLARE done BIT DEFAULT 0; + DECLARE visible_calc INTEGER; + DECLARE available_calc INTEGER; + DECLARE dateStart DATE; + + SET dateStart = TIMESTAMPADD(MONTH, -2, CURDATE()); + SELECT TIMESTAMPADD(DAY, -1, today) INTO yesterday; + -- lo quitamos despues de campañaA + SELECT TIMESTAMP(TIMESTAMPADD(DAY, scopeDays, yesterday),'23:59:59') INTO maxDate; + -- SELECT TIMESTAMP(TIMESTAMPADD(DAY, 14, yesterday),'23:59:59') INTO maxDate; + -- Creamos una tabla con los Comerciales de los que se mostraran los tickets + IF worker = 2 and curdate() between '2018-07-02' and '2018-07-09' then + + set worker = 43; + + end if; + + CALL subordinate(worker,TRUE); + + -- 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 + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + INNER JOIN Clientes C on C.Id_Cliente = T.Id_Cliente + INNER JOIN subordinate s1 ON C.Id_Trabajador = s1.Id_Trabajador + WHERE Fecha >= yesterday + AND Fecha <= maxDate AND T.Factura Is NULL + AND IFNULL(tls.alertLevel,0) < 3 + + UNION DISTINCT + + SELECT Id_Ticket, s.Id_Cliente, s.Id_Trabajador + FROM sharingclient s + INNER JOIN Tickets T USING(Id_Cliente) + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + INNER JOIN subordinate s2 ON s.Id_Trabajador = s2.Id_Trabajador + WHERE maxDate >= datSTART + AND datEND >= yesterday + AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART) + AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND) + AND IFNULL(tls.alertLevel,0) < 3 + + UNION DISTINCT + + SELECT Id_Ticket, C.Id_Cliente, s.Id_Suplente + FROM Clientes C + INNER JOIN Tickets T USING(Id_Cliente) + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + INNER JOIN sharingcart s ON s.Id_Trabajador = C.Id_Trabajador + INNER JOIN subordinate su on su.Id_Trabajador=Id_Suplente + WHERE maxDate >= datSTART + AND datEND >= yesterday + AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART) + AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND) + AND IFNULL(tls.alertLevel,0) < 3 + + UNION DISTINCT + + SELECT Id_Ticket, C.Id_Cliente, C.Id_Trabajador + FROM Clientes C + INNER JOIN Tickets T USING(Id_Cliente) + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + INNER JOIN workerTeamCollegues w ON w.collegueId = C.Id_Trabajador + WHERE Fecha >= yesterday + AND Fecha <= maxDate AND T.Factura Is NULL + AND IFNULL(tls.alertLevel,0) < 3 + AND w.workerId = worker; + + IF (SELECT COUNT(*) FROM ticketRange) THEN + + -- Generamos varias auxiliares (ya podian los de mysql haber solucionado esto) + + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; + CREATE TEMPORARY TABLE tmp.client_list + (INDEX (Id_Cliente)) + ENGINE = MEMORY + SELECT DISTINCT Id_Cliente FROM ticketRange; + + DROP TEMPORARY TABLE IF EXISTS cr5; + CREATE TEMPORARY TABLE cr5 + (INDEX (Id_Cliente)) + ENGINE = MEMORY + SELECT Id_Cliente FROM tmp.client_list; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + ENGINE = MEMORY + 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 vn.ticketGetTotal(); + + -- Generamos otra tabla temporal con los Tickets_iva + + DROP TEMPORARY TABLE IF EXISTS tt3; + CREATE TEMPORARY TABLE tt3 + ENGINE = MEMORY + SELECT t.ticketFk, tt.total, tr.* + FROM tmp.ticket t + LEFT JOIN tmp.ticketTotal tt ON t.ticketFk = tt.ticketFk + JOIN ticketRange tr ON tr.Id_Ticket = t.ticketFk; + + -- Generamos la lista de tickets y sus datos + + DROP TEMPORARY TABLE IF EXISTS Radartest; + + CREATE TEMPORARY TABLE Radartest + + SELECT IF(C.Id_Trabajador = worker, 1, 0) as Propio, + Credito, + CAST(Riesgo AS DECIMAL (10,2)) Riesgo, + -- Greuge, + T.Id_Ticket, + T.warehouse_id as wh, + T.Fecha, + T.Alias, + -- T.Vista, + REPEAT(' ',50) as problem, + T.Agencia Tipo, + -- C.Id_Trabajador, + T.workerId AS Id_Trabajador, + T.Solucion, + T.Localizacion, + 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 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; + + UPDATE Radartest SET Riesgo = + IF(@cliente <> @cliente:= Id_Cliente , - Importe + @riesgo:= - Riesgo + Importe , - Importe + @riesgo:= @riesgo + Importe) + order by Id_Cliente, Fecha_Simple DESC; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; + + CREATE TEMPORARY TABLE tmp.ticket_list + SELECT Id_Ticket, Id_Cliente FROM Radartest; + + CALL prepare_client_list(); + CALL production_buffer_problems; + + UPDATE Radartest r + JOIN ( + SELECT Id_Ticket, GROUP_CONCAT(problem) problem + FROM tmp.buffer_problems + GROUP BY Id_Ticket + ) p on p.Id_Ticket = r.Id_Ticket + SET r.problem = p.problem; + + + + SELECT R.*, Riesgo + Credito as Risk , CodigoTrabajador + FROM Radartest R + INNER JOIN vn2008.Trabajadores trab on R.Id_Trabajador=trab.Id_Trabajador; + + END IF; + + DROP TEMPORARY TABLE IF EXISTS ticketRange; + 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 ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_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 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `__radarTest`(IN `today` DATETIME, IN `worker` INT, IN `scopeDays` SMALLINT) +BEGIN + + DECLARE todayMidnight DATE DEFAULT TIMESTAMP(today,'23:59:59'); + DECLARE yesterday DATETIME; + DECLARE maxDate DATETIME; + DECLARE datBUF DATETIME; + DECLARE warehouse INTEGER; + DECLARE done BIT DEFAULT 0; + DECLARE visible_calc INTEGER; + DECLARE available_calc INTEGER; + DECLARE dateStart DATE; + + SET dateStart = TIMESTAMPADD(MONTH, -2, CURDATE()); + SELECT TIMESTAMPADD(DAY, -1, today) INTO yesterday; + -- lo quitamos despues de campañaA + SELECT TIMESTAMP(TIMESTAMPADD(DAY, scopeDays, yesterday),'23:59:59') INTO maxDate; + -- SELECT TIMESTAMP(TIMESTAMPADD(DAY, 14, yesterday),'23:59:59') INTO maxDate; + -- Creamos una tabla con los Comerciales de los que se mostraran los tickets + CALL subordinate(worker,TRUE); + + -- Se genera una tabla con los tickets representados + DROP TEMPORARY TABLE IF EXISTS ticketRange; + CREATE TEMPORARY TABLE ticketRange + SELECT T.Id_Ticket, T.Id_Cliente, C.Id_Trabajador + FROM Tickets T + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + INNER JOIN Clientes C on C.Id_Cliente = T.Id_Cliente + INNER JOIN subordinate s1 ON C.Id_Trabajador = s1.Id_Trabajador + WHERE Fecha >= yesterday + AND Fecha <= maxDate AND T.Factura Is NULL + AND IFNULL(tls.alertLevel,0) < 3 + + UNION DISTINCT + + SELECT Id_Ticket, s.Id_Cliente, s.Id_Trabajador + FROM sharingclient s + INNER JOIN Tickets T USING(Id_Cliente) + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + INNER JOIN subordinate s2 ON s.Id_Trabajador = s2.Id_Trabajador + WHERE maxDate >= datSTART + AND datEND >= yesterday + AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART) + AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND) + AND IFNULL(tls.alertLevel,0) < 3 + + UNION DISTINCT + + SELECT Id_Ticket, C.Id_Cliente, s.Id_Suplente + FROM Clientes C + INNER JOIN Tickets T USING(Id_Cliente) + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + INNER JOIN sharingcart s ON s.Id_Trabajador = C.Id_Trabajador + INNER JOIN subordinate su on su.Id_Trabajador=Id_Suplente + WHERE maxDate >= datSTART + AND datEND >= yesterday + AND date(Fecha) >= IF(yesterday > datSTART, yesterday, datSTART) + AND date(Fecha) <= IF(datEND > maxDate, maxDate, datEND) + AND IFNULL(tls.alertLevel,0) < 3 + + UNION DISTINCT + + SELECT Id_Ticket, C.Id_Cliente, C.Id_Trabajador + FROM Clientes C + INNER JOIN Tickets T USING(Id_Cliente) + LEFT JOIN vn.ticketState tls on tls.ticket = T.Id_Ticket + INNER JOIN workerTeamCollegues w ON w.collegueId = C.Id_Trabajador + WHERE Fecha >= yesterday + AND Fecha <= maxDate AND T.Factura Is NULL + AND IFNULL(tls.alertLevel,0) < 3 + AND w.workerId = worker; + + IF (SELECT COUNT(*) FROM ticketRange) THEN + + -- Generamos varias auxiliares (ya podian los de mysql haber solucionado esto) + + DROP TEMPORARY TABLE IF EXISTS tmp.client_list; + CREATE TEMPORARY TABLE tmp.client_list + (INDEX (Id_Cliente)) + ENGINE = MEMORY + SELECT DISTINCT Id_Cliente FROM ticketRange; + + DROP TEMPORARY TABLE IF EXISTS cr5; + CREATE TEMPORARY TABLE cr5 + (INDEX (Id_Cliente)) + ENGINE = MEMORY + SELECT Id_Cliente FROM tmp.client_list; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket; + CREATE TEMPORARY TABLE tmp.ticket + ENGINE = MEMORY + 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 vn.ticketGetTotal(); + + -- Generamos otra tabla temporal con los Tickets_iva + + DROP TEMPORARY TABLE IF EXISTS tt3; + CREATE TEMPORARY TABLE tt3 + ENGINE = MEMORY + SELECT t.ticketFk, tt.total, tr.* + FROM tmp.ticket t + LEFT JOIN tmp.ticketTotal tt ON t.ticketFk = tt.ticketFk + JOIN ticketRange tr ON tr.Id_Ticket = t.ticketFk; + + -- Generamos la lista de tickets y sus datos + + DROP TEMPORARY TABLE IF EXISTS Radartest; + + CREATE TEMPORARY TABLE Radartest + + SELECT IF(C.Id_Trabajador = worker, 1, 0) as Propio, + Credito, + CAST(Riesgo AS DECIMAL (10,2)) Riesgo, + -- Greuge, + T.Id_Ticket, + T.warehouse_id as wh, + T.Fecha, + T.Alias, + -- T.Vista, + REPEAT(' ',50) as problem, + T.Agencia Tipo, + -- C.Id_Trabajador, + T.workerId AS Id_Trabajador, + T.Solucion, + T.Localizacion, + 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 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 + ORDER BY C.Id_Cliente; + -- Actualizamos el Riesgo con los tickets futuros + set @cliente:= 0; + SET @riesgo := 0; + + SELECT * FROM Radartest; + + UPDATE Radartest SET Riesgo = + IF(@cliente <> @cliente:= Id_Cliente , + - Importe + @riesgo:= - (Riesgo + Importe), + - Importe + @riesgo := (@riesgo + Importe)), + Propio = @riesgo + order by Id_Cliente, Fecha_Simple DESC; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; + + CREATE TEMPORARY TABLE tmp.ticket_list + SELECT Id_Ticket, Id_Cliente FROM Radartest; + -- select * from Radartest; + + CALL prepare_client_list(); + CALL production_buffer_problems; + + + UPDATE Radartest r + JOIN ( + SELECT Id_Ticket, GROUP_CONCAT(problem) problem + FROM tmp.buffer_problems + GROUP BY Id_Ticket + ) p on p.Id_Ticket = r.Id_Ticket + SET r.problem = p.problem; + + + + SELECT R.*, Riesgo + Credito as Risk , CodigoTrabajador + FROM Radartest R + INNER JOIN vn2008.Trabajadores trab on R.Id_Trabajador=trab.Id_Trabajador; + + END IF; + + DROP TEMPORARY TABLE IF EXISTS ticketRange; + 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 ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `__saldos_bancos` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `__saldos_bancos`() +BEGIN + +declare datEND DATE; + +SET datEND = CURDATE() + INTERVAL 2 MONTH; + +drop table if exists bi.saldos_bancos; + + +create table bi.saldos_bancos + + select Semana, Mes, Año, Entrada + , Salida + , @saldo := IF(@banco = Id_Banco and @emp = empresa_id, @saldo,0) + ifnull(Entrada,0)-ifnull(Salida,0) as Saldo + , @banco := Id_Banco as Id_Banco + , @emp := empresa_id as empresa_id + , 'NUL' as Empresa + + from + ( + select * from + ( + select t.week as Semana, t.year as Año, t.month as Mes, b.Id_Banco, sum(Entrada) as Entrada, sum(Salida) as Salida, @banco := 0, @saldo := 0, @emp := 0, e.id as empresa_id + from time t + join Bancos b on b.entity_id = 1 + join empresa e on e.id IN (791,442) + left join + ( + Select Id_Banco, Entrada, Salida, Cajafecha,empresa_id + from Cajas + where Cajafecha >= '2015-01-01' + and Serie = 'MB' + union all + Select Id_Banco, NULL, importe, greatest(fecha,TIMESTAMPADD(DAY,1,CURDATE())),empresa_id + from pago + where conciliado = FALSE /*fecha between CURDATE() and datEND*/ + union all + Select Id_Banco, Entregado, NULL, greatest(Fechacobro,TIMESTAMPADD(DAY,1,CURDATE())),empresa_id + from Recibos + where Fechacobro between CURDATE() and datEND + union all + Select IFNULL(Id_Banco,9999), Importe, NULL, Fecha,empresa_id + from Saldos_Prevision + where Fecha between CURDATE() and datEND + ) sub2 on t.date = sub2.Cajafecha and b.Id_Banco = sub2.Id_Banco and e.id = sub2.empresa_id + + where t.date between '2015-01-01' and datEND + and b.cash != 1 + group by b.Id_Banco, e.id, t.year, t.week + ) sub3 + order by Id_Banco, empresa_id, Año, Mes, Semana + ) sub +; + +update bi.saldos_bancos s +join empresa e on e.id = s.empresa_id +set s.Empresa = abbreviation; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `__saldos_bancos_pordia` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `__saldos_bancos_pordia`() +BEGIN + +declare datEND DATE; + +SET datEND = CURDATE() + INTERVAL 2 MONTH; + +drop table if exists bi.saldos_bancos_pordia; + + +create table bi.saldos_bancos_pordia + + select Fecha, Entrada + , Salida + , @saldo := IF(@banco = Id_Banco and @emp = empresa_id, @saldo,0) + ifnull(Entrada,0)-ifnull(Salida,0) as Saldo + , @banco := Id_Banco as Id_Banco + , @emp := empresa_id as empresa_id + , 'NUL' as Empresa + , Año, Mes, Dia + + from + ( + select * from + ( + select t.day as Dia, t.month as Mes,t.year as Año, t.date as Fecha, b.Id_Banco, sum(Entrada) as Entrada, sum(Salida) as Salida, @banco := 0, @saldo := 0, @emp := 0, e.id as empresa_id + from time t + join Bancos b on b.entity_id = 1 + join empresa e on e.id IN (791,442) + left join + ( + Select Id_Banco, Entrada, Salida, Cajafecha,empresa_id + from Cajas + where Cajafecha >= '2015-01-01' + and Serie = 'MB' + union all + Select Id_Banco, NULL, importe, greatest(fecha,TIMESTAMPADD(DAY,1,CURDATE())),empresa_id + from pago + where conciliado = FALSE /*fecha between CURDATE() and datEND*/ + union all + Select Id_Banco, Entregado, NULL, greatest(Fechacobro,TIMESTAMPADD(DAY,1,CURDATE())),empresa_id + from Recibos + where conciliado = FALSE -- Fechacobro between CURDATE() and datEND + union all + Select IFNULL(Id_Banco,9999), Importe, NULL, Fecha,empresa_id + from Saldos_Prevision + where Fecha between CURDATE() and datEND + ) sub2 on t.date = sub2.Cajafecha and b.Id_Banco = sub2.Id_Banco and e.id = sub2.empresa_id + + where t.date between '2015-01-01' and datEND + and b.cash != 1 + group by b.Id_Banco, e.id, t.date + ) sub3 + order by Id_Banco, empresa_id, Fecha + ) sub +; + +update bi.saldos_bancos_pordia s +join empresa e on e.id = s.empresa_id +set s.Empresa = abbreviation; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `__subordinate` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `__subordinate`(IN `idWORKER` INT, IN `CasoBase` INT) +BEGIN + DECLARE auxWorker INT; + DECLARE vCompanyId INT; + + SELECT empresa_id + INTO vCompanyId + FROM Trabajadores + WHERE Id_Trabajador = idWORKER; + + IF vCompanyId = 1381 THEN -- ORNAMENTALES + + DROP TABLE IF EXISTS subordinate; + CREATE TABLE subordinate + (INDEX (Id_Trabajador)) ENGINE = MEMORY + SELECT Id_Trabajador,TRUE visited,0 boss + FROM Trabajadores + WHERE empresa_id = vCompanyId; + + ELSE + + + /* PAK 23/05/2016 + + Guardia de domingos + + Los domingos viene Fran a hacer de comercial y necesita ver todos los radares + + + + IF dayofweek(curdate()) = 1 and idWORKER = 43 then -- Domingo y Fran Natek + + DROP TABLE IF EXISTS subordinate; + + CREATE TABLE subordinate + (INDEX (Id_Trabajador)) ENGINE = MEMORY + SELECT Id_Trabajador,TRUE visited,0 boss + FROM Trabajadores; + + + else + */ + + IF CasoBase THEN + SET @@max_sp_recursion_depth = 5 ; + DROP TABLE IF EXISTS subordinate; + CREATE TABLE subordinate + (INDEX (Id_Trabajador)) ENGINE = MEMORY + SELECT idWORKER Id_Trabajador,TRUE visited,0 boss; + END IF; + + INSERT INTO subordinate + SELECT Id_Trabajador,0,idWORKER FROM Trabajadores WHERE boss = idWORKER; + IF (SELECT COUNT(*) FROM subordinate WHERE visited = 0 AND idWORKER = boss LIMIT 1) > 0 THEN + SELECT Id_Trabajador into auxWorker FROM subordinate WHERE visited = 0 AND idWORKER = boss LIMIT 1; + REPEAT + CALL subordinate(auxWorker,FALSE); + UPDATE subordinate SET visited = TRUE WHERE Id_Trabajador = auxWorker; + SET auxWorker = 0; + SELECT Id_Trabajador into auxWorker FROM subordinate WHERE visited = 0 AND idWORKER = boss LIMIT 1; + UNTIL auxWorker = 0 + END REPEAT; + END IF; + + /* + end if; + */ + + END IF; + + IF idWorker = 2 THEN + INSERT INTO subordinate(Id_Trabajador,visited,boss) VALUES (2,TRUE,2); + -- INSERT INTO subordinate(Id_Trabajador,visited,boss) VALUES (43,TRUE,2); + END IF; + + /* + IF CasoBase THEN + SELECT * FROM subordinate; + END IF;*/ + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `__subordinate2` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `__subordinate2`(IN `idWORKER` INT, IN `CasoBase` INT) +BEGIN + DECLARE auxWorker INT; + DECLARE vCompanyId INT; + + SELECT empresa_id + INTO vCompanyId + FROM Trabajadores + WHERE Id_Trabajador = idWORKER; + + IF vCompanyId = 1381 THEN -- ORNAMENTALES + + DROP TABLE IF EXISTS subordinate; + CREATE TABLE subordinate + (INDEX (Id_Trabajador)) ENGINE = MEMORY + SELECT Id_Trabajador,TRUE visited,0 boss + FROM Trabajadores + WHERE empresa_id = vCompanyId; + + ELSE + + + /* PAK 23/05/2016 + + Guardia de domingos + + Los domingos viene Fran a hacer de comercial y necesita ver todos los radares + + + + IF dayofweek(curdate()) = 1 and idWORKER = 43 then -- Domingo y Fran Natek + + DROP TABLE IF EXISTS subordinate; + + CREATE TABLE subordinate + (INDEX (Id_Trabajador)) ENGINE = MEMORY + SELECT Id_Trabajador,TRUE visited,0 boss + FROM Trabajadores; + + + else + */ + + IF CasoBase THEN + SET @@max_sp_recursion_depth = 5 ; + DROP TABLE IF EXISTS subordinate; + CREATE TABLE subordinate + (INDEX (Id_Trabajador)) ENGINE = MEMORY + SELECT idWORKER Id_Trabajador,TRUE visited,0 boss; + END IF; + + INSERT INTO subordinate + SELECT Id_Trabajador,0,idWORKER FROM Trabajadores WHERE boss = idWORKER; + IF (SELECT COUNT(*) FROM subordinate WHERE visited = 0 AND idWORKER = boss LIMIT 1) > 0 THEN + SELECT Id_Trabajador into auxWorker FROM subordinate WHERE visited = 0 AND idWORKER = boss LIMIT 1; + REPEAT + CALL subordinate(auxWorker,FALSE); + UPDATE subordinate SET visited = TRUE WHERE Id_Trabajador = auxWorker; + SET auxWorker = 0; + SELECT Id_Trabajador into auxWorker FROM subordinate WHERE visited = 0 AND idWORKER = boss LIMIT 1; + UNTIL auxWorker = 0 + END REPEAT; + END IF; + + /* + end if; + */ + + END IF; + + IF idWorker = 2 THEN + INSERT INTO subordinate(Id_Trabajador) VALUES (2); + END IF; + + /* + IF CasoBase THEN + SELECT * FROM subordinate; + END IF;*/ + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -40861,6 +41354,38 @@ CREATE DATABASE /*!32312 IF NOT EXISTS*/ `vn` /*!40100 DEFAULT CHARACTER SET utf USE `vn`; +-- +-- Table structure for table `__dailyTaskLog` +-- + +DROP TABLE IF EXISTS `__dailyTaskLog`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__dailyTaskLog` ( + `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__deliveryError` +-- + +DROP TABLE IF EXISTS `__deliveryError`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__deliveryError` ( + `ticket` int(11) NOT NULL, + `description` varchar(255) CHARACTER SET latin1 NOT NULL, + `worker` int(11) NOT NULL, + `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + KEY `errorTickets_idx` (`ticket`), + KEY `errorWorker_idx` (`worker`), + CONSTRAINT `errorTickets` FOREIGN KEY (`ticket`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `errorWorker` FOREIGN KEY (`worker`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Temporary table structure for view `accounting` -- @@ -41186,7 +41711,7 @@ CREATE TABLE `autoRadioLogCall` ( PRIMARY KEY (`id`), KEY `ticket_idx` (`ticketFk`), CONSTRAINT `ticket` FOREIGN KEY (`ticketFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=306 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=345 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41432,6 +41957,20 @@ CREATE TABLE `category` ( ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `chain` +-- + +DROP TABLE IF EXISTS `chain`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `chain` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Grupos de clientes'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Temporary table structure for view `city` -- @@ -41700,6 +42239,25 @@ SET character_set_client = utf8; 1 AS `typeFk`*/; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `clientChain` +-- + +DROP TABLE IF EXISTS `clientChain`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `clientChain` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `clientFk` int(11) NOT NULL, + `chainFk` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `clientChain_fk1_idx` (`clientFk`), + KEY `clientChain_fk2_idx` (`chainFk`), + CONSTRAINT `clientChain_fk1` FOREIGN KEY (`clientFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `clientChain_fk2` FOREIGN KEY (`chainFk`) REFERENCES `chain` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `clientContact` -- @@ -41713,7 +42271,7 @@ CREATE TABLE `clientContact` ( `name` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `phone` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=4111 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=4112 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41787,7 +42345,7 @@ CREATE TABLE `clientLog` ( KEY `userFk` (`userFk`), CONSTRAINT `clientLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `clientLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=194129 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=196905 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41919,21 +42477,6 @@ SET character_set_client = utf8; 1 AS `expired`*/; SET character_set_client = @saved_cs_client; --- --- Temporary table structure for view `companyOLD` --- - -DROP TABLE IF EXISTS `companyOLD`; -/*!50001 DROP VIEW IF EXISTS `companyOLD`*/; -SET @saved_cs_client = @@character_set_client; -SET character_set_client = utf8; -/*!50001 CREATE VIEW `companyOLD` AS SELECT - 1 AS `id`, - 1 AS `code`, - 1 AS `supplierAccountFk`, - 1 AS `CodigoEmpresa`*/; -SET character_set_client = @saved_cs_client; - -- -- Temporary table structure for view `comparative` -- @@ -42227,7 +42770,7 @@ CREATE TABLE `creditClassification` ( KEY `creditClassifClientFk_idx` (`client`), KEY `creditClassifdateEnd_idx` (`dateEnd`), CONSTRAINT `creditClassifClientFk` FOREIGN KEY (`client`) REFERENCES `vn2008`.`Clientes` (`id_cliente`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3030 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3041 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -42272,7 +42815,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=2482 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalla los clientes que tienen seguro de credito'; +) ENGINE=InnoDB AUTO_INCREMENT=2527 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 */ ; @@ -42312,19 +42855,6 @@ SET character_set_client = utf8; 1 AS `name`*/; SET character_set_client = @saved_cs_client; --- --- Table structure for table `dailyTaskLog` --- - -DROP TABLE IF EXISTS `dailyTaskLog`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `dailyTaskLog` ( - `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL, - `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `dayMinute` -- @@ -42358,25 +42888,6 @@ SET character_set_client = utf8; 1 AS `hasChanged`*/; SET character_set_client = @saved_cs_client; --- --- Table structure for table `deliveryError` --- - -DROP TABLE IF EXISTS `deliveryError`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `deliveryError` ( - `ticket` int(11) NOT NULL, - `description` varchar(255) CHARACTER SET latin1 NOT NULL, - `worker` int(11) NOT NULL, - `creation_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - KEY `errorTickets_idx` (`ticket`), - KEY `errorWorker_idx` (`worker`), - CONSTRAINT `errorTickets` FOREIGN KEY (`ticket`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `errorWorker` FOREIGN KEY (`worker`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Temporary table structure for view `deliveryMethod` -- @@ -42499,7 +43010,7 @@ CREATE TABLE `dua` ( CONSTRAINT `dua_fk1` FOREIGN KEY (`gestdocFk`) REFERENCES `vn2008`.`gestdoc` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `dua_fk2` FOREIGN KEY (`awbFk`) REFERENCES `vn2008`.`awb` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `dua_fk4` FOREIGN KEY (`companyFk`) REFERENCES `vn2008`.`empresa` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=3678 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3703 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42540,7 +43051,7 @@ CREATE TABLE `duaIntrastat` ( KEY `duaIntrastat_fk2_idx` (`duaFk`), CONSTRAINT `duaIntrastat_fk1` FOREIGN KEY (`intrastatFk`) REFERENCES `vn2008`.`Intrastat` (`Codintrastat`) ON UPDATE CASCADE, CONSTRAINT `duaIntrastat_fk2` FOREIGN KEY (`duaFk`) REFERENCES `dua` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=5610 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=5652 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42560,7 +43071,7 @@ CREATE TABLE `duaInvoiceIn` ( KEY `duaInvoiceIn_fk2_idx` (`invoiceInFk`), CONSTRAINT `duaInvoiceIn_fk1` FOREIGN KEY (`duaFk`) REFERENCES `dua` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `duaInvoiceIn_fk2` FOREIGN KEY (`invoiceInFk`) REFERENCES `vn2008`.`recibida` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=4578 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Facturas asociadas a la declaración aduanera, básicamente la del agente transitario'; +) ENGINE=InnoDB AUTO_INCREMENT=4593 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Facturas asociadas a la declaración aduanera, básicamente la del agente transitario'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42585,7 +43096,7 @@ CREATE TABLE `duaTax` ( CONSTRAINT `duaTax_fk1` FOREIGN KEY (`duaFk`) REFERENCES `dua` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `duaTax_fk2` FOREIGN KEY (`supplierFk`) REFERENCES `vn2008`.`Proveedores` (`Id_Proveedor`) ON UPDATE CASCADE, CONSTRAINT `duaTax_fk3` FOREIGN KEY (`taxClassFk`) REFERENCES `vn2008`.`iva_group` (`iva_group_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=4096 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=4215 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42681,7 +43192,7 @@ CREATE TABLE `entryLog` ( KEY `entryLog_ibfk_2` (`userFk`), 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 UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=116120 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=119524 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -42715,7 +43226,7 @@ CREATE TABLE `envialiaCity` ( PRIMARY KEY (`id`), KEY `agencyFk` (`agencyFk`), KEY `postalCode` (`postalCode`) -) ENGINE=InnoDB AUTO_INCREMENT=818150 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=898887 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43127,7 +43638,7 @@ CREATE TABLE `inventoryFailure` ( CONSTRAINT `inventoryFailure_fk3` FOREIGN KEY (`guiltyFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `inventoryFailure_fk4` FOREIGN KEY (`warehouseFk`) REFERENCES `vn2008`.`warehouse` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `inventoryFailure_fk5` FOREIGN KEY (`causeFk`) REFERENCES `inventoryFailureCause` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=6066 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=6816 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43398,7 +43909,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=98057 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=101397 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 */; -- @@ -43441,7 +43952,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=1036853 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1050515 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43493,7 +44004,7 @@ SET character_set_client = utf8; 1 AS `value10`, 1 AS `minimum`, 1 AS `upToDown`, - 1 AS `lastPrice`*/; + 1 AS `compression`*/; SET character_set_client = @saved_cs_client; -- @@ -43623,9 +44134,9 @@ 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', + `id` int(11) NOT NULL AUTO_INCREMENT, `originFk` int(11) NOT NULL, - `userFk` int(10) unsigned NOT NULL, + `userFk` int(10) unsigned DEFAULT NULL, `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL, `creationDate` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `description` text CHARACTER SET utf8, @@ -43634,10 +44145,11 @@ CREATE TABLE `itemLog` ( `newInstance` text COLLATE utf8_unicode_ci, `changedModelId` int(11) DEFAULT NULL, `changedModelValue` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), 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 + CONSTRAINT `itemLogItemFk` FOREIGN KEY (`originFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `itemLogUserFk` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -43680,7 +44192,7 @@ CREATE TABLE `itemPlacementSupply` ( CONSTRAINT `itemPlacementSupply_fk1` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemPlacementSupply_fk2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemPlacementSupply_fk3` FOREIGN KEY (`repoUserFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=473 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de nichos de picking que hay que reponer'; +) ENGINE=InnoDB AUTO_INCREMENT=2173 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de nichos de picking que hay que reponer'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43752,7 +44264,7 @@ CREATE TABLE `itemShelving` ( CONSTRAINT `itemShelving_fk1` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemShelving_fk2` FOREIGN KEY (`shelvingFk`) REFERENCES `shelving` (`code`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemShelving_fk3` FOREIGN KEY (`packagingFk`) REFERENCES `vn2008`.`Cubos` (`Id_Cubo`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=56846 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla utilizada para localizar los artículos dentro de los carros. Usado para la gestión del almacén en el altillo '; +) ENGINE=InnoDB AUTO_INCREMENT=60629 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla utilizada para localizar los artículos dentro de los carros. Usado para la gestión del almacén en el altillo '; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43785,6 +44297,36 @@ SET character_set_client = utf8; 1 AS `packing`*/; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `itemShelvingAvailableKk` +-- + +DROP TABLE IF EXISTS `itemShelvingAvailableKk`; +/*!50001 DROP VIEW IF EXISTS `itemShelvingAvailableKk`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `itemShelvingAvailableKk` AS SELECT + 1 AS `saleFk`, + 1 AS `Modificado`, + 1 AS `ticketFk`, + 1 AS `isPicked`, + 1 AS `itemFk`, + 1 AS `quantity`, + 1 AS `concept`, + 1 AS `size`, + 1 AS `Estado`, + 1 AS `sectorProdPriority`, + 1 AS `available`, + 1 AS `sectorFk`, + 1 AS `matricula`, + 1 AS `parking`, + 1 AS `itemShelving`, + 1 AS `Agency`, + 1 AS `shipped`, + 1 AS `grouping`, + 1 AS `packing`*/; +SET character_set_client = @saved_cs_client; + -- -- Temporary table structure for view `itemShelvingList` -- @@ -43826,7 +44368,7 @@ CREATE TABLE `itemShelvingPlacementSupply` ( KEY `itemShelvingPlacementSupply_fk3_idx` (`userFk`), CONSTRAINT `itemShelvingPlacementSupply_fk1` FOREIGN KEY (`itemShelvingFk`) REFERENCES `itemShelving` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemShelvingPlacementSupply_fk2` FOREIGN KEY (`itemPlacementSupplyFk`) REFERENCES `itemPlacementSupply` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=213 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de los itemShelving afectados por las ordenes de reposicion de nicho'; +) ENGINE=InnoDB AUTO_INCREMENT=1580 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle de los itemShelving afectados por las ordenes de reposicion de nicho'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43873,7 +44415,7 @@ CREATE TABLE `itemShelvingSale` ( CONSTRAINT `itemShelvingSale_fk1` FOREIGN KEY (`itemShelvingFk`) REFERENCES `itemShelving` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `itemShelvingSale_fk2` FOREIGN KEY (`saleFk`) REFERENCES `vn2008`.`Movimientos` (`Id_Movimiento`) ON UPDATE CASCADE, CONSTRAINT `itemShelvingSale_fk3` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle del producto que se retira de los carros, relacionando la linea de movimiento correspondiente'; +) ENGINE=InnoDB AUTO_INCREMENT=794 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Detalle del producto que se retira de los carros, relacionando la linea de movimiento correspondiente'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -43957,7 +44499,7 @@ CREATE TABLE `itemTag` ( KEY `priorityItem` (`priority`,`itemFk`), KEY `value` (`value`), CONSTRAINT `itemFK` FOREIGN KEY (`itemFk`) REFERENCES `vn2008`.`Articles` (`Id_Article`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1069550 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1084822 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 */ ; @@ -44026,32 +44568,6 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; --- --- Table structure for table `itemTagArranged` --- - -DROP TABLE IF EXISTS `itemTagArranged`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `itemTagArranged` ( - `itemFk` int(11) NOT NULL, - `tag1` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `val1` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `tag2` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `val2` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `tag3` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `val3` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `tag4` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `val4` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `tag5` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `val5` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `tag6` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `val6` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, - `description` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, - PRIMARY KEY (`itemFk`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Cache de columnas de características de artículo'; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Temporary table structure for view `itemTagged` -- @@ -44085,7 +44601,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=638708 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Define la clase de iva por artículo y pais'; +) ENGINE=InnoDB AUTO_INCREMENT=650867 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 */; -- @@ -44127,7 +44643,8 @@ SET character_set_client = utf8; 1 AS `life`, 1 AS `workerFk`, 1 AS `warehouseFk`, - 1 AS `isPackaging`*/; + 1 AS `isPackaging`, + 1 AS `density`*/; SET character_set_client = @saved_cs_client; -- @@ -44176,7 +44693,7 @@ CREATE TABLE `itemTypeTag` ( KEY `itemTypeTagTag_idx` (`tagFk`), CONSTRAINT `itemTypeTagTag` FOREIGN KEY (`tagFk`) REFERENCES `tag` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `itemTypeTagTipos` FOREIGN KEY (`itemTypeFk`) REFERENCES `vn2008`.`Tipos` (`tipo_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=224 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=230 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44249,7 +44766,8 @@ CREATE TABLE `labourTree` ( `lft` int(11) NOT NULL, `rgt` int(11) NOT NULL, `depth` bigint(22) NOT NULL DEFAULT '0', - `sons` decimal(10,0) DEFAULT NULL + `sons` decimal(10,0) DEFAULT NULL, + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -44369,7 +44887,7 @@ CREATE TABLE `medicalCenter` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(45) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44394,7 +44912,7 @@ CREATE TABLE `medicalReview` ( KEY `frgnkWorker_idx` (`workerFk`), CONSTRAINT `frgcenter` FOREIGN KEY (`centerFk`) REFERENCES `medicalCenter` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `frgnkWorker` FOREIGN KEY (`workerFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=168 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=177 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44415,7 +44933,7 @@ CREATE TABLE `message` ( KEY `sender` (`sender`), KEY `recipient` (`recipient`), KEY `uuid` (`uuid`(8)) -) ENGINE=InnoDB AUTO_INCREMENT=1764066 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1776448 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44437,7 +44955,7 @@ CREATE TABLE `messageInbox` ( PRIMARY KEY (`id`), KEY `uuid` (`uuid`(8)), KEY `finalRecipient` (`finalRecipient`) -) ENGINE=InnoDB AUTO_INCREMENT=1928245 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1941341 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -44671,7 +45189,7 @@ CREATE TABLE `parking` ( UNIQUE KEY `code_UNIQUE` (`code`), KEY `parking_fk1_idx` (`sectorFk`), CONSTRAINT `parking_fk1` FOREIGN KEY (`sectorFk`) REFERENCES `sector` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=24718 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla con los parkings del altillo'; +) ENGINE=InnoDB AUTO_INCREMENT=24873 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Tabla con los parkings del altillo'; /*!40101 SET character_set_client = @saved_cs_client */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -45449,7 +45967,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=786536 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=803007 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45460,6 +45978,7 @@ DROP TABLE IF EXISTS `routeParams`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `routeParams` ( + `ID` int(10) unsigned NOT NULL AUTO_INCREMENT, `kmRate` decimal(10,2) DEFAULT NULL, `m3Distributed` decimal(10,2) DEFAULT NULL, `load1m3` decimal(10,2) DEFAULT NULL, @@ -45467,8 +45986,9 @@ CREATE TABLE `routeParams` ( `load3m3` decimal(10,2) DEFAULT NULL, `load4m3` decimal(10,2) DEFAULT NULL, `load5m3` decimal(10,2) DEFAULT NULL, - `load6m3` decimal(10,2) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + `load6m3` decimal(10,2) DEFAULT NULL, + PRIMARY KEY (`ID`) +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45554,7 +46074,7 @@ CREATE TABLE `saleItemShelving` ( `ubication` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`), KEY `saleItemShelving_fk1_idx` (`itemShelvingFk`) -) ENGINE=InnoDB AUTO_INCREMENT=25629 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=26201 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45687,7 +46207,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=122260 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=123563 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45704,7 +46224,7 @@ CREATE TABLE `smsConfig` ( `password` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `title` varchar(50) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='SMS configuration parameters'; +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='SMS configuration parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45852,7 +46372,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=558024 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=575412 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -45930,8 +46450,8 @@ SET character_set_client = utf8; 1 AS `supplier`, 1 AS `entryFk`, 1 AS `landed`, - 1 AS `in`, 1 AS `out`, + 1 AS `in`, 1 AS `almacen`*/; SET character_set_client = @saved_cs_client; @@ -46164,7 +46684,7 @@ 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_user` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=4637235 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=4801730 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46236,7 +46756,7 @@ CREATE TABLE `ticketPackaging` ( 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, CONSTRAINT `ticketPackaging_fk3` FOREIGN KEY (`workerFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=53851 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=54907 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 */ ; @@ -46250,7 +46770,7 @@ DELIMITER ;; /*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `vn`.`ticketPackaging_BEFORE_INSERT` BEFORE INSERT ON `ticketPackaging` FOR EACH ROW BEGIN - SET NEW.workerFk = vn.getUser(); + SET NEW.workerFk = vn.getWorker(); END */;; DELIMITER ; @@ -46324,7 +46844,7 @@ CREATE TABLE `ticketService` ( KEY `fgn_ticketFk_idx` (`ticketFk`), CONSTRAINT `fgn_ticketFk` FOREIGN KEY (`ticketFk`) REFERENCES `vn2008`.`Tickets` (`Id_Ticket`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `ticketServiceIvaGroup` FOREIGN KEY (`taxClassFk`) REFERENCES `vn2008`.`iva_group` (`iva_group_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Servicios asociadas a un ticket'; +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Servicios asociadas a un ticket'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46450,6 +46970,34 @@ SET character_set_client = utf8; 1 AS `weekDay`*/; SET character_set_client = @saved_cs_client; +-- +-- Temporary table structure for view `ticketeToPreparePrepared` +-- + +DROP TABLE IF EXISTS `ticketeToPreparePrepared`; +/*!50001 DROP VIEW IF EXISTS `ticketeToPreparePrepared`*/; +SET @saved_cs_client = @@character_set_client; +SET character_set_client = utf8; +/*!50001 CREATE VIEW `ticketeToPreparePrepared` AS SELECT + 1 AS `Id_Ticket`, + 1 AS `Id_Movimiento`, + 1 AS `Id_Movimiento_mark`, + 1 AS `Id_Trabjador`, + 1 AS `Id_Article`, + 1 AS `Concepte`, + 1 AS `subName`, + 1 AS `Cantidad`, + 1 AS `original_quantity`, + 1 AS `Hora`, + 1 AS `Departure`, + 1 AS `Minuto`, + 1 AS `agency_id`, + 1 AS `warehouse_id`, + 1 AS `province_id`, + 1 AS `picked`, + 1 AS `trabajador`*/; +SET character_set_client = @saved_cs_client; + -- -- Temporary table structure for view `till` -- @@ -46561,7 +47109,7 @@ CREATE TABLE `trainingCourse` ( CONSTRAINT `frgnCenter` FOREIGN KEY (`centerFk`) REFERENCES `trainingCenter` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `frgnTrainingCourseType` FOREIGN KEY (`trainingCourseTypeFk`) REFERENCES `trainingCourseType` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `frgnWorker` FOREIGN KEY (`workerFk`) REFERENCES `vn2008`.`Trabajadores` (`Id_Trabajador`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=243 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de trabajadores que han realizado una formación'; +) ENGINE=InnoDB AUTO_INCREMENT=245 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Lista de trabajadores que han realizado una formación'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46886,7 +47434,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=9378 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=9582 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46936,7 +47484,7 @@ CREATE TABLE `workerJourney` ( UNIQUE KEY `userFk_UNIQUE` (`userFk`,`dated`), KEY `fk_workerJourney_user_idx` (`userFk`), CONSTRAINT `fk_workerJourney_user` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=20228093 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=22041021 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -46958,7 +47506,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=8634 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=8871 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47021,7 +47569,7 @@ CREATE TABLE `workerTimeControl` ( KEY `warehouseFkfk1_idx` (`warehouseFk`), CONSTRAINT `warehouseFk_1` FOREIGN KEY (`warehouseFk`) REFERENCES `vn2008`.`warehouse` (`id`) ON UPDATE CASCADE, CONSTRAINT `workerTimeControl_fk1` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2109507 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Fichadas'; +) ENGINE=InnoDB AUTO_INCREMENT=2287257 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Fichadas'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47146,15 +47694,13 @@ CREATE TABLE `zone` ( `travelingDays` int(11) NOT NULL DEFAULT '1', `price` double NOT NULL DEFAULT '0', `bonus` double NOT NULL DEFAULT '0', + `isVolumetric` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`,`name`), - UNIQUE KEY `name_UNIQUE` (`name`), KEY `fk_zone_1_idx` (`warehouseFk`), KEY `fk_zone_2_idx` (`agencyModeFk`), - KEY `fk_zone1_idx` (`warehouseFk`), - KEY `fk_zone2_idx` (`agencyModeFk`), CONSTRAINT `fk_zone_1` FOREIGN KEY (`warehouseFk`) REFERENCES `vn2008`.`warehouse` (`id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `fk_zone_2` FOREIGN KEY (`agencyModeFk`) REFERENCES `vn2008`.`Agencias` (`Id_Agencia`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -47185,7 +47731,10 @@ CREATE TABLE `zoneGeo` ( `lft` int(11) DEFAULT NULL, `rgt` int(11) DEFAULT NULL, `depth` bigint(22) NOT NULL DEFAULT '0', - `sons` decimal(10,0) DEFAULT NULL + `sons` decimal(10,0) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `zoneGeo_lft_IDX` (`lft`) USING BTREE, + UNIQUE KEY `zoneGeo_rgt_IDX` (`rgt`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -48246,7 +48795,6 @@ DELIMITER ; /*!50003 SET collation_connection = @saved_col_connection */ ; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; /*!50003 DROP FUNCTION IF EXISTS `getUser` */; -ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -48259,14 +48807,15 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `getUser`() RETURNS int(11) DETERMINISTIC BEGIN - RETURN getWorker(); +/* JGF 2019-03-04 obsoleto, usar account.userGetId() */ + /*RETURN getWorker(); */ + RETURN account.userGetId(); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; /*!50003 DROP FUNCTION IF EXISTS `getUserId` */; ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_general_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; @@ -48294,6 +48843,27 @@ DELIMITER ; /*!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 `getUserKk` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 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 `getUserKk`() RETURNS int(11) + DETERMINISTIC +BEGIN +/* JGF 2019-03-04 obsoleto, usar account.userGetId() */ + RETURN getWorker(); +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP FUNCTION IF EXISTS `getWorker` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -48334,7 +48904,7 @@ CREATE DEFINER=`root`@`%` FUNCTION `getWorkerCode`() RETURNS varchar(3) CHARSET BEGIN DECLARE vUserCode VARCHAR(3) CHARSET utf8 COLLATE utf8_unicode_ci; -SELECT workerCode INTO vUserCode +SELECT code INTO vUserCode FROM worker WHERE userFk = account.userGetId(); @@ -49305,6 +49875,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `agencyHourGetAgency`(vAddress INT, vDate DATE) BEGIN /** + * DEPRECATED usar zoneGetAgency * Devuelve el listado de agencias disponibles para la fecha * y dirección pasadas. * @@ -49378,6 +49949,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `agencyHourGetFirstShipped`(vAgencyMode INT, vAddress INT, vWarehouse INT) BEGIN /** + * DEPRECATED usar zoneGetFirstShipped * Devuelve la primera fecha de envio disponible para una agencia en una direccion y un warehouse * * @param vAgencyMode id de la agencia en vn.agencyMode @@ -49425,7 +49997,8 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `agencyHourGetLanded`(vDated DATE, vAddress INT, vAgency INT, vWarehouse INT) BEGIN /** - * Devuelve una tabla temporal con el dia de recepcion para vDated. + * DEPRECATED usar zoneGetLanded + * Devuelve una tabla temporal con el dia de recepcion para vDated. * * @param vDated Fecha de preparacion de mercancia * @param vAddress Id de consignatario, %NULL para recogida @@ -49474,6 +50047,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `agencyHourGetShipped`(vLanded DATE, vAddressFk INT, vAgencyFk INT) BEGIN /** + * DEPRECATED usar zoneGetShipped * Devuelve las posibles fechas de envío de un ticket * * @param vLanded La fecha de recepcion @@ -49553,7 +50127,8 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `agencyHourGetWarehouse`(vAddress INT, vDate DATE, vWarehouse INT) BEGIN /** -* Devuelve el listado de agencias disponibles para la fecha, + * DEPRECATED usar zoneGetWarehouse + * Devuelve el listado de agencias disponibles para la fecha, * dirección y warehouuse pasadas * * @param vAddress no puede ser NULL @@ -49642,6 +50217,8 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `agencyHourListGetShipped`(vDate DATE, vAddress INT, vAgency INT) BEGIN + /* * DEPRECATED usar zoneGetShipped +*/ CALL vn.agencyHourGetShipped(vDate, vAddress, vAgency); SELECT * FROM tmp.agencyHourGetShipped; @@ -49667,6 +50244,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `agencyListAvailable`(vDate DATE, vAddress INT) BEGIN /** + * DEPRECATED usar zoneGetAgency * Devuelve la lista de almacenes disponibles y la fecha de * envío desde cada uno. * @@ -49922,43 +50500,36 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `clean`() -BEGIN - - DECLARE vDateShort DATETIME; - DECLARE oneYearAgo DATE; - DECLARE twoYearsAgo DATE; - DECLARE sixYearsAgo DATE; - - SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE()); - SET oneYearAgo = TIMESTAMPADD(YEAR,-1,CURDATE()); - SET twoYearsAgo = TIMESTAMPADD(YEAR,-2,CURDATE()); - SET sixYearsAgo = TIMESTAMPADD(YEAR,-6,CURDATE()); - - DELETE FROM vn.dailyTaskLog WHERE created < vDateShort; - - INSERT INTO vn.dailyTaskLog(state) VALUES('clean START'); - - DELETE FROM vn.message WHERE sendDate < vDateShort; - DELETE FROM vn.messageInbox WHERE sendDate < vDateShort; - DELETE FROM vn.messageInbox WHERE sendDate < vDateShort; - DELETE FROM vn.workerTimeControl WHERE timed < sixYearsAgo; - DELETE FROM vn.itemShelving WHERE created < CURDATE() AND visible = 0; - - UPDATE vn.shelving s - LEFT JOIN vn.itemShelving it ON it.shelvingFk = s.code - SET it.visible = 0 - WHERE it.shelvingFk IS NULL; - - CALL vn.ticketPackagingRecovery; - - INSERT INTO vn.dailyTaskLog(state) VALUES('clean END'); +BEGIN + DECLARE vDateShort DATETIME; + DECLARE oneYearAgo DATE; + DECLARE twoYearsAgo DATE; + DECLARE sixYearsAgo DATE; + + SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE()); + SET oneYearAgo = TIMESTAMPADD(YEAR,-1,CURDATE()); + SET twoYearsAgo = TIMESTAMPADD(YEAR,-2,CURDATE()); + SET sixYearsAgo = TIMESTAMPADD(YEAR,-6,CURDATE()); + + DELETE FROM vn.message WHERE sendDate < vDateShort; + DELETE FROM vn.messageInbox WHERE sendDate < vDateShort; + DELETE FROM vn.messageInbox WHERE sendDate < vDateShort; + DELETE FROM vn.workerTimeControl WHERE timed < sixYearsAgo; + DELETE FROM vn.itemShelving WHERE created < CURDATE() AND visible = 0; + + UPDATE vn.shelving s + LEFT JOIN vn.itemShelving it ON it.shelvingFk = s.code + SET it.visible = 0 + WHERE it.shelvingFk IS NULL; + + CALL vn.ticketPackagingRecovery; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -50535,69 +51106,56 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `clientRemoveWorker`() -BEGIN - - - DECLARE done BOOL DEFAULT FALSE; - DECLARE vClientFk INT; - - DECLARE rs CURSOR FOR - SELECT c.clientFk - FROM tmp.clientGetDebt c - LEFT JOIN tmp.risk r ON r.clientFk = c.clientFk - WHERE IFNULL(r.risk,0) = 0 - ; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; - - DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; - CREATE TEMPORARY TABLE tmp.clientGetDebt - SELECT cd.id as clientFk - FROM bs.clientDied cd - LEFT JOIN vn.clientProtected cp ON cp.clientFk = cd.id - JOIN vn.client c ON c.id = cd.id - JOIN vn.province p ON p.id = c.provinceFk - JOIN vn.country co ON co.id = p.countryFk - - WHERE cd.Aviso = 'TERCER AVISO' - AND cp.clientFk IS NULL - AND co.country NOT IN ('Portugal','Francia','España exento') - AND c.salesPersonFk IS NOT NULL - ; - - CALL vn.clientGetDebt(curdate()); - - OPEN rs; - - DELETE FROM tmp.contador; - - FETCH rs INTO vClientFk; - - WHILE NOT done DO - - INSERT INTO tmp.contador(id) VALUES(vClientFk); - - CALL vn.greugeSpray(vClientFk, TRUE, '',TRUE); - - UPDATE vn.client SET salesPersonFk = NULL WHERE id = vClientFk; - - FETCH rs INTO vClientFk; - - END WHILE; - - - CLOSE rs; - - - - +BEGIN + DECLARE done BOOL DEFAULT FALSE; + DECLARE vClientFk INT; + + DECLARE rs CURSOR FOR + SELECT c.clientFk + FROM tmp.clientGetDebt c + LEFT JOIN tmp.risk r ON r.clientFk = c.clientFk + WHERE IFNULL(r.risk,0) = 0; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + + DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt; + CREATE TEMPORARY TABLE tmp.clientGetDebt + SELECT cd.id as clientFk + FROM bs.clientDied cd + LEFT JOIN vn.clientProtected cp ON cp.clientFk = cd.id + JOIN vn.client c ON c.id = cd.id + JOIN vn.province p ON p.id = c.provinceFk + JOIN vn.country co ON co.id = p.countryFk + WHERE cd.Aviso = 'TERCER AVISO' + AND cp.clientFk IS NULL + AND co.country NOT IN ('Portugal','Francia','España exento') + AND c.salesPersonFk IS NOT NULL; + + CALL vn.clientGetDebt(curdate()); + + DROP TEMPORARY TABLE IF EXISTS tmp.contador; + CREATE TEMPORARY TABLE tmp.contador (id INT) + ENGINE = MEMORY; + + OPEN rs; + FETCH rs INTO vClientFk; + + WHILE NOT done DO + INSERT INTO tmp.contador SET id = vClientFk; + CALL vn.greugeSpray(vClientFk, TRUE, '',TRUE); + UPDATE vn.client SET salesPersonFk = NULL WHERE id = vClientFk; + + FETCH rs INTO vClientFk; + END WHILE; + + CLOSE rs; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -50984,14 +51542,13 @@ SET @ordr := 0; SET @user := 0; DROP TEMPORARY TABLE IF EXISTS tmp.dayMinuteWorker; - CREATE TEMPORARY TABLE tmp.dayMinuteWorker ENGINE = MEMORY SELECT sub3.id, sub3.hh as Hora, sub3.mm as Minuto, sub3.userFk, - sub3.workerCode as CodigoTrabajador, + sub3.code as CodigoTrabajador, sub3.firstname as Nombre, sub3.name as Apellidos, sub3.warehouseFk as Almacen, @@ -51003,7 +51560,7 @@ CREATE TEMPORARY TABLE tmp.dayMinuteWorker hh, mm, userFk, - workerCode, + code, firstname, name, @ordr := IF(@user != userFk,0,@ordr), @@ -51018,7 +51575,7 @@ CREATE TEMPORARY TABLE tmp.dayMinuteWorker dm.mm, users.userFk, sub.`order`, - users.workerCode, + users.code, firstName, name, users.warehouseFk @@ -51026,7 +51583,7 @@ CREATE TEMPORARY TABLE tmp.dayMinuteWorker JOIN ( SELECT DISTINCT wtc.userFk , - workerCode , + code , firstName, name, IFNULL(warehouseFk,1) warehouseFk @@ -51865,7 +52422,7 @@ BEGIN SELECT t.id, e.id INTO vTravel, vEntry FROM travel t LEFT JOIN entry e ON t.id = e.travelFk WHERE t.landed = vInOutDate AND t.shipped = vInOutDate AND t.warehouseOutFk = vShipmentWarehouse - AND t.warehouseInFk = vLandingWarehouse AND agencyFk = vAgencyDirectFromProvider + AND t.warehouseInFk = vLandingWarehouse AND t.agencyFk = vAgencyDirectFromProvider LIMIT 1; -- creamos el travel si es necesario @@ -51956,7 +52513,7 @@ CREATE DEFINER=`root`@`%` PROCEDURE `getDeliveryWorkers`() BEGIN SELECT w.id, concat(p.firstname," ",p.name) AS fullName, - w.workerCode, + w.code AS workerCode, pwc.name, rl.routeFk as routeLoader FROM postgresql.person AS p @@ -52189,7 +52746,7 @@ BEGIN SELECT id INTO vOwner FROM vn.worker - WHERE workerCode = vWorkerCode COLLATE utf8_general_ci; + WHERE code = vWorkerCode COLLATE utf8_general_ci; END IF; @@ -52296,7 +52853,7 @@ WHILE NOT done DO JOIN vn.sale s ON s.ticketFk = t.id LEFT JOIN cache.last_buy lb ON lb.warehouse_id = t.warehouseFk AND item_id = s.itemFk LEFT JOIN vn.buy b ON b.id = lb.buy_id - LEFT JOIN vn.worker w ON w.workerCode = LEFT(s.concept, 3) + LEFT JOIN vn.worker w ON w.code = LEFT(s.concept, 3) WHERE t.id = vTicketFk AND s.quantity > 0; @@ -54627,7 +55184,7 @@ CREATE DEFINER=`root`@`%` PROCEDURE `itemPlacementSupplyCloseOrder`(vId INT, vQu BEGIN UPDATE vn.itemPlacementSupply - SET quantity = vQuantity + SET priority = 10 WHERE id = vId; END ;; @@ -55102,9 +55659,9 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; @@ -55864,7 +56421,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 `itemTagArrangedUpdate` */; +/*!50003 DROP PROCEDURE IF EXISTS `itemTagArrangedUpdateKk` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -55874,7 +56431,7 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `itemTagArrangedUpdate`(IN vItem BIGINT) +CREATE DEFINER=`root`@`%` PROCEDURE `itemTagArrangedUpdateKk`(IN vItem BIGINT) BEGIN /** * Actualiza la tabla itemTagArranged @@ -57152,6 +57709,66 @@ BEGIN END IF; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `packingListPrinted` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `packingListPrinted`(ticketFk INT) +BEGIN + + UPDATE vn2008.Movimientos_mark mm + JOIN vn2008.Movimientos m ON m.Id_Movimiento = mm.Id_Movimiento + SET mm.valor = 2 -- Impreso + WHERE mm.valor = 1 -- Listo para imprimir + AND mm.stateFk = 9 -- Encajando + AND m.Id_Ticket = ticketFk; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `packingListSwitch` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `packingListSwitch`(saleFk INT) +BEGIN + + DECLARE valueFk INT; + DECLARE encajando INT DEFAULT 9; + DECLARE accionEncajado INT DEFAULT 5; + + SELECT valor INTO valueFk + FROM vn2008.Movimientos_mark + WHERE Id_Movimiento = saleFk + AND stateFk = encajando; + + SET valueFk = (IFNULL(valueFk,0) + 1) MOD 3; + + REPLACE vn2008.Movimientos_mark(Id_Movimiento, valor, Id_Trabajador, Id_Accion, stateFk) + VALUES(saleFk,valueFk,getWorker(),accionEncajado,encajando); + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -57233,7 +57850,6 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `printTrolleyLabel` */; -ALTER DATABASE `vn` CHARACTER SET latin1 COLLATE latin1_swedish_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; @@ -57258,7 +57874,7 @@ BEGIN DECLARE vShipmentHour VARCHAR(10); SELECT getTicketTrolleyLabelCount(vTicket) INTO vLabelCount; - SELECT getUser() INTO vWorker; + SELECT getWorker() INTO vWorker; SELECT CONCAT(getShipmentHour(vTicket),':00') INTO vShipmentHour; INSERT INTO printingQueue(printer @@ -57281,7 +57897,6 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; -ALTER DATABASE `vn` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; /*!50003 DROP PROCEDURE IF EXISTS `productionSectorList` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -57310,7 +57925,7 @@ BEGIN FROM vn.itemShelvingAvailable isa JOIN vn.item i ON i.id = isa.itemFk LEFT JOIN cache.ticketShipping tsh ON tsh.ticketFk = isa.ticketFk - WHERE tsh.calc_id = vCalcFk + WHERE tsh.calc_id = vCalcFk AND MOD(TRUNCATE(isa.quantity,0), isa.packing)= 0 AND isa.sectorProdPriority <= 3 GROUP BY saleFk HAVING isa.quantity <= totalAvailable; @@ -58082,61 +58697,61 @@ DELIMITER ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `shelvingPark`(IN `vShelvingFk` VARCHAR(8), IN `vParkingCode` VARCHAR(8)) -BEGIN - - DECLARE vParkingFk INT DEFAULT 0; - DECLARE idParking INT; - DECLARE vColumn VARCHAR(3); +BEGIN + + DECLARE vParkingFk INT DEFAULT 0; + DECLARE idParking INT; + DECLARE vColumn VARCHAR(3); DECLARE vRow VARCHAR(2); - DECLARE vReturn VARCHAR(50); - - /*ELIMINAR ESPACIOS*/ - SET vParkingCode = replace(vParkingCode,' ','') ; - - /*SINO EXISTE EL PARKING LO CREAMOS*/ - SELECT id INTO idParking - FROM vn.parking - WHERE code = vParkingCode COLLATE utf8_unicode_ci; - - IF idParking IS NULL THEN - IF LOCATE('-',vParkingCode) = 4 THEN - SELECT SUBSTRING_INDEX(vParkingCode,'-',1) INTO vColumn; - SELECT SUBSTRING_INDEX(vParkingCode,'-',-1) INTO vRow; - INSERT INTO vn.parking(`column`,`row`,code,sectorFk) - VALUES(vColumn,vRow,vParkingCode,2); - END IF; - END IF; - /*FIN INSERTAR PARKING*/ - - - SELECT id INTO vParkingFk - FROM vn.parking - WHERE `code` = vParkingCode COLLATE utf8_unicode_ci; - - IF length(vShelvingFk) > 6 THEN + DECLARE vReturn VARCHAR(50); - - REPLACE vn.shelving(code, parkingFk, isPrinted, parked) + /*ELIMINAR ESPACIOS*/ + SET vParkingCode = replace(vParkingCode,' ','') ; + + /*SINO EXISTE EL PARKING LO CREAMOS*/ + SELECT id INTO idParking + FROM vn.parking + WHERE code = vParkingCode COLLATE utf8_unicode_ci; + + IF idParking IS NULL THEN + IF LOCATE('-',vParkingCode) = 4 THEN + SELECT SUBSTRING_INDEX(vParkingCode,'-',1) INTO vColumn; + SELECT SUBSTRING_INDEX(vParkingCode,'-',-1) INTO vRow; + INSERT INTO vn.parking(`column`,`row`,code,sectorFk) + VALUES(vColumn,vRow,vParkingCode,2); + END IF; + END IF; + /*FIN INSERTAR PARKING*/ + + + SELECT id INTO vParkingFk + FROM vn.parking + WHERE `code` = vParkingCode COLLATE utf8_unicode_ci; + + IF length(vShelvingFk) > 6 THEN + + + REPLACE vn.shelving(code, parkingFk, isPrinted, parked) VALUES(vShelvingFk, vParkingFk, TRUE, NOW()); - CALL vn.ticketStatePrevious(vShelvingFk); - - ELSE + CALL vn.ticketStatePrevious(vShelvingFk); + + ELSE - - UPDATE vn.shelving - SET parkingFk = vParkingFk, parked = NOW() + + UPDATE vn.shelving + SET parkingFk = vParkingFk, parked = NOW() WHERE `code` = vShelvingFk COLLATE utf8_unicode_ci; SELECT (COUNT(*) > 0) AS IsUpdated FROM vn.shelving WHERE parkingFk = vParkingFk - AND `code` = vShelvingFk COLLATE utf8_unicode_ci; - + AND `code` = vShelvingFk COLLATE utf8_unicode_ci; + END IF; - - + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -58535,6 +59150,45 @@ BEGIN CLOSE workerCur; END WHILE; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `supplierPackaging_ReportSource` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `supplierPackaging_ReportSource`(vFromDated DATE, vSupplierFk INT) +BEGIN + + SELECT * FROM + ( + SELECT supplierFk, itemFk, longName, supplier, entryFk, landed, `out`, `in`, almacen + FROM supplierPackaging + WHERE supplierFk = vSupplierFk + AND landed >= vFromDated + + UNION ALL + + SELECT vSupplierFk, itemFk, longName, supplier, 'anterior', vFromDated, sum(`out`), sum(`in`), NULL + FROM supplierPackaging + WHERE supplierFk = vSupplierFk + AND landed < vFromDated + GROUP BY itemFk + ) sub + ORDER BY itemFk, landed; + + + + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -58916,133 +59570,128 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `ticketClosure`() -BEGIN -/** - * Realiza el cierre de todos los - * tickets de la table ticketClosure. - */ - - DECLARE vDone BOOL; - DECLARE vClientFk INT; - DECLARE vTicketFk INT; - DECLARE vIsTaxDataChecked BOOL; - DECLARE vCompanyFk INT; - DECLARE vShipped DATE; - DECLARE vPriority INT DEFAULT 1; - DECLARE vReportDeliveryNote INT DEFAULT 1; - DECLARE vNewInvoiceId INT; - DECLARE vIsUeeMember BOOL; - DECLARE vWithPackage BOOL; - - DECLARE cur CURSOR FOR - SELECT ticketFk FROM tmp.ticketClosure; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - RESIGNAL; - END; - - INSERT INTO dailyTaskLog(state) VALUES('ticketClosure: START'); - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure2; - CREATE TEMPORARY TABLE tmp.ticketClosure2 - SELECT ticketFk FROM tmp.ticketClosure; - INSERT INTO tmp.ticketClosure - SELECT id FROM stowaway s - JOIN tmp.ticketClosure2 tc ON s.shipFk = tc.ticketFk; - OPEN cur; - - proc: LOOP - SET vDone = FALSE; - - FETCH cur INTO vTicketFk; - - IF vDone THEN - LEAVE proc; - END IF; - - -- ticketClosure start - SELECT - c.id, - c.isTaxDataChecked, - t.companyFk, - t.shipped, - co.isUeeMember, - w.isManaged - INTO vClientFk, - vIsTaxDataChecked, - vCompanyFk, - vShipped, - 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); JGF 2017/12/04 - - INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity) - (SELECT vTicketFk, p.id, COUNT(*) - FROM expedition e - JOIN packaging 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, isPriceFixed) - (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 packaging p ON p.itemFk = i.id - WHERE e.ticketFk = vTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0 - AND getSpecialPrice(e.itemFk, vClientFk) > 0 - GROUP BY e.itemFk); - - IF(vIsUeeMember = FALSE) THEN - - -- Facturacion rapida - CALL ticketTrackingAdd(vTicketFk, 'DELIVERED', 20); - -- Facturar si está contabilizado - IF vIsTaxDataChecked THEN - - IF (SELECT clientTaxArea(vClientFk, vCompanyFk)) = 'NATIONAL' THEN - CALL invoiceMakeByClient( - vClientFk, - (SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')), - vShipped, - vCompanyFk, - vNewInvoiceId); - ELSE - CALL invoiceMakeByTicket(vTicketFk, (SELECT invoiceSerial(vClientFk, vCompanyFk, 'R')), vNewInvoiceId); - END IF; - - END IF; - ELSE - -- Albaran_print - CALL ticketTrackingAdd(vTicketFk, (SELECT vn.getAlert3State(vTicketFk)), 20); - INSERT INTO printServerQueue(priorityFk, reportFk, param1) VALUES(vPriority, vReportDeliveryNote, vTicketFk); - END IF; - - -- ticketClosure end - END LOOP; - - CLOSE cur; - - DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure2; - - INSERT INTO dailyTaskLog(state) VALUES('ticketClosure: END'); +BEGIN +/** + * Realiza el cierre de todos los + * tickets de la table ticketClosure. + */ + DECLARE vDone BOOL; + DECLARE vClientFk INT; + DECLARE vTicketFk INT; + DECLARE vIsTaxDataChecked BOOL; + DECLARE vCompanyFk INT; + DECLARE vShipped DATE; + DECLARE vPriority INT DEFAULT 1; + DECLARE vReportDeliveryNote INT DEFAULT 1; + DECLARE vNewInvoiceId INT; + DECLARE vIsUeeMember BOOL; + DECLARE vWithPackage BOOL; + + DECLARE cur CURSOR FOR + SELECT ticketFk FROM tmp.ticketClosure; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + RESIGNAL; + END; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure2; + CREATE TEMPORARY TABLE tmp.ticketClosure2 + SELECT ticketFk FROM tmp.ticketClosure; + INSERT INTO tmp.ticketClosure + SELECT id FROM stowaway s + JOIN tmp.ticketClosure2 tc ON s.shipFk = tc.ticketFk; + OPEN cur; + + proc: LOOP + SET vDone = FALSE; + + FETCH cur INTO vTicketFk; + + IF vDone THEN + LEAVE proc; + END IF; + + -- ticketClosure start + SELECT + c.id, + c.isTaxDataChecked, + t.companyFk, + t.shipped, + co.isUeeMember, + w.isManaged + INTO vClientFk, + vIsTaxDataChecked, + vCompanyFk, + vShipped, + 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); JGF 2017/12/04 + + INSERT INTO ticketPackaging (ticketFk, packagingFk, quantity) + (SELECT vTicketFk, p.id, COUNT(*) + FROM expedition e + JOIN packaging 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, isPriceFixed) + (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 packaging p ON p.itemFk = i.id + WHERE e.ticketFk = vTicketFk AND IFNULL(p.isPackageReturnable, 0) = 0 + AND getSpecialPrice(e.itemFk, vClientFk) > 0 + GROUP BY e.itemFk); + + IF(vIsUeeMember = FALSE) THEN + + -- Facturacion rapida + CALL ticketTrackingAdd(vTicketFk, 'DELIVERED', 20); + -- Facturar si está contabilizado + IF vIsTaxDataChecked THEN + + IF (SELECT clientTaxArea(vClientFk, vCompanyFk)) = 'NATIONAL' THEN + CALL invoiceMakeByClient( + vClientFk, + (SELECT invoiceSerial(vClientFk, vCompanyFk, 'M')), + vShipped, + vCompanyFk, + vNewInvoiceId); + ELSE + CALL invoiceMakeByTicket(vTicketFk, (SELECT invoiceSerial(vClientFk, vCompanyFk, 'R')), vNewInvoiceId); + END IF; + + END IF; + ELSE + -- Albaran_print + CALL ticketTrackingAdd(vTicketFk, (SELECT vn.getAlert3State(vTicketFk)), 20); + INSERT INTO printServerQueue(priorityFk, reportFk, param1) VALUES(vPriority, vReportDeliveryNote, vTicketFk); + END IF; + + -- ticketClosure end + END LOOP; + + CLOSE cur; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketClosure2; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -59320,11 +59969,12 @@ proc: BEGIN * @param vAgencyModeFk Id del modo de agencia * @return tmp.ticketComponent, tmp.ticketComponentPrice */ + DECLARE vClientFk INT; - DECLARE vGeneralInflationCoefficient INT DEFAULT 1.3; + DECLARE vGeneralInflationCoefficient INT DEFAULT 1; DECLARE vMinimumDensityWeight INT DEFAULT 167; DECLARE vBoxFreightItem INT DEFAULT 71; - DECLARE vBoxVolume BIGINT DEFAULT 138000; + DECLARE vBoxVolume BIGINT; -- DEFAULT 138000; DECLARE vSpecialPriceComponent INT DEFAULT 10; DECLARE vExtraFreightComponent INT DEFAULT 14; DECLARE vDeliveryComponent INT DEFAULT 15; @@ -59337,6 +59987,11 @@ proc: BEGIN DECLARE vManaAutoComponent INT DEFAULT 39; DECLARE vFreightBonusComponent INT DEFAULT 41; + + SELECT volume INTO vBoxVolume + FROM vn.packaging + WHERE id = '94'; + SELECT clientFk INTO vClientFK FROM address WHERE id = vAddressFk; @@ -59449,11 +60104,12 @@ proc: BEGIN tcc.itemFk, vDeliveryComponent, vGeneralInflationCoefficient - * ROUND( - r.cm3 + * ROUND(( + i.compression + * r.cm3 * IF(am.deliveryMethodFk = 1, (GREATEST(i.density, vMinimumDensityWeight) / vMinimumDensityWeight), 1) * IFNULL(amz.price - * amz.inflation, 50) / vBoxVolume, 4 + * amz.inflation, 50)) / vBoxVolume, 4 ) cost FROM tmp.ticketComponentCalculate tcc JOIN item i ON i.id = tcc.itemFk @@ -59600,6 +60256,319 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticketComponentCalculateKK` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentCalculateKK`( + vAddressFk INT, + vAgencyModeFk INT) +proc: BEGIN +/** + * Calcula los componentes de un ticket + * + * @param vAddressFk Id del consignatario + * @param vAgencyModeFk Id del modo de agencia + * @return tmp.ticketComponent, tmp.ticketComponentPrice + */ + DECLARE vClientFk INT; + DECLARE vGeneralInflationCoefficient INT DEFAULT 1; + DECLARE vMinimumDensityWeight INT DEFAULT 167; + DECLARE vBoxFreightItem INT DEFAULT 71; + DECLARE vBoxVolume BIGINT; -- DEFAULT 138000; + DECLARE vSpecialPriceComponent INT DEFAULT 10; + DECLARE vExtraFreightComponent INT DEFAULT 14; + DECLARE vDeliveryComponent INT DEFAULT 15; + DECLARE vRecoveryComponent INT DEFAULT 17; + DECLARE vSellByPacketComponent INT DEFAULT 22; + DECLARE vBuyValueComponent INT DEFAULT 28; + DECLARE vMarginComponent INT DEFAULT 29; + DECLARE vDiscountLastItemComponent INT DEFAULT 32; + DECLARE vExtraBaggedComponent INT DEFAULT 38; + DECLARE vManaAutoComponent INT DEFAULT 39; + DECLARE vFreightBonusComponent INT DEFAULT 41; + + + SELECT volume INTO vBoxVolume + FROM vn.packaging + WHERE id = '94'; + + SELECT clientFk INTO vClientFK + FROM address + WHERE id = vAddressFk; + + SET @rate2 := 0; + SET @rate3 := 0; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentCalculate; + CREATE TEMPORARY TABLE tmp.ticketComponentCalculate + (PRIMARY KEY (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT + tl.itemFk, tl.warehouseFk, tl.available, + IF((@rate2 := IFNULL(pf.rate2, b.price2)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate2) * 1.0 rate2, + IF((@rate3 := IFNULL(pf.rate3, b.price3)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate3) * 1.0 rate3, + IFNULL(pf.rate3, 0) AS minPrice, + IFNULL(pf.packing, b.packing) packing, + IFNULL(pf.grouping, b.grouping) grouping, + ABS(IFNULL(pf.box, b.groupingMode)) groupingMode, + tl.buyFk, i.typeFk + FROM tmp.ticketLot tl + JOIN buy b ON b.id = tl.buyFk + JOIN item i ON i.id = tl.itemFk + JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN specialPrice sp ON sp.itemFk = i.id AND sp.clientFk = vClientFk + LEFT JOIN ( + SELECT * FROM ( + SELECT pf.itemFk, pf.grouping, pf.packing, pf.box, pf.rate2, pf.rate3, aho.warehouseFk + FROM priceFixed pf + JOIN tmp.agencyHourGetShipped aho ON pf.warehouseFk = aho.warehouseFk OR pf.warehouseFk = 0 + WHERE aho.shipped BETWEEN pf.started AND pf.ended ORDER BY pf.itemFk, pf.warehouseFk DESC + ) tpf + GROUP BY tpf.itemFk, tpf.warehouseFk + ) pf ON pf.itemFk = tl.itemFk AND pf.warehouseFk = tl.warehouseFk + WHERE b.buyingValue + b.freightValue + b.packageValue + b.comissionValue > 0.01 AND ic.display <> 0; + + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent; + CREATE TEMPORARY TABLE tmp.ticketComponent ( + `warehouseFk` INT UNSIGNED NOT NULL, + `itemFk` INT NOT NULL, + `componentFk` INT UNSIGNED NOT NULL, + `cost` DECIMAL(10,4) NOT NULL, + INDEX `itemWarehouse` USING BTREE (`itemFk` ASC, `warehouseFk` ASC), + UNIQUE INDEX `itemWarehouseComponent` (`itemFk` ASC, `warehouseFk` ASC, `componentFk` ASC)); + + + + INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) + SELECT + tcc.warehouseFk, + tcc.itemFk, + vBuyValueComponent, + b.buyingValue + b.freightValue + b.packageValue + b.comissionValue + FROM tmp.ticketComponentCalculate tcc + JOIN buy b ON b.id = tcc.buyFk; + + INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) + SELECT + tcc.warehouseFk, + tcc.itemFk, + vMarginComponent, + tcc.rate3 - b.buyingValue - b.freightValue - b.packageValue - b.comissionValue + FROM tmp.ticketComponentCalculate tcc + JOIN buy b ON b.id = tcc.buyFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentBase; + CREATE TEMPORARY TABLE tmp.ticketComponentBase ENGINE = MEMORY + SELECT tc.itemFk, ROUND(SUM(tc.cost), 4) AS base, tc.warehouseFk + FROM tmp.ticketComponent tc + GROUP BY tc.itemFk, warehouseFk; + + INSERT INTO tmp.ticketComponent + SELECT tcb.warehouseFk, tcb.itemFk, vRecoveryComponent, ROUND(tcb.base * LEAST(cr.recobro, 0.25), 3) + FROM tmp.ticketComponentBase tcb + JOIN bi.claims_ratio cr ON cr.Id_Cliente = vClientFk + WHERE cr.recobro > 0.009; + + INSERT INTO tmp.ticketComponent + SELECT tcb.warehouseFk, tcb.itemFk, vManaAutoComponent, ROUND(base * (0.01 + prices_modifier_rate), 3) as manaAuto + FROM tmp.ticketComponentBase tcb + JOIN `client` c on c.id = vClientFk + JOIN bs.mana_spellers ms ON c.salesPersonFk = ms.Id_Trabajador + WHERE ms.prices_modifier_activated + HAVING manaAuto <> 0; + + INSERT INTO tmp.ticketComponent + SELECT + tcb.warehouseFk, + tcb.itemFk, + cr.id, + GREATEST(IFNULL(ROUND(tcb.base * cr.tax, 4), 0), tcc.minPrice - tcc.rate3) + FROM tmp.ticketComponentBase tcb + JOIN componentRate cr + JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk + LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk + WHERE cr.id = vDiscountLastItemComponent AND cr.tax <> 0 AND tcc.minPrice < tcc.rate3 AND sp.value IS NULL; + + INSERT INTO tmp.ticketComponent + SELECT tcc.warehouseFk, tcc.itemFk, vSellByPacketComponent, tcc.rate2 - tcc.rate3 + FROM tmp.ticketComponentCalculate tcc + JOIN buy b ON b.id = tcc.buyFk + LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk + WHERE sp.value IS NULL; + + INSERT INTO tmp.ticketComponent + SELECT + tcc.warehouseFK, + tcc.itemFk, + vDeliveryComponent, + vGeneralInflationCoefficient + * ROUND(( + i.compression + * r.cm3 + * IF(am.deliveryMethodFk = 1, (GREATEST(i.density, vMinimumDensityWeight) / vMinimumDensityWeight), 1) + * IFNULL(amz.price + * amz.inflation, 50)) / vBoxVolume, 4 + ) cost + FROM tmp.ticketComponentCalculate tcc + JOIN item i ON i.id = tcc.itemFk + JOIN agencyMode am ON am.id = vAgencyModeFk + JOIN `address` a ON a.id = vAddressFk + JOIN agencyProvince ap ON ap.agencyFk = am.agencyFk + AND ap.warehouseFk = tcc.warehouseFk AND ap.provinceFk = a.provinceFk + JOIN agencyModeZone amz ON amz.agencyModeFk = vAgencyModeFk + AND amz.zone = ap.zone AND amz.itemFk = 71 AND amz.warehouseFk = tcc.warehouseFk + LEFT JOIN bi.rotacion r ON r.warehouse_id = tcc.warehouseFk + AND r.Id_Article = tcc.itemFk + HAVING cost <> 0; + + INSERT INTO tmp.ticketComponent + SELECT + tcc.warehouseFk, + tcc.itemFk, + vFreightBonusComponent, + vGeneralInflationCoefficient + * ROUND( + r.cm3 + * IF(am.deliveryMethodFk = 1, (GREATEST(i.density, vMinimumDensityWeight) / vMinimumDensityWeight), 1) + * awb.bonus + * amz.inflation / vBoxVolume, 4 + ) cost + FROM tmp.ticketComponentCalculate tcc + JOIN item i ON i.id = tcc.itemFk + JOIN agencyMode am ON am.id = vAgencyModeFk + JOIN `address` a ON a.id = vAddressFk + JOIN agencyProvince ap ON ap.agencyFk = a.id + AND ap.warehouseFk = tcc.warehouseFk AND ap.provinceFk = a.provinceFk + JOIN agencyModeZone amz ON amz.agencyModeFk = vAgencyModeFk + AND amz.zone = ap.zone AND amz.itemFk = vBoxFreightItem AND amz.warehouseFk = tcc.warehouseFk + JOIN agencyWeekDayBonus awb ON awb.warehouseFk = amz.warehouseFk AND awb.zone = amz.zone AND am.id = awb.agencyFk + LEFT JOIN bi.rotacion r ON r.warehouse_id = tcc.warehouseFk + AND r.Id_Article = tcc.itemFk + JOIN tmp.agencyHourGetShipped aho ON aho.warehouseFk = awb.warehouseFk + AND WEEKDAY(aho.landed) = awb.weekDay + HAVING cost <> 0 + LIMIT 1; + + IF (SELECT COUNT(*) FROM vn.addressForPackaging WHERE addressFk = vAddressFk) THEN + INSERT INTO tmp.ticketComponent + SELECT tcc.warehouseFk, b.itemFk, vExtraBaggedComponent, ap.packagingValue cost + FROM tmp.ticketComponentCalculate tcc + JOIN vn.addressForPackaging ap + WHERE ap.addressFk = vAddressFk; + END IF; + + INSERT INTO tmp.ticketComponent + SELECT tcb.warehouseFk, tcb.itemFk, vExtraFreightComponent, tcb.base * (IFNULL(pe.percentage,pp.percentage)/100) + FROM tmp.ticketComponentBase tcb + JOIN tmp.agencyHourGetShipped aho ON aho.warehouseFk = tcb.warehouseFk + LEFT JOIN preparationPercentage pp ON pp.weekDay = WEEKDAY(aho.shipped) + AND tcb.warehouseFk = IFNULL(pp.warehouseFk, tcb.warehouseFk) + LEFT JOIN preparationException pe ON pe.exceptionDay = aho.shipped + AND tcb.warehouseFk = IFNULL(pe.warehouseFk, tcb.warehouseFk) + WHERE IFNULL(pe.percentage, pp.percentage); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentCopy; + CREATE TEMPORARY TABLE tmp.ticketComponentCopy ENGINE = MEMORY + SELECT * FROM tmp.ticketComponent; + + INSERT INTO tmp.ticketComponent + SELECT + tcc.warehouseFk, + tcc.itemFk, + vSpecialPriceComponent, + sp.value - SUM(tcc.cost) sumCost + FROM tmp.ticketComponentCopy tcc + JOIN componentRate cr ON cr.id = tcc.componentFk + JOIN specialPrice sp ON sp.clientFk = vClientFK AND sp.itemFk = tcc.itemFk + WHERE cr.classRate IS NULL + GROUP BY tcc.itemFk, tcc.warehouseFk + HAVING ABS(sumCost) > 0.001; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentSum; + CREATE TEMPORARY TABLE tmp.ticketComponentSum + (INDEX (itemFk, warehouseFk)) + ENGINE = MEMORY + SELECT SUM(cost) sumCost, tc.itemFk, tc.warehouseFk, cr.classRate + FROM tmp.ticketComponent tc + JOIN componentRate cr ON cr.id = tc.componentFk + GROUP BY tc.itemFk, tc.warehouseFk, cr.classRate; + + select 1; + + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentRate; + CREATE TEMPORARY TABLE tmp.ticketComponentRate ENGINE = MEMORY + SELECT + tcc.warehouseFk, + tcc.itemFk, + 1 rate, + IF(tcc.groupingMode = 1, tcc.grouping, 1) grouping, + SUM(tcs.sumCost) price + FROM tmp.ticketComponentCalculate tcc + JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk + AND tcs.warehouseFk = tcc.warehouseFk + WHERE IFNULL(tcs.classRate, 1) = 1 + AND tcc.groupingMode < 2 AND (tcc.packing > tcc.grouping or tcc.groupingMode = 0) + GROUP BY tcs.warehouseFk, tcs.itemFk; + + INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, grouping, price) + SELECT + tcc.warehouseFk, + tcc.itemFk, + 2 rate, + tcc.packing grouping, + SUM(tcs.sumCost) price + FROM tmp.ticketComponentCalculate tcc + JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk + AND tcs.warehouseFk = tcc.warehouseFk + WHERE tcc.available IS NULL OR (IFNULL(tcs.classRate, 2) = 2 + AND tcc.packing > 0 AND tcc.available >= tcc.packing) + GROUP BY tcs.warehouseFk, tcs.itemFk; + + INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, grouping, price) + SELECT + tcc.warehouseFk, + tcc.itemFk, + 3 rate, + tcc.available grouping, + SUM(tcs.sumCost) price + FROM tmp.ticketComponentCalculate tcc + JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk + AND tcs.warehouseFk = tcc.warehouseFk + WHERE IFNULL(tcs.classRate, 3) = 3 + GROUP BY tcs.warehouseFk, tcs.itemFk; + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentPrice; + +select 2; + + CREATE TEMPORARY TABLE tmp.ticketComponentPrice ENGINE = MEMORY + SELECT * FROM ( + SELECT * FROM tmp.ticketComponentRate ORDER BY price + ) t + GROUP BY itemFk, warehouseFk, grouping; + + DROP TEMPORARY TABLE + tmp.ticketComponentCalculate, + tmp.ticketComponentSum, + tmp.ticketComponentBase, + tmp.ticketComponentRate, + tmp.ticketComponentCopy; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketComponentMakeUpdate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59802,6 +60771,147 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticketComponentPreviewKk` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentPreviewKk`( + vTicketFk INT, + vLanded DATE, + vAddressFk INT, + vAgencyModeFk INT, + vWarehouseFk SMALLINT) +BEGIN +/** + * Devuelve un listado previo de + * componentes para un ticket + * + * @param vTicketFk Id del ticket + * @param vLanded Fecha de recepcion + * @param vAddressFk Id del consignatario + * @param vAgencyModeFk Id del modo de agencia + * @param vWarehouseFk Id del almacén + */ + + DECLARE vAgencyFk INT; + DECLARE vShipped DATE; + DECLARE vBuyOrderItem INT DEFAULT 100; + + DECLARE vHasDataChanged BOOL DEFAULT FALSE; + DECLARE vHasAddressChanged BOOL; + DECLARE vHasAgencyModeChanged BOOL DEFAULT FALSE; + DECLARE vHasWarehouseChanged BOOL DEFAULT FALSE; + + DECLARE vAddressTypeRateFk INT DEFAULT NULL; + DECLARE vAgencyModeTypeRateFk INT DEFAULT NULL; + + DECLARE vHasChangeAll BOOL DEFAULT FALSE; + + SELECT DATE(landed) <> vLanded, + addressFk <> vAddressFk, + agencyModeFk <> vAgencyModeFk, + warehouseFk <> vWarehouseFk + INTO + vHasDataChanged, + vHasAddressChanged, + vHasAgencyModeChanged, + vHasWarehouseChanged + FROM vn.ticket t + WHERE t.id = vTicketFk; +/*SELECT vHasDataChanged, + vHasAddressChanged, + vHasAgencyModeChanged, + vHasWarehouseChanged; + */ + IF vHasDataChanged OR vHasWarehouseChanged THEN + SET vHasChangeAll = TRUE; + END IF; + + IF vHasAddressChanged THEN + SET vAddressTypeRateFk = 5; + END IF; + + IF vHasAgencyModeChanged THEN + SET vAgencyModeTypeRateFk = 6; + END IF; + + SELECT agencyFk INTO vAgencyFk + FROM agencyMode + WHERE id = vAgencyModeFk; + select 1; + CALL agencyHourGetShipped(vLanded, vAddressFk, vAgencyFk); + + SELECT shipped INTO vShipped + FROM tmp.agencyHourGetShipped + WHERE warehouseFk = vWarehouseFK; + select 2; + CALL buyUltimate(vWarehouseFK, vShipped); + + DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot; + CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY ( + SELECT + vWarehouseFK AS warehouseFk, + NULL AS available, + s.itemFk, + bu.buyFk + FROM sale s + LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk + WHERE s.ticketFk = vTicketFk + AND s.itemFk != vBuyOrderItem + GROUP BY bu.warehouseFk, bu.itemFk); + select 3; + CALL ticketComponentCalculateKK(vAddressFk, vAgencyModeFk); + select 4; +/*SELECT *,vHasChangeAll,cr.isRenewable = FALSE,vHasChangeAll, + NOT (cr.componentTypeRate <=> vAddressTypeRateFk),NOT (cr.componentTypeRate <=> vAgencyModeTypeRateFk), + NOT (cr.componentTypeRate <=> vAddressTypeRateFk) OR NOT (cr.componentTypeRate <=> vAgencyModeTypeRateFk) + FROM saleComponent sc + JOIN sale s ON s.id = sc.saleFk + JOIN ticket t ON t.id = s.ticketFk + JOIN componentRate cr ON cr.id = sc.componentFk + WHERE s.ticketFk = vTicketFk + AND (cr.isRenewable = FALSE + OR + (NOT vHasChangeAll + AND (NOT (cr.componentTypeRate <=> vAddressTypeRateFk + OR cr.componentTypeRate <=> vAgencyModeTypeRateFk))));*/ +/*SELECT * FROM tmp.ticketComponent;*/ + -- Inserta los componentes que NO seran modificados + REPLACE INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost) + SELECT t.warehouseFk, s.itemFk, sc.componentFk, sc.value + FROM saleComponent sc + JOIN sale s ON s.id = sc.saleFk + JOIN ticket t ON t.id = s.ticketFk + JOIN componentRate cr ON cr.id = sc.componentFk + WHERE s.ticketFk = vTicketFk + AND (cr.isRenewable = FALSE + OR + (NOT vHasChangeAll + AND (NOT (cr.componentTypeRate <=> vAddressTypeRateFk + OR cr.componentTypeRate <=> vAgencyModeTypeRateFk)))); +/*SELECT * FROM tmp.ticketComponent;*/ + SET @shipped = vShipped; + + DROP TEMPORARY TABLE + tmp.agencyHourGetShipped, + tmp.buyUltimate, + tmp.ticketLot; + + IF IFNULL(vShipped, CURDATE() - 1) < CURDATE() THEN + CALL util.throw('NO_AGENCY_AVAILABLE'); + END IF; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketComponentPriceDifference` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -59863,6 +60973,67 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `ticketComponentPriceDifferenceKk` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentPriceDifferenceKk`( + vTicketFk INT, + vLanded DATE, + vAddressFk INT, + vAgencyModeFk INT, + vWarehouseFk INT) +BEGIN +/** + * Devuelve las diferencias de precio + * de los movimientos de un ticket. + * + * @param vTicketFk Id del ticket + * @param vLanded Fecha de recepcion + * @param vAddressFk Id del consignatario + * @param vAgencyModeFk Id del modo de agencia + * @param vWarehouseFk Id del almacén + */ + CALL vn.ticketComponentPreviewKk(vTicketFk, vLanded, vAddressFk, vAgencyModeFk, vWarehouseFk); +select 1; + SELECT s.itemFk, + i.name, + i.size, + i.category, + IFNULL(s.quantity, 0) AS quantity, + IFNULL(s.price, 0) AS price, + ROUND(SUM(tc.cost), 2) AS newPrice, + s.quantity * (s.price - ROUND(SUM(tc.cost), 2)) difference, + s.id AS saleFk + FROM sale s + JOIN item i ON i.id = s.itemFk + JOIN ticket t ON t.id = s.ticketFk + LEFT JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk + AND tc.warehouseFk = t.warehouseFk + LEFT JOIN saleComponent sc ON sc.saleFk = s.id + AND sc.componentFk = tc.componentFk + LEFT JOIN componentRate cr ON cr.id = tc.componentFk + WHERE + t.id = vTicketFk + AND IF(sc.componentFk IS NULL + AND cr.classRate IS NOT NULL, FALSE, TRUE) + GROUP BY s.id ORDER BY s.id; + + DROP TEMPORARY TABLE + tmp.ticketComponent, + tmp.ticketComponentPrice; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; /*!50003 DROP PROCEDURE IF EXISTS `ticketComponentUpdate` */; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; @@ -60156,23 +61327,10 @@ CREATE DEFINER=`root`@`%` PROCEDURE `ticketCreateWithUser`( ,OUT vNewTicket INT) BEGIN - DECLARE vClientOrnamentales INT DEFAULT 5270; - DECLARE vCompanyOrn INT DEFAULT 1381; - DECLARE vProvinceName VARCHAR(255); - IF vClientId IS NULL THEN CALL util.throw ('CLIENT_NOT_ESPECIFIED'); END IF; - SELECT p.name INTO vProvinceName - FROM vn.client c - JOIN province p ON p.id = c.provinceFk - WHERE c.id = vClientId; - - IF vProvinceName IN ('SANTA CRUZ DE TENERIFE', 'LAS PALMAS DE GRAN CANARIA') AND vClientId <> vClientOrnamentales THEN - SET vCompanyFk = vCompanyOrn; - END IF; - IF NOT vAddressFk OR vAddressFk IS NULL THEN SELECT id INTO vAddressFk FROM address @@ -60275,16 +61433,11 @@ DELIMITER ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `ticketGetProblems`() BEGIN -/* - * Obtiene los problemas de uno o varios tickets - * - * @table tmp.ticketGetProblems(ticketFk, clientFk, warehouseFk, shipped) - * @return tmp.ticketProblems - */ + DECLARE vWarehouse INT; DECLARE vDate DATE; DECLARE vAvailableCache INT; @@ -60350,13 +61503,7 @@ BEGIN FROM tmp.ticketList tl JOIN vn.ticketRequest tr ON tr.ticketFk = tl.ticketFk WHERE tr.isOK IS NULL; - /* - INSERT INTO tmp.ticketProblems(ticketFk, problem) - SELECT DISTINCT tl.ticketFk, 'Code 100' - FROM tmp.ticketList tl - JOIN sale s ON s.ticketFk = tl.ticketFk - WHERE s.itemFk = 100; - */ + DELETE tl FROM tmp.ticketList tl JOIN tmp.ticketProblems tp ON tl.ticketFk = tp.ticketFk; @@ -60709,7 +61856,7 @@ DELIMITER ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `ticketGetVisibleAvailable`( vTicket INT) @@ -60739,8 +61886,8 @@ BEGIN LEFT JOIN cache.visible v ON v.item_id = s.itemFk AND v.calc_id = vVisibleCalc LEFT JOIN cache.available av ON av.item_id = s.itemFk AND av.calc_id = vAvailableCalc LEFT JOIN item it ON it.id = s.itemFk - WHERE s.ticketFk = vTicket; - + WHERE s.ticketFk = vTicket + ORDER BY s.concept; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -61217,16 +62364,21 @@ DELIMITER ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `ticketToPrePrepare`(IN vIdTicket INT) +CREATE DEFINER=`root`@`%` PROCEDURE `ticketToPrePrepare`(IN vIdTicket INT, IN viewAll BOOL) BEGIN /* Tickets con estado 26 para preaprar en altillo */ - +IF viewAll IS true THEN SELECT * - FROM vn.ticketToPrepare ttp + FROM vn.ticketeToPreparePrepared ttp WHERE ttp.Id_Ticket = vIdTicket; - +ELSE + SELECT * + FROM vn.ticketToPrepare ttp + WHERE ttp.Id_Ticket = vIdTicket; + +END IF; END ;; DELIMITER ; @@ -62049,7 +63201,7 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `workerTimeControlNonDays`() BEGIN - SELECT wtc.userFk, date(wtc.timed) as Fecha , COUNT(wtc.`order`) as maxOrder, c.name as worker, wb.workerCode as Boss, CONCAT (au.name, "@verdnatura.es") AS bossMail + SELECT wtc.userFk, date(wtc.timed) as Fecha , COUNT(wtc.`order`) as maxOrder, c.name as worker, wb.code as Boss, CONCAT (au.name, "@verdnatura.es") AS bossMail FROM workerTimeControl wtc JOIN worker w ON w.userFk = wtc.userFk LEFT JOIN worker wb ON wb.id = w.bossFk @@ -62268,6 +63420,261 @@ BEGIN CREATE TEMPORARY TABLE tmp.xdiarioNextId AS SELECT vNewAsien ; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `zoneGetAgency` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetAgency`(vAddress INT, vLanded DATE) +BEGIN +/** + * Devuelve el listado de agencias disponibles para la fecha + * y dirección pasadas. + * + * @param vAddress Id de dirección de envío, %NULL si es recogida + * @param vDate Fecha de recogida + * @select Listado de agencias disponibles + */ + + DECLARE vPostalCode varchar(10); + + SELECT postalCode INTO vPostalCode + FROM address WHERE id = vAddress; + + /*DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetAgency; + CREATE TEMPORARY TABLE tmp.zoneGetAgency + (INDEX (agencyModeFk)) ENGINE = MEMORY*/ + SELECT * FROM ( + SELECT am.id agencyModeFk, + am.name agencyMode, + am.description, + am.deliveryMethodFk, + TIMESTAMPADD(DAY,-z.travelingDays, vLanded) shipped, + zi.isIncluded + FROM zoneGeo zgSon + JOIN zoneGeo zgFather ON zgSon.lft BETWEEN zgFather.lft AND zgFather.rgt + JOIN zoneIncluded zi ON zi.geoFk = zgFather.id + JOIN zone z ON z.id = zi.zoneFk + JOIN zoneCalendar zc ON zc.zoneFk = z.id + JOIN agencyMode am ON am.id = z.agencyModeFk + WHERE zgSon.`name` LIKE vPostalCode + AND zc.delivered = vLanded + AND IF(TIMESTAMPADD(DAY,-z.travelingDays, vLanded) = CURDATE(), hour(now()) < hour(z.`hour`),TRUE) + ORDER BY zgFather.depth DESC) t + GROUP BY agencyModeFk + HAVING isIncluded > 0; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `zoneGetFirstShipped` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetFirstShipped`(vAgencyModeFk INT, vAddress INT, vWarehouseFk INT) +BEGIN +/** +* Devuelve la primera fecha de envio disponible para una agencia en una direccion y un warehouse +* +* @param vAgencyMode id de la agencia en vn.agencyMode +* @param vAddress id de la direccion +* @param vWarehouse id del warehouse +* @return vShipped la primera fecha disponible y vLanded la fecha de llegada/recojida +*/ + + DECLARE vPostalCode varchar(10); + + SELECT postalCode INTO vPostalCode + FROM address WHERE id = vAddress; + + SELECT * FROM ( + SELECT TIMESTAMPADD(DAY,-z.travelingDays, zc.delivered) shipped, + zc.delivered landed + FROM zoneGeo zgSon + JOIN zoneGeo zgFather ON zgSon.lft BETWEEN zgFather.lft AND zgFather.rgt + JOIN zoneIncluded zi ON zi.geoFk = zgFather.id + JOIN zone z ON z.id = zi.zoneFk + JOIN zoneCalendar zc ON zc.zoneFk = z.id + WHERE zgSon.`name` LIKE vPostalCode + AND z.agencyModeFk = vAgencyModeFk + AND z.warehouseFk = vWarehouseFk + AND IF(TIMESTAMPADD(DAY,-z.travelingDays, zc.delivered) = CURDATE(), hour(now()) < hour(z.`hour`),TRUE) + ORDER BY landed ASC, zgFather.depth DESC) t + HAVING isIncluded > 0 LIMIT 1; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `zoneGetLanded` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetLanded`(vShipped DATE, vAddress INT, vAgencyMode INT, vWarehouse INT) +BEGIN +/** +* Devuelve una tabla temporal con el dia de recepcion para vShipped. +* +* @param vShipped Fecha de preparacion de mercancia +* @param vAddress Id de consignatario, %NULL para recogida +* @param vAgencyMode Id agencia +* @table tmp.zoneGetLanded Datos de recepción +*/ + DECLARE vPostalCode varchar(10); + + SELECT postalCode INTO vPostalCode + FROM address WHERE id = vAddress; + + DROP TEMPORARY TABLE IF EXISTS tmp.zoneGetLanded; + CREATE TEMPORARY TABLE tmp.zoneGetLanded + ENGINE = MEMORY + SELECT vWarehouse warehouseFk,delivered landed FROM ( + SELECT zi.* + FROM vn.zoneGeo zgSon + JOIN vn.zoneGeo zgFather ON zgSon.lft BETWEEN zgFather.lft AND zgFather.rgt + JOIN zoneIncluded zi ON zi.geoFk = zgFather.id + JOIN zone z ON z.id = zi.zoneFk + JOIN zoneCalendar zc ON zc.zoneFk = z.id + WHERE zgSon.`name` LIKE vPostalCode + AND zc.delivered = TIMESTAMPADD(DAY,z.travelingDays, vShipped) + AND IF(vShipped = CURDATE(), hour(now()) < hour(z.`hour`),TRUE) + AND z.agencyModeFk = vAgencyMode + ORDER BY zgFather.depth DESC) t + GROUP BY zoneFk + HAVING isIncluded > 0 + LIMIT 1; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `zoneGetShipped` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetShipped`(vLanded DATE, vAddressFk INT, vAgencyModeFk INT, vWarehouseFk INT) +BEGIN +/** + * Devuelve la mínima fecha de envía para cada warehouse + * + * @param vLanded La fecha de recepcion + * @param vAddressFk Id del consignatario + * @param vAgencyModeFk Id de la agencia + * @return tmp.zoneGetShipped + */ + + DECLARE vPostalCode varchar(10); + + SELECT postalCode INTO vPostalCode + FROM address WHERE id = vAddressFk; + + SELECT * FROM ( + SELECT z.id, + TIMESTAMPADD(DAY,-z.travelingDays, vLanded) shipped, + vLanded landed, + zi.isIncluded + FROM zoneGeo zgSon + JOIN zoneGeo zgFather ON zgSon.lft BETWEEN zgFather.lft AND zgFather.rgt + JOIN zoneIncluded zi ON zi.geoFk = zgFather.id + JOIN zone z ON z.id = zi.zoneFk + JOIN zoneCalendar zc ON zc.zoneFk = z.id + WHERE zgSon.`name` LIKE vPostalCode + AND zc.delivered = vLanded + AND z.agencyModeFk = vAgencyModeFk + AND z.warehouseFk = vWarehouseFk + AND IF(TIMESTAMPADD(DAY,-z.travelingDays, vLanded) = CURDATE(), hour(now()) < hour(z.`hour`),TRUE) + ORDER BY z.id, landed ASC, zgFather.depth DESC) t + GROUP BY id + HAVING isIncluded > 0; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `zoneGetWarehouse` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `zoneGetWarehouse`(vAddress INT, vLanded DATE, vWarehouse INT) +BEGIN +/** +* Devuelve el listado de agencias disponibles para la fecha, + * dirección y warehouse pasadas + * + * @param vAddress + * @param vWarehouse warehouse + * @param vLanded Fecha de recogida + * @select Listado de agencias disponibles + */ + + DECLARE vPostalCode varchar(10); + + SELECT postalCode INTO vPostalCode + FROM address WHERE id = vAddress; + + SELECT * FROM ( + SELECT am.id, + am.name agencyMode, + am.description, + am.deliveryMethodFk, + TIMESTAMPADD(DAY,-z.travelingDays, vLanded) shipped, + z.warehouseFk, + zi.isIncluded + FROM zoneGeo zgSon + JOIN zoneGeo zgFather ON zgSon.lft BETWEEN zgFather.lft AND zgFather.rgt + JOIN zoneIncluded zi ON zi.geoFk = zgFather.id + JOIN zone z ON z.id = zi.zoneFk + JOIN zoneCalendar zc ON zc.zoneFk = z.id + JOIN agencyMode am ON am.id = z.agencyModeFk + WHERE zgSon.`name` LIKE vPostalCode + AND delivered = vLanded + AND z.warehouseFk = vWarehouse + AND IF(TIMESTAMPADD(DAY,-z.travelingDays, vLanded) = CURDATE(), hour(now()) < hour(z.`hour`),TRUE) + ORDER BY zgFather.depth DESC) t + GROUP BY id + HAVING isIncluded > 0; + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -62616,7 +64023,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=432480 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=438475 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -62717,7 +64124,7 @@ CREATE TABLE `deliveryInformation` ( KEY `fgbSupplyResponse_idx2` (`FirstOrderDateTime`), KEY `fgbSupplyResponse_idx3` (`LatestOrderDateTime`), CONSTRAINT `fgbSupplyResponse` FOREIGN KEY (`supplyResponseID`) REFERENCES `supplyResponse` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=15212514 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=15756877 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -63020,7 +64427,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=455151 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=461230 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -63243,7 +64650,7 @@ CREATE TABLE `supplyResponse` ( `MarketFormCode` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT '"002" Standard Sales\n"005" Catalogue (optional)\n"001" Committed (optional)\n"003" Buffer (optional, Clock Pre Sales) ', PRIMARY KEY (`ID`), UNIQUE KEY `ID_UNIQUE` (`ID`) -) ENGINE=InnoDB AUTO_INCREMENT=4629106 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=4866603 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -63684,6 +65091,22 @@ SET character_set_client = utf8; 1 AS `month`*/; SET character_set_client = @saved_cs_client; +-- +-- Table structure for table `__departmentCost` +-- + +DROP TABLE IF EXISTS `__departmentCost`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__departmentCost` ( + `departmentFk` int(11) NOT NULL, + `workerHours` decimal(10,1) DEFAULT NULL, + `labourCost` decimal(10,0) DEFAULT NULL, + `dated` date NOT NULL, + KEY `departmentCost_fk1_idx` (`departmentFk`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `bancos_evolution` -- @@ -63774,23 +65197,6 @@ CREATE TABLE `compradores_evolution` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `departmentCost` --- - -DROP TABLE IF EXISTS `departmentCost`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `departmentCost` ( - `departmentFk` int(11) NOT NULL, - `workerHours` decimal(10,1) DEFAULT NULL, - `labourCost` decimal(10,0) DEFAULT NULL, - `dated` date NOT NULL, - KEY `departmentCost_fk1_idx` (`departmentFk`), - CONSTRAINT `departmentCost_fk1` FOREIGN KEY (`departmentFk`) REFERENCES `vn2008`.`department` (`department_id`) ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `experienceIberflora2016` -- @@ -63922,6 +65328,7 @@ DROP TABLE IF EXISTS `m3`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `m3` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `fecha` date NOT NULL, `provinceFk` smallint(5) unsigned DEFAULT NULL, `warehouseFk` smallint(6) unsigned NOT NULL DEFAULT '0', @@ -63931,8 +65338,9 @@ CREATE TABLE `m3` ( `week` int(11) DEFAULT NULL, `day` int(11) DEFAULT NULL, `dayName` varchar(12) COLLATE utf8_unicode_ci DEFAULT NULL, - `euros` decimal(10,2) DEFAULT '0.00' -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + `euros` decimal(10,2) DEFAULT '0.00', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=71376 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -64178,7 +65586,24 @@ CREATE TABLE `productivity` ( `numPaletizadores` int(11) NOT NULL DEFAULT '0', `costPaletizado` double NOT NULL DEFAULT '0', PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=19107758 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=20651803 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `productivityDepartment` +-- + +DROP TABLE IF EXISTS `productivityDepartment`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `productivityDepartment` ( + `dated` date NOT NULL, + `amountCoordinacion` decimal(10,2) NOT NULL DEFAULT '0.00', + `amountSacado` decimal(10,2) NOT NULL DEFAULT '0.00', + `amountEncajado` decimal(10,2) NOT NULL DEFAULT '0.00', + `amountPaletizado` decimal(10,2) NOT NULL DEFAULT '0.00', + PRIMARY KEY (`dated`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -64205,7 +65630,8 @@ DROP TABLE IF EXISTS `salesByWeek`; CREATE TABLE `salesByWeek` ( `week` int(11) NOT NULL, `year` int(11) NOT NULL, - `sales` double DEFAULT NULL + `sales` double DEFAULT NULL, + UNIQUE KEY `week` (`week`,`year`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -64668,43 +66094,43 @@ DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `campaignComparative`(vDateFrom DATE, vDateTo DATE) BEGIN - SELECT - workerName, - id, - name, - CAST(SUM(previousAmmount) AS DECIMAL(10, 0)) AS previousAmmount, - CAST(SUM(currentAmmount) AS DECIMAL(10, 0)) AS currentAmmount - FROM ( - (SELECT - CONCAT(w.firstname, ' ', w.name) AS workerName, - c.id, - c.name, - SUM(v.importe) AS previousAmmount, - 0 currentAmmount - FROM bs.ventas v - INNER JOIN vn.`client` c ON v.Id_Cliente = c.id - INNER JOIN vn.worker w ON c.salesPersonFk = w.id - WHERE v.fecha BETWEEN DATE_ADD(vDateFrom, INTERVAL - 1 YEAR) - AND DATE_ADD(vDateTo, INTERVAL - 1 YEAR) - GROUP BY w.id, v.Id_Cliente) - UNION ALL - (SELECT - CONCAT(w.firstname, ' ', w.name) AS workerName, - c.id, - c.name, - 0 AS previousAmmount, - SUM(s.quantity * s.price) AS currentAmmount - FROM vn.sale s - JOIN vn.ticket t ON t.id = s.ticketFk - JOIN vn.client c ON c.id = t.clientFk - JOIN vn.worker w ON c.salesPersonFk = w.id - WHERE t.shipped BETWEEN vDateFrom - AND vDateTo - GROUP BY w.id, c.id) - ) comparative - GROUP BY workerName, id - HAVING (previousAmmount <> 0 OR currentAmmount <> 0) - ORDER BY workerName, id; + SELECT + workerName, + id, + name, + CAST(SUM(previousAmmount) AS DECIMAL(10, 0)) AS previousAmmount, + CAST(SUM(currentAmmount) AS DECIMAL(10, 0)) AS currentAmmount + FROM ( + (SELECT + CONCAT(w.firstname, ' ', w.lastName) AS workerName, + c.id, + c.name, + SUM(v.importe) AS previousAmmount, + 0 currentAmmount + FROM bs.ventas v + INNER JOIN vn.`client` c ON v.Id_Cliente = c.id + INNER JOIN vn.worker w ON c.salesPersonFk = w.id + WHERE v.fecha BETWEEN DATE_ADD(vDateFrom, INTERVAL - 1 YEAR) + AND DATE_ADD(vDateTo, INTERVAL - 1 YEAR) + GROUP BY w.id, v.Id_Cliente) + UNION ALL + (SELECT + CONCAT(w.firstname, ' ', w.lastName) AS workerName, + c.id, + c.name, + 0 AS previousAmmount, + SUM(s.quantity * s.price) AS currentAmmount + FROM vn.sale s + JOIN vn.ticket t ON t.id = s.ticketFk + JOIN vn.client c ON c.id = t.clientFk + JOIN vn.worker w ON c.salesPersonFk = w.id + WHERE t.shipped BETWEEN vDateFrom + AND vDateTo + GROUP BY w.id, c.id) + ) comparative + GROUP BY workerName, id + HAVING (previousAmmount <> 0 OR currentAmmount <> 0) + ORDER BY workerName, id; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -64758,23 +66184,24 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `clientDied`() BEGIN -IF DAY(CURDATE()) = 6 THEN + IF DAY(CURDATE()) = 6 THEN SET @primerAviso := TIMESTAMPADD(MONTH,-1,CURDATE()); SET @segundoAviso := TIMESTAMPADD(MONTH,-2,CURDATE()); SET @tercerAviso := TIMESTAMPADD(MONTH,-3,CURDATE()); TRUNCATE TABLE bs.clientDied; + INSERT INTO bs.clientDied - SELECT c.id, - c.name as clientName, - maxIssued as lastInvoiced, - w.code, - b.code as Boss, - CASE - WHEN IFNULL(maxIssued,'2000-01-01') < @tercerAviso THEN 'Tercer Aviso' - WHEN maxIssued < @segundoAviso THEN 'Segundo Aviso' - WHEN maxIssued < @primerAviso THEN 'Primer Aviso' + SELECT c.id, + c.name as clientName, + maxIssued as lastInvoiced, + w.code AS workerCode, + b.code AS Boss, + CASE + WHEN IFNULL(maxIssued,'2000-01-01') < @tercerAviso THEN 'Tercer Aviso' + WHEN maxIssued < @segundoAviso THEN 'Segundo Aviso' + WHEN maxIssued < @primerAviso THEN 'Primer Aviso' END as Aviso FROM vn.client c JOIN vn.worker w ON w.id = c.salesPersonFk @@ -64782,10 +66209,10 @@ IF DAY(CURDATE()) = 6 THEN JOIN vn.worker b ON b.id = j.boss_id JOIN bs.mana_spellers ms ON ms.Id_Trabajador = c.salesPersonFk LEFT JOIN (SELECT clientFk, max(issued) as maxIssued FROM vn.invoiceOut GROUP BY clientFk) io ON io.clientFk = c.id - WHERE (maxIssued IS NULL OR maxIssued < @primerAviso) - AND c.created < @tercerAviso; - -END IF; + WHERE (maxIssued IS NULL OR maxIssued < @primerAviso) + AND c.created < @tercerAviso; + + END IF; END ;; DELIMITER ; @@ -65362,8 +66789,7 @@ BEGIN DELETE FROM bs.m3 WHERE fecha >= datSTART; - - INSERT INTO bs.m3 + INSERT INTO bs.m3 (fecha, provinceFk, warehouseFk, m3, year, month, week, day, dayName, euros) SELECT v.fecha, a.provinceFk, t.warehouseFk, sum(s.quantity * r.cm3) / 1000000 AS m3, year(v.fecha), month(v.fecha), week(v.fecha), day(v.fecha), dayname(v.fecha), sum(importe) FROM vn.ticket t @@ -65487,37 +66913,32 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `mana_price_modifier_update`() -BEGIN - -INSERT INTO vn2008.daily_task_log(consulta) -VALUES ('bs.mana_price_modifier_update'); - -UPDATE mana_spellers -JOIN - (SELECT Id_Trabajador, floor(sum(importe)/12) as pesoCarteraMensual - FROM bs.vendedores v - WHERE año * 100 + mes >= (year(curdate()) -1) * 100 + month(curdate()) - GROUP BY Id_Trabajador - ) ultimo_año_de_ventas using(Id_Trabajador) -SET prices_modifier_rate = GREATEST(-0.05,LEAST(0.05,round(- used/pesoCarteraMensual,3))) ; - --- pak 20/11/18 Petición expresa de Miriam. Quiere un 1% mínimo -UPDATE mana_spellers -JOIN - (SELECT Id_Trabajador, floor(sum(importe)/12) as pesoCarteraMensual - FROM bs.vendedores v - WHERE año * 100 + mes >= (year(curdate()) -1) * 100 + month(curdate()) - AND Id_Trabajador = 24 -- Miriam - ) ultimo_año_de_ventas using(Id_Trabajador) -SET prices_modifier_rate = GREATEST(0.01,LEAST(0.05,round(- used/pesoCarteraMensual,3))) ; - +BEGIN + UPDATE mana_spellers + JOIN + (SELECT Id_Trabajador, floor(sum(importe)/12) as pesoCarteraMensual + FROM bs.vendedores v + WHERE año * 100 + mes >= (year(curdate()) -1) * 100 + month(curdate()) + GROUP BY Id_Trabajador + ) ultimo_año_de_ventas using(Id_Trabajador) + SET prices_modifier_rate = GREATEST(-0.05,LEAST(0.05,round(- used/pesoCarteraMensual,3))) ; + + -- pak 20/11/18 Petición expresa de Miriam. Quiere un 1% mínimo + UPDATE mana_spellers + JOIN + (SELECT Id_Trabajador, floor(sum(importe)/12) as pesoCarteraMensual + FROM bs.vendedores v + WHERE año * 100 + mes >= (year(curdate()) -1) * 100 + month(curdate()) + AND Id_Trabajador = 24 -- Miriam + ) ultimo_año_de_ventas using(Id_Trabajador) + SET prices_modifier_rate = GREATEST(0.01,LEAST(0.05,round(- used/pesoCarteraMensual,3))) ; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65585,90 +67006,86 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `nocturnEvent_Tickets_Bionizar`() -BEGIN -/* - - DECLARE vDone INT DEFAULT FALSE; - DECLARE vId BIGINT; - DECLARE vMaxSaleComponent DATE ; - DECLARE rs CURSOR FOR - SELECT sub.id - FROM (SELECT t.id as ticket,s.id, s.price *(1-(s.discount/100)) as price, SUM(sc.value) AS total, (s.price *(1-(s.discount/100)))- SUM(sc.value) as totales - FROM vn.ticket t - JOIN vn.sale s - ON s.ticketFk=t.id - JOIN vn.item i - ON i.id=s.itemFk - JOIN vn.itemType it - ON i.typeFk=it.id - LEFT JOIN vn.saleComponent sc - ON s.id=sc.saleFk - JOIN vn.warehouse w ON w.id=t.warehouseFk - WHERE t.shipped>=DATE_ADD(CURDATE(), INTERVAL -7 DAY) - AND it.categoryFk<6 - AND t.companyFk=442 - AND w.name!='Inventario' - GROUP BY s.id - HAVING ABS(price-IFNULL(total,0))>0.01 ) AS sub; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - - OPEN rs; - - read_loop: LOOP - FETCH rs INTO vId; - - IF vDone THEN - LEAVE read_loop; - END IF; - - CALL vn2008.bionic_calc_movement(vId); - - END LOOP; - CLOSE rs; - - -*/ - - -/* - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - - GET DIAGNOSTICS CONDITION 2 @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT; - SELECT CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')); - INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('jgallego@verdnatura.es', 'nocturnEvent_Tickets_Bionizar' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'))); - INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('pako@verdnatura.es', 'nocturnEvent_Tickets_Bionizar' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'))); - -END; -*/ -/* PAK 12/03/2018 No cal rebionitzar. Anem a intentar que els tickets es facen tots correctament. - -SET MyDate = timestampadd(week,-1,curdate()); - - INSERT INTO vn2008.daily_task_log(consulta) VALUES('Comença la rebionització de tickets '); - -WHILE MyDate < CURDATE() DO - - CALL `vn2008`.`bionic_tickets_range_bionizar`(MyDate, MyDate); - - SET MyDate = timestampadd(DAY,1,MyDate); - - SELECT MyDate; - -END WHILE; - - INSERT INTO vn2008.daily_task_log(consulta) VALUES('finalitza la rebionització de tickets '); -*/ - +BEGIN +/* + + DECLARE vDone INT DEFAULT FALSE; + DECLARE vId BIGINT; + DECLARE vMaxSaleComponent DATE ; + DECLARE rs CURSOR FOR + SELECT sub.id + FROM (SELECT t.id as ticket,s.id, s.price *(1-(s.discount/100)) as price, SUM(sc.value) AS total, (s.price *(1-(s.discount/100)))- SUM(sc.value) as totales + FROM vn.ticket t + JOIN vn.sale s + ON s.ticketFk=t.id + JOIN vn.item i + ON i.id=s.itemFk + JOIN vn.itemType it + ON i.typeFk=it.id + LEFT JOIN vn.saleComponent sc + ON s.id=sc.saleFk + JOIN vn.warehouse w ON w.id=t.warehouseFk + WHERE t.shipped>=DATE_ADD(CURDATE(), INTERVAL -7 DAY) + AND it.categoryFk<6 + AND t.companyFk=442 + AND w.name!='Inventario' + GROUP BY s.id + HAVING ABS(price-IFNULL(total,0))>0.01 ) AS sub; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + OPEN rs; + + read_loop: LOOP + FETCH rs INTO vId; + + IF vDone THEN + LEAVE read_loop; + END IF; + + CALL vn2008.bionic_calc_movement(vId); + + END LOOP; + CLOSE rs; + + +*/ + + +/* + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + + GET DIAGNOSTICS CONDITION 2 @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT; + SELECT CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')); + INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('jgallego@verdnatura.es', 'nocturnEvent_Tickets_Bionizar' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'))); + INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('pako@verdnatura.es', 'nocturnEvent_Tickets_Bionizar' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'))); + +END; +*/ +/* PAK 12/03/2018 No cal rebionitzar. Anem a intentar que els tickets es facen tots correctament. + +SET MyDate = timestampadd(week,-1,curdate()); + +WHILE MyDate < CURDATE() DO + + CALL `vn2008`.`bionic_tickets_range_bionizar`(MyDate, MyDate); + + SET MyDate = timestampadd(DAY,1,MyDate); + + SELECT MyDate; + +END WHILE; +*/ + END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65837,6 +67254,79 @@ BEGIN +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `productivityDepartmentAdd` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `productivityDepartmentAdd`(IN vDateStartPeriod DATETIME, IN vDateEndPeriod DATETIME, IN vDateStart DATETIME) +BEGIN + + DECLARE vEndingDate DATETIME; + + SET vEndingDate = vDateStart; + + WHILE vEndingDate <= vDateEndPeriod DO + REPLACE INTO bs.productivityDepartment + SELECT vEndingDate, + CAST(((productivityCoordinacionLastYear - productivityCoordinacion) / 2) * m3 AS DECIMAL (10,2)) AS amountCoordinacion, + CAST(((productivitySacadoLastYear - productivitySacado) / 2) * m3 AS DECIMAL (10,2)) AS amountSacado, + CAST(((productivityEncajadoLastYear - productivityEncajado) / 2) * m3 AS DECIMAL (10,2)) AS amountEncajado, + CAST(((productivityPaletizadoLastYear - productivityPaletizado) / 2) * m3 AS DECIMAL (10,2)) AS amountPaletizado + FROM + (SELECT + SUM(p.m3) AS m3, + SUM(p.costCoordinacion) / SUM(p.m3) AS productivityCoordinacion, + SUM(p.costSacado) / SUM(p.m3) AS productivitySacado, + SUM(p.costEncajado) / SUM(p.m3) AS productivityEncajado, + SUM(p.costPaletizado) / SUM(p.m3) AS productivityPaletizado + FROM + bs.productivity p + WHERE + p.dated BETWEEN vDateStartPeriod AND vEndingDate) sub + JOIN + (SELECT + SUM(p.costCoordinacion) / SUM(p.m3) AS productivityCoordinacionLastYear, + SUM(p.costSacado) / SUM(p.m3) AS productivitySacadoLastYear, + SUM(p.costEncajado) / SUM(p.m3) AS productivityEncajadoLastYear, + SUM(p.costPaletizado) / SUM(p.m3) AS productivityPaletizadoLastYear + FROM + bs.productivity p + WHERE + p.dated BETWEEN DATE_ADD(vDateStartPeriod, INTERVAL - 1 YEAR) AND DATE_ADD(vEndingDate, INTERVAL - 1 YEAR)) sub1; + + SET vEndingDate = TIMESTAMPADD(DAY,1, vEndingDate); + END WHILE; + END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `productivityDepartmentLauncher` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `productivityDepartmentLauncher`() +BEGIN + CALL bs.productivityDepartmentAdd('2018-11-01', CURDATE(),DATE_SUB(CURDATE(), INTERVAL 2 WEEK)); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -65856,14 +67346,18 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `productivityLauncher`() BEGIN - DECLARE vDateFrom DATE DEFAULT TIMESTAMPADD(MONTH, -3, CURDATE()); + DECLARE vDateFrom DATE DEFAULT TIMESTAMPADD(MONTH, -1, CURDATE()); WHILE CURDATE() > vDateFrom DO - - CALL bs.productivityAdd(vDateFrom); - + CALL bs.productivityAdd(vDateFrom); + SET vDateFrom = TIMESTAMPADD(DAY,1,vDateFrom); + END WHILE; + + SET vDateFrom = TIMESTAMPADD(MONTH, -13, CURDATE()); + + WHILE TIMESTAMPADD(MONTH, -12, CURDATE()) > vDateFrom DO + CALL bs.productivityAdd(vDateFrom); SET vDateFrom = TIMESTAMPADD(DAY,1,vDateFrom); - END WHILE; END ;; @@ -65949,7 +67443,7 @@ JOIN ( SELECT cc.Id_Trabajador_old as Id_Trabajador , sum(importe) * 0.029 * comision_old as cedido - + , sum(importe) * 0.029 * comision_new as arrendada FROM ventas v JOIN vn2008.Clientes c on v.Id_Cliente = c.Id_Cliente JOIN vn2008.Clientes_cedidos cc on cc.Id_Cliente = c.Id_Cliente @@ -65958,7 +67452,7 @@ WHERE time.year = intYEAR and time.month = intMONTH AND c.Id_Trabajador is not null GROUP BY cc.Id_Trabajador_old ) sub using(Id_Trabajador) -SET comisionCedida = cedido, comision = comision - cedido +SET comisionCedida = cedido, comision = comision - cedido - arrendada WHERE año = intYEAR and mes = intMONTH; -- Ventas arrendadas @@ -65977,7 +67471,7 @@ WHERE time.year = intYEAR and time.month = intMONTH AND c.Id_Trabajador is not null GROUP BY cc.Id_Trabajador_new ) sub using(Id_Trabajador) -SET comisionArrendada = arrendada, comision = comision - arrendada +SET comisionArrendada = arrendada WHERE año = intYEAR and mes = intMONTH; @@ -66456,7 +67950,7 @@ CREATE TABLE `Equalizator` ( `Impreso` int(11) DEFAULT NULL, `Encajado` int(11) DEFAULT NULL, PRIMARY KEY (`Vista`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -66528,13 +68022,51 @@ CREATE TABLE `Last_buy_id` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `Radar` +-- Table structure for table `Ticket_Portes` -- -DROP TABLE IF EXISTS `Radar`; +DROP TABLE IF EXISTS `Ticket_Portes`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `Radar` ( +CREATE TABLE `Ticket_Portes` ( + `Id_Ticket` int(11) NOT NULL, + `rate` tinyint(4) NOT NULL COMMENT 'Tarifa', + `real_amount` double NOT NULL COMMENT 'Cantidad pactada con la agencia', + `payed_amount` double NOT NULL COMMENT 'Cantidad reflejada en el Ticket', + PRIMARY KEY (`Id_Ticket`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `XDiario_ALL` +-- + +DROP TABLE IF EXISTS `XDiario_ALL`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `XDiario_ALL` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `empresa_id` int(5) NOT NULL, + `SUBCTA` varchar(11) COLLATE utf8_unicode_ci NOT NULL, + `Eurodebe` double DEFAULT NULL, + `Eurohaber` double DEFAULT NULL, + `Fecha` date DEFAULT NULL, + `FECHA_EX` date DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `Cuenta` (`SUBCTA`), + KEY `empresa` (`empresa_id`), + KEY `Fecha` (`Fecha`) +) ENGINE=InnoDB AUTO_INCREMENT=399125 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__Radar` +-- + +DROP TABLE IF EXISTS `__Radar`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__Radar` ( `Propio` int(1) NOT NULL DEFAULT '0', `Credito` double NOT NULL DEFAULT '0', `Riesgo` double(19,2) DEFAULT NULL, @@ -66559,39 +68091,98 @@ CREATE TABLE `Radar` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `Ticket_Portes` +-- Table structure for table `__comparativa_clientes` -- -DROP TABLE IF EXISTS `Ticket_Portes`; +DROP TABLE IF EXISTS `__comparativa_clientes`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `Ticket_Portes` ( - `Id_Ticket` int(11) NOT NULL, - `rate` tinyint(4) NOT NULL COMMENT 'Tarifa', - `real_amount` double NOT NULL COMMENT 'Cantidad pactada con la agencia', - `payed_amount` double NOT NULL COMMENT 'Cantidad reflejada en el Ticket', - PRIMARY KEY (`Id_Ticket`) +CREATE TABLE `__comparativa_clientes` ( + `Fecha` date NOT NULL DEFAULT '0000-00-00', + `Id_Cliente` int(11) NOT NULL DEFAULT '0', + `Propietario` int(11) DEFAULT NULL, + `titular` varchar(3) COLLATE utf8_unicode_ci NOT NULL, + `suplente` varchar(3) COLLATE utf8_unicode_ci NOT NULL, + `trabajador` int(11) DEFAULT NULL, + `actual` double DEFAULT NULL, + `pasado` double DEFAULT NULL, + `concepto` varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '', + KEY `cc_data_indez` (`Fecha`), + KEY `cc_Id_Cliente_index` (`Id_Cliente`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__dailyTaskLog` +-- + +DROP TABLE IF EXISTS `__dailyTaskLog`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__dailyTaskLog` ( + `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='No he encontrado el lugar en el que vicente almacena la hora en que se ejecutan las daily tasks, asi que he hecho esta tabla, a eliminar cuando se considere oportuno'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__saldos_bancos` +-- + +DROP TABLE IF EXISTS `__saldos_bancos`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__saldos_bancos` ( + `Semana` int(2) NOT NULL, + `Mes` int(2) NOT NULL, + `Año` int(4) NOT NULL, + `Entrada` double DEFAULT NULL, + `Salida` decimal(32,2) DEFAULT NULL, + `Saldo` double DEFAULT NULL, + `Id_Banco` int(11) NOT NULL DEFAULT '0', + `empresa_id` int(5) unsigned NOT NULL DEFAULT '0', + `Empresa` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT '' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `XDiario_ALL` +-- Table structure for table `__saldos_bancos_pordia` -- -DROP TABLE IF EXISTS `XDiario_ALL`; +DROP TABLE IF EXISTS `__saldos_bancos_pordia`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `XDiario_ALL` ( - `empresa_id` int(5) NOT NULL, - `SUBCTA` varchar(11) COLLATE utf8_unicode_ci NOT NULL, - `Eurodebe` double DEFAULT NULL, - `Eurohaber` double DEFAULT NULL, - `Fecha` date DEFAULT NULL, - `FECHA_EX` date DEFAULT NULL, - KEY `Cuenta` (`SUBCTA`), - KEY `empresa` (`empresa_id`), - KEY `Fecha` (`Fecha`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +CREATE TABLE `__saldos_bancos_pordia` ( + `Fecha` date NOT NULL, + `Entrada` double DEFAULT NULL, + `Salida` decimal(32,2) DEFAULT NULL, + `Saldo` double DEFAULT NULL, + `Id_Banco` int(11) NOT NULL DEFAULT '0', + `empresa_id` int(5) unsigned NOT NULL DEFAULT '0', + `Empresa` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT '', + `Año` int(4) NOT NULL, + `Mes` int(2) NOT NULL, + `Dia` int(2) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__sales` +-- + +DROP TABLE IF EXISTS `__sales`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__sales` ( + `Id_Trabajador` int(10) unsigned NOT NULL, + `year` int(10) unsigned NOT NULL, + `month` int(10) unsigned NOT NULL, + `weight` int(11) NOT NULL DEFAULT '0', + `boss_aid` int(10) NOT NULL DEFAULT '0', + `boss_id` int(10) NOT NULL DEFAULT '0', + `comision` int(11) DEFAULT NULL, + PRIMARY KEY (`Id_Trabajador`,`year`,`month`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -66604,7 +68195,8 @@ DROP TABLE IF EXISTS `analisis_grafico_simple`; CREATE TABLE `analisis_grafico_simple` ( `Año` smallint(5) unsigned NOT NULL, `Semana` tinyint(3) unsigned NOT NULL, - `Importe` double DEFAULT NULL + `Importe` double DEFAULT NULL, + UNIQUE KEY `Año` (`Año`,`Semana`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -66630,6 +68222,7 @@ DROP TABLE IF EXISTS `analisis_ventas`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `analisis_ventas` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `Familia` varchar(30) COLLATE utf8_unicode_ci NOT NULL, `Reino` varchar(45) COLLATE utf8_unicode_ci NOT NULL, `Comercial` varchar(3) COLLATE utf8_unicode_ci NOT NULL, @@ -66641,8 +68234,9 @@ CREATE TABLE `analisis_ventas` ( `Semana` tinyint(3) unsigned NOT NULL, `Vista` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, `Importe` double NOT NULL, + PRIMARY KEY (`id`), KEY `Año` (`Año`,`Semana`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=10174566 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -66658,7 +68252,7 @@ CREATE TABLE `analisis_ventas_almacen_evolution` ( `Ventas` int(11) NOT NULL, `Año` int(11) NOT NULL, `Periodo` int(11) NOT NULL, - KEY `Almacen` (`Almacen`,`Periodo`), + UNIQUE KEY `Almacen` (`Almacen`,`Periodo`), KEY `Periodo` (`Periodo`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -66694,7 +68288,7 @@ CREATE TABLE `analisis_ventas_familia_evolution` ( `ventas` int(11) NOT NULL, `año` int(11) NOT NULL, `periodo` int(11) NOT NULL, - KEY `familia` (`familia`,`periodo`), + UNIQUE KEY `familia` (`familia`,`periodo`), KEY `periodo` (`periodo`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -66835,28 +68429,6 @@ CREATE TABLE `claims_ratio` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `comparativa_clientesKk` --- - -DROP TABLE IF EXISTS `comparativa_clientesKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `comparativa_clientesKk` ( - `Fecha` date NOT NULL DEFAULT '0000-00-00', - `Id_Cliente` int(11) NOT NULL DEFAULT '0', - `Propietario` int(11) DEFAULT NULL, - `titular` varchar(3) COLLATE utf8_unicode_ci NOT NULL, - `suplente` varchar(3) COLLATE utf8_unicode_ci NOT NULL, - `trabajador` int(11) DEFAULT NULL, - `actual` double DEFAULT NULL, - `pasado` double DEFAULT NULL, - `concepto` varchar(10) CHARACTER SET utf8 NOT NULL DEFAULT '', - KEY `cc_data_indez` (`Fecha`), - KEY `cc_Id_Cliente_index` (`Id_Cliente`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `customerDebtInventory` -- @@ -66903,19 +68475,6 @@ CREATE TABLE `customer_risk` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Saldo de apertura < 2015-01-01'; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `dailyTaskLog` --- - -DROP TABLE IF EXISTS `dailyTaskLog`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `dailyTaskLog` ( - `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL, - `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='No he encontrado el lugar en el que vicente almacena la hora en que se ejecutan las daily tasks, asi que he hecho esta tabla, a eliminar cuando se considere oportuno'; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `defaulters` -- @@ -66946,7 +68505,7 @@ CREATE TABLE `defaulting` ( `date` date NOT NULL, `amount` double NOT NULL, PRIMARY KEY (`date`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -67132,66 +68691,6 @@ DELIMITER ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; --- --- Table structure for table `saldos_bancos` --- - -DROP TABLE IF EXISTS `saldos_bancos`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `saldos_bancos` ( - `Semana` int(2) NOT NULL, - `Mes` int(2) NOT NULL, - `Año` int(4) NOT NULL, - `Entrada` double DEFAULT NULL, - `Salida` decimal(32,2) DEFAULT NULL, - `Saldo` double DEFAULT NULL, - `Id_Banco` int(11) NOT NULL DEFAULT '0', - `empresa_id` int(5) unsigned NOT NULL DEFAULT '0', - `Empresa` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT '' -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `saldos_bancos_pordia` --- - -DROP TABLE IF EXISTS `saldos_bancos_pordia`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `saldos_bancos_pordia` ( - `Fecha` date NOT NULL, - `Entrada` double DEFAULT NULL, - `Salida` decimal(32,2) DEFAULT NULL, - `Saldo` double DEFAULT NULL, - `Id_Banco` int(11) NOT NULL DEFAULT '0', - `empresa_id` int(5) unsigned NOT NULL DEFAULT '0', - `Empresa` varchar(3) CHARACTER SET utf8 NOT NULL DEFAULT '', - `Año` int(4) NOT NULL, - `Mes` int(2) NOT NULL, - `Dia` int(2) NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `salesKk` --- - -DROP TABLE IF EXISTS `salesKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `salesKk` ( - `Id_Trabajador` int(10) unsigned NOT NULL, - `year` int(10) unsigned NOT NULL, - `month` int(10) unsigned NOT NULL, - `weight` int(11) NOT NULL DEFAULT '0', - `boss_aid` int(10) NOT NULL DEFAULT '0', - `boss_id` int(10) NOT NULL DEFAULT '0', - `comision` int(11) DEFAULT NULL, - PRIMARY KEY (`Id_Trabajador`,`year`,`month`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `tarifa_componentes` -- @@ -67669,54 +69168,62 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `analisis_ventas_update`() -BEGIN - - DECLARE vLastMonth DATE; - - SET vLastMonth = util.firstDayOfMonth(TIMESTAMPADD(MONTH, -1, CURDATE())); - - DELETE FROM bi.analisis_ventas - WHERE Año > YEAR(vLastMonth) - OR (Año = YEAR(vLastMonth) AND Mes >= MONTH(vLastMonth)); - - INSERT INTO bi.analisis_ventas - - SELECT - `tp`.`Tipo` AS `Familia`, - `r`.`reino` AS `Reino`, - `tr`.`CodigoTrabajador` AS `Comercial`, - `tr2`.`CodigoTrabajador` AS `Comprador`, - `p`.`name` AS `Provincia`, - `w`.`name` AS `almacen`, - `time`.`year` AS `Año`, - `time`.`month` AS `Mes`, - `time`.`week` AS `Semana`, - `v`.`vista` AS `Vista`, - `bt`.`importe` AS `Importe` - FROM - (((((((((`bs`.`ventas` `bt` - LEFT JOIN `vn2008`.`Tipos` `tp` ON ((`tp`.`tipo_id` = `bt`.`tipo_id`))) - LEFT JOIN `vn2008`.`reinos` `r` ON ((`r`.`id` = `tp`.`reino_id`))) - LEFT JOIN `vn2008`.`Clientes` c on c.Id_Cliente = bt.Id_Cliente - LEFT JOIN `vn2008`.`Trabajadores` `tr` ON ((`tr`.`Id_Trabajador` = `c`.`Id_Trabajador`))) - LEFT JOIN `vn2008`.`Trabajadores` `tr2` ON ((`tr2`.`Id_Trabajador` = `tp`.`Id_Trabajador`))) - JOIN vn2008.time on time.date = bt.fecha - JOIN vn2008.Movimientos m on m.Id_Movimiento = bt.Id_Movimiento - LEFT JOIN `vn2008`.`Tickets` `t` ON ((`t`.`Id_Ticket` = `m`.`Id_Ticket`))) - JOIN vn2008.Agencias a on a.Id_Agencia = t.Id_Agencia - LEFT JOIN `vn2008`.`Vistas` `v` ON ((`v`.`vista_id` = `a`.`Vista`))) - LEFT JOIN `vn2008`.`Consignatarios` `cs` ON ((`cs`.`Id_Consigna` = `t`.`Id_Consigna`))) - LEFT JOIN `vn2008`.`province` `p` ON ((`p`.`province_id` = `cs`.`province_id`))) - LEFT JOIN `vn2008`.`warehouse` `w` ON ((`w`.`id` = `t`.`warehouse_id`))) - WHERE bt.fecha >= vLastMonth AND r.mercancia; - +BEGIN + DECLARE vLastMonth DATE; + + SET vLastMonth = util.firstDayOfMonth(TIMESTAMPADD(MONTH, -1, CURDATE())); + + DELETE FROM analisis_ventas + WHERE Año > YEAR(vLastMonth) + OR (Año = YEAR(vLastMonth) AND Mes >= MONTH(vLastMonth)); + + INSERT INTO analisis_ventas ( + Familia, + Reino, + Comercial, + Comprador, + Provincia, + almacen, + Año, + Mes, + Semana, + Vista, + Importe + ) + SELECT + tp.Tipo AS Familia, + r.reino AS Reino, + tr.CodigoTrabajador AS Comercial, + tr2.CodigoTrabajador AS Comprador, + p.name AS Provincia, + w.name AS almacen, + tm.year AS Año, + tm.month AS Mes, + tm.week AS Semana, + v.vista AS Vista, + bt.importe AS Importe + FROM bs.ventas bt + LEFT JOIN vn2008.Tipos tp ON tp.tipo_id = bt.tipo_id + LEFT JOIN vn2008.reinos r ON r.id = tp.reino_id + LEFT JOIN vn2008.Clientes c on c.Id_Cliente = bt.Id_Cliente + LEFT JOIN vn2008.Trabajadores tr ON tr.Id_Trabajador = c.Id_Trabajador + LEFT JOIN vn2008.Trabajadores tr2 ON tr2.Id_Trabajador = tp.Id_Trabajador + JOIN vn2008.time tm ON tm.date = bt.fecha + JOIN vn2008.Movimientos m ON m.Id_Movimiento = bt.Id_Movimiento + LEFT JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + JOIN vn2008.Agencias a ON a.Id_Agencia = t.Id_Agencia + LEFT JOIN vn2008.Vistas v ON v.vista_id = a.Vista + LEFT JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = t.Id_Consigna + LEFT JOIN vn2008.province p ON p.province_id = cs.province_id + LEFT JOIN vn2008.warehouse w ON w.id = t.warehouse_id + WHERE bt.fecha >= vLastMonth AND r.mercancia; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -67727,46 +69234,40 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `call_add`() -BEGIN - -DECLARE datSTART DATETIME DEFAULT '2012-03-01'/*CURDATE()*/ ; --- control -INSERT INTO vn2008.daily_task_log(consulta) VALUES('bi.call_add'); - --- Seleccionamos la ultima fecha introducida -SELECT MAX(Fecha) INTO datSTART FROM `call`; - - --- Borramos todas las entradas del dia datSTART por si hubiese registros nuevos -DELETE FROM `call` WHERE Fecha = datSTART; - -INSERT INTO bi.`call`(CodTrabajadorCartera,CodTrabajadorTelefono,dur_in,dur_out,Fecha,`year`,`month`,`week`,`hour`,phone) -SELECT vn2008.Averiguar_ComercialCliente(pb.Id_Cliente,Fecha) CodTrabajadorCartera,ll.CodigoTrabajador, dur_in, - dur_out, ll.Fecha,YEAR(ll.Fecha) `year`, MONTH(ll.Fecha) `month`,WEEK(ll.Fecha,7) `week`, Hora,phone -FROM -( -SELECT Id_Trabajador,CodigoTrabajador, IFNULL(billsec,0) dur_in, 0 dur_out, 1 as Recibidas, NULL as Emitidas, calldate as Fecha, - hour(calldate) as Hora,src as phone -FROM vn2008.Trabajadores T -INNER JOIN vn2008.cdr C ON C.dstchannel LIKE CONCAT('%', T.extension, '%') -WHERE calldate >= datSTART AND LENGTH(C.src) >=9 AND disposition = 'ANSWERED' AND duration -UNION ALL -SELECT Id_Trabajador,CodigoTrabajador,0 dur_in, IFNULL(billsec,0) dur_out, NULL as Recibidas, 1 as Emitidas, date(calldate), hour(calldate),dst -FROM vn2008.Trabajadores T -INNER JOIN vn2008.cdr C ON C.src = T.extension -WHERE calldate >= datSTART AND LENGTH(C.dst) >=9 AND disposition = 'ANSWERED' AND duration -) ll -INNER JOIN vn2008.Permisos USING(Id_Trabajador) -LEFT JOIN vn2008.v_phonebook pb ON pb.Telefono = ll.phone -WHERE Id_Grupo = 6; - +BEGIN + DECLARE datSTART DATETIME DEFAULT '2012-03-01'/*CURDATE()*/ ; + + -- Seleccionamos la ultima fecha introducida + SELECT MAX(Fecha) INTO datSTART FROM `call`; + + -- Borramos todas las entradas del dia datSTART por si hubiese registros nuevos + DELETE FROM `call` WHERE Fecha = datSTART; + + INSERT INTO bi.`call`(CodTrabajadorCartera,CodTrabajadorTelefono,dur_in,dur_out,Fecha,`year`,`month`,`week`,`hour`,phone) + SELECT vn2008.Averiguar_ComercialCliente(pb.Id_Cliente,Fecha) CodTrabajadorCartera,ll.CodigoTrabajador, dur_in, + dur_out, ll.Fecha,YEAR(ll.Fecha) `year`, MONTH(ll.Fecha) `month`,WEEK(ll.Fecha,7) `week`, Hora,phone + FROM ( + SELECT Id_Trabajador,CodigoTrabajador, IFNULL(billsec,0) dur_in, 0 dur_out, 1 as Recibidas, NULL as Emitidas, calldate as Fecha, + hour(calldate) as Hora,src as phone + FROM vn2008.Trabajadores T + JOIN vn2008.cdr C ON C.dstchannel LIKE CONCAT('%', T.extension, '%') + WHERE calldate >= datSTART AND LENGTH(C.src) >=9 AND disposition = 'ANSWERED' AND duration + UNION ALL + SELECT Id_Trabajador,CodigoTrabajador,0 dur_in, IFNULL(billsec,0) dur_out, NULL as Recibidas, 1 as Emitidas, date(calldate), hour(calldate),dst + FROM vn2008.Trabajadores T + JOIN vn2008.cdr C ON C.src = T.extension + WHERE calldate >= datSTART AND LENGTH(C.dst) >=9 AND disposition = 'ANSWERED' AND duration + ) ll + JOIN vn2008.Permisos USING(Id_Trabajador) + LEFT JOIN vn2008.v_phonebook pb ON pb.Telefono = ll.phone + WHERE Id_Grupo = 6; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -67777,221 +69278,212 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `claim_ratio_routine`() -BEGIN - -DECLARE vMonthToRefund INT DEFAULT 4; - --- control -INSERT INTO vn2008.daily_task_log(consulta) - VALUES('bi.claim_ratio_routine START'); - -/* -* PAK 2015-11-20 -* Se trata de añadir a la tabla Greuges todos los -* cargos que luego vamos a utilizar para calcular el recobro -*/ - --- descuentos comerciales COD 11 - -INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario, Importe, Id_Ticket) - SELECT Fecha, Id_Cliente, Concat('COD11 : ',Concepte), - round(Cantidad * - Preu * (100 - Descuento) / 100 ,2) AS Importe, t.Id_Ticket - FROM vn2008.Tickets t - JOIN vn2008.Movimientos m ON m.Id_Ticket = t.Id_Ticket - WHERE Id_Article = 11 - AND Concepte NOT LIKE '$%' - AND Fecha > '2014-01-01' - HAVING nz(Importe) <> 0; - -DELETE mc.* - FROM vn2008.Movimientos_componentes mc - JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento - JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket - WHERE m.Id_Article = 11 - AND m.Concepte NOT LIKE '$%' - AND t.Fecha > '2017-01-01'; - -INSERT INTO vn2008.Movimientos_componentes(Id_Movimiento, Id_Componente, Valor) - SELECT m.Id_Movimiento, 34, round(m.Preu * (100 - m.Descuento)/100,4) - FROM vn2008.Movimientos m - JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket - WHERE m.Id_Article = 11 - AND m.Concepte NOT LIKE '$%' - AND t.Fecha > '2017-01-01'; - -UPDATE vn2008.Movimientos m - JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket - SET Concepte = CONCAT('$ ',Concepte) - WHERE Id_Article = 11 - AND Concepte NOT LIKE '$%' - AND Fecha > '2014-01-01'; - --- Reclamaciones demasiado sensibles - -INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario, - Importe, Greuges_type_id,Id_Ticket) - SELECT cm.Fecha - , cm.Id_Cliente - , concat('Claim ',cm.id,' : ', m.Concepte) - ,round( -1 * ((sensib -1)/4) * Cantidad * - Preu * (100 - Descuento) / 100, 2) AS Reclamaciones - , 4 - , m.Id_Ticket - FROM vn2008.Movimientos m - JOIN vn2008.cl_act ca USING(Id_Movimiento) - JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id - WHERE ca.cl_sol_id NOT IN (1,5) - AND ca.greuge = 0 - AND cm.cl_est_id = 3; - - -- Reclamaciones que pasan a Maná - -INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario, - Importe , Greuges_type_id,Id_Ticket) - SELECT cm.Fecha - , cm.Id_Cliente - , concat('Claim_mana ',cm.id,' : ', m.Concepte) - ,round( ((sensib -1)/4) * Cantidad * Preu * (100 - Descuento) / 100, 2) - AS Reclamaciones - ,3 - ,m.Id_Ticket - FROM vn2008.Movimientos m - JOIN vn2008.cl_act ca USING(Id_Movimiento) - JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id - WHERE ca.cl_sol_id NOT IN (1,5) - AND ca.greuge = 0 - AND cm.cl_est_id = 3 - AND cm.mana; - - -- Marcamos para no repetir -UPDATE vn2008.cl_act ca - JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id - SET greuge = 1 - WHERE ca.cl_sol_id NOT IN (1,5) - AND ca.greuge = 0 - AND cm.cl_est_id = 3; - - - --- Recobros - -DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; -CREATE TEMPORARY TABLE tmp.ticket_list -(PRIMARY KEY (Id_Ticket)) -SELECT DISTINCT t.Id_Ticket - FROM vn2008.Movimientos_componentes mc - JOIN vn2008.Movimientos m ON mc.Id_Movimiento = m.Id_Movimiento - JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket - JOIN vn2008.Tickets_state ts ON ts.Id_Ticket = t.Id_Ticket - JOIN vncontrol.inter i ON i.inter_id = ts.inter_id - JOIN vn2008.state s ON s.id = i.state_id - WHERE mc.Id_Componente = 17 - AND mc.greuge = 0 - AND t.Fecha >= '2016-10-01' - AND t.Fecha < CURDATE() - AND t.warehouse_id <> 41 - AND s.alert_level >= 3; - -DELETE g.* - FROM vn2008.Greuges g - JOIN tmp.ticket_list t ON g.Id_Ticket = t.Id_Ticket - WHERE Greuges_type_id = 2; - -INSERT INTO vn2008.Greuges (Id_Cliente,Comentario,Importe,Fecha, - Greuges_type_id, Id_Ticket) - SELECT Id_Cliente - ,concat('recobro ', m.Id_Ticket), - round(SUM(mc.Valor*Cantidad),2) - AS dif - ,date(t.Fecha) - , 2 - ,tt.Id_Ticket - FROM vn2008.Movimientos m - JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket - JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.Id_Ticket - JOIN vn2008.Movimientos_componentes mc - ON mc.Id_Movimiento = m.Id_Movimiento AND mc.Id_Componente = 17 - GROUP BY t.Id_Ticket - HAVING ABS(dif) > 1; - -UPDATE vn2008.Movimientos_componentes mc - JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento - JOIN tmp.ticket_list tt ON tt.Id_Ticket = m.Id_Ticket - SET greuge = 1 - WHERE Id_Componente = 17; - -/* -* Recalculamos la ratio de las reclamaciones, que luego -* se va a utilizar en el recobro -*/ - -REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro) - SELECT Id_Cliente, 0,0,0,0 - FROM vn2008.Clientes; - -REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro) - SELECT fm.Id_Cliente, 12 * fm.Consumo, Reclamaciones, - round(Reclamaciones / (12*fm.Consumo),4) AS Ratio, 0 - FROM bi.facturacion_media_anual fm - LEFT JOIN( - SELECT cm.Id_Cliente, round(sum(-1 * ((sensib -1)/4) * - Cantidad * Preu * (100 - Descuento) / 100)) - AS Reclamaciones - FROM vn2008.Movimientos m - JOIN vn2008.cl_act ca - ON ca.Id_Movimiento = m.Id_Movimiento - JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id - WHERE ca.cl_sol_id NOT IN (1,5) - AND cm.cl_est_id = 3 - AND cm.Fecha >= TIMESTAMPADD(YEAR, -1, CURDATE()) - GROUP BY cm.Id_Cliente - ) claims ON claims.Id_Cliente = fm.Id_Cliente; - - --- Calculamos el porcentaje del recobro para añadirlo al precio de venta -UPDATE bi.claims_ratio cr - JOIN ( - SELECT Id_Cliente, nz(SUM(Importe)) AS Greuge - FROM vn2008.Greuges - WHERE Fecha <= CURDATE() - GROUP BY Id_Cliente - ) g ON g.Id_Cliente = cr.Id_Cliente - SET recobro = GREATEST(0,round(nz(Greuge) / - (nz(Consumo) * vMonthToRefund / 12 ) ,3)); - --- Protección neonatos -UPDATE bi.claims_ratio cr - JOIN vn.firstTicketShipped fts ON fts.clientFk = cr.Id_Cliente - SET recobro = 0, Ratio = 0 - WHERE fts.shipped > TIMESTAMPADD(MONTH,-1,CURDATE()); - --- CLIENTE 7983, JULIAN SUAU -UPDATE bi.claims_ratio SET recobro = LEAST(0.05, recobro) WHERE Id_Cliente = 7983; - --- CLIENTE 3504, VAZQUEZ --- UPDATE bi.claims_ratio SET recobro = GREATEST(0.08, recobro) WHERE Id_Cliente = 3504; - --- CLIENTE 5523, VERDECORA -UPDATE bi.claims_ratio SET recobro = GREATEST(0.12, recobro) WHERE Id_Cliente = 5523; - --- CLIENTE 5189 i 8942, son de CSR i son el mateix client -UPDATE bi.claims_ratio cr - JOIN (SELECT sum(Consumo * recobro)/sum(Consumo) as recobro - FROM bi.claims_ratio - WHERE Id_Cliente IN ( 5189,8942) - ) sub - SET cr.recobro = sub.recobro - WHERE Id_Cliente IN ( 5189,8942); - --- control -INSERT INTO vn2008.daily_task_log(consulta) - VALUES('bi.claim_ratio_routine END'); +BEGIN + DECLARE vMonthToRefund INT DEFAULT 4; + + /* + * PAK 2015-11-20 + * Se trata de añadir a la tabla Greuges todos los + * cargos que luego vamos a utilizar para calcular el recobro + */ + + -- descuentos comerciales COD 11 + + INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario, Importe, Id_Ticket) + SELECT Fecha, Id_Cliente, Concat('COD11 : ',Concepte), - round(Cantidad * + Preu * (100 - Descuento) / 100 ,2) AS Importe, t.Id_Ticket + FROM vn2008.Tickets t + JOIN vn2008.Movimientos m ON m.Id_Ticket = t.Id_Ticket + WHERE Id_Article = 11 + AND Concepte NOT LIKE '$%' + AND Fecha > '2014-01-01' + HAVING nz(Importe) <> 0; + + DELETE mc.* + FROM vn2008.Movimientos_componentes mc + JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento + JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + WHERE m.Id_Article = 11 + AND m.Concepte NOT LIKE '$%' + AND t.Fecha > '2017-01-01'; + + INSERT INTO vn2008.Movimientos_componentes(Id_Movimiento, Id_Componente, Valor) + SELECT m.Id_Movimiento, 34, round(m.Preu * (100 - m.Descuento)/100,4) + FROM vn2008.Movimientos m + JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + WHERE m.Id_Article = 11 + AND m.Concepte NOT LIKE '$%' + AND t.Fecha > '2017-01-01'; + + UPDATE vn2008.Movimientos m + JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + SET Concepte = CONCAT('$ ',Concepte) + WHERE Id_Article = 11 + AND Concepte NOT LIKE '$%' + AND Fecha > '2014-01-01'; + + -- Reclamaciones demasiado sensibles + + INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario, + Importe, Greuges_type_id,Id_Ticket) + SELECT cm.Fecha + , cm.Id_Cliente + , concat('Claim ',cm.id,' : ', m.Concepte) + ,round( -1 * ((sensib -1)/4) * Cantidad * + Preu * (100 - Descuento) / 100, 2) AS Reclamaciones + , 4 + , m.Id_Ticket + FROM vn2008.Movimientos m + JOIN vn2008.cl_act ca USING(Id_Movimiento) + JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id + WHERE ca.cl_sol_id NOT IN (1,5) + AND ca.greuge = 0 + AND cm.cl_est_id = 3; + + -- Reclamaciones que pasan a Maná + + INSERT INTO vn2008.Greuges(Fecha, Id_Cliente, Comentario, + Importe , Greuges_type_id,Id_Ticket) + SELECT cm.Fecha + , cm.Id_Cliente + , concat('Claim_mana ',cm.id,' : ', m.Concepte) + ,round( ((sensib -1)/4) * Cantidad * Preu * (100 - Descuento) / 100, 2) + AS Reclamaciones + ,3 + ,m.Id_Ticket + FROM vn2008.Movimientos m + JOIN vn2008.cl_act ca USING(Id_Movimiento) + JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id + WHERE ca.cl_sol_id NOT IN (1,5) + AND ca.greuge = 0 + AND cm.cl_est_id = 3 + AND cm.mana; + + -- Marcamos para no repetir + UPDATE vn2008.cl_act ca + JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id + SET greuge = 1 + WHERE ca.cl_sol_id NOT IN (1,5) + AND ca.greuge = 0 + AND cm.cl_est_id = 3; + + + + -- Recobros + + DROP TEMPORARY TABLE IF EXISTS tmp.ticket_list; + CREATE TEMPORARY TABLE tmp.ticket_list + (PRIMARY KEY (Id_Ticket)) + SELECT DISTINCT t.Id_Ticket + FROM vn2008.Movimientos_componentes mc + JOIN vn2008.Movimientos m ON mc.Id_Movimiento = m.Id_Movimiento + JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + JOIN vn2008.Tickets_state ts ON ts.Id_Ticket = t.Id_Ticket + JOIN vncontrol.inter i ON i.inter_id = ts.inter_id + JOIN vn2008.state s ON s.id = i.state_id + WHERE mc.Id_Componente = 17 + AND mc.greuge = 0 + AND t.Fecha >= '2016-10-01' + AND t.Fecha < CURDATE() + AND t.warehouse_id <> 41 + AND s.alert_level >= 3; + + DELETE g.* + FROM vn2008.Greuges g + JOIN tmp.ticket_list t ON g.Id_Ticket = t.Id_Ticket + WHERE Greuges_type_id = 2; + + INSERT INTO vn2008.Greuges (Id_Cliente,Comentario,Importe,Fecha, + Greuges_type_id, Id_Ticket) + SELECT Id_Cliente + ,concat('recobro ', m.Id_Ticket), - round(SUM(mc.Valor*Cantidad),2) + AS dif + ,date(t.Fecha) + , 2 + ,tt.Id_Ticket + FROM vn2008.Movimientos m + JOIN vn2008.Tickets t ON t.Id_Ticket = m.Id_Ticket + JOIN tmp.ticket_list tt ON tt.Id_Ticket = t.Id_Ticket + JOIN vn2008.Movimientos_componentes mc + ON mc.Id_Movimiento = m.Id_Movimiento AND mc.Id_Componente = 17 + GROUP BY t.Id_Ticket + HAVING ABS(dif) > 1; + + UPDATE vn2008.Movimientos_componentes mc + JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento + JOIN tmp.ticket_list tt ON tt.Id_Ticket = m.Id_Ticket + SET greuge = 1 + WHERE Id_Componente = 17; + + /* + * Recalculamos la ratio de las reclamaciones, que luego + * se va a utilizar en el recobro + */ + + REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro) + SELECT Id_Cliente, 0,0,0,0 + FROM vn2008.Clientes; + + REPLACE bi.claims_ratio(Id_Cliente, Consumo, Reclamaciones, Ratio, recobro) + SELECT fm.Id_Cliente, 12 * fm.Consumo, Reclamaciones, + round(Reclamaciones / (12*fm.Consumo),4) AS Ratio, 0 + FROM bi.facturacion_media_anual fm + LEFT JOIN( + SELECT cm.Id_Cliente, round(sum(-1 * ((sensib -1)/4) * + Cantidad * Preu * (100 - Descuento) / 100)) + AS Reclamaciones + FROM vn2008.Movimientos m + JOIN vn2008.cl_act ca + ON ca.Id_Movimiento = m.Id_Movimiento + JOIN vn2008.cl_main cm ON cm.id = ca.cl_main_id + WHERE ca.cl_sol_id NOT IN (1,5) + AND cm.cl_est_id = 3 + AND cm.Fecha >= TIMESTAMPADD(YEAR, -1, CURDATE()) + GROUP BY cm.Id_Cliente + ) claims ON claims.Id_Cliente = fm.Id_Cliente; + + + -- Calculamos el porcentaje del recobro para añadirlo al precio de venta + UPDATE bi.claims_ratio cr + JOIN ( + SELECT Id_Cliente, nz(SUM(Importe)) AS Greuge + FROM vn2008.Greuges + WHERE Fecha <= CURDATE() + GROUP BY Id_Cliente + ) g ON g.Id_Cliente = cr.Id_Cliente + SET recobro = GREATEST(0,round(nz(Greuge) / + (nz(Consumo) * vMonthToRefund / 12 ) ,3)); + + -- Protección neonatos + UPDATE bi.claims_ratio cr + JOIN vn.firstTicketShipped fts ON fts.clientFk = cr.Id_Cliente + SET recobro = 0, Ratio = 0 + WHERE fts.shipped > TIMESTAMPADD(MONTH,-1,CURDATE()); + + -- CLIENTE 7983, JULIAN SUAU + UPDATE bi.claims_ratio SET recobro = LEAST(0.05, recobro) WHERE Id_Cliente = 7983; + + -- CLIENTE 3504, VAZQUEZ + -- UPDATE bi.claims_ratio SET recobro = GREATEST(0.08, recobro) WHERE Id_Cliente = 3504; + + -- CLIENTE 5523, VERDECORA + UPDATE bi.claims_ratio SET recobro = GREATEST(0.12, recobro) WHERE Id_Cliente = 5523; + + -- CLIENTE 5189 i 8942, son de CSR i son el mateix client + UPDATE bi.claims_ratio cr + JOIN (SELECT sum(Consumo * recobro)/sum(Consumo) as recobro + FROM bi.claims_ratio + WHERE Id_Cliente IN ( 5189,8942) + ) sub + SET cr.recobro = sub.recobro + WHERE Id_Cliente IN ( 5189,8942); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -68002,35 +69494,30 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `clean`() -BEGIN -DECLARE vDateShort DATETIME; -DECLARE vDateLong DATETIME; -DECLARE vOneYearAgo DATETIME; - -SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE()); -SET vDateLong = TIMESTAMPADD(MONTH, -18,CURDATE()); -SET vOneYearAgo = TIMESTAMPADD(YEAR, -1,CURDATE()); - -INSERT INTO bi.dailyTaskLog(state) VALUES('clean START'); - --- DELETE FROM bi.comparativa_clientes WHERE Fecha < vDateLong; - -DELETE - FROM bi.Greuge_Evolution - WHERE (Fecha < vDateShort AND weekday(Fecha) != 1) - OR Fecha < vOneYearAgo; - -DELETE FROM bi.defaulters WHERE `date` < vDateLong; -DELETE FROM bi.defaulting WHERE `date` < vDateLong; - -INSERT INTO bi.dailyTaskLog(state) VALUES('clean END'); +BEGIN + DECLARE vDateShort DATETIME; + DECLARE vDateLong DATETIME; + DECLARE vOneYearAgo DATETIME; + + SET vDateShort = TIMESTAMPADD(MONTH, -2, CURDATE()); + SET vDateLong = TIMESTAMPADD(MONTH, -18,CURDATE()); + SET vOneYearAgo = TIMESTAMPADD(YEAR, -1,CURDATE()); + + -- DELETE FROM bi.comparativa_clientes WHERE Fecha < vDateLong; + + DELETE FROM bi.Greuge_Evolution + WHERE (Fecha < vDateShort AND weekday(Fecha) != 1) + OR Fecha < vOneYearAgo; + + DELETE FROM bi.defaulters WHERE `date` < vDateLong; + DELETE FROM bi.defaulting WHERE `date` < vDateLong; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -68203,24 +69690,24 @@ DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `defaultersFromDate`(IN vDate DATE) BEGIN -SELECT t1.*, c.Cliente, w.code, c.pay_met_id,c.Vencimiento -FROM ( --- Filtramos aquellos clientes cuyo saldo se ha incrementado de ayer a hoy - select * from( - select today.client, today.amount todayAmount, yesterday.amount yesterdayAmount, round(yesterday.amount - today.amount,2) as difference, defaulterSince - from - (select client, amount, defaulterSince - from defaulters - where date = vDate and hasChanged) today - join - (select client, amount - from defaulters - where date = TIMESTAMPADD(DAY,-1,vDate)) yesterday using(client) - - having today.amount > 0 and difference <> 0 - ) newDefaulters -)t1 left join vn2008.Clientes c ON t1.client = c.Id_Cliente - left join vn.worker w ON w.id = c.Id_Trabajador; + SELECT t1.*, c.Cliente, w.code AS workerCode, c.pay_met_id,c.Vencimiento + FROM ( + -- Filtramos aquellos clientes cuyo saldo se ha incrementado de ayer a hoy + select * from( + select today.client, today.amount todayAmount, yesterday.amount yesterdayAmount, round(yesterday.amount - today.amount,2) as difference, defaulterSince + from + (select client, amount, defaulterSince + from defaulters + where date = vDate and hasChanged) today + join + (select client, amount + from defaulters + where date = TIMESTAMPADD(DAY,-1,vDate)) yesterday using(client) + + having today.amount > 0 and difference <> 0 + ) newDefaulters + )t1 left join vn2008.Clientes c ON t1.client = c.Id_Cliente + left join vn.worker w ON w.id = c.Id_Trabajador; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -68231,191 +69718,91 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `defaulting`(IN vDate DATE) -BEGIN -/*JGF para usar el campo vencimiento de facturas*/ - DECLARE vDone BOOLEAN; - DECLARE vClient INT; - DECLARE vAmount INT; - DECLARE vDued DATE; - DECLARE vAmountInvoice DECIMAL(10,2); - DECLARE vGraceDays INT; - DECLARE defaulters CURSOR FOR - SELECT client, amount, graceDays FROM bi.defaulters d - JOIN vn2008.Clientes c ON c.Id_Cliente = d.client - JOIN vn2008.pay_met pm ON pm.id = c.pay_met_id - WHERE hasChanged AND date = vDate; - - DECLARE invoices CURSOR FOR - SELECT Vencimiento, importe FROM vn2008.Facturas f - WHERE f.Fecha >= '2016-01-01' AND f.Id_Cliente = vClient ORDER BY f.Fecha DESC; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - -- Control - - INSERT INTO vn2008.daily_task_log(consulta) VALUES('defaulting'); - - DELETE FROM bi.defaulters WHERE date = vDate; - - INSERT INTO bi.defaulters(client, date, amount) - SELECT customer_id, vDate, FLOOR(SUM(amount)) AS amount - FROM bi.customerRiskOverdue - GROUP BY customer_id; - - -- marcamos si ha cambiado y heredamos la fecha defaulterSince - UPDATE bi.defaulters d - JOIN ( - SELECT * FROM( - SELECT client, amount , defaulterSince FROM bi.defaulters - WHERE date <= TIMESTAMPADD(DAY,-1, vDate) - ORDER BY date DESC) t GROUP BY client - ) yesterday using(client) - SET d.hasChanged = IF(d.amount <> yesterday.amount, 1, 0), - d.defaulterSince = yesterday.defaulterSince - WHERE d.date = vDate ; - - OPEN defaulters; - defaulters: LOOP - SET vDone = FALSE; - SET vAmount = 0; - FETCH defaulters INTO vClient,vAmount, vGraceDays; - IF vDone THEN - LEAVE defaulters; - END IF; - OPEN invoices; - invoices:LOOP - - FETCH invoices INTO vDued, vAmountInvoice; - IF vDone THEN - LEAVE invoices; - END IF; - - IF TIMESTAMPADD(DAY, vGraceDays, vDued) <= vDate THEN - SET vAmount = vAmount - vAmountInvoice; - IF vAmount <= 0 THEN - - UPDATE defaulters SET defaulterSince = vDued - WHERE client = vClient and date = vDate; - - SET vAmount = 0; - LEAVE invoices; - END IF; - END IF; - END LOOP; - CLOSE invoices; - END LOOP; - CLOSE defaulters; - DELETE FROM bi.defaulting WHERE date = vDate; - - INSERT INTO bi.defaulting(date, amount) - SELECT vDate, SUM(amount) - FROM bi.defaulters - WHERE date = vDate and amount > 0; - - CALL vn.clientFreeze(); -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `defaultingKk` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `defaultingKk`(IN vDate DATE) -BEGIN - DECLARE vDone BOOLEAN; - DECLARE vClient INT; - DECLARE vAmount INT; - DECLARE vDateInvoice DATE; - DECLARE vAmountInvoice DECIMAL(10,2); - DECLARE vDueDay INT; - DECLARE vGraceDays INT; - DECLARE defaulters CURSOR FOR - SELECT client, amount, Vencimiento, graceDays FROM bi.defaulters d - JOIN vn2008.Clientes c ON c.Id_Cliente = d.client - JOIN vn2008.pay_met pm ON pm.id = c.pay_met_id - WHERE hasChanged AND date = vDate; - - DECLARE invoices CURSOR FOR - SELECT Fecha, importe FROM vn2008.Facturas f - WHERE f.Fecha >= '2016-01-01' AND f.Id_Cliente = vClient ORDER BY f.Fecha DESC; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - -- Control - - INSERT INTO vn2008.daily_task_log(consulta) VALUES('defaulting'); - - DELETE FROM bi.defaulters WHERE date = vDate; - - INSERT INTO bi.defaulters(client, date, amount) - SELECT customer_id, vDate, FLOOR(SUM(amount)) AS amount - FROM bi.customerRiskOverdue - GROUP BY customer_id; - - -- marcamos si ha cambiado y heredamos la fecha defaulterSince - UPDATE bi.defaulters d - JOIN ( - SELECT * FROM( - SELECT client, amount , defaulterSince FROM bi.defaulters - WHERE date <= TIMESTAMPADD(DAY,-1, vDate) - ORDER BY date DESC) t GROUP BY client - ) yesterday using(client) - SET d.hasChanged = IF(d.amount <> yesterday.amount, 1, 0), - d.defaulterSince = yesterday.defaulterSince - WHERE d.date = vDate ; - - OPEN defaulters; - defaulters: LOOP - SET vDone = FALSE; - SET vAmount = 0; - FETCH defaulters INTO vClient,vAmount, vDueDay, vGraceDays; - IF vDone THEN - LEAVE defaulters; - END IF; - OPEN invoices; - invoices:LOOP - - FETCH invoices INTO vDateInvoice, vAmountInvoice; - IF vDone THEN - LEAVE invoices; - END IF; - - IF TIMESTAMPADD(DAY, vGraceDays, vn2008.paymentday(vDateInvoice, vDueDay)) <= vDate THEN - SET vAmount = vAmount - vAmountInvoice; - IF vAmount <= 0 THEN - UPDATE defaulters SET defaulterSince = vn2008.paymentday(vDateInvoice, vDueDay) - WHERE client = vClient and date = vDate; - - SET vAmount = 0; - LEAVE invoices; - END IF; - END IF; - END LOOP; - CLOSE invoices; - END LOOP; - CLOSE defaulters; - DELETE FROM bi.defaulting WHERE date = vDate; - - INSERT INTO bi.defaulting(date, amount) - SELECT vDate, SUM(amount) - FROM bi.defaulters - WHERE date = vDate and amount > 0; - - CALL vn.clientFreeze(); +CREATE DEFINER=`root`@`%` PROCEDURE `defaulting`(IN `vDate` DATE) +BEGIN +/*JGF para usar el campo vencimiento de facturas*/ + DECLARE vDone BOOLEAN; + DECLARE vClient INT; + DECLARE vAmount INT; + DECLARE vDued DATE; + DECLARE vAmountInvoice DECIMAL(10,2); + DECLARE vGraceDays INT; + DECLARE defaulters CURSOR FOR + SELECT client, amount, graceDays FROM bi.defaulters d + JOIN vn2008.Clientes c ON c.Id_Cliente = d.client + JOIN vn2008.pay_met pm ON pm.id = c.pay_met_id + WHERE hasChanged AND date = vDate; + + DECLARE invoices CURSOR FOR + SELECT Vencimiento, importe FROM vn2008.Facturas f + WHERE f.Fecha >= '2016-01-01' AND f.Id_Cliente = vClient ORDER BY f.Fecha DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DELETE FROM bi.defaulters WHERE date = vDate; + + INSERT INTO bi.defaulters(client, date, amount) + SELECT customer_id, vDate, FLOOR(SUM(amount)) AS amount + FROM bi.customerRiskOverdue + GROUP BY customer_id; + + -- marcamos si ha cambiado y heredamos la fecha defaulterSince + UPDATE bi.defaulters d + JOIN ( + SELECT * FROM( + SELECT client, amount , defaulterSince FROM bi.defaulters + WHERE date <= TIMESTAMPADD(DAY,-1, vDate) + ORDER BY date DESC) t GROUP BY client + ) yesterday using(client) + SET d.hasChanged = IF(d.amount <> yesterday.amount, 1, 0), + d.defaulterSince = yesterday.defaulterSince + WHERE d.date = vDate ; + + OPEN defaulters; + defaulters: LOOP + SET vDone = FALSE; + SET vAmount = 0; + FETCH defaulters INTO vClient,vAmount, vGraceDays; + IF vDone THEN + LEAVE defaulters; + END IF; + OPEN invoices; + invoices:LOOP + + FETCH invoices INTO vDued, vAmountInvoice; + IF vDone THEN + LEAVE invoices; + END IF; + + IF TIMESTAMPADD(DAY, vGraceDays, vDued) <= vDate THEN + SET vAmount = vAmount - vAmountInvoice; + IF vAmount <= 0 THEN + + UPDATE defaulters SET defaulterSince = vDued + WHERE client = vClient and date = vDate; + + SET vAmount = 0; + LEAVE invoices; + END IF; + END IF; + END LOOP; + CLOSE invoices; + END LOOP; + CLOSE defaulters; + DELETE FROM bi.defaulting WHERE date = vDate; + + INSERT INTO bi.defaulting(date, amount) + SELECT vDate, SUM(amount) + FROM bi.defaulters + WHERE date = vDate and amount > 0; + + CALL vn.clientFreeze(); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -68426,99 +69813,96 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `defaultingTest`(IN vDate DATE) -BEGIN -/*JGF para usar el campo vencimiento de facturas*/ - DECLARE vDone BOOLEAN; - DECLARE vClient INT; - DECLARE vAmount INT; - DECLARE vDued DATE; - DECLARE vAmountInvoice DECIMAL(10,2); - DECLARE vGraceDays INT; - DECLARE defaulters CURSOR FOR - SELECT client, amount, graceDays FROM bi.defaulters d - JOIN vn2008.Clientes c ON c.Id_Cliente = d.client - JOIN vn2008.pay_met pm ON pm.id = c.pay_met_id - WHERE hasChanged AND date = vDate; - - DECLARE invoices CURSOR FOR - SELECT Fecha, importe FROM vn2008.Facturas f - WHERE f.Fecha >= '2016-01-01' AND f.Id_Cliente = vClient ORDER BY f.Fecha DESC; - - DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; - -- Control - - INSERT INTO vn2008.daily_task_log(consulta) VALUES('defaulting'); - - DELETE FROM bi.defaulters WHERE date = vDate; - - INSERT INTO bi.defaulters(client, date, amount) - SELECT customer_id, vDate, FLOOR(SUM(amount)) AS amount - FROM bi.customerRiskOverdue - GROUP BY customer_id; - - SELECT * FROM( - SELECT client, amount , defaulterSince FROM bi.defaulters - WHERE date <= TIMESTAMPADD(DAY,-1, vDate) - ORDER BY date DESC) t GROUP BY client; - SELECT * FROM bi.defaulters where client = 14669; - - -- marcamos si ha cambiado y heredamos la fecha defaulterSince - UPDATE bi.defaulters d - JOIN ( - SELECT * FROM( - SELECT client, amount , defaulterSince FROM bi.defaulters - WHERE date <= TIMESTAMPADD(DAY,-1, vDate) - ORDER BY date DESC) t GROUP BY client - ) yesterday using(client) - SET d.hasChanged = IF(d.amount <> yesterday.amount, 1, 0), - d.defaulterSince = yesterday.defaulterSince - WHERE d.date = vDate ; - - OPEN defaulters; - defaulters: LOOP - SET vDone = FALSE; - SET vAmount = 0; - FETCH defaulters INTO vClient,vAmount, vGraceDays; - IF vDone THEN - LEAVE defaulters; - END IF; - OPEN invoices; - invoices:LOOP - - FETCH invoices INTO vDued, vAmountInvoice; - IF vDone THEN - LEAVE invoices; - END IF; - - IF TIMESTAMPADD(DAY, vGraceDays, vDued) <= vDate THEN - SET vAmount = vAmount - vAmountInvoice; - IF vAmount <= 0 THEN - UPDATE defaulters SET defaulterSince = vDued - WHERE client = vClient and date = vDate; - - SET vAmount = 0; - LEAVE invoices; - END IF; - END IF; - END LOOP; - CLOSE invoices; - END LOOP; - CLOSE defaulters; - DELETE FROM bi.defaulting WHERE date = vDate; - - INSERT INTO bi.defaulting(date, amount) - SELECT vDate, SUM(amount) - FROM bi.defaulters - WHERE date = vDate and amount > 0; - - CALL vn.clientFreeze(); +CREATE DEFINER=`root`@`%` PROCEDURE `defaultingTest`(IN `vDate` DATE) +BEGIN +/*JGF para usar el campo vencimiento de facturas*/ + DECLARE vDone BOOLEAN; + DECLARE vClient INT; + DECLARE vAmount INT; + DECLARE vDued DATE; + DECLARE vAmountInvoice DECIMAL(10,2); + DECLARE vGraceDays INT; + DECLARE defaulters CURSOR FOR + SELECT client, amount, graceDays FROM bi.defaulters d + JOIN vn2008.Clientes c ON c.Id_Cliente = d.client + JOIN vn2008.pay_met pm ON pm.id = c.pay_met_id + WHERE hasChanged AND date = vDate; + + DECLARE invoices CURSOR FOR + SELECT Fecha, importe FROM vn2008.Facturas f + WHERE f.Fecha >= '2016-01-01' AND f.Id_Cliente = vClient ORDER BY f.Fecha DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE; + + DELETE FROM bi.defaulters WHERE date = vDate; + + INSERT INTO bi.defaulters(client, date, amount) + SELECT customer_id, vDate, FLOOR(SUM(amount)) AS amount + FROM bi.customerRiskOverdue + GROUP BY customer_id; + + SELECT * FROM( + SELECT client, amount , defaulterSince FROM bi.defaulters + WHERE date <= TIMESTAMPADD(DAY,-1, vDate) + ORDER BY date DESC) t GROUP BY client; + SELECT * FROM bi.defaulters where client = 14669; + + -- marcamos si ha cambiado y heredamos la fecha defaulterSince + UPDATE bi.defaulters d + JOIN ( + SELECT * FROM( + SELECT client, amount , defaulterSince FROM bi.defaulters + WHERE date <= TIMESTAMPADD(DAY,-1, vDate) + ORDER BY date DESC) t GROUP BY client + ) yesterday using(client) + SET d.hasChanged = IF(d.amount <> yesterday.amount, 1, 0), + d.defaulterSince = yesterday.defaulterSince + WHERE d.date = vDate ; + + OPEN defaulters; + defaulters: LOOP + SET vDone = FALSE; + SET vAmount = 0; + FETCH defaulters INTO vClient,vAmount, vGraceDays; + IF vDone THEN + LEAVE defaulters; + END IF; + OPEN invoices; + invoices:LOOP + + FETCH invoices INTO vDued, vAmountInvoice; + IF vDone THEN + LEAVE invoices; + END IF; + + IF TIMESTAMPADD(DAY, vGraceDays, vDued) <= vDate THEN + SET vAmount = vAmount - vAmountInvoice; + IF vAmount <= 0 THEN + UPDATE defaulters SET defaulterSince = vDued + WHERE client = vClient and date = vDate; + + SET vAmount = 0; + LEAVE invoices; + END IF; + END IF; + END LOOP; + CLOSE invoices; + END LOOP; + CLOSE defaulters; + DELETE FROM bi.defaulting WHERE date = vDate; + + INSERT INTO bi.defaulting(date, amount) + SELECT vDate, SUM(amount) + FROM bi.defaulters + WHERE date = vDate and amount > 0; + + CALL vn.clientFreeze(); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -68612,30 +69996,25 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `facturacion_media_anual_update`() -BEGIN - --- control -INSERT INTO vn2008.daily_task_log(consulta) VALUES('bi.facturacion_media_anual_update'); - -TRUNCATE TABLE bi.facturacion_media_anual; - -REPLACE bi.facturacion_media_anual(Id_Cliente, Consumo) - SELECT clientFk, avg(Facturacion) - FROM ( - SELECT clientFk, YEAR(issued) year, MONTH(issued) month, sum(amount) as Facturacion - FROM vn.invoiceOut - WHERE issued BETWEEN TIMESTAMPADD(YEAR,-1,CURDATE()) AND TIMESTAMPADD(DAY, - DAY(CURDATE()),CURDATE()) - GROUP BY clientFk, year, month - ) vol - GROUP BY clientFk; - +BEGIN + TRUNCATE TABLE bi.facturacion_media_anual; + + REPLACE bi.facturacion_media_anual(Id_Cliente, Consumo) + SELECT clientFk, avg(Facturacion) + FROM ( + SELECT clientFk, YEAR(issued) year, MONTH(issued) month, sum(amount) as Facturacion + FROM vn.invoiceOut + WHERE issued BETWEEN TIMESTAMPADD(YEAR,-1,CURDATE()) AND TIMESTAMPADD(DAY, - DAY(CURDATE()),CURDATE()) + GROUP BY clientFk, year, month + ) vol + GROUP BY clientFk; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -68801,201 +70180,121 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `Greuge_Evolution_Add`() -BEGIN - - /* - - Inserta en la tabla Greuge_Evolution el saldo acumulado de cada cliente, así como las ventas acumuladas en los ultimos 365 dias - , para poder controlar su evolucion - - */ - - DECLARE datFEC DATE; - DECLARE datFEC_TOMORROW DATE; - DECLARE datFEC_LASTYEAR DATE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN - - GET DIAGNOSTICS CONDITION 2 @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT; - SELECT CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')); - INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('jgallego@verdnatura.es', 'Greuge_Evolution_Add' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'))); - INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('pako@verdnatura.es', 'Greuge_Evolution_Add' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'))); - - END; - - SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; - - INSERT INTO vn2008.daily_task_log(consulta) VALUES('Greuge Evolution Add START'); - - SELECT TIMESTAMPADD(DAY,1,MAX(Fecha)), - TIMESTAMPADD(DAY,2,MAX(Fecha)) - INTO datFEC, - datFEC_TOMORROW - FROM bi.Greuge_Evolution; - - SET datFEC_LASTYEAR = TIMESTAMPADD(YEAR,-1,datFEC); - - DELETE FROM bi.Greuge_Evolution WHERE Fecha >= datFEC; - - DROP TEMPORARY TABLE IF EXISTS maxInvoice; - - CREATE TEMPORARY TABLE maxInvoice - (PRIMARY KEY (Id_Cliente)) - ENGINE = MEMORY - SELECT DISTINCT Id_Cliente, max(Fecha) as maxFecha - FROM vn2008.Facturas - GROUP BY Id_Cliente - HAVING maxFecha < timestampadd(month,-2,datFEC); - - INSERT INTO vn2008.daily_task_log(consulta) VALUES('Greuge Evolution Add MIDDLE'); - - WHILE datFEC < CURDATE() DO - - REPLACE bi.Greuge_Evolution(Id_Cliente, Fecha, Greuge, Ventas, Fosil) - - SELECT Id_Cliente, datFEC as Fecha, Greuge, Ventas, 0 - - FROM - - ( - SELECT Id_Cliente, sum(Importe) as Greuge - FROM vn2008.Greuges - where Fecha <= datFEC - group by Id_Cliente - - ) sub - - RIGHT JOIN - - ( - - SELECT Id_Cliente, sum(Ventas) as Ventas - FROM - ( - - SELECT Id_Cliente, IF (fecha != datFEC, -1,1) * (importe + recargo) as Ventas - FROM bs.ventas - WHERE fecha = datFEC or fecha = datFEC_LASTYEAR - - UNION ALL - - SELECT Id_Cliente, Ventas - FROM bi.Greuge_Evolution - WHERE Fecha = TIMESTAMPADD(DAY, -1, datFEC) - - ) sub - group by Id_Cliente - - ) v using(Id_Cliente) - ; - - - -- Ahora calcularemos el greuge muerto - - - - UPDATE bi.Greuge_Evolution ge - JOIN maxInvoice m using(Id_Cliente) - SET FOSIL = GREUGE - WHERE m.maxFecha < TIMESTAMPADD(MONTH,-2,ge.Fecha); - - - -- Recobro - - UPDATE bi.Greuge_Evolution ge - JOIN ( - SELECT cs.Id_Cliente, sum(Valor * Cantidad) as Importe - FROM vn2008.Tickets t - JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna - JOIN vn2008.Movimientos m on m.Id_Ticket = t.Id_Ticket - JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento - WHERE t.Fecha >= datFEC - AND t.Fecha < datFEC_TOMORROW - AND mc.Id_Componente = 17 -- Recobro - GROUP BY cs.Id_Cliente - ) sub using(Id_Cliente) - SET Recobro = Importe - WHERE ge.Fecha = datFEC; - - INSERT INTO vn2008.daily_task_log(consulta) VALUES(CONCAT('Greuge Evolution ',datFEC)); - - SET datFEC = datFEC_TOMORROW; - SET datFEC_TOMORROW = TIMESTAMPADD(DAY,1,datFEC_TOMORROW); - SET datFEC_LASTYEAR = TIMESTAMPADD(YEAR,-1,datFEC); - - - END WHILE; - - DROP TEMPORARY TABLE IF EXISTS maxInvoice; - - INSERT INTO vn2008.daily_task_log(consulta) VALUES('Greuge Evolution Add END'); - -END ;; -DELIMITER ; -/*!50003 SET sql_mode = @saved_sql_mode */ ; -/*!50003 SET character_set_client = @saved_cs_client */ ; -/*!50003 SET character_set_results = @saved_cs_results */ ; -/*!50003 SET collation_connection = @saved_col_connection */ ; -/*!50003 DROP PROCEDURE IF EXISTS `last_buy_id_addKk` */; -/*!50003 SET @saved_cs_client = @@character_set_client */ ; -/*!50003 SET @saved_cs_results = @@character_set_results */ ; -/*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; -DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `last_buy_id_addKk`() -BEGIN - --- control --- INSERT INTO vn2008.daily_task_log(consulta) VALUES('bi.last_buy_id_add'); - --- DELETE FROM bi.Last_buy_id; -TRUNCATE TABLE bi.Last_buy_id; - - --- Primero metemos las del futuro, por si no hay en el presente - -INSERT INTO bi.Last_buy_id SELECT * FROM - (SELECT - Id_Article, Id_Compra, warehouse_id - FROM - vn2008.Compres c - JOIN vn2008.Entradas e USING (Id_Entrada) - JOIN vn2008.travel tr ON tr.id = e.travel_id - WHERE - Novincular = FALSE AND tarifa2 > 0 AND NOT Redada - AND landing > curdate() - ORDER BY landing DESC) t1 -GROUP BY Id_Article , warehouse_id; - --- Ahora el presente machaca al futuro - -REPLACE bi.Last_buy_id SELECT * FROM - (SELECT - Id_Article, Id_Compra, warehouse_id - FROM - vn2008.Compres c - JOIN vn2008.Entradas e USING (Id_Entrada) - JOIN vn2008.travel tr ON tr.id = e.travel_id - WHERE - Novincular = FALSE AND tarifa2 > 0 AND NOT Redada - AND landing BETWEEN vn2008.date_inv() AND curdate() - ORDER BY landing DESC) t1 -GROUP BY Id_Article , warehouse_id; - - TRUNCATE TABLE bi.Last_buy_idBackUp; - INSERT INTO bi.Last_buy_idBackUp - SELECT * FROM Last_buy_id; +BEGIN +/* + Inserta en la tabla Greuge_Evolution el saldo acumulado de cada cliente, + así como las ventas acumuladas en los ultimos 365 dias, para poder controlar + su evolucion. +*/ + DECLARE datFEC DATE; + DECLARE datFEC_TOMORROW DATE; + DECLARE datFEC_LASTYEAR DATE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN + + GET DIAGNOSTICS CONDITION 2 @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT; + SELECT CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto')); + INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('jgallego@verdnatura.es', 'Greuge_Evolution_Add' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'))); + INSERT INTO vn2008.mail (`to`,`subject`,`text`) VALUES ('pako@verdnatura.es', 'Greuge_Evolution_Add' ,CONCAT('ERROR ', IFNULL(@errno,0), ': ', ifnull(@text,'texto'))); + + END; + + SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; + + SELECT TIMESTAMPADD(DAY,1,MAX(Fecha)), + TIMESTAMPADD(DAY,2,MAX(Fecha)) + INTO datFEC, + datFEC_TOMORROW + FROM bi.Greuge_Evolution; + + SET datFEC_LASTYEAR = TIMESTAMPADD(YEAR,-1,datFEC); + + DELETE FROM bi.Greuge_Evolution WHERE Fecha >= datFEC; + + DROP TEMPORARY TABLE IF EXISTS maxInvoice; + + CREATE TEMPORARY TABLE maxInvoice + (PRIMARY KEY (Id_Cliente)) + ENGINE = MEMORY + SELECT DISTINCT Id_Cliente, max(Fecha) as maxFecha + FROM vn2008.Facturas + GROUP BY Id_Cliente + HAVING maxFecha < timestampadd(month,-2,datFEC); + + WHILE datFEC < CURDATE() DO + + REPLACE bi.Greuge_Evolution(Id_Cliente, Fecha, Greuge, Ventas, Fosil) + + SELECT Id_Cliente, datFEC as Fecha, Greuge, Ventas, 0 + FROM ( + SELECT Id_Cliente, sum(Importe) as Greuge + FROM vn2008.Greuges + where Fecha <= datFEC + group by Id_Cliente + ) sub + RIGHT JOIN + + ( + + SELECT Id_Cliente, sum(Ventas) as Ventas + FROM + ( + + SELECT Id_Cliente, IF (fecha != datFEC, -1,1) * (importe + recargo) as Ventas + FROM bs.ventas + WHERE fecha = datFEC or fecha = datFEC_LASTYEAR + + UNION ALL + + SELECT Id_Cliente, Ventas + FROM bi.Greuge_Evolution + WHERE Fecha = TIMESTAMPADD(DAY, -1, datFEC) + + ) sub + group by Id_Cliente + + ) v using(Id_Cliente) + ; + + -- Ahora calcularemos el greuge muerto + + UPDATE bi.Greuge_Evolution ge + JOIN maxInvoice m using(Id_Cliente) + SET FOSIL = GREUGE + WHERE m.maxFecha < TIMESTAMPADD(MONTH,-2,ge.Fecha); + + -- Recobro + + UPDATE bi.Greuge_Evolution ge + JOIN ( + SELECT cs.Id_Cliente, sum(Valor * Cantidad) as Importe + FROM vn2008.Tickets t + JOIN vn2008.Consignatarios cs on cs.Id_Consigna = t.Id_Consigna + JOIN vn2008.Movimientos m on m.Id_Ticket = t.Id_Ticket + JOIN vn2008.Movimientos_componentes mc on mc.Id_Movimiento = m.Id_Movimiento + WHERE t.Fecha >= datFEC + AND t.Fecha < datFEC_TOMORROW + AND mc.Id_Componente = 17 -- Recobro + GROUP BY cs.Id_Cliente + ) sub using(Id_Cliente) + SET Recobro = Importe + WHERE ge.Fecha = datFEC; + + SET datFEC = datFEC_TOMORROW; + SET datFEC_TOMORROW = TIMESTAMPADD(DAY,1,datFEC_TOMORROW); + SET datFEC_LASTYEAR = TIMESTAMPADD(YEAR,-1,datFEC); + + + END WHILE; + + DROP TEMPORARY TABLE IF EXISTS maxInvoice; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -69072,23 +70371,17 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `nigthlyAnalisisVentas`() -BEGIN - - INSERT INTO vn2008.daily_task_log(consulta) VALUES('analisis ventas START'); - - CALL bi.analisis_ventas_update; - CALL bi.analisis_ventas_simple; - CALL bi.analisis_ventas_evolution_add; - - INSERT INTO vn2008.daily_task_log(consulta) VALUES('analisis ventas END'); - +BEGIN + CALL analisis_ventas_update; + CALL analisis_ventas_simple; + CALL analisis_ventas_evolution_add; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -69357,22 +70650,16 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `rotacion_update`() -BEGIN - --- control -INSERT INTO vn2008.daily_task_log(consulta) VALUES('bi.rotation_update'); - --- Sólo hace la consulta gorda los sábados de madrugada. Necesita casi dos horas. - - call rotacion_update_manual(1, 999999, TIMESTAMPADD(WEEK,-1,CURDATE()), CURDATE()) ; - +BEGIN + -- Sólo hace la consulta gorda los sábados de madrugada. Necesita casi dos horas. + CALL rotacion_update_manual(1, 999999, TIMESTAMPADD(WEEK,-1,CURDATE()), CURDATE()); END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -69977,7 +71264,7 @@ CREATE TABLE `cdr` ( KEY `dstchannel` (`dst_channel`), KEY `disposition` (`disposition`), KEY `src` (`src`) -) ENGINE=MyISAM AUTO_INCREMENT=257001 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=260663 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -70243,7 +71530,7 @@ CREATE TABLE `queueMember` ( KEY `extension` (`extension`), CONSTRAINT `queueMember_ibfk_1` FOREIGN KEY (`queue`) REFERENCES `queue` (`name`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `queueMember_ibfk_2` FOREIGN KEY (`extension`) REFERENCES `sip` (`extension`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=735 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queue members'; +) ENGINE=InnoDB AUTO_INCREMENT=738 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Queue members'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -70481,7 +71768,7 @@ CREATE TABLE `sipConfig` ( `dtlsprivatekey` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `dtlssetup` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Default values for SIP accounts'; +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Default values for SIP accounts'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -70719,6 +72006,19 @@ CREATE DATABASE /*!32312 IF NOT EXISTS*/ `cache` /*!40100 DEFAULT CHARACTER SET USE `cache`; +-- +-- Table structure for table `__dailyTaskLog` +-- + +DROP TABLE IF EXISTS `__dailyTaskLog`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__dailyTaskLog` ( + `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='No he encontrado el lugar en el que vicente almacena la hora en que se ejecutan las daily tasks, asi que he hecho esta tabla, a eliminar cuando se considere oportuno'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `available` -- @@ -70730,8 +72030,8 @@ CREATE TABLE `available` ( `calc_id` int(10) unsigned NOT NULL, `item_id` int(11) NOT NULL, `available` int(11) NOT NULL, - KEY `calc_id_4` (`calc_id`) USING BTREE, - KEY `calc_id` (`item_id`,`calc_id`) + UNIQUE KEY `calc_id` (`item_id`,`calc_id`) USING HASH, + KEY `calc_id_4` (`calc_id`) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -70772,7 +72072,7 @@ CREATE TABLE `cache_calc` ( KEY `cache_id` (`cache_id`), KEY `cacheName` (`cacheName`), KEY `expires` (`expires`) -) ENGINE=InnoDB AUTO_INCREMENT=279870 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=289519 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -70783,21 +72083,10 @@ DROP TABLE IF EXISTS `cache_valid`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `cache_valid` ( - `valid` tinyint(3) unsigned NOT NULL -) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `dailyTaskLog` --- - -DROP TABLE IF EXISTS `dailyTaskLog`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `dailyTaskLog` ( - `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL, - `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='No he encontrado el lugar en el que vicente almacena la hora en que se ejecutan las daily tasks, asi que he hecho esta tabla, a eliminar cuando se considere oportuno'; + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `valid` tinyint(3) unsigned NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MEMORY AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -70863,7 +72152,7 @@ CREATE TABLE `item_range` ( `calc_id` int(11) NOT NULL, `item_id` int(11) NOT NULL, `date_end` datetime DEFAULT NULL, - KEY `calc_item` (`calc_id`,`item_id`), + UNIQUE KEY `calc_item` (`calc_id`,`item_id`) USING HASH, KEY `calc_id` (`calc_id`) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -70880,8 +72169,8 @@ CREATE TABLE `last_buy` ( `warehouse_id` smallint(5) unsigned NOT NULL, `buy_id` int(10) unsigned DEFAULT NULL, `landing` date DEFAULT NULL, + UNIQUE KEY `item_id` (`item_id`,`warehouse_id`) USING HASH, KEY `buy_id` (`buy_id`), - KEY `item_id` (`item_id`,`warehouse_id`), KEY `warehouse_id` (`warehouse_id`) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -70894,13 +72183,15 @@ DROP TABLE IF EXISTS `prod_graphic_source`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `prod_graphic_source` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `m3` double NOT NULL DEFAULT '0', `warehouse_id` int(11) NOT NULL, `hora` int(11) NOT NULL, `order` int(11) NOT NULL DEFAULT '0', `alert_level` int(11) NOT NULL DEFAULT '0', - `Agencia` varchar(45) CHARACTER SET utf8 NOT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + `Agencia` varchar(45) CHARACTER SET utf8 NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=25139 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -70914,7 +72205,7 @@ CREATE TABLE `stock` ( `warehouse_id` smallint(5) unsigned NOT NULL, `item_id` int(10) unsigned NOT NULL, `amount` int(11) NOT NULL, - KEY `warehouse_id` (`warehouse_id`,`item_id`), + UNIQUE KEY `warehouse_id` (`warehouse_id`,`item_id`) USING HASH, KEY `warehouse_id_2` (`warehouse_id`) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -70947,8 +72238,8 @@ CREATE TABLE `visible` ( `calc_id` int(10) unsigned NOT NULL, `item_id` int(11) NOT NULL, `visible` int(11) NOT NULL, - KEY `id` (`calc_id`) USING BTREE, - KEY `calc_id` (`calc_id`,`item_id`) + UNIQUE KEY `calc_id` (`calc_id`,`item_id`) USING HASH, + KEY `id` (`calc_id`) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -70965,7 +72256,7 @@ CREATE TABLE `weekly_sales` ( `warehouse_id` smallint(5) unsigned NOT NULL, `amount` int(11) NOT NULL, `price` double NOT NULL, - KEY `item_id` (`item_id`,`warehouse_id`), + UNIQUE KEY `week_2` (`week`,`item_id`,`warehouse_id`), KEY `week` (`week`) USING BTREE ) ENGINE=MEMORY DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -70974,27 +72265,7 @@ CREATE TABLE `weekly_sales` ( -- Dumping events for database 'cache' -- /*!50106 SET @save_time_zone= @@TIME_ZONE */ ; -/*!50106 DROP EVENT IF EXISTS `barcodes_update` */; -DELIMITER ;; -ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;; -/*!50003 SET @saved_cs_client = @@character_set_client */ ;; -/*!50003 SET @saved_cs_results = @@character_set_results */ ;; -/*!50003 SET @saved_col_connection = @@collation_connection */ ;; -/*!50003 SET character_set_client = utf8 */ ;; -/*!50003 SET character_set_results = utf8 */ ;; -/*!50003 SET collation_connection = utf8_general_ci */ ;; -/*!50003 SET @saved_sql_mode = @@sql_mode */ ;; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;; -/*!50003 SET @saved_time_zone = @@time_zone */ ;; -/*!50003 SET time_zone = 'SYSTEM' */ ;; -/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`%`*/ /*!50106 EVENT `barcodes_update` ON SCHEDULE EVERY 1 HOUR STARTS '2016-08-17 00:00:00' ON COMPLETION NOT PRESERVE ENABLE DO CALL barcodes_update() */ ;; -/*!50003 SET time_zone = @saved_time_zone */ ;; -/*!50003 SET sql_mode = @saved_sql_mode */ ;; -/*!50003 SET character_set_client = @saved_cs_client */ ;; -/*!50003 SET character_set_results = @saved_cs_results */ ;; -/*!50003 SET collation_connection = @saved_col_connection */ ;; -ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ;; -/*!50106 DROP EVENT IF EXISTS `cacheCalcClean` */;; +/*!50106 DROP EVENT IF EXISTS `cacheCalcClean` */; DELIMITER ;; ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_general_ci ;; /*!50003 SET @saved_cs_client = @@character_set_client */ ;; @@ -71607,24 +72878,20 @@ ALTER DATABASE `cache` CHARACTER SET utf8 COLLATE utf8_unicode_ci ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `clean`() -BEGIN - - DECLARE vDateShort DATETIME; - - SET vDateShort = TIMESTAMPADD(MONTH, -1, CURDATE()); - - INSERT INTO cache.dailyTaskLog(state) VALUES('clean START'); - - DELETE FROM cache.departure_limit WHERE Fecha < vDateShort; - - INSERT INTO cache.dailyTaskLog(state) VALUES('clean END'); +BEGIN + + DECLARE vDateShort DATETIME; + + SET vDateShort = TIMESTAMPADD(MONTH, -1, CURDATE()); + + DELETE FROM cache.departure_limit WHERE Fecha < vDateShort; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -72406,7 +73673,7 @@ CREATE TABLE `ACL` ( `principalType` set('ROLE','USER') COLLATE utf8_unicode_ci DEFAULT 'ROLE', `principalId` varchar(512) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=149 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=151 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -72526,7 +73793,7 @@ CREATE TABLE `userConfigView` ( `configuration` text COLLATE utf8_unicode_ci, PRIMARY KEY (`id`), UNIQUE KEY `uniqueUser_TableCode` (`userFk`,`tableCode`) -) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -72600,6 +73867,32 @@ CREATE DATABASE /*!32312 IF NOT EXISTS*/ `vncontrol` /*!40100 DEFAULT CHARACTER USE `vncontrol`; +-- +-- Table structure for table `__clientes_match` +-- + +DROP TABLE IF EXISTS `__clientes_match`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__clientes_match` ( + `Id_cliente` int(11) NOT NULL, + `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__dailyTaskLog` +-- + +DROP TABLE IF EXISTS `__dailyTaskLog`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__dailyTaskLog` ( + `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='No he encontrado el lugar en el que vicente almacena la hora en que se ejecutan las daily tasks, asi que he hecho esta tabla, a eliminar cuando se considere oportuno'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `accion` -- @@ -72614,32 +73907,6 @@ CREATE TABLE `accion` ( ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `clientes_match` --- - -DROP TABLE IF EXISTS `clientes_match`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `clientes_match` ( - `Id_cliente` int(11) NOT NULL, - `odbc_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `dailyTaskLog` --- - -DROP TABLE IF EXISTS `dailyTaskLog`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `dailyTaskLog` ( - `state` varchar(250) COLLATE utf8_unicode_ci NOT NULL, - `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='No he encontrado el lugar en el que vicente almacena la hora en que se ejecutan las daily tasks, asi que he hecho esta tabla, a eliminar cuando se considere oportuno'; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `fallo` -- @@ -72683,7 +73950,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=15462470 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=15728387 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 */ ; @@ -72873,23 +74140,16 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `clean`() -BEGIN - - DECLARE v_date2 DATETIME DEFAULT TIMESTAMPADD(MONTH, -2,CURDATE()); - - INSERT INTO vncontrol.dailyTaskLog(state) VALUES('clean START'); - - DELETE FROM vncontrol.inter WHERE odbc_date <= v_date2; - - INSERT INTO vncontrol.dailyTaskLog(state) VALUES('clean END'); - +BEGIN + DECLARE vDate DATETIME DEFAULT TIMESTAMPADD(MONTH, -2, CURDATE()); + DELETE FROM inter WHERE odbc_date <= vDate; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -72949,7 +74209,7 @@ CREATE TABLE `browser` ( `name` varchar(30) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Browser name in browscap', `version` float NOT NULL COMMENT 'Minimal version', UNIQUE KEY `name` (`name`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='List of compatible web browsers and its version'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='List of compatible web browsers and its version'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -72973,7 +74233,7 @@ CREATE TABLE `config` ( `productionDomain` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'The address for production website', `pdfsDir` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Directory where PDFs are allocated', PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters'; +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Global configuration parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -73043,7 +74303,7 @@ CREATE TABLE `imageConfig` ( `useXsendfile` tinyint(4) NOT NULL COMMENT 'Whether to use the apache module XSendfile', `url` varchar(255) NOT NULL COMMENT 'Public URL where image are hosted', PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='Global image parameters'; +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='Global image parameters'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -73077,7 +74337,7 @@ CREATE TABLE `language` ( `orgName` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `isActive` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`code`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -73094,7 +74354,7 @@ CREATE TABLE `link` ( `link` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `image` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=37 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -73116,7 +74376,7 @@ CREATE TABLE `location` ( `phone` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, `language` char(2) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -73199,7 +74459,7 @@ CREATE TABLE `message` ( `description` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`) -) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -73215,7 +74475,7 @@ CREATE TABLE `metatag` ( `content` varchar(255) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -73555,7 +74815,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=1779395 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1800738 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -73571,7 +74831,7 @@ CREATE TABLE `orderCheck` ( `denySunday` tinyint(1) NOT NULL, `denyDay` date DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Conditions to check when an order is confirmed'; +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Conditions to check when an order is confirmed'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -73587,7 +74847,7 @@ CREATE TABLE `orderCheckFestive` ( `acceptOrders` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), UNIQUE KEY `date` (`date`) -) ENGINE=MyISAM AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -73601,7 +74861,7 @@ CREATE TABLE `orderCheckWday` ( `weekday` tinyint(3) unsigned NOT NULL COMMENT '0 = Monday, 6 = Sunday', `maxTime` time NOT NULL, PRIMARY KEY (`weekday`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -73657,7 +74917,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=10799021 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=10926931 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 */ ; @@ -73938,7 +75198,7 @@ CREATE TABLE `tpvImapConfig` ( `successFolder` varchar(150) CHARACTER SET utf8 DEFAULT NULL, `errorFolder` varchar(150) CHARACTER SET utf8 DEFAULT NULL, PRIMARY KEY (`id`) -) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='IMAP configuration parameters for virtual TPV'; +) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='IMAP configuration parameters for virtual TPV'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -74017,7 +75277,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=287580 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Transactions realized through the virtual TPV'; +) ENGINE=InnoDB AUTO_INCREMENT=291107 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Transactions realized through the virtual TPV'; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -74030,7 +75290,7 @@ DROP TABLE IF EXISTS `userSession`; CREATE TABLE `userSession` ( `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `lastUpdate` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `ssid` char(64) COLLATE utf8_unicode_ci DEFAULT NULL, + `ssid` char(64) COLLATE utf8_unicode_ci NOT NULL, `data` text COLLATE utf8_unicode_ci, `userVisit` int(10) unsigned DEFAULT NULL, UNIQUE KEY `ssid` (`ssid`), @@ -74052,7 +75312,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=1624249 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=1648996 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -74072,7 +75332,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=3565746 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3617310 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -74097,7 +75357,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=2208561 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=2237086 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -74117,7 +75377,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=3227028 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +) ENGINE=InnoDB AUTO_INCREMENT=3261248 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -74216,29 +75476,35 @@ DELIMITER ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` FUNCTION `orderGetTotal`(vOrder INT) RETURNS decimal(10,2) READS SQL DATA DETERMINISTIC BEGIN /** - * Obtiene el total de un pedido con el IVA y el recargo de - * equivalencia incluidos. - * - * @param vOrder El identificador del pedido - * @return El total del pedido - */ - DECLARE vTotal DECIMAL(10,2); +* Obtiene el total de un pedido con el IVA y el recargo de +* equivalencia incluidos. +* +* @param vOrder El identificador del pedido +* @return El total del pedido +*/ +DECLARE vTotal DECIMAL(10,2); - CALL orderGetTax (vOrder); +DROP TEMPORARY TABLE IF EXISTS tmp.order; +CREATE TEMPORARY TABLE tmp.order +ENGINE = MEMORY +SELECT vOrder orderFk; - SELECT SUM(taxBase) + SUM(tax) + SUM(equalizationTax) INTO vTotal - FROM tmp.orderTax; +CALL orderGetTotal; - DROP TEMPORARY TABLE tmp.orderTax; - - RETURN vTotal; +SELECT total INTO vTotal FROM tmp.orderTotal; + +DROP TEMPORARY TABLE +tmp.order, +tmp.orderTotal; + +RETURN vTotal; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -74514,7 +75780,7 @@ DELIMITER ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; CREATE DEFINER=`root`@`%` PROCEDURE `basketGetTax`() READS SQL DATA @@ -74524,7 +75790,14 @@ BEGIN * * @treturn tmp.orderTax */ - CALL orderGetTax(myBasketGetId()); + DROP TEMPORARY TABLE IF EXISTS tmp.order; + CREATE TEMPORARY TABLE tmp.order + ENGINE = MEMORY + SELECT myBasketGetId() orderFk; + + CALL orderGetTax(); + + DROP TEMPORARY TABLE IF EXISTS tmp.order; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -75218,19 +76491,6 @@ BEGIN IF isMine THEN CALL orderConfirm(vOrderFk); - /*JGF 2018-12-20 Temporal quitar despues de las pruebas */ - IF (SELECT NOW() mod 2) THEN - SELECT ot.ticketFk INTO vTicketFk FROM vn.orderTicket ot - LEFT JOIN vn.ticketState ts ON ts.ticketFk = ot.ticketfk - WHERE orderFk = vOrderFk LIMIT 1; - IF (SELECT Id_Ticket FROM vn2008.Tickets WHERE Id_Ticket = vTicketFk) THEN - INSERT INTO vncontrol.inter(state_id, Id_Ticket, Id_Trabajador) - SELECT id, vTicketFk, vn.getWorker() - FROM vn.state - WHERE `code` = 'DELIVERED'; - END IF; - END IF; - -- -------------- END IF; END ;; @@ -75784,236 +77044,252 @@ DELIMITER ; /*!50003 SET @saved_cs_client = @@character_set_client */ ; /*!50003 SET @saved_cs_results = @@character_set_results */ ; /*!50003 SET @saved_col_connection = @@collation_connection */ ; -/*!50003 SET character_set_client = utf8 */ ; -/*!50003 SET character_set_results = utf8 */ ; -/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; /*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `orderConfirmWithUser`(vOrder INT, vUserId INT) -BEGIN -/** - * Confirms an order, creating each of its tickets on - * the corresponding date, store and user - * - * @param vOrder The order identifier - *@param vUser The user identifier - */ - DECLARE vOk BOOL; - DECLARE vDone BOOL DEFAULT FALSE; - DECLARE vWarehouse INT; - DECLARE vShipment DATETIME; - DECLARE vTicket INT; - DECLARE vNotes VARCHAR(255); - DECLARE vItem INT; - DECLARE vConcept VARCHAR(30); - DECLARE vAmount INT; - DECLARE vPrice DECIMAL(10,2); - DECLARE vSale INT; - DECLARE vRate INT; - DECLARE vRowId INT; - DECLARE vDelivery DATE; - DECLARE vAddress INT; - DECLARE vAgency INT; - DECLARE vIsConfirmed BOOL; - DECLARE vClientId INT; - DECLARE vCompanyId INT; - DECLARE vAgencyModeId INT; - - DECLARE TICKET_FREE INT DEFAULT 2; - DECLARE SYSTEM_WORKER INT DEFAULT 20; - - DECLARE cDates CURSOR FOR - SELECT ah.shipped, r.warehouse_id - FROM `order` o - JOIN order_row r ON r.order_id = o.id - LEFT JOIN tmp.agencyHourGetShipped ah ON ah.warehouseFk = r.warehouse_id - WHERE o.id = vOrder AND r.amount != 0 - GROUP BY warehouse_id; - - DECLARE cRows CURSOR FOR - SELECT r.id, r.item_id, a.Article, r.amount, r.price, r.rate - FROM order_row r - JOIN vn2008.Articles a ON a.Id_Article = r.item_id - WHERE r.amount != 0 - AND r.warehouse_id = vWarehouse - AND r.order_id = vOrder - ORDER BY r.rate DESC; - - DECLARE CONTINUE HANDLER FOR NOT FOUND - SET vDone = TRUE; - - DECLARE EXIT HANDLER FOR SQLEXCEPTION - BEGIN - ROLLBACK; - RESIGNAL; - END; - - -- Carga los datos del pedido - - SELECT o.date_send, o.address_id, o.note, a.agency_id, - o.confirmed, cs.Id_Cliente, o.company_id, o.agency_id - INTO vDelivery, vAddress, vNotes, vAgency, - vIsConfirmed, vClientId, vCompanyId, vAgencyModeId - FROM hedera.`order` o - JOIN vn2008.Agencias a ON a.Id_Agencia = o.agency_id - JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = o.address_id - WHERE id = vOrder; - - -- Comprueba que el pedido no está confirmado - - IF vIsConfirmed THEN - CALL util.throw ('ORDER_ALREADY_CONFIRMED'); - END IF; - - -- Comprueba que el pedido no está vacío - - SELECT COUNT(*) > 0 INTO vOk - FROM order_row WHERE order_id = vOrder AND amount > 0; - - IF !vOk THEN - CALL util.throw ('ORDER_EMPTY'); - END IF; - - -- Carga las fechas de salida de cada almacén - - CALL vn.agencyHourGetShipped (vDelivery, vAddress, vAgency); - - -- Trabajador que realiza la acción - - IF vUserId IS NULL THEN - SELECT employeeFk INTO vUserId FROM orderConfig; - END IF; - - -- Crea los tickets del pedido - - START TRANSACTION; - - OPEN cDates; - - lDates: - LOOP - SET vTicket = NULL; - SET vDone = FALSE; - FETCH cDates INTO vShipment, vWarehouse; - - IF vDone THEN - LEAVE lDates; - END IF; - - -- Busca un ticket existente que coincida con los parametros del nuevo pedido - - SELECT Id_Ticket INTO vTicket - FROM vn2008.Tickets t - LEFT JOIN vn.ticketState tls on tls.ticket = t.Id_Ticket - JOIN `order` o - ON o.address_id = t.Id_Consigna - AND vWarehouse = t.warehouse_id - AND o.agency_id = t.Id_Agencia - AND t.landing = o.date_send - AND vShipment = DATE(t.Fecha) - WHERE o.id = vOrder - AND t.Factura IS NULL - AND IFNULL(tls.alertLevel,0) = 0 - AND t.Id_Cliente <> 1118 - LIMIT 1; - - -- Crea el ticket en el caso de no existir uno adecuado - - IF vTicket IS NULL - THEN - CALL vn.ticketCreateWithUser( - vClientId, - IFNULL(vShipment, CURDATE()), - vWarehouse, - vCompanyId, - vAddress, - vAgencyModeId, - NULL, - vDelivery, - vUserId, - vTicket - ); - ELSE - INSERT INTO vncontrol.inter - SET Id_Ticket = vTicket, - Id_Trabajador = SYSTEM_WORKER, - state_id = TICKET_FREE; - END IF; - - INSERT IGNORE INTO vn2008.order_Tickets - SET order_id = vOrder, - Id_Ticket = vTicket; - - -- Añade las notas - - IF vNotes IS NOT NULL AND vNotes != '' - THEN - INSERT INTO vn2008.ticket_observation (Id_Ticket, observation_type_id, text) - VALUES (vTicket, 4/*comercial*/ , vNotes) - ON DUPLICATE KEY UPDATE text = CONCAT(VALUES(text),'. ', text); - END IF; - - -- Añade los movimientos y sus componentes - - OPEN cRows; - - lRows: - LOOP - SET vDone = FALSE; - FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate; - - IF vDone THEN - LEAVE lRows; - END IF; - - INSERT INTO vn2008.Movimientos - SET - Id_Article = vItem, - Id_Ticket = vTicket, - Concepte = vConcept, - Cantidad = vAmount, - Preu = vPrice, - CostFixat = 0, - PrecioFijado = TRUE; - - SET vSale = LAST_INSERT_ID(); - - INSERT INTO vn2008.Movimientos_componentes (Id_Movimiento, Id_Componente, Valor) - SELECT vSale, cm.component_id, cm.price - FROM order_component cm - JOIN bi.tarifa_componentes tc ON tc.Id_Componente = cm.component_id - WHERE cm.order_row_id = vRowId - GROUP BY vSale, cm.component_id; - - UPDATE order_row SET Id_Movimiento = vSale - WHERE id = vRowId; - - END LOOP; - - CLOSE cRows; - - -- Fija el Costfixat - - UPDATE vn2008.Movimientos m - JOIN (SELECT SUM(mc.Valor) sum_valor,mc.Id_Movimiento - FROM vn2008.Movimientos_componentes mc - JOIN bi.tarifa_componentes tc USING(Id_Componente) - JOIN bi.tarifa_componentes_series tcs on tcs.tarifa_componentes_series_id = tc.tarifa_componentes_series_id AND tcs.base - JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento - WHERE m.Id_Ticket = vTicket - GROUP BY mc.Id_Movimiento) mc ON mc.Id_Movimiento = m.Id_Movimiento - SET m.CostFixat = sum_valor; - END LOOP; - - CLOSE cDates; - - DELETE FROM basketOrder WHERE orderFk = vOrder; - UPDATE `order` SET confirmed = TRUE, confirm_date = NOW() - WHERE id = vOrder; - - COMMIT; - +CREATE DEFINER=`root`@`%` PROCEDURE `orderConfirmWithUser`(IN `vOrder` INT, IN `vUserId` INT) +BEGIN +/** + * Confirms an order, creating each of its tickets on the corresponding + * date, store and user. + * + * @param vOrder The order identifier + * @param vUser The user identifier + */ + DECLARE vOk BOOL; + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vWarehouse INT; + DECLARE vShipment DATETIME; + DECLARE vTicket INT; + DECLARE vNotes VARCHAR(255); + DECLARE vItem INT; + DECLARE vConcept VARCHAR(30); + DECLARE vAmount INT; + DECLARE vPrice DECIMAL(10,2); + DECLARE vSale INT; + DECLARE vRate INT; + DECLARE vRowId INT; + DECLARE vDelivery DATE; + DECLARE vAddress INT; + DECLARE vAgency INT; + DECLARE vIsConfirmed BOOL; + DECLARE vClientId INT; + DECLARE vCompanyId INT; + DECLARE vAgencyModeId INT; + + DECLARE TICKET_FREE INT DEFAULT 2; + DECLARE SYSTEM_WORKER INT DEFAULT 20; + + DECLARE cDates CURSOR FOR + SELECT ah.shipped, r.warehouse_id + FROM `order` o + JOIN order_row r ON r.order_id = o.id + LEFT JOIN tmp.agencyHourGetShipped ah + ON ah.warehouseFk = r.warehouse_id + WHERE o.id = vOrder AND r.amount != 0 + GROUP BY warehouse_id; + + DECLARE cRows CURSOR FOR + SELECT r.id, r.item_id, a.Article, r.amount, r.price, r.rate + FROM order_row r + JOIN vn2008.Articles a ON a.Id_Article = r.item_id + WHERE r.amount != 0 + AND r.warehouse_id = vWarehouse + AND r.order_id = vOrder + ORDER BY r.rate DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + -- Carga los datos del pedido + + SELECT o.date_send, o.address_id, o.note, a.agency_id, + o.confirmed, cs.Id_Cliente, o.company_id, o.agency_id + INTO vDelivery, vAddress, vNotes, vAgency, + vIsConfirmed, vClientId, vCompanyId, vAgencyModeId + FROM hedera.`order` o + JOIN vn2008.Agencias a ON a.Id_Agencia = o.agency_id + JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = o.address_id + WHERE id = vOrder; + + -- Comprueba que el pedido no está confirmado + + IF vIsConfirmed THEN + CALL util.throw ('ORDER_ALREADY_CONFIRMED'); + END IF; + + -- Comprueba que el pedido no está vacío + + SELECT COUNT(*) > 0 INTO vOk + FROM order_row WHERE order_id = vOrder AND amount > 0; + + IF !vOk THEN + CALL util.throw ('ORDER_EMPTY'); + END IF; + + -- Carga las fechas de salida de cada almacén + + CALL vn.agencyHourGetShipped (vDelivery, vAddress, vAgency); + + -- Trabajador que realiza la acción + + IF vUserId IS NULL THEN + SELECT employeeFk INTO vUserId FROM orderConfig; + END IF; + + -- Crea los tickets del pedido + + START TRANSACTION; + + OPEN cDates; + + lDates: + LOOP + SET vTicket = NULL; + SET vDone = FALSE; + FETCH cDates INTO vShipment, vWarehouse; + + IF vDone THEN + LEAVE lDates; + END IF; + + -- Busca un ticket existente que coincida con los parametros + + SELECT Id_Ticket INTO vTicket + FROM vn2008.Tickets t + LEFT JOIN vn.ticketState tls on tls.ticket = t.Id_Ticket + JOIN `order` o + ON o.address_id = t.Id_Consigna + AND vWarehouse = t.warehouse_id + AND o.agency_id = t.Id_Agencia + AND t.landing = o.date_send + AND vShipment = DATE(t.Fecha) + WHERE o.id = vOrder + AND t.Factura IS NULL + AND IFNULL(tls.alertLevel,0) = 0 + AND t.Id_Cliente <> 1118 + LIMIT 1; + + -- Crea el ticket en el caso de no existir uno adecuado + + IF vTicket IS NULL + THEN + CALL vn.ticketCreateWithUser( + vClientId, + IFNULL(vShipment, CURDATE()), + vWarehouse, + vCompanyId, + vAddress, + vAgencyModeId, + NULL, + vDelivery, + vUserId, + vTicket + ); + ELSE + INSERT INTO vncontrol.inter + SET Id_Ticket = vTicket, + Id_Trabajador = SYSTEM_WORKER, + state_id = TICKET_FREE; + END IF; + + INSERT IGNORE INTO vn2008.order_Tickets + SET order_id = vOrder, + Id_Ticket = vTicket; + + -- Añade las notas + + IF vNotes IS NOT NULL AND vNotes != '' + THEN + INSERT INTO vn2008.ticket_observation SET + Id_Ticket = vTicket, + observation_type_id = 4 /* salesperson */, + `text` = vNotes + ON DUPLICATE KEY UPDATE + `text` = CONCAT(VALUES(`text`),'. ', `text`); + END IF; + + -- Añade los movimientos y sus componentes + + OPEN cRows; + + lRows: + LOOP + SET vDone = FALSE; + FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate; + + IF vDone THEN + LEAVE lRows; + END IF; + + INSERT INTO vn2008.Movimientos + SET + Id_Article = vItem, + Id_Ticket = vTicket, + Concepte = vConcept, + Cantidad = vAmount, + Preu = vPrice, + CostFixat = 0, + PrecioFijado = TRUE; + + SET vSale = LAST_INSERT_ID(); + + INSERT INTO vn2008.Movimientos_componentes + (Id_Movimiento, Id_Componente, Valor) + SELECT vSale, cm.component_id, cm.price + FROM order_component cm + JOIN bi.tarifa_componentes tc + ON tc.Id_Componente = cm.component_id + WHERE cm.order_row_id = vRowId + GROUP BY vSale, cm.component_id; + + UPDATE order_row SET Id_Movimiento = vSale + WHERE id = vRowId; + + END LOOP; + + CLOSE cRows; + + -- Fija el coste + + DROP TEMPORARY TABLE IF EXISTS tComponents; + CREATE TEMPORARY TABLE tComponents + (INDEX (saleFk)) + ENGINE = MEMORY + SELECT SUM(mc.Valor) valueSum, mc.Id_Movimiento saleFk + FROM vn2008.Movimientos_componentes mc + JOIN bi.tarifa_componentes tc USING(Id_Componente) + JOIN bi.tarifa_componentes_series tcs + ON tcs.tarifa_componentes_series_id = tc.tarifa_componentes_series_id + AND tcs.base + JOIN vn2008.Movimientos m + ON m.Id_Movimiento = mc.Id_Movimiento + WHERE m.Id_Ticket = vTicket + GROUP BY mc.Id_Movimiento; + + UPDATE vn2008.Movimientos m + JOIN tComponents mc ON mc.saleFk = m.Id_Movimiento + SET m.CostFixat = valueSum; + + DROP TEMPORARY TABLE tComponents; + END LOOP; + + CLOSE cDates; + + DELETE FROM basketOrder WHERE orderFk = vOrder; + UPDATE `order` SET confirmed = TRUE, confirm_date = NOW() + WHERE id = vOrder; + + COMMIT; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -76049,9 +77325,9 @@ DELIMITER ; /*!50003 SET character_set_results = utf8 */ ; /*!50003 SET collation_connection = utf8_general_ci */ ; /*!50003 SET @saved_sql_mode = @@sql_mode */ ; -/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; DELIMITER ;; -CREATE DEFINER=`root`@`%` PROCEDURE `orderGetTax`(vOrder INT) +CREATE DEFINER=`root`@`%` PROCEDURE `orderGetTax`() READS SQL DATA BEGIN /** @@ -76061,38 +77337,88 @@ BEGIN * @param vOrder El identificador del pedido * @treturn tmp.orderTax Bases imponibles, IVA y recargo de equivalencia */ - CALL vn.taxGetRates (NULL); + DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany; + CREATE TEMPORARY TABLE tmp.addressCompany + (INDEX (addressFk, companyFk)) + ENGINE = MEMORY + SELECT DISTINCT o.address_id addressFk, o.company_id companyFk + FROM tmp.order tmpOrder + JOIN hedera.order o ON o.id = tmpOrder.orderFk; + + CALL vn.addressTaxArea (); -- Calcula el IVA y el recargo desglosado. - DROP TEMPORARY TABLE IF EXISTS tmp.orderTax; CREATE TEMPORARY TABLE tmp.orderTax (INDEX (orderFk)) ENGINE = MEMORY - SELECT id orderFk, t.type, t.taxBase, - CAST(IF(t.hasTax, t.taxBase * x.rate, 0) AS DECIMAL(10,2)) tax, - CAST(IF(t.hasEqualizationTax, t.taxBase * x.equalizationTax, 0) AS DECIMAL(10,2)) equalizationTax - FROM ( - SELECT o.id, g.countryFk, g.type - ,SUM(CAST(m.amount * m.price AS DECIMAL(10,2))) taxBase - ,NOT(c.isVies AND p.countryFk <> c.countryFk) hasTax - ,c.isEqualizated != FALSE AS hasEqualizationTax - FROM `order` o + SELECT o.id orderFk, + tc.code, + SUM(m.amount * m.price) taxableBase, + pgc.rate + FROM tmp.order tmpOrder + JOIN `order` o ON o.id = tmpOrder.orderFk JOIN orderRow m ON m.orderFk = o.id - JOIN vn.item a ON a.id = m.itemFk + JOIN vn.item i ON i.id = m.itemFk JOIN vn.client c ON c.id = o.customer_id - JOIN vn.supplier p ON p.id = o.company_id - JOIN tmp.taxClass g - ON g.countryFk = p.countryFk AND g.taxClassFk = a.taxClassFk - WHERE o.id = vOrder - GROUP BY o.id, g.type - ) t - JOIN tmp.taxType x - ON x.countryFk = t.countryFk AND x.type = t.type; + JOIN vn.supplier s ON s.id = o.company_id + JOIN tmp.addressTaxArea ata + ON ata.addressFk = o.address_id AND ata.companyFk = o.company_id + JOIN vn.itemTaxCountry itc + ON itc.itemFk = i.id AND itc.countryFk = s.countryFk + JOIN vn.bookingPlanner bp + ON bp.countryFk = s.countryFk + AND bp.taxAreaFk = ata.areaFk + AND bp.taxClassFk = itc.taxClassFk + JOIN vn.pgc ON pgc.code = bp.pgcFk + JOIN vn.taxClass tc ON tc.id = bp.taxClassFk + GROUP BY tmpOrder.orderFk, pgc.code,pgc.rate + HAVING taxableBase != 0; + + DROP TEMPORARY TABLE IF EXISTS tmp.orderAmount; + CREATE TEMPORARY TABLE tmp.orderAmount + (INDEX (orderFk)) + ENGINE = MEMORY + SELECT orderFk, taxableBase, SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax,code + FROM tmp.orderTax + GROUP BY orderFk, code; - DROP TEMPORARY TABLE - tmp.taxClass, - tmp.taxType; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `orderGetTotal` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'IGNORE_SPACE,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `orderGetTotal`() +BEGIN +/** +* Calcula el total con IVA para un conjunto de orders. +* +* @table tmp.order(orderFk) Identificadores de las ordenes a calcular +* @return tmp.orderTotal Total para cada order +*/ +CALL orderGetTax; + +DROP TEMPORARY TABLE IF EXISTS tmp.orderTotal; +CREATE TEMPORARY TABLE tmp.orderTotal +(INDEX (orderFk)) +ENGINE = MEMORY +SELECT o.orderFk, IFNULL(SUM(ot.taxableBase + ot.tax), 0.0) AS total +FROM tmp.order o +LEFT JOIN tmp.orderAmount ot ON o.orderFk = ot.orderFk +GROUP BY orderFk; + +DROP TEMPORARY TABLE IF EXISTS tmp.orderTax; END ;; DELIMITER ; /*!50003 SET sql_mode = @saved_sql_mode */ ; @@ -76799,6 +78125,229 @@ DELIMITER ; /*!50003 SET character_set_client = @saved_cs_client */ ; /*!50003 SET character_set_results = @saved_cs_results */ ; /*!50003 SET collation_connection = @saved_col_connection */ ; +/*!50003 DROP PROCEDURE IF EXISTS `__orderConfirmWithUser` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8mb4 */ ; +/*!50003 SET character_set_results = utf8mb4 */ ; +/*!50003 SET collation_connection = utf8mb4_unicode_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`%` PROCEDURE `__orderConfirmWithUser`(vOrder INT, vUserId INT) +BEGIN + + DECLARE vOk BOOL; + DECLARE vDone BOOL DEFAULT FALSE; + DECLARE vWarehouse INT; + DECLARE vShipment DATETIME; + DECLARE vTicket INT; + DECLARE vNotes VARCHAR(255); + DECLARE vItem INT; + DECLARE vConcept VARCHAR(30); + DECLARE vAmount INT; + DECLARE vPrice DECIMAL(10,2); + DECLARE vSale INT; + DECLARE vRate INT; + DECLARE vRowId INT; + DECLARE vDelivery DATE; + DECLARE vAddress INT; + DECLARE vAgency INT; + DECLARE vIsConfirmed BOOL; + DECLARE vClientId INT; + DECLARE vCompanyId INT; + DECLARE vAgencyModeId INT; + + DECLARE TICKET_FREE INT DEFAULT 2; + DECLARE SYSTEM_WORKER INT DEFAULT 20; + + DECLARE cDates CURSOR FOR + SELECT ah.shipped, r.warehouse_id + FROM `order` o + JOIN order_row r ON r.order_id = o.id + LEFT JOIN tmp.agencyHourGetShipped ah ON ah.warehouseFk = r.warehouse_id + WHERE o.id = vOrder AND r.amount != 0 + GROUP BY warehouse_id; + + DECLARE cRows CURSOR FOR + SELECT r.id, r.item_id, a.Article, r.amount, r.price, r.rate + FROM order_row r + JOIN vn2008.Articles a ON a.Id_Article = r.item_id + WHERE r.amount != 0 + AND r.warehouse_id = vWarehouse + AND r.order_id = vOrder + ORDER BY r.rate DESC; + + DECLARE CONTINUE HANDLER FOR NOT FOUND + SET vDone = TRUE; + + DECLARE EXIT HANDLER FOR SQLEXCEPTION + BEGIN + ROLLBACK; + RESIGNAL; + END; + + + SELECT o.date_send, o.address_id, o.note, a.agency_id, + o.confirmed, cs.Id_Cliente, o.company_id, o.agency_id + INTO vDelivery, vAddress, vNotes, vAgency, + vIsConfirmed, vClientId, vCompanyId, vAgencyModeId + FROM hedera.`order` o + JOIN vn2008.Agencias a ON a.Id_Agencia = o.agency_id + JOIN vn2008.Consignatarios cs ON cs.Id_Consigna = o.address_id + WHERE id = vOrder; + + + IF vIsConfirmed THEN + CALL util.throw ('ORDER_ALREADY_CONFIRMED'); + END IF; + + + SELECT COUNT(*) > 0 INTO vOk + FROM order_row WHERE order_id = vOrder AND amount > 0; + + IF !vOk THEN + CALL util.throw ('ORDER_EMPTY'); + END IF; + + + CALL vn.agencyHourGetShipped (vDelivery, vAddress, vAgency); + + + IF vUserId IS NULL THEN + SELECT employeeFk INTO vUserId FROM orderConfig; + END IF; + + + START TRANSACTION; + + OPEN cDates; + + lDates: + LOOP + SET vTicket = NULL; + SET vDone = FALSE; + FETCH cDates INTO vShipment, vWarehouse; + + IF vDone THEN + LEAVE lDates; + END IF; + + + SELECT Id_Ticket INTO vTicket + FROM vn2008.Tickets t + LEFT JOIN vn.ticketState tls on tls.ticket = t.Id_Ticket + JOIN `order` o + ON o.address_id = t.Id_Consigna + AND vWarehouse = t.warehouse_id + AND o.agency_id = t.Id_Agencia + AND t.landing = o.date_send + AND vShipment = DATE(t.Fecha) + WHERE o.id = vOrder + AND t.Factura IS NULL + AND IFNULL(tls.alertLevel,0) = 0 + AND t.Id_Cliente <> 1118 + LIMIT 1; + + + IF vTicket IS NULL + THEN + CALL vn.ticketCreateWithUser( + vClientId, + IFNULL(vShipment, CURDATE()), + vWarehouse, + vCompanyId, + vAddress, + vAgencyModeId, + NULL, + vDelivery, + vUserId, + vTicket + ); + ELSE + INSERT INTO vncontrol.inter + SET Id_Ticket = vTicket, + Id_Trabajador = SYSTEM_WORKER, + state_id = TICKET_FREE; + END IF; + + INSERT IGNORE INTO vn2008.order_Tickets + SET order_id = vOrder, + Id_Ticket = vTicket; + + + IF vNotes IS NOT NULL AND vNotes != '' + THEN + INSERT INTO vn2008.ticket_observation (Id_Ticket, observation_type_id, text) + VALUES (vTicket, 4 , vNotes) + ON DUPLICATE KEY UPDATE text = CONCAT(VALUES(text),'. ', text); + END IF; + + + OPEN cRows; + + lRows: + LOOP + SET vDone = FALSE; + FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate; + + IF vDone THEN + LEAVE lRows; + END IF; + + INSERT INTO vn2008.Movimientos + SET + Id_Article = vItem, + Id_Ticket = vTicket, + Concepte = vConcept, + Cantidad = vAmount, + Preu = vPrice, + CostFixat = 0, + PrecioFijado = TRUE; + + SET vSale = LAST_INSERT_ID(); + + INSERT INTO vn2008.Movimientos_componentes (Id_Movimiento, Id_Componente, Valor) + SELECT vSale, cm.component_id, cm.price + FROM order_component cm + JOIN bi.tarifa_componentes tc ON tc.Id_Componente = cm.component_id + WHERE cm.order_row_id = vRowId + GROUP BY vSale, cm.component_id; + + UPDATE order_row SET Id_Movimiento = vSale + WHERE id = vRowId; + + END LOOP; + + CLOSE cRows; + + + UPDATE vn2008.Movimientos m + JOIN (SELECT SUM(mc.Valor) sum_valor,mc.Id_Movimiento + FROM vn2008.Movimientos_componentes mc + JOIN bi.tarifa_componentes tc USING(Id_Componente) + JOIN bi.tarifa_componentes_series tcs on tcs.tarifa_componentes_series_id = tc.tarifa_componentes_series_id AND tcs.base + JOIN vn2008.Movimientos m ON m.Id_Movimiento = mc.Id_Movimiento + WHERE m.Id_Ticket = vTicket + GROUP BY mc.Id_Movimiento) mc ON mc.Id_Movimiento = m.Id_Movimiento + SET m.CostFixat = sum_valor; + END LOOP; + + CLOSE cDates; + + DELETE FROM basketOrder WHERE orderFk = vOrder; + UPDATE `order` SET confirmed = TRUE, confirm_date = NOW() + WHERE id = vOrder; + + COMMIT; + +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; -- -- Current Database: `stock` @@ -77557,6 +79106,1227 @@ CREATE DATABASE /*!32312 IF NOT EXISTS*/ `postgresql` /*!40100 DEFAULT CHARACTER USE `postgresql`; +-- +-- Table structure for table `__address_default` +-- + +DROP TABLE IF EXISTS `__address_default`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__address_default` ( + `address_default_id` int(11) NOT NULL AUTO_INCREMENT, + `profile_business_id` int(11) NOT NULL, + `address_id` int(11) NOT NULL, + PRIMARY KEY (`address_default_id`), + KEY `address_default_address_id_idx` (`address_id`), + CONSTRAINT `fk_media_default_copy1_address1` FOREIGN KEY (`address_id`) REFERENCES `address` (`address_id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__business_agricultural` +-- + +DROP TABLE IF EXISTS `__business_agricultural`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__business_agricultural` ( + `business_id` int(11) NOT NULL, + PRIMARY KEY (`business_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__business_common` +-- + +DROP TABLE IF EXISTS `__business_common`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__business_common` ( + `business_id` int(11) NOT NULL, + `rate` int(11) DEFAULT NULL, + `credit` int(11) DEFAULT NULL, + PRIMARY KEY (`business_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__business_labour_calendar_employee` +-- + +DROP TABLE IF EXISTS `__business_labour_calendar_employee`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__business_labour_calendar_employee` ( + `business_labour_calendar_employee_id` int(11) NOT NULL, + `business_id` int(11) NOT NULL, + `calendar_labour_type_id` int(11) NOT NULL, + `date_start` date NOT NULL, + PRIMARY KEY (`business_id`,`date_start`), + KEY `hour_labour_id` (`calendar_labour_type_id`), + CONSTRAINT `business_id` FOREIGN KEY (`business_id`) REFERENCES `business_labour` (`business_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `hour_labour_id` FOREIGN KEY (`calendar_labour_type_id`) REFERENCES `calendar_labour_type` (`calendar_labour_type_id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__business_labour_ccc` +-- + +DROP TABLE IF EXISTS `__business_labour_ccc`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__business_labour_ccc` ( + `business_id` int(11) NOT NULL, + `ccc` varchar(30) NOT NULL, + `date_start` datetime DEFAULT NULL, + `date_end` datetime DEFAULT NULL, + PRIMARY KEY (`business_id`,`ccc`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__business_labour_payment` +-- + +DROP TABLE IF EXISTS `__business_labour_payment`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__business_labour_payment` ( + `business_id` int(11) DEFAULT NULL, + `amount` double DEFAULT NULL, + `date` date DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__business_link` +-- + +DROP TABLE IF EXISTS `__business_link`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__business_link` ( + `business_id` int(11) NOT NULL, + `copy_business_id` int(11) NOT NULL, + PRIMARY KEY (`business_id`), + KEY `business_link_copy_business_id_idx` (`copy_business_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__business_professional` +-- + +DROP TABLE IF EXISTS `__business_professional`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__business_professional` ( + `business_id` int(11) NOT NULL, + PRIMARY KEY (`business_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__business_service` +-- + +DROP TABLE IF EXISTS `__business_service`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__business_service` ( + `business_id` int(11) NOT NULL, + PRIMARY KEY (`business_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__business_transport` +-- + +DROP TABLE IF EXISTS `__business_transport`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__business_transport` ( + `business_id` int(11) NOT NULL, + `m3` int(11) DEFAULT NULL, + PRIMARY KEY (`business_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__clado` +-- + +DROP TABLE IF EXISTS `__clado`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__clado` ( + `n` int(11) NOT NULL, + `col` int(11) DEFAULT NULL, + `fid` int(11) DEFAULT NULL, + `lin` int(11) DEFAULT NULL, + PRIMARY KEY (`n`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__class` +-- + +DROP TABLE IF EXISTS `__class`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__class` ( + `class_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(10) DEFAULT NULL, + PRIMARY KEY (`class_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__color` +-- + +DROP TABLE IF EXISTS `__color`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__color` ( + `color_id` int(11) NOT NULL AUTO_INCREMENT, + `image` longblob NOT NULL, + `sort` smallint(6) NOT NULL, + `name` char(3) DEFAULT NULL, + PRIMARY KEY (`color_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__convenio_time` +-- + +DROP TABLE IF EXISTS `__convenio_time`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__convenio_time` ( + `pausa_remunerada` time DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__dbljornada` +-- + +DROP TABLE IF EXISTS `__dbljornada`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__dbljornada` ( + `?column?` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__delivery` +-- + +DROP TABLE IF EXISTS `__delivery`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__delivery` ( + `delivery_id` int(11) NOT NULL AUTO_INCREMENT, + `state_id` int(11) NOT NULL DEFAULT '1', + `business_id` int(11) NOT NULL, + `travel_id` int(11) NOT NULL, + `ref` varchar(15) DEFAULT NULL, + `notes` varchar(50) DEFAULT NULL, + `tax` double DEFAULT NULL, + `invoice_id` int(11) DEFAULT NULL, + PRIMARY KEY (`delivery_id`), + KEY `delivery_invoice_id_idx` (`invoice_id`), + KEY `delivery_state_id_idx` (`state_id`), + KEY `delivery_travel_id_idx` (`travel_id`), + CONSTRAINT `__delivery_ibfk_1` FOREIGN KEY (`travel_id`) REFERENCES `__travel` (`travel_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `__delivery_ibfk_2` FOREIGN KEY (`state_id`) REFERENCES `__state_delivery` (`state_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `fk_delivery_invoice1` FOREIGN KEY (`invoice_id`) REFERENCES `__invoice` (`invoice_id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__delivery_expedition` +-- + +DROP TABLE IF EXISTS `__delivery_expedition`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__delivery_expedition` ( + `delivery_id` int(11) NOT NULL, + `expedition` int(11) DEFAULT NULL, + PRIMARY KEY (`delivery_id`), + CONSTRAINT `fk_delivery_expedition_delivery1` FOREIGN KEY (`delivery_id`) REFERENCES `__delivery` (`delivery_id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__discount_type` +-- + +DROP TABLE IF EXISTS `__discount_type`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__discount_type` ( + `discount_type_id` int(11) NOT NULL AUTO_INCREMENT, + `amount` double NOT NULL, + `description` varchar(1) NOT NULL, + `combine` smallint(6) DEFAULT NULL, + PRIMARY KEY (`discount_type_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__doc` +-- + +DROP TABLE IF EXISTS `__doc`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__doc` ( + `doc_id` int(11) NOT NULL AUTO_INCREMENT, + `worker_id` int(11) NOT NULL, + `person_id` int(11) NOT NULL, + `doc_type_id` int(11) NOT NULL, + `sref` varchar(15) NOT NULL, + `brief` varchar(200) DEFAULT NULL, + `sort` int(11) DEFAULT NULL, + `filename` varchar(30) NOT NULL, + `original` smallint(6) NOT NULL, + PRIMARY KEY (`doc_id`), + KEY `doc_doc_type_id_idx` (`doc_type_id`), + KEY `doc_person_id_idx` (`person_id`), + KEY `doc_worker_id_idx` (`worker_id`), + CONSTRAINT `__doc_ibfk_1` FOREIGN KEY (`doc_type_id`) REFERENCES `__doc_type` (`doc_type_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `__doc_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `person` (`person_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `__doc_ibfk_3` FOREIGN KEY (`worker_id`) REFERENCES `person` (`person_id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__doc_type` +-- + +DROP TABLE IF EXISTS `__doc_type`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__doc_type` ( + `doc_type_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(20) NOT NULL, + `path` varchar(30) NOT NULL, + PRIMARY KEY (`doc_type_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__family` +-- + +DROP TABLE IF EXISTS `__family`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__family` ( + `family_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(15) NOT NULL, + `sort` smallint(6) NOT NULL, + `father_id` int(11) DEFAULT NULL, + `temperature` longtext, + PRIMARY KEY (`family_id`), + KEY `family_father_id_idx` (`father_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__goodbusiness_id` +-- + +DROP TABLE IF EXISTS `__goodbusiness_id`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__goodbusiness_id` ( + `business_id` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__holding` +-- + +DROP TABLE IF EXISTS `__holding`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__holding` ( + `holding_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(20) DEFAULT NULL, + PRIMARY KEY (`holding_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__holding_person` +-- + +DROP TABLE IF EXISTS `__holding_person`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__holding_person` ( + `holding_person_id` int(11) NOT NULL AUTO_INCREMENT, + `person_id` int(11) NOT NULL, + `holding_id` int(11) NOT NULL, + PRIMARY KEY (`holding_person_id`), + KEY `holding_person_holding_id_idx` (`holding_id`), + KEY `holding_person_person_id_idx` (`person_id`), + CONSTRAINT `__holding_person_ibfk_1` FOREIGN KEY (`holding_id`) REFERENCES `__holding` (`holding_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `__holding_person_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `person` (`person_id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__intbus_id` +-- + +DROP TABLE IF EXISTS `__intbus_id`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__intbus_id` ( + `business_id` int(11) DEFAULT NULL, + `person_id` int(11) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__intrastat_code` +-- + +DROP TABLE IF EXISTS `__intrastat_code`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__intrastat_code` ( + `intrastat_code_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `sort` smallint(6) NOT NULL, + PRIMARY KEY (`intrastat_code_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__invoice` +-- + +DROP TABLE IF EXISTS `__invoice`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__invoice` ( + `invoice_id` int(11) NOT NULL AUTO_INCREMENT, + `currency_id` int(11) NOT NULL DEFAULT '1', + `business_id` int(11) NOT NULL, + `doc_id` int(11) DEFAULT NULL, + `date` date NOT NULL, + `serie` char(2) DEFAULT NULL, + `ref` bigint(20) NOT NULL, + `amount` double DEFAULT NULL, + PRIMARY KEY (`invoice_id`), + KEY `invoice_business_id_idx` (`business_id`), + KEY `invoice_currency_id_idx` (`currency_id`), + KEY `invoice_doc_id_idx` (`doc_id`), + CONSTRAINT `__invoice_ibfk_2` FOREIGN KEY (`doc_id`) REFERENCES `__doc` (`doc_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `__invoice_ibfk_3` FOREIGN KEY (`currency_id`) REFERENCES `currency` (`currency_id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__item` +-- + +DROP TABLE IF EXISTS `__item`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__item` ( + `item_id` int(11) NOT NULL AUTO_INCREMENT, + `variety_id` int(11) NOT NULL, + PRIMARY KEY (`item_id`), + KEY `item_variety_id_idx` (`variety_id`), + CONSTRAINT `fk_item_variety1` FOREIGN KEY (`variety_id`) REFERENCES `__variety` (`variety_id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__license` +-- + +DROP TABLE IF EXISTS `__license`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__license` ( + `profile_id` int(11) DEFAULT NULL, + `license_group_id` int(11) DEFAULT NULL, + UNIQUE KEY `license_profile_id_key` (`profile_id`,`license_group_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__license_group` +-- + +DROP TABLE IF EXISTS `__license_group`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__license_group` ( + `license_group_id` int(11) NOT NULL AUTO_INCREMENT, + `tipopermiso` char(1) DEFAULT NULL, + `menu_id` int(11) DEFAULT NULL, + PRIMARY KEY (`license_group_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__license_menu` +-- + +DROP TABLE IF EXISTS `__license_menu`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__license_menu` ( + `menu_id` int(11) DEFAULT NULL, + `nommenu` longtext +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__lot` +-- + +DROP TABLE IF EXISTS `__lot`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__lot` ( + `lot_id` int(11) NOT NULL, + `opinion_id` int(11) DEFAULT NULL, + `quality_id` int(11) DEFAULT NULL, + `amount` smallint(6) NOT NULL, + `expire` smallint(6) NOT NULL, + `address_id` int(11) NOT NULL, + `item_id` int(11) NOT NULL, + `labour_profile_id` int(11) NOT NULL, + `price_unit_id` int(11) NOT NULL, + `sales_unit_id` int(11) NOT NULL, + PRIMARY KEY (`lot_id`), + KEY `lot_address_id_idx` (`address_id`), + KEY `lot_item_id_idx` (`item_id`), + KEY `lot_opinion_id_idx` (`opinion_id`), + KEY `lot_price_unit_id_idx` (`price_unit_id`), + KEY `lot_quality_id_idx` (`quality_id`), + KEY `lot_sales_unit_id_idx` (`sales_unit_id`), + CONSTRAINT `__lot_ibfk_12` FOREIGN KEY (`address_id`) REFERENCES `__origin` (`address_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `__lot_ibfk_3` FOREIGN KEY (`quality_id`) REFERENCES `__quality` (`quality_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `__lot_ibfk_8` FOREIGN KEY (`opinion_id`) REFERENCES `__opinion` (`opinion_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `fk_lot_item1` FOREIGN KEY (`item_id`) REFERENCES `__item` (`item_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `fk_lot_pack_type1` FOREIGN KEY (`sales_unit_id`) REFERENCES `__pack_type` (`pack_type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `fk_lot_pack_type2` FOREIGN KEY (`price_unit_id`) REFERENCES `__pack_type` (`pack_type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__lot_packing` +-- + +DROP TABLE IF EXISTS `__lot_packing`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__lot_packing` ( + `lot_packing_id` int(11) NOT NULL AUTO_INCREMENT, + `packing_id` int(11) NOT NULL, + `lot_id` int(11) NOT NULL, + PRIMARY KEY (`lot_packing_id`), + KEY `lot_packing_lot_id_idx` (`lot_id`), + KEY `lot_packing_packing_id_idx` (`packing_id`), + CONSTRAINT `fk_lot_packing_lot1` FOREIGN KEY (`lot_id`) REFERENCES `__lot` (`lot_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `fk_lot_packing_packing1` FOREIGN KEY (`packing_id`) REFERENCES `__packing` (`packing_id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__lot_property` +-- + +DROP TABLE IF EXISTS `__lot_property`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__lot_property` ( + `lot_property_id` int(11) NOT NULL AUTO_INCREMENT, + `property_id` int(11) NOT NULL, + `lot_id` int(11) NOT NULL, + PRIMARY KEY (`lot_property_id`), + KEY `lot_property_lot_id_idx` (`lot_id`), + KEY `lot_property_property_id_idx` (`property_id`), + CONSTRAINT `fk_lot_property_lot1` FOREIGN KEY (`lot_id`) REFERENCES `__lot` (`lot_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `fk_lot_property_property1` FOREIGN KEY (`property_id`) REFERENCES `__property` (`property_id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__maintenance_pcs` +-- + +DROP TABLE IF EXISTS `__maintenance_pcs`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__maintenance_pcs` ( + `pc_nombre` char(6) NOT NULL, + `os` varchar(20) DEFAULT NULL, + `servicepack` varchar(20) DEFAULT NULL, + `nmonitores` int(11) DEFAULT NULL, + `micro` varchar(20) DEFAULT NULL, + `antivirus` varchar(20) DEFAULT NULL, + `ram` varchar(20) DEFAULT NULL, + `user_name` varchar(40) DEFAULT NULL, + `business_id` int(11) DEFAULT NULL, + `ip` varchar(15) DEFAULT NULL, + `auric` varchar(20) DEFAULT NULL, + `pgsql` char(2) DEFAULT NULL, + PRIMARY KEY (`pc_nombre`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__media_default` +-- + +DROP TABLE IF EXISTS `__media_default`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__media_default` ( + `media_default_id` int(11) NOT NULL AUTO_INCREMENT, + `media_media_id` int(11) NOT NULL, + `business_profile_business_id` int(11) NOT NULL, + PRIMARY KEY (`media_default_id`), + KEY `media_default_media_media_id_idx` (`media_media_id`), + CONSTRAINT `fk_media_default_media1` FOREIGN KEY (`media_media_id`) REFERENCES `media` (`media_id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__menus_perm` +-- + +DROP TABLE IF EXISTS `__menus_perm`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__menus_perm` ( + `idmenus_perm` int(11) NOT NULL AUTO_INCREMENT, + `menu` varchar(45) DEFAULT NULL, + `father_id` int(11) DEFAULT NULL, + `icono` longblob, + `idorden` smallint(6) DEFAULT NULL, + PRIMARY KEY (`idmenus_perm`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__mutua` +-- + +DROP TABLE IF EXISTS `__mutua`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__mutua` ( + `mutua_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(100) DEFAULT NULL, + PRIMARY KEY (`mutua_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__mutua_employee` +-- + +DROP TABLE IF EXISTS `__mutua_employee`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__mutua_employee` ( + `business_id` int(11) DEFAULT NULL, + `capable` tinyint(4) DEFAULT NULL, + `notes` longtext, + `mutura_revisiones_id` int(11) NOT NULL, + PRIMARY KEY (`mutura_revisiones_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__mutua_revisiones` +-- + +DROP TABLE IF EXISTS `__mutua_revisiones`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__mutua_revisiones` ( + `mutua_id` int(11) NOT NULL, + `date` datetime DEFAULT NULL, + `mutua_revisiones_id` int(11) NOT NULL, + PRIMARY KEY (`mutua_revisiones_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__nominas_gestoria` +-- + +DROP TABLE IF EXISTS `__nominas_gestoria`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__nominas_gestoria` ( + `numgestoria` int(11) NOT NULL, + `empresa_id` int(11) NOT NULL, + `person_id` int(11) DEFAULT NULL, + `numcontaplus` int(11) DEFAULT NULL, + PRIMARY KEY (`numgestoria`,`empresa_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__opinion` +-- + +DROP TABLE IF EXISTS `__opinion`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__opinion` ( + `opinion_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(15) DEFAULT NULL, + PRIMARY KEY (`opinion_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__origin` +-- + +DROP TABLE IF EXISTS `__origin`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__origin` ( + `nick` char(3) NOT NULL, + `name` varchar(15) NOT NULL, + `flag` longblob, + `address_id` int(11) NOT NULL, + `font` smallint(6) DEFAULT NULL, + PRIMARY KEY (`address_id`), + CONSTRAINT `origin_adress_id` FOREIGN KEY (`address_id`) REFERENCES `address` (`address_id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__pack_type` +-- + +DROP TABLE IF EXISTS `__pack_type`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__pack_type` ( + `pack_type_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(15) DEFAULT 'A1', + `brief` varchar(3) DEFAULT NULL, + PRIMARY KEY (`pack_type_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__packing` +-- + +DROP TABLE IF EXISTS `__packing`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__packing` ( + `packing_id` int(11) NOT NULL AUTO_INCREMENT, + `amount` int(11) DEFAULT NULL, + `pack_type_id` int(11) NOT NULL, + PRIMARY KEY (`packing_id`), + KEY `packing_pack_type_id_idx` (`pack_type_id`), + CONSTRAINT `fk_packing_pack_type1` FOREIGN KEY (`pack_type_id`) REFERENCES `__pack_type` (`pack_type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__pagosemanal` +-- + +DROP TABLE IF EXISTS `__pagosemanal`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__pagosemanal` ( + `periodo` int(11) NOT NULL, + `business_id` int(11) NOT NULL, + `id_trabajador` int(11) DEFAULT NULL, + `importe` double DEFAULT NULL, + `horasemanales` time DEFAULT NULL, + `contrato` time DEFAULT NULL, + `impar` tinyint(4) DEFAULT '0', + PRIMARY KEY (`periodo`,`business_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__pagosemanal_new` +-- + +DROP TABLE IF EXISTS `__pagosemanal_new`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__pagosemanal_new` ( + `periodo` int(11) NOT NULL, + `business_id` int(11) NOT NULL, + `id_trabajador` int(11) DEFAULT NULL, + `importe` double DEFAULT NULL, + `horasemanales` time DEFAULT NULL, + `contrato` time DEFAULT NULL, + `impar` tinyint(4) DEFAULT '0', + `person_id` int(11) DEFAULT NULL, + PRIMARY KEY (`periodo`,`business_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__property` +-- + +DROP TABLE IF EXISTS `__property`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__property` ( + `property_id` int(11) NOT NULL AUTO_INCREMENT, + `value` smallint(6) NOT NULL, + `class_id` int(11) NOT NULL, + PRIMARY KEY (`property_id`), + KEY `property_class_id_idx` (`class_id`), + CONSTRAINT `fk_property_class1` FOREIGN KEY (`class_id`) REFERENCES `__class` (`class_id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__quality` +-- + +DROP TABLE IF EXISTS `__quality`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__quality` ( + `quality_id` int(11) NOT NULL AUTO_INCREMENT, + `name` char(3) DEFAULT 'A1', + PRIMARY KEY (`quality_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__state` +-- + +DROP TABLE IF EXISTS `__state`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__state` ( + `state_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(15) DEFAULT NULL, + PRIMARY KEY (`state_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__state_delivery` +-- + +DROP TABLE IF EXISTS `__state_delivery`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__state_delivery` ( + `state_id` int(11) NOT NULL, + `sort` int(11) NOT NULL, + PRIMARY KEY (`state_id`), + UNIQUE KEY `state_delivery_sort_key` (`sort`), + KEY `state_delivery_state_id_idx` (`state_id`), + CONSTRAINT `state_ordre_ibfk_1` FOREIGN KEY (`state_id`) REFERENCES `__state` (`state_id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__state_travel` +-- + +DROP TABLE IF EXISTS `__state_travel`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__state_travel` ( + `state_id` int(11) NOT NULL, + `sort` int(11) DEFAULT NULL, + PRIMARY KEY (`state_id`), + UNIQUE KEY `state_travel_sort_key` (`sort`), + KEY `state_travel_state_id_idx` (`state_id`), + CONSTRAINT `__state_travel_ibfk_1` FOREIGN KEY (`state_id`) REFERENCES `__state` (`state_id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__tipo_perm` +-- + +DROP TABLE IF EXISTS `__tipo_perm`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__tipo_perm` ( + `idtipo_perm` int(11) NOT NULL AUTO_INCREMENT, + `tipopermiso` varchar(45) DEFAULT NULL, + PRIMARY KEY (`idtipo_perm`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__totalms` +-- + +DROP TABLE IF EXISTS `__totalms`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__totalms` ( + `date_part` double DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__transfer_reader` +-- + +DROP TABLE IF EXISTS `__transfer_reader`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__transfer_reader` ( + `transfer_reader_id` int(11) NOT NULL AUTO_INCREMENT, + `business_id` int(11) DEFAULT NULL, + `idorden` int(11) DEFAULT NULL, + `date` datetime DEFAULT NULL, + `manual` tinyint(4) DEFAULT '0', + `person_id` int(11) DEFAULT NULL, + `workcenter_id` int(11) DEFAULT NULL, + PRIMARY KEY (`transfer_reader_id`), + UNIQUE KEY `wc_date_person_UNIQUE` (`workcenter_id`,`date`,`person_id`), + KEY `fki_person_transfer` (`person_id`), + KEY `fk_id` (`business_id`), + CONSTRAINT `fk_id` FOREIGN KEY (`business_id`) REFERENCES `business_labour` (`business_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `person_transfer` FOREIGN KEY (`person_id`) REFERENCES `person` (`person_id`) ON UPDATE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=1090649 DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__transfer_reader_horasfichajes` +-- + +DROP TABLE IF EXISTS `__transfer_reader_horasfichajes`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__transfer_reader_horasfichajes` ( + `transfer_reader_horasfichajes_id` int(11) NOT NULL AUTO_INCREMENT, + `hora` time DEFAULT NULL, + PRIMARY KEY (`transfer_reader_horasfichajes_id`), + UNIQUE KEY `punique_trhf` (`hora`) +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__transfer_reader_incidencias` +-- + +DROP TABLE IF EXISTS `__transfer_reader_incidencias`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__transfer_reader_incidencias` ( + `transfer_reader_id` int(11) NOT NULL, + `transfer_reader_incidencias_type_id` int(11) NOT NULL, + PRIMARY KEY (`transfer_reader_id`), + KEY `fki_fkey` (`transfer_reader_id`), + KEY `fki_fkey1` (`transfer_reader_id`), + KEY `fki_fkey2` (`transfer_reader_incidencias_type_id`), + CONSTRAINT `fkey` FOREIGN KEY (`transfer_reader_id`) REFERENCES `__transfer_reader` (`transfer_reader_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `fkey2` FOREIGN KEY (`transfer_reader_incidencias_type_id`) REFERENCES `__transfer_reader_incidencias_type` (`transfer_reader_incidencias_type_id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__transfer_reader_incidencias_type` +-- + +DROP TABLE IF EXISTS `__transfer_reader_incidencias_type`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__transfer_reader_incidencias_type` ( + `transfer_reader_incidencias_type_id` int(11) NOT NULL AUTO_INCREMENT, + `descripcion` longtext NOT NULL, + PRIMARY KEY (`transfer_reader_incidencias_type_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__transfer_reader_relationship` +-- + +DROP TABLE IF EXISTS `__transfer_reader_relationship`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__transfer_reader_relationship` ( + `id` int(11) NOT NULL, + `nis` bigint(20) NOT NULL, + `id_trabajador` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `fichador` (`nis`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__transfer_reader_relationship_nuevolector` +-- + +DROP TABLE IF EXISTS `__transfer_reader_relationship_nuevolector`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__transfer_reader_relationship_nuevolector` ( + `nis` bigint(20) DEFAULT NULL, + `id_trabajador` int(11) DEFAULT NULL, + `id` int(11) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `pkeyniss` (`nis`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__transfer_reader_tmp` +-- + +DROP TABLE IF EXISTS `__transfer_reader_tmp`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__transfer_reader_tmp` ( + `nis` int(11) NOT NULL, + `date` datetime NOT NULL, + `transfer_reader_id` int(11) NOT NULL, + `warehouseFk` smallint(6) unsigned DEFAULT NULL, + PRIMARY KEY (`nis`,`date`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__travel` +-- + +DROP TABLE IF EXISTS `__travel`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__travel` ( + `travel_id` int(11) NOT NULL AUTO_INCREMENT, + `state_id` int(11) NOT NULL DEFAULT '1', + `shipment` date NOT NULL, + `landing` date NOT NULL, + `name` varchar(15) DEFAULT NULL, + `address_out_id` int(11) NOT NULL, + `address_in_id` int(11) NOT NULL, + `agency_id` int(11) NOT NULL, + PRIMARY KEY (`travel_id`), + KEY `travel_address_in_id_idx` (`address_in_id`), + KEY `travel_address_out_id_idx` (`address_out_id`), + KEY `travel_agency_id_idx` (`agency_id`), + KEY `travel_state_id_idx` (`state_id`), + CONSTRAINT `__travel_ibfk_4` FOREIGN KEY (`state_id`) REFERENCES `__state_travel` (`state_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `fk_travel_address1` FOREIGN KEY (`address_out_id`) REFERENCES `address` (`address_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `fk_travel_address2` FOREIGN KEY (`address_in_id`) REFERENCES `address` (`address_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `fk_travel_business_transport1` FOREIGN KEY (`agency_id`) REFERENCES `__business_transport` (`business_id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-06'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__uniform` +-- + +DROP TABLE IF EXISTS `__uniform`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__uniform` ( + `uniform_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) DEFAULT NULL, + `uniform_size_id` int(11) DEFAULT NULL, + `uniform_colour_id` int(11) DEFAULT NULL, + `uniform_season_id` int(11) DEFAULT NULL, + PRIMARY KEY (`uniform_id`), + UNIQUE KEY `uniforms_index02` (`name`), + KEY `uniforms_index01` (`uniform_size_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__uniform_colour` +-- + +DROP TABLE IF EXISTS `__uniform_colour`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__uniform_colour` ( + `uniform_colour_id` int(11) NOT NULL AUTO_INCREMENT, + `colour` varchar(30) DEFAULT NULL, + PRIMARY KEY (`uniform_colour_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__uniform_employee` +-- + +DROP TABLE IF EXISTS `__uniform_employee`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__uniform_employee` ( + `business_id` int(11) NOT NULL, + `uniform_id` int(11) NOT NULL, + PRIMARY KEY (`business_id`), + KEY `uniform_employee_index01` (`uniform_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__uniform_season` +-- + +DROP TABLE IF EXISTS `__uniform_season`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__uniform_season` ( + `uniform_season_id` int(11) NOT NULL AUTO_INCREMENT, + `season` varchar(100) NOT NULL, + PRIMARY KEY (`uniform_season_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__uniform_size` +-- + +DROP TABLE IF EXISTS `__uniform_size`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__uniform_size` ( + `uniform_size_id` int(11) NOT NULL AUTO_INCREMENT, + `size` varchar(30) NOT NULL, + PRIMARY KEY (`uniform_size_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__variety` +-- + +DROP TABLE IF EXISTS `__variety`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__variety` ( + `variety_id` int(11) NOT NULL AUTO_INCREMENT, + `intrastat_code_id` int(11) NOT NULL, + `color_id` int(11) NOT NULL, + `family_id` int(11) NOT NULL, + `name` varchar(40) NOT NULL, + `picture` varchar(20) DEFAULT NULL, + `botanic` varchar(35) DEFAULT NULL, + PRIMARY KEY (`variety_id`), + KEY `variety_color_id_idx` (`color_id`), + KEY `variety_family_id_idx` (`family_id`), + KEY `variety_intrastat_code_id_idx` (`intrastat_code_id`), + CONSTRAINT `__variety_ibfk_1` FOREIGN KEY (`family_id`) REFERENCES `__family` (`family_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `__variety_ibfk_2` FOREIGN KEY (`color_id`) REFERENCES `__color` (`color_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `__variety_ibfk_3` FOREIGN KEY (`intrastat_code_id`) REFERENCES `__intrastat_code` (`intrastat_code_id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__zone` +-- + +DROP TABLE IF EXISTS `__zone`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__zone` ( + `zone_id` int(11) NOT NULL AUTO_INCREMENT, + `province_id` int(11) NOT NULL, + `agency_id` int(11) NOT NULL, + `name` varchar(3) NOT NULL, + PRIMARY KEY (`zone_id`), + KEY `zone_agency_id_idx` (`agency_id`), + KEY `zone_province_id_idx` (`province_id`), + CONSTRAINT `__zone_ibfk_2` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `fk_zone_business_transport1` FOREIGN KEY (`agency_id`) REFERENCES `__business_transport` (`business_id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__zone_exception` +-- + +DROP TABLE IF EXISTS `__zone_exception`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__zone_exception` ( + `zone_exception_id` int(11) NOT NULL AUTO_INCREMENT, + `town_id` int(11) NOT NULL, + `daily` smallint(6) NOT NULL, + `tc` smallint(6) NOT NULL, + `zone_id` int(11) NOT NULL, + `priority` smallint(6) DEFAULT NULL, + PRIMARY KEY (`zone_exception_id`), + KEY `zone_exception_town_id_idx` (`town_id`), + KEY `zone_exception_zone_id_idx` (`zone_id`), + CONSTRAINT `__zone_exception_ibfk_4` FOREIGN KEY (`town_id`) REFERENCES `town` (`town_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `fk_zone_exception_zone1` FOREIGN KEY (`zone_id`) REFERENCES `__zone` (`zone_id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__zone_price` +-- + +DROP TABLE IF EXISTS `__zone_price`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__zone_price` ( + `zone_price_id` int(11) NOT NULL AUTO_INCREMENT, + `zone_id` int(11) NOT NULL, + `kg` int(11) NOT NULL DEFAULT '20', + `price` double NOT NULL, + PRIMARY KEY (`zone_price_id`), + KEY `zone_price_zone_id_idx` (`zone_id`), + CONSTRAINT `__zone_price_ibfk_1` FOREIGN KEY (`zone_id`) REFERENCES `__zone` (`zone_id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `__zone_province` +-- + +DROP TABLE IF EXISTS `__zone_province`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `__zone_province` ( + `zone_province_id` int(11) NOT NULL AUTO_INCREMENT, + `province_id` int(11) NOT NULL, + `zone_id` int(11) NOT NULL, + `daily` smallint(6) NOT NULL, + `tc` double DEFAULT NULL, + PRIMARY KEY (`zone_province_id`), + KEY `zone_province_province_id_idx` (`province_id`), + KEY `zone_province_zone_id_idx` (`zone_id`), + CONSTRAINT `__zone_province_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON DELETE NO ACTION ON UPDATE CASCADE, + CONSTRAINT `__zone_province_ibfk_2` FOREIGN KEY (`zone_id`) REFERENCES `__zone` (`zone_id`) ON DELETE NO ACTION ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='@deprecated: 2019-02-07'; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `address` -- @@ -77577,24 +80347,7 @@ CREATE TABLE `address` ( KEY `address_town_id_idx` (`town_id`), CONSTRAINT `address_ibfk_1` FOREIGN KEY (`address_type_id`) REFERENCES `address_type` (`address_type_id`) ON DELETE NO ACTION ON UPDATE CASCADE, CONSTRAINT `address_ibfk_2` FOREIGN KEY (`town_id`) REFERENCES `town` (`town_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=761 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `address_default` --- - -DROP TABLE IF EXISTS `address_default`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `address_default` ( - `address_default_id` int(11) NOT NULL AUTO_INCREMENT, - `profile_business_id` int(11) NOT NULL, - `address_id` int(11) NOT NULL, - PRIMARY KEY (`address_default_id`), - KEY `address_default_address_id_idx` (`address_id`), - CONSTRAINT `fk_media_default_copy1_address1` FOREIGN KEY (`address_id`) REFERENCES `address` (`address_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=768 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -77640,7 +80393,7 @@ CREATE TABLE `bank_account` ( CONSTRAINT `bank_account_bank_account_type_id_fkey` FOREIGN KEY (`bank_account_type_id`) REFERENCES `bank_account_type` (`bank_account_type_id`) ON UPDATE CASCADE, CONSTRAINT `bank_account_nation_id_fkey` FOREIGN KEY (`nation_id`) REFERENCES `nation` (`nation_id`) ON UPDATE CASCADE, CONSTRAINT `bank_profile` FOREIGN KEY (`client_id`) REFERENCES `profile` (`profile_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=748 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=758 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -77675,94 +80428,6 @@ CREATE TABLE `bank_bic` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `barcodeKk` --- - -DROP TABLE IF EXISTS `barcodeKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `barcodeKk` ( - `item_id` int(11) NOT NULL, - `barcode` varchar(50) DEFAULT NULL, - PRIMARY KEY (`item_id`), - KEY `barcode_item_id_idx` (`item_id`), - CONSTRAINT `fk_barcode_item1` FOREIGN KEY (`item_id`) REFERENCES `itemKk` (`item_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `bucketKk` --- - -DROP TABLE IF EXISTS `bucketKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `bucketKk` ( - `pack_type_id` int(11) NOT NULL, - `name` varchar(15) DEFAULT NULL, - `x` int(11) NOT NULL DEFAULT '1', - `y` int(11) NOT NULL DEFAULT '1', - `z` int(11) NOT NULL DEFAULT '1', - `returning` smallint(6) NOT NULL, - PRIMARY KEY (`pack_type_id`), - KEY `bucket_pack_type_id_idx` (`pack_type_id`), - CONSTRAINT `fk_bucket_pack_type1` FOREIGN KEY (`pack_type_id`) REFERENCES `pack_typeKk` (`pack_type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `bucket_returnKk` --- - -DROP TABLE IF EXISTS `bucket_returnKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `bucket_returnKk` ( - `pack_type_id` int(11) NOT NULL, - `empty` double NOT NULL, - `complete` double NOT NULL, - PRIMARY KEY (`pack_type_id`), - KEY `bucket_return_pack_type_id_idx` (`pack_type_id`), - CONSTRAINT `fk_bucket_return_bucket1` FOREIGN KEY (`pack_type_id`) REFERENCES `bucketKk` (`pack_type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `bundleKk` --- - -DROP TABLE IF EXISTS `bundleKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `bundleKk` ( - `bundle_id` int(11) NOT NULL AUTO_INCREMENT, - `delivery_id` int(11) NOT NULL, - `bundle_type_id` int(11) NOT NULL, - `amount` int(11) NOT NULL DEFAULT '1', - `value` double NOT NULL, - PRIMARY KEY (`bundle_id`,`delivery_id`), - KEY `bundle_bundle_type_id_idx` (`bundle_type_id`), - KEY `bundle_delivery_id_idx` (`delivery_id`), - CONSTRAINT `bundleKk_ibfk_1` FOREIGN KEY (`bundle_type_id`) REFERENCES `bundle_typeKk` (`bundle_type_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `bundleKk_ibfk_2` FOREIGN KEY (`delivery_id`) REFERENCES `delivery` (`delivery_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `bundle_typeKk` --- - -DROP TABLE IF EXISTS `bundle_typeKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `bundle_typeKk` ( - `bundle_type_id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(20) NOT NULL, - PRIMARY KEY (`bundle_type_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `business` -- @@ -77783,35 +80448,7 @@ CREATE TABLE `business` ( KEY `bussiness_provider` (`provider_id`), CONSTRAINT `business_client` FOREIGN KEY (`client_id`) REFERENCES `profile` (`profile_id`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `bussiness_provider` FOREIGN KEY (`provider_id`) REFERENCES `profile` (`profile_id`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=2295 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `business_agricultural` --- - -DROP TABLE IF EXISTS `business_agricultural`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `business_agricultural` ( - `business_id` int(11) NOT NULL, - PRIMARY KEY (`business_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `business_common` --- - -DROP TABLE IF EXISTS `business_common`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `business_common` ( - `business_id` int(11) NOT NULL, - `rate` int(11) DEFAULT NULL, - `credit` int(11) DEFAULT NULL, - PRIMARY KEY (`business_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=2311 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -77844,55 +80481,6 @@ CREATE TABLE `business_labour` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `business_labour_calendar_employee` --- - -DROP TABLE IF EXISTS `business_labour_calendar_employee`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `business_labour_calendar_employee` ( - `business_labour_calendar_employee_id` int(11) NOT NULL, - `business_id` int(11) NOT NULL, - `calendar_labour_type_id` int(11) NOT NULL, - `date_start` date NOT NULL, - PRIMARY KEY (`business_id`,`date_start`), - KEY `hour_labour_id` (`calendar_labour_type_id`), - CONSTRAINT `business_id` FOREIGN KEY (`business_id`) REFERENCES `business_labour` (`business_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `hour_labour_id` FOREIGN KEY (`calendar_labour_type_id`) REFERENCES `calendar_labour_type` (`calendar_labour_type_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `business_labour_ccc` --- - -DROP TABLE IF EXISTS `business_labour_ccc`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `business_labour_ccc` ( - `business_id` int(11) NOT NULL, - `ccc` varchar(30) NOT NULL, - `date_start` datetime DEFAULT NULL, - `date_end` datetime DEFAULT NULL, - PRIMARY KEY (`business_id`,`ccc`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `business_labour_payment` --- - -DROP TABLE IF EXISTS `business_labour_payment`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `business_labour_payment` ( - `business_id` int(11) DEFAULT NULL, - `amount` double DEFAULT NULL, - `date` date DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `business_labour_payroll` -- @@ -77911,61 +80499,6 @@ CREATE TABLE `business_labour_payroll` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `business_link` --- - -DROP TABLE IF EXISTS `business_link`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `business_link` ( - `business_id` int(11) NOT NULL, - `copy_business_id` int(11) NOT NULL, - PRIMARY KEY (`business_id`), - KEY `business_link_copy_business_id_idx` (`copy_business_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `business_professional` --- - -DROP TABLE IF EXISTS `business_professional`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `business_professional` ( - `business_id` int(11) NOT NULL, - PRIMARY KEY (`business_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `business_service` --- - -DROP TABLE IF EXISTS `business_service`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `business_service` ( - `business_id` int(11) NOT NULL, - PRIMARY KEY (`business_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `business_transport` --- - -DROP TABLE IF EXISTS `business_transport`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `business_transport` ( - `business_id` int(11) NOT NULL, - `m3` int(11) DEFAULT NULL, - PRIMARY KEY (`business_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `calendar_employee` -- @@ -78073,64 +80606,6 @@ CREATE TABLE `calendar_state` ( ) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `clado` --- - -DROP TABLE IF EXISTS `clado`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `clado` ( - `n` int(11) NOT NULL, - `col` int(11) DEFAULT NULL, - `fid` int(11) DEFAULT NULL, - `lin` int(11) DEFAULT NULL, - PRIMARY KEY (`n`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `class` --- - -DROP TABLE IF EXISTS `class`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `class` ( - `class_id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(10) DEFAULT NULL, - PRIMARY KEY (`class_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `colorKk` --- - -DROP TABLE IF EXISTS `colorKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `colorKk` ( - `color_id` int(11) NOT NULL AUTO_INCREMENT, - `image` longblob NOT NULL, - `sort` smallint(6) NOT NULL, - `name` char(3) DEFAULT NULL, - PRIMARY KEY (`color_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `convenio_time` --- - -DROP TABLE IF EXISTS `convenio_time`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `convenio_time` ( - `pausa_remunerada` time DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `currency` -- @@ -78145,198 +80620,6 @@ CREATE TABLE `currency` ( ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `dbljornada` --- - -DROP TABLE IF EXISTS `dbljornada`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `dbljornada` ( - `?column?` int(11) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `delivery` --- - -DROP TABLE IF EXISTS `delivery`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `delivery` ( - `delivery_id` int(11) NOT NULL AUTO_INCREMENT, - `state_id` int(11) NOT NULL DEFAULT '1', - `business_id` int(11) NOT NULL, - `travel_id` int(11) NOT NULL, - `ref` varchar(15) DEFAULT NULL, - `notes` varchar(50) DEFAULT NULL, - `tax` double DEFAULT NULL, - `invoice_id` int(11) DEFAULT NULL, - PRIMARY KEY (`delivery_id`), - KEY `delivery_invoice_id_idx` (`invoice_id`), - KEY `delivery_state_id_idx` (`state_id`), - KEY `delivery_travel_id_idx` (`travel_id`), - CONSTRAINT `delivery_ibfk_1` FOREIGN KEY (`travel_id`) REFERENCES `travel` (`travel_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `delivery_ibfk_2` FOREIGN KEY (`state_id`) REFERENCES `state_deliveryKk` (`state_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `fk_delivery_invoice1` FOREIGN KEY (`invoice_id`) REFERENCES `invoiceKk` (`invoice_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `delivery_expedition` --- - -DROP TABLE IF EXISTS `delivery_expedition`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `delivery_expedition` ( - `delivery_id` int(11) NOT NULL, - `expedition` int(11) DEFAULT NULL, - PRIMARY KEY (`delivery_id`), - CONSTRAINT `fk_delivery_expedition_delivery1` FOREIGN KEY (`delivery_id`) REFERENCES `delivery` (`delivery_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `discount_type` --- - -DROP TABLE IF EXISTS `discount_type`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `discount_type` ( - `discount_type_id` int(11) NOT NULL AUTO_INCREMENT, - `amount` double NOT NULL, - `description` varchar(1) NOT NULL, - `combine` smallint(6) DEFAULT NULL, - PRIMARY KEY (`discount_type_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `doc` --- - -DROP TABLE IF EXISTS `doc`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `doc` ( - `doc_id` int(11) NOT NULL AUTO_INCREMENT, - `worker_id` int(11) NOT NULL, - `person_id` int(11) NOT NULL, - `doc_type_id` int(11) NOT NULL, - `sref` varchar(15) NOT NULL, - `brief` varchar(200) DEFAULT NULL, - `sort` int(11) DEFAULT NULL, - `filename` varchar(30) NOT NULL, - `original` smallint(6) NOT NULL, - PRIMARY KEY (`doc_id`), - KEY `doc_doc_type_id_idx` (`doc_type_id`), - KEY `doc_person_id_idx` (`person_id`), - KEY `doc_worker_id_idx` (`worker_id`), - CONSTRAINT `doc_ibfk_1` FOREIGN KEY (`doc_type_id`) REFERENCES `doc_type` (`doc_type_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `doc_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `person` (`person_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `doc_ibfk_3` FOREIGN KEY (`worker_id`) REFERENCES `person` (`person_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `doc_type` --- - -DROP TABLE IF EXISTS `doc_type`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `doc_type` ( - `doc_type_id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(20) NOT NULL, - `path` varchar(30) NOT NULL, - PRIMARY KEY (`doc_type_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `familyKk` --- - -DROP TABLE IF EXISTS `familyKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `familyKk` ( - `family_id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(15) NOT NULL, - `sort` smallint(6) NOT NULL, - `father_id` int(11) DEFAULT NULL, - `temperature` longtext, - PRIMARY KEY (`family_id`), - KEY `family_father_id_idx` (`father_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `family_classKk` --- - -DROP TABLE IF EXISTS `family_classKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `family_classKk` ( - `family_id` int(11) NOT NULL, - `sort` smallint(6) NOT NULL, - `variety_id` int(11) NOT NULL, - PRIMARY KEY (`family_id`), - KEY `family_class_variety_id_idx` (`variety_id`), - CONSTRAINT `family_classKk_ibfk_1` FOREIGN KEY (`family_id`) REFERENCES `familyKk` (`family_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `fk_family_class_variety1` FOREIGN KEY (`variety_id`) REFERENCES `varietyKk` (`variety_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `goodbusiness_id` --- - -DROP TABLE IF EXISTS `goodbusiness_id`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `goodbusiness_id` ( - `business_id` int(11) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `holding` --- - -DROP TABLE IF EXISTS `holding`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `holding` ( - `holding_id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(20) DEFAULT NULL, - PRIMARY KEY (`holding_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `holding_person` --- - -DROP TABLE IF EXISTS `holding_person`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `holding_person` ( - `holding_person_id` int(11) NOT NULL AUTO_INCREMENT, - `person_id` int(11) NOT NULL, - `holding_id` int(11) NOT NULL, - PRIMARY KEY (`holding_person_id`), - KEY `holding_person_holding_id_idx` (`holding_id`), - KEY `holding_person_person_id_idx` (`person_id`), - CONSTRAINT `holding_person_ibfk_1` FOREIGN KEY (`holding_id`) REFERENCES `holding` (`holding_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `holding_person_ibfk_2` FOREIGN KEY (`person_id`) REFERENCES `person` (`person_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `income_employee` -- @@ -78357,7 +80640,7 @@ CREATE TABLE `income_employee` ( KEY `fperson_id` (`person_id`), CONSTRAINT `fincometype_id` FOREIGN KEY (`id_incomeType`) REFERENCES `incometype_employee` (`id_incometype`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fperson_id` FOREIGN KEY (`person_id`) REFERENCES `person` (`person_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=61237 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=61266 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -78375,224 +80658,6 @@ CREATE TABLE `incometype_employee` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `intbus_id` --- - -DROP TABLE IF EXISTS `intbus_id`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `intbus_id` ( - `business_id` int(11) DEFAULT NULL, - `person_id` int(11) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `intrastatKk` --- - -DROP TABLE IF EXISTS `intrastatKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `intrastatKk` ( - `intrastat_id` int(11) NOT NULL AUTO_INCREMENT, - `invoice_id` int(11) NOT NULL, - `intrastat_code_id` int(11) NOT NULL, - `amount` double DEFAULT NULL, - PRIMARY KEY (`intrastat_id`), - UNIQUE KEY `intrastat_invoice_id_key` (`invoice_id`,`intrastat_code_id`), - KEY `intrastat_intrastat_code_id_idx` (`intrastat_code_id`), - KEY `intrastat_invoice_id_idx` (`invoice_id`), - CONSTRAINT `intrastatKk_ibfk_1` FOREIGN KEY (`intrastat_code_id`) REFERENCES `intrastat_codeKk` (`intrastat_code_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `intrastatKk_ibfk_2` FOREIGN KEY (`invoice_id`) REFERENCES `invoiceKk` (`invoice_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `intrastat_codeKk` --- - -DROP TABLE IF EXISTS `intrastat_codeKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `intrastat_codeKk` ( - `intrastat_code_id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(50) NOT NULL, - `sort` smallint(6) NOT NULL, - PRIMARY KEY (`intrastat_code_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `invoiceKk` --- - -DROP TABLE IF EXISTS `invoiceKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `invoiceKk` ( - `invoice_id` int(11) NOT NULL AUTO_INCREMENT, - `currency_id` int(11) NOT NULL DEFAULT '1', - `business_id` int(11) NOT NULL, - `doc_id` int(11) DEFAULT NULL, - `date` date NOT NULL, - `serie` char(2) DEFAULT NULL, - `ref` bigint(20) NOT NULL, - `amount` double DEFAULT NULL, - PRIMARY KEY (`invoice_id`), - KEY `invoice_business_id_idx` (`business_id`), - KEY `invoice_currency_id_idx` (`currency_id`), - KEY `invoice_doc_id_idx` (`doc_id`), - CONSTRAINT `invoiceKk_ibfk_2` FOREIGN KEY (`doc_id`) REFERENCES `doc` (`doc_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `invoiceKk_ibfk_3` FOREIGN KEY (`currency_id`) REFERENCES `currency` (`currency_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `invoice_discountKk` --- - -DROP TABLE IF EXISTS `invoice_discountKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `invoice_discountKk` ( - `invoice_discount_id` int(11) NOT NULL AUTO_INCREMENT, - `discount_type_id` int(11) NOT NULL, - `invoice_id` int(11) NOT NULL, - `amount` double DEFAULT NULL, - PRIMARY KEY (`invoice_discount_id`), - KEY `invoice_discount_discount_type_id_idx` (`discount_type_id`), - KEY `invoice_discount_invoice_id_idx` (`invoice_id`), - CONSTRAINT `fk_invoice_discount_discount_type1` FOREIGN KEY (`discount_type_id`) REFERENCES `discount_type` (`discount_type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `fk_invoice_discount_invoice1` FOREIGN KEY (`invoice_id`) REFERENCES `invoiceKk` (`invoice_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `invoice_intrastatKk` --- - -DROP TABLE IF EXISTS `invoice_intrastatKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `invoice_intrastatKk` ( - `invoice_intrastat_id` int(11) NOT NULL AUTO_INCREMENT, - `invoice_id` int(11) NOT NULL, - `unit` int(11) NOT NULL DEFAULT '0', - `weight` int(11) DEFAULT NULL, - `price` double DEFAULT NULL, - `intrastat_id` int(11) NOT NULL, - PRIMARY KEY (`invoice_intrastat_id`), - KEY `invoice_intrastat_intrastat_id_idx` (`intrastat_id`), - KEY `invoice_intrastat_invoice_id_idx` (`invoice_id`), - CONSTRAINT `fk_invoice_intrastat_intrastat1` FOREIGN KEY (`intrastat_id`) REFERENCES `intrastatKk` (`intrastat_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `invoice_ret_ibfk_100` FOREIGN KEY (`invoice_id`) REFERENCES `invoiceKk` (`invoice_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `invoice_recKk` --- - -DROP TABLE IF EXISTS `invoice_recKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `invoice_recKk` ( - `invoice_rec_id` int(11) NOT NULL AUTO_INCREMENT, - `invoice_tax_id` int(11) NOT NULL, - `amount` double NOT NULL, - PRIMARY KEY (`invoice_rec_id`), - KEY `invoice_rec_invoice_tax_id_idx` (`invoice_tax_id`), - CONSTRAINT `invoice_recKk_ibfk_1` FOREIGN KEY (`invoice_tax_id`) REFERENCES `invoice_taxKk` (`invoice_tax_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `invoice_retKk` --- - -DROP TABLE IF EXISTS `invoice_retKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `invoice_retKk` ( - `invoice_ret_id` int(11) NOT NULL AUTO_INCREMENT, - `invoice_id` int(11) NOT NULL, - `amount` double NOT NULL, - PRIMARY KEY (`invoice_ret_id`), - KEY `invoice_ret_invoice_id_idx` (`invoice_id`), - CONSTRAINT `invoice_retKk_ibfk_1` FOREIGN KEY (`invoice_id`) REFERENCES `invoiceKk` (`invoice_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `invoice_supKk` --- - -DROP TABLE IF EXISTS `invoice_supKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `invoice_supKk` ( - `invoice_sup_id` int(11) NOT NULL AUTO_INCREMENT, - `invoice_id` int(11) NOT NULL, - `amount` double NOT NULL, - `description` varchar(45) DEFAULT NULL, - PRIMARY KEY (`invoice_sup_id`), - KEY `invoice_sup_invoice_id_idx` (`invoice_id`), - CONSTRAINT `invoice_ret_ibfk_10` FOREIGN KEY (`invoice_id`) REFERENCES `invoiceKk` (`invoice_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `invoice_taxKk` --- - -DROP TABLE IF EXISTS `invoice_taxKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `invoice_taxKk` ( - `invoice_tax_id` int(11) NOT NULL AUTO_INCREMENT, - `tax_id` int(11) NOT NULL, - `invoice_id` int(11) NOT NULL, - `base` double NOT NULL, - `quota` double DEFAULT NULL, - PRIMARY KEY (`invoice_tax_id`), - UNIQUE KEY `invoice_tax_invoice_id_key` (`tax_id`,`invoice_id`), - KEY `invoice_tax_invoice_id_idx` (`invoice_id`), - KEY `invoice_tax_tax_id_idx` (`tax_id`), - CONSTRAINT `invoice_taxKk_ibfk_1` FOREIGN KEY (`invoice_id`) REFERENCES `invoiceKk` (`invoice_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `invoice_taxKk_ibfk_2` FOREIGN KEY (`tax_id`) REFERENCES `taxKk` (`tax_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `itemKk` --- - -DROP TABLE IF EXISTS `itemKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `itemKk` ( - `item_id` int(11) NOT NULL AUTO_INCREMENT, - `variety_id` int(11) NOT NULL, - PRIMARY KEY (`item_id`), - KEY `item_variety_id_idx` (`variety_id`), - CONSTRAINT `fk_item_variety1` FOREIGN KEY (`variety_id`) REFERENCES `varietyKk` (`variety_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `jornadaKk` --- - -DROP TABLE IF EXISTS `jornadaKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `jornadaKk` ( - `?column?` time DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `journey` -- @@ -78630,144 +80695,6 @@ CREATE TABLE `labour_agreement` ( ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `license` --- - -DROP TABLE IF EXISTS `license`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `license` ( - `profile_id` int(11) DEFAULT NULL, - `license_group_id` int(11) DEFAULT NULL, - UNIQUE KEY `license_profile_id_key` (`profile_id`,`license_group_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `license_group` --- - -DROP TABLE IF EXISTS `license_group`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `license_group` ( - `license_group_id` int(11) NOT NULL AUTO_INCREMENT, - `tipopermiso` char(1) DEFAULT NULL, - `menu_id` int(11) DEFAULT NULL, - PRIMARY KEY (`license_group_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `license_menu` --- - -DROP TABLE IF EXISTS `license_menu`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `license_menu` ( - `menu_id` int(11) DEFAULT NULL, - `nommenu` longtext -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `lot` --- - -DROP TABLE IF EXISTS `lot`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `lot` ( - `lot_id` int(11) NOT NULL, - `opinion_id` int(11) DEFAULT NULL, - `quality_id` int(11) DEFAULT NULL, - `amount` smallint(6) NOT NULL, - `expire` smallint(6) NOT NULL, - `address_id` int(11) NOT NULL, - `item_id` int(11) NOT NULL, - `labour_profile_id` int(11) NOT NULL, - `price_unit_id` int(11) NOT NULL, - `sales_unit_id` int(11) NOT NULL, - PRIMARY KEY (`lot_id`), - KEY `lot_address_id_idx` (`address_id`), - KEY `lot_item_id_idx` (`item_id`), - KEY `lot_opinion_id_idx` (`opinion_id`), - KEY `lot_price_unit_id_idx` (`price_unit_id`), - KEY `lot_quality_id_idx` (`quality_id`), - KEY `lot_sales_unit_id_idx` (`sales_unit_id`), - CONSTRAINT `fk_lot_item1` FOREIGN KEY (`item_id`) REFERENCES `itemKk` (`item_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `fk_lot_pack_type1` FOREIGN KEY (`sales_unit_id`) REFERENCES `pack_typeKk` (`pack_type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `fk_lot_pack_type2` FOREIGN KEY (`price_unit_id`) REFERENCES `pack_typeKk` (`pack_type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `lot_ibfk_12` FOREIGN KEY (`address_id`) REFERENCES `originKk` (`address_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `lot_ibfk_3` FOREIGN KEY (`quality_id`) REFERENCES `qualityKk` (`quality_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `lot_ibfk_8` FOREIGN KEY (`opinion_id`) REFERENCES `opinionKk` (`opinion_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `lot_packing` --- - -DROP TABLE IF EXISTS `lot_packing`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `lot_packing` ( - `lot_packing_id` int(11) NOT NULL AUTO_INCREMENT, - `packing_id` int(11) NOT NULL, - `lot_id` int(11) NOT NULL, - PRIMARY KEY (`lot_packing_id`), - KEY `lot_packing_lot_id_idx` (`lot_id`), - KEY `lot_packing_packing_id_idx` (`packing_id`), - CONSTRAINT `fk_lot_packing_lot1` FOREIGN KEY (`lot_id`) REFERENCES `lot` (`lot_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `fk_lot_packing_packing1` FOREIGN KEY (`packing_id`) REFERENCES `packingKk` (`packing_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `lot_property` --- - -DROP TABLE IF EXISTS `lot_property`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `lot_property` ( - `lot_property_id` int(11) NOT NULL AUTO_INCREMENT, - `property_id` int(11) NOT NULL, - `lot_id` int(11) NOT NULL, - PRIMARY KEY (`lot_property_id`), - KEY `lot_property_lot_id_idx` (`lot_id`), - KEY `lot_property_property_id_idx` (`property_id`), - CONSTRAINT `fk_lot_property_lot1` FOREIGN KEY (`lot_id`) REFERENCES `lot` (`lot_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `fk_lot_property_property1` FOREIGN KEY (`property_id`) REFERENCES `propertyKk` (`property_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `maintenance_pcs` --- - -DROP TABLE IF EXISTS `maintenance_pcs`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `maintenance_pcs` ( - `pc_nombre` char(6) NOT NULL, - `os` varchar(20) DEFAULT NULL, - `servicepack` varchar(20) DEFAULT NULL, - `nmonitores` int(11) DEFAULT NULL, - `micro` varchar(20) DEFAULT NULL, - `antivirus` varchar(20) DEFAULT NULL, - `ram` varchar(20) DEFAULT NULL, - `user_name` varchar(40) DEFAULT NULL, - `business_id` int(11) DEFAULT NULL, - `ip` varchar(15) DEFAULT NULL, - `auric` varchar(20) DEFAULT NULL, - `pgsql` char(2) DEFAULT NULL, - PRIMARY KEY (`pc_nombre`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `media` -- @@ -78783,24 +80710,7 @@ CREATE TABLE `media` ( PRIMARY KEY (`media_id`), KEY `media_media_type_id_idx` (`media_type_id`), CONSTRAINT `media_ibfk_1` FOREIGN KEY (`media_type_id`) REFERENCES `media_type` (`media_type_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=935 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `media_default` --- - -DROP TABLE IF EXISTS `media_default`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `media_default` ( - `media_default_id` int(11) NOT NULL AUTO_INCREMENT, - `media_media_id` int(11) NOT NULL, - `business_profile_business_id` int(11) NOT NULL, - PRIMARY KEY (`media_default_id`), - KEY `media_default_media_media_id_idx` (`media_media_id`), - CONSTRAINT `fk_media_default_media1` FOREIGN KEY (`media_media_id`) REFERENCES `media` (`media_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=945 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -78818,93 +80728,6 @@ CREATE TABLE `media_type` ( ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `menus_perm` --- - -DROP TABLE IF EXISTS `menus_perm`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `menus_perm` ( - `idmenus_perm` int(11) NOT NULL AUTO_INCREMENT, - `menu` varchar(45) DEFAULT NULL, - `father_id` int(11) DEFAULT NULL, - `icono` longblob, - `idorden` smallint(6) DEFAULT NULL, - PRIMARY KEY (`idmenus_perm`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `moveKk` --- - -DROP TABLE IF EXISTS `moveKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `moveKk` ( - `move_id` int(11) NOT NULL AUTO_INCREMENT, - `lot_id` int(11) NOT NULL, - `cprice` double NOT NULL, - `cport` double NOT NULL, - `cpack` double NOT NULL, - `ctax` double NOT NULL, - `amount` int(11) NOT NULL DEFAULT '0', - `ok` smallint(6) NOT NULL, - `order_id` int(11) NOT NULL, - PRIMARY KEY (`move_id`), - KEY `move_lot_id_idx` (`lot_id`), - KEY `move_order_id_idx` (`order_id`), - CONSTRAINT `fk_move_order1` FOREIGN KEY (`order_id`) REFERENCES `orderKk` (`order_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `moveKk_ibfk_1` FOREIGN KEY (`lot_id`) REFERENCES `lot` (`lot_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `mutua` --- - -DROP TABLE IF EXISTS `mutua`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `mutua` ( - `mutua_id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(100) DEFAULT NULL, - PRIMARY KEY (`mutua_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `mutua_employee` --- - -DROP TABLE IF EXISTS `mutua_employee`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `mutua_employee` ( - `business_id` int(11) DEFAULT NULL, - `capable` tinyint(4) DEFAULT NULL, - `notes` longtext, - `mutura_revisiones_id` int(11) NOT NULL, - PRIMARY KEY (`mutura_revisiones_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `mutua_revisiones` --- - -DROP TABLE IF EXISTS `mutua_revisiones`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `mutua_revisiones` ( - `mutua_id` int(11) NOT NULL, - `date` datetime DEFAULT NULL, - `mutua_revisiones_id` int(11) NOT NULL, - PRIMARY KEY (`mutua_revisiones_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `nation` -- @@ -78925,178 +80748,6 @@ CREATE TABLE `nation` ( ) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `nicheKk` --- - -DROP TABLE IF EXISTS `nicheKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `nicheKk` ( - `niche_id` int(11) NOT NULL AUTO_INCREMENT, - `address_id` int(11) NOT NULL, - `lot_id` int(11) NOT NULL, - `name` char(5) NOT NULL, - PRIMARY KEY (`niche_id`), - KEY `niche_address_id_idx` (`address_id`), - KEY `niche_lot_id_idx` (`lot_id`), - CONSTRAINT `nicheKk_ibfk_1` FOREIGN KEY (`lot_id`) REFERENCES `lot` (`lot_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `nicheKk_ibfk_2` FOREIGN KEY (`address_id`) REFERENCES `address` (`address_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `nominas_gestoria` --- - -DROP TABLE IF EXISTS `nominas_gestoria`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `nominas_gestoria` ( - `numgestoria` int(11) NOT NULL, - `empresa_id` int(11) NOT NULL, - `person_id` int(11) DEFAULT NULL, - `numcontaplus` int(11) DEFAULT NULL, - PRIMARY KEY (`numgestoria`,`empresa_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `numdaysKk` --- - -DROP TABLE IF EXISTS `numdaysKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `numdaysKk` ( - `coalesce` decimal(10,0) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `opinionKk` --- - -DROP TABLE IF EXISTS `opinionKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `opinionKk` ( - `opinion_id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(15) DEFAULT NULL, - PRIMARY KEY (`opinion_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `orderKk` --- - -DROP TABLE IF EXISTS `orderKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `orderKk` ( - `order_id` int(11) NOT NULL AUTO_INCREMENT, - `delivery_id` int(11) NOT NULL, - `description` varchar(45) DEFAULT NULL, - `amount` int(11) NOT NULL, - `price` double DEFAULT NULL, - `discount` int(11) DEFAULT NULL, - `all_equal` smallint(6) DEFAULT NULL, - PRIMARY KEY (`order_id`), - KEY `order_delivery_id_idx` (`delivery_id`), - CONSTRAINT `fk_order_delivery1` FOREIGN KEY (`delivery_id`) REFERENCES `delivery` (`delivery_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `originKk` --- - -DROP TABLE IF EXISTS `originKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `originKk` ( - `nick` char(3) NOT NULL, - `name` varchar(15) NOT NULL, - `flag` longblob, - `address_id` int(11) NOT NULL, - `font` smallint(6) DEFAULT NULL, - PRIMARY KEY (`address_id`), - CONSTRAINT `origin_adress_id` FOREIGN KEY (`address_id`) REFERENCES `address` (`address_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `pack_typeKk` --- - -DROP TABLE IF EXISTS `pack_typeKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `pack_typeKk` ( - `pack_type_id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(15) DEFAULT 'A1', - `brief` varchar(3) DEFAULT NULL, - PRIMARY KEY (`pack_type_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `packingKk` --- - -DROP TABLE IF EXISTS `packingKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `packingKk` ( - `packing_id` int(11) NOT NULL AUTO_INCREMENT, - `amount` int(11) DEFAULT NULL, - `pack_type_id` int(11) NOT NULL, - PRIMARY KEY (`packing_id`), - KEY `packing_pack_type_id_idx` (`pack_type_id`), - CONSTRAINT `fk_packing_pack_type1` FOREIGN KEY (`pack_type_id`) REFERENCES `pack_typeKk` (`pack_type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `pagosemanal` --- - -DROP TABLE IF EXISTS `pagosemanal`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `pagosemanal` ( - `periodo` int(11) NOT NULL, - `business_id` int(11) NOT NULL, - `id_trabajador` int(11) DEFAULT NULL, - `importe` double DEFAULT NULL, - `horasemanales` time DEFAULT NULL, - `contrato` time DEFAULT NULL, - `impar` tinyint(4) DEFAULT '0', - PRIMARY KEY (`periodo`,`business_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `pagosemanal_new` --- - -DROP TABLE IF EXISTS `pagosemanal_new`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `pagosemanal_new` ( - `periodo` int(11) NOT NULL, - `business_id` int(11) NOT NULL, - `id_trabajador` int(11) DEFAULT NULL, - `importe` double DEFAULT NULL, - `horasemanales` time DEFAULT NULL, - `contrato` time DEFAULT NULL, - `impar` tinyint(4) DEFAULT '0', - `person_id` int(11) DEFAULT NULL, - PRIMARY KEY (`periodo`,`business_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `periodos` -- @@ -79138,7 +80789,7 @@ CREATE TABLE `person` ( UNIQUE KEY `person_nif_key` (`nif`), KEY `index1` (`person_id`,`name`,`nickname`,`firstname`), KEY `person_worker` (`id_trabajador`) -) ENGINE=InnoDB AUTO_INCREMENT=990 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=996 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -79189,7 +80840,7 @@ CREATE TABLE `profile` ( KEY `profile_person_id_idx` (`person_id`), KEY `profile_profile_type_id_idx` (`profile_type_id`), CONSTRAINT `person_fk` FOREIGN KEY (`person_id`) REFERENCES `person` (`person_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=868 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=874 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -79206,7 +80857,7 @@ CREATE TABLE `profile_address` ( PRIMARY KEY (`profile_address_id`), KEY `profile_address_address_id_idx` (`address_id`), KEY `profile_address_profile_id_idx` (`profile_id`) -) ENGINE=InnoDB AUTO_INCREMENT=98 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=105 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -79225,7 +80876,7 @@ CREATE TABLE `profile_media` ( KEY `profile_media_profile_id_idx` (`profile_id`), CONSTRAINT `fk_profile_media_media1` FOREIGN KEY (`media_id`) REFERENCES `media` (`media_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `media_ibfk_20` FOREIGN KEY (`profile_id`) REFERENCES `profile` (`profile_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1083 DEFAULT CHARSET=utf8; +) ENGINE=InnoDB AUTO_INCREMENT=1093 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -79242,23 +80893,6 @@ CREATE TABLE `profile_type` ( ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `propertyKk` --- - -DROP TABLE IF EXISTS `propertyKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `propertyKk` ( - `property_id` int(11) NOT NULL AUTO_INCREMENT, - `value` smallint(6) NOT NULL, - `class_id` int(11) NOT NULL, - PRIMARY KEY (`property_id`), - KEY `property_class_id_idx` (`class_id`), - CONSTRAINT `fk_property_class1` FOREIGN KEY (`class_id`) REFERENCES `class` (`class_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `province` -- @@ -79277,143 +80911,6 @@ CREATE TABLE `province` ( ) ENGINE=InnoDB AUTO_INCREMENT=162 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `pruebaimagenKk` --- - -DROP TABLE IF EXISTS `pruebaimagenKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `pruebaimagenKk` ( - `p2` varchar(255) DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `qualityKk` --- - -DROP TABLE IF EXISTS `qualityKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `qualityKk` ( - `quality_id` int(11) NOT NULL AUTO_INCREMENT, - `name` char(3) DEFAULT 'A1', - PRIMARY KEY (`quality_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `stateKk` --- - -DROP TABLE IF EXISTS `stateKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `stateKk` ( - `state_id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(15) DEFAULT NULL, - PRIMARY KEY (`state_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `state_deliveryKk` --- - -DROP TABLE IF EXISTS `state_deliveryKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `state_deliveryKk` ( - `state_id` int(11) NOT NULL, - `sort` int(11) NOT NULL, - PRIMARY KEY (`state_id`), - UNIQUE KEY `state_delivery_sort_key` (`sort`), - KEY `state_delivery_state_id_idx` (`state_id`), - CONSTRAINT `state_ordre_ibfk_1` FOREIGN KEY (`state_id`) REFERENCES `stateKk` (`state_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `state_travelKk` --- - -DROP TABLE IF EXISTS `state_travelKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `state_travelKk` ( - `state_id` int(11) NOT NULL, - `sort` int(11) DEFAULT NULL, - PRIMARY KEY (`state_id`), - UNIQUE KEY `state_travel_sort_key` (`sort`), - KEY `state_travel_state_id_idx` (`state_id`), - CONSTRAINT `state_travelKk_ibfk_1` FOREIGN KEY (`state_id`) REFERENCES `stateKk` (`state_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `taxKk` --- - -DROP TABLE IF EXISTS `taxKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `taxKk` ( - `tax_id` int(11) NOT NULL AUTO_INCREMENT, - `nation_id` int(11) NOT NULL, - `tax_type_id` int(11) NOT NULL, - `value` double NOT NULL, - `rec` double NOT NULL, - `date` date NOT NULL, - PRIMARY KEY (`tax_id`), - KEY `tax_nation_id_idx` (`nation_id`), - KEY `tax_tax_type_id_idx` (`tax_type_id`), - CONSTRAINT `fk_tax_nation1` FOREIGN KEY (`nation_id`) REFERENCES `nation` (`nation_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `taxKk_ibfk_1` FOREIGN KEY (`tax_type_id`) REFERENCES `tax_typeKk` (`tax_type_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `tax_typeKk` --- - -DROP TABLE IF EXISTS `tax_typeKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `tax_typeKk` ( - `tax_type_id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(15) NOT NULL, - `brief` varchar(1) NOT NULL, - PRIMARY KEY (`tax_type_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `tipo_perm` --- - -DROP TABLE IF EXISTS `tipo_perm`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `tipo_perm` ( - `idtipo_perm` int(11) NOT NULL AUTO_INCREMENT, - `tipopermiso` varchar(45) DEFAULT NULL, - PRIMARY KEY (`idtipo_perm`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `totalms` --- - -DROP TABLE IF EXISTS `totalms`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `totalms` ( - `date_part` double DEFAULT NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `town` -- @@ -79432,255 +80929,6 @@ CREATE TABLE `town` ( ) ENGINE=InnoDB AUTO_INCREMENT=3673 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `transfer_reader_horasfichajes` --- - -DROP TABLE IF EXISTS `transfer_reader_horasfichajes`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `transfer_reader_horasfichajes` ( - `transfer_reader_horasfichajes_id` int(11) NOT NULL AUTO_INCREMENT, - `hora` time DEFAULT NULL, - PRIMARY KEY (`transfer_reader_horasfichajes_id`), - UNIQUE KEY `punique_trhf` (`hora`) -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `transfer_reader_incidencias` --- - -DROP TABLE IF EXISTS `transfer_reader_incidencias`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `transfer_reader_incidencias` ( - `transfer_reader_id` int(11) NOT NULL, - `transfer_reader_incidencias_type_id` int(11) NOT NULL, - PRIMARY KEY (`transfer_reader_id`), - KEY `fki_fkey` (`transfer_reader_id`), - KEY `fki_fkey1` (`transfer_reader_id`), - KEY `fki_fkey2` (`transfer_reader_incidencias_type_id`), - CONSTRAINT `fkey` FOREIGN KEY (`transfer_reader_id`) REFERENCES `transfer_reader_kk` (`transfer_reader_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `fkey2` FOREIGN KEY (`transfer_reader_incidencias_type_id`) REFERENCES `transfer_reader_incidencias_type` (`transfer_reader_incidencias_type_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `transfer_reader_incidencias_type` --- - -DROP TABLE IF EXISTS `transfer_reader_incidencias_type`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `transfer_reader_incidencias_type` ( - `transfer_reader_incidencias_type_id` int(11) NOT NULL AUTO_INCREMENT, - `descripcion` longtext NOT NULL, - PRIMARY KEY (`transfer_reader_incidencias_type_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `transfer_reader_kk` --- - -DROP TABLE IF EXISTS `transfer_reader_kk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `transfer_reader_kk` ( - `transfer_reader_id` int(11) NOT NULL AUTO_INCREMENT, - `business_id` int(11) DEFAULT NULL, - `idorden` int(11) DEFAULT NULL, - `date` datetime DEFAULT NULL, - `manual` tinyint(4) DEFAULT '0', - `person_id` int(11) DEFAULT NULL, - `workcenter_id` int(11) DEFAULT NULL, - PRIMARY KEY (`transfer_reader_id`), - UNIQUE KEY `wc_date_person_UNIQUE` (`workcenter_id`,`date`,`person_id`), - KEY `fki_person_transfer` (`person_id`), - KEY `fk_id` (`business_id`), - CONSTRAINT `fk_id` FOREIGN KEY (`business_id`) REFERENCES `business_labour` (`business_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `person_transfer` FOREIGN KEY (`person_id`) REFERENCES `person` (`person_id`) ON UPDATE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=1090649 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `transfer_reader_relationship` --- - -DROP TABLE IF EXISTS `transfer_reader_relationship`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `transfer_reader_relationship` ( - `id` int(11) NOT NULL, - `nis` bigint(20) NOT NULL, - `id_trabajador` int(11) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `fichador` (`nis`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `transfer_reader_relationship_nuevolector` --- - -DROP TABLE IF EXISTS `transfer_reader_relationship_nuevolector`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `transfer_reader_relationship_nuevolector` ( - `nis` bigint(20) DEFAULT NULL, - `id_trabajador` int(11) DEFAULT NULL, - `id` int(11) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `pkeyniss` (`nis`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `transfer_reader_tmp` --- - -DROP TABLE IF EXISTS `transfer_reader_tmp`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `transfer_reader_tmp` ( - `nis` int(11) NOT NULL, - `date` datetime NOT NULL, - `transfer_reader_id` int(11) NOT NULL, - `warehouseFk` smallint(6) unsigned DEFAULT NULL, - PRIMARY KEY (`nis`,`date`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `travel` --- - -DROP TABLE IF EXISTS `travel`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `travel` ( - `travel_id` int(11) NOT NULL AUTO_INCREMENT, - `state_id` int(11) NOT NULL DEFAULT '1', - `shipment` date NOT NULL, - `landing` date NOT NULL, - `name` varchar(15) DEFAULT NULL, - `address_out_id` int(11) NOT NULL, - `address_in_id` int(11) NOT NULL, - `agency_id` int(11) NOT NULL, - PRIMARY KEY (`travel_id`), - KEY `travel_address_in_id_idx` (`address_in_id`), - KEY `travel_address_out_id_idx` (`address_out_id`), - KEY `travel_agency_id_idx` (`agency_id`), - KEY `travel_state_id_idx` (`state_id`), - CONSTRAINT `fk_travel_address1` FOREIGN KEY (`address_out_id`) REFERENCES `address` (`address_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `fk_travel_address2` FOREIGN KEY (`address_in_id`) REFERENCES `address` (`address_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `fk_travel_business_transport1` FOREIGN KEY (`agency_id`) REFERENCES `business_transport` (`business_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `travel_ibfk_4` FOREIGN KEY (`state_id`) REFERENCES `state_travelKk` (`state_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `uniform` --- - -DROP TABLE IF EXISTS `uniform`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `uniform` ( - `uniform_id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(255) DEFAULT NULL, - `uniform_size_id` int(11) DEFAULT NULL, - `uniform_colour_id` int(11) DEFAULT NULL, - `uniform_season_id` int(11) DEFAULT NULL, - PRIMARY KEY (`uniform_id`), - UNIQUE KEY `uniforms_index02` (`name`), - KEY `uniforms_index01` (`uniform_size_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `uniform_colour` --- - -DROP TABLE IF EXISTS `uniform_colour`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `uniform_colour` ( - `uniform_colour_id` int(11) NOT NULL AUTO_INCREMENT, - `colour` varchar(30) DEFAULT NULL, - PRIMARY KEY (`uniform_colour_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `uniform_employee` --- - -DROP TABLE IF EXISTS `uniform_employee`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `uniform_employee` ( - `business_id` int(11) NOT NULL, - `uniform_id` int(11) NOT NULL, - PRIMARY KEY (`business_id`), - KEY `uniform_employee_index01` (`uniform_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `uniform_season` --- - -DROP TABLE IF EXISTS `uniform_season`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `uniform_season` ( - `uniform_season_id` int(11) NOT NULL AUTO_INCREMENT, - `season` varchar(100) NOT NULL, - PRIMARY KEY (`uniform_season_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `uniform_size` --- - -DROP TABLE IF EXISTS `uniform_size`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `uniform_size` ( - `uniform_size_id` int(11) NOT NULL AUTO_INCREMENT, - `size` varchar(30) NOT NULL, - PRIMARY KEY (`uniform_size_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `varietyKk` --- - -DROP TABLE IF EXISTS `varietyKk`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `varietyKk` ( - `variety_id` int(11) NOT NULL AUTO_INCREMENT, - `intrastat_code_id` int(11) NOT NULL, - `color_id` int(11) NOT NULL, - `family_id` int(11) NOT NULL, - `name` varchar(40) NOT NULL, - `picture` varchar(20) DEFAULT NULL, - `botanic` varchar(35) DEFAULT NULL, - PRIMARY KEY (`variety_id`), - KEY `variety_color_id_idx` (`color_id`), - KEY `variety_family_id_idx` (`family_id`), - KEY `variety_intrastat_code_id_idx` (`intrastat_code_id`), - CONSTRAINT `varietyKk_ibfk_1` FOREIGN KEY (`family_id`) REFERENCES `familyKk` (`family_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `varietyKk_ibfk_2` FOREIGN KEY (`color_id`) REFERENCES `colorKk` (`color_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `varietyKk_ibfk_3` FOREIGN KEY (`intrastat_code_id`) REFERENCES `intrastat_codeKk` (`intrastat_code_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Table structure for table `workcenter` -- @@ -79714,87 +80962,6 @@ CREATE TABLE `workerTimeControlConfig` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; --- --- Table structure for table `zone` --- - -DROP TABLE IF EXISTS `zone`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `zone` ( - `zone_id` int(11) NOT NULL AUTO_INCREMENT, - `province_id` int(11) NOT NULL, - `agency_id` int(11) NOT NULL, - `name` varchar(3) NOT NULL, - PRIMARY KEY (`zone_id`), - KEY `zone_agency_id_idx` (`agency_id`), - KEY `zone_province_id_idx` (`province_id`), - CONSTRAINT `fk_zone_business_transport1` FOREIGN KEY (`agency_id`) REFERENCES `business_transport` (`business_id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `zone_ibfk_2` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `zone_exception` --- - -DROP TABLE IF EXISTS `zone_exception`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `zone_exception` ( - `zone_exception_id` int(11) NOT NULL AUTO_INCREMENT, - `town_id` int(11) NOT NULL, - `daily` smallint(6) NOT NULL, - `tc` smallint(6) NOT NULL, - `zone_id` int(11) NOT NULL, - `priority` smallint(6) DEFAULT NULL, - PRIMARY KEY (`zone_exception_id`), - KEY `zone_exception_town_id_idx` (`town_id`), - KEY `zone_exception_zone_id_idx` (`zone_id`), - CONSTRAINT `fk_zone_exception_zone1` FOREIGN KEY (`zone_id`) REFERENCES `zone` (`zone_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `zone_exception_ibfk_4` FOREIGN KEY (`town_id`) REFERENCES `town` (`town_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `zone_price` --- - -DROP TABLE IF EXISTS `zone_price`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `zone_price` ( - `zone_price_id` int(11) NOT NULL AUTO_INCREMENT, - `zone_id` int(11) NOT NULL, - `kg` int(11) NOT NULL DEFAULT '20', - `price` double NOT NULL, - PRIMARY KEY (`zone_price_id`), - KEY `zone_price_zone_id_idx` (`zone_id`), - CONSTRAINT `zone_price_ibfk_1` FOREIGN KEY (`zone_id`) REFERENCES `zone` (`zone_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `zone_province` --- - -DROP TABLE IF EXISTS `zone_province`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `zone_province` ( - `zone_province_id` int(11) NOT NULL AUTO_INCREMENT, - `province_id` int(11) NOT NULL, - `zone_id` int(11) NOT NULL, - `daily` smallint(6) NOT NULL, - `tc` double DEFAULT NULL, - PRIMARY KEY (`zone_province_id`), - KEY `zone_province_province_id_idx` (`province_id`), - KEY `zone_province_zone_id_idx` (`zone_id`), - CONSTRAINT `zone_province_ibfk_1` FOREIGN KEY (`province_id`) REFERENCES `province` (`province_id`) ON DELETE NO ACTION ON UPDATE CASCADE, - CONSTRAINT `zone_province_ibfk_2` FOREIGN KEY (`zone_id`) REFERENCES `zone` (`zone_id`) ON DELETE NO ACTION ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - -- -- Dumping events for database 'postgresql' -- @@ -80200,24 +81367,6 @@ USE `vn2008`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; --- --- Final view structure for view `itemTagArranged` --- - -/*!50001 DROP VIEW IF EXISTS `itemTagArranged`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 SET character_set_results = utf8 */; -/*!50001 SET collation_connection = utf8_general_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemTagArranged` AS select `i`.`itemFk` AS `itemFk`,`i`.`tag1` AS `tag1`,`i`.`val1` AS `val1`,`i`.`tag2` AS `tag2`,`i`.`val2` AS `val2`,`i`.`tag3` AS `tag3`,`i`.`val3` AS `val3`,`i`.`tag4` AS `tag4`,`i`.`val4` AS `val4`,`i`.`tag5` AS `tag5`,`i`.`val5` AS `val5`,`i`.`tag6` AS `tag6`,`i`.`val6` AS `val6`,`i`.`description` AS `description` from `vn`.`itemTagArranged` `i` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - -- -- Final view structure for view `item_entry_in` -- @@ -80555,7 +81704,7 @@ USE `vn2008`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `v_Movimientos_Volumen_shipping_charge` AS select `M`.`Id_Ticket` AS `Id_Ticket`,`M`.`Id_Movimiento` AS `Id_Movimiento`,`t`.`Fecha` AS `Fecha`,`az`.`price` AS `price`,(((`M`.`Cantidad` * `r`.`cm3`) / `cb`.`Volumen`) * `az`.`price`) AS `freight` from (((((((`vn2008`.`Movimientos` `M` join `vn2008`.`Tickets` `t` on((`t`.`Id_Ticket` = `M`.`Id_Ticket`))) join `vn2008`.`Consignatarios` `c` on((`c`.`id_consigna` = `t`.`Id_Consigna`))) join `bi`.`rotacion` `r` on(((`r`.`Id_Article` = `M`.`Id_Article`) and (`r`.`warehouse_id` = `t`.`warehouse_id`)))) join `vn2008`.`Cubos` `cb` on((`cb`.`Id_Cubo` = 94))) join `vn2008`.`Agencias` `a` on((`a`.`Id_Agencia` = `t`.`Id_Agencia`))) join `vn2008`.`Agencias_province` `ap` on(((`t`.`warehouse_id` = `ap`.`warehouse_id`) and (`ap`.`province_id` = `c`.`province_id`) and (`ap`.`agency_id` = `a`.`agency_id`)))) join `vn2008`.`Agencias_zonas` `az` on(((`az`.`Id_Agencia` = `t`.`Id_Agencia`) and (`az`.`zona` = `ap`.`zona`) and (`t`.`warehouse_id` = `az`.`warehouse_id`) and (`az`.`Id_Article` = 71)))) */; +/*!50001 VIEW `v_Movimientos_Volumen_shipping_charge` AS select `M`.`Id_Ticket` AS `Id_Ticket`,`M`.`Id_Movimiento` AS `Id_Movimiento`,`t`.`Fecha` AS `Fecha`,`az`.`price` AS `price`,(((((`M`.`Cantidad` * `r`.`cm3`) * `az`.`price`) * `az`.`inflacion`) * `i`.`compression`) / `cb`.`Volumen`) AS `freight` from ((((((((`vn2008`.`Movimientos` `M` join `vn2008`.`Articles` `i` on((`i`.`Id_Article` = `M`.`Id_Article`))) join `vn2008`.`Tickets` `t` on((`t`.`Id_Ticket` = `M`.`Id_Ticket`))) join `vn2008`.`Consignatarios` `c` on((`c`.`id_consigna` = `t`.`Id_Consigna`))) join `bi`.`rotacion` `r` on(((`r`.`Id_Article` = `M`.`Id_Article`) and (`r`.`warehouse_id` = `t`.`warehouse_id`)))) join `vn2008`.`Cubos` `cb` on((`cb`.`Id_Cubo` = '94'))) join `vn2008`.`Agencias` `a` on((`a`.`Id_Agencia` = `t`.`Id_Agencia`))) join `vn2008`.`Agencias_province` `ap` on(((`t`.`warehouse_id` = `ap`.`warehouse_id`) and (`ap`.`province_id` = `c`.`province_id`) and (`ap`.`agency_id` = `a`.`agency_id`)))) join `vn2008`.`Agencias_zonas` `az` on(((`az`.`Id_Agencia` = `t`.`Id_Agencia`) and (`az`.`zona` = `ap`.`zona`) and (`t`.`warehouse_id` = `az`.`warehouse_id`) and (`az`.`Id_Article` = 71)))) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -82114,24 +83263,6 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; --- --- Final view structure for view `companyOLD` --- - -/*!50001 DROP VIEW IF EXISTS `companyOLD`*/; -/*!50001 SET @saved_cs_client = @@character_set_client */; -/*!50001 SET @saved_cs_results = @@character_set_results */; -/*!50001 SET @saved_col_connection = @@collation_connection */; -/*!50001 SET character_set_client = utf8 */; -/*!50001 SET character_set_results = utf8 */; -/*!50001 SET collation_connection = utf8_general_ci */; -/*!50001 CREATE ALGORITHM=UNDEFINED */ -/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `companyOLD` AS select `e`.`id` AS `id`,`e`.`abbreviation` AS `code`,`e`.`Id_Proveedores_account` AS `supplierAccountFk`,`e`.`CodigoEmpresa` AS `CodigoEmpresa` from `vn2008`.`empresa` `e` */; -/*!50001 SET character_set_client = @saved_cs_client */; -/*!50001 SET character_set_results = @saved_cs_results */; -/*!50001 SET collation_connection = @saved_col_connection */; - -- -- Final view structure for view `comparative` -- @@ -83009,7 +84140,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `item` AS select `t`.`Id_Article` AS `id`,`t`.`Article` AS `name`,`t`.`tipo_id` AS `typeFk`,`t`.`Medida` AS `size`,`t`.`Color` AS `inkFk`,`t`.`Categoria` AS `category`,`t`.`Tallos` AS `stems`,`t`.`id_origen` AS `originFk`,`t`.`description` AS `description`,`t`.`producer_id` AS `producerFk`,`t`.`Codintrastat` AS `intrastatFk`,`t`.`offer` AS `isOnOffer`,`t`.`caja` AS `box`,`t`.`expenceFk` AS `expenceFk`,`t`.`bargain` AS `isBargain`,`t`.`comments` AS `comment`,`t`.`relevancy` AS `relevancy`,`t`.`Foto` AS `image`,`t`.`generic` AS `generic`,`t`.`density` AS `density`,`t`.`iva_group_id` AS `taxClassFk`,`t`.`PVP` AS `minPrice`,`t`.`Min` AS `hasMinPrice`,`t`.`isActive` AS `isActive`,`t`.`longName` AS `longName`,`t`.`subName` AS `subName`,`t`.`tag5` AS `tag5`,`t`.`value5` AS `value5`,`t`.`tag6` AS `tag6`,`t`.`value6` AS `value6`,`t`.`tag7` AS `tag7`,`t`.`value7` AS `value7`,`t`.`tag8` AS `tag8`,`t`.`value8` AS `value8`,`t`.`tag9` AS `tag9`,`t`.`value9` AS `value9`,`t`.`tag10` AS `tag10`,`t`.`value10` AS `value10`,`t`.`minimum` AS `minimum`,`t`.`upToDown` AS `upToDown`,`t`.`lastPrice` AS `lastPrice` from `vn2008`.`Articles` `t` */; +/*!50001 VIEW `item` AS select `t`.`Id_Article` AS `id`,`t`.`Article` AS `name`,`t`.`tipo_id` AS `typeFk`,`t`.`Medida` AS `size`,`t`.`Color` AS `inkFk`,`t`.`Categoria` AS `category`,`t`.`Tallos` AS `stems`,`t`.`id_origen` AS `originFk`,`t`.`description` AS `description`,`t`.`producer_id` AS `producerFk`,`t`.`Codintrastat` AS `intrastatFk`,`t`.`offer` AS `isOnOffer`,`t`.`caja` AS `box`,`t`.`expenceFk` AS `expenceFk`,`t`.`bargain` AS `isBargain`,`t`.`comments` AS `comment`,`t`.`relevancy` AS `relevancy`,`t`.`Foto` AS `image`,`t`.`generic` AS `generic`,`t`.`density` AS `density`,`t`.`iva_group_id` AS `taxClassFk`,`t`.`PVP` AS `minPrice`,`t`.`Min` AS `hasMinPrice`,`t`.`isActive` AS `isActive`,`t`.`longName` AS `longName`,`t`.`subName` AS `subName`,`t`.`tag5` AS `tag5`,`t`.`value5` AS `value5`,`t`.`tag6` AS `tag6`,`t`.`value6` AS `value6`,`t`.`tag7` AS `tag7`,`t`.`value7` AS `value7`,`t`.`tag8` AS `tag8`,`t`.`value8` AS `value8`,`t`.`tag9` AS `tag9`,`t`.`value9` AS `value9`,`t`.`tag10` AS `tag10`,`t`.`value10` AS `value10`,`t`.`minimum` AS `minimum`,`t`.`upToDown` AS `upToDown`,`t`.`compression` AS `compression` from `vn2008`.`Articles` `t` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -83135,7 +84266,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemPlacementSupplyList` AS select `ips`.`id` AS `id`,`ips`.`itemFk` AS `itemFk`,`ips`.`quantity` AS `quantity`,`ips`.`priority` AS `priority`,`ips`.`created` AS `created`,`ips`.`userFk` AS `userFk`,`ips`.`repoUserFk` AS `repoUserFk`,(`ips`.`quantity` - sum(ifnull(`isps`.`quantity`,0))) AS `saldo`,concat(`i`.`longName`,' ',`i`.`size`) AS `longName`,`i`.`subName` AS `subName`,`i`.`size` AS `size`,`w`.`workerCode` AS `workerCode`,`rw`.`workerCode` AS `repoCode`,`p`.`code` AS `parking` from (((((((`vn`.`itemPlacementSupply` `ips` join `vn`.`itemShelving` `ish` on((`ish`.`itemFk` = `ips`.`itemFk`))) join `vn`.`item` `i` on((`i`.`id` = `ish`.`itemFk`))) left join `vn`.`worker` `w` on((`w`.`id` = `ips`.`userFk`))) left join `vn`.`worker` `rw` on((`rw`.`id` = `ips`.`repoUserFk`))) left join `vn`.`itemShelvingPlacementSupply` `isps` on((`isps`.`itemShelvingFk` = `ish`.`id`))) left join `vn`.`shelving` `s` on((`ish`.`shelvingFk` = `s`.`code`))) left join `vn`.`parking` `p` on((`s`.`parkingFk` = `p`.`id`))) group by `ips`.`id` */; +/*!50001 VIEW `itemPlacementSupplyList` AS select `ips`.`id` AS `id`,`ips`.`itemFk` AS `itemFk`,`ips`.`quantity` AS `quantity`,`ips`.`priority` AS `priority`,`ips`.`created` AS `created`,`ips`.`userFk` AS `userFk`,`ips`.`repoUserFk` AS `repoUserFk`,(`ips`.`quantity` - sum(ifnull(`isps`.`quantity`,0))) AS `saldo`,concat(`i`.`longName`,' ',`i`.`size`) AS `longName`,`i`.`subName` AS `subName`,`i`.`size` AS `size`,`w`.`code` AS `workerCode`,`rw`.`code` AS `repoCode`,`p`.`code` AS `parking` from (((((((`vn`.`itemPlacementSupply` `ips` join `vn`.`itemShelving` `ish` on((`ish`.`itemFk` = `ips`.`itemFk`))) join `vn`.`item` `i` on((`i`.`id` = `ish`.`itemFk`))) left join `vn`.`worker` `w` on((`w`.`userFk` = `ips`.`userFk`))) left join `vn`.`worker` `rw` on((`rw`.`userFk` = `ips`.`repoUserFk`))) left join `vn`.`itemShelvingPlacementSupply` `isps` on((`isps`.`itemPlacementSupplyFk` = `ips`.`id`))) left join `vn`.`shelving` `s` on((`ish`.`shelvingFk` = `s`.`code`))) left join `vn`.`parking` `p` on((`s`.`parkingFk` = `p`.`id`))) group by `ips`.`id` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -83153,7 +84284,25 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemShelvingAvailable` AS select `s`.`id` AS `saleFk`,`tst`.`updated` AS `Modificado`,`s`.`ticketFk` AS `ticketFk`,`s`.`isPicked` AS `isPicked`,`s`.`itemFk` AS `itemFk`,`s`.`quantity` AS `quantity`,`s`.`concept` AS `concept`,`i`.`size` AS `size`,`st`.`name` AS `Estado`,`st`.`sectorProdPriority` AS `sectorProdPriority`,`its`.`available` AS `available`,`pk`.`sectorFk` AS `sectorFk`,`sh`.`code` AS `matricula`,`pk`.`id` AS `parking`,`its`.`id` AS `itemShelving`,`am`.`name` AS `Agency`,`t`.`shipped` AS `shipped`,`its`.`grouping` AS `grouping`,`its`.`packing` AS `packing` from (((((((((`vn`.`sale` `s` join `vn`.`ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `vn`.`agencyMode` `am` on((`am`.`id` = `t`.`agencyModeFk`))) join `vn`.`ticketStateToday` `tst` on((`tst`.`ticket` = `t`.`id`))) join `vn`.`state` `st` on((`st`.`id` = `tst`.`state`))) join `vn`.`item` `i` on((`i`.`id` = `s`.`itemFk`))) join `vn`.`itemShelving` `its` on((`its`.`itemFk` = `s`.`itemFk`))) join `vn`.`shelving` `sh` on((`sh`.`code` = `its`.`shelvingFk`))) join `vn`.`parking` `pk` on((`pk`.`id` = `sh`.`parkingFk`))) join `vn`.`sector` `sc` on(((`sc`.`id` = `pk`.`sectorFk`) and (`sc`.`warehouseFk` = `t`.`warehouseFk`)))) where ((`t`.`shipped` between `util`.`yesterday`() and `util`.`dayend`(curdate())) and (`its`.`available` > 0) and (`sh`.`code` <> 'FUE') and (`its`.`grouping` <= `s`.`quantity`) and `st`.`sectorProdPriority`) */; +/*!50001 VIEW `itemShelvingAvailable` AS select `s`.`id` AS `saleFk`,`tst`.`updated` AS `Modificado`,`s`.`ticketFk` AS `ticketFk`,`stk`.`isChecked` AS `isPicked`,`s`.`itemFk` AS `itemFk`,`s`.`quantity` AS `quantity`,`s`.`concept` AS `concept`,`i`.`size` AS `size`,`st`.`name` AS `Estado`,`st`.`sectorProdPriority` AS `sectorProdPriority`,`its`.`available` AS `available`,`pk`.`sectorFk` AS `sectorFk`,`sh`.`code` AS `matricula`,`pk`.`id` AS `parking`,`its`.`id` AS `itemShelving`,`am`.`name` AS `Agency`,`t`.`shipped` AS `shipped`,`its`.`grouping` AS `grouping`,`its`.`packing` AS `packing` from ((((((((((`vn`.`sale` `s` join `vn`.`ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `vn`.`agencyMode` `am` on((`am`.`id` = `t`.`agencyModeFk`))) join `vn`.`ticketStateToday` `tst` on((`tst`.`ticket` = `t`.`id`))) join `vn`.`state` `st` on((`st`.`id` = `tst`.`state`))) join `vn`.`item` `i` on((`i`.`id` = `s`.`itemFk`))) join `vn`.`itemShelving` `its` on((`its`.`itemFk` = `s`.`itemFk`))) join `vn`.`shelving` `sh` on((`sh`.`code` = `its`.`shelvingFk`))) join `vn`.`parking` `pk` on((`pk`.`id` = `sh`.`parkingFk`))) join `vn`.`sector` `sc` on(((`sc`.`id` = `pk`.`sectorFk`) and (`sc`.`warehouseFk` = `t`.`warehouseFk`)))) left join `vn`.`saleTracking` `stk` on(((`stk`.`saleFk` = `s`.`id`) and (`stk`.`stateFk` = 26)))) where ((`t`.`shipped` between `util`.`yesterday`() and `util`.`dayend`(curdate())) and (`its`.`available` > 0) and (`sh`.`code` <> 'FUE') and (`its`.`grouping` <= `s`.`quantity`) and `st`.`sectorProdPriority`) */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + +-- +-- Final view structure for view `itemShelvingAvailableKk` +-- + +/*!50001 DROP VIEW IF EXISTS `itemShelvingAvailableKk`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8 */; +/*!50001 SET character_set_results = utf8 */; +/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `itemShelvingAvailableKk` AS select `s`.`id` AS `saleFk`,`tst`.`updated` AS `Modificado`,`s`.`ticketFk` AS `ticketFk`,`s`.`isPicked` AS `isPicked`,`s`.`itemFk` AS `itemFk`,`s`.`quantity` AS `quantity`,`s`.`concept` AS `concept`,`i`.`size` AS `size`,`st`.`name` AS `Estado`,`st`.`sectorProdPriority` AS `sectorProdPriority`,`its`.`available` AS `available`,`pk`.`sectorFk` AS `sectorFk`,`sh`.`code` AS `matricula`,`pk`.`id` AS `parking`,`its`.`id` AS `itemShelving`,`am`.`name` AS `Agency`,`t`.`shipped` AS `shipped`,`its`.`grouping` AS `grouping`,`its`.`packing` AS `packing` from (((((((((`vn`.`sale` `s` join `vn`.`ticket` `t` on((`t`.`id` = `s`.`ticketFk`))) join `vn`.`agencyMode` `am` on((`am`.`id` = `t`.`agencyModeFk`))) join `vn`.`ticketStateToday` `tst` on((`tst`.`ticket` = `t`.`id`))) join `vn`.`state` `st` on((`st`.`id` = `tst`.`state`))) join `vn`.`item` `i` on((`i`.`id` = `s`.`itemFk`))) join `vn`.`itemShelving` `its` on((`its`.`itemFk` = `s`.`itemFk`))) join `vn`.`shelving` `sh` on((`sh`.`code` = `its`.`shelvingFk`))) join `vn`.`parking` `pk` on((`pk`.`id` = `sh`.`parkingFk`))) join `vn`.`sector` `sc` on(((`sc`.`id` = `pk`.`sectorFk`) and (`sc`.`warehouseFk` = `t`.`warehouseFk`)))) where ((`t`.`shipped` between `util`.`yesterday`() and `util`.`dayend`(curdate())) and (`its`.`available` > 0) and (`sh`.`code` <> 'FUE') and (`its`.`grouping` <= `s`.`quantity`) and `st`.`sectorProdPriority`) */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -83189,7 +84338,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemShelvingPlacementSupplyStock` AS select `ish`.`id` AS `itemShelvingFk`,`ish`.`itemFk` AS `itemFk`,`ish`.`quantity` AS `quantity`,`ish`.`packing` AS `packing`,((`ish`.`visible` - sum(ifnull(`iss`.`quantity`,0))) - sum(ifnull(`isps`.`quantity`,0))) AS `stock`,`i`.`longName` AS `longName`,`i`.`size` AS `size`,`i`.`subName` AS `subName`,`sh`.`code` AS `shelving`,`p`.`code` AS `parking`,`ish`.`created` AS `created`,ifnull(`sh`.`priority`,1) AS `priority` from (((((`vn`.`itemShelving` `ish` join `vn`.`shelving` `sh` on((`sh`.`code` = `ish`.`shelvingFk`))) left join `vn`.`parking` `p` on((`p`.`id` = `sh`.`parkingFk`))) join `vn`.`item` `i` on((`i`.`id` = `ish`.`itemFk`))) left join `vn`.`itemShelvingSale` `iss` on((`iss`.`itemShelvingFk` = `ish`.`id`))) left join `vn`.`itemShelvingPlacementSupply` `isps` on((`isps`.`itemShelvingFk` = `ish`.`id`))) group by `ish`.`id` */; +/*!50001 VIEW `itemShelvingPlacementSupplyStock` AS select `ish`.`id` AS `itemShelvingFk`,`ish`.`itemFk` AS `itemFk`,`ish`.`quantity` AS `quantity`,`ish`.`packing` AS `packing`,`ish`.`visible` AS `stock`,`i`.`longName` AS `longName`,`i`.`size` AS `size`,`i`.`subName` AS `subName`,`sh`.`code` AS `shelving`,`p`.`code` AS `parking`,`ish`.`created` AS `created`,ifnull(`sh`.`priority`,1) AS `priority` from (((((`vn`.`itemShelving` `ish` join `vn`.`shelving` `sh` on((`sh`.`code` = `ish`.`shelvingFk`))) left join `vn`.`parking` `p` on((`p`.`id` = `sh`.`parkingFk`))) join `vn`.`item` `i` on((`i`.`id` = `ish`.`itemFk`))) left join `vn`.`itemShelvingSale` `iss` on((`iss`.`itemShelvingFk` = `ish`.`id`))) left join `vn`.`itemShelvingPlacementSupply` `isps` on((`isps`.`itemShelvingFk` = `ish`.`id`))) group by `ish`.`id` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -83315,7 +84464,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `itemType` AS select `t`.`tipo_id` AS `id`,`t`.`Id_Tipo` AS `code`,`t`.`Tipo` AS `name`,`t`.`reino_id` AS `categoryFk`,`t`.`life` AS `life`,`t`.`Id_Trabajador` AS `workerFk`,`t`.`warehouseFk` AS `warehouseFk`,`t`.`isPackaging` AS `isPackaging` from `vn2008`.`Tipos` `t` */; +/*!50001 VIEW `itemType` AS select `t`.`tipo_id` AS `id`,`t`.`Id_Tipo` AS `code`,`t`.`Tipo` AS `name`,`t`.`reino_id` AS `categoryFk`,`t`.`life` AS `life`,`t`.`Id_Trabajador` AS `workerFk`,`t`.`warehouseFk` AS `warehouseFk`,`t`.`isPackaging` AS `isPackaging`,`t`.`density` AS `density` from `vn2008`.`Tipos` `t` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -84179,7 +85328,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `supplierPackaging` AS select `e`.`supplierFk` AS `supplierFk`,`b`.`itemFk` AS `itemFk`,`i`.`longName` AS `longName`,`s`.`name` AS `supplier`,`b`.`entryFk` AS `entryFk`,`tr`.`landed` AS `landed`,-(least(`b`.`quantity`,0)) AS `in`,greatest(`b`.`quantity`,0) AS `out`,`w`.`name` AS `almacen` from ((((((`vn`.`buy` `b` join `vn`.`item` `i` on((`i`.`id` = `b`.`itemFk`))) join `vn`.`packaging` `p` on((`p`.`itemFk` = `i`.`id`))) join `vn`.`entry` `e` on((`e`.`id` = `b`.`entryFk`))) join `vn`.`supplier` `s` on((`s`.`id` = `e`.`supplierFk`))) join `vn`.`travel` `tr` on((`tr`.`id` = `e`.`travelFk`))) join `vn`.`warehouse` `w` on((`w`.`id` = `tr`.`warehouseInFk`))) where `p`.`isPackageReturnable` */; +/*!50001 VIEW `supplierPackaging` AS select `e`.`supplierFk` AS `supplierFk`,`b`.`itemFk` AS `itemFk`,`i`.`longName` AS `longName`,`s`.`name` AS `supplier`,`b`.`entryFk` AS `entryFk`,`tr`.`landed` AS `landed`,-(least(`b`.`quantity`,0)) AS `out`,greatest(`b`.`quantity`,0) AS `in`,`w`.`name` AS `almacen` from ((((((`vn`.`buy` `b` join `vn`.`item` `i` on((`i`.`id` = `b`.`itemFk`))) join `vn`.`packaging` `p` on((`p`.`itemFk` = `i`.`id`))) join `vn`.`entry` `e` on((`e`.`id` = `b`.`entryFk`))) join `vn`.`supplier` `s` on((`s`.`id` = `e`.`supplierFk`))) join `vn`.`travel` `tr` on((`tr`.`id` = `e`.`travelFk`))) join `vn`.`warehouse` `w` on((`w`.`id` = `tr`.`warehouseInFk`))) where `p`.`isPackageReturnable` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -84413,7 +85562,7 @@ USE `vn`; /*!50001 SET collation_connection = utf8_general_ci */; /*!50001 CREATE ALGORITHM=UNDEFINED */ /*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ -/*!50001 VIEW `ticketToPrepare` AS select `m`.`Id_Ticket` AS `Id_Ticket`,`mk`.`Id_Movimiento` AS `Id_Movimiento`,`mk`.`Id_Movimiento_mark` AS `Id_Movimiento_mark`,`mk`.`Id_Trabajador` AS `Id_Trabjador`,`m`.`Id_Article` AS `Id_Article`,`m`.`Concepte` AS `Concepte`,`art`.`subName` AS `subName`,`mk`.`original_quantity` AS `Cantidad`,`mk`.`original_quantity` AS `original_quantity`,hour(`t`.`shipped`) AS `Hora`,hour(`t`.`shipped`) AS `Departure`,minute(`t`.`shipped`) AS `Minuto`,`am`.`agencyFk` AS `agency_id`,`t`.`warehouseFk` AS `warehouse_id`,`a`.`provinceFk` AS `province_id`,`is`.`quantity` AS `picked` from ((((((`vn2008`.`Movimientos_mark` `mk` join `vn2008`.`Movimientos` `m` on((`m`.`Id_Movimiento` = `mk`.`Id_Movimiento`))) join `vn`.`ticket` `t` on((`m`.`Id_Ticket` = `t`.`id`))) join `vn`.`agencyMode` `am` on((`am`.`id` = `t`.`agencyModeFk`))) join `vn`.`address` `a` on((`a`.`id` = `t`.`addressFk`))) left join `vn`.`itemShelvingSale` `is` on((`is`.`saleFk` = `mk`.`Id_Movimiento`))) join `vn2008`.`Articles` `art` on((`art`.`Id_Article` = `m`.`Id_Article`))) where ((`mk`.`stateFk` = 26) and (`mk`.`valor` <> 1)) */; +/*!50001 VIEW `ticketToPrepare` AS select `m`.`Id_Ticket` AS `Id_Ticket`,`mk`.`Id_Movimiento` AS `Id_Movimiento`,`mk`.`Id_Movimiento_mark` AS `Id_Movimiento_mark`,`mk`.`Id_Trabajador` AS `Id_Trabjador`,`m`.`Id_Article` AS `Id_Article`,`m`.`Concepte` AS `Concepte`,`art`.`subName` AS `subName`,(`mk`.`original_quantity` - ifnull(`is`.`quantity`,0)) AS `Cantidad`,`mk`.`original_quantity` AS `original_quantity`,hour(`t`.`shipped`) AS `Hora`,hour(`t`.`shipped`) AS `Departure`,minute(`t`.`shipped`) AS `Minuto`,`am`.`agencyFk` AS `agency_id`,`t`.`warehouseFk` AS `warehouse_id`,`a`.`provinceFk` AS `province_id`,`is`.`quantity` AS `picked` from ((((((`vn2008`.`Movimientos_mark` `mk` join `vn2008`.`Movimientos` `m` on((`m`.`Id_Movimiento` = `mk`.`Id_Movimiento`))) join `vn`.`ticket` `t` on((`m`.`Id_Ticket` = `t`.`id`))) join `vn`.`agencyMode` `am` on((`am`.`id` = `t`.`agencyModeFk`))) join `vn`.`address` `a` on((`a`.`id` = `t`.`addressFk`))) left join `vn`.`itemShelvingSale` `is` on((`is`.`saleFk` = `mk`.`Id_Movimiento`))) join `vn2008`.`Articles` `art` on((`art`.`Id_Article` = `m`.`Id_Article`))) where ((`mk`.`stateFk` = 26) and (`mk`.`valor` <> 1) and (`t`.`warehouseFk` = 1)) group by `mk`.`Id_Movimiento_mark` */; /*!50001 SET character_set_client = @saved_cs_client */; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; @@ -84472,6 +85621,24 @@ USE `vn`; /*!50001 SET character_set_results = @saved_cs_results */; /*!50001 SET collation_connection = @saved_col_connection */; +-- +-- Final view structure for view `ticketeToPreparePrepared` +-- + +/*!50001 DROP VIEW IF EXISTS `ticketeToPreparePrepared`*/; +/*!50001 SET @saved_cs_client = @@character_set_client */; +/*!50001 SET @saved_cs_results = @@character_set_results */; +/*!50001 SET @saved_col_connection = @@collation_connection */; +/*!50001 SET character_set_client = utf8 */; +/*!50001 SET character_set_results = utf8 */; +/*!50001 SET collation_connection = utf8_general_ci */; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`%` SQL SECURITY DEFINER */ +/*!50001 VIEW `ticketeToPreparePrepared` AS select `m`.`Id_Ticket` AS `Id_Ticket`,`mk`.`Id_Movimiento` AS `Id_Movimiento`,`mk`.`Id_Movimiento_mark` AS `Id_Movimiento_mark`,`mk`.`Id_Trabajador` AS `Id_Trabjador`,`m`.`Id_Article` AS `Id_Article`,`m`.`Concepte` AS `Concepte`,`art`.`subName` AS `subName`,(`mk`.`original_quantity` - ifnull(`is`.`quantity`,0)) AS `Cantidad`,`mk`.`original_quantity` AS `original_quantity`,hour(`t`.`shipped`) AS `Hora`,hour(`t`.`shipped`) AS `Departure`,minute(`t`.`shipped`) AS `Minuto`,`am`.`agencyFk` AS `agency_id`,`t`.`warehouseFk` AS `warehouse_id`,`a`.`provinceFk` AS `province_id`,`is`.`quantity` AS `picked`,`t`.`CodigoTrabajador` AS `trabajador` from (((((((`vn2008`.`Movimientos_mark` `mk` join `vn2008`.`Movimientos` `m` on((`m`.`Id_Movimiento` = `mk`.`Id_Movimiento`))) join `vn`.`ticket` `t` on((`m`.`Id_Ticket` = `t`.`id`))) join `vn`.`agencyMode` `am` on((`am`.`id` = `t`.`agencyModeFk`))) join `vn`.`address` `a` on((`a`.`id` = `t`.`addressFk`))) left join `vn`.`itemShelvingSale` `is` on((`is`.`saleFk` = `mk`.`Id_Movimiento`))) join `vn2008`.`Articles` `art` on((`art`.`Id_Article` = `m`.`Id_Article`))) left join `vn2008`.`Trabajadores` `t` on((`t`.`Id_Trabajador` = `mk`.`Id_Trabajador`))) where ((`mk`.`stateFk` = 26) and (`t`.`warehouseFk` = 1)) group by `mk`.`Id_Movimiento_mark` */; +/*!50001 SET character_set_client = @saved_cs_client */; +/*!50001 SET character_set_results = @saved_cs_results */; +/*!50001 SET collation_connection = @saved_col_connection */; + -- -- Final view structure for view `till` -- @@ -85681,4 +86848,4 @@ USE `postgresql`; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2019-03-01 13:39:22 +-- Dump completed on 2019-03-15 8:57:04 diff --git a/e2e/paths/ticket-module/06_edit_basic_data_steps.spec.js b/e2e/paths/ticket-module/06_edit_basic_data_steps.spec.js index 067cc55e4..d467a9f5e 100644 --- a/e2e/paths/ticket-module/06_edit_basic_data_steps.spec.js +++ b/e2e/paths/ticket-module/06_edit_basic_data_steps.spec.js @@ -73,7 +73,7 @@ describe('Ticket Edit basic data path', () => { .wait(1900) .waitToGetProperty(selectors.ticketBasicData.stepTwoTotalPriceDif, 'innerText'); - expect(result).toContain('-€208.75'); + expect(result).toContain('-€204.25'); }); it(`should then click next to move on to step three`, async() => { diff --git a/modules/client/back/methods/client/specs/getCard.spec.js b/modules/client/back/methods/client/specs/getCard.spec.js index 1619280f8..768b65c9a 100644 --- a/modules/client/back/methods/client/specs/getCard.spec.js +++ b/modules/client/back/methods/client/specs/getCard.spec.js @@ -7,6 +7,6 @@ describe('Client get', () => { expect(result.id).toEqual(101); expect(result.name).toEqual('Bruce Wayne'); - expect(result.debt).toEqual(595.81); + expect(result.debt).toEqual(598.45); }); }); diff --git a/modules/client/back/methods/client/specs/summary.spec.js b/modules/client/back/methods/client/specs/summary.spec.js index aeae819ee..2916a548f 100644 --- a/modules/client/back/methods/client/specs/summary.spec.js +++ b/modules/client/back/methods/client/specs/summary.spec.js @@ -17,7 +17,7 @@ describe('client summary()', () => { it('should return a summary object containing debt', async() => { let result = await app.models.Client.summary(101); - expect(result.debt.debt).toEqual(595.81); + expect(result.debt.debt).toEqual(598.45); }); it('should return a summary object containing averageInvoiced', async() => { diff --git a/modules/order/back/methods/order/specs/getTotalVolume.spec.js b/modules/order/back/methods/order/specs/getTotalVolume.spec.js index cad72fd8c..58916d8a5 100644 --- a/modules/order/back/methods/order/specs/getTotalVolume.spec.js +++ b/modules/order/back/methods/order/specs/getTotalVolume.spec.js @@ -5,6 +5,6 @@ describe('order getTotalVolume()', () => { let result = await app.models.Order.getTotalVolume(1); expect(result.totalVolume).toEqual(0.066); - expect(result.totalBoxes).toBeFalsy(); + expect(result.totalBoxes).toEqual(0.5); }); }); diff --git a/modules/ticket/back/methods/sale/priceDifference.js b/modules/ticket/back/methods/sale/priceDifference.js index 58af82527..c744a8321 100644 --- a/modules/ticket/back/methods/sale/priceDifference.js +++ b/modules/ticket/back/methods/sale/priceDifference.js @@ -59,6 +59,9 @@ module.exports = Self => { salesObj.totalUnitPrice += sale.price; salesObj.totalNewPrice += sale.component.newPrice; salesObj.totalDifference += sale.component.difference; + salesObj.totalUnitPrice = Math.round(salesObj.totalUnitPrice * 100) / 100; + salesObj.totalNewPrice = Math.round(salesObj.totalNewPrice * 100) / 100; + salesObj.totalDifference = Math.round(salesObj.totalDifference * 100) / 100; }); return salesObj; diff --git a/modules/ticket/back/methods/sale/specs/priceDifference.spec.js b/modules/ticket/back/methods/sale/specs/priceDifference.spec.js index 7f7867e30..0f1d2e4be 100644 --- a/modules/ticket/back/methods/sale/specs/priceDifference.spec.js +++ b/modules/ticket/back/methods/sale/specs/priceDifference.spec.js @@ -11,7 +11,7 @@ describe('sale priceDifference()', () => { let result = await app.models.Sale.priceDifference(1, data); expect(result.totalUnitPrice).toEqual(22.33); - expect(result.totalNewPrice).toEqual(22.29); - expect(result.totalDifference).toEqual(0.8); + expect(result.totalNewPrice).toEqual(22.27); + expect(result.totalDifference).toEqual(0.87); }); });